aboutsummaryrefslogtreecommitdiffstats
path: root/libmount/src/utils.c
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2022-05-25 14:01:52 +0200
committerKarel Zak <kzak@redhat.com>2023-01-03 12:53:12 +0100
commitb0a165dc76c024614a930325877a25555d4ff819 (patch)
tree3aeb54c393c16da209ee34f012e63ef6f45403d9 /libmount/src/utils.c
parent17de67aa1d7dee8cb8ea3040867a989af44a8243 (diff)
downloadutil-linux-b0a165dc76c024614a930325877a25555d4ff819.tar.gz
libmount: reimplement X-mount.subdir= by hooks
* "prepare-target hook" checks for X-mount.subdir= and define pre-mount hook * "mount-pre hook" unshares temporary directory, redirect the next mount(2) to this temporary directory * "mount-post hook" binds subdirectory to the final target, umounts temporary directory Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/utils.c')
-rw-r--r--libmount/src/utils.c73
1 files changed, 0 insertions, 73 deletions
diff --git a/libmount/src/utils.c b/libmount/src/utils.c
index 5693cf8adf..26c5aef7b1 100644
--- a/libmount/src/utils.c
+++ b/libmount/src/utils.c
@@ -1240,79 +1240,6 @@ done:
return 1;
}
-/*
- * Initialize MNT_PATH_TMPTGT; mkdir, create a new namespace and
- * mark (bind mount) the directory as private.
- */
-int mnt_tmptgt_unshare(int *old_ns_fd)
-{
-#ifdef USE_LIBMOUNT_SUPPORT_NAMESPACES
- int rc = 0, fd = -1;
-
- assert(old_ns_fd);
-
- *old_ns_fd = -1;
-
- /* remember the current namespace */
- fd = open("/proc/self/ns/mnt", O_RDONLY | O_CLOEXEC);
- if (fd < 0)
- goto fail;
-
- /* create new namespace */
- if (unshare(CLONE_NEWNS) != 0)
- goto fail;
-
- /* create directory */
- rc = ul_mkdir_p(MNT_PATH_TMPTGT, S_IRWXU);
- if (rc)
- goto fail;
-
- /* try to set top-level directory as private, this is possible if
- * MNT_RUNTIME_TOPDIR (/run) is a separated filesystem. */
- if (mount("none", MNT_RUNTIME_TOPDIR, NULL, MS_PRIVATE, NULL) != 0) {
-
- /* failed; create a mountpoint from MNT_PATH_TMPTGT */
- if (mount(MNT_PATH_TMPTGT, MNT_PATH_TMPTGT, "none", MS_BIND, NULL) != 0)
- goto fail;
- if (mount("none", MNT_PATH_TMPTGT, NULL, MS_PRIVATE, NULL) != 0)
- goto fail;
- }
-
- DBG(UTILS, ul_debug(MNT_PATH_TMPTGT " unshared"));
- *old_ns_fd = fd;
- return 0;
-fail:
- if (rc == 0)
- rc = errno ? -errno : -EINVAL;
-
- mnt_tmptgt_cleanup(fd);
- DBG(UTILS, ul_debug(MNT_PATH_TMPTGT " unshare failed"));
- return rc;
-#else
- return -ENOSYS;
-#endif
-}
-
-/*
- * Clean up MNT_PATH_TMPTGT; umount and switch back to old namespace
- */
-int mnt_tmptgt_cleanup(int old_ns_fd)
-{
-#ifdef USE_LIBMOUNT_SUPPORT_NAMESPACES
- umount(MNT_PATH_TMPTGT);
-
- if (old_ns_fd >= 0) {
- setns(old_ns_fd, CLONE_NEWNS);
- close(old_ns_fd);
- }
-
- DBG(UTILS, ul_debug(MNT_PATH_TMPTGT " cleanup done"));
- return 0;
-#else
- return -ENOSYS;
-#endif
-}
-
#ifdef TEST_PROGRAM
static int test_match_fstype(struct libmnt_test *ts, int argc, char *argv[])
{