backport test case btrfs/216 fixes
Subsystems (2)
cover backport test case btrfs/216 fixes
In an attempt to make all the fstests test cases pass on stable-5.15.y, backport fixes for the test case btrfs/216.
Anand Jain (4):
btrfs: convert latest_bdev type to btrfs_device and rename
btrfs: use latest_dev in btrfs_show_devname
btrfs: update latest_dev when we create a sprout device
btrfs: remove stale comment about the btrfs_show_devname
fs/btrfs/disk-io.c | 6 +++--- fs/btrfs/extent_io.c | 2 +- fs/btrfs/inode.c | 2 +- fs/btrfs/super.c | 26 ++++++-------------------- fs/btrfs/volumes.c | 19 +++++++------------ fs/btrfs/volumes.h | 6 +++++- 6 files changed, 23 insertions(+), 38 deletions(-)
Signature · 1 line
2.33.1
PATCH 1/4 btrfs: convert latest_bdev type to btrfs_device and rename
Commit d24fa5c1da08026be9959baca309fa0adf8708bf upstream.
In preparation to fix a bug in btrfs_show_devname().
Convert fs_devices::latest_bdev type from struct block_device to struct btrfs_device and, rename the member to fs_devices::latest_dev. So that btrfs_show_devname() can use fs_devices::latest_dev::name.
--- fs/btrfs/disk-io.c | 6 +++--- fs/btrfs/extent_io.c | 2 +- fs/btrfs/inode.c | 2 +- fs/btrfs/super.c | 2 +- fs/btrfs/volumes.c | 10 +++++----- fs/btrfs/volumes.h | 6 +++++- 6 files changed, 16 insertions(+), 12 deletions(-)
fs/btrfs/disk-io.c +3 -3
@@ -3229,12 +3229,12 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_devicemapping_set_gfp_mask (fs_info->btree_inode->i_mapping,GFP_NOFS );btrfs_init_btree_inode (fs_info); -invalidate_bdev (fs_devices->latest_bdev); +invalidate_bdev (fs_devices->latest_dev->bdev);/* * Read super block and check the signature bytes only */ - disk_super =btrfs_read_dev_super (fs_devices->latest_bdev); + disk_super =btrfs_read_dev_super (fs_devices->latest_dev->bdev);if (IS_ERR (disk_super)) { err =PTR_ERR (disk_super); goto fail_alloc;
@@ -3466,7 +3466,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device* below in btrfs_init_dev_replace(). */ btrfs_free_extra_devids (fs_devices); -if (!fs_devices->latest_bdev) { +if (!fs_devices->latest_dev->bdev) {btrfs_err (fs_info,"failed to read devices" ); goto fail_tree_roots; }
fs/btrfs/extent_io.c +1 -1
@@ -3327,7 +3327,7 @@ static int alloc_new_bio(struct btrfs_inode *inode,if (wbc) {struct block_device *bdev; - bdev = fs_info->fs_devices->latest_bdev; + bdev = fs_info->fs_devices->latest_dev->bdev;bio_set_dev (bio, bdev);wbc_init_bio (wbc, bio); }
fs/btrfs/inode.c +1 -1
@@ -7967,7 +7967,7 @@ static int btrfs_dio_iomap_begin(struct inode *inode, loff_t start, iomap->type =IOMAP_MAPPED ; } iomap->offset = start; - iomap->bdev = fs_info->fs_devices->latest_bdev; + iomap->bdev = fs_info->fs_devices->latest_dev->bdev; iomap->length = len;if (write &&btrfs_use_zone_append (BTRFS_I (inode), em->block_start))
fs/btrfs/super.c +1 -1
@@ -1705,7 +1705,7 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type, goto error_close_devices; } - bdev = fs_devices->latest_bdev; + bdev = fs_devices->latest_dev->bdev; s =sget (fs_type, btrfs_test_super, btrfs_set_super, flags |SB_NOSEC , fs_info);if (IS_ERR (s)) {
fs/btrfs/volumes.c +5 -5
@@ -1092,7 +1092,7 @@ void btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices)list_for_each_entry (seed_dev, &fs_devices->seed_list, seed_list)__btrfs_free_extra_devids (seed_dev, &latest_dev); - fs_devices->latest_bdev = latest_dev->bdev; + fs_devices->latest_dev = latest_dev;mutex_unlock (&uuid_mutex); }
@@ -1225,7 +1225,7 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices,return -EINVAL ; fs_devices->opened =1 ; - fs_devices->latest_bdev = latest_dev->bdev; + fs_devices->latest_dev = latest_dev; fs_devices->total_rw_bytes =0 ; fs_devices->chunk_alloc_policy =BTRFS_CHUNK_ALLOC_REGULAR ; fs_devices->read_policy =BTRFS_READ_POLICY_PID ;
@@ -1993,7 +1993,7 @@ static struct btrfs_device * btrfs_find_next_active_device( }/* -* Helper function to check if the given device is part of s_bdev / latest_bdev +* Helper function to check if the given device is part of s_bdev / latest_dev * and replace it with the provided or the next active device, in the context * where this function called, there should be always be another device (or * this_dev) which is active.
@@ -2012,8 +2012,8 @@ void __cold btrfs_assign_next_active_device(struct btrfs_device *device, (fs_info->sb->s_bdev == device->bdev)) fs_info->sb->s_bdev = next_device->bdev; -if (fs_info->fs_devices->latest_bdev == device->bdev) - fs_info->fs_devices->latest_bdev = next_device->bdev; +if (fs_info->fs_devices->latest_dev->bdev == device->bdev) + fs_info->fs_devices->latest_dev = next_device; }/*
fs/btrfs/volumes.h +5 -1
@@ -246,7 +246,11 @@ struct btrfs_fs_devices {/* Highest generation number of seen devices */ u64 latest_generation; -struct block_device *latest_bdev; +/* +* The mount device or a device with highest generation after removal +* or replace. +*/ +struct btrfs_device *latest_dev;/* all of the devices in the FS, protected by a mutex * so we can safely walk it to write out the supers without
Signature · 1 line
2.33.1
PATCH 2/4 btrfs: use latest_dev in btrfs_show_devname
In reply to Anand JainCommit 6605fd2f394bba0a0059df2b6cfc87b0b6d393a2 upstream.
The test case btrfs/238 reports the warning below:
WARNING: CPU: 3 PID: 481 at fs/btrfs/super.c:2509 btrfs_show_devname+0x104/0x1e8 [btrfs] CPU: 2 PID: 1 Comm: systemd Tainted: G W O 5.14.0-rc1-custom #72 Hardware name: QEMU QEMU Virtual Machine, BIOS 0.0.0 02/06/2015 Call trace: btrfs_show_devname+0x108/0x1b4 [btrfs] show_mountinfo+0x234/0x2c4 m_show+0x28/0x34 seq_read_iter+0x12c/0x3c4 vfs_read+0x29c/0x2c8 ksys_read+0x80/0xec __arm64_sys_read+0x28/0x34 invoke_syscall+0x50/0xf8 do_el0_svc+0x88/0x138 el0_svc+0x2c/0x8c el0t_64_sync_handler+0x84/0xe4 el0t_64_sync+0x198/0x19c
Reason:
While btrfs_prepare_sprout() moves the fs_devices::devices into fs_devices::seed_list, the btrfs_show_devname() searches for the devices and found none, leading to the warning as in above.
Fix:latest_dev is updated according to the changes to the device list. That means we could use the latest_dev->name to show the device name in /proc/self/mounts, the pointer will be always valid as it's assigned before the device is deleted from the list in remove or replace. The RCU protection is sufficient as the device structure is freed after synchronization.
--- fs/btrfs/super.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-)
fs/btrfs/super.c +5 -19
@@ -2463,30 +2463,16 @@ 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_device *dev, *first_dev =NULL ;/* -* Lightweight locking of the devices. We should not need -* device_list_mutex here as we only read the device data and the list -* is protected by RCU. Even if a device is deleted during the list -* traversals, we'll get valid data, the freeing callback will wait at -* least until the rcu_read_unlock. +* There should be always a valid pointer in latest_dev, it may be stale +* for a short moment in case it's being deleted but still valid until +* the end of RCU grace period. */ rcu_read_lock (); -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) -seq_escape (m,rcu_str_deref (first_dev->name)," \t\n\\" ); -else -WARN_ON (1 ); +seq_escape (m,rcu_str_deref (fs_info->fs_devices->latest_dev->name)," \t\n\\" );rcu_read_unlock (); +return 0 ; }
Signature · 1 line
2.33.1
PATCH 3/4 btrfs: update latest_dev when we create a sprout device
In reply to Anand JainCommit b7cb29e666fe79dda5dbe5f57fb7c92413bf161c upstream.
When we add a device to the seed filesystem (sprouting) it is a new filesystem (and fsid) on the device added. Update the latest_dev so that /proc/self/mounts shows the correct device.
Example:
$ btrfstune -S1 /dev/vg/seed $ mount /dev/vg/seed /btrfs mount: /btrfs: WARNING: device write-protected, mounted read-only.
$ cat /proc/self/mounts | grep btrfs /dev/mapper/vg-seed /btrfs btrfs ro,relatime,space_cache,subvolid=5,subvol=/ 0 0
$ btrfs dev add -f /dev/vg/new /btrfs
Before:
$ cat /proc/self/mounts | grep btrfs /dev/mapper/vg-seed /btrfs btrfs ro,relatime,space_cache,subvolid=5,subvol=/ 0 0
After:
$ cat /proc/self/mounts | grep btrfs /dev/mapper/vg-new /btrfs btrfs ro,relatime,space_cache,subvolid=5,subvol=/ 0 0
--- fs/btrfs/volumes.c | 2 ++ 1 file changed, 2 insertions(+)
fs/btrfs/volumes.c +2 -0
@@ -2634,6 +2634,8 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathbtrfs_abort_transaction (trans, ret); goto error_trans; } +btrfs_assign_next_active_device (fs_info->fs_devices->latest_dev, + device); } device->fs_devices = fs_devices;
Signature · 1 line
2.33.1
PATCH 4/4 btrfs: remove stale comment about the btrfs_show_devname
In reply to Anand JainCommit cdccc03a8a369b59cff5e7ea3292511cfa551120 upstream.
There were few lockdep warnings because btrfs_show_devname() was using device_list_mutex as recorded in the commits:
0ccd05285e7f ("btrfs: fix a possible umount deadlock")
779bf3fefa83 ("btrfs: fix lock dep warning, move scratch dev out of device_list_mutex and uuid_mutex")
And finally, commit 88c14590cdd6 ("btrfs: use RCU in btrfs_show_devname for device list traversal") removed the device_list_mutex from btrfs_show_devname for performance reasons.
This patch removes a stale comment about the function btrfs_show_devname and device_list_mutex.
--- fs/btrfs/volumes.c | 7 ------- 1 file changed, 7 deletions(-)
fs/btrfs/volumes.c +0 -7
@@ -2312,13 +2312,6 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_device *tgtdev)mutex_unlock (&fs_devices->device_list_mutex); -/* -* The update_dev_time() with in btrfs_scratch_superblocks() -* may lead to a call to btrfs_show_devname() which will try -* to hold device_list_mutex. And here this device -* is already out of device list, so we don't have to hold -* the device_list_mutex lock. -*/ btrfs_scratch_superblocks (tgtdev->fs_info, tgtdev->bdev, tgtdev->name->str);
Signature · 1 line
2.33.1
Oops, the wrong email id used. Please ignore.
Thanks, Anand
Quoted 9 lines · Anand Jain
In an attempt to make all the fstests test cases pass on stable-5.15.y, backport fixes for the test case btrfs/216.
Anand Jain (4):
btrfs: convertlatest_bdevtype tobtrfs_deviceand rename
btrfs: uselatest_devinbtrfs_show_devname
btrfs: updatelatest_devwhen we create a sprout device
btrfs: remove stale comment about thebtrfs_show_devname
Quoted 11 lines
fs/btrfs/disk-io.c | 6 +++--- fs/btrfs/extent_io.c | 2 +- fs/btrfs/inode.c | 2 +- fs/btrfs/super.c | 26 ++++++-------------------- fs/btrfs/volumes.c | 19 +++++++------------ fs/btrfs/volumes.h | 6 +++++- 6 files changed, 23 insertions(+), 38 deletions(-)Signature · 1 line
2.33.1
Now queued up, thanks.
greg k-h