From: Yu Kuai <yukuai3@xxxxxxxxxx> 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@xxxxxxxxxx> --- drivers/md/md-bitmap.c | 6 ++++-- drivers/md/md-bitmap.h | 15 +++++++++++++-- drivers/md/raid1.c | 3 ++- drivers/md/raid10.c | 2 +- drivers/md/raid5.c | 5 ++--- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c index b85ae1bf2b7d..75e87073e3bc 100644 --- a/drivers/md/md-bitmap.c +++ b/drivers/md/md-bitmap.c @@ -1460,7 +1460,8 @@ __acquires(bitmap->lock) &(bitmap->bp[page].map[pageoff]); } -int md_bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sectors, int behind) +static int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, + unsigned long sectors, int behind) { if (!bitmap) return 0; @@ -1522,7 +1523,6 @@ int md_bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long s } return 0; } -EXPORT_SYMBOL(md_bitmap_startwrite); void md_bitmap_endwrite(struct bitmap *bitmap, sector_t offset, unsigned long sectors, int success, int behind) @@ -2716,6 +2716,8 @@ static struct bitmap_operations bitmap_ops = { .write_all = bitmap_write_all, .dirty_bits = bitmap_dirty_bits, + .startwrite = bitmap_startwrite, + .update_sb = bitmap_update_sb, }; diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h index b708a25bd6f4..166cc2a44909 100644 --- a/drivers/md/md-bitmap.h +++ b/drivers/md/md-bitmap.h @@ -243,6 +243,9 @@ struct bitmap_operations { void (*write_all)(struct bitmap *bitmap); void (*dirty_bits)(struct bitmap *bitmap, unsigned long s, unsigned long e); + int (*startwrite)(struct bitmap *bitmap, sector_t offset, + unsigned long sectors, int behind); + void (*update_sb)(struct bitmap *bitmap); }; @@ -316,8 +319,16 @@ static inline void md_bitmap_dirty_bits(struct mddev *mddev, unsigned long s, } /* these are exported */ -int md_bitmap_startwrite(struct bitmap *bitmap, sector_t offset, - unsigned long sectors, int behind); +static inline int md_bitmap_startwrite(struct mddev *mddev, sector_t offset, + unsigned long sectors, int behind) +{ + if (!mddev->bitmap || !mddev->bitmap_ops->startwrite) + return -EOPNOTSUPP; + + return mddev->bitmap_ops->startwrite(mddev->bitmap, offset, sectors, + behind); +} + 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); diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c index 7acfe7c9dc8d..16e741bde382 100644 --- a/drivers/md/raid1.c +++ b/drivers/md/raid1.c @@ -1617,7 +1617,8 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio, alloc_behind_master_bio(r1_bio, bio); } - md_bitmap_startwrite(bitmap, r1_bio->sector, r1_bio->sectors, + md_bitmap_startwrite(mddev, r1_bio->sector, + r1_bio->sectors, test_bit(R1BIO_BehindIO, &r1_bio->state)); first_clone = 0; } diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c index 2a9c4ee982e0..34948fef1339 100644 --- a/drivers/md/raid10.c +++ b/drivers/md/raid10.c @@ -1492,7 +1492,7 @@ static void raid10_write_request(struct mddev *mddev, struct bio *bio, md_account_bio(mddev, &bio); r10_bio->master_bio = bio; atomic_set(&r10_bio->remaining, 1); - md_bitmap_startwrite(mddev->bitmap, r10_bio->sector, r10_bio->sectors, 0); + md_bitmap_startwrite(mddev, r10_bio->sector, r10_bio->sectors, 0); for (i = 0; i < conf->copies; i++) { if (r10_bio->devs[i].bio) diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index c14cf2410365..127e4b4c6c20 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -3563,7 +3563,7 @@ static void __add_stripe_bio(struct stripe_head *sh, struct bio *bi, */ set_bit(STRIPE_BITMAP_PENDING, &sh->state); spin_unlock_irq(&sh->stripe_lock); - md_bitmap_startwrite(conf->mddev->bitmap, sh->sector, + md_bitmap_startwrite(conf->mddev, sh->sector, RAID5_STRIPE_SECTORS(conf), 0); spin_lock_irq(&sh->stripe_lock); clear_bit(STRIPE_BITMAP_PENDING, &sh->state); @@ -5791,8 +5791,7 @@ static void make_discard_request(struct mddev *mddev, struct bio *bi) for (d = 0; d < conf->raid_disks - conf->max_degraded; d++) - md_bitmap_startwrite(mddev->bitmap, - sh->sector, + md_bitmap_startwrite(mddev, sh->sector, RAID5_STRIPE_SECTORS(conf), 0); sh->bm_seq = conf->seq_flush + 1; -- 2.39.2