From acdd22ab683c1a2dcbb188d63c19dc434e896019 Mon Sep 17 00:00:00 2001 From: Naohiro Aota Date: Mon, 26 Apr 2021 15:27:18 +0900 Subject: [PATCH] btrfs-progs: provide fs_info from btrfs_device Likewise in the kernel code, provide fs_info access from struct btrfs_device. This will help to unify the code between the kernel and the userland. Since fs_info can be NULL at the time of btrfs_add_to_fsid(), let's use btrfs_open_devices() to set fs_info to the devices. Signed-off-by: Naohiro Aota Signed-off-by: David Sterba --- cmds/rescue-chunk-recover.c | 2 +- common/device-scan.c | 1 + kernel-shared/disk-io.c | 2 +- kernel-shared/volumes.c | 8 ++++++-- kernel-shared/volumes.h | 5 +++-- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cmds/rescue-chunk-recover.c b/cmds/rescue-chunk-recover.c index d7e479be..7eb64c2b 100644 --- a/cmds/rescue-chunk-recover.c +++ b/cmds/rescue-chunk-recover.c @@ -1446,7 +1446,7 @@ open_ctree_with_broken_chunk(struct recover_control *rc) fs_info->is_chunk_recover = 1; fs_info->fs_devices = rc->fs_devices; - ret = btrfs_open_devices(fs_info->fs_devices, O_RDWR); + ret = btrfs_open_devices(fs_info, fs_info->fs_devices, O_RDWR); if (ret) goto out; diff --git a/common/device-scan.c b/common/device-scan.c index cd4c1282..01d2e065 100644 --- a/common/device-scan.c +++ b/common/device-scan.c @@ -141,6 +141,7 @@ int btrfs_add_to_fsid(struct btrfs_trans_handle *trans, dev_item = &disk_super->dev_item; uuid_generate(device->uuid); + device->fs_info = fs_info; device->devid = 0; device->type = 0; device->io_width = io_width; diff --git a/kernel-shared/disk-io.c b/kernel-shared/disk-io.c index 0c061954..2c1cd516 100644 --- a/kernel-shared/disk-io.c +++ b/kernel-shared/disk-io.c @@ -1270,7 +1270,7 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, struct open_ctree_flags *oc if (flags & OPEN_CTREE_EXCLUSIVE) oflags |= O_EXCL; - ret = btrfs_open_devices(fs_devices, oflags); + ret = btrfs_open_devices(fs_info, fs_devices, oflags); if (ret) goto out; diff --git a/kernel-shared/volumes.c b/kernel-shared/volumes.c index c2068603..d4bd3cdf 100644 --- a/kernel-shared/volumes.c +++ b/kernel-shared/volumes.c @@ -389,13 +389,17 @@ void btrfs_close_all_devices(void) } } -int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, int flags) +int btrfs_open_devices(struct btrfs_fs_info *fs_info, + struct btrfs_fs_devices *fs_devices, int flags) { int fd; struct btrfs_device *device; int ret; list_for_each_entry(device, &fs_devices->devices, dev_list) { + if (!device->fs_info) + device->fs_info = fs_info; + if (!device->name) { printk("no name for device %llu, skip it now\n", device->devid); continue; @@ -2106,7 +2110,7 @@ static int open_seed_devices(struct btrfs_fs_info *fs_info, u8 *fsid) memcpy(fs_devices->fsid, fsid, BTRFS_FSID_SIZE); } - ret = btrfs_open_devices(fs_devices, O_RDONLY); + ret = btrfs_open_devices(fs_info, fs_devices, O_RDONLY); if (ret) goto out; diff --git a/kernel-shared/volumes.h b/kernel-shared/volumes.h index e1d7918d..faaa285d 100644 --- a/kernel-shared/volumes.h +++ b/kernel-shared/volumes.h @@ -28,6 +28,7 @@ struct btrfs_device { struct list_head dev_list; struct btrfs_root *dev_root; struct btrfs_fs_devices *fs_devices; + struct btrfs_fs_info *fs_info; u64 total_ios; @@ -282,8 +283,8 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, u64 *num_bytes, u64 type); int btrfs_alloc_data_chunk(struct btrfs_trans_handle *trans, struct btrfs_fs_info *fs_info, u64 *start, u64 num_bytes); -int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, - int flags); +int btrfs_open_devices(struct btrfs_fs_info *fs_info, + struct btrfs_fs_devices *fs_devices, int flags); int btrfs_close_devices(struct btrfs_fs_devices *fs_devices); void btrfs_close_all_devices(void); int btrfs_insert_dev_extent(struct btrfs_trans_handle *trans,