Commit e1791dae authored by Yu Kuai's avatar Yu Kuai Committed by Song Liu

md/md-bitmap: pass in mddev directly for md_bitmap_resize()

And move the condition "if (mddev->bitmap)" into md_bitmap_resize() as
well, on the one hand make code cleaner, on the other hand try not to
access bitmap directly.

Since we are here, also change the parameter 'init' from int to bool.
Signed-off-by: default avatarYu Kuai <yukuai3@huawei.com>
Link: https://lore.kernel.org/r/20240826074452.1490072-35-yukuai1@huaweicloud.comSigned-off-by: default avatarSong Liu <song@kernel.org>
parent 18db2a9c
...@@ -4068,7 +4068,7 @@ static int raid_preresume(struct dm_target *ti) ...@@ -4068,7 +4068,7 @@ static int raid_preresume(struct dm_target *ti)
mddev->bitmap_info.chunksize != to_bytes(rs->requested_bitmap_chunk_sectors)))) { mddev->bitmap_info.chunksize != to_bytes(rs->requested_bitmap_chunk_sectors)))) {
int chunksize = to_bytes(rs->requested_bitmap_chunk_sectors) ?: mddev->bitmap_info.chunksize; 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, false);
if (r) if (r)
DMERR("Failed to resize bitmap"); DMERR("Failed to resize bitmap");
} }
......
...@@ -32,6 +32,9 @@ ...@@ -32,6 +32,9 @@
#include "md.h" #include "md.h"
#include "md-bitmap.h" #include "md-bitmap.h"
static int __bitmap_resize(struct bitmap *bitmap, sector_t blocks,
int chunksize, bool init);
static inline char *bmname(struct bitmap *bitmap) static inline char *bmname(struct bitmap *bitmap)
{ {
return bitmap->mddev ? mdname(bitmap->mddev) : "mdX"; return bitmap->mddev ? mdname(bitmap->mddev) : "mdX";
...@@ -1975,7 +1978,8 @@ static struct bitmap *__bitmap_create(struct mddev *mddev, int slot) ...@@ -1975,7 +1978,8 @@ static struct bitmap *__bitmap_create(struct mddev *mddev, int slot)
goto error; goto error;
bitmap->daemon_lastrun = jiffies; bitmap->daemon_lastrun = jiffies;
err = md_bitmap_resize(bitmap, blocks, mddev->bitmap_info.chunksize, 1); err = __bitmap_resize(bitmap, blocks, mddev->bitmap_info.chunksize,
true);
if (err) if (err)
goto error; goto error;
...@@ -2163,8 +2167,8 @@ static int bitmap_get_stats(struct bitmap *bitmap, struct md_bitmap_stats *stats ...@@ -2163,8 +2167,8 @@ static int bitmap_get_stats(struct bitmap *bitmap, struct md_bitmap_stats *stats
return 0; return 0;
} }
int md_bitmap_resize(struct bitmap *bitmap, sector_t blocks, static int __bitmap_resize(struct bitmap *bitmap, sector_t blocks,
int chunksize, int init) int chunksize, bool init)
{ {
/* If chunk_size is 0, choose an appropriate chunk size. /* If chunk_size is 0, choose an appropriate chunk size.
* Then possibly allocate new storage space. * Then possibly allocate new storage space.
...@@ -2369,6 +2373,17 @@ int md_bitmap_resize(struct bitmap *bitmap, sector_t blocks, ...@@ -2369,6 +2373,17 @@ int md_bitmap_resize(struct bitmap *bitmap, sector_t blocks,
err: err:
return ret; return ret;
} }
int md_bitmap_resize(struct mddev *mddev, sector_t blocks, int chunksize,
bool init)
{
struct bitmap *bitmap = mddev->bitmap;
if (!bitmap)
return 0;
return __bitmap_resize(bitmap, blocks, chunksize, init);
}
EXPORT_SYMBOL_GPL(md_bitmap_resize); EXPORT_SYMBOL_GPL(md_bitmap_resize);
static ssize_t static ssize_t
......
...@@ -280,8 +280,8 @@ void mddev_set_bitmap_ops(struct mddev *mddev); ...@@ -280,8 +280,8 @@ void mddev_set_bitmap_ops(struct mddev *mddev);
/* these are exported */ /* these are exported */
int md_bitmap_resize(struct bitmap *bitmap, sector_t blocks, int md_bitmap_resize(struct mddev *mddev, sector_t blocks, int chunksize,
int chunksize, int init); bool init);
struct bitmap *get_bitmap_from_slot(struct mddev *mddev, int slot); struct bitmap *get_bitmap_from_slot(struct mddev *mddev, int slot);
int md_bitmap_copy_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); sector_t *lo, sector_t *hi, bool clear_bits);
......
...@@ -628,8 +628,8 @@ static int process_recvd_msg(struct mddev *mddev, struct cluster_msg *msg) ...@@ -628,8 +628,8 @@ static int process_recvd_msg(struct mddev *mddev, struct cluster_msg *msg)
break; break;
case BITMAP_RESIZE: case BITMAP_RESIZE:
if (le64_to_cpu(msg->high) != mddev->pers->size(mddev, 0, 0)) if (le64_to_cpu(msg->high) != mddev->pers->size(mddev, 0, 0))
ret = md_bitmap_resize(mddev->bitmap, ret = md_bitmap_resize(mddev, le64_to_cpu(msg->high), 0,
le64_to_cpu(msg->high), 0, 0); false);
break; break;
default: default:
ret = -1; ret = -1;
......
...@@ -3297,14 +3297,16 @@ static int raid1_resize(struct mddev *mddev, sector_t sectors) ...@@ -3297,14 +3297,16 @@ static int raid1_resize(struct mddev *mddev, sector_t sectors)
* worth it. * worth it.
*/ */
sector_t newsize = raid1_size(mddev, sectors, 0); sector_t newsize = raid1_size(mddev, sectors, 0);
int ret;
if (mddev->external_size && if (mddev->external_size &&
mddev->array_sectors > newsize) mddev->array_sectors > newsize)
return -EINVAL; return -EINVAL;
if (mddev->bitmap) {
int ret = md_bitmap_resize(mddev->bitmap, newsize, 0, 0); ret = md_bitmap_resize(mddev, newsize, 0, false);
if (ret) if (ret)
return ret; return ret;
}
md_set_array_sectors(mddev, newsize); md_set_array_sectors(mddev, newsize);
if (sectors > mddev->dev_sectors && if (sectors > mddev->dev_sectors &&
mddev->recovery_cp > mddev->dev_sectors) { mddev->recovery_cp > mddev->dev_sectors) {
......
...@@ -4196,6 +4196,7 @@ static int raid10_resize(struct mddev *mddev, sector_t sectors) ...@@ -4196,6 +4196,7 @@ static int raid10_resize(struct mddev *mddev, sector_t sectors)
*/ */
struct r10conf *conf = mddev->private; struct r10conf *conf = mddev->private;
sector_t oldsize, size; sector_t oldsize, size;
int ret;
if (mddev->reshape_position != MaxSector) if (mddev->reshape_position != MaxSector)
return -EBUSY; return -EBUSY;
...@@ -4208,11 +4209,11 @@ static int raid10_resize(struct mddev *mddev, sector_t sectors) ...@@ -4208,11 +4209,11 @@ static int raid10_resize(struct mddev *mddev, sector_t sectors)
if (mddev->external_size && if (mddev->external_size &&
mddev->array_sectors > size) mddev->array_sectors > size)
return -EINVAL; return -EINVAL;
if (mddev->bitmap) {
int ret = md_bitmap_resize(mddev->bitmap, size, 0, 0); ret = md_bitmap_resize(mddev, size, 0, false);
if (ret) if (ret)
return ret; return ret;
}
md_set_array_sectors(mddev, size); md_set_array_sectors(mddev, size);
if (sectors > mddev->dev_sectors && if (sectors > mddev->dev_sectors &&
mddev->recovery_cp > oldsize) { mddev->recovery_cp > oldsize) {
...@@ -4478,7 +4479,7 @@ static int raid10_start_reshape(struct mddev *mddev) ...@@ -4478,7 +4479,7 @@ static int raid10_start_reshape(struct mddev *mddev)
newsize = raid10_size(mddev, 0, conf->geo.raid_disks); newsize = raid10_size(mddev, 0, conf->geo.raid_disks);
if (!mddev_is_clustered(mddev)) { if (!mddev_is_clustered(mddev)) {
ret = md_bitmap_resize(mddev->bitmap, newsize, 0, 0); ret = md_bitmap_resize(mddev, newsize, 0, false);
if (ret) if (ret)
goto abort; goto abort;
else else
...@@ -4500,13 +4501,13 @@ static int raid10_start_reshape(struct mddev *mddev) ...@@ -4500,13 +4501,13 @@ static int raid10_start_reshape(struct mddev *mddev)
MD_FEATURE_RESHAPE_ACTIVE)) || (oldsize == newsize)) MD_FEATURE_RESHAPE_ACTIVE)) || (oldsize == newsize))
goto out; goto out;
ret = md_bitmap_resize(mddev->bitmap, newsize, 0, 0); ret = md_bitmap_resize(mddev, newsize, 0, false);
if (ret) if (ret)
goto abort; goto abort;
ret = md_cluster_ops->resize_bitmaps(mddev, newsize, oldsize); ret = md_cluster_ops->resize_bitmaps(mddev, newsize, oldsize);
if (ret) { if (ret) {
md_bitmap_resize(mddev->bitmap, oldsize, 0, 0); md_bitmap_resize(mddev, oldsize, 0, false);
goto abort; goto abort;
} }
} }
......
...@@ -8313,6 +8313,7 @@ static int raid5_resize(struct mddev *mddev, sector_t sectors) ...@@ -8313,6 +8313,7 @@ static int raid5_resize(struct mddev *mddev, sector_t sectors)
*/ */
sector_t newsize; sector_t newsize;
struct r5conf *conf = mddev->private; struct r5conf *conf = mddev->private;
int ret;
if (raid5_has_log(conf) || raid5_has_ppl(conf)) if (raid5_has_log(conf) || raid5_has_ppl(conf))
return -EINVAL; return -EINVAL;
...@@ -8321,11 +8322,11 @@ static int raid5_resize(struct mddev *mddev, sector_t sectors) ...@@ -8321,11 +8322,11 @@ static int raid5_resize(struct mddev *mddev, sector_t sectors)
if (mddev->external_size && if (mddev->external_size &&
mddev->array_sectors > newsize) mddev->array_sectors > newsize)
return -EINVAL; return -EINVAL;
if (mddev->bitmap) {
int ret = md_bitmap_resize(mddev->bitmap, sectors, 0, 0); ret = md_bitmap_resize(mddev, sectors, 0, false);
if (ret) if (ret)
return ret; return ret;
}
md_set_array_sectors(mddev, newsize); md_set_array_sectors(mddev, newsize);
if (sectors > mddev->dev_sectors && if (sectors > mddev->dev_sectors &&
mddev->recovery_cp > mddev->dev_sectors) { mddev->recovery_cp > mddev->dev_sectors) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment