Skip to content

Commit e4319cd

Browse files
asjkdave
authored andcommitted
btrfs: refactor btrfs_find_device() take fs_devices as argument
btrfs_find_device() accepts fs_info as an argument and retrieves fs_devices from fs_info. Instead use fs_devices, so that this function can be used in non-mount (during device scanning) context as well. Signed-off-by: Anand Jain <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 6e927ce commit e4319cd

File tree

5 files changed

+30
-28
lines changed

5 files changed

+30
-28
lines changed

fs/btrfs/dev-replace.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ int btrfs_init_dev_replace(struct btrfs_fs_info *fs_info)
111111
break;
112112
case BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED:
113113
case BTRFS_IOCTL_DEV_REPLACE_STATE_SUSPENDED:
114-
dev_replace->srcdev = btrfs_find_device(fs_info, src_devid,
115-
NULL, NULL);
116-
dev_replace->tgtdev = btrfs_find_device(fs_info,
114+
dev_replace->srcdev = btrfs_find_device(fs_info->fs_devices,
115+
src_devid, NULL, NULL);
116+
dev_replace->tgtdev = btrfs_find_device(fs_info->fs_devices,
117117
BTRFS_DEV_REPLACE_DEVID,
118118
NULL, NULL);
119119
/*

fs/btrfs/ioctl.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,7 @@ static noinline int btrfs_ioctl_resize(struct file *file,
16421642
btrfs_info(fs_info, "resizing devid %llu", devid);
16431643
}
16441644

1645-
device = btrfs_find_device(fs_info, devid, NULL, NULL);
1645+
device = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL);
16461646
if (!device) {
16471647
btrfs_info(fs_info, "resizer unable to find device %llu",
16481648
devid);
@@ -3178,7 +3178,8 @@ static long btrfs_ioctl_dev_info(struct btrfs_fs_info *fs_info,
31783178
s_uuid = di_args->uuid;
31793179

31803180
rcu_read_lock();
3181-
dev = btrfs_find_device(fs_info, di_args->devid, s_uuid, NULL);
3181+
dev = btrfs_find_device(fs_info->fs_devices, di_args->devid, s_uuid,
3182+
NULL);
31823183

31833184
if (!dev) {
31843185
ret = -ENODEV;

fs/btrfs/scrub.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3835,7 +3835,7 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
38353835
return PTR_ERR(sctx);
38363836

38373837
mutex_lock(&fs_info->fs_devices->device_list_mutex);
3838-
dev = btrfs_find_device(fs_info, devid, NULL, NULL);
3838+
dev = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL);
38393839
if (!dev || (test_bit(BTRFS_DEV_STATE_MISSING, &dev->dev_state) &&
38403840
!is_dev_replace)) {
38413841
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,
40124012
struct scrub_ctx *sctx = NULL;
40134013

40144014
mutex_lock(&fs_info->fs_devices->device_list_mutex);
4015-
dev = btrfs_find_device(fs_info, devid, NULL, NULL);
4015+
dev = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL);
40164016
if (dev)
40174017
sctx = dev->scrub_ctx;
40184018
if (sctx)

fs/btrfs/volumes.c

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,11 +2385,11 @@ static struct btrfs_device *btrfs_find_device_by_path(
23852385
devid = btrfs_stack_device_id(&disk_super->dev_item);
23862386
dev_uuid = disk_super->dev_item.uuid;
23872387
if (btrfs_fs_incompat(fs_info, METADATA_UUID))
2388-
device = btrfs_find_device(fs_info, devid, dev_uuid,
2389-
disk_super->metadata_uuid);
2388+
device = btrfs_find_device(fs_info->fs_devices, devid, dev_uuid,
2389+
disk_super->metadata_uuid);
23902390
else
2391-
device = btrfs_find_device(fs_info, devid,
2392-
dev_uuid, disk_super->fsid);
2391+
device = btrfs_find_device(fs_info->fs_devices, devid, dev_uuid,
2392+
disk_super->fsid);
23932393

23942394
brelse(bh);
23952395
if (!device)
@@ -2408,7 +2408,8 @@ struct btrfs_device *btrfs_find_device_by_devspec(
24082408
struct btrfs_device *device;
24092409

24102410
if (devid) {
2411-
device = btrfs_find_device(fs_info, devid, NULL, NULL);
2411+
device = btrfs_find_device(fs_info->fs_devices, devid, NULL,
2412+
NULL);
24122413
if (!device)
24132414
return ERR_PTR(-ENOENT);
24142415
return device;
@@ -2550,7 +2551,8 @@ static int btrfs_finish_sprout(struct btrfs_trans_handle *trans,
25502551
BTRFS_UUID_SIZE);
25512552
read_extent_buffer(leaf, fs_uuid, btrfs_device_fsid(dev_item),
25522553
BTRFS_FSID_SIZE);
2553-
device = btrfs_find_device(fs_info, devid, dev_uuid, fs_uuid);
2554+
device = btrfs_find_device(fs_info->fs_devices, devid, dev_uuid,
2555+
fs_uuid);
25542556
BUG_ON(!device); /* Logic error */
25552557

25562558
if (device->fs_devices->seeding) {
@@ -6603,21 +6605,19 @@ blk_status_t btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio,
66036605
return BLK_STS_OK;
66046606
}
66056607

6606-
struct btrfs_device *btrfs_find_device(struct btrfs_fs_info *fs_info, u64 devid,
6607-
u8 *uuid, u8 *fsid)
6608+
struct btrfs_device *btrfs_find_device(struct btrfs_fs_devices *fs_devices,
6609+
u64 devid, u8 *uuid, u8 *fsid)
66086610
{
66096611
struct btrfs_device *device;
6610-
struct btrfs_fs_devices *cur_devices;
66116612

6612-
cur_devices = fs_info->fs_devices;
6613-
while (cur_devices) {
6613+
while (fs_devices) {
66146614
if (!fsid ||
6615-
!memcmp(cur_devices->metadata_uuid, fsid, BTRFS_FSID_SIZE)) {
6616-
device = find_device(cur_devices, devid, uuid);
6615+
!memcmp(fs_devices->metadata_uuid, fsid, BTRFS_FSID_SIZE)) {
6616+
device = find_device(fs_devices, devid, uuid);
66176617
if (device)
66186618
return device;
66196619
}
6620-
cur_devices = cur_devices->seed;
6620+
fs_devices = fs_devices->seed;
66216621
}
66226622
return NULL;
66236623
}
@@ -6862,8 +6862,8 @@ static int read_one_chunk(struct btrfs_fs_info *fs_info, struct btrfs_key *key,
68626862
read_extent_buffer(leaf, uuid, (unsigned long)
68636863
btrfs_stripe_dev_uuid_nr(chunk, i),
68646864
BTRFS_UUID_SIZE);
6865-
map->stripes[i].dev = btrfs_find_device(fs_info, devid,
6866-
uuid, NULL);
6865+
map->stripes[i].dev = btrfs_find_device(fs_info->fs_devices,
6866+
devid, uuid, NULL);
68676867
if (!map->stripes[i].dev &&
68686868
!btrfs_test_opt(fs_info, DEGRADED)) {
68696869
free_extent_map(em);
@@ -7002,7 +7002,8 @@ static int read_one_dev(struct btrfs_fs_info *fs_info,
70027002
return PTR_ERR(fs_devices);
70037003
}
70047004

7005-
device = btrfs_find_device(fs_info, devid, dev_uuid, fs_uuid);
7005+
device = btrfs_find_device(fs_info->fs_devices, devid, dev_uuid,
7006+
fs_uuid);
70067007
if (!device) {
70077008
if (!btrfs_test_opt(fs_info, DEGRADED)) {
70087009
btrfs_report_missing_device(fs_info, devid,
@@ -7592,7 +7593,7 @@ int btrfs_get_dev_stats(struct btrfs_fs_info *fs_info,
75927593
int i;
75937594

75947595
mutex_lock(&fs_devices->device_list_mutex);
7595-
dev = btrfs_find_device(fs_info, stats->devid, NULL, NULL);
7596+
dev = btrfs_find_device(fs_info->fs_devices, stats->devid, NULL, NULL);
75967597
mutex_unlock(&fs_devices->device_list_mutex);
75977598

75987599
if (!dev) {
@@ -7806,7 +7807,7 @@ static int verify_one_dev_extent(struct btrfs_fs_info *fs_info,
78067807
}
78077808

78087809
/* Make sure no dev extent is beyond device bondary */
7809-
dev = btrfs_find_device(fs_info, devid, NULL, NULL);
7810+
dev = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL);
78107811
if (!dev) {
78117812
btrfs_err(fs_info, "failed to find devid %llu", devid);
78127813
ret = -EUCLEAN;

fs/btrfs/volumes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,8 @@ void __exit btrfs_cleanup_fs_uuids(void);
433433
int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len);
434434
int btrfs_grow_device(struct btrfs_trans_handle *trans,
435435
struct btrfs_device *device, u64 new_size);
436-
struct btrfs_device *btrfs_find_device(struct btrfs_fs_info *fs_info, u64 devid,
437-
u8 *uuid, u8 *fsid);
436+
struct btrfs_device *btrfs_find_device(struct btrfs_fs_devices *fs_devices,
437+
u64 devid, u8 *uuid, u8 *fsid);
438438
int btrfs_shrink_device(struct btrfs_device *device, u64 new_size);
439439
int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *path);
440440
int btrfs_balance(struct btrfs_fs_info *fs_info,

0 commit comments

Comments
 (0)