Commit 6c050407 authored by Nikolay Borisov's avatar Nikolay Borisov Committed by David Sterba

btrfs: Make btrfs_find_device_missing_or_by_path return directly a device

This function returns a numeric error value and additionally the
device found in one of its input parameters. Simplify this by making
the function directly return a pointer to btrfs_device. Additionally
adjust the caller to handle the case when we want to remove the
'missing' device and ENOENT is returned to return the expected
positive error value, parsed by progs. Finally, unexport the function
since it's not called outside of volume.c. No functional changes.
Signed-off-by: default avatarNikolay Borisov <nborisov@suse.com>
Reviewed-by: default avatarQu Wenruo <wqu@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent b444ad46
...@@ -2134,11 +2134,10 @@ static struct btrfs_device *btrfs_find_device_by_path( ...@@ -2134,11 +2134,10 @@ static struct btrfs_device *btrfs_find_device_by_path(
return device; return device;
} }
int btrfs_find_device_missing_or_by_path(struct btrfs_fs_info *fs_info, static struct btrfs_device *btrfs_find_device_missing_or_by_path(
const char *device_path, struct btrfs_fs_info *fs_info, const char *device_path)
struct btrfs_device **device)
{ {
*device = NULL; struct btrfs_device *device = NULL;
if (strcmp(device_path, "missing") == 0) { if (strcmp(device_path, "missing") == 0) {
struct list_head *devices; struct list_head *devices;
struct btrfs_device *tmp; struct btrfs_device *tmp;
...@@ -2147,20 +2146,18 @@ int btrfs_find_device_missing_or_by_path(struct btrfs_fs_info *fs_info, ...@@ -2147,20 +2146,18 @@ int btrfs_find_device_missing_or_by_path(struct btrfs_fs_info *fs_info,
list_for_each_entry(tmp, devices, dev_list) { list_for_each_entry(tmp, devices, dev_list) {
if (test_bit(BTRFS_DEV_STATE_IN_FS_METADATA, if (test_bit(BTRFS_DEV_STATE_IN_FS_METADATA,
&tmp->dev_state) && !tmp->bdev) { &tmp->dev_state) && !tmp->bdev) {
*device = tmp; device = tmp;
break; break;
} }
} }
if (!*device) if (!device)
return BTRFS_ERROR_DEV_MISSING_NOT_FOUND; return ERR_PTR(-ENOENT);
} else { } else {
*device = btrfs_find_device_by_path(fs_info, device_path); device = btrfs_find_device_by_path(fs_info, device_path);
if (IS_ERR(*device))
return PTR_ERR(*device);
} }
return 0; return device;
} }
/* /*
...@@ -2170,10 +2167,9 @@ int btrfs_find_device_by_devspec(struct btrfs_fs_info *fs_info, u64 devid, ...@@ -2170,10 +2167,9 @@ int btrfs_find_device_by_devspec(struct btrfs_fs_info *fs_info, u64 devid,
const char *devpath, const char *devpath,
struct btrfs_device **device) struct btrfs_device **device)
{ {
int ret; int ret = 0;
if (devid) { if (devid) {
ret = 0;
*device = btrfs_find_device(fs_info, devid, NULL, NULL); *device = btrfs_find_device(fs_info, devid, NULL, NULL);
if (!*device) if (!*device)
ret = -ENOENT; ret = -ENOENT;
...@@ -2181,8 +2177,14 @@ int btrfs_find_device_by_devspec(struct btrfs_fs_info *fs_info, u64 devid, ...@@ -2181,8 +2177,14 @@ int btrfs_find_device_by_devspec(struct btrfs_fs_info *fs_info, u64 devid,
if (!devpath || !devpath[0]) if (!devpath || !devpath[0])
return -EINVAL; return -EINVAL;
ret = btrfs_find_device_missing_or_by_path(fs_info, devpath, *device = btrfs_find_device_missing_or_by_path(fs_info, devpath);
device); if (IS_ERR(*device)) {
if (PTR_ERR(*device) == -ENOENT &&
strcmp(devpath, "missing") == 0)
ret = BTRFS_ERROR_DEV_MISSING_NOT_FOUND;
else
ret = PTR_ERR(*device);
}
} }
return ret; return ret;
} }
......
...@@ -410,9 +410,6 @@ int btrfs_close_devices(struct btrfs_fs_devices *fs_devices); ...@@ -410,9 +410,6 @@ int btrfs_close_devices(struct btrfs_fs_devices *fs_devices);
void btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices, int step); void btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices, int step);
void btrfs_assign_next_active_device(struct btrfs_device *device, void btrfs_assign_next_active_device(struct btrfs_device *device,
struct btrfs_device *this_dev); struct btrfs_device *this_dev);
int btrfs_find_device_missing_or_by_path(struct btrfs_fs_info *fs_info,
const char *device_path,
struct btrfs_device **device);
int btrfs_find_device_by_devspec(struct btrfs_fs_info *fs_info, u64 devid, int btrfs_find_device_by_devspec(struct btrfs_fs_info *fs_info, u64 devid,
const char *devpath, const char *devpath,
struct btrfs_device **device); struct btrfs_device **device);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment