Fix device count check btrfs_rm_devices() and add comments
PATCH 1/2 btrfs: use num_device to check for the last surviving seed device
In reply to Anand JainFor both sprout and seed fsids,
btrfs_fs_devices::num_devices provides device count including missing btrfs_fs_devices::open_devices provides device count excluding missing
We create a dummy struct btrfs_device for the missing device, so num_devices != open_devices when there is a missing device.
In btrfs_rm_devices() we wrongly check for %cur_devices->open_devices before freeing the seed fs_devices. Instead we should check for %cur_devices->num_devices.
--- fs/btrfs/volumes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/volumes.c +1 -1
@@ -2184,7 +2184,7 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, const char *device_path,synchronize_rcu ();btrfs_free_device (device); -if (cur_devices->open_devices ==0 ) { +if (cur_devices->num_devices ==0 ) {list_del_init (&cur_devices->seed_list);close_fs_devices (cur_devices);free_fs_devices (cur_devices);
Signature · 1 line
2.31.1
cover Fix device count check btrfs_rm_devices() and add comments
Patch 1/2 fixes a bug that we checked open_devices to check if the deleted device was the last surviving device in the seed fsid.
Patch 2/2 adds comments about the device counts in struct btrfs_fs_devices.
Anand Jain (2):
btrfs: use num_device to check for the last surviving seed device
btrfs: add comments for device counts in struct btrfs_fs_devices
fs/btrfs/volumes.c | 2 +- fs/btrfs/volumes.h | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-)
Signature · 1 line
2.31.1
PATCH 2/2 btrfs: add comments for device counts in struct btrfs_fs_devices
A bug was was checking a wrong device count before we delete the struct btrfs_fs_devices in btrfs_rm_device(). To avoid future confusion and easy reference add a comment about the various device counts that we have in the struct btrfs_fs_devices.
--- fs/btrfs/volumes.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
fs/btrfs/volumes.h +19 -0
@@ -236,11 +236,30 @@ struct btrfs_fs_devices {bool fsid_change;struct list_head fs_list; +/* +* Number of devices under this fsid including missing and +* replace-target device and excludes seed devices. +*/ u64 num_devices; + +/* +* The number of devices that successfully opened, including +* replace-target, excludes seed devices. +*/ u64 open_devices; + +/* The number of devices that are under the chunk allocation list. */ u64 rw_devices; + +/* Count of missing devices under this fsid excluding seed device. */ u64 missing_devices;u64 total_rw_bytes; + +/* +* Count of devices from btrfs_super_block::num_devices for this fsid, +* which includes the seed device, excludes the transient replace-target +* device. +*/ u64 total_devices;/* Highest generation number of seen devices */
Signature · 1 line
2.31.1
Re: [PATCH 1/2] btrfs: use num_device to check for the last surviving seed device
In reply to Anand JainQuoted 4 lines · Anand Jain
For both sprout and seed fsids,
btrfs_fs_devices::num_devicesprovides device count including missingbtrfs_fs_devices::open_devicesprovides device count excluding missing
Quoted 8 lines
We create a dummy struct
btrfs_devicefor the missing device, sonum_devices!=open_deviceswhen there is a missing device.In
btrfs_rm_devices()we wrongly check for %cur_devices->open_devices before freeing the seedfs_devices. Instead we should check for %cur_devices->num_devices.Signed-off-by Anand Jain <[email protected]>
Is there a sequence of step that reproduce the problem?
Quoted 18 lines
--- fs/btrfs/volumes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/btrfs/volumes.c +1
-1@@ -2184,7 +2184,7 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, const char *device_path,synchronize_rcu ();btrfs_free_device (device); -if (cur_devices->open_devices ==0 ) { +if (cur_devices->num_devices ==0 ) {list_del_init (&cur_devices->seed_list);close_fs_devices (cur_devices);free_fs_devices (cur_devices);
Re: [PATCH 1/2] btrfs: use num_device to check for the last surviving seed device
Quoted 10 lines · Nikolay Borisov
Quoted 7 lines · Anand Jain
For both sprout and seed fsids,
btrfs_fs_devices::num_devicesprovides device count including missingbtrfs_fs_devices::open_devicesprovides device count excluding missingWe create a dummy struct
btrfs_devicefor the missing device, sonum_devices!=open_deviceswhen there is a missing device.
Quoted 7 lines
Quoted 5 lines
In
btrfs_rm_devices()we wrongly check for %cur_devices->open_devices before freeing the seedfs_devices. Instead we should check for %cur_devices->num_devices.Signed-off-by Anand Jain <[email protected]>Is there a sequence of step that reproduce the problem?
Yeah that would be great, I don't have much idea what actually happens here and what is the bug.
Re: [PATCH 1/2] btrfs: use num_device to check for the last surviving seed device
Quoted 11 lines · David Sterba
Quoted 10 lines · Nikolay Borisov
Quoted 7 lines · Anand Jain
For both sprout and seed fsids,
btrfs_fs_devices::num_devicesprovides device count including missingbtrfs_fs_devices::open_devicesprovides device count excluding missingWe create a dummy struct
btrfs_devicefor the missing device, sonum_devices!=open_deviceswhen there is a missing device.
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
In
btrfs_rm_devices()we wrongly check for %cur_devices->open_devices before freeing the seedfs_devices. Instead we should check for %cur_devices->num_devices.Signed-off-by Anand Jain <[email protected]>Is there a sequence of step that reproduce the problem?
Fundamentally per our design, we should have a struct btrfs_device even for a missing device.
Here is an example where we break that rule after deleting a device in a degraded seed device.
The below example needs boilerplate code here [1], to dump the struct btrfs_fs_devices from the kernel.
---------- cut ------
# Steps
# Create raid1 seed device and degrade it.
# Mount it with -o degraded.
# Add a RW device (sprout).
# Remount it so that it is writable now.
# Still we can't remove the seed device because it is degraded. # So convert the raid1 chunks to single.
# Now remove the seed device (note: missing device is still there). # At this stage the total devices should be 2 (one sprout and another # missing).
DEV1=/dev/vg/scratch0
DEV2=/dev/vg/scratch1
DEV3=/dev/vg/scratch2
local dfilter='fsid:|devid:|missing|total_devices|num_devices|open_devices|device:|MISSING|UUID'
mkfs.btrfs -fq -draid1 -mraid1 $DEV1 $DEV2
mount $DEV1 /btrfs
xfs_io -f -c "pwrite 0 1M" /btrfs/foo
umount /btrfs
btrfstune -S1 $DEV1
wipefs -a $DEV2
btrfs dev scan --forget
mount -o degraded $DEV1 /btrfs
btrfs dev add -f $DEV3 /btrfs
mount -o remount,rw $DEV3 /btrfs
btrfs bal start --force -dconvert=single -mconvert=single /btrfs btrfs dev del $DEV1 /btrfs
# dump btrfs_fs_devices.
cat /proc/fs/btrfs/devlist | egrep '$dfilter'
----------------
Before the patch:
total_devices = 2 but, we see only one device with devid 3.
[fsid: f3bd00d8-7be3-491c-a785-0d207a43b248]
num_devices: 1 open_devices: 1 missing_devices: 0 total_devices: 2 [[UUID: 8c2d2dc6-7c0c-4a02-b63e-109131edd563]] device: /dev/mapper/vg-scratch2 <-- DEV3 devid: 3
After the patch:
total_devices = 2 and, we see both devid 3 and devid 2 (with the missing flag).
[fsid: 8542998a-64e8-4180-bb29-978403beb81c]
num_devices: 1 open_devices: 1 missing_devices: 0 total_devices: 2 [[UUID: b0960a13-f956-4a0b-9ec2-b0da05060ec6]] device: /dev/mapper/vg-scratch2 <-- DEV3 devid: 3 [[seed_fsid: 8dbae94f-f4c2-4875-9a88-b7db7847e740]] sprout_fsid: 8542998a-64e8-4180-bb29-978403beb81c num_devices: 1 open_devices: 0 missing_devices: 1 total_devices: 1 [[UUID: 9ade13a3-8264-4e41-908d-048dae3af370]] device: (null) <-- DEV1 devid: 2 dev_state: |IN_FS_METADATA|MISSING|dev_stats_valid
Thanks, Anand
Ping?
Thanks, Anand
Quoted 12 lines · Anand Jain
Patch 1/2 fixes a bug that we checked
open_devicesto check if the deleted device was the last surviving device in the seed fsid.
Patch 2/2 adds comments about the device counts in structbtrfs_fs_devices.Anand Jain (2):
btrfs: usenum_deviceto check for the last surviving seed device
btrfs: add comments for device counts in structbtrfs_fs_devicesfs/btrfs/volumes.c | 2 +- fs/btrfs/volumes.h | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-)