[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240810020854.797814-20-yukuai1@huaweicloud.com>
Date: Sat, 10 Aug 2024 10:08:47 +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 19/26] md/md-bitmap: merge md_bitmap_resize() 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/dm-raid.c | 2 +-
drivers/md/md-bitmap.c | 11 +++++++----
drivers/md/md-bitmap.h | 13 +++++++++++--
drivers/md/md-cluster.c | 4 ++--
drivers/md/raid1.c | 2 +-
drivers/md/raid10.c | 8 ++++----
drivers/md/raid5.c | 2 +-
7 files changed, 27 insertions(+), 15 deletions(-)
diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c
index 0c3323e0adb2..6342775c79dd 100644
--- a/drivers/md/dm-raid.c
+++ b/drivers/md/dm-raid.c
@@ -4066,7 +4066,7 @@ static int raid_preresume(struct dm_target *ti)
mddev->bitmap_info.chunksize != to_bytes(rs->requested_bitmap_chunk_sectors)))) {
int chunksize = to_bytes(rs->requested_bitmap_chunk_sectors) ?: mddev->bitmap_info.chunksize;
- r = md_bitmap_resize(mddev->bitmap, mddev->dev_sectors, chunksize, 0);
+ r = md_bitmap_resize(mddev, mddev->dev_sectors, chunksize, 0);
if (r)
DMERR("Failed to resize bitmap");
}
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 8828175ad442..ed43139b52f4 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -32,6 +32,9 @@
#include "md.h"
#include "md-bitmap.h"
+static int bitmap_resize(struct bitmap *bitmap, sector_t blocks,
+ int chunksize, int init);
+
static inline char *bmname(struct bitmap *bitmap)
{
return bitmap->mddev ? mdname(bitmap->mddev) : "mdX";
@@ -1936,7 +1939,7 @@ static struct bitmap *bitmap_create(struct mddev *mddev, int slot)
goto error;
bitmap->daemon_lastrun = jiffies;
- err = md_bitmap_resize(bitmap, blocks, mddev->bitmap_info.chunksize, 1);
+ err = bitmap_resize(bitmap, blocks, mddev->bitmap_info.chunksize, 1);
if (err)
goto error;
@@ -2108,8 +2111,8 @@ static void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
seq_printf(seq, "\n");
}
-int md_bitmap_resize(struct bitmap *bitmap, sector_t blocks,
- int chunksize, int init)
+static int bitmap_resize(struct bitmap *bitmap, sector_t blocks,
+ int chunksize, int init)
{
/* If chunk_size is 0, choose an appropriate chunk size.
* Then possibly allocate new storage space.
@@ -2314,7 +2317,6 @@ int md_bitmap_resize(struct bitmap *bitmap, sector_t blocks,
err:
return ret;
}
-EXPORT_SYMBOL_GPL(md_bitmap_resize);
static ssize_t
location_show(struct mddev *mddev, char *page)
@@ -2712,6 +2714,7 @@ static struct bitmap_operations bitmap_ops = {
.cond_end_sync = bitmap_cond_end_sync,
.update_sb = bitmap_update_sb,
+ .resize = bitmap_resize,
.sync_with_cluster = bitmap_sync_with_cluster,
};
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index 5a77b6d8358b..37edf8626a60 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -255,6 +255,8 @@ struct bitmap_operations {
void (*cond_end_sync)(struct bitmap *bitmap, sector_t sector, bool force);
void (*update_sb)(struct bitmap *bitmap);
+ int (*resize)(struct bitmap *bitmap, sector_t blocks, int chunksize,
+ int init);
void (*sync_with_cluster)(struct bitmap *bitmap,
sector_t old_lo, sector_t old_hi,
sector_t new_lo, sector_t new_hi);
@@ -389,6 +391,15 @@ static inline void md_bitmap_cond_end_sync(struct mddev *mddev, sector_t sector,
mddev->bitmap_ops->cond_end_sync(mddev->bitmap, sector, force);
}
+static inline int md_bitmap_resize(struct mddev *mddev, sector_t blocks,
+ int chunksize, int init)
+{
+ if (!mddev->bitmap || !mddev->bitmap_ops->resize)
+ return -EOPNOTSUPP;
+
+ return mddev->bitmap_ops->resize(mddev->bitmap, blocks, chunksize, init);
+}
+
static inline void md_bitmap_sync_with_cluster(struct mddev *mddev,
sector_t old_lo, sector_t old_hi,
sector_t new_lo, sector_t new_hi)
@@ -404,8 +415,6 @@ void md_bitmap_unplug(struct bitmap *bitmap);
void md_bitmap_unplug_async(struct bitmap *bitmap);
void md_bitmap_daemon_work(struct mddev *mddev);
-int md_bitmap_resize(struct bitmap *bitmap, sector_t blocks,
- int chunksize, int init);
struct bitmap *get_bitmap_from_slot(struct mddev *mddev, int slot);
int md_bitmap_copy_from_slot(struct mddev *mddev, int slot,
sector_t *lo, sector_t *hi, bool clear_bits);
diff --git a/drivers/md/md-cluster.c b/drivers/md/md-cluster.c
index 79e67393fee0..d843ea190e7b 100644
--- a/drivers/md/md-cluster.c
+++ b/drivers/md/md-cluster.c
@@ -628,8 +628,8 @@ static int process_recvd_msg(struct mddev *mddev, struct cluster_msg *msg)
break;
case BITMAP_RESIZE:
if (le64_to_cpu(msg->high) != mddev->pers->size(mddev, 0, 0))
- ret = md_bitmap_resize(mddev->bitmap,
- le64_to_cpu(msg->high), 0, 0);
+ ret = md_bitmap_resize(mddev, le64_to_cpu(msg->high), 0,
+ 0);
break;
default:
ret = -1;
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index c8cd6036441b..fef69fce586c 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -3311,7 +3311,7 @@ static int raid1_resize(struct mddev *mddev, sector_t sectors)
mddev->array_sectors > newsize)
return -EINVAL;
if (mddev->bitmap) {
- int ret = md_bitmap_resize(mddev->bitmap, newsize, 0, 0);
+ int ret = md_bitmap_resize(mddev, newsize, 0, 0);
if (ret)
return ret;
}
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 1ea9b4117b08..a8a14cda8446 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -4201,7 +4201,7 @@ static int raid10_resize(struct mddev *mddev, sector_t sectors)
mddev->array_sectors > size)
return -EINVAL;
if (mddev->bitmap) {
- int ret = md_bitmap_resize(mddev->bitmap, size, 0, 0);
+ int ret = md_bitmap_resize(mddev, size, 0, 0);
if (ret)
return ret;
}
@@ -4470,7 +4470,7 @@ static int raid10_start_reshape(struct mddev *mddev)
newsize = raid10_size(mddev, 0, conf->geo.raid_disks);
if (!mddev_is_clustered(mddev)) {
- ret = md_bitmap_resize(mddev->bitmap, newsize, 0, 0);
+ ret = md_bitmap_resize(mddev, newsize, 0, 0);
if (ret)
goto abort;
else
@@ -4492,13 +4492,13 @@ static int raid10_start_reshape(struct mddev *mddev)
MD_FEATURE_RESHAPE_ACTIVE)) || (oldsize == newsize))
goto out;
- ret = md_bitmap_resize(mddev->bitmap, newsize, 0, 0);
+ ret = md_bitmap_resize(mddev, newsize, 0, 0);
if (ret)
goto abort;
ret = md_cluster_ops->resize_bitmaps(mddev, newsize, oldsize);
if (ret) {
- md_bitmap_resize(mddev->bitmap, oldsize, 0, 0);
+ md_bitmap_resize(mddev, oldsize, 0, 0);
goto abort;
}
}
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 8f0de56c0b23..8b1e2157a798 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -8320,7 +8320,7 @@ static int raid5_resize(struct mddev *mddev, sector_t sectors)
mddev->array_sectors > newsize)
return -EINVAL;
if (mddev->bitmap) {
- int ret = md_bitmap_resize(mddev->bitmap, sectors, 0, 0);
+ int ret = md_bitmap_resize(mddev, sectors, 0, 0);
if (ret)
return ret;
}
--
2.39.2
Powered by blists - more mailing lists