Skip to content

Commit 6e927ce

Browse files
asjkdave
authored andcommitted
btrfs: cleanup btrfs_find_device_by_devspec()
btrfs_find_device_by_devspec() finds the device by @devid or by @device_path. This patch makes code flow easy to read by open coding the else part and renames devpath to device_path. Signed-off-by: Anand Jain <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent d95a830 commit 6e927ce

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

fs/btrfs/volumes.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2402,32 +2402,33 @@ static struct btrfs_device *btrfs_find_device_by_path(
24022402
* Lookup a device given by device id, or the path if the id is 0.
24032403
*/
24042404
struct btrfs_device *btrfs_find_device_by_devspec(
2405-
struct btrfs_fs_info *fs_info, u64 devid, const char *devpath)
2405+
struct btrfs_fs_info *fs_info, u64 devid,
2406+
const char *device_path)
24062407
{
24072408
struct btrfs_device *device;
24082409

24092410
if (devid) {
24102411
device = btrfs_find_device(fs_info, devid, NULL, NULL);
24112412
if (!device)
24122413
return ERR_PTR(-ENOENT);
2413-
} else {
2414-
if (!devpath || !devpath[0])
2415-
return ERR_PTR(-EINVAL);
2416-
2417-
if (strcmp(devpath, "missing") == 0) {
2418-
list_for_each_entry(device, &fs_info->fs_devices->devices,
2419-
dev_list) {
2420-
if (test_bit(BTRFS_DEV_STATE_IN_FS_METADATA,
2421-
&device->dev_state) &&
2422-
!device->bdev)
2423-
return device;
2424-
}
2425-
return ERR_PTR(-ENOENT);
2426-
} else {
2427-
device = btrfs_find_device_by_path(fs_info, devpath);
2414+
return device;
2415+
}
2416+
2417+
if (!device_path || !device_path[0])
2418+
return ERR_PTR(-EINVAL);
2419+
2420+
if (strcmp(device_path, "missing") == 0) {
2421+
/* Find first missing device */
2422+
list_for_each_entry(device, &fs_info->fs_devices->devices,
2423+
dev_list) {
2424+
if (test_bit(BTRFS_DEV_STATE_IN_FS_METADATA,
2425+
&device->dev_state) && !device->bdev)
2426+
return device;
24282427
}
2428+
return ERR_PTR(-ENOENT);
24292429
}
2430-
return device;
2430+
2431+
return btrfs_find_device_by_path(fs_info, device_path);
24312432
}
24322433

24332434
/*

0 commit comments

Comments
 (0)