Commit 7f7583d4 authored by Jianpeng Ma's avatar Jianpeng Ma Committed by NeilBrown

Subject: [PATCH] md:change resync_mismatches to atomic64_t to avoid races

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: default avatarJianpeng Ma <majianpeng@gmail.com>
Signed-off-by: default avatarNeilBrown <neilb@suse.de>
parent 1ed850f3
...@@ -4269,7 +4269,8 @@ static ssize_t ...@@ -4269,7 +4269,8 @@ static ssize_t
mismatch_cnt_show(struct mddev *mddev, char *page) mismatch_cnt_show(struct mddev *mddev, char *page)
{ {
return sprintf(page, "%llu\n", 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 = static struct md_sysfs_entry md_scan_mode =
...@@ -5235,7 +5236,7 @@ static void md_clean(struct mddev *mddev) ...@@ -5235,7 +5236,7 @@ static void md_clean(struct mddev *mddev)
mddev->new_layout = 0; mddev->new_layout = 0;
mddev->new_chunk_sectors = 0; mddev->new_chunk_sectors = 0;
mddev->curr_resync = 0; mddev->curr_resync = 0;
mddev->resync_mismatches = 0; atomic64_set(&mddev->resync_mismatches, 0);
mddev->suspend_lo = mddev->suspend_hi = 0; mddev->suspend_lo = mddev->suspend_hi = 0;
mddev->sync_speed_min = mddev->sync_speed_max = 0; mddev->sync_speed_min = mddev->sync_speed_max = 0;
mddev->recovery = 0; mddev->recovery = 0;
...@@ -7357,7 +7358,7 @@ void md_do_sync(struct md_thread *thread) ...@@ -7357,7 +7358,7 @@ void md_do_sync(struct md_thread *thread)
* which defaults to physical size, but can be virtual size * which defaults to physical size, but can be virtual size
*/ */
max_sectors = mddev->resync_max_sectors; 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 */ /* we don't use the checkpoint if there's a bitmap */
if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery))
j = mddev->resync_min; j = mddev->resync_min;
......
...@@ -282,7 +282,7 @@ struct mddev { ...@@ -282,7 +282,7 @@ struct mddev {
sector_t resync_max_sectors; /* may be set by personality */ 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 * parity/replica mismatch found
*/ */
......
...@@ -1876,7 +1876,7 @@ static int process_checks(struct r1bio *r1_bio) ...@@ -1876,7 +1876,7 @@ static int process_checks(struct r1bio *r1_bio)
} else } else
j = 0; j = 0;
if (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) if (j < 0 || (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)
&& test_bit(BIO_UPTODATE, &sbio->bi_flags))) { && test_bit(BIO_UPTODATE, &sbio->bi_flags))) {
/* No need to write to this device. */ /* No need to write to this device. */
......
...@@ -2011,7 +2011,7 @@ static void sync_request_write(struct mddev *mddev, struct r10bio *r10_bio) ...@@ -2011,7 +2011,7 @@ static void sync_request_write(struct mddev *mddev, struct r10bio *r10_bio)
break; break;
if (j == vcnt) if (j == vcnt)
continue; continue;
mddev->resync_mismatches += r10_bio->sectors; atomic64_add(r10_bio->sectors, &mddev->resync_mismatches);
if (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)) if (test_bit(MD_RECOVERY_CHECK, &mddev->recovery))
/* Don't fix anything. */ /* Don't fix anything. */
continue; continue;
......
...@@ -2973,7 +2973,7 @@ static void handle_parity_checks5(struct r5conf *conf, struct stripe_head *sh, ...@@ -2973,7 +2973,7 @@ static void handle_parity_checks5(struct r5conf *conf, struct stripe_head *sh,
*/ */
set_bit(STRIPE_INSYNC, &sh->state); set_bit(STRIPE_INSYNC, &sh->state);
else { else {
conf->mddev->resync_mismatches += STRIPE_SECTORS; atomic64_add(STRIPE_SECTORS, &conf->mddev->resync_mismatches);
if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery)) if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery))
/* don't try to repair!! */ /* don't try to repair!! */
set_bit(STRIPE_INSYNC, &sh->state); set_bit(STRIPE_INSYNC, &sh->state);
...@@ -3125,7 +3125,7 @@ static void handle_parity_checks6(struct r5conf *conf, struct stripe_head *sh, ...@@ -3125,7 +3125,7 @@ static void handle_parity_checks6(struct r5conf *conf, struct stripe_head *sh,
*/ */
} }
} else { } else {
conf->mddev->resync_mismatches += STRIPE_SECTORS; atomic64_add(STRIPE_SECTORS, &conf->mddev->resync_mismatches);
if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery)) if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery))
/* don't try to repair!! */ /* don't try to repair!! */
set_bit(STRIPE_INSYNC, &sh->state); set_bit(STRIPE_INSYNC, &sh->state);
......
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