]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
Subject: [PATCH] md:change resync_mismatches to atomic64_t to avoid races
authorJianpeng Ma <majianpeng@gmail.com>
Thu, 27 Sep 2012 02:37:30 +0000 (12:37 +1000)
committerNeilBrown <neilb@suse.de>
Thu, 27 Sep 2012 02:37:30 +0000 (12:37 +1000)
Now that multiple threads can handle stripes, it is safer to
use an atomic64_t for resync_mismatches, to avoid update races.

Signed-off-by: Jianpeng Ma <majianpeng@gmail.com>
Signed-off-by: NeilBrown <neilb@suse.de>
drivers/md/md.c
drivers/md/md.h
drivers/md/raid1.c
drivers/md/raid10.c
drivers/md/raid5.c

index a75fd91c9b0fb685abb3bd5571e72468376116cf..373b3ebf353a0fafb9405d7855a27e820edfb576 100644 (file)
@@ -4306,7 +4306,8 @@ static ssize_t
 mismatch_cnt_show(struct mddev *mddev, char *page)
 {
        return sprintf(page, "%llu\n",
-                      (unsigned long long) mddev->resync_mismatches);
+                      (unsigned long long)
+                      atomic64_read(&mddev->resync_mismatches));
 }
 
 static struct md_sysfs_entry md_scan_mode =
@@ -5277,7 +5278,7 @@ static void md_clean(struct mddev *mddev)
        mddev->new_layout = 0;
        mddev->new_chunk_sectors = 0;
        mddev->curr_resync = 0;
-       mddev->resync_mismatches = 0;
+       atomic64_set(&mddev->resync_mismatches, 0);
        mddev->suspend_lo = mddev->suspend_hi = 0;
        mddev->sync_speed_min = mddev->sync_speed_max = 0;
        mddev->recovery = 0;
@@ -7403,7 +7404,7 @@ void md_do_sync(struct md_thread *thread)
                 * which defaults to physical size, but can be virtual size
                 */
                max_sectors = mddev->resync_max_sectors;
-               mddev->resync_mismatches = 0;
+               atomic64_set(&mddev->resync_mismatches, 0);
                /* we don't use the checkpoint if there's a bitmap */
                if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery))
                        j = mddev->resync_min;
index dce301ced932c188557d54038088f6a06cec3842..719a6eb1abf3d8406146e1a28030d1d4fc02fd7b 100644 (file)
@@ -282,7 +282,7 @@ struct mddev {
 
        sector_t                        resync_max_sectors; /* may be set by personality */
 
-       sector_t                        resync_mismatches; /* count of sectors where
+       atomic64_t                      resync_mismatches; /* count of sectors where
                                                            * parity/replica mismatch found
                                                            */
 
index d705f9e495b75cb5fb4d3fb1acbe3b845dec4247..68d457064c0ab194821cd54c3392290214c0db75 100644 (file)
@@ -1875,7 +1875,7 @@ static int process_checks(struct r1bio *r1_bio)
                } else
                        j = 0;
                if (j >= 0)
-                       mddev->resync_mismatches += r1_bio->sectors;
+                       atomic64_add(r1_bio->sectors, &mddev->resync_mismatches);
                if (j < 0 || (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)
                              && test_bit(BIO_UPTODATE, &sbio->bi_flags))) {
                        /* No need to write to this device. */
index a456e2e6b72d3fec32988a50b468c13eee5606c8..56149ce3278e7af38cff6e90faabed2e58f30bd9 100644 (file)
@@ -2012,7 +2012,7 @@ static void sync_request_write(struct mddev *mddev, struct r10bio *r10_bio)
                                        break;
                        if (j == vcnt)
                                continue;
-                       mddev->resync_mismatches += r10_bio->sectors;
+                       atomic64_add(r10_bio->sectors, &mddev->resync_mismatches);
                        if (test_bit(MD_RECOVERY_CHECK, &mddev->recovery))
                                /* Don't fix anything. */
                                continue;
index 7840e8cc20bb9552e7ddf14af12bdac75b0c057d..8321e81395e2b3d38243c4406b7d887a3d80e596 100644 (file)
@@ -3023,7 +3023,7 @@ static void handle_parity_checks5(struct r5conf *conf, struct stripe_head *sh,
                         */
                        set_bit(STRIPE_INSYNC, &sh->state);
                else {
-                       conf->mddev->resync_mismatches += STRIPE_SECTORS;
+                       atomic64_add(STRIPE_SECTORS, &conf->mddev->resync_mismatches);
                        if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery))
                                /* don't try to repair!! */
                                set_bit(STRIPE_INSYNC, &sh->state);
@@ -3175,7 +3175,7 @@ static void handle_parity_checks6(struct r5conf *conf, struct stripe_head *sh,
                                 */
                        }
                } else {
-                       conf->mddev->resync_mismatches += STRIPE_SECTORS;
+                       atomic64_add(STRIPE_SECTORS, &conf->mddev->resync_mismatches);
                        if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery))
                                /* don't try to repair!! */
                                set_bit(STRIPE_INSYNC, &sh->state);