Skip to content

Commit a27a94c

Browse files
lorddoskiaskdave
authored andcommitted
btrfs: Make btrfs_find_device_by_devspec return btrfs_device directly
Instead of returning an error value and using one of the parameters for returning the actual object we are interested in just refactor the function to directly return btrfs_device *. Also bubble up the error handling for the special BTRFS_ERROR_DEV_MISSING_NOT_FOUND value into btrfs_rm_device. No functional changes. Signed-off-by: Nikolay Borisov <[email protected]> Reviewed-by: Qu Wenruo <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 6c05040 commit a27a94c

File tree

3 files changed

+25
-28
lines changed

3 files changed

+25
-28
lines changed

fs/btrfs/dev-replace.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -409,10 +409,10 @@ int btrfs_dev_replace_start(struct btrfs_fs_info *fs_info,
409409
struct btrfs_device *tgt_device = NULL;
410410
struct btrfs_device *src_device = NULL;
411411

412-
ret = btrfs_find_device_by_devspec(fs_info, srcdevid,
413-
srcdev_name, &src_device);
414-
if (ret)
415-
return ret;
412+
src_device = btrfs_find_device_by_devspec(fs_info, srcdevid,
413+
srcdev_name);
414+
if (IS_ERR(src_device))
415+
return PTR_ERR(src_device);
416416

417417
ret = btrfs_init_dev_replace_tgtdev(fs_info, tgtdev_name,
418418
src_device, &tgt_device);

fs/btrfs/volumes.c

+18-21
Original file line numberDiff line numberDiff line change
@@ -1889,10 +1889,16 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, const char *device_path,
18891889
if (ret)
18901890
goto out;
18911891

1892-
ret = btrfs_find_device_by_devspec(fs_info, devid, device_path,
1893-
&device);
1894-
if (ret)
1892+
device = btrfs_find_device_by_devspec(fs_info, devid, device_path);
1893+
1894+
if (IS_ERR(device)) {
1895+
if (PTR_ERR(device) == -ENOENT &&
1896+
strcmp(device_path, "missing") == 0)
1897+
ret = BTRFS_ERROR_DEV_MISSING_NOT_FOUND;
1898+
else
1899+
ret = PTR_ERR(device);
18951900
goto out;
1901+
}
18961902

18971903
if (test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state)) {
18981904
ret = BTRFS_ERROR_DEV_TGT_REPLACE;
@@ -2163,30 +2169,21 @@ static struct btrfs_device *btrfs_find_device_missing_or_by_path(
21632169
/*
21642170
* Lookup a device given by device id, or the path if the id is 0.
21652171
*/
2166-
int btrfs_find_device_by_devspec(struct btrfs_fs_info *fs_info, u64 devid,
2167-
const char *devpath,
2168-
struct btrfs_device **device)
2172+
struct btrfs_device *btrfs_find_device_by_devspec(
2173+
struct btrfs_fs_info *fs_info, u64 devid, const char *devpath)
21692174
{
2170-
int ret = 0;
2175+
struct btrfs_device *device;
21712176

21722177
if (devid) {
2173-
*device = btrfs_find_device(fs_info, devid, NULL, NULL);
2174-
if (!*device)
2175-
ret = -ENOENT;
2178+
device = btrfs_find_device(fs_info, devid, NULL, NULL);
2179+
if (!device)
2180+
return ERR_PTR(-ENOENT);
21762181
} else {
21772182
if (!devpath || !devpath[0])
2178-
return -EINVAL;
2179-
2180-
*device = btrfs_find_device_missing_or_by_path(fs_info, devpath);
2181-
if (IS_ERR(*device)) {
2182-
if (PTR_ERR(*device) == -ENOENT &&
2183-
strcmp(devpath, "missing") == 0)
2184-
ret = BTRFS_ERROR_DEV_MISSING_NOT_FOUND;
2185-
else
2186-
ret = PTR_ERR(*device);
2187-
}
2183+
return ERR_PTR(-EINVAL);
2184+
device = btrfs_find_device_missing_or_by_path(fs_info, devpath);
21882185
}
2189-
return ret;
2186+
return device;
21902187
}
21912188

21922189
/*

fs/btrfs/volumes.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,9 @@ int btrfs_close_devices(struct btrfs_fs_devices *fs_devices);
410410
void btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices, int step);
411411
void btrfs_assign_next_active_device(struct btrfs_device *device,
412412
struct btrfs_device *this_dev);
413-
int btrfs_find_device_by_devspec(struct btrfs_fs_info *fs_info, u64 devid,
414-
const char *devpath,
415-
struct btrfs_device **device);
413+
struct btrfs_device *btrfs_find_device_by_devspec(struct btrfs_fs_info *fs_info,
414+
u64 devid,
415+
const char *devpath);
416416
struct btrfs_device *btrfs_alloc_device(struct btrfs_fs_info *fs_info,
417417
const u64 *devid,
418418
const u8 *uuid);

0 commit comments

Comments
 (0)