diff mbox series

[md-6.12,05/41] md/md-bitmap: add 'sync_size' into struct md_bitmap_stats

Message ID 20240822024718.2158259-6-yukuai1@huaweicloud.com (mailing list archive)
State Superseded
Headers show
Series md/md-bitmap: introduce bitmap_operations and make structure internel | expand

Commit Message

Yu Kuai Aug. 22, 2024, 2:46 a.m. UTC
From: Yu Kuai <yukuai3@huawei.com>

To avoid dereferencing bitmap directly in md-cluster to prepare
inventing a new bitmap.

BTW, also fix following checkpatch warnings:

WARNING: Deprecated use of 'kmap_atomic', prefer 'kmap_local_page' instead
WARNING: Deprecated use of 'kunmap_atomic', prefer 'kunmap_local' instead

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 drivers/md/md-bitmap.c  |  6 ++++++
 drivers/md/md-bitmap.h  |  1 +
 drivers/md/md-cluster.c | 34 ++++++++++++++++++++--------------
 3 files changed, 27 insertions(+), 14 deletions(-)

Comments

kernel test robot Aug. 22, 2024, 10:07 p.m. UTC | #1
Hi Yu,

kernel test robot noticed the following build warnings:

[auto build test WARNING on device-mapper-dm/for-next]
[also build test WARNING on linus/master v6.11-rc4 next-20240822]
[cannot apply to song-md/md-next]
[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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Yu-Kuai/md-raid1-use-md_bitmap_wait_behind_writes-in-raid1_read_request/20240822-110233
base:   https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git for-next
patch link:    https://lore.kernel.org/r/20240822024718.2158259-6-yukuai1%40huaweicloud.com
patch subject: [PATCH md-6.12 05/41] md/md-bitmap: add 'sync_size' into struct md_bitmap_stats
config: x86_64-randconfig-121-20240822 (https://download.01.org/0day-ci/archive/20240823/202408230544.w18wb47U-lkp@intel.com/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240823/202408230544.w18wb47U-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202408230544.w18wb47U-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
>> drivers/md/md-bitmap.c:2106:26: sparse: sparse: incorrect type in assignment (different base types) @@     expected unsigned long sync_size @@     got restricted __le64 [usertype] sync_size @@
   drivers/md/md-bitmap.c:2106:26: sparse:     expected unsigned long sync_size
   drivers/md/md-bitmap.c:2106:26: sparse:     got restricted __le64 [usertype] sync_size
   drivers/md/md-bitmap.c: note: in included file (through include/linux/mmzone.h, include/linux/gfp.h, include/linux/xarray.h, ...):
   include/linux/page-flags.h:235:46: sparse: sparse: self-comparison always evaluates to false
   include/linux/page-flags.h:235:46: sparse: sparse: self-comparison always evaluates to false

vim +2106 drivers/md/md-bitmap.c

  2096	
  2097	int md_bitmap_get_stats(struct bitmap *bitmap, struct md_bitmap_stats *stats)
  2098	{
  2099		struct bitmap_counts *counts;
  2100		bitmap_super_t *sb;
  2101	
  2102		if (!bitmap)
  2103			return -ENOENT;
  2104	
  2105		sb = kmap_local_page(bitmap->storage.sb_page);
> 2106		stats->sync_size = sb->sync_size;
  2107		kunmap_local(sb);
  2108	
  2109		counts = &bitmap->counts;
  2110		stats->missing_pages = counts->missing_pages;
  2111		stats->pages = counts->pages;
  2112	
  2113		stats->events_cleared = bitmap->events_cleared;
  2114		stats->file = bitmap->storage.file;
  2115	
  2116		return 0;
  2117	}
  2118	EXPORT_SYMBOL_GPL(md_bitmap_get_stats);
  2119
Yu Kuai Aug. 26, 2024, 1:38 a.m. UTC | #2
Hi,

在 2024/08/23 6:07, kernel test robot 写道:
> Hi Yu,
> 
> kernel test robot noticed the following build warnings:
> 
> [auto build test WARNING on device-mapper-dm/for-next]
> [also build test WARNING on linus/master v6.11-rc4 next-20240822]
> [cannot apply to song-md/md-next]
> [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#_base_tree_information]
> 
> url:    https://github.com/intel-lab-lkp/linux/commits/Yu-Kuai/md-raid1-use-md_bitmap_wait_behind_writes-in-raid1_read_request/20240822-110233
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git for-next
> patch link:    https://lore.kernel.org/r/20240822024718.2158259-6-yukuai1%40huaweicloud.com
> patch subject: [PATCH md-6.12 05/41] md/md-bitmap: add 'sync_size' into struct md_bitmap_stats
> config: x86_64-randconfig-121-20240822 (https://download.01.org/0day-ci/archive/20240823/202408230544.w18wb47U-lkp@intel.com/config)
> compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240823/202408230544.w18wb47U-lkp@intel.com/reproduce)
> 
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202408230544.w18wb47U-lkp@intel.com/
> 
> sparse warnings: (new ones prefixed by >>)
>>> drivers/md/md-bitmap.c:2106:26: sparse: sparse: incorrect type in assignment (different base types) @@     expected unsigned long sync_size @@     got restricted __le64 [usertype] sync_size @@
>     drivers/md/md-bitmap.c:2106:26: sparse:     expected unsigned long sync_size
>     drivers/md/md-bitmap.c:2106:26: sparse:     got restricted __le64 [usertype] sync_size

So this is actually the old code behavior. I'll fix this. :)

Thanks,
Kuai

>     drivers/md/md-bitmap.c: note: in included file (through include/linux/mmzone.h, include/linux/gfp.h, include/linux/xarray.h, ...):
>     include/linux/page-flags.h:235:46: sparse: sparse: self-comparison always evaluates to false
>     include/linux/page-flags.h:235:46: sparse: sparse: self-comparison always evaluates to false
> 
> vim +2106 drivers/md/md-bitmap.c
> 
>    2096	
>    2097	int md_bitmap_get_stats(struct bitmap *bitmap, struct md_bitmap_stats *stats)
>    2098	{
>    2099		struct bitmap_counts *counts;
>    2100		bitmap_super_t *sb;
>    2101	
>    2102		if (!bitmap)
>    2103			return -ENOENT;
>    2104	
>    2105		sb = kmap_local_page(bitmap->storage.sb_page);
>> 2106		stats->sync_size = sb->sync_size;
>    2107		kunmap_local(sb);
>    2108	
>    2109		counts = &bitmap->counts;
>    2110		stats->missing_pages = counts->missing_pages;
>    2111		stats->pages = counts->pages;
>    2112	
>    2113		stats->events_cleared = bitmap->events_cleared;
>    2114		stats->file = bitmap->storage.file;
>    2115	
>    2116		return 0;
>    2117	}
>    2118	EXPORT_SYMBOL_GPL(md_bitmap_get_stats);
>    2119	
>
diff mbox series

Patch

diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 95afc22bd255..105778cc34ed 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -2097,10 +2097,15 @@  EXPORT_SYMBOL_GPL(md_bitmap_copy_from_slot);
 int md_bitmap_get_stats(struct bitmap *bitmap, struct md_bitmap_stats *stats)
 {
 	struct bitmap_counts *counts;
+	bitmap_super_t *sb;
 
 	if (!bitmap)
 		return -ENOENT;
 
+	sb = kmap_local_page(bitmap->storage.sb_page);
+	stats->sync_size = sb->sync_size;
+	kunmap_local(sb);
+
 	counts = &bitmap->counts;
 	stats->missing_pages = counts->missing_pages;
 	stats->pages = counts->pages;
@@ -2110,6 +2115,7 @@  int md_bitmap_get_stats(struct bitmap *bitmap, struct md_bitmap_stats *stats)
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(md_bitmap_get_stats);
 
 int md_bitmap_resize(struct bitmap *bitmap, sector_t blocks,
 		  int chunksize, int init)
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index 751dca2366c3..a43a75575769 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -237,6 +237,7 @@  struct bitmap {
 struct md_bitmap_stats {
 	u64		events_cleared;
 	unsigned long	missing_pages;
+	unsigned long	sync_size;
 	unsigned long	pages;
 	struct file	*file;
 };
diff --git a/drivers/md/md-cluster.c b/drivers/md/md-cluster.c
index 1d0db62f0351..e3faf752f0b1 100644
--- a/drivers/md/md-cluster.c
+++ b/drivers/md/md-cluster.c
@@ -1207,18 +1207,21 @@  static int resize_bitmaps(struct mddev *mddev, sector_t newsize, sector_t oldsiz
  */
 static int cluster_check_sync_size(struct mddev *mddev)
 {
-	int i, rv;
-	bitmap_super_t *sb;
-	unsigned long my_sync_size, sync_size = 0;
-	int node_num = mddev->bitmap_info.nodes;
 	int current_slot = md_cluster_ops->slot_number(mddev);
+	int node_num = mddev->bitmap_info.nodes;
 	struct bitmap *bitmap = mddev->bitmap;
-	char str[64];
 	struct dlm_lock_resource *bm_lockres;
+	struct md_bitmap_stats stats;
+	unsigned long sync_size = 0;
+	unsigned long my_sync_size;
+	char str[64];
+	int i, rv;
 
-	sb = kmap_atomic(bitmap->storage.sb_page);
-	my_sync_size = sb->sync_size;
-	kunmap_atomic(sb);
+	rv = md_bitmap_get_stats(bitmap, &stats);
+	if (rv)
+		return rv;
+
+	my_sync_size = stats.sync_size;
 
 	for (i = 0; i < node_num; i++) {
 		if (i == current_slot)
@@ -1247,15 +1250,18 @@  static int cluster_check_sync_size(struct mddev *mddev)
 			md_bitmap_update_sb(bitmap);
 		lockres_free(bm_lockres);
 
-		sb = kmap_atomic(bitmap->storage.sb_page);
-		if (sync_size == 0)
-			sync_size = sb->sync_size;
-		else if (sync_size != sb->sync_size) {
-			kunmap_atomic(sb);
+		rv = md_bitmap_get_stats(bitmap, &stats);
+		if (rv) {
+			md_bitmap_free(bitmap);
+			return rv;
+		}
+
+		if (sync_size == 0) {
+			sync_size = stats.sync_size;
+		} else if (sync_size != stats.sync_size) {
 			md_bitmap_free(bitmap);
 			return -1;
 		}
-		kunmap_atomic(sb);
 		md_bitmap_free(bitmap);
 	}