@@ -253,28 +253,6 @@ static struct btrfs_device *__alloc_device(void)
253
253
return dev ;
254
254
}
255
255
256
- /*
257
- * Find a device specified by @devid or @uuid in the list of @fs_devices, or
258
- * return NULL.
259
- *
260
- * If devid and uuid are both specified, the match must be exact, otherwise
261
- * only devid is used.
262
- */
263
- static struct btrfs_device * find_device (struct btrfs_fs_devices * fs_devices ,
264
- u64 devid , const u8 * uuid )
265
- {
266
- struct list_head * head = & fs_devices -> devices ;
267
- struct btrfs_device * dev ;
268
-
269
- list_for_each_entry (dev , head , dev_list ) {
270
- if (dev -> devid == devid &&
271
- (!uuid || !memcmp (dev -> uuid , uuid , BTRFS_UUID_SIZE ))) {
272
- return dev ;
273
- }
274
- }
275
- return NULL ;
276
- }
277
-
278
256
static noinline struct btrfs_fs_devices * find_fsid (u8 * fsid )
279
257
{
280
258
struct btrfs_fs_devices * fs_devices ;
@@ -629,8 +607,8 @@ static noinline int device_list_add(const char *path,
629
607
630
608
device = NULL ;
631
609
} else {
632
- device = find_device (fs_devices , devid ,
633
- disk_super -> dev_item .uuid );
610
+ device = btrfs_find_device (fs_devices , devid ,
611
+ disk_super -> dev_item .uuid , NULL , false );
634
612
}
635
613
636
614
if (!device ) {
@@ -2115,7 +2093,8 @@ static int btrfs_find_device_by_path(struct btrfs_fs_info *fs_info,
2115
2093
disk_super = (struct btrfs_super_block * )bh -> b_data ;
2116
2094
devid = btrfs_stack_device_id (& disk_super -> dev_item );
2117
2095
dev_uuid = disk_super -> dev_item .uuid ;
2118
- * device = btrfs_find_device (fs_info , devid , dev_uuid , disk_super -> fsid );
2096
+ * device = btrfs_find_device (fs_info -> fs_devices , devid , dev_uuid ,
2097
+ disk_super -> fsid , true);
2119
2098
brelse (bh );
2120
2099
if (!* device )
2121
2100
ret = - ENOENT ;
@@ -2164,7 +2143,8 @@ int btrfs_find_device_by_devspec(struct btrfs_fs_info *fs_info, u64 devid,
2164
2143
2165
2144
if (devid ) {
2166
2145
ret = 0 ;
2167
- * device = btrfs_find_device (fs_info , devid , NULL , NULL );
2146
+ * device = btrfs_find_device (fs_info -> fs_devices , devid ,
2147
+ NULL , NULL , true);
2168
2148
if (!* device )
2169
2149
ret = - ENOENT ;
2170
2150
} else {
@@ -2296,7 +2276,8 @@ static int btrfs_finish_sprout(struct btrfs_trans_handle *trans,
2296
2276
BTRFS_UUID_SIZE );
2297
2277
read_extent_buffer (leaf , fs_uuid , btrfs_device_fsid (dev_item ),
2298
2278
BTRFS_FSID_SIZE );
2299
- device = btrfs_find_device (fs_info , devid , dev_uuid , fs_uuid );
2279
+ device = btrfs_find_device (fs_info -> fs_devices , devid , dev_uuid ,
2280
+ fs_uuid , true);
2300
2281
BUG_ON (!device ); /* Logic error */
2301
2282
2302
2283
if (device -> fs_devices -> seeding ) {
@@ -6300,21 +6281,36 @@ blk_status_t btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio,
6300
6281
return BLK_STS_OK ;
6301
6282
}
6302
6283
6303
- struct btrfs_device * btrfs_find_device (struct btrfs_fs_info * fs_info , u64 devid ,
6304
- u8 * uuid , u8 * fsid )
6284
+ /*
6285
+ * Find a device specified by @devid or @uuid in the list of @fs_devices, or
6286
+ * return NULL.
6287
+ *
6288
+ * If devid and uuid are both specified, the match must be exact, otherwise
6289
+ * only devid is used.
6290
+ *
6291
+ * If @seed is true, traverse through the seed devices.
6292
+ */
6293
+ struct btrfs_device * btrfs_find_device (struct btrfs_fs_devices * fs_devices ,
6294
+ u64 devid , u8 * uuid , u8 * fsid ,
6295
+ bool seed )
6305
6296
{
6306
6297
struct btrfs_device * device ;
6307
- struct btrfs_fs_devices * cur_devices ;
6308
6298
6309
- cur_devices = fs_info -> fs_devices ;
6310
- while (cur_devices ) {
6299
+ while (fs_devices ) {
6311
6300
if (!fsid ||
6312
- !memcmp (cur_devices -> fsid , fsid , BTRFS_FSID_SIZE )) {
6313
- device = find_device (cur_devices , devid , uuid );
6314
- if (device )
6315
- return device ;
6301
+ !memcmp (fs_devices -> fsid , fsid , BTRFS_FSID_SIZE )) {
6302
+ list_for_each_entry (device , & fs_devices -> devices ,
6303
+ dev_list ) {
6304
+ if (device -> devid == devid &&
6305
+ (!uuid || memcmp (device -> uuid , uuid ,
6306
+ BTRFS_UUID_SIZE ) == 0 ))
6307
+ return device ;
6308
+ }
6316
6309
}
6317
- cur_devices = cur_devices -> seed ;
6310
+ if (seed )
6311
+ fs_devices = fs_devices -> seed ;
6312
+ else
6313
+ return NULL ;
6318
6314
}
6319
6315
return NULL ;
6320
6316
}
@@ -6547,8 +6543,8 @@ static int read_one_chunk(struct btrfs_fs_info *fs_info, struct btrfs_key *key,
6547
6543
read_extent_buffer (leaf , uuid , (unsigned long )
6548
6544
btrfs_stripe_dev_uuid_nr (chunk , i ),
6549
6545
BTRFS_UUID_SIZE );
6550
- map -> stripes [i ].dev = btrfs_find_device (fs_info , devid ,
6551
- uuid , NULL );
6546
+ map -> stripes [i ].dev = btrfs_find_device (fs_info -> fs_devices ,
6547
+ devid , uuid , NULL , true );
6552
6548
if (!map -> stripes [i ].dev &&
6553
6549
!btrfs_test_opt (fs_info , DEGRADED )) {
6554
6550
free_extent_map (em );
@@ -6683,7 +6679,8 @@ static int read_one_dev(struct btrfs_fs_info *fs_info,
6683
6679
return PTR_ERR (fs_devices );
6684
6680
}
6685
6681
6686
- device = btrfs_find_device (fs_info , devid , dev_uuid , fs_uuid );
6682
+ device = btrfs_find_device (fs_info -> fs_devices , devid , dev_uuid ,
6683
+ fs_uuid , true);
6687
6684
if (!device ) {
6688
6685
if (!btrfs_test_opt (fs_info , DEGRADED )) {
6689
6686
btrfs_report_missing_device (fs_info , devid , dev_uuid );
@@ -7256,7 +7253,8 @@ int btrfs_get_dev_stats(struct btrfs_fs_info *fs_info,
7256
7253
int i ;
7257
7254
7258
7255
mutex_lock (& fs_devices -> device_list_mutex );
7259
- dev = btrfs_find_device (fs_info , stats -> devid , NULL , NULL );
7256
+ dev = btrfs_find_device (fs_info -> fs_devices , stats -> devid ,
7257
+ NULL , NULL , true);
7260
7258
mutex_unlock (& fs_devices -> device_list_mutex );
7261
7259
7262
7260
if (!dev ) {
0 commit comments