lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240810020854.797814-23-yukuai1@huaweicloud.com>
Date: Sat, 10 Aug 2024 10:08:50 +0800
From: Yu Kuai <yukuai1@...weicloud.com>
To: song@...nel.org
Cc: linux-kernel@...r.kernel.org,
	linux-raid@...r.kernel.org,
	yukuai3@...wei.com,
	yukuai1@...weicloud.com,
	yi.zhang@...wei.com,
	yangerkun@...wei.com
Subject: [PATCH RFC -next 22/26] md/md-bitmap: merge md_bitmap_free() into bitmap_operations

From: Yu Kuai <yukuai3@...wei.com>

So that the implementation won't be exposed, and it'll be possible
to invent a new bitmap by replacing bitmap_operations.

Signed-off-by: Yu Kuai <yukuai3@...wei.com>
---
 drivers/md/md-bitmap.c  | 17 +++++++----------
 drivers/md/md-bitmap.h  | 10 +++++++++-
 drivers/md/md-cluster.c | 10 +++++-----
 3 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 199bd6757543..99c496a32e94 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -1790,10 +1790,7 @@ static void bitmap_flush(struct mddev *mddev)
 	bitmap_update_sb(bitmap);
 }
 
-/*
- * free memory that was allocated
- */
-void md_bitmap_free(struct bitmap *bitmap)
+static void __bitmap_free(struct bitmap *bitmap)
 {
 	unsigned long k, pages;
 	struct bitmap_page *bp;
@@ -1827,7 +1824,6 @@ void md_bitmap_free(struct bitmap *bitmap)
 	kfree(bp);
 	kfree(bitmap);
 }
-EXPORT_SYMBOL(md_bitmap_free);
 
 void md_bitmap_wait_behind_writes(struct mddev *mddev)
 {
@@ -1861,7 +1857,7 @@ static void bitmap_destroy(struct mddev *mddev)
 	mutex_unlock(&mddev->bitmap_info.mutex);
 	mddev_set_timeout(mddev, MAX_SCHEDULE_TIMEOUT, true);
 
-	md_bitmap_free(bitmap);
+	__bitmap_free(bitmap);
 }
 
 /*
@@ -1952,7 +1948,7 @@ static struct bitmap *bitmap_create(struct mddev *mddev, int slot)
 
 	return bitmap;
  error:
-	md_bitmap_free(bitmap);
+	__bitmap_free(bitmap);
 	return ERR_PTR(err);
 }
 
@@ -2013,7 +2009,7 @@ static int bitmap_load(struct mddev *mddev)
 	return err;
 }
 
-/* caller need to free returned bitmap with md_bitmap_free() */
+/* caller need to free returned bitmap with __bitmap_free() */
 static struct bitmap *bitmap_get_from_slot(struct mddev *mddev, int slot)
 {
 	int rv = 0;
@@ -2027,7 +2023,7 @@ static struct bitmap *bitmap_get_from_slot(struct mddev *mddev, int slot)
 
 	rv = md_bitmap_init_from_disk(bitmap, 0);
 	if (rv) {
-		md_bitmap_free(bitmap);
+		__bitmap_free(bitmap);
 		return ERR_PTR(rv);
 	}
 
@@ -2076,7 +2072,7 @@ static int bitmap_copy_from_slot(struct mddev *mddev, int slot, sector_t *low,
 	md_bitmap_unplug(mddev->bitmap);
 	*low = lo;
 	*high = hi;
-	md_bitmap_free(bitmap);
+	__bitmap_free(bitmap);
 
 	return rv;
 }
@@ -2715,6 +2711,7 @@ static struct bitmap_operations bitmap_ops = {
 	.sync_with_cluster	= bitmap_sync_with_cluster,
 	.get_from_slot		= bitmap_get_from_slot,
 	.copy_from_slot		= bitmap_copy_from_slot,
+	.free			= __bitmap_free,
 };
 
 void mddev_set_bitmap_ops(struct mddev *mddev)
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index acd868e2ef5e..b5836e5ff1e3 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -263,6 +263,7 @@ struct bitmap_operations {
 	struct bitmap* (*get_from_slot)(struct mddev *mddev, int slot);
 	int (*copy_from_slot)(struct mddev *mddev, int slot,
 			      sector_t *lo, sector_t *hi, bool clear_bits);
+	void (*free)(struct bitmap *bitmap);
 };
 
 /* the bitmap API */
@@ -433,11 +434,18 @@ static inline int md_bitmap_copy_from_slot(struct mddev *mddev, int slot,
 	return mddev->bitmap_ops->copy_from_slot(mddev, slot, lo, hi, clear_bits);
 }
 
+static inline void md_bitmap_free(struct mddev *mddev, struct bitmap *bitmap)
+{
+	if (!mddev->bitmap_ops->free)
+		return;
+
+	return mddev->bitmap_ops->free(bitmap);
+}
+
 void md_bitmap_unplug(struct bitmap *bitmap);
 void md_bitmap_unplug_async(struct bitmap *bitmap);
 void md_bitmap_daemon_work(struct mddev *mddev);
 
-void md_bitmap_free(struct bitmap *bitmap);
 void md_bitmap_wait_behind_writes(struct mddev *mddev);
 
 static inline bool md_bitmap_enabled(struct bitmap *bitmap)
diff --git a/drivers/md/md-cluster.c b/drivers/md/md-cluster.c
index d608535fc06a..9e3c579703f6 100644
--- a/drivers/md/md-cluster.c
+++ b/drivers/md/md-cluster.c
@@ -1192,12 +1192,12 @@ static int resize_bitmaps(struct mddev *mddev, sector_t newsize, sector_t oldsiz
 			 * can't resize bitmap
 			 */
 			goto out;
-		md_bitmap_free(bitmap);
+		md_bitmap_free(mddev, bitmap);
 	}
 
 	return 0;
 out:
-	md_bitmap_free(bitmap);
+	md_bitmap_free(mddev, bitmap);
 	update_bitmap_size(mddev, oldsize);
 	return -1;
 }
@@ -1238,7 +1238,7 @@ static int cluster_check_sync_size(struct mddev *mddev)
 		bm_lockres = lockres_init(mddev, str, NULL, 1);
 		if (!bm_lockres) {
 			pr_err("md-cluster: Cannot initialize %s\n", str);
-			md_bitmap_free(bitmap);
+			md_bitmap_free(mddev, bitmap);
 			return -1;
 		}
 		bm_lockres->flags |= DLM_LKF_NOQUEUE;
@@ -1253,11 +1253,11 @@ static int cluster_check_sync_size(struct mddev *mddev)
 			sync_size = sb->sync_size;
 		else if (sync_size != sb->sync_size) {
 			kunmap_atomic(sb);
-			md_bitmap_free(bitmap);
+			md_bitmap_free(mddev, bitmap);
 			return -1;
 		}
 		kunmap_atomic(sb);
-		md_bitmap_free(bitmap);
+		md_bitmap_free(mddev, bitmap);
 	}
 
 	return (my_sync_size == sync_size) ? 0 : -1;
-- 
2.39.2


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ