Skip to content

Commit c4a3955

Browse files
jbrassowneilbrown
authored andcommitted
MD: Remember the last sync operation that was performed
MD: Remember the last sync operation that was performed This patch adds a field to the mddev structure to track the last sync operation that was performed. This is especially useful when it comes to what is recorded in mismatch_cnt in sysfs. If the last operation was "data-check", then it reports the number of descrepancies found by the user-initiated check. If it was a "repair" operation, then it is reporting the number of descrepancies repaired. etc. Signed-off-by: Jonathan Brassow <[email protected]> Signed-off-by: NeilBrown <[email protected]>
1 parent eea136d commit c4a3955

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

Documentation/device-mapper/dm-raid.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,4 @@ Version History
223223
1.5.0 Add message interface to allow manipulation of the sync_action.
224224
New status (STATUSTYPE_INFO) fields: sync_action and mismatch_cnt.
225225
1.5.1 Add ability to restore transiently failed devices on resume.
226+
1.5.2 'mismatch_cnt' is zero unless [last_]sync_action is "check".

drivers/md/dm-raid.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,7 @@ static void raid_status(struct dm_target *ti, status_type_t type,
13881388
* performing a "check" of the array.
13891389
*/
13901390
DMEMIT(" %llu",
1391+
(strcmp(rs->md.last_sync_action, "check")) ? 0 :
13911392
(unsigned long long)
13921393
atomic64_read(&rs->md.resync_mismatches));
13931394
break;
@@ -1651,7 +1652,7 @@ static void raid_resume(struct dm_target *ti)
16511652

16521653
static struct target_type raid_target = {
16531654
.name = "raid",
1654-
.version = {1, 5, 1},
1655+
.version = {1, 5, 2},
16551656
.module = THIS_MODULE,
16561657
.ctr = raid_ctr,
16571658
.dtr = raid_dtr,

drivers/md/md.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ void mddev_init(struct mddev *mddev)
521521
init_waitqueue_head(&mddev->recovery_wait);
522522
mddev->reshape_position = MaxSector;
523523
mddev->reshape_backwards = 0;
524+
mddev->last_sync_action = "none";
524525
mddev->resync_min = 0;
525526
mddev->resync_max = MaxSector;
526527
mddev->level = LEVEL_NONE;
@@ -4272,6 +4273,17 @@ action_store(struct mddev *mddev, const char *page, size_t len)
42724273
return len;
42734274
}
42744275

4276+
static struct md_sysfs_entry md_scan_mode =
4277+
__ATTR(sync_action, S_IRUGO|S_IWUSR, action_show, action_store);
4278+
4279+
static ssize_t
4280+
last_sync_action_show(struct mddev *mddev, char *page)
4281+
{
4282+
return sprintf(page, "%s\n", mddev->last_sync_action);
4283+
}
4284+
4285+
static struct md_sysfs_entry md_last_scan_mode = __ATTR_RO(last_sync_action);
4286+
42754287
static ssize_t
42764288
mismatch_cnt_show(struct mddev *mddev, char *page)
42774289
{
@@ -4280,10 +4292,6 @@ mismatch_cnt_show(struct mddev *mddev, char *page)
42804292
atomic64_read(&mddev->resync_mismatches));
42814293
}
42824294

4283-
static struct md_sysfs_entry md_scan_mode =
4284-
__ATTR(sync_action, S_IRUGO|S_IWUSR, action_show, action_store);
4285-
4286-
42874295
static struct md_sysfs_entry md_mismatches = __ATTR_RO(mismatch_cnt);
42884296

42894297
static ssize_t
@@ -4686,6 +4694,7 @@ static struct attribute *md_default_attrs[] = {
46864694

46874695
static struct attribute *md_redundancy_attrs[] = {
46884696
&md_scan_mode.attr,
4697+
&md_last_scan_mode.attr,
46894698
&md_mismatches.attr,
46904699
&md_sync_min.attr,
46914700
&md_sync_max.attr,
@@ -7329,7 +7338,7 @@ void md_do_sync(struct md_thread *thread)
73297338
sector_t last_check;
73307339
int skipped = 0;
73317340
struct md_rdev *rdev;
7332-
char *desc;
7341+
char *desc, *action = NULL;
73337342
struct blk_plug plug;
73347343

73357344
/* just incase thread restarts... */
@@ -7339,17 +7348,21 @@ void md_do_sync(struct md_thread *thread)
73397348
return;
73407349

73417350
if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) {
7342-
if (test_bit(MD_RECOVERY_CHECK, &mddev->recovery))
7351+
if (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)) {
73437352
desc = "data-check";
7344-
else if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery))
7353+
action = "check";
7354+
} else if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) {
73457355
desc = "requested-resync";
7346-
else
7356+
action = "repair";
7357+
} else
73477358
desc = "resync";
73487359
} else if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery))
73497360
desc = "reshape";
73507361
else
73517362
desc = "recovery";
73527363

7364+
mddev->last_sync_action = action ?: desc;
7365+
73537366
/* we overload curr_resync somewhat here.
73547367
* 0 == not engaged in resync at all
73557368
* 2 == checking that there is no conflict with another sync

drivers/md/md.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,14 @@ struct mddev {
268268

269269
struct md_thread *thread; /* management thread */
270270
struct md_thread *sync_thread; /* doing resync or reconstruct */
271+
272+
/* 'last_sync_action' is initialized to "none". It is set when a
273+
* sync operation (i.e "data-check", "requested-resync", "resync",
274+
* "recovery", or "reshape") is started. It holds this value even
275+
* when the sync thread is "frozen" (interrupted) or "idle" (stopped
276+
* or finished). It is overwritten when a new sync operation is begun.
277+
*/
278+
char *last_sync_action;
271279
sector_t curr_resync; /* last block scheduled */
272280
/* As resync requests can complete out of order, we cannot easily track
273281
* how much resync has been completed. So we occasionally pause until

0 commit comments

Comments
 (0)