All of lore.kernel.org
 help / color / mirror / Atom feed
From: Omar Sandoval <osandov@osandov.com>
To: Chris Mason <clm@fb.com>, Josef Bacik <jbacik@fb.com>,
	David Sterba <dsterba@suse.cz>,
	linux-btrfs@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Omar Sandoval <osandov@osandov.com>
Subject: [PATCH 0/3] Btrfs: show subvolume name and ID in /proc/mounts
Date: Tue,  7 Apr 2015 22:33:59 -0700	[thread overview]
Message-ID: <cover.1428471096.git.osandov@osandov.com> (raw)

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


             reply	other threads:[~2015-04-08  5:34 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-08  5:33 Omar Sandoval [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover.1428471096.git.osandov@osandov.com \
    --to=osandov@osandov.com \
    --cc=clm@fb.com \
    --cc=dsterba@suse.cz \
    --cc=jbacik@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.