Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751489AbbDHFef (ORCPT ); Wed, 8 Apr 2015 01:34:35 -0400 Received: from mail-pd0-f172.google.com ([209.85.192.172]:36673 "EHLO mail-pd0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751037AbbDHFec (ORCPT ); Wed, 8 Apr 2015 01:34:32 -0400 From: Omar Sandoval To: Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Omar Sandoval Subject: [PATCH 0/3] Btrfs: show subvolume name and ID in /proc/mounts Date: Tue, 7 Apr 2015 22:33:59 -0700 Message-Id: X-Mailer: git-send-email 2.3.5 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3104 Lines: 111 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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/