Skip to contentSkip to conversation

btrfs_show_devname don't traverse into the seed fsid

PATCH In review Anand Jain 6 participants 13 messages Jul 10, 2020 – Jul 20, 2020 Btrfs file system

lore
Share & tools
lore

Anand Jain

author
#0 lore raw

PATCH 1/1 btrfs_show_devname don't traverse into the seed fsid

->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 messy.
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 9c5085c14798 (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

---
This has passed the xfstests/btrfs sucessfully with no new regressions. Thanks.

 fs/btrfs/super.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)
fs/btrfs/super.c +7 -14
index c7ee119cffa1..1e2a36f5c792 100644
@@ -2377,9 +2377,7 @@ static int btrfs_unfreeze(struct super_block *sb)
 static int btrfs_show_devname(struct seq_file *m, struct dentry *root)
 {
 	struct btrfs_fs_info *fs_info = btrfs_sb(root->d_sb);
-	struct btrfs_fs_devices *cur_devices;
 	struct btrfs_device *dev, *first_dev = NULL;
-	struct list_head *head;
 
 	/*
 	 * Lightweight locking of the devices. We should not need
@@ -2389,18 +2387,13 @@ static int btrfs_show_devname(struct seq_file *m, struct dentry *root)
 	 * least until the rcu_read_unlock.
 	 */
 	rcu_read_lock();
-	cur_devices = fs_info->fs_devices;
-	while (cur_devices) {
-		head = &cur_devices->devices;
-		list_for_each_entry_rcu(dev, head, dev_list) {
-			if (test_bit(BTRFS_DEV_STATE_MISSING, &dev->dev_state))
-				continue;
-			if (!dev->name)
-				continue;
-			if (!first_dev || dev->devid < first_dev->devid)
-				first_dev = dev;
-		}
-		cur_devices = cur_devices->seed;
+	list_for_each_entry_rcu(dev, &fs_info->fs_devices->devices, dev_list) {
+		if (test_bit(BTRFS_DEV_STATE_MISSING, &dev->dev_state))
+			continue;
+		if (!dev->name)
+			continue;
+		if (!first_dev || dev->devid < first_dev->devid)
+			first_dev = dev;
 	}
 
 	if (first_dev)
Signature · 1 line
2.25.1
#1 lore raw
Quoted 61 lines · Anand Jain

->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 messy.
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 9c5085c14798 (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
Quoted 5 lines

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

This needs to come with an xfstest so we do not regress this in the future. Thanks,

Josef

author
#2 lore raw
Quoted 3 lines

This needs to come with an xfstest so we do not regress this in the future.  Thanks,

Oh yes. Makes sense. An xfstests test case is on its way.

Thanks, Anand

Quoted 2 lines

Josef

author
#4 lore raw

PATCH 1/1 fstests: btrfs test if show_devname returns sprout device

In reply to Anand Jain

Test if the show_devname() returns sprout device instead of seed device.

---
 tests/btrfs/215     | 59 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/215.out |  2 ++
 tests/btrfs/group   |  1 +
 3 files changed, 62 insertions(+)
 create mode 100755 tests/btrfs/215
 create mode 100644 tests/btrfs/215.out
tests/btrfs/215 new file +59 -0
new file mode 100755
index 000000000000..19eb68437567
@@ -0,0 +1,59 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 Oracle.  All Rights Reserved.
+#
+# FS QA Test 215
+#
+# Test if the show_devname() returns sprout device instead of seed device.
+#
+# Requires kernel patch:
+#   btrfs: btrfs_show_devname don't traverse into the seed fsid
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1	# failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+	cd /
+	rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+_supported_fs btrfs
+_supported_os Linux
+_require_scratch_dev_pool 2
+
+_scratch_dev_pool_get 2
+
+seed=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
+sprout=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
+
+_mkfs_dev $seed
+$BTRFS_TUNE_PROG -S 1 $seed
+_mount $seed $SCRATCH_MNT >> $seqres.full 2>&1
+cat /proc/self/mounts | grep $seed >> $seqres.full
+$BTRFS_UTIL_PROG device add -f $sprout $SCRATCH_MNT
+cat /proc/self/mounts | grep $sprout >> $seqres.full
+
+#must fail
+cat /proc/self/mounts | grep $seed
+
+_scratch_dev_pool_put
+
+echo "Silence is golden"
+# success, all done
+status=0
+exit
tests/btrfs/215.out new file +2 -0
new file mode 100644
index 000000000000..0a11773bbb32
@@ -0,0 +1,2 @@
+QA output created by 215
+Silence is golden
tests/btrfs/group +1 -0
index 505665b54d61..76c8b78d08f9 100644
@@ -217,3 +217,4 @@
 212 auto balance dangerous
 213 auto balance dangerous
 214 auto quick send snapshot
+215 auto quick seed
Signature · 1 line
2.25.1
#5 lore raw

Re: [PATCH] fstests: btrfs test if show_devname returns sprout device

Quoted 59 lines · Anand Jain

Test if the show_devname() returns sprout device instead of seed device.

---
 tests/btrfs/215     | 59 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/215.out |  2 ++
 tests/btrfs/group   |  1 +
 3 files changed, 62 insertions(+)
 create mode 100755 tests/btrfs/215
 create mode 100644 tests/btrfs/215.out
tests/btrfs/215 new file +42 -0
new file mode 100755
index 000000000000..19eb68437567
@@ -0,0 +1,59 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 Oracle.  All Rights Reserved.
+#
+# FS QA Test 215
+#
+# Test if the show_devname() returns sprout device instead of seed device.
+#
+# Requires kernel patch:
+#   btrfs: btrfs_show_devname don't traverse into the seed fsid
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1	# failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+	cd /
+	rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+_supported_fs btrfs
+_supported_os Linux
+_require_scratch_dev_pool 2
+
+_scratch_dev_pool_get 2
+
+seed=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
+sprout=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')

tests/btrfs/215 line 52

Quoted 10 lines
tests/btrfs/215 new file +10 -0
+
+_mkfs_dev $seed
+$BTRFS_TUNE_PROG -S 1 $seed
+_mount $seed $SCRATCH_MNT >> $seqres.full 2>&1
+cat /proc/self/mounts | grep $seed >> $seqres.full
+$BTRFS_UTIL_PROG device add -f $sprout $SCRATCH_MNT
+cat /proc/self/mounts | grep $sprout >> $seqres.full
+
+#must fail
+cat /proc/self/mounts | grep $seed

Checking for presence of specific sprout device will make the test more robust rather than checking for the absence of the seed device.

Quoted 25 lines
tests/btrfs/215 new file +7 -0
+
+_scratch_dev_pool_put
+
+echo "Silence is golden"
+# success, all done
+status=0
+exit
tests/btrfs/215.out new file +2 -0
new file mode 100644
index 000000000000..0a11773bbb32
@@ -0,0 +1,2 @@
+QA output created by 215
+Silence is golden
tests/btrfs/group +1 -0
index 505665b54d61..76c8b78d08f9 100644
@@ -217,3 +217,4 @@
 212 auto balance dangerous
 213 auto balance dangerous
 214 auto quick send snapshot
+215 auto quick seed
author
#6 lore raw

PATCH v2 1/1 fstests: btrfs test if show_devname returns sprout device

Test if the show_devname() returns sprout device instead of seed device.

---
v2: check for presence of needed sprout device.

 common/filter       |  8 ++++++
 tests/btrfs/215     | 59 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/215.out |  2 ++
 tests/btrfs/group   |  1 +
 4 files changed, 70 insertions(+)
 create mode 100755 tests/btrfs/215
 create mode 100644 tests/btrfs/215.out
common/filter +8 -0
index 2477f3860151..992783aba187 100644
@@ -284,6 +284,14 @@ _filter_test_dir()
 	    -e "s,\B$TEST_DEV,TEST_DEV,g"
 }
 
+_filter_devs()
+{
+	local filter_devs
+
+	filter_devs=$(echo $1 | sed -e 's/\s\+/\\\|/g')
+	sed -e "s,$filter_devs,SCRATCH_DEV,g"
+}
+
 _filter_scratch()
 {
 	# SCRATCH_DEV may be a prefix of SCRATCH_MNT (e.g. /mnt, /mnt/ovl-mnt)
tests/btrfs/215 new file +59 -0

59 lines not on this page · raw message

tests/btrfs/215.out new file +2 -0
new file mode 100644
index 000000000000..ed3207851653
@@ -0,0 +1,2 @@
+QA output created by 215
+SCRATCH_DEV
tests/btrfs/group +1 -0
index 505665b54d61..76c8b78d08f9 100644
@@ -217,3 +217,4 @@
 212 auto balance dangerous
 213 auto balance dangerous
 214 auto quick send snapshot
+215 auto quick seed
Signature · 1 line
2.25.1
#7 lore raw

Re: [PATCH v2] fstests: btrfs test if show_devname returns sprout device

Quoted 82 lines · Anand Jain

Test if the show_devname() returns sprout device instead of seed device.

---
v2: check for presence of needed sprout device.

 common/filter       |  8 ++++++
 tests/btrfs/215     | 59 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/215.out |  2 ++
 tests/btrfs/group   |  1 +
 4 files changed, 70 insertions(+)
 create mode 100755 tests/btrfs/215
 create mode 100644 tests/btrfs/215.out
common/filter +8 -0
index 2477f3860151..992783aba187 100644
@@ -284,6 +284,14 @@ _filter_test_dir()
 	    -e "s,\B$TEST_DEV,TEST_DEV,g"
 }
 
+_filter_devs()
+{
+	local filter_devs
+
+	filter_devs=$(echo $1 | sed -e 's/\s\+/\\\|/g')
+	sed -e "s,$filter_devs,SCRATCH_DEV,g"
+}
+
 _filter_scratch()
 {
 	# SCRATCH_DEV may be a prefix of SCRATCH_MNT (e.g. /mnt, /mnt/ovl-mnt)
tests/btrfs/215 new file +43 -0
new file mode 100755
index 000000000000..cf5e360d14b1
@@ -0,0 +1,59 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 Oracle.  All Rights Reserved.
+#
+# FS QA Test 215
+#
+# Test if the show_devname() returns sprout device instead of seed device.
+#
+# Fixed in kernel patch:
+#   btrfs: btrfs_show_devname don't traverse into the seed fsid
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1	# failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+	cd /
+	rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+_supported_fs btrfs
+_supported_os Linux
+_require_scratch_dev_pool 2
+
+_scratch_dev_pool_get 2
+
+seed=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
+sprout=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
+

tests/btrfs/215 line 53

Quoted 10 lines
tests/btrfs/215 new file +10 -0
+_mkfs_dev $seed
+$BTRFS_TUNE_PROG -S 1 $seed
+_mount $seed $SCRATCH_MNT >> $seqres.full 2>&1
+cat /proc/self/mounts | grep $seed >> $seqres.full
+$BTRFS_UTIL_PROG device add -f $sprout $SCRATCH_MNT
+cat /proc/self/mounts | grep $sprout >> $seqres.full
+
+# check if the show_devname() returns the sprout device instead of seed device.
+cat /proc/self/mounts | grep $SCRATCH_MNT | awk '{print $1}' | \
+							_filter_devs $sprout

Why does this have to be so complicated - 4 chained program executions, 1 additional function...

dev=$(grep $SCRATCH_MOUNT /proc/mounts | awk '{printf $1}')

if [ $sprout != $dev ]; then
_fail "Unexpected device"
fi

Quoted 24 lines
tests/btrfs/215 new file +6 -0
+
+_scratch_dev_pool_put
+
+# success, all done
+status=0
+exit
tests/btrfs/215.out new file +2 -0
new file mode 100644
index 000000000000..ed3207851653
@@ -0,0 +1,2 @@
+QA output created by 215
+SCRATCH_DEV
tests/btrfs/group +1 -0
index 505665b54d61..76c8b78d08f9 100644
@@ -217,3 +217,4 @@
 212 auto balance dangerous
 213 auto balance dangerous
 214 auto quick send snapshot
+215 auto quick seed
author
#8 lore raw

Re: [PATCH v2] fstests: btrfs test if show_devname returns sprout device

Quoted 10 lines

tests/btrfs/215 line 53

Quoted 6 lines
tests/btrfs/215 new file +3 -0
+# check if the show_devname() returns the sprout device instead of seed device.
+cat /proc/self/mounts | grep $SCRATCH_MNT | awk '{print $1}' | \
+							_filter_devs $sprout

Why does this have to be so complicated - 4 chained program executions, 1 additional function...

For example:
/dev/sdb /btrfs btrfs
ro,relatime,noacl,space_cache,subvolid=5,subvol=/ 0 0

$1 to $3 remain constant, but $4 options might vary. So to avoid unnecessary breakage of test case due to kernel updates or mount options, I just used $1.

Quoted 5 lines

dev=$(grep $SCRATCH_MOUNT /proc/mounts | awk '{printf $1}')

if [ $sprout != $dev ]; then
_fail "Unexpected device"
fi

fstests prefers use of .out file to look for the expected string. Will wait for Eryu comments.

Thanks, Anand

#9 lore raw

Re: [PATCH v2] fstests: btrfs test if show_devname returns sprout device

Quoted 11 lines · Anand Jain
Quoted 10 lines

tests/btrfs/215 line 53

Quoted 6 lines
tests/btrfs/215 new file +3 -0
+# check if the show_devname() returns the sprout device instead of seed device.
+cat /proc/self/mounts | grep $SCRATCH_MNT | awk '{print $1}' | \
+							_filter_devs $sprout

Why does this have to be so complicated - 4 chained program executions, 1 additional function...

Quoted 8 lines

For example:
/dev/sdb /btrfs btrfs ro,relatime,noacl,space_cache,subvolid=5,subvol=/ 0 0

$1 to $3 remain constant, but $4 options might vary. So to avoid unnecessary breakage of test case due to kernel updates or mount options, I just used $1.

Quoted 1 line

dev=$(grep $SCRATCH_MOUNT /proc/mounts | awk '{printf $1}')

This looks simpler, just use $AWK_PROG instead of bare awk.

Quoted 6 lines
Quoted 4 lines

if [ $sprout != $dev ]; then
_fail "Unexpected device"
fi

fstests prefers use of .out file to look for the expected string. Will wait for Eryu comments.

Even $dev is not constant, we don't have to filter the device to "SCRATCH_DEV" by _filter_devs. Just do

echo "Silence is golden"
if [ "$sprout" != "$dev" ]; then
echo "Unexpected device: $dev"
fi

Thanks,
Eryu

author
#10 lore raw

PATCH v3 1/1 fstests: btrfs test if show_devname returns sprout device

Test if the show_devname() returns sprout device instead of seed device.

---
v2: check for presence of needed sprout device.
v3: check for not presence of needed sprout device and break the silence.

 tests/btrfs/215     | 63 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/215.out |  2 ++
 tests/btrfs/group   |  1 +
 3 files changed, 66 insertions(+)
 create mode 100755 tests/btrfs/215
 create mode 100644 tests/btrfs/215.out
tests/btrfs/215 new file +63 -0
new file mode 100755
index 000000000000..5be6d0f60192
@@ -0,0 +1,63 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 Oracle.  All Rights Reserved.
+#
+# FS QA Test 215
+#
+# Test if the show_devname() returns sprout device instead of seed device.
+#
+# Fixed in kernel patch:
+#   btrfs: btrfs_show_devname don't traverse into the seed fsid
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1	# failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+	cd /
+	rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+_supported_fs btrfs
+_supported_os Linux
+_require_scratch_dev_pool 2
+
+_scratch_dev_pool_get 2
+
+seed=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
+sprout=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
+
+_mkfs_dev $seed
+$BTRFS_TUNE_PROG -S 1 $seed
+_mount $seed $SCRATCH_MNT >> $seqres.full 2>&1
+cat /proc/self/mounts | grep $seed >> $seqres.full
+$BTRFS_UTIL_PROG device add -f $sprout $SCRATCH_MNT
+cat /proc/self/mounts | grep $sprout >> $seqres.full
+
+# check if the show_devname() returns the sprout device instead of seed device.
+dev=$(grep $SCRATCH_MNT /proc/self/mounts | $AWK_PROG '{print $1}')
+
+if [ "$sprout" != "$dev" ]; then
+	echo "Unexpected device: $dev"
+fi
+echo "Silence is golden"
+
+_scratch_dev_pool_put
+
+# success, all done
+status=0
+exit
tests/btrfs/215.out new file +2 -0
new file mode 100644
index 000000000000..0a11773bbb32
@@ -0,0 +1,2 @@
+QA output created by 215
+Silence is golden
tests/btrfs/group +1 -0
index 505665b54d61..76c8b78d08f9 100644
@@ -217,3 +217,4 @@
 212 auto balance dangerous
 213 auto balance dangerous
 214 auto quick send snapshot
+215 auto quick seed
Signature · 1 line
2.25.1
Reviewed-by Tested-by on v1 1/1
#11 lore raw
In reply to Anand Jain
Quoted 61 lines · Anand Jain

->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 messy.
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 9c5085c14798 (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

Quoted 5 lines

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

Quoted 48 lines

---
This has passed the xfstests/btrfs sucessfully with no new regressions. Thanks.

 fs/btrfs/super.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)
fs/btrfs/super.c +7 -14
index c7ee119cffa1..1e2a36f5c792 100644
@@ -2377,9 +2377,7 @@ static int btrfs_unfreeze(struct super_block *sb)
 static int btrfs_show_devname(struct seq_file *m, struct dentry *root)
 {
 	struct btrfs_fs_info *fs_info = btrfs_sb(root->d_sb);
-	struct btrfs_fs_devices *cur_devices;
 	struct btrfs_device *dev, *first_dev = NULL;
-	struct list_head *head;
 
 	/*
 	 * Lightweight locking of the devices. We should not need
@@ -2389,18 +2387,13 @@ static int btrfs_show_devname(struct seq_file *m, struct dentry *root)
 	 * least until the rcu_read_unlock.
 	 */
 	rcu_read_lock();
-	cur_devices = fs_info->fs_devices;
-	while (cur_devices) {
-		head = &cur_devices->devices;
-		list_for_each_entry_rcu(dev, head, dev_list) {
-			if (test_bit(BTRFS_DEV_STATE_MISSING, &dev->dev_state))
-				continue;
-			if (!dev->name)
-				continue;
-			if (!first_dev || dev->devid < first_dev->devid)
-				first_dev = dev;
-		}
-		cur_devices = cur_devices->seed;
+	list_for_each_entry_rcu(dev, &fs_info->fs_devices->devices, dev_list) {
+		if (test_bit(BTRFS_DEV_STATE_MISSING, &dev->dev_state))
+			continue;
+		if (!dev->name)
+			continue;
+		if (!first_dev || dev->devid < first_dev->devid)
+			first_dev = dev;
 	}
 
 	if (first_dev)
#12 lore raw
In reply to Anand Jain
Quoted 61 lines · Anand Jain

->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 messy.
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 9c5085c14798 (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

Quoted 5 lines

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

Added to misc-next, thanks.