Skip to content

Commit 562d7b1

Browse files
josefbacikkdave
authored andcommitted
btrfs: handle device lookup with btrfs_dev_lookup_args
We have a lot of device lookup functions that all do something slightly different. Clean this up by adding a struct to hold the different lookup criteria, and then pass this around to btrfs_find_device() so it can do the proper matching based on the lookup criteria. Reviewed-by: Anand Jain <[email protected]> Signed-off-by: Josef Bacik <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 8b41393 commit 562d7b1

File tree

5 files changed

+112
-65
lines changed

5 files changed

+112
-65
lines changed

fs/btrfs/dev-replace.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ static int btrfs_dev_replace_kthread(void *data);
7070

7171
int btrfs_init_dev_replace(struct btrfs_fs_info *fs_info)
7272
{
73+
struct btrfs_dev_lookup_args args = { .devid = BTRFS_DEV_REPLACE_DEVID };
7374
struct btrfs_key key;
7475
struct btrfs_root *dev_root = fs_info->dev_root;
7576
struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;
@@ -100,8 +101,7 @@ int btrfs_init_dev_replace(struct btrfs_fs_info *fs_info)
100101
* We don't have a replace item or it's corrupted. If there is
101102
* a replace target, fail the mount.
102103
*/
103-
if (btrfs_find_device(fs_info->fs_devices,
104-
BTRFS_DEV_REPLACE_DEVID, NULL, NULL)) {
104+
if (btrfs_find_device(fs_info->fs_devices, &args)) {
105105
btrfs_err(fs_info,
106106
"found replace target device without a valid replace item");
107107
ret = -EUCLEAN;
@@ -163,8 +163,7 @@ int btrfs_init_dev_replace(struct btrfs_fs_info *fs_info)
163163
* We don't have an active replace item but if there is a
164164
* replace target, fail the mount.
165165
*/
166-
if (btrfs_find_device(fs_info->fs_devices,
167-
BTRFS_DEV_REPLACE_DEVID, NULL, NULL)) {
166+
if (btrfs_find_device(fs_info->fs_devices, &args)) {
168167
btrfs_err(fs_info,
169168
"replace devid present without an active replace item");
170169
ret = -EUCLEAN;
@@ -175,11 +174,10 @@ int btrfs_init_dev_replace(struct btrfs_fs_info *fs_info)
175174
break;
176175
case BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED:
177176
case BTRFS_IOCTL_DEV_REPLACE_STATE_SUSPENDED:
178-
dev_replace->srcdev = btrfs_find_device(fs_info->fs_devices,
179-
src_devid, NULL, NULL);
180-
dev_replace->tgtdev = btrfs_find_device(fs_info->fs_devices,
181-
BTRFS_DEV_REPLACE_DEVID,
182-
NULL, NULL);
177+
dev_replace->tgtdev = btrfs_find_device(fs_info->fs_devices, &args);
178+
args.devid = src_devid;
179+
dev_replace->srcdev = btrfs_find_device(fs_info->fs_devices, &args);
180+
183181
/*
184182
* allow 'btrfs dev replace_cancel' if src/tgt device is
185183
* missing

fs/btrfs/ioctl.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,6 +1602,7 @@ static int exclop_start_or_cancel_reloc(struct btrfs_fs_info *fs_info,
16021602
static noinline int btrfs_ioctl_resize(struct file *file,
16031603
void __user *arg)
16041604
{
1605+
BTRFS_DEV_LOOKUP_ARGS(args);
16051606
struct inode *inode = file_inode(file);
16061607
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
16071608
u64 new_size;
@@ -1657,7 +1658,8 @@ static noinline int btrfs_ioctl_resize(struct file *file,
16571658
btrfs_info(fs_info, "resizing devid %llu", devid);
16581659
}
16591660

1660-
device = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL);
1661+
args.devid = devid;
1662+
device = btrfs_find_device(fs_info->fs_devices, &args);
16611663
if (!device) {
16621664
btrfs_info(fs_info, "resizer unable to find device %llu",
16631665
devid);
@@ -3317,22 +3319,21 @@ static long btrfs_ioctl_fs_info(struct btrfs_fs_info *fs_info,
33173319
static long btrfs_ioctl_dev_info(struct btrfs_fs_info *fs_info,
33183320
void __user *arg)
33193321
{
3322+
BTRFS_DEV_LOOKUP_ARGS(args);
33203323
struct btrfs_ioctl_dev_info_args *di_args;
33213324
struct btrfs_device *dev;
33223325
int ret = 0;
3323-
char *s_uuid = NULL;
33243326

33253327
di_args = memdup_user(arg, sizeof(*di_args));
33263328
if (IS_ERR(di_args))
33273329
return PTR_ERR(di_args);
33283330

3331+
args.devid = di_args->devid;
33293332
if (!btrfs_is_empty_uuid(di_args->uuid))
3330-
s_uuid = di_args->uuid;
3333+
args.uuid = di_args->uuid;
33313334

33323335
rcu_read_lock();
3333-
dev = btrfs_find_device(fs_info->fs_devices, di_args->devid, s_uuid,
3334-
NULL);
3335-
3336+
dev = btrfs_find_device(fs_info->fs_devices, &args);
33363337
if (!dev) {
33373338
ret = -ENODEV;
33383339
goto out;

fs/btrfs/scrub.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4067,6 +4067,7 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
40674067
u64 end, struct btrfs_scrub_progress *progress,
40684068
int readonly, int is_dev_replace)
40694069
{
4070+
struct btrfs_dev_lookup_args args = { .devid = devid };
40704071
struct scrub_ctx *sctx;
40714072
int ret;
40724073
struct btrfs_device *dev;
@@ -4114,7 +4115,7 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
41144115
goto out_free_ctx;
41154116

41164117
mutex_lock(&fs_info->fs_devices->device_list_mutex);
4117-
dev = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL);
4118+
dev = btrfs_find_device(fs_info->fs_devices, &args);
41184119
if (!dev || (test_bit(BTRFS_DEV_STATE_MISSING, &dev->dev_state) &&
41194120
!is_dev_replace)) {
41204121
mutex_unlock(&fs_info->fs_devices->device_list_mutex);
@@ -4287,11 +4288,12 @@ int btrfs_scrub_cancel_dev(struct btrfs_device *dev)
42874288
int btrfs_scrub_progress(struct btrfs_fs_info *fs_info, u64 devid,
42884289
struct btrfs_scrub_progress *progress)
42894290
{
4291+
struct btrfs_dev_lookup_args args = { .devid = devid };
42904292
struct btrfs_device *dev;
42914293
struct scrub_ctx *sctx = NULL;
42924294

42934295
mutex_lock(&fs_info->fs_devices->device_list_mutex);
4294-
dev = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL);
4296+
dev = btrfs_find_device(fs_info->fs_devices, &args);
42954297
if (dev)
42964298
sctx = dev->scrub_ctx;
42974299
if (sctx)

0 commit comments

Comments
 (0)