diff mbox series

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

Message ID 20240814071113.346781-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. 14, 2024, 7:10 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 | 25 +++++++++++++++----------
 3 files changed, 22 insertions(+), 10 deletions(-)

Comments

Mariusz Tkaczyk Aug. 14, 2024, 12:52 p.m. UTC | #1
On Wed, 14 Aug 2024 15:10:37 +0800
Yu Kuai <yukuai1@huaweicloud.com> wrote:

> 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 | 25 +++++++++++++++----------
>  3 files changed, 22 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
> index 8a2411040d2f..9ff5ed250ba5 100644
> --- a/drivers/md/md-bitmap.c
> +++ b/drivers/md/md-bitmap.c
> @@ -2096,11 +2096,16 @@ EXPORT_SYMBOL_GPL(md_bitmap_copy_from_slot);
>  
>  int md_bitmap_get_stats(struct bitmap *bitmap, struct md_bitmap_stats *stats)
>  {
> +	bitmap_super_t *sb;
>  	struct bitmap_counts *counts;

Hi Kuai,

Use reversed christmas tree convention if possible :)



> diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
> index c8527ba38dfc..1a7ad2cf9f75 100644
> --- a/drivers/md/md-bitmap.h
> +++ b/drivers/md/md-bitmap.h
> @@ -237,6 +237,7 @@ struct bitmap {
>  struct md_bitmap_stats {
>  	unsigned long pages;
>  	unsigned long missing_pages;
> +	unsigned long sync_size;

Same here.

Anyway, LGTM.
Mariusz
diff mbox series

Patch

diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 8a2411040d2f..9ff5ed250ba5 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -2096,11 +2096,16 @@  EXPORT_SYMBOL_GPL(md_bitmap_copy_from_slot);
 
 int md_bitmap_get_stats(struct bitmap *bitmap, struct md_bitmap_stats *stats)
 {
+	bitmap_super_t *sb;
 	struct bitmap_counts *counts;
 
 	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->pages = counts->pages;
 	stats->missing_pages = counts->missing_pages;
@@ -2109,6 +2114,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 c8527ba38dfc..1a7ad2cf9f75 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -237,6 +237,7 @@  struct bitmap {
 struct md_bitmap_stats {
 	unsigned long pages;
 	unsigned long missing_pages;
+	unsigned long sync_size;
 	struct file *file;
 	u64 events_cleared;
 };
diff --git a/drivers/md/md-cluster.c b/drivers/md/md-cluster.c
index 1d0db62f0351..9d87c215f094 100644
--- a/drivers/md/md-cluster.c
+++ b/drivers/md/md-cluster.c
@@ -1208,17 +1208,19 @@  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);
 	struct bitmap *bitmap = mddev->bitmap;
 	char str[64];
 	struct dlm_lock_resource *bm_lockres;
+	struct md_bitmap_stats stats;
 
-	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 +1249,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);
 	}