aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/btrfs/dev-replace.c4
-rw-r--r--fs/btrfs/ioctl.c4
-rw-r--r--fs/btrfs/scrub.c4
-rw-r--r--fs/btrfs/volumes.c72
-rw-r--r--fs/btrfs/volumes.h2
5 files changed, 42 insertions, 44 deletions
diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index 6f0fe3623381..13863354ff9d 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -112,10 +112,10 @@ no_valid_dev_replace_entry_found:
112 case BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED: 112 case BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED:
113 case BTRFS_IOCTL_DEV_REPLACE_STATE_SUSPENDED: 113 case BTRFS_IOCTL_DEV_REPLACE_STATE_SUSPENDED:
114 dev_replace->srcdev = btrfs_find_device(fs_info->fs_devices, 114 dev_replace->srcdev = btrfs_find_device(fs_info->fs_devices,
115 src_devid, NULL, NULL); 115 src_devid, NULL, NULL, true);
116 dev_replace->tgtdev = btrfs_find_device(fs_info->fs_devices, 116 dev_replace->tgtdev = btrfs_find_device(fs_info->fs_devices,
117 BTRFS_DEV_REPLACE_DEVID, 117 BTRFS_DEV_REPLACE_DEVID,
118 NULL, NULL); 118 NULL, NULL, true);
119 /* 119 /*
120 * allow 'btrfs dev replace_cancel' if src/tgt device is 120 * allow 'btrfs dev replace_cancel' if src/tgt device is
121 * missing 121 * missing
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index fd5f97aeb35c..3f9d7be30bf4 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1642,7 +1642,7 @@ static noinline int btrfs_ioctl_resize(struct file *file,
1642 btrfs_info(fs_info, "resizing devid %llu", devid); 1642 btrfs_info(fs_info, "resizing devid %llu", devid);
1643 } 1643 }
1644 1644
1645 device = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL); 1645 device = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL, true);
1646 if (!device) { 1646 if (!device) {
1647 btrfs_info(fs_info, "resizer unable to find device %llu", 1647 btrfs_info(fs_info, "resizer unable to find device %llu",
1648 devid); 1648 devid);
@@ -3179,7 +3179,7 @@ static long btrfs_ioctl_dev_info(struct btrfs_fs_info *fs_info,
3179 3179
3180 rcu_read_lock(); 3180 rcu_read_lock();
3181 dev = btrfs_find_device(fs_info->fs_devices, di_args->devid, s_uuid, 3181 dev = btrfs_find_device(fs_info->fs_devices, di_args->devid, s_uuid,
3182 NULL); 3182 NULL, true);
3183 3183
3184 if (!dev) { 3184 if (!dev) {
3185 ret = -ENODEV; 3185 ret = -ENODEV;
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 72044efc610a..b320910c6740 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -3835,7 +3835,7 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
3835 return PTR_ERR(sctx); 3835 return PTR_ERR(sctx);
3836 3836
3837 mutex_lock(&fs_info->fs_devices->device_list_mutex); 3837 mutex_lock(&fs_info->fs_devices->device_list_mutex);
3838 dev = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL); 3838 dev = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL, true);
3839 if (!dev || (test_bit(BTRFS_DEV_STATE_MISSING, &dev->dev_state) && 3839 if (!dev || (test_bit(BTRFS_DEV_STATE_MISSING, &dev->dev_state) &&
3840 !is_dev_replace)) { 3840 !is_dev_replace)) {
3841 mutex_unlock(&fs_info->fs_devices->device_list_mutex); 3841 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,
4012 struct scrub_ctx *sctx = NULL; 4012 struct scrub_ctx *sctx = NULL;
4013 4013
4014 mutex_lock(&fs_info->fs_devices->device_list_mutex); 4014 mutex_lock(&fs_info->fs_devices->device_list_mutex);
4015 dev = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL); 4015 dev = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL, true);
4016 if (dev) 4016 if (dev)
4017 sctx = dev->scrub_ctx; 4017 sctx = dev->scrub_ctx;
4018 if (sctx) 4018 if (sctx)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 74bbfed6428b..7ca31c83e730 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -415,27 +415,6 @@ static struct btrfs_device *__alloc_device(void)
415 return dev; 415 return dev;
416} 416}
417 417
418/*
419 * Find a device specified by @devid or @uuid in the list of @fs_devices, or
420 * return NULL.
421 *
422 * If devid and uuid are both specified, the match must be exact, otherwise
423 * only devid is used.
424 */
425static struct btrfs_device *find_device(struct btrfs_fs_devices *fs_devices,
426 u64 devid, const u8 *uuid)
427{
428 struct btrfs_device *dev;
429
430 list_for_each_entry(dev, &fs_devices->devices, dev_list) {
431 if (dev->devid == devid &&
432 (!uuid || !memcmp(dev->uuid, uuid, BTRFS_UUID_SIZE))) {
433 return dev;
434 }
435 }
436 return NULL;
437}
438
439static noinline struct btrfs_fs_devices *find_fsid( 418static noinline struct btrfs_fs_devices *find_fsid(
440 const u8 *fsid, const u8 *metadata_fsid) 419 const u8 *fsid, const u8 *metadata_fsid)
441{ 420{
@@ -984,8 +963,8 @@ static noinline struct btrfs_device *device_list_add(const char *path,
984 device = NULL; 963 device = NULL;
985 } else { 964 } else {
986 mutex_lock(&fs_devices->device_list_mutex); 965 mutex_lock(&fs_devices->device_list_mutex);
987 device = find_device(fs_devices, devid, 966 device = btrfs_find_device(fs_devices, devid,
988 disk_super->dev_item.uuid); 967 disk_super->dev_item.uuid, NULL, false);
989 968
990 /* 969 /*
991 * If this disk has been pulled into an fs devices created by 970 * If this disk has been pulled into an fs devices created by
@@ -2402,10 +2381,10 @@ static struct btrfs_device *btrfs_find_device_by_path(
2402 dev_uuid = disk_super->dev_item.uuid; 2381 dev_uuid = disk_super->dev_item.uuid;
2403 if (btrfs_fs_incompat(fs_info, METADATA_UUID)) 2382 if (btrfs_fs_incompat(fs_info, METADATA_UUID))
2404 device = btrfs_find_device(fs_info->fs_devices, devid, dev_uuid, 2383 device = btrfs_find_device(fs_info->fs_devices, devid, dev_uuid,
2405 disk_super->metadata_uuid); 2384 disk_super->metadata_uuid, true);
2406 else 2385 else
2407 device = btrfs_find_device(fs_info->fs_devices, devid, dev_uuid, 2386 device = btrfs_find_device(fs_info->fs_devices, devid, dev_uuid,
2408 disk_super->fsid); 2387 disk_super->fsid, true);
2409 2388
2410 brelse(bh); 2389 brelse(bh);
2411 if (!device) 2390 if (!device)
@@ -2425,7 +2404,7 @@ struct btrfs_device *btrfs_find_device_by_devspec(
2425 2404
2426 if (devid) { 2405 if (devid) {
2427 device = btrfs_find_device(fs_info->fs_devices, devid, NULL, 2406 device = btrfs_find_device(fs_info->fs_devices, devid, NULL,
2428 NULL); 2407 NULL, true);
2429 if (!device) 2408 if (!device)
2430 return ERR_PTR(-ENOENT); 2409 return ERR_PTR(-ENOENT);
2431 return device; 2410 return device;
@@ -2568,7 +2547,7 @@ next_slot:
2568 read_extent_buffer(leaf, fs_uuid, btrfs_device_fsid(dev_item), 2547 read_extent_buffer(leaf, fs_uuid, btrfs_device_fsid(dev_item),
2569 BTRFS_FSID_SIZE); 2548 BTRFS_FSID_SIZE);
2570 device = btrfs_find_device(fs_info->fs_devices, devid, dev_uuid, 2549 device = btrfs_find_device(fs_info->fs_devices, devid, dev_uuid,
2571 fs_uuid); 2550 fs_uuid, true);
2572 BUG_ON(!device); /* Logic error */ 2551 BUG_ON(!device); /* Logic error */
2573 2552
2574 if (device->fs_devices->seeding) { 2553 if (device->fs_devices->seeding) {
@@ -6621,19 +6600,36 @@ blk_status_t btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio,
6621 return BLK_STS_OK; 6600 return BLK_STS_OK;
6622} 6601}
6623 6602
6603/*
6604 * Find a device specified by @devid or @uuid in the list of @fs_devices, or
6605 * return NULL.
6606 *
6607 * If devid and uuid are both specified, the match must be exact, otherwise
6608 * only devid is used.
6609 *
6610 * If @seed is true, traverse through the seed devices.
6611 */
6624struct btrfs_device *btrfs_find_device(struct btrfs_fs_devices *fs_devices, 6612struct btrfs_device *btrfs_find_device(struct btrfs_fs_devices *fs_devices,
6625 u64 devid, u8 *uuid, u8 *fsid) 6613 u64 devid, u8 *uuid, u8 *fsid,
6614 bool seed)
6626{ 6615{
6627 struct btrfs_device *device; 6616 struct btrfs_device *device;
6628 6617
6629 while (fs_devices) { 6618 while (fs_devices) {
6630 if (!fsid || 6619 if (!fsid ||
6631 !memcmp(fs_devices->metadata_uuid, fsid, BTRFS_FSID_SIZE)) { 6620 !memcmp(fs_devices->metadata_uuid, fsid, BTRFS_FSID_SIZE)) {
6632 device = find_device(fs_devices, devid, uuid); 6621 list_for_each_entry(device, &fs_devices->devices,
6633 if (device) 6622 dev_list) {
6634 return device; 6623 if (device->devid == devid &&
6624 (!uuid || memcmp(device->uuid, uuid,
6625 BTRFS_UUID_SIZE) == 0))
6626 return device;
6627 }
6635 } 6628 }
6636 fs_devices = fs_devices->seed; 6629 if (seed)
6630 fs_devices = fs_devices->seed;
6631 else
6632 return NULL;
6637 } 6633 }
6638 return NULL; 6634 return NULL;
6639} 6635}
@@ -6879,7 +6875,7 @@ static int read_one_chunk(struct btrfs_fs_info *fs_info, struct btrfs_key *key,
6879 btrfs_stripe_dev_uuid_nr(chunk, i), 6875 btrfs_stripe_dev_uuid_nr(chunk, i),
6880 BTRFS_UUID_SIZE); 6876 BTRFS_UUID_SIZE);
6881 map->stripes[i].dev = btrfs_find_device(fs_info->fs_devices, 6877 map->stripes[i].dev = btrfs_find_device(fs_info->fs_devices,
6882 devid, uuid, NULL); 6878 devid, uuid, NULL, true);
6883 if (!map->stripes[i].dev && 6879 if (!map->stripes[i].dev &&
6884 !btrfs_test_opt(fs_info, DEGRADED)) { 6880 !btrfs_test_opt(fs_info, DEGRADED)) {
6885 free_extent_map(em); 6881 free_extent_map(em);
@@ -7019,7 +7015,7 @@ static int read_one_dev(struct btrfs_fs_info *fs_info,
7019 } 7015 }
7020 7016
7021 device = btrfs_find_device(fs_info->fs_devices, devid, dev_uuid, 7017 device = btrfs_find_device(fs_info->fs_devices, devid, dev_uuid,
7022 fs_uuid); 7018 fs_uuid, true);
7023 if (!device) { 7019 if (!device) {
7024 if (!btrfs_test_opt(fs_info, DEGRADED)) { 7020 if (!btrfs_test_opt(fs_info, DEGRADED)) {
7025 btrfs_report_missing_device(fs_info, devid, 7021 btrfs_report_missing_device(fs_info, devid,
@@ -7609,7 +7605,8 @@ int btrfs_get_dev_stats(struct btrfs_fs_info *fs_info,
7609 int i; 7605 int i;
7610 7606
7611 mutex_lock(&fs_devices->device_list_mutex); 7607 mutex_lock(&fs_devices->device_list_mutex);
7612 dev = btrfs_find_device(fs_info->fs_devices, stats->devid, NULL, NULL); 7608 dev = btrfs_find_device(fs_info->fs_devices, stats->devid, NULL, NULL,
7609 true);
7613 mutex_unlock(&fs_devices->device_list_mutex); 7610 mutex_unlock(&fs_devices->device_list_mutex);
7614 7611
7615 if (!dev) { 7612 if (!dev) {
@@ -7823,7 +7820,7 @@ static int verify_one_dev_extent(struct btrfs_fs_info *fs_info,
7823 } 7820 }
7824 7821
7825 /* Make sure no dev extent is beyond device bondary */ 7822 /* Make sure no dev extent is beyond device bondary */
7826 dev = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL); 7823 dev = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL, true);
7827 if (!dev) { 7824 if (!dev) {
7828 btrfs_err(fs_info, "failed to find devid %llu", devid); 7825 btrfs_err(fs_info, "failed to find devid %llu", devid);
7829 ret = -EUCLEAN; 7826 ret = -EUCLEAN;
@@ -7832,7 +7829,8 @@ static int verify_one_dev_extent(struct btrfs_fs_info *fs_info,
7832 7829
7833 /* It's possible this device is a dummy for seed device */ 7830 /* It's possible this device is a dummy for seed device */
7834 if (dev->disk_total_bytes == 0) { 7831 if (dev->disk_total_bytes == 0) {
7835 dev = find_device(fs_info->fs_devices->seed, devid, NULL); 7832 dev = btrfs_find_device(fs_info->fs_devices->seed, devid, NULL,
7833 NULL, false);
7836 if (!dev) { 7834 if (!dev) {
7837 btrfs_err(fs_info, "failed to find seed devid %llu", 7835 btrfs_err(fs_info, "failed to find seed devid %llu",
7838 devid); 7836 devid);
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 4b7c049c8c7c..656ea8d85770 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -434,7 +434,7 @@ int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len);
434int btrfs_grow_device(struct btrfs_trans_handle *trans, 434int btrfs_grow_device(struct btrfs_trans_handle *trans,
435 struct btrfs_device *device, u64 new_size); 435 struct btrfs_device *device, u64 new_size);
436struct btrfs_device *btrfs_find_device(struct btrfs_fs_devices *fs_devices, 436struct btrfs_device *btrfs_find_device(struct btrfs_fs_devices *fs_devices,
437 u64 devid, u8 *uuid, u8 *fsid); 437 u64 devid, u8 *uuid, u8 *fsid, bool seed);
438int btrfs_shrink_device(struct btrfs_device *device, u64 new_size); 438int btrfs_shrink_device(struct btrfs_device *device, u64 new_size);
439int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *path); 439int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *path);
440int btrfs_balance(struct btrfs_fs_info *fs_info, 440int btrfs_balance(struct btrfs_fs_info *fs_info,