linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/6] Btrfs: show subvolume name and ID in /proc/mounts
@ 2015-04-09 21:34 Omar Sandoval
  2015-04-09 21:34 ` [PATCH v2 1/6] Btrfs: lock superblock before remounting for rw subvol Omar Sandoval
                   ` (6 more replies)
  0 siblings, 7 replies; 21+ messages in thread
From: Omar Sandoval @ 2015-04-09 21:34 UTC (permalink / raw)
  To: Chris Mason, Josef Bacik, David Sterba, linux-btrfs
  Cc: linux-kernel, Qu Wenruo, Omar Sandoval

Here's version 2 of providing the subvolume name and ID in /proc/mounts.

It turns out that getting the name of a subvolume reliably is a bit
trickier than it would seem because of how mounting subvolumes by ID is
implemented. In particular, in that case, the dentry we get for the root
of the mount is not necessarily attached to the dentry tree, which means
that the obvious solution of just dumping the dentry does not work. The
solution I put together makes the tradeoff of churning a bit more code
in order to avoid implementing this with weird hacks.

Changes from v1 (https://lkml.org/lkml/2015/4/8/16):

- Put subvol= last in show_options
- Change commit log to remove comment about userspace having no way to
  know which subvolume is mounted, as David pointed out you can use
  btrfs inspect-internal rootid <mountpoint>
- Split up patch 2
- Minor coding style fixes

This still applies to v4.0-rc7. Tested manually and with the script
below (updated from v1).

Thanks!

Omar Sandoval (6):
  Btrfs: lock superblock before remounting for rw subvol
  Btrfs: remove all subvol options before mounting top-level
  Btrfs: clean up error handling in mount_subvol()
  Btrfs: fail on mismatched subvol and subvolid mount options
  Btrfs: unify subvol= and subvolid= mounting
  Btrfs: show subvol= and subvolid= in /proc/mounts

 fs/btrfs/super.c | 376 ++++++++++++++++++++++++++++++++++++-------------------
 fs/seq_file.c    |   1 +
 2 files changed, 251 insertions(+), 126 deletions(-)

Testing script:

----
#!/bin/sh

set -e

check_subvol () {
	NAME="$1"
	ID="$2"

	# Mount by name.
	mount -osubvol="$NAME" /dev/vdb /mnt
	if ! findmnt -fno OPTIONS /mnt | grep -F ",subvolid=$ID,subvol=$NAME"; then
		echo "Failed $NAME" >&2
		umount /mnt
		exit 1
	fi
	umount /mnt

	# Mount by ID.
	mount -osubvolid="$ID" /dev/vdb /mnt
	if ! findmnt -fno OPTIONS /mnt | grep -F ",subvolid=$ID,subvol=$NAME"; then
		echo "Failed $ID" >&2
		umount /mnt
		exit 1
	fi
	umount /mnt
}

check_default_subvol () {
	NAME="$1"
	ID="$2"

	mount /dev/vdb /mnt
	if ! findmnt -fno OPTIONS /mnt | grep -F ",subvolid=$ID,subvol=$NAME"; then
		echo "Failed default" >&2
		umount /mnt
		exit 1
	fi
	umount /mnt
}

mkfs.btrfs -f /dev/vdb
mount /dev/vdb /mnt
btrfs subvolume create /mnt/vol
btrfs subvolume create /mnt/vol/nestedvol
mkdir /mnt/dir
btrfs subvolume create /mnt/dir/dirvol
btrfs subvolume create /mnt/dir/dirvol/nesteddirvol
mkdir /mnt/vol/voldir
btrfs subvolume create /mnt/vol/voldir/voldirvol
btrfs subvolume list /mnt
umount /mnt

check_subvol /vol 257
check_subvol /vol/nestedvol 258
check_subvol /dir/dirvol 259
check_subvol /dir/dirvol/nesteddirvol 260
check_subvol /vol/voldir/voldirvol 261

check_default_subvol / 5

mount /dev/vdb /mnt
btrfs subvolume set-default 257 /mnt
umount /mnt

check_default_subvol /vol 257

if mount -osubvolid=258,subvol=/vol /dev/vdb /mnt 2>/dev/null; then
	umount /mnt
	echo "Mount of mismatched subvol and subvolid should have failed" >&2
	exit 1
fi
----

-- 
2.3.5


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2015-05-12  0:46 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-09 21:34 [PATCH v2 0/6] Btrfs: show subvolume name and ID in /proc/mounts Omar Sandoval
2015-04-09 21:34 ` [PATCH v2 1/6] Btrfs: lock superblock before remounting for rw subvol Omar Sandoval
2015-05-11 16:07   ` David Sterba
2015-04-09 21:34 ` [PATCH v2 2/6] Btrfs: remove all subvol options before mounting top-level Omar Sandoval
2015-05-11 16:08   ` David Sterba
2015-04-09 21:34 ` [PATCH v2 3/6] Btrfs: clean up error handling in mount_subvol() Omar Sandoval
2015-05-11 16:08   ` David Sterba
2015-04-09 21:34 ` [PATCH v2 4/6] Btrfs: fail on mismatched subvol and subvolid mount options Omar Sandoval
2015-04-10  0:39   ` Qu Wenruo
2015-04-14 15:07     ` David Sterba
2015-05-11 16:09   ` David Sterba
2015-04-09 21:34 ` [PATCH v2 5/6] Btrfs: unify subvol= and subvolid= mounting Omar Sandoval
2015-05-11 15:37   ` David Sterba
2015-05-11 21:15     ` Omar Sandoval
2015-05-11 16:10   ` David Sterba
2015-04-09 21:34 ` [PATCH v2 6/6] Btrfs: show subvol= and subvolid= in /proc/mounts Omar Sandoval
2015-05-11 16:10   ` David Sterba
2015-05-11  9:42 ` [PATCH v2 0/6] Btrfs: show subvolume name and ID " Omar Sandoval
2015-05-11 14:51   ` David Sterba
2015-05-11 21:20     ` Omar Sandoval
2015-05-12  0:46   ` Qu Wenruo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).