diff mbox series

[2/5] btrfs: Factor out loop logic from btrfs_free_extra_devids

Message ID 20200715104850.19071-3-nborisov@suse.com (mailing list archive)
State New, archived
Headers show
Series Convert seed devices to proper list API | expand

Commit Message

Nikolay Borisov July 15, 2020, 10:48 a.m. UTC
This prepares the code to switching seeds devices to a proper list.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 fs/btrfs/volumes.c | 34 +++++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 13 deletions(-)

Comments

kernel test robot July 15, 2020, 12:32 p.m. UTC | #1
Hi Nikolay,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on kdave/for-next]
[also build test WARNING on v5.8-rc5 next-20200715]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Nikolay-Borisov/Convert-seed-devices-to-proper-list-API/20200715-185102
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next
config: x86_64-rhel-7.6-kselftests (attached as .config)
compiler: gcc-9 (Debian 9.3.0-14) 9.3.0
reproduce (this is a W=1 build):
        # save the attached .config to linux build tree
        make W=1 ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   In file included from fs/btrfs/volumes.c:17:
   fs/btrfs/ctree.h:2271:8: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
    2271 | size_t __const btrfs_get_num_csums(void);
         |        ^~~~~~~
   In file included from fs/btrfs/volumes.c:28:
   fs/btrfs/sysfs.h:16:1: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
      16 | const char * const btrfs_feature_set_name(enum btrfs_feature_set set);
         | ^~~~~
>> fs/btrfs/volumes.c:1029:6: warning: no previous prototype for '__btrfs_free_extra_devids' [-Wmissing-prototypes]
    1029 | void __btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices, int step,
         |      ^~~~~~~~~~~~~~~~~~~~~~~~~

vim +/__btrfs_free_extra_devids +1029 fs/btrfs/volumes.c

  1026	
  1027	
  1028	
> 1029	void __btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices, int step,
  1030				       struct btrfs_device **latest_dev)
  1031	{
  1032		struct btrfs_device *device, *next;
  1033	
  1034		/* This is the initialized path, it is safe to release the devices. */
  1035		list_for_each_entry_safe(device, next, &fs_devices->devices, dev_list) {
  1036			if (test_bit(BTRFS_DEV_STATE_IN_FS_METADATA,
  1037				     &device->dev_state)) {
  1038				if (!test_bit(BTRFS_DEV_STATE_REPLACE_TGT,
  1039					      &device->dev_state) &&
  1040				    !test_bit(BTRFS_DEV_STATE_MISSING,
  1041					      &device->dev_state) &&
  1042				    (!*latest_dev ||
  1043				     device->generation > (*latest_dev)->generation)) {
  1044					*latest_dev = device;
  1045				}
  1046				continue;
  1047			}
  1048	
  1049			if (device->devid == BTRFS_DEV_REPLACE_DEVID) {
  1050				/*
  1051				 * In the first step, keep the device which has
  1052				 * the correct fsid and the devid that is used
  1053				 * for the dev_replace procedure.
  1054				 * In the second step, the dev_replace state is
  1055				 * read from the device tree and it is known
  1056				 * whether the procedure is really active or
  1057				 * not, which means whether this device is
  1058				 * used or whether it should be removed.
  1059				 */
  1060				if (step == 0 || test_bit(BTRFS_DEV_STATE_REPLACE_TGT,
  1061							  &device->dev_state)) {
  1062					continue;
  1063				}
  1064			}
  1065			if (device->bdev) {
  1066				blkdev_put(device->bdev, device->mode);
  1067				device->bdev = NULL;
  1068				fs_devices->open_devices--;
  1069			}
  1070			if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state)) {
  1071				list_del_init(&device->dev_alloc_list);
  1072				clear_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state);
  1073				if (!test_bit(BTRFS_DEV_STATE_REPLACE_TGT,
  1074					      &device->dev_state))
  1075					fs_devices->rw_devices--;
  1076			}
  1077			list_del_init(&device->dev_list);
  1078			fs_devices->num_devices--;
  1079			btrfs_free_device(device);
  1080		}
  1081	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Nikolay Borisov July 15, 2020, 12:39 p.m. UTC | #2
On 15.07.20 г. 15:32 ч., kernel test robot wrote:
> Hi Nikolay,
> 
> Thank you for the patch! Perhaps something to improve:
> 
> [auto build test WARNING on kdave/for-next]
> [also build test WARNING on v5.8-rc5 next-20200715]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch]
> 
> url:    https://github.com/0day-ci/linux/commits/Nikolay-Borisov/Convert-seed-devices-to-proper-list-API/20200715-185102
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next
> config: x86_64-rhel-7.6-kselftests (attached as .config)
> compiler: gcc-9 (Debian 9.3.0-14) 9.3.0
> reproduce (this is a W=1 build):
>         # save the attached .config to linux build tree
>         make W=1 ARCH=x86_64 
> 
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
> 
> All warnings (new ones prefixed by >>):
> 
>    In file included from fs/btrfs/volumes.c:17:
>    fs/btrfs/ctree.h:2271:8: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
>     2271 | size_t __const btrfs_get_num_csums(void);
>          |        ^~~~~~~
>    In file included from fs/btrfs/volumes.c:28:
>    fs/btrfs/sysfs.h:16:1: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
>       16 | const char * const btrfs_feature_set_name(enum btrfs_feature_set set);
>          | ^~~~~
>>> fs/btrfs/volumes.c:1029:6: warning: no previous prototype for '__btrfs_free_extra_devids' [-Wmissing-prototypes]
>     1029 | void __btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices, int step,
>          |      ^~~~~~~~~~~~~~~~~~~~~~~~~
> 
> vim +/__btrfs_free_extra_devids +1029 fs/btrfs/volumes.c
> 
>   1026	
>   1027	
>   1028	
>> 1029	void __btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices, int step



This function is missing a static modifier. It shouldn't be a reason to
block review.
Josef Bacik Aug. 18, 2020, 3:03 p.m. UTC | #3
On 7/15/20 6:48 AM, Nikolay Borisov wrote:
> This prepares the code to switching seeds devices to a proper list.
> 
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>

Reviewed-by: Josef Bacik <josef@toxicpanda.com>

Thanks,

Josef
diff mbox series

Patch

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index ce01e44f8134..db29fc4fbe89 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1024,28 +1024,24 @@  static struct btrfs_fs_devices *clone_fs_devices(struct btrfs_fs_devices *orig)
 	return ERR_PTR(ret);
 }
 
-/*
- * After we have read the system tree and know devids belonging to
- * this filesystem, remove the device which does not belong there.
- */
-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,
+			       struct btrfs_device **latest_dev)
 {
 	struct btrfs_device *device, *next;
-	struct btrfs_device *latest_dev = NULL;
 
-	mutex_lock(&uuid_mutex);
-again:
 	/* This is the initialized path, it is safe to release the devices. */
 	list_for_each_entry_safe(device, next, &fs_devices->devices, dev_list) {
 		if (test_bit(BTRFS_DEV_STATE_IN_FS_METADATA,
-							&device->dev_state)) {
+			     &device->dev_state)) {
 			if (!test_bit(BTRFS_DEV_STATE_REPLACE_TGT,
-			     &device->dev_state) &&
+				      &device->dev_state) &&
 			    !test_bit(BTRFS_DEV_STATE_MISSING,
 				      &device->dev_state) &&
-			     (!latest_dev ||
-			      device->generation > latest_dev->generation)) {
-				latest_dev = device;
+			    (!*latest_dev ||
+			     device->generation > (*latest_dev)->generation)) {
+				*latest_dev = device;
 			}
 			continue;
 		}
@@ -1083,6 +1079,18 @@  void btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices, int step)
 		btrfs_free_device(device);
 	}
 
+}
+/*
+ * After we have read the system tree and know devids belonging to
+ * this filesystem, remove the device which does not belong there.
+ */
+void btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices, int step)
+{
+	struct btrfs_device *latest_dev = NULL;
+
+	mutex_lock(&uuid_mutex);
+again:
+	__btrfs_free_extra_devids(fs_devices, step, &latest_dev);
 	if (fs_devices->seed) {
 		fs_devices = fs_devices->seed;
 		goto again;