Commit 67143510 authored by Heinz Mauelshagen's avatar Heinz Mauelshagen Committed by Mike Snitzer

dm raid: display a consistent copy of the MD status via raid_status()

The MD sync thread updates recovery flags providing state of any
running, idle, frozen, recovering, reshaping, ... activity it performs
and updates respective flags asynchronously versus dm processing
raid_status().  To close that race window, take a single copy of the
flags and pass it into its callees.
Signed-off-by: default avatarHeinz Mauelshagen <heinzm@redhat.com>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
parent d39f0010
...@@ -3300,25 +3300,25 @@ static int raid_map(struct dm_target *ti, struct bio *bio) ...@@ -3300,25 +3300,25 @@ static int raid_map(struct dm_target *ti, struct bio *bio)
} }
/* Return string describing the current sync action of @mddev */ /* Return string describing the current sync action of @mddev */
static const char *decipher_sync_action(struct mddev *mddev) static const char *decipher_sync_action(struct mddev *mddev, unsigned long recovery)
{ {
if (test_bit(MD_RECOVERY_FROZEN, &mddev->recovery)) if (test_bit(MD_RECOVERY_FROZEN, &recovery))
return "frozen"; return "frozen";
if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) || if (test_bit(MD_RECOVERY_RUNNING, &recovery) ||
(!mddev->ro && test_bit(MD_RECOVERY_NEEDED, &mddev->recovery))) { (!mddev->ro && test_bit(MD_RECOVERY_NEEDED, &recovery))) {
if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) if (test_bit(MD_RECOVERY_RESHAPE, &recovery))
return "reshape"; return "reshape";
if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { if (test_bit(MD_RECOVERY_SYNC, &recovery)) {
if (!test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) if (!test_bit(MD_RECOVERY_REQUESTED, &recovery))
return "resync"; return "resync";
else if (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)) else if (test_bit(MD_RECOVERY_CHECK, &recovery))
return "check"; return "check";
return "repair"; return "repair";
} }
if (test_bit(MD_RECOVERY_RECOVER, &mddev->recovery)) if (test_bit(MD_RECOVERY_RECOVER, &recovery))
return "recover"; return "recover";
} }
...@@ -3350,7 +3350,7 @@ static const char *__raid_dev_status(struct raid_set *rs, struct md_rdev *rdev, ...@@ -3350,7 +3350,7 @@ static const char *__raid_dev_status(struct raid_set *rs, struct md_rdev *rdev,
} }
/* Helper to return resync/reshape progress for @rs and @array_in_sync */ /* Helper to return resync/reshape progress for @rs and @array_in_sync */
static sector_t rs_get_progress(struct raid_set *rs, static sector_t rs_get_progress(struct raid_set *rs, unsigned long recovery,
sector_t resync_max_sectors, bool *array_in_sync) sector_t resync_max_sectors, bool *array_in_sync)
{ {
sector_t r, curr_resync_completed; sector_t r, curr_resync_completed;
...@@ -3367,7 +3367,7 @@ static sector_t rs_get_progress(struct raid_set *rs, ...@@ -3367,7 +3367,7 @@ static sector_t rs_get_progress(struct raid_set *rs,
r = mddev->reshape_position; r = mddev->reshape_position;
/* Reshape is relative to the array size */ /* Reshape is relative to the array size */
if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) || if (test_bit(MD_RECOVERY_RESHAPE, &recovery) ||
r != MaxSector) { r != MaxSector) {
if (r == MaxSector) { if (r == MaxSector) {
*array_in_sync = true; *array_in_sync = true;
...@@ -3382,20 +3382,20 @@ static sector_t rs_get_progress(struct raid_set *rs, ...@@ -3382,20 +3382,20 @@ static sector_t rs_get_progress(struct raid_set *rs,
} }
/* Sync is relative to the component device size */ /* Sync is relative to the component device size */
} else if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) } else if (test_bit(MD_RECOVERY_RUNNING, &recovery))
r = curr_resync_completed; r = curr_resync_completed;
else else
r = mddev->recovery_cp; r = mddev->recovery_cp;
if ((r == MaxSector) || if ((r == MaxSector) ||
(test_bit(MD_RECOVERY_DONE, &mddev->recovery) && (test_bit(MD_RECOVERY_DONE, &recovery) &&
(mddev->curr_resync_completed == resync_max_sectors))) { (mddev->curr_resync_completed == resync_max_sectors))) {
/* /*
* Sync complete. * Sync complete.
*/ */
*array_in_sync = true; *array_in_sync = true;
r = resync_max_sectors; r = resync_max_sectors;
} else if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) { } else if (test_bit(MD_RECOVERY_REQUESTED, &recovery)) {
/* /*
* If "check" or "repair" is occurring, the raid set has * If "check" or "repair" is occurring, the raid set has
* undergone an initial sync and the health characters * undergone an initial sync and the health characters
...@@ -3438,6 +3438,7 @@ static void raid_status(struct dm_target *ti, status_type_t type, ...@@ -3438,6 +3438,7 @@ static void raid_status(struct dm_target *ti, status_type_t type,
struct r5conf *conf = mddev->private; struct r5conf *conf = mddev->private;
int i, max_nr_stripes = conf ? conf->max_nr_stripes : 0; int i, max_nr_stripes = conf ? conf->max_nr_stripes : 0;
bool array_in_sync; bool array_in_sync;
unsigned long recovery;
unsigned int raid_param_cnt = 1; /* at least 1 for chunksize */ unsigned int raid_param_cnt = 1; /* at least 1 for chunksize */
unsigned int sz = 0; unsigned int sz = 0;
unsigned int rebuild_disks; unsigned int rebuild_disks;
...@@ -3457,13 +3458,14 @@ static void raid_status(struct dm_target *ti, status_type_t type, ...@@ -3457,13 +3458,14 @@ static void raid_status(struct dm_target *ti, status_type_t type,
/* Access most recent mddev properties for status output */ /* Access most recent mddev properties for status output */
smp_rmb(); smp_rmb();
recovery = rs->md.recovery;
/* Get sensible max sectors even if raid set not yet started */ /* Get sensible max sectors even if raid set not yet started */
resync_max_sectors = test_bit(RT_FLAG_RS_PRERESUMED, &rs->runtime_flags) ? resync_max_sectors = test_bit(RT_FLAG_RS_PRERESUMED, &rs->runtime_flags) ?
mddev->resync_max_sectors : mddev->dev_sectors; mddev->resync_max_sectors : mddev->dev_sectors;
progress = rs_get_progress(rs, resync_max_sectors, &array_in_sync); progress = rs_get_progress(rs, recovery, resync_max_sectors, &array_in_sync);
resync_mismatches = (mddev->last_sync_action && !strcasecmp(mddev->last_sync_action, "check")) ? resync_mismatches = (mddev->last_sync_action && !strcasecmp(mddev->last_sync_action, "check")) ?
atomic64_read(&mddev->resync_mismatches) : 0; atomic64_read(&mddev->resync_mismatches) : 0;
sync_action = decipher_sync_action(&rs->md); sync_action = decipher_sync_action(&rs->md, recovery);
/* HM FIXME: do we want another state char for raid0? It shows 'D'/'A'/'-' now */ /* HM FIXME: do we want another state char for raid0? It shows 'D'/'A'/'-' now */
for (i = 0; i < rs->raid_disks; i++) for (i = 0; i < rs->raid_disks; i++)
......
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