@@ -415,27 +415,6 @@ static struct btrfs_device *__alloc_device(void)
415415 return dev ;
416416}
417417
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-
439418static noinline struct btrfs_fs_devices * find_fsid (
440419 const u8 * fsid , const u8 * metadata_fsid )
441420{
@@ -984,8 +963,8 @@ static noinline struct btrfs_device *device_list_add(const char *path,
984963 device = NULL ;
985964 } else {
986965 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 );
989968
990969 /*
991970 * 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(
24022381 dev_uuid = disk_super -> dev_item .uuid ;
24032382 if (btrfs_fs_incompat (fs_info , METADATA_UUID ))
24042383 device = btrfs_find_device (fs_info -> fs_devices , devid , dev_uuid ,
2405- disk_super -> metadata_uuid );
2384+ disk_super -> metadata_uuid , true );
24062385 else
24072386 device = btrfs_find_device (fs_info -> fs_devices , devid , dev_uuid ,
2408- disk_super -> fsid );
2387+ disk_super -> fsid , true );
24092388
24102389 brelse (bh );
24112390 if (!device )
@@ -2425,7 +2404,7 @@ struct btrfs_device *btrfs_find_device_by_devspec(
24252404
24262405 if (devid ) {
24272406 device = btrfs_find_device (fs_info -> fs_devices , devid , NULL ,
2428- NULL );
2407+ NULL , true );
24292408 if (!device )
24302409 return ERR_PTR (- ENOENT );
24312410 return device ;
@@ -2568,7 +2547,7 @@ static int btrfs_finish_sprout(struct btrfs_trans_handle *trans,
25682547 read_extent_buffer (leaf , fs_uuid , btrfs_device_fsid (dev_item ),
25692548 BTRFS_FSID_SIZE );
25702549 device = btrfs_find_device (fs_info -> fs_devices , devid , dev_uuid ,
2571- fs_uuid );
2550+ fs_uuid , true );
25722551 BUG_ON (!device ); /* Logic error */
25732552
25742553 if (device -> fs_devices -> seeding ) {
@@ -6621,19 +6600,36 @@ blk_status_t btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio,
66216600 return BLK_STS_OK ;
66226601}
66236602
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+ */
66246612struct 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 )
66266615{
66276616 struct btrfs_device * device ;
66286617
66296618 while (fs_devices ) {
66306619 if (!fsid ||
66316620 !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+ }
66356628 }
6636- fs_devices = fs_devices -> seed ;
6629+ if (seed )
6630+ fs_devices = fs_devices -> seed ;
6631+ else
6632+ return NULL ;
66376633 }
66386634 return NULL ;
66396635}
@@ -6879,7 +6875,7 @@ static int read_one_chunk(struct btrfs_fs_info *fs_info, struct btrfs_key *key,
68796875 btrfs_stripe_dev_uuid_nr (chunk , i ),
68806876 BTRFS_UUID_SIZE );
68816877 map -> stripes [i ].dev = btrfs_find_device (fs_info -> fs_devices ,
6882- devid , uuid , NULL );
6878+ devid , uuid , NULL , true );
68836879 if (!map -> stripes [i ].dev &&
68846880 !btrfs_test_opt (fs_info , DEGRADED )) {
68856881 free_extent_map (em );
@@ -7019,7 +7015,7 @@ static int read_one_dev(struct btrfs_fs_info *fs_info,
70197015 }
70207016
70217017 device = btrfs_find_device (fs_info -> fs_devices , devid , dev_uuid ,
7022- fs_uuid );
7018+ fs_uuid , true );
70237019 if (!device ) {
70247020 if (!btrfs_test_opt (fs_info , DEGRADED )) {
70257021 btrfs_report_missing_device (fs_info , devid ,
@@ -7609,7 +7605,8 @@ int btrfs_get_dev_stats(struct btrfs_fs_info *fs_info,
76097605 int i ;
76107606
76117607 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);
76137610 mutex_unlock (& fs_devices -> device_list_mutex );
76147611
76157612 if (!dev ) {
@@ -7823,7 +7820,7 @@ static int verify_one_dev_extent(struct btrfs_fs_info *fs_info,
78237820 }
78247821
78257822 /* 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 );
78277824 if (!dev ) {
78287825 btrfs_err (fs_info , "failed to find devid %llu" , devid );
78297826 ret = - EUCLEAN ;
@@ -7832,7 +7829,8 @@ static int verify_one_dev_extent(struct btrfs_fs_info *fs_info,
78327829
78337830 /* It's possible this device is a dummy for seed device */
78347831 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);
78367834 if (!dev ) {
78377835 btrfs_err (fs_info , "failed to find seed devid %llu" ,
78387836 devid );
0 commit comments