]> git.ipfire.org Git - thirdparty/util-linux.git/commit - sys-utils/mount.8.adoc
libmount: add X-mount.subdir=
authorKarel Zak <kzak@redhat.com>
Wed, 11 Aug 2021 13:57:37 +0000 (15:57 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 11 Aug 2021 14:14:38 +0000 (16:14 +0200)
commite311e731be92d96a674be0609da4b7ef44c16522
treebe6009a9964cff4b5ca888e077ba400270218220
parent77d4e97784714a4862334fa05ab8590735d0eab6
libmount: add X-mount.subdir=

Like btrfs subvol=, but more generic and for all filesystems. This
feature is marked as EXPERIMENTAL (may be removed).

 # mount /dev/sdc /mnt/test -o X-mount.subdir=AAA

 # findmnt /dev/sdc
 TARGET    SOURCE         FSTYPE OPTIONS
 /mnt/test /dev/sdc[/AAA] ext4   rw,relatime,stripe=512

Implemented as:

 * open current namespace from /proc/self/ns/mnt
 * mkdir /tmp/mount/mount.<pid>
 * unshare mount namespace
 * create mount node from /tmp/mount/mount.<pid> by mount(MS_BIND)
 * mark /tmp/mount/mount.<pid> private by mount(MS_PRIVATE|MS_REC)
 * bind mount /tmp/mount/mount.<pid>/subdir to <target>
 * umount /tmp/mount/mount.<pid>
 * rmdir /tmp/mount/mount.<pid>
 * setns() to the original namespace

Note that /tmp/mount/mount.<pid> conversion to mount node and call for
MS_PRIVATE are visible (propagated to the system) if /tmp is a shared
filesystem, the rest (all operations with the desired filesystem) is
atomic for a parental namespace.

Maybe one day it will be possible to reimplement it in more
elegant way with new mount kernel APIs (open_tree(), etc.).

Fixes: https://github.com/karelzak/util-linux/issues/1103
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/context.c
libmount/src/context_mount.c
libmount/src/mountP.h
libmount/src/utils.c
sys-utils/mount.8.adoc