preparatory work to add device forget
v3 cover preparatory work to add device forget
v2->v3:
@ 6/6:
add btrfs_free_stale_device() fn description, suggested by Nikolay Fix line with longer than 80 char
v1->v2:
@ 6/6:
btrfs_device::name is null when we have missing device and unmounted. So we still need to check for dev->name.
We can reuse the function btrfs_free_stale_device() to add feature to forget a scanned device or all stale devices. So this patch set proposes following changes to it.
Anand Jain (6):
btrfs: cleanup btrfs_free_stale_device() usage
btrfs: no need to check for btrfs_fs_devices::seeding
btrfs: make btrfs_free_stale_device() to delete all stales
btrfs: make btrfs_free_stale_device() argument optional
btrfs: make btrfs_free_stale_device() to search given path
btrfs: cleanup to make btrfs_free_stale_device() readable
fs/btrfs/volumes.c | 50 +++++++++++++++----------------------------------- 1 file changed, 15 insertions(+), 35 deletions(-)
Signature · 1 line
2.7.0
PATCH v3 1/6 btrfs: cleanup btrfs_free_stale_device() usage
We call btrfs_free_stale_device() only when we alloc a new struct btrfs_device (ret=1), so move it closer to where we alloc the new device. Also drop the comments.
--- fs/btrfs/volumes.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
fs/btrfs/volumes.c +1 -7
@@ -782,6 +782,7 @@ static noinline int device_list_add(const char *path, ret =1 ; device->fs_devices = fs_devices; +btrfs_free_stale_device (device); }else if (!device->name ||strcmp (device->name->str, path)) {/* * When FS is already mounted.
@@ -840,13 +841,6 @@ static noinline int device_list_add(const char *path,if (!fs_devices->opened) device->generation = found_transid; -/* -* if there is new btrfs on an already registered device, -* then remove the stale device entry. -*/ -if (ret >0 ) -btrfs_free_stale_device (device); - *fs_devices_ret = fs_devices;return ret;
Signature · 1 line
2.7.0
Re: [PATCH 1/6] btrfs: cleanup btrfs_free_stale_device() usage
Quoted 5 lines · Anand Jain
We call
btrfs_free_stale_device()only when we alloc a new structbtrfs_device(ret=1), so move it closer to where we alloc the new device. Also drop the comments.Signed-off-by Anand Jain <[email protected]>
Thanks,
Josef
PATCH v3 2/6 btrfs: no need to check for btrfs_fs_devices::seeding
In reply to Anand JainThere is no need to check for btrfs_fs_devices::seeding when we have checked for btrfs_fs_devices::opened, because we can't sprout without its seed FS being opened.
--- fs/btrfs/volumes.c | 2 -- 1 file changed, 2 deletions(-)
fs/btrfs/volumes.c +0 -2
@@ -619,8 +619,6 @@ static void btrfs_free_stale_device(struct btrfs_device *cur_dev)if (fs_devs->opened)continue ; -if (fs_devs->seeding) -continue ;list_for_each_entry (dev, &fs_devs->devices, dev_list) {
Signature · 1 line
2.7.0
Re: [PATCH 2/6] btrfs: no need to check for btrfs_fs_devices::seeding
Quoted 5 lines · Anand Jain
There is no need to check for
btrfs_fs_devices::seedingwhen we have checked forbtrfs_fs_devices::opened, because we can't sprout without its seed FS being opened.Signed-off-by Anand Jain <[email protected]>
Thanks,
Josef
PATCH v3 3/6 btrfs: make btrfs_free_stale_device() to iterate all stales
In reply to Anand JainFrom: Anand Jain <[email protected]>
Let the list iterator iterate further and find other stale devices and delete it. This is in preparation to add support for user land request-able stale devices cleanup.
--- fs/btrfs/volumes.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)
fs/btrfs/volumes.c +9 -11
@@ -608,19 +608,20 @@ static void pending_bios_fn(struct btrfs_work *work)static void btrfs_free_stale_device (struct btrfs_device *cur_dev) { -struct btrfs_fs_devices *fs_devs; -struct btrfs_device *dev; +struct btrfs_fs_devices *fs_devs, *tmp_fs_devs; +struct btrfs_device *dev, *tmp_dev;if (!cur_dev->name)return ; -list_for_each_entry (fs_devs, &fs_uuids, list) { -int del =1 ; +list_for_each_entry_safe (fs_devs, tmp_fs_devs, &fs_uuids, list) {if (fs_devs->opened)continue ; -list_for_each_entry (dev, &fs_devs->devices, dev_list) { +list_for_each_entry_safe (dev, tmp_dev, + &fs_devs->devices, dev_list) { +int not_found;if (dev == cur_dev)continue ;
@@ -634,14 +635,12 @@ static void btrfs_free_stale_device(struct btrfs_device *cur_dev)* either use mapper or non mapper path throughout. */ rcu_read_lock (); - del =strcmp (rcu_str_deref (dev->name), + not_found =strcmp (rcu_str_deref (dev->name),rcu_str_deref (cur_dev->name));rcu_read_unlock (); -if (!del) -break ; - } +if (not_found) +continue ; -if (!del) {/* delete the stale device */ if (fs_devs->num_devices ==1 ) {btrfs_sysfs_remove_fsid (fs_devs);
@@ -652,7 +651,6 @@ static void btrfs_free_stale_device(struct btrfs_device *cur_dev)list_del (&dev->dev_list);free_device (dev); } -break ; } } }
Signature · 1 line
2.7.0
Re: [PATCH 3/6] btrfs: make btrfs_free_stale_device() to iterate all stales
Quoted 7 lines · Anand Jain
From: Anand Jain <[email protected]>
Let the list iterator iterate further and find other stale devices and delete it. This is in preparation to add support for user land request-able stale devices cleanup.
Signed-off-by Anand Jain <[email protected]>
If we're going to do this then please change the function name to btrfs_free_stale_devices() so it's clear what its intentions are. Thanks,
Josef
PATCH v3 4/6 btrfs: make btrfs_free_stale_device() argument optional
In reply to Anand JainFrom: Anand Jain <[email protected]>
This updates btrfs_free_stale_device() helper function to delete all unmouted devices, when arg is NULL.
--- fs/btrfs/volumes.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
fs/btrfs/volumes.c +6 -8
@@ -611,9 +611,6 @@ static void btrfs_free_stale_device(struct btrfs_device *cur_dev)struct btrfs_fs_devices *fs_devs, *tmp_fs_devs;struct btrfs_device *dev, *tmp_dev; -if (!cur_dev->name) -return ; -list_for_each_entry_safe (fs_devs, tmp_fs_devs, &fs_uuids, list) {if (fs_devs->opened)
@@ -623,9 +620,7 @@ static void btrfs_free_stale_device(struct btrfs_device *cur_dev) &fs_devs->devices, dev_list) {int not_found; -if (dev == cur_dev) -continue ; -if (!dev->name) +if (cur_dev && (cur_dev == dev || !dev->name))continue ;/*
@@ -635,8 +630,11 @@ static void btrfs_free_stale_device(struct btrfs_device *cur_dev)* either use mapper or non mapper path throughout. */ rcu_read_lock (); - not_found =strcmp (rcu_str_deref (dev->name), -rcu_str_deref (cur_dev->name)); +if (cur_dev) + not_found =strcmp (rcu_str_deref (dev->name), +rcu_str_deref (cur_dev->name)); +else + not_found =0 ;rcu_read_unlock ();if (not_found)continue ;
Signature · 1 line
2.7.0
Re: [PATCH 4/6] btrfs: make btrfs_free_stale_device() argument optional
Quoted 25 lines · Anand Jain
From: Anand Jain <[email protected]>
This updates
btrfs_free_stale_device()helper function to delete all unmouted devices, when arg is NULL.Signed-off-by Anand Jain <[email protected]>--- fs/btrfs/volumes.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)fs/btrfs/volumes.c +0
-3@@ -611,9 +611,6 @@ static void btrfs_free_stale_device(struct btrfs_device *cur_dev)struct btrfs_fs_devices *fs_devs, *tmp_fs_devs;struct btrfs_device *dev, *tmp_dev; -if (!cur_dev->name) -return ; -list_for_each_entry_safe (fs_devs, tmp_fs_devs, &fs_uuids, list) {if (fs_devs->opened)
fs/btrfs/volumes.c static void btrfs_free_stale_device(struct btrfs_device *cur_dev) · line 621
Quoted 2 lines
fs/btrfs/volumes.c +0
-0@@ -623,9 +620,7 @@ static void btrfs_free_stale_device(struct btrfs_device *cur_dev) &fs_devs->devices, dev_list) {int not_found;
Change this to
int not_found = 0;
Quoted 9 lines
fs/btrfs/volumes.c +1
-3-if (dev == cur_dev) -continue ; -if (!dev->name) +if (cur_dev && (cur_dev == dev || !dev->name))continue ;/*
fs/btrfs/volumes.c static void btrfs_free_stale_device(struct btrfs_device *cur_dev) · line 637
Quoted 10 lines
fs/btrfs/volumes.c +5
-2@@ -635,8 +630,11 @@ static void btrfs_free_stale_device(struct btrfs_device *cur_dev)* either use mapper or non mapper path throughout. */ rcu_read_lock (); - not_found =strcmp (rcu_str_deref (dev->name), -rcu_str_deref (cur_dev->name)); +if (cur_dev) + not_found =strcmp (rcu_str_deref (dev->name), +rcu_str_deref (cur_dev->name)); +else + not_found =0 ;
And drop the else part of this. Thanks,
Josef
PATCH v3 5/6 btrfs: make btrfs_free_stale_device() to match the path
In reply to Anand JainFrom: Anand Jain <[email protected]>
The btrfs_free_stale_device() is updated to match for the given device path and delete it. (It searchs for only unmounted list of devices.)
--- fs/btrfs/volumes.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/btrfs/volumes.c +4 -2
@@ -606,7 +606,7 @@ static void pending_bios_fn(struct btrfs_work *work) } -static void btrfs_free_stale_device (struct btrfs_device *cur_dev) +static void btrfs_free_stale_device (struct btrfs_device *cur_dev,char *path) {struct btrfs_fs_devices *fs_devs, *tmp_fs_devs;struct btrfs_device *dev, *tmp_dev;
@@ -633,6 +633,8 @@ static void btrfs_free_stale_device(struct btrfs_device *cur_dev)if (cur_dev) not_found =strcmp (rcu_str_deref (dev->name),rcu_str_deref (cur_dev->name)); +else if (path) + not_found =strcmp (rcu_str_deref (dev->name), path);else not_found =0 ;rcu_read_unlock ();
@@ -776,7 +778,7 @@ static noinline int device_list_add(const char *path, ret =1 ; device->fs_devices = fs_devices; -btrfs_free_stale_device (device); +btrfs_free_stale_device (device,NULL ); }else if (!device->name ||strcmp (device->name->str, path)) {/* * When FS is already mounted.
Signature · 1 line
2.7.0
Re: [PATCH 5/6] btrfs: make btrfs_free_stale_device() to match the path
Quoted 7 lines · Anand Jain
From: Anand Jain <[email protected]>
The
btrfs_free_stale_device()is updated to match for the given device path and delete it. (It searchs for only unmounted list of devices.)Signed-off-by Anand Jain <[email protected]>
Thanks,
Josef
PATCH v3 6/6 btrfs: cleanup to make btrfs_free_stale_device() readable
In reply to Anand JainFrom: Anand Jain <[email protected]>
Now as the there is path in arg, so instead of reading the path from cur_device just get it from the caller, and so the purpose of cur_device is to skip the device, so rename it to skip_dev. Also drop the comment about different path being used for the same device, since now we will have cli to clean any device that's not a concern any more.
---
v3: add btrfs_free_stale_device() fn description, as suggested by
Nikolay
Fix line with longer than 80 char
v2: btrfs_device::name is null when we have missing device and
unmounted. So we still need to check for dev->name.
fs/btrfs/volumes.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-)
fs/btrfs/volumes.c +16 -14
@@ -605,8 +605,17 @@ static void pending_bios_fn(struct btrfs_work *work)run_scheduled_bios (device); } - -static void btrfs_free_stale_device (struct btrfs_device *cur_dev,char *path) +/* +* btrfs_free_stale_device() +* Search and remove all stale (devices which are not mounted) devices. +* When both inputs are NULL, it will search and release all stale devices. +* path: Optional. When provided will it release all unmounted devices +* matching this path only. +* skip_dev: Optional. Will skip this device when searching for the stale +* devices. +*/ +static void btrfs_free_stale_device (const char *path, +struct btrfs_device *skip_dev) {struct btrfs_fs_devices *fs_devs, *tmp_fs_devs;struct btrfs_device *dev, *tmp_dev;
@@ -620,20 +629,13 @@ static void btrfs_free_stale_device(struct btrfs_device *cur_dev, char *path) &fs_devs->devices, dev_list) {int not_found; -if (cur_dev && (cur_dev == dev || !dev->name)) +if (skip_dev && skip_dev == dev) +continue ; +if (path && !dev->name)continue ; -/* -* Todo: This won't be enough. What if the same device -* comes back (with new uuid and) with its mapper path? -* But for now, this does help as mostly an admin will -* either use mapper or non mapper path throughout. -*/ rcu_read_lock (); -if (cur_dev) - not_found =strcmp (rcu_str_deref (dev->name), -rcu_str_deref (cur_dev->name)); -else if (path) +if (path) not_found =strcmp (rcu_str_deref (dev->name), path);else not_found =0 ;
@@ -778,7 +780,7 @@ static noinline int device_list_add(const char *path, ret =1 ; device->fs_devices = fs_devices; -btrfs_free_stale_device (device,NULL ); +btrfs_free_stale_device (path, device); }else if (!device->name ||strcmp (device->name->str, path)) {/* * When FS is already mounted.
Signature · 1 line
2.7.0
Re: [PATCH 6/6] btrfs: cleanup to make btrfs_free_stale_device() readable
Quoted 9 lines · Anand Jain
From: Anand Jain <[email protected]>
Now as the there is path in arg, so instead of reading the path from
cur_devicejust get it from the caller, and so the purpose ofcur_deviceis to skip the device, so rename it toskip_dev. Also drop the comment about different path being used for the same device, since now we will have cli to clean any device that's not a concern any more.Signed-off-by Anand Jain <[email protected]>
Wait you added char *path, and then changed it to device here? Just drop the previous patch and do this one. Thanks,
Josef