btrfs: refactor btrfs_find_device() take fs_devices as argument
[sfrench/cifs-2.6.git] / fs / btrfs / volumes.c
index 15561926ab32cbc8c0ba8a4006fcb8a45e87e6d5..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))
-               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
-               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)
@@ -2398,50 +2398,38 @@ static struct btrfs_device *btrfs_find_device_by_path(
        return device;
 }
 
-static struct btrfs_device *btrfs_find_device_missing_or_by_path(
-               struct btrfs_fs_info *fs_info, const char *device_path)
-{
-       struct btrfs_device *device = NULL;
-       if (strcmp(device_path, "missing") == 0) {
-               struct list_head *devices;
-               struct btrfs_device *tmp;
-
-               devices = &fs_info->fs_devices->devices;
-               list_for_each_entry(tmp, devices, dev_list) {
-                       if (test_bit(BTRFS_DEV_STATE_IN_FS_METADATA,
-                                       &tmp->dev_state) && !tmp->bdev) {
-                               device = tmp;
-                               break;
-                       }
-               }
-
-               if (!device)
-                       return ERR_PTR(-ENOENT);
-       } else {
-               device = btrfs_find_device_by_path(fs_info, device_path);
-       }
-
-       return device;
-}
-
 /*
  * Lookup a device given by device id, or the path if the id is 0.
  */
 struct btrfs_device *btrfs_find_device_by_devspec(
-               struct btrfs_fs_info *fs_info, u64 devid, const char *devpath)
+               struct btrfs_fs_info *fs_info, u64 devid,
+               const char *device_path)
 {
        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);
-       } else {
-               if (!devpath || !devpath[0])
-                       return ERR_PTR(-EINVAL);
-               device = btrfs_find_device_missing_or_by_path(fs_info, devpath);
+               return device;
        }
-       return device;
+
+       if (!device_path || !device_path[0])
+               return ERR_PTR(-EINVAL);
+
+       if (strcmp(device_path, "missing") == 0) {
+               /* Find first missing device */
+               list_for_each_entry(device, &fs_info->fs_devices->devices,
+                                   dev_list) {
+                       if (test_bit(BTRFS_DEV_STATE_IN_FS_METADATA,
+                                    &device->dev_state) && !device->bdev)
+                               return device;
+               }
+               return ERR_PTR(-ENOENT);
+       }
+
+       return btrfs_find_device_by_path(fs_info, device_path);
 }
 
 /*
@@ -2563,7 +2551,8 @@ next_slot:
                                   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) {
@@ -6616,21 +6605,19 @@ blk_status_t btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio,
        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_fs_devices *cur_devices;
 
-       cur_devices = fs_info->fs_devices;
-       while (cur_devices) {
+       while (fs_devices) {
                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;
                }
-               cur_devices = cur_devices->seed;
+               fs_devices = fs_devices->seed;
        }
        return NULL;
 }
@@ -6875,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);
-               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);
@@ -7015,7 +7002,8 @@ static int read_one_dev(struct btrfs_fs_info *fs_info,
                        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,
@@ -7605,7 +7593,7 @@ int btrfs_get_dev_stats(struct btrfs_fs_info *fs_info,
        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) {
@@ -7819,7 +7807,7 @@ static int verify_one_dev_extent(struct btrfs_fs_info *fs_info,
        }
 
        /* 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;