Skip to content

Commit 5578b68

Browse files
josefbacikgregkh
authored andcommitted
btrfs: handle device lookup with btrfs_dev_lookup_args
[ Upstream commit 562d7b1 ] 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]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 09674bf commit 5578b68

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
@@ -1657,6 +1657,7 @@ static int exclop_start_or_cancel_reloc(struct btrfs_fs_info *fs_info,
16571657
static noinline int btrfs_ioctl_resize(struct file *file,
16581658
void __user *arg)
16591659
{
1660+
BTRFS_DEV_LOOKUP_ARGS(args);
16601661
struct inode *inode = file_inode(file);
16611662
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
16621663
u64 new_size;
@@ -1712,7 +1713,8 @@ static noinline int btrfs_ioctl_resize(struct file *file,
17121713
btrfs_info(fs_info, "resizing devid %llu", devid);
17131714
}
17141715

1715-
device = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL);
1716+
args.devid = devid;
1717+
device = btrfs_find_device(fs_info->fs_devices, &args);
17161718
if (!device) {
17171719
btrfs_info(fs_info, "resizer unable to find device %llu",
17181720
devid);
@@ -3375,22 +3377,21 @@ static long btrfs_ioctl_fs_info(struct btrfs_fs_info *fs_info,
33753377
static long btrfs_ioctl_dev_info(struct btrfs_fs_info *fs_info,
33763378
void __user *arg)
33773379
{
3380+
BTRFS_DEV_LOOKUP_ARGS(args);
33783381
struct btrfs_ioctl_dev_info_args *di_args;
33793382
struct btrfs_device *dev;
33803383
int ret = 0;
3381-
char *s_uuid = NULL;
33823384

33833385
di_args = memdup_user(arg, sizeof(*di_args));
33843386
if (IS_ERR(di_args))
33853387
return PTR_ERR(di_args);
33863388

3389+
args.devid = di_args->devid;
33873390
if (!btrfs_is_empty_uuid(di_args->uuid))
3388-
s_uuid = di_args->uuid;
3391+
args.uuid = di_args->uuid;
33893392

33903393
rcu_read_lock();
3391-
dev = btrfs_find_device(fs_info->fs_devices, di_args->devid, s_uuid,
3392-
NULL);
3393-
3394+
dev = btrfs_find_device(fs_info->fs_devices, &args);
33943395
if (!dev) {
33953396
ret = -ENODEV;
33963397
goto out;

fs/btrfs/scrub.c

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

41174118
mutex_lock(&fs_info->fs_devices->device_list_mutex);
4118-
dev = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL);
4119+
dev = btrfs_find_device(fs_info->fs_devices, &args);
41194120
if (!dev || (test_bit(BTRFS_DEV_STATE_MISSING, &dev->dev_state) &&
41204121
!is_dev_replace)) {
41214122
mutex_unlock(&fs_info->fs_devices->device_list_mutex);
@@ -4288,11 +4289,12 @@ int btrfs_scrub_cancel_dev(struct btrfs_device *dev)
42884289
int btrfs_scrub_progress(struct btrfs_fs_info *fs_info, u64 devid,
42894290
struct btrfs_scrub_progress *progress)
42904291
{
4292+
struct btrfs_dev_lookup_args args = { .devid = devid };
42914293
struct btrfs_device *dev;
42924294
struct scrub_ctx *sctx = NULL;
42934295

42944296
mutex_lock(&fs_info->fs_devices->device_list_mutex);
4295-
dev = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL);
4297+
dev = btrfs_find_device(fs_info->fs_devices, &args);
42964298
if (dev)
42974299
sctx = dev->scrub_ctx;
42984300
if (sctx)

0 commit comments

Comments
 (0)