Commit 3486015f authored by Yu Kuai's avatar Yu Kuai Committed by Song Liu

md/md-bitmap: merge md_bitmap_endwrite() into bitmap_operations

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

Also change the parameter from bitmap to mddev, to avoid access
bitmap outside md-bitmap.c as much as possible. And change the type
of 'success' and 'behind' from int to bool.
Signed-off-by: default avatarYu Kuai <yukuai3@huawei.com>
Link: https://lore.kernel.org/r/20240826074452.1490072-25-yukuai1@huaweicloud.comSigned-off-by: default avatarSong Liu <song@kernel.org>
parent c2257df4
...@@ -1524,11 +1524,14 @@ static int bitmap_startwrite(struct mddev *mddev, sector_t offset, ...@@ -1524,11 +1524,14 @@ static int bitmap_startwrite(struct mddev *mddev, sector_t offset,
return 0; return 0;
} }
void md_bitmap_endwrite(struct bitmap *bitmap, sector_t offset, static void bitmap_endwrite(struct mddev *mddev, sector_t offset,
unsigned long sectors, int success, int behind) unsigned long sectors, bool success, bool behind)
{ {
struct bitmap *bitmap = mddev->bitmap;
if (!bitmap) if (!bitmap)
return; return;
if (behind) { if (behind) {
if (atomic_dec_and_test(&bitmap->behind_writes)) if (atomic_dec_and_test(&bitmap->behind_writes))
wake_up(&bitmap->behind_wait); wake_up(&bitmap->behind_wait);
...@@ -1575,7 +1578,6 @@ void md_bitmap_endwrite(struct bitmap *bitmap, sector_t offset, ...@@ -1575,7 +1578,6 @@ void md_bitmap_endwrite(struct bitmap *bitmap, sector_t offset,
sectors = 0; sectors = 0;
} }
} }
EXPORT_SYMBOL(md_bitmap_endwrite);
static int __bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, static int __bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks,
int degraded) int degraded)
...@@ -2731,6 +2733,7 @@ static struct bitmap_operations bitmap_ops = { ...@@ -2731,6 +2733,7 @@ static struct bitmap_operations bitmap_ops = {
.dirty_bits = bitmap_dirty_bits, .dirty_bits = bitmap_dirty_bits,
.startwrite = bitmap_startwrite, .startwrite = bitmap_startwrite,
.endwrite = bitmap_endwrite,
.update_sb = bitmap_update_sb, .update_sb = bitmap_update_sb,
.get_stats = bitmap_get_stats, .get_stats = bitmap_get_stats,
......
...@@ -257,6 +257,8 @@ struct bitmap_operations { ...@@ -257,6 +257,8 @@ struct bitmap_operations {
int (*startwrite)(struct mddev *mddev, sector_t offset, int (*startwrite)(struct mddev *mddev, sector_t offset,
unsigned long sectors, bool behind); unsigned long sectors, bool behind);
void (*endwrite)(struct mddev *mddev, sector_t offset,
unsigned long sectors, bool success, bool behind);
void (*update_sb)(struct bitmap *bitmap); void (*update_sb)(struct bitmap *bitmap);
int (*get_stats)(struct bitmap *bitmap, struct md_bitmap_stats *stats); int (*get_stats)(struct bitmap *bitmap, struct md_bitmap_stats *stats);
...@@ -266,8 +268,6 @@ struct bitmap_operations { ...@@ -266,8 +268,6 @@ struct bitmap_operations {
void mddev_set_bitmap_ops(struct mddev *mddev); void mddev_set_bitmap_ops(struct mddev *mddev);
/* these are exported */ /* these are exported */
void md_bitmap_endwrite(struct bitmap *bitmap, sector_t offset,
unsigned long sectors, int success, int behind);
int md_bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, int degraded); int md_bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, int degraded);
void md_bitmap_end_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, int aborted); void md_bitmap_end_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, int aborted);
void md_bitmap_close_sync(struct bitmap *bitmap); void md_bitmap_close_sync(struct bitmap *bitmap);
......
...@@ -411,18 +411,20 @@ static void raid1_end_read_request(struct bio *bio) ...@@ -411,18 +411,20 @@ static void raid1_end_read_request(struct bio *bio)
static void close_write(struct r1bio *r1_bio) static void close_write(struct r1bio *r1_bio)
{ {
struct mddev *mddev = r1_bio->mddev;
/* it really is the end of this request */ /* it really is the end of this request */
if (test_bit(R1BIO_BehindIO, &r1_bio->state)) { if (test_bit(R1BIO_BehindIO, &r1_bio->state)) {
bio_free_pages(r1_bio->behind_master_bio); bio_free_pages(r1_bio->behind_master_bio);
bio_put(r1_bio->behind_master_bio); bio_put(r1_bio->behind_master_bio);
r1_bio->behind_master_bio = NULL; r1_bio->behind_master_bio = NULL;
} }
/* clear the bitmap if all writes complete successfully */ /* clear the bitmap if all writes complete successfully */
md_bitmap_endwrite(r1_bio->mddev->bitmap, r1_bio->sector, mddev->bitmap_ops->endwrite(mddev, r1_bio->sector, r1_bio->sectors,
r1_bio->sectors,
!test_bit(R1BIO_Degraded, &r1_bio->state), !test_bit(R1BIO_Degraded, &r1_bio->state),
test_bit(R1BIO_BehindIO, &r1_bio->state)); test_bit(R1BIO_BehindIO, &r1_bio->state));
md_write_end(r1_bio->mddev); md_write_end(mddev);
} }
static void r1_bio_write_done(struct r1bio *r1_bio) static void r1_bio_write_done(struct r1bio *r1_bio)
......
...@@ -426,12 +426,13 @@ static void raid10_end_read_request(struct bio *bio) ...@@ -426,12 +426,13 @@ static void raid10_end_read_request(struct bio *bio)
static void close_write(struct r10bio *r10_bio) static void close_write(struct r10bio *r10_bio)
{ {
struct mddev *mddev = r10_bio->mddev;
/* clear the bitmap if all writes complete successfully */ /* clear the bitmap if all writes complete successfully */
md_bitmap_endwrite(r10_bio->mddev->bitmap, r10_bio->sector, mddev->bitmap_ops->endwrite(mddev, r10_bio->sector, r10_bio->sectors,
r10_bio->sectors,
!test_bit(R10BIO_Degraded, &r10_bio->state), !test_bit(R10BIO_Degraded, &r10_bio->state),
0); false);
md_write_end(r10_bio->mddev); md_write_end(mddev);
} }
static void one_write_done(struct r10bio *r10_bio) static void one_write_done(struct r10bio *r10_bio)
......
...@@ -313,10 +313,10 @@ void r5c_handle_cached_data_endio(struct r5conf *conf, ...@@ -313,10 +313,10 @@ void r5c_handle_cached_data_endio(struct r5conf *conf,
if (sh->dev[i].written) { if (sh->dev[i].written) {
set_bit(R5_UPTODATE, &sh->dev[i].flags); set_bit(R5_UPTODATE, &sh->dev[i].flags);
r5c_return_dev_pending_writes(conf, &sh->dev[i]); r5c_return_dev_pending_writes(conf, &sh->dev[i]);
md_bitmap_endwrite(conf->mddev->bitmap, sh->sector, conf->mddev->bitmap_ops->endwrite(conf->mddev,
RAID5_STRIPE_SECTORS(conf), sh->sector, RAID5_STRIPE_SECTORS(conf),
!test_bit(STRIPE_DEGRADED, &sh->state), !test_bit(STRIPE_DEGRADED, &sh->state),
0); false);
} }
} }
} }
......
...@@ -3663,8 +3663,9 @@ handle_failed_stripe(struct r5conf *conf, struct stripe_head *sh, ...@@ -3663,8 +3663,9 @@ handle_failed_stripe(struct r5conf *conf, struct stripe_head *sh,
bi = nextbi; bi = nextbi;
} }
if (bitmap_end) if (bitmap_end)
md_bitmap_endwrite(conf->mddev->bitmap, sh->sector, conf->mddev->bitmap_ops->endwrite(conf->mddev,
RAID5_STRIPE_SECTORS(conf), 0, 0); sh->sector, RAID5_STRIPE_SECTORS(conf),
false, false);
bitmap_end = 0; bitmap_end = 0;
/* and fail all 'written' */ /* and fail all 'written' */
bi = sh->dev[i].written; bi = sh->dev[i].written;
...@@ -3709,8 +3710,9 @@ handle_failed_stripe(struct r5conf *conf, struct stripe_head *sh, ...@@ -3709,8 +3710,9 @@ handle_failed_stripe(struct r5conf *conf, struct stripe_head *sh,
} }
} }
if (bitmap_end) if (bitmap_end)
md_bitmap_endwrite(conf->mddev->bitmap, sh->sector, conf->mddev->bitmap_ops->endwrite(conf->mddev,
RAID5_STRIPE_SECTORS(conf), 0, 0); sh->sector, RAID5_STRIPE_SECTORS(conf),
false, false);
/* If we were in the middle of a write the parity block might /* If we were in the middle of a write the parity block might
* still be locked - so just clear all R5_LOCKED flags * still be locked - so just clear all R5_LOCKED flags
*/ */
...@@ -4059,10 +4061,10 @@ static void handle_stripe_clean_event(struct r5conf *conf, ...@@ -4059,10 +4061,10 @@ static void handle_stripe_clean_event(struct r5conf *conf,
bio_endio(wbi); bio_endio(wbi);
wbi = wbi2; wbi = wbi2;
} }
md_bitmap_endwrite(conf->mddev->bitmap, sh->sector, conf->mddev->bitmap_ops->endwrite(conf->mddev,
RAID5_STRIPE_SECTORS(conf), sh->sector, RAID5_STRIPE_SECTORS(conf),
!test_bit(STRIPE_DEGRADED, &sh->state), !test_bit(STRIPE_DEGRADED, &sh->state),
0); false);
if (head_sh->batch_head) { if (head_sh->batch_head) {
sh = list_first_entry(&sh->batch_list, sh = list_first_entry(&sh->batch_list,
struct stripe_head, struct stripe_head,
......
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