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

So this is something that has bothered me as a Btrfs user for some time
and that came up in discussing a separate bug here:
https://lkml.org/lkml/2015/4/2/447.

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.

Patch 1 is a bug fix that I came across during testing. Because it would
conflict with merging patch 2, I'm including it here.

Patch 2 is the big one: it makes mounts by subvolid work the same way as
mounts by subvol name by looking up the name for a subvolid from the
root backrefs and inode refs. It comes with the added benefit of making
subvolume mounts share the same codepath regardless of the method.

Patch 3 is really simple thanks to patch 2: the obvious change to
btrfs_show_options() works now.

This series applies to v4.0-rc7. I've tested it manually and with the
script below. Thank you!

Omar Sandoval (3):
  Btrfs: lock superblock before remounting for rw subvol
  Btrfs: unify subvol= and subvolid= mounting
  Btrfs: show subvol= and subvolid= in /proc/mounts

 fs/btrfs/super.c | 353 ++++++++++++++++++++++++++++++++++++-------------------
 fs/seq_file.c    |   1 +
 2 files changed, 232 insertions(+), 122 deletions(-)


Testing script:

----
#!/bin/sh

set -e

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

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

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

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

	mount /dev/vdb /mnt
	if ! grep vdb /proc/mounts | grep ",subvol=$NAME,subvolid=$ID"; then
		echo "Failed default" >&2
		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
----

-- 
2.3.5


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

end of thread, other threads:[~2015-04-10  0:33 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-08  5:33 [PATCH 0/3] Btrfs: show subvolume name and ID in /proc/mounts Omar Sandoval
2015-04-08  5:34 ` [PATCH 1/3] Btrfs: lock superblock before remounting for rw subvol Omar Sandoval
2015-04-08  5:34 ` [PATCH 2/3] Btrfs: unify subvol= and subvolid= mounting Omar Sandoval
2015-04-08  6:06   ` Qu Wenruo
2015-04-08  7:17     ` Omar Sandoval
2015-04-08  7:36       ` Qu Wenruo
2015-04-09 16:10     ` David Sterba
2015-04-10  0:33       ` Qu Wenruo
2015-04-09 16:28   ` David Sterba
2015-04-09 19:03     ` Omar Sandoval
2015-04-08  5:34 ` [PATCH 3/3] Btrfs: show subvol= and subvolid= in /proc/mounts Omar Sandoval
2015-04-08  5:57   ` Qu Wenruo
2015-04-09 15:56   ` David Sterba

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).