]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
md/md-bitmap: merge md_bitmap_endwrite() into bitmap_operations
authorYu Kuai <yukuai3@huawei.com>
Mon, 26 Aug 2024 07:44:34 +0000 (15:44 +0800)
committerSong Liu <song@kernel.org>
Tue, 27 Aug 2024 17:14:17 +0000 (10:14 -0700)
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: Yu Kuai <yukuai3@huawei.com>
Link: https://lore.kernel.org/r/20240826074452.1490072-25-yukuai1@huaweicloud.com
Signed-off-by: Song Liu <song@kernel.org>
drivers/md/md-bitmap.c
drivers/md/md-bitmap.h
drivers/md/raid1.c
drivers/md/raid10.c
drivers/md/raid5-cache.c
drivers/md/raid5.c

index 0168dbd5ecb0f5c9fce66c8752f235f6885e60bf..4d174ab2533982258fd2498d6b2a7a122bff15bc 100644 (file)
@@ -1524,11 +1524,14 @@ static int bitmap_startwrite(struct mddev *mddev, sector_t offset,
        return 0;
 }
 
-void md_bitmap_endwrite(struct bitmap *bitmap, sector_t offset,
-                       unsigned long sectors, int success, int behind)
+static void bitmap_endwrite(struct mddev *mddev, sector_t offset,
+                           unsigned long sectors, bool success, bool behind)
 {
+       struct bitmap *bitmap = mddev->bitmap;
+
        if (!bitmap)
                return;
+
        if (behind) {
                if (atomic_dec_and_test(&bitmap->behind_writes))
                        wake_up(&bitmap->behind_wait);
@@ -1575,7 +1578,6 @@ void md_bitmap_endwrite(struct bitmap *bitmap, sector_t offset,
                        sectors = 0;
        }
 }
-EXPORT_SYMBOL(md_bitmap_endwrite);
 
 static int __bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks,
                               int degraded)
@@ -2731,6 +2733,7 @@ static struct bitmap_operations bitmap_ops = {
        .dirty_bits             = bitmap_dirty_bits,
 
        .startwrite             = bitmap_startwrite,
+       .endwrite               = bitmap_endwrite,
 
        .update_sb              = bitmap_update_sb,
        .get_stats              = bitmap_get_stats,
index 1433d13e447a666e6efdb90fe59bfe858e52674f..056a80ee500f578289fe6e6a68e83333b5727423 100644 (file)
@@ -257,6 +257,8 @@ struct bitmap_operations {
 
        int (*startwrite)(struct mddev *mddev, sector_t offset,
                          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);
        int (*get_stats)(struct bitmap *bitmap, struct md_bitmap_stats *stats);
@@ -266,8 +268,6 @@ struct bitmap_operations {
 void mddev_set_bitmap_ops(struct mddev *mddev);
 
 /* 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);
 void md_bitmap_end_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, int aborted);
 void md_bitmap_close_sync(struct bitmap *bitmap);
index 708687cb28d56a17e4c7248fe84279f3c4bf525b..b335293ec472883a326c03a8ed2bf661f0579153 100644 (file)
@@ -411,18 +411,20 @@ static void raid1_end_read_request(struct bio *bio)
 
 static void close_write(struct r1bio *r1_bio)
 {
+       struct mddev *mddev = r1_bio->mddev;
+
        /* it really is the end of this request */
        if (test_bit(R1BIO_BehindIO, &r1_bio->state)) {
                bio_free_pages(r1_bio->behind_master_bio);
                bio_put(r1_bio->behind_master_bio);
                r1_bio->behind_master_bio = NULL;
        }
+
        /* clear the bitmap if all writes complete successfully */
-       md_bitmap_endwrite(r1_bio->mddev->bitmap, r1_bio->sector,
-                          r1_bio->sectors,
-                          !test_bit(R1BIO_Degraded, &r1_bio->state),
-                          test_bit(R1BIO_BehindIO, &r1_bio->state));
-       md_write_end(r1_bio->mddev);
+       mddev->bitmap_ops->endwrite(mddev, r1_bio->sector, r1_bio->sectors,
+                                   !test_bit(R1BIO_Degraded, &r1_bio->state),
+                                   test_bit(R1BIO_BehindIO, &r1_bio->state));
+       md_write_end(mddev);
 }
 
 static void r1_bio_write_done(struct r1bio *r1_bio)
index 8f9172c3329a81865b01225f32fe864a1b337b5c..ce28150e0464a856de52eee6b11c7bdac633ea63 100644 (file)
@@ -426,12 +426,13 @@ static void raid10_end_read_request(struct bio *bio)
 
 static void close_write(struct r10bio *r10_bio)
 {
+       struct mddev *mddev = r10_bio->mddev;
+
        /* clear the bitmap if all writes complete successfully */
-       md_bitmap_endwrite(r10_bio->mddev->bitmap, r10_bio->sector,
-                          r10_bio->sectors,
-                          !test_bit(R10BIO_Degraded, &r10_bio->state),
-                          0);
-       md_write_end(r10_bio->mddev);
+       mddev->bitmap_ops->endwrite(mddev, r10_bio->sector, r10_bio->sectors,
+                                   !test_bit(R10BIO_Degraded, &r10_bio->state),
+                                   false);
+       md_write_end(mddev);
 }
 
 static void one_write_done(struct r10bio *r10_bio)
index 874874fe4fa12de97c0b442cd37d9d2484bca24a..23f2cbcf1a6c4f0856aaa4562636475b894abeeb 100644 (file)
@@ -313,10 +313,10 @@ void r5c_handle_cached_data_endio(struct r5conf *conf,
                if (sh->dev[i].written) {
                        set_bit(R5_UPTODATE, &sh->dev[i].flags);
                        r5c_return_dev_pending_writes(conf, &sh->dev[i]);
-                       md_bitmap_endwrite(conf->mddev->bitmap, sh->sector,
-                                          RAID5_STRIPE_SECTORS(conf),
-                                          !test_bit(STRIPE_DEGRADED, &sh->state),
-                                          0);
+                       conf->mddev->bitmap_ops->endwrite(conf->mddev,
+                                       sh->sector, RAID5_STRIPE_SECTORS(conf),
+                                       !test_bit(STRIPE_DEGRADED, &sh->state),
+                                       false);
                }
        }
 }
index c24036d1e6dade717de3039c15adf3ad19c2b633..93d582b9f922e34fa3e4f97a1c28bcdad873e53e 100644 (file)
@@ -3663,8 +3663,9 @@ handle_failed_stripe(struct r5conf *conf, struct stripe_head *sh,
                        bi = nextbi;
                }
                if (bitmap_end)
-                       md_bitmap_endwrite(conf->mddev->bitmap, sh->sector,
-                                          RAID5_STRIPE_SECTORS(conf), 0, 0);
+                       conf->mddev->bitmap_ops->endwrite(conf->mddev,
+                                       sh->sector, RAID5_STRIPE_SECTORS(conf),
+                                       false, false);
                bitmap_end = 0;
                /* and fail all 'written' */
                bi = sh->dev[i].written;
@@ -3709,8 +3710,9 @@ handle_failed_stripe(struct r5conf *conf, struct stripe_head *sh,
                        }
                }
                if (bitmap_end)
-                       md_bitmap_endwrite(conf->mddev->bitmap, sh->sector,
-                                          RAID5_STRIPE_SECTORS(conf), 0, 0);
+                       conf->mddev->bitmap_ops->endwrite(conf->mddev,
+                                       sh->sector, RAID5_STRIPE_SECTORS(conf),
+                                       false, false);
                /* If we were in the middle of a write the parity block might
                 * still be locked - so just clear all R5_LOCKED flags
                 */
@@ -4059,10 +4061,10 @@ returnbi:
                                        bio_endio(wbi);
                                        wbi = wbi2;
                                }
-                               md_bitmap_endwrite(conf->mddev->bitmap, sh->sector,
-                                                  RAID5_STRIPE_SECTORS(conf),
-                                                  !test_bit(STRIPE_DEGRADED, &sh->state),
-                                                  0);
+                               conf->mddev->bitmap_ops->endwrite(conf->mddev,
+                                       sh->sector, RAID5_STRIPE_SECTORS(conf),
+                                       !test_bit(STRIPE_DEGRADED, &sh->state),
+                                       false);
                                if (head_sh->batch_head) {
                                        sh = list_first_entry(&sh->batch_list,
                                                              struct stripe_head,