btrfs: refactor btrfs_find_device() take fs_devices as argument
authorAnand Jain <anand.jain@oracle.com>
Thu, 17 Jan 2019 15:32:31 +0000 (23:32 +0800)
committerDavid Sterba <dsterba@suse.com>
Mon, 25 Feb 2019 13:13:23 +0000 (14:13 +0100)
btrfs_find_device() accepts fs_info as an argument and retrieves
fs_devices from fs_info.

Instead use fs_devices, so that this function can be used in non-mount
(during device scanning) context as well.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/dev-replace.c
fs/btrfs/ioctl.c
fs/btrfs/scrub.c
fs/btrfs/volumes.c
fs/btrfs/volumes.h

index 8750c835f53548963ad5cad5411cdbfbc3a6817b..6f0fe3623381342cadb32978619ad0ace4a610f4 100644 (file)
@@ -111,9 +111,9 @@ no_valid_dev_replace_entry_found:
                break;
        case BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED:
        case BTRFS_IOCTL_DEV_REPLACE_STATE_SUSPENDED:
                break;
        case BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED:
        case BTRFS_IOCTL_DEV_REPLACE_STATE_SUSPENDED:
-               dev_replace->srcdev = btrfs_find_device(fs_info, src_devid,
-                                                       NULL, NULL);
-               dev_replace->tgtdev = btrfs_find_device(fs_info,
+               dev_replace->srcdev = btrfs_find_device(fs_info->fs_devices,
+                                                       src_devid, NULL, NULL);
+               dev_replace->tgtdev = btrfs_find_device(fs_info->fs_devices,
                                                        BTRFS_DEV_REPLACE_DEVID,
                                                        NULL, NULL);
                /*
                                                        BTRFS_DEV_REPLACE_DEVID,
                                                        NULL, NULL);
                /*
index 72b2b2de62933302979a23d3a752af42a1bca9de..fd5f97aeb35c2c61cc8729070eaeef4135bd9956 100644 (file)
@@ -1642,7 +1642,7 @@ static noinline int btrfs_ioctl_resize(struct file *file,
                btrfs_info(fs_info, "resizing devid %llu", devid);
        }
 
                btrfs_info(fs_info, "resizing devid %llu", devid);
        }
 
-       device = btrfs_find_device(fs_info, devid, NULL, NULL);
+       device = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL);
        if (!device) {
                btrfs_info(fs_info, "resizer unable to find device %llu",
                           devid);
        if (!device) {
                btrfs_info(fs_info, "resizer unable to find device %llu",
                           devid);
@@ -3178,7 +3178,8 @@ static long btrfs_ioctl_dev_info(struct btrfs_fs_info *fs_info,
                s_uuid = di_args->uuid;
 
        rcu_read_lock();
                s_uuid = di_args->uuid;
 
        rcu_read_lock();
-       dev = btrfs_find_device(fs_info, di_args->devid, s_uuid, NULL);
+       dev = btrfs_find_device(fs_info->fs_devices, di_args->devid, s_uuid,
+                               NULL);
 
        if (!dev) {
                ret = -ENODEV;
 
        if (!dev) {
                ret = -ENODEV;
index 6dcd36d7b84906bc4585c861ea7b55659d365fe3..72044efc610ac1df8c55f17d4da60d4cb67efa7a 100644 (file)
@@ -3835,7 +3835,7 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
                return PTR_ERR(sctx);
 
        mutex_lock(&fs_info->fs_devices->device_list_mutex);
                return PTR_ERR(sctx);
 
        mutex_lock(&fs_info->fs_devices->device_list_mutex);
-       dev = btrfs_find_device(fs_info, devid, NULL, NULL);
+       dev = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL);
        if (!dev || (test_bit(BTRFS_DEV_STATE_MISSING, &dev->dev_state) &&
                     !is_dev_replace)) {
                mutex_unlock(&fs_info->fs_devices->device_list_mutex);
        if (!dev || (test_bit(BTRFS_DEV_STATE_MISSING, &dev->dev_state) &&
                     !is_dev_replace)) {
                mutex_unlock(&fs_info->fs_devices->device_list_mutex);
@@ -4012,7 +4012,7 @@ int btrfs_scrub_progress(struct btrfs_fs_info *fs_info, u64 devid,
        struct scrub_ctx *sctx = NULL;
 
        mutex_lock(&fs_info->fs_devices->device_list_mutex);
        struct scrub_ctx *sctx = NULL;
 
        mutex_lock(&fs_info->fs_devices->device_list_mutex);
-       dev = btrfs_find_device(fs_info, devid, NULL, NULL);
+       dev = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL);
        if (dev)
                sctx = dev->scrub_ctx;
        if (sctx)
        if (dev)
                sctx = dev->scrub_ctx;
        if (sctx)
index e4be0f679460a0d6d5b24a9155e7f87201865b10..1bb2a7923fc6a138bdf3cc76cfa7f2e2390907b7 100644 (file)
@@ -2385,11 +2385,11 @@ static struct btrfs_device *btrfs_find_device_by_path(
        devid = btrfs_stack_device_id(&disk_super->dev_item);
        dev_uuid = disk_super->dev_item.uuid;
        if (btrfs_fs_incompat(fs_info, METADATA_UUID))
        devid = btrfs_stack_device_id(&disk_super->dev_item);
        dev_uuid = disk_super->dev_item.uuid;
        if (btrfs_fs_incompat(fs_info, METADATA_UUID))
-               device = btrfs_find_device(fs_info, devid, dev_uuid,
-                               disk_super->metadata_uuid);
+               device = btrfs_find_device(fs_info->fs_devices, devid, dev_uuid,
+                                          disk_super->metadata_uuid);
        else
        else
-               device = btrfs_find_device(fs_info, devid,
-                               dev_uuid, disk_super->fsid);
+               device = btrfs_find_device(fs_info->fs_devices, devid, dev_uuid,
+                                          disk_super->fsid);
 
        brelse(bh);
        if (!device)
 
        brelse(bh);
        if (!device)
@@ -2408,7 +2408,8 @@ struct btrfs_device *btrfs_find_device_by_devspec(
        struct btrfs_device *device;
 
        if (devid) {
        struct btrfs_device *device;
 
        if (devid) {
-               device = btrfs_find_device(fs_info, devid, NULL, NULL);
+               device = btrfs_find_device(fs_info->fs_devices, devid, NULL,
+                                          NULL);
                if (!device)
                        return ERR_PTR(-ENOENT);
                return device;
                if (!device)
                        return ERR_PTR(-ENOENT);
                return device;
@@ -2550,7 +2551,8 @@ next_slot:
                                   BTRFS_UUID_SIZE);
                read_extent_buffer(leaf, fs_uuid, btrfs_device_fsid(dev_item),
                                   BTRFS_FSID_SIZE);
                                   BTRFS_UUID_SIZE);
                read_extent_buffer(leaf, fs_uuid, btrfs_device_fsid(dev_item),
                                   BTRFS_FSID_SIZE);
-               device = btrfs_find_device(fs_info, devid, dev_uuid, fs_uuid);
+               device = btrfs_find_device(fs_info->fs_devices, devid, dev_uuid,
+                                          fs_uuid);
                BUG_ON(!device); /* Logic error */
 
                if (device->fs_devices->seeding) {
                BUG_ON(!device); /* Logic error */
 
                if (device->fs_devices->seeding) {
@@ -6603,21 +6605,19 @@ blk_status_t btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio,
        return BLK_STS_OK;
 }
 
        return BLK_STS_OK;
 }
 
-struct btrfs_device *btrfs_find_device(struct btrfs_fs_info *fs_info, u64 devid,
-                                      u8 *uuid, u8 *fsid)
+struct btrfs_device *btrfs_find_device(struct btrfs_fs_devices *fs_devices,
+                                      u64 devid, u8 *uuid, u8 *fsid)
 {
        struct btrfs_device *device;
 {
        struct btrfs_device *device;
-       struct btrfs_fs_devices *cur_devices;
 
 
-       cur_devices = fs_info->fs_devices;
-       while (cur_devices) {
+       while (fs_devices) {
                if (!fsid ||
                if (!fsid ||
-                   !memcmp(cur_devices->metadata_uuid, fsid, BTRFS_FSID_SIZE)) {
-                       device = find_device(cur_devices, devid, uuid);
+                   !memcmp(fs_devices->metadata_uuid, fsid, BTRFS_FSID_SIZE)) {
+                       device = find_device(fs_devices, devid, uuid);
                        if (device)
                                return device;
                }
                        if (device)
                                return device;
                }
-               cur_devices = cur_devices->seed;
+               fs_devices = fs_devices->seed;
        }
        return NULL;
 }
        }
        return NULL;
 }
@@ -6862,8 +6862,8 @@ static int read_one_chunk(struct btrfs_fs_info *fs_info, struct btrfs_key *key,
                read_extent_buffer(leaf, uuid, (unsigned long)
                                   btrfs_stripe_dev_uuid_nr(chunk, i),
                                   BTRFS_UUID_SIZE);
                read_extent_buffer(leaf, uuid, (unsigned long)
                                   btrfs_stripe_dev_uuid_nr(chunk, i),
                                   BTRFS_UUID_SIZE);
-               map->stripes[i].dev = btrfs_find_device(fs_info, devid,
-                                                       uuid, NULL);
+               map->stripes[i].dev = btrfs_find_device(fs_info->fs_devices,
+                                                       devid, uuid, NULL);
                if (!map->stripes[i].dev &&
                    !btrfs_test_opt(fs_info, DEGRADED)) {
                        free_extent_map(em);
                if (!map->stripes[i].dev &&
                    !btrfs_test_opt(fs_info, DEGRADED)) {
                        free_extent_map(em);
@@ -7002,7 +7002,8 @@ static int read_one_dev(struct btrfs_fs_info *fs_info,
                        return PTR_ERR(fs_devices);
        }
 
                        return PTR_ERR(fs_devices);
        }
 
-       device = btrfs_find_device(fs_info, devid, dev_uuid, fs_uuid);
+       device = btrfs_find_device(fs_info->fs_devices, devid, dev_uuid,
+                                  fs_uuid);
        if (!device) {
                if (!btrfs_test_opt(fs_info, DEGRADED)) {
                        btrfs_report_missing_device(fs_info, devid,
        if (!device) {
                if (!btrfs_test_opt(fs_info, DEGRADED)) {
                        btrfs_report_missing_device(fs_info, devid,
@@ -7592,7 +7593,7 @@ int btrfs_get_dev_stats(struct btrfs_fs_info *fs_info,
        int i;
 
        mutex_lock(&fs_devices->device_list_mutex);
        int i;
 
        mutex_lock(&fs_devices->device_list_mutex);
-       dev = btrfs_find_device(fs_info, stats->devid, NULL, NULL);
+       dev = btrfs_find_device(fs_info->fs_devices, stats->devid, NULL, NULL);
        mutex_unlock(&fs_devices->device_list_mutex);
 
        if (!dev) {
        mutex_unlock(&fs_devices->device_list_mutex);
 
        if (!dev) {
@@ -7806,7 +7807,7 @@ static int verify_one_dev_extent(struct btrfs_fs_info *fs_info,
        }
 
        /* Make sure no dev extent is beyond device bondary */
        }
 
        /* Make sure no dev extent is beyond device bondary */
-       dev = btrfs_find_device(fs_info, devid, NULL, NULL);
+       dev = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL);
        if (!dev) {
                btrfs_err(fs_info, "failed to find devid %llu", devid);
                ret = -EUCLEAN;
        if (!dev) {
                btrfs_err(fs_info, "failed to find devid %llu", devid);
                ret = -EUCLEAN;
index ed806649a473f4557792f6c2df182c303207b4c7..4b7c049c8c7c9a46df13679b600f14c39f293321 100644 (file)
@@ -433,8 +433,8 @@ void __exit btrfs_cleanup_fs_uuids(void);
 int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len);
 int btrfs_grow_device(struct btrfs_trans_handle *trans,
                      struct btrfs_device *device, u64 new_size);
 int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len);
 int btrfs_grow_device(struct btrfs_trans_handle *trans,
                      struct btrfs_device *device, u64 new_size);
-struct btrfs_device *btrfs_find_device(struct btrfs_fs_info *fs_info, u64 devid,
-                                      u8 *uuid, u8 *fsid);
+struct btrfs_device *btrfs_find_device(struct btrfs_fs_devices *fs_devices,
+                                      u64 devid, u8 *uuid, u8 *fsid);
 int btrfs_shrink_device(struct btrfs_device *device, u64 new_size);
 int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *path);
 int btrfs_balance(struct btrfs_fs_info *fs_info,
 int btrfs_shrink_device(struct btrfs_device *device, u64 new_size);
 int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *path);
 int btrfs_balance(struct btrfs_fs_info *fs_info,