@@ -507,13 +507,13 @@ static int btrfs_free_stale_devices(dev_t devt, struct btrfs_device *skip_device
{
struct btrfs_fs_devices *fs_devices, *tmp_fs_devices;
struct btrfs_device *device, *tmp_device;
- int ret = 0;
+ int ret;
+ bool freed = false;
lockdep_assert_held(&uuid_mutex);
- if (devt)
- ret = -ENOENT;
-
+ /* Return good status if there is no instance of devt. */
+ ret = 0;
list_for_each_entry_safe(fs_devices, tmp_fs_devices, &fs_uuids, fs_list) {
mutex_lock(&fs_devices->device_list_mutex);
@@ -524,8 +524,7 @@ static int btrfs_free_stale_devices(dev_t devt, struct btrfs_device *skip_device
if (devt && devt != device->devt)
continue;
if (fs_devices->opened) {
- /* for an already deleted device return 0 */
- if (devt && ret != 0)
+ if (devt)
ret = -EBUSY;
break;
}
@@ -535,7 +534,7 @@ static int btrfs_free_stale_devices(dev_t devt, struct btrfs_device *skip_device
list_del(&device->dev_list);
btrfs_free_device(device);
- ret = 0;
+ freed = true;
}
mutex_unlock(&fs_devices->device_list_mutex);
@@ -546,6 +545,10 @@ static int btrfs_free_stale_devices(dev_t devt, struct btrfs_device *skip_device
}
}
+ /* If there is atleast one freed device return 0 */
+ if (freed)
+ return 0;
+
return ret;
}
In commit d41f57d15a90 ("btrfs: scan but don't register device on single device filesystem"), the code scans the device but refrains from registering the single device filesystem. Consequently, there's no reason to report an error when running the 'btrfs device scan --forget <dev>' command for a single device if 'dev' is not present in the device_list. In such cases, returning success is the appropriate. Signed-off-by: Anand Jain <anand.jain@oracle.com> --- This patch fixes the failure reported by the test cases in btrfs/254, due to the kernel commit d41f57d15a90. So this can be folded into it. fs/btrfs/volumes.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)