diff mbox series

btrfs: scan forget for no instance of dev

Message ID d18a400b7708b2405278122c264357918be3bc5d.1694503804.git.anand.jain@oracle.com (mailing list archive)
State New, archived
Headers show
Series btrfs: scan forget for no instance of dev | expand

Commit Message

Anand Jain Sept. 12, 2023, 7:39 a.m. UTC
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(-)

Comments

David Sterba Sept. 13, 2023, 4:26 p.m. UTC | #1
On Tue, Sep 12, 2023 at 03:39:59PM +0800, Anand Jain wrote:
> 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.

Right.

> 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.

Folded, thanks.
diff mbox series

Patch

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 53dcb8f17253..cc2b21a90106 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -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;
 }