@@ -415,27 +415,6 @@ static struct btrfs_device *__alloc_device(void)
415
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
- */
425
- static 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
-
439
418
static noinline struct btrfs_fs_devices * find_fsid (
440
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
963
device = NULL ;
985
964
} else {
986
965
mutex_lock (& fs_devices -> device_list_mutex );
987
- device = find_device (fs_devices , devid ,
988
- disk_super -> dev_item .uuid );
966
+ device = btrfs_find_device (fs_devices , devid ,
967
+ disk_super -> dev_item .uuid , NULL , false );
989
968
990
969
/*
991
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
2381
dev_uuid = disk_super -> dev_item .uuid ;
2403
2382
if (btrfs_fs_incompat (fs_info , METADATA_UUID ))
2404
2383
device = btrfs_find_device (fs_info -> fs_devices , devid , dev_uuid ,
2405
- disk_super -> metadata_uuid );
2384
+ disk_super -> metadata_uuid , true );
2406
2385
else
2407
2386
device = btrfs_find_device (fs_info -> fs_devices , devid , dev_uuid ,
2408
- disk_super -> fsid );
2387
+ disk_super -> fsid , true );
2409
2388
2410
2389
brelse (bh );
2411
2390
if (!device )
@@ -2425,7 +2404,7 @@ struct btrfs_device *btrfs_find_device_by_devspec(
2425
2404
2426
2405
if (devid ) {
2427
2406
device = btrfs_find_device (fs_info -> fs_devices , devid , NULL ,
2428
- NULL );
2407
+ NULL , true );
2429
2408
if (!device )
2430
2409
return ERR_PTR (- ENOENT );
2431
2410
return device ;
@@ -2568,7 +2547,7 @@ static int btrfs_finish_sprout(struct btrfs_trans_handle *trans,
2568
2547
read_extent_buffer (leaf , fs_uuid , btrfs_device_fsid (dev_item ),
2569
2548
BTRFS_FSID_SIZE );
2570
2549
device = btrfs_find_device (fs_info -> fs_devices , devid , dev_uuid ,
2571
- fs_uuid );
2550
+ fs_uuid , true );
2572
2551
BUG_ON (!device ); /* Logic error */
2573
2552
2574
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
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
+ */
6624
6612
struct 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
6616
struct btrfs_device * device ;
6628
6617
6629
6618
while (fs_devices ) {
6630
6619
if (!fsid ||
6631
6620
!memcmp (fs_devices -> metadata_uuid , fsid , BTRFS_FSID_SIZE )) {
6632
- device = find_device (fs_devices , devid , uuid );
6633
- if (device )
6634
- return device ;
6621
+ list_for_each_entry (device , & fs_devices -> devices ,
6622
+ dev_list ) {
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
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
6875
btrfs_stripe_dev_uuid_nr (chunk , i ),
6880
6876
BTRFS_UUID_SIZE );
6881
6877
map -> stripes [i ].dev = btrfs_find_device (fs_info -> fs_devices ,
6882
- devid , uuid , NULL );
6878
+ devid , uuid , NULL , true );
6883
6879
if (!map -> stripes [i ].dev &&
6884
6880
!btrfs_test_opt (fs_info , DEGRADED )) {
6885
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
7017
device = btrfs_find_device (fs_info -> fs_devices , devid , dev_uuid ,
7022
- fs_uuid );
7018
+ fs_uuid , true );
7023
7019
if (!device ) {
7024
7020
if (!btrfs_test_opt (fs_info , DEGRADED )) {
7025
7021
btrfs_report_missing_device (fs_info , devid ,
@@ -7609,7 +7605,8 @@ int btrfs_get_dev_stats(struct btrfs_fs_info *fs_info,
7609
7605
int i ;
7610
7606
7611
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
7610
mutex_unlock (& fs_devices -> device_list_mutex );
7614
7611
7615
7612
if (!dev ) {
@@ -7823,7 +7820,7 @@ static int verify_one_dev_extent(struct btrfs_fs_info *fs_info,
7823
7820
}
7824
7821
7825
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
7824
if (!dev ) {
7828
7825
btrfs_err (fs_info , "failed to find devid %llu" , devid );
7829
7826
ret = - EUCLEAN ;
@@ -7832,7 +7829,8 @@ static int verify_one_dev_extent(struct btrfs_fs_info *fs_info,
7832
7829
7833
7830
/* It's possible this device is a dummy for seed device */
7834
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
7834
if (!dev ) {
7837
7835
btrfs_err (fs_info , "failed to find seed devid %llu" ,
7838
7836
devid );
0 commit comments