Skip to content

Commit 3d34529

Browse files
asjgregkh
authored andcommitted
btrfs: don't traverse into the seed devices in show_devname
commit 4faf55b upstream. ->show_devname currently shows the lowest devid in the list. As the seed devices have the lowest devid in the sprouted filesystem, the userland tool such as findmnt end up seeing seed device instead of the device from the read-writable sprouted filesystem. As shown below. mount /dev/sda /btrfs mount: /btrfs: WARNING: device write-protected, mounted read-only. findmnt --output SOURCE,TARGET,UUID /btrfs SOURCE TARGET UUID /dev/sda /btrfs 899f7027-3e46-4626-93e7-7d4c9ad19111 btrfs dev add -f /dev/sdb /btrfs umount /btrfs mount /dev/sdb /btrfs findmnt --output SOURCE,TARGET,UUID /btrfs SOURCE TARGET UUID /dev/sda /btrfs 899f7027-3e46-4626-93e7-7d4c9ad19111 All sprouts from a single seed will show the same seed device and the same fsid. That's confusing. This is causing problems in our prototype as there isn't any reference to the sprout file-system(s) which is being used for actual read and write. This was added in the patch which implemented the show_devname in btrfs commit 9c5085c ("Btrfs: implement ->show_devname"). I tried to look for any particular reason that we need to show the seed device, there isn't any. So instead, do not traverse through the seed devices, just show the lowest devid in the sprouted fsid. After the patch: mount /dev/sda /btrfs mount: /btrfs: WARNING: device write-protected, mounted read-only. findmnt --output SOURCE,TARGET,UUID /btrfs SOURCE TARGET UUID /dev/sda /btrfs 899f7027-3e46-4626-93e7-7d4c9ad19111 btrfs dev add -f /dev/sdb /btrfs mount -o rw,remount /dev/sdb /btrfs findmnt --output SOURCE,TARGET,UUID /btrfs SOURCE TARGET UUID /dev/sdb /btrfs 595ca0e6-b82e-46b5-b9e2-c72a6928be48 mount /dev/sda /btrfs1 mount: /btrfs1: WARNING: device write-protected, mounted read-only. btrfs dev add -f /dev/sdc /btrfs1 findmnt --output SOURCE,TARGET,UUID /btrfs1 SOURCE TARGET UUID /dev/sdc /btrfs1 ca1dbb7a-8446-4f95-853c-a20f3f82bdbb cat /proc/self/mounts | grep btrfs /dev/sdb /btrfs btrfs rw,relatime,noacl,space_cache,subvolid=5,subvol=/ 0 0 /dev/sdc /btrfs1 btrfs ro,relatime,noacl,space_cache,subvolid=5,subvol=/ 0 0 Reported-by: Martin K. Petersen <[email protected]> CC: [email protected] # 4.19+ Tested-by: Martin K. Petersen <[email protected]> Signed-off-by: Anand Jain <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 8bc3a5d commit 3d34529

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

fs/btrfs/super.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,9 +2254,7 @@ static int btrfs_unfreeze(struct super_block *sb)
22542254
static int btrfs_show_devname(struct seq_file *m, struct dentry *root)
22552255
{
22562256
struct btrfs_fs_info *fs_info = btrfs_sb(root->d_sb);
2257-
struct btrfs_fs_devices *cur_devices;
22582257
struct btrfs_device *dev, *first_dev = NULL;
2259-
struct list_head *head;
22602258

22612259
/*
22622260
* Lightweight locking of the devices. We should not need
@@ -2266,18 +2264,13 @@ static int btrfs_show_devname(struct seq_file *m, struct dentry *root)
22662264
* least until the rcu_read_unlock.
22672265
*/
22682266
rcu_read_lock();
2269-
cur_devices = fs_info->fs_devices;
2270-
while (cur_devices) {
2271-
head = &cur_devices->devices;
2272-
list_for_each_entry_rcu(dev, head, dev_list) {
2273-
if (test_bit(BTRFS_DEV_STATE_MISSING, &dev->dev_state))
2274-
continue;
2275-
if (!dev->name)
2276-
continue;
2277-
if (!first_dev || dev->devid < first_dev->devid)
2278-
first_dev = dev;
2279-
}
2280-
cur_devices = cur_devices->seed;
2267+
list_for_each_entry_rcu(dev, &fs_info->fs_devices->devices, dev_list) {
2268+
if (test_bit(BTRFS_DEV_STATE_MISSING, &dev->dev_state))
2269+
continue;
2270+
if (!dev->name)
2271+
continue;
2272+
if (!first_dev || dev->devid < first_dev->devid)
2273+
first_dev = dev;
22812274
}
22822275

22832276
if (first_dev)

0 commit comments

Comments
 (0)