Commit 7545d385 authored by Yu Kuai's avatar Yu Kuai Committed by Song Liu

md/md-bitmap: simplify md_bitmap_create() + md_bitmap_load()

Other than internal api get_bitmap_from_slot(), all other places will
set returned bitmap to mddev->bitmap. So move the setting of
mddev->bitmap into md_bitmap_create() to simplify code.
Signed-off-by: default avatarYu Kuai <yukuai3@huawei.com>
Link: https://lore.kernel.org/r/20240826074452.1490072-13-yukuai1@huaweicloud.comSigned-off-by: default avatarSong Liu <song@kernel.org>
parent 7add9db6
...@@ -1879,7 +1879,7 @@ void md_bitmap_destroy(struct mddev *mddev) ...@@ -1879,7 +1879,7 @@ void md_bitmap_destroy(struct mddev *mddev)
* if this returns an error, bitmap_destroy must be called to do clean up * if this returns an error, bitmap_destroy must be called to do clean up
* once mddev->bitmap is set * once mddev->bitmap is set
*/ */
struct bitmap *md_bitmap_create(struct mddev *mddev, int slot) static struct bitmap *__bitmap_create(struct mddev *mddev, int slot)
{ {
struct bitmap *bitmap; struct bitmap *bitmap;
sector_t blocks = mddev->resync_max_sectors; sector_t blocks = mddev->resync_max_sectors;
...@@ -1966,6 +1966,17 @@ struct bitmap *md_bitmap_create(struct mddev *mddev, int slot) ...@@ -1966,6 +1966,17 @@ struct bitmap *md_bitmap_create(struct mddev *mddev, int slot)
return ERR_PTR(err); return ERR_PTR(err);
} }
int md_bitmap_create(struct mddev *mddev, int slot)
{
struct bitmap *bitmap = __bitmap_create(mddev, slot);
if (IS_ERR(bitmap))
return PTR_ERR(bitmap);
mddev->bitmap = bitmap;
return 0;
}
int md_bitmap_load(struct mddev *mddev) int md_bitmap_load(struct mddev *mddev)
{ {
int err = 0; int err = 0;
...@@ -2030,7 +2041,7 @@ struct bitmap *get_bitmap_from_slot(struct mddev *mddev, int slot) ...@@ -2030,7 +2041,7 @@ struct bitmap *get_bitmap_from_slot(struct mddev *mddev, int slot)
int rv = 0; int rv = 0;
struct bitmap *bitmap; struct bitmap *bitmap;
bitmap = md_bitmap_create(mddev, slot); bitmap = __bitmap_create(mddev, slot);
if (IS_ERR(bitmap)) { if (IS_ERR(bitmap)) {
rv = PTR_ERR(bitmap); rv = PTR_ERR(bitmap);
return ERR_PTR(rv); return ERR_PTR(rv);
...@@ -2384,7 +2395,6 @@ location_store(struct mddev *mddev, const char *buf, size_t len) ...@@ -2384,7 +2395,6 @@ location_store(struct mddev *mddev, const char *buf, size_t len)
} else { } else {
/* No bitmap, OK to set a location */ /* No bitmap, OK to set a location */
long long offset; long long offset;
struct bitmap *bitmap;
if (strncmp(buf, "none", 4) == 0) if (strncmp(buf, "none", 4) == 0)
/* nothing to be done */; /* nothing to be done */;
...@@ -2411,13 +2421,10 @@ location_store(struct mddev *mddev, const char *buf, size_t len) ...@@ -2411,13 +2421,10 @@ location_store(struct mddev *mddev, const char *buf, size_t len)
} }
mddev->bitmap_info.offset = offset; mddev->bitmap_info.offset = offset;
bitmap = md_bitmap_create(mddev, -1); rv = md_bitmap_create(mddev, -1);
if (IS_ERR(bitmap)) { if (rv)
rv = PTR_ERR(bitmap);
goto out; goto out;
}
mddev->bitmap = bitmap;
rv = md_bitmap_load(mddev); rv = md_bitmap_load(mddev);
if (rv) { if (rv) {
mddev->bitmap_info.offset = 0; mddev->bitmap_info.offset = 0;
......
...@@ -253,7 +253,7 @@ struct bitmap_operations { ...@@ -253,7 +253,7 @@ struct bitmap_operations {
void mddev_set_bitmap_ops(struct mddev *mddev); void mddev_set_bitmap_ops(struct mddev *mddev);
/* these are used only by md/bitmap */ /* these are used only by md/bitmap */
struct bitmap *md_bitmap_create(struct mddev *mddev, int slot); int md_bitmap_create(struct mddev *mddev, int slot);
int md_bitmap_load(struct mddev *mddev); int md_bitmap_load(struct mddev *mddev);
void md_bitmap_flush(struct mddev *mddev); void md_bitmap_flush(struct mddev *mddev);
void md_bitmap_destroy(struct mddev *mddev); void md_bitmap_destroy(struct mddev *mddev);
......
...@@ -6224,16 +6224,10 @@ int md_run(struct mddev *mddev) ...@@ -6224,16 +6224,10 @@ int md_run(struct mddev *mddev)
} }
if (err == 0 && pers->sync_request && if (err == 0 && pers->sync_request &&
(mddev->bitmap_info.file || mddev->bitmap_info.offset)) { (mddev->bitmap_info.file || mddev->bitmap_info.offset)) {
struct bitmap *bitmap; err = md_bitmap_create(mddev, -1);
if (err)
bitmap = md_bitmap_create(mddev, -1);
if (IS_ERR(bitmap)) {
err = PTR_ERR(bitmap);
pr_warn("%s: failed to create bitmap (%d)\n", pr_warn("%s: failed to create bitmap (%d)\n",
mdname(mddev), err); mdname(mddev), err);
} else
mddev->bitmap = bitmap;
} }
if (err) if (err)
goto bitmap_abort; goto bitmap_abort;
...@@ -7288,14 +7282,10 @@ static int set_bitmap_file(struct mddev *mddev, int fd) ...@@ -7288,14 +7282,10 @@ static int set_bitmap_file(struct mddev *mddev, int fd)
err = 0; err = 0;
if (mddev->pers) { if (mddev->pers) {
if (fd >= 0) { if (fd >= 0) {
struct bitmap *bitmap; err = md_bitmap_create(mddev, -1);
if (!err)
bitmap = md_bitmap_create(mddev, -1);
if (!IS_ERR(bitmap)) {
mddev->bitmap = bitmap;
err = md_bitmap_load(mddev); err = md_bitmap_load(mddev);
} else
err = PTR_ERR(bitmap);
if (err) { if (err) {
md_bitmap_destroy(mddev); md_bitmap_destroy(mddev);
fd = -1; fd = -1;
...@@ -7304,6 +7294,7 @@ static int set_bitmap_file(struct mddev *mddev, int fd) ...@@ -7304,6 +7294,7 @@ static int set_bitmap_file(struct mddev *mddev, int fd)
md_bitmap_destroy(mddev); md_bitmap_destroy(mddev);
} }
} }
if (fd < 0) { if (fd < 0) {
struct file *f = mddev->bitmap_info.file; struct file *f = mddev->bitmap_info.file;
if (f) { if (f) {
...@@ -7572,7 +7563,6 @@ static int update_array_info(struct mddev *mddev, mdu_array_info_t *info) ...@@ -7572,7 +7563,6 @@ static int update_array_info(struct mddev *mddev, mdu_array_info_t *info)
goto err; goto err;
} }
if (info->state & (1<<MD_SB_BITMAP_PRESENT)) { if (info->state & (1<<MD_SB_BITMAP_PRESENT)) {
struct bitmap *bitmap;
/* add the bitmap */ /* add the bitmap */
if (mddev->bitmap) { if (mddev->bitmap) {
rv = -EEXIST; rv = -EEXIST;
...@@ -7586,12 +7576,10 @@ static int update_array_info(struct mddev *mddev, mdu_array_info_t *info) ...@@ -7586,12 +7576,10 @@ static int update_array_info(struct mddev *mddev, mdu_array_info_t *info)
mddev->bitmap_info.default_offset; mddev->bitmap_info.default_offset;
mddev->bitmap_info.space = mddev->bitmap_info.space =
mddev->bitmap_info.default_space; mddev->bitmap_info.default_space;
bitmap = md_bitmap_create(mddev, -1); rv = md_bitmap_create(mddev, -1);
if (!IS_ERR(bitmap)) { if (!rv)
mddev->bitmap = bitmap;
rv = md_bitmap_load(mddev); rv = md_bitmap_load(mddev);
} else
rv = PTR_ERR(bitmap);
if (rv) if (rv)
md_bitmap_destroy(mddev); md_bitmap_destroy(mddev);
} else { } else {
......
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