Skip to content

Commit f9a67b1

Browse files
GuoqingJiangshligit
authored andcommitted
md/bitmap: clear bitmap if bitmap_create failed
If bitmap_create returns an error, we need to call either bitmap_destroy or bitmap_free to do clean up, and the selection is based on mddev->bitmap is set or not. And the sysfs_put(bitmap->sysfs_can_clear) is moved from bitmap_destroy to bitmap_free, and the comment of bitmap_create is changed as well. Signed-off-by: Guoqing Jiang <gqjiang@suse.com> Signed-off-by: Shaohua Li <shli@fb.com>
1 parent ed3b98c commit f9a67b1

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

drivers/md/bitmap.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,9 @@ static void bitmap_free(struct bitmap *bitmap)
16731673
if (!bitmap) /* there was no bitmap */
16741674
return;
16751675

1676+
if (bitmap->sysfs_can_clear)
1677+
sysfs_put(bitmap->sysfs_can_clear);
1678+
16761679
if (mddev_is_clustered(bitmap->mddev) && bitmap->mddev->cluster_info &&
16771680
bitmap->cluster_slot == md_cluster_ops->slot_number(bitmap->mddev))
16781681
md_cluster_stop(bitmap->mddev);
@@ -1712,15 +1715,13 @@ void bitmap_destroy(struct mddev *mddev)
17121715
if (mddev->thread)
17131716
mddev->thread->timeout = MAX_SCHEDULE_TIMEOUT;
17141717

1715-
if (bitmap->sysfs_can_clear)
1716-
sysfs_put(bitmap->sysfs_can_clear);
1717-
17181718
bitmap_free(bitmap);
17191719
}
17201720

17211721
/*
17221722
* initialize the bitmap structure
17231723
* if this returns an error, bitmap_destroy must be called to do clean up
1724+
* once mddev->bitmap is set
17241725
*/
17251726
struct bitmap *bitmap_create(struct mddev *mddev, int slot)
17261727
{
@@ -1865,8 +1866,10 @@ int bitmap_copy_from_slot(struct mddev *mddev, int slot,
18651866
struct bitmap_counts *counts;
18661867
struct bitmap *bitmap = bitmap_create(mddev, slot);
18671868

1868-
if (IS_ERR(bitmap))
1869+
if (IS_ERR(bitmap)) {
1870+
bitmap_free(bitmap);
18691871
return PTR_ERR(bitmap);
1872+
}
18701873

18711874
rv = bitmap_init_from_disk(bitmap, 0);
18721875
if (rv)
@@ -2170,14 +2173,14 @@ location_store(struct mddev *mddev, const char *buf, size_t len)
21702173
else {
21712174
mddev->bitmap = bitmap;
21722175
rv = bitmap_load(mddev);
2173-
if (rv) {
2174-
bitmap_destroy(mddev);
2176+
if (rv)
21752177
mddev->bitmap_info.offset = 0;
2176-
}
21772178
}
21782179
mddev->pers->quiesce(mddev, 0);
2179-
if (rv)
2180+
if (rv) {
2181+
bitmap_destroy(mddev);
21802182
return rv;
2183+
}
21812184
}
21822185
}
21832186
}

0 commit comments

Comments
 (0)