dm raid: fix deadlocks and sync ratio races
Subsystems (2)
v2 cover dm raid: fix deadlocks and sync ratio races
This is version 2 of the patch series addressing issues causing deadlocks under load and sync ratio/action and health char races. I reordered patches and split a large one further up.
Patches 1-8 are critical with 6-8 to be applied in order and 9-11 providing cleanups and 12 adding an additional constructor check.
Patch 1:
fix reshape conversion deadlock under io load by moving md_stop_writes() to post suspend thus allowing the MD resync thread to work until after the raid set got quiesced.
Patch 2:
be prepared for MD raid personalities to adjust rdev sectors after finishing a reshape conversion (MD upstream commit c6563a8c38fde3c1c7fc925a10bde3ca20799301)
Patch 3:
avoid bogus resize assumption when reshsaping. Needed becaue of patch 2.
Patch 4:
fix raid set size revalidation for disk adding reshape and related deadlock: do it before starting the reshape when shrinking and after when growing (i.e. remove/add stripes). Avoids random deadlocks.
Patch 5:
fix reshape staying frozen on multiple table reloads. Only the last table reload may unfreeze the raid set so that the proper reshape position can be retrieved from the superblocks read in the constructor.
Patch 6:
close an recovery flag race in raid_status() and its callees by taking a copy and passing it on.
Patch 7:
avoid the array_in_sync variale in preparation for more state to pass between raid_status() and its callees.
Patch 8:
fix various sync state issues causing racy/bogus sync ratio, sync_action ad health chars in dm_status() info output.
Patch 9:
cleanup grouping the definition of raid set rw and in_sync with mddev_suspend
Patch 10+11:
cleanup removing an unused struct member and fix comments
Patch 12:
enhance adding a data component device size check to the constructor (i.e. reject on small component data devices)
Resolves: rhbz1210637 Resolves: rhbz1372101 Related: rhbz1388632 Resolves: rhbz1507729 Resolves: rhbz1508070 Related: rhbz1514215 Resolves: rhbz1514500
Heinz Mauelshagen (12):
dm raid: fix deadlock caused by stopped writes
dm raid: correct sizes and check of component devices dm raid: correct resizing state in ctr
dm raid: correct raid set size revalidation
dm raid: enhance resume() frozen checks
dm raid: close MD recovery flags race window
dm raid: avoid array_in_sync variable
dm raid: fix rs_get_progress() synchronization state/ratio dm raid: group rw and in_sync definitions with mddev_resume() dm raid: remove unused "struct raid_set" member
dm raid: comments
dm raid: add component device size check
Documentation/device-mapper/dm-raid.txt | 3 +- drivers/md/dm-raid.c | 274 ++++++++++++++++++++++---------- 2 files changed, 191 insertions(+), 86 deletions(-)
Signature · 1 line
2.13.6
PATCH v2 1/12 dm raid: fix deadlock caused by stopped writes
md_stop_writes() is called in presuspend causing deadlocks on bios submitted afterwards which happens on loaded raid sets with conversion requests.
Fix by moving md_stop_writes to postsuspend.
Hence the raid set is quiesced remove superfluous
readonly setting too.
Adjust target version to be able to recognize the fix.
--- Documentation/device-mapper/dm-raid.txt | 3 ++- drivers/md/dm-raid.c | 20 +++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-)
Documentation/device-mapper/dm-raid.txt +2 -1
@@ -343,5 +343,6 @@ Version History 1.11.0 Fix table line argument order (wrong raid10_copies/raid10_format sequence) 1.11.1 Add raid4/5/6 journal write-back support via journal_mode option -1.12.1 fix for MD deadlock between mddev_suspend() and md_write_start() available +1.12.1 Fix for MD deadlock between mddev_suspend() and md_write_start() available 1.13.0 Fix dev_health status at end of "recover" (was 'a', now 'A') +1.13.1 Fix deadlock caused by early md_stop_writes()
drivers/md/dm-raid.c +9 -11
@@ -3613,24 +3613,23 @@ static void raid_io_hints(struct dm_target *ti, struct queue_limits *limits)blk_limits_io_opt (limits, chunk_size *mddev_data_stripes (rs)); } -static void raid_presuspend (struct dm_target *ti) -{ -struct raid_set *rs = ti->private; - -md_stop_writes (&rs->md); -} -static void raid_postsuspend (struct dm_target *ti) {struct raid_set *rs = ti->private;if (!test_and_set_bit (RT_FLAG_RS_SUSPENDED , &rs->runtime_flags)) { +/* +* Writes have to be stopped before suspending to avoid deadlocks. +* +* https://bugzilla.redhat.com/show_bug.cgi?id=1514539 +*/ +if (!test_bit (MD_RECOVERY_FROZEN , &rs->md.recovery)) +md_stop_writes (&rs->md); +mddev_lock_nointr (&rs->md);mddev_suspend (&rs->md);mddev_unlock (&rs->md); } - - rs->md.ro =1 ; }static void attempt_restore_of_faulty_devices (struct raid_set *rs)
@@ -3894,7 +3893,7 @@ static void raid_resume(struct dm_target *ti)static struct target_type raid_target = { .name ="raid" , - .version = {1 ,13 ,0 }, + .version = {1 ,13 ,1 }, .module =THIS_MODULE , .ctr = raid_ctr, .dtr = raid_dtr,
@@ -3903,7 +3902,6 @@ static struct target_type raid_target = { .message = raid_message, .iterate_devices = raid_iterate_devices, .io_hints = raid_io_hints, - .presuspend = raid_presuspend, .postsuspend = raid_postsuspend, .preresume = raid_preresume, .resume = raid_resume,
Signature · 1 line
2.13.6
PATCH v2 2/12 dm raid: correct sizes and check of component devices
In reply to Heinz MauelshagenThe md raid personalities call md_finish_reshape() at the end of a reshape conversion which adjusts rdev->sectors.
Correct/check rdev->sectors before initiating a reshape and raise the recovery pointer accordingly.
--- drivers/md/dm-raid.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-)
drivers/md/dm-raid.c +35 -1
@@ -2640,12 +2640,19 @@ static int rs_adjust_data_offsets(struct raid_set *rs)* Make sure we got a minimum amount of free sectors per device */ if (rs->data_offset && -to_sector (i_size_read (rdev->bdev->bd_inode)) - rdev->sectors <MIN_FREE_RESHAPE_SPACE ) { +to_sector (i_size_read (rdev->bdev->bd_inode)) - rs->md.dev_sectors <MIN_FREE_RESHAPE_SPACE ) { rs->ti->error = data_offset ?"No space for forward reshape" :"No space for backward reshape" ;return -ENOSPC ; } out: +/* +* Raise recovery_cp in case data_offset != 0 to +* avoid false recovery positives in the constructor. +*/ +if (rs->md.recovery_cp < rs->md.dev_sectors) + rs->md.recovery_cp += rs->dev[0 ].rdev.data_offset; +/* Adjust data offsets on all rdevs but on any raid4/5/6 journal device */ rdev_for_each (rdev, &rs->md) {if (!test_bit (Journal, &rdev->flags)) {
@@ -2777,6 +2784,23 @@ static int rs_prepare_reshape(struct raid_set *rs)return 0 ; } +/* Get reshape sectors from data_offsets or raid set */ +static sector_t _get_reshape_sectors (struct raid_set *rs) +{ +struct md_rdev *rdev; +sector_t reshape_sectors =0 ; + +rdev_for_each (rdev, &rs->md) +if (!test_bit (Journal, &rdev->flags)) { + reshape_sectors = (rdev->data_offset > rdev->new_data_offset) ? + rdev->data_offset - rdev->new_data_offset : + rdev->new_data_offset - rdev->data_offset; +break ; + } + +return max (reshape_sectors, (sector_t ) rs->data_offset); +} +/* * * - change raid layout
@@ -2788,6 +2812,7 @@ static int rs_setup_reshape(struct raid_set *rs) {int r =0 ;unsigned int cur_raid_devs, d; +sector_t reshape_sectors =_get_reshape_sectors (rs);struct mddev *mddev = &rs->md;struct md_rdev *rdev;
@@ -2874,6 +2899,15 @@ static int rs_setup_reshape(struct raid_set *rs) mddev->reshape_backwards = rs->dev[0 ].rdev.data_offset ?0 :1 ; } +/* +* Adjust device size for forward reshape +* because md_finish_reshape() reduces it. +*/ +if (!mddev->reshape_backwards) +rdev_for_each (rdev, &rs->md) +if (!test_bit (Journal, &rdev->flags)) + rdev->sectors += reshape_sectors; +return r; }
Signature · 1 line
2.13.6
PATCH v2 3/12 dm raid: correct resizing state in ctr
In reply to Heinz MauelshagenPay attention to existing reshape space to define if a raid set needs resizing or we can hit "Can't resize a reshaping raid set"
when a reshape is being requested.
--- drivers/md/dm-raid.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/md/dm-raid.c +6 -4
@@ -2969,10 +2969,10 @@ static void configure_discard_support(struct raid_set *rs)static int raid_ctr (struct dm_target *ti,unsigned int argc,char **argv) {int r; -bool resize; +bool resize = false;struct raid_type *rt;unsigned int num_raid_params, num_raid_devs; -sector_t calculated_dev_sectors, rdev_sectors; +sector_t calculated_dev_sectors, rdev_sectors, reshape_sectors;struct raid_set *rs =NULL ;const char *arg;struct rs_layout rs_layout;
@@ -3055,7 +3055,10 @@ static int raid_ctr(struct dm_target *ti, unsigned int argc, char **argv) goto bad; } - resize = calculated_dev_sectors != rdev_sectors; + + reshape_sectors =_get_reshape_sectors (rs); +if (calculated_dev_sectors != rdev_sectors) + resize = calculated_dev_sectors != (reshape_sectors ? rdev_sectors - reshape_sectors : rdev_sectors);INIT_WORK (&rs->md.event_work, do_table_event); ti->private = rs;
@@ -3178,7 +3181,6 @@ static int raid_ctr(struct dm_target *ti, unsigned int argc, char **argv)mddev_lock_nointr (&rs->md); r =md_run (&rs->md); rs->md.in_sync =0 ;/* Assume already marked dirty */ -if (r) { ti->error ="Failed to run raid array" ;mddev_unlock (&rs->md);
Signature · 1 line
2.13.6
PATCH v2 4/12 dm raid: correct raid set size revalidation
In reply to Heinz MauelshagenThe raid set size is being revalidated unconditionally before a reshaping conversion is started. MD requires the size to only be reduced in case of a stripe removing (i.e. shrinking) reshape but not when growing because the raid array has to stay small until after the growing reshape finished.
Fix by avoiding the size revalidation in preresume unless a shrinking reshape is requested.
--- drivers/md/dm-raid.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-)
drivers/md/dm-raid.c +20 -10
@@ -675,15 +675,11 @@ static struct raid_type *get_raid_type_by_ll(const int level, const int layout)return NULL ; } -/* -* Conditionally change bdev capacity of @rs -* in case of a disk add/remove reshape -*/ -static void rs_set_capacity (struct raid_set *rs) +/* Adjust rdev sectors */ +static void rs_set_rdev_sectors (struct raid_set *rs) {struct mddev *mddev = &rs->md;struct md_rdev *rdev; -struct gendisk *gendisk =dm_disk (dm_table_get_md (rs->ti->table));/* * raid10 sets rdev->sector to the device size, which
@@ -692,8 +688,16 @@ static void rs_set_capacity(struct raid_set *rs)rdev_for_each (rdev, mddev)if (!test_bit (Journal, &rdev->flags)) rdev->sectors = mddev->dev_sectors; +} -set_capacity (gendisk, mddev->array_sectors); +/* +* Change bdev capacity of @rs in case of a disk add/remove reshape +*/ +static void rs_set_capacity (struct raid_set *rs) +{ +struct gendisk *gendisk =dm_disk (dm_table_get_md (rs->ti->table)); + +set_capacity (gendisk, rs->md.array_sectors);revalidate_disk (gendisk); }
@@ -1674,8 +1678,11 @@ static void do_table_event(struct work_struct *ws) struct raid_set *rs = container_of(ws, struct raid_set, md.event_work);smp_rmb ();/* Make sure we access most actual mddev properties */ -if (!rs_is_reshaping (rs)) +if (!rs_is_reshaping (rs)) { +if (rs_is_raid10 (rs)) +rs_set_rdev_sectors (rs);rs_set_capacity (rs); + }dm_table_event (rs->ti->table); }
@@ -3877,11 +3884,10 @@ static int raid_preresume(struct dm_target *ti) mddev->resync_min = mddev->recovery_cp; } -rs_set_capacity (rs); -/* Check for any reshape request unless new raid set */ if (test_and_clear_bit (RT_FLAG_RESHAPE_RS , &rs->runtime_flags)) {/* Initiate a reshape. */ +rs_set_rdev_sectors (rs);mddev_lock_nointr (mddev); r =rs_start_reshape (rs);mddev_unlock (mddev);
@@ -3910,6 +3916,10 @@ static void raid_resume(struct dm_target *ti) mddev->ro =0 ; mddev->in_sync =0 ; +/* Only reduce raid set size before running a disk removing reshape. */ +if (mddev->delta_disks <0 ) +rs_set_capacity (rs); +/* * Keep the RAID set frozen if reshape/rebuild flags are set. * The RAID set is unfrozen once the next table load/resume,
Signature · 1 line
2.13.6
PATCH v2 5/12 dm raid: enhance resume() frozen checks
In reply to Heinz MauelshagenIn case userspace reloads multiple times thus reading the superblocks, the raid set needs to stay frozen in case of a reshape request until all config changes (chunk size, layout data_offset, delta_disks) have been stored in the superblocks and respective flags cleared.
--- drivers/md/dm-raid.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/md/dm-raid.c +10 -3
@@ -3885,7 +3885,7 @@ static int raid_preresume(struct dm_target *ti) }/* Check for any reshape request unless new raid set */ -if (test_and_clear_bit (RT_FLAG_RESHAPE_RS , &rs->runtime_flags)) { +if (test_bit (RT_FLAG_RESHAPE_RS , &rs->runtime_flags)) {/* Initiate a reshape. */ rs_set_rdev_sectors (rs);mddev_lock_nointr (mddev);
@@ -3927,8 +3927,15 @@ static void raid_resume(struct dm_target *ti)* This ensures that the constructor for the inactive table * retrieves an up-to-date reshape_position. */ -if (!(rs->ctr_flags &RESUME_STAY_FROZEN_FLAGS )) -clear_bit (MD_RECOVERY_FROZEN , &mddev->recovery); +if (!test_and_clear_bit (RT_FLAG_RESHAPE_RS , &rs->runtime_flags) && + !(rs->ctr_flags &RESUME_STAY_FROZEN_FLAGS )) { +if (rs_is_reshapable (rs)) { +if (!rs_is_reshaping (rs) || +_get_reshape_sectors (rs)) +clear_bit (MD_RECOVERY_FROZEN , &mddev->recovery); + }else +clear_bit (MD_RECOVERY_FROZEN , &mddev->recovery); + }if (test_and_clear_bit (RT_FLAG_RS_SUSPENDED , &rs->runtime_flags)) {mddev_lock_nointr (mddev);
Signature · 1 line
2.13.6
PATCH v2 6/12 dm raid: close MD recovery flags race window
In reply to Heinz MauelshagenThe MD sync thread updates recovery flags providing state of any running,idle,frozen,recovering,reshaping,... activity it performs and updates respective flags asynchronously to dm processing raid_status(). To close that race window, take a copy of the flags and pass it into its callees.
--- drivers/md/dm-raid.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-)
drivers/md/dm-raid.c +19 -16
@@ -3282,25 +3282,26 @@ static int raid_map(struct dm_target *ti, struct bio *bio) }/* 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" ; -if (test_bit (MD_RECOVERY_RUNNING , &mddev->recovery) || - (!mddev->ro &&test_bit (MD_RECOVERY_NEEDED , &mddev->recovery))) { -if (test_bit (MD_RECOVERY_RESHAPE , &mddev->recovery)) +if (!test_bit (MD_RECOVERY_DONE , &recovery) && + (test_bit (MD_RECOVERY_RUNNING , &recovery) || + (!mddev->ro &&test_bit (MD_RECOVERY_NEEDED , &recovery)))) { +if (test_bit (MD_RECOVERY_RESHAPE , &recovery))return "reshape" ; -if (test_bit (MD_RECOVERY_SYNC , &mddev->recovery)) { -if (!test_bit (MD_RECOVERY_REQUESTED , &mddev->recovery)) +if (test_bit (MD_RECOVERY_SYNC , &recovery)) { +if (!test_bit (MD_RECOVERY_REQUESTED , &recovery))return "resync" ; -else if (test_bit (MD_RECOVERY_CHECK , &mddev->recovery)) +else if (test_bit (MD_RECOVERY_CHECK , &recovery))return "check" ;return "repair" ; } -if (test_bit (MD_RECOVERY_RECOVER , &mddev->recovery)) +if (test_bit (MD_RECOVERY_RECOVER , &recovery))return "recover" ; }
@@ -3332,7 +3333,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 */ -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 r, curr_resync_completed;
@@ -3349,7 +3350,7 @@ static sector_t rs_get_progress(struct raid_set *rs, r = mddev->reshape_position;/* Reshape is relative to the array size */ -if (test_bit (MD_RECOVERY_RESHAPE , &mddev->recovery) || +if (test_bit (MD_RECOVERY_RESHAPE , &recovery) || r != MaxSector) {if (r == MaxSector) { *array_in_sync = true;
@@ -3364,20 +3365,20 @@ static sector_t rs_get_progress(struct raid_set *rs, }/* 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;else r = mddev->recovery_cp;if ((r == MaxSector) || - (test_bit (MD_RECOVERY_DONE , &mddev->recovery) && + (test_bit (MD_RECOVERY_DONE , &recovery) && (mddev->curr_resync_completed == resync_max_sectors))) {/* * Sync complete. */ *array_in_sync = true; 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 * undergone an initial sync and the health characters
@@ -3420,6 +3421,7 @@ static void raid_status(struct dm_target *ti, status_type_t type,struct r5conf *conf = mddev->private;int i, max_nr_stripes = conf ? conf->max_nr_stripes :0 ;bool array_in_sync; +unsigned long recovery;unsigned int raid_param_cnt =1 ;/* at least 1 for chunksize */ unsigned int sz =0 ;unsigned int rebuild_disks;
@@ -3439,13 +3441,14 @@ static void raid_status(struct dm_target *ti, status_type_t type,/* Access most recent mddev properties for status output */ smp_rmb (); + recovery = rs->md.recovery;/* Get sensible max sectors even if raid set not yet started */ resync_max_sectors =test_bit (RT_FLAG_RS_PRERESUMED , &rs->runtime_flags) ? 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" )) ?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 */ for (i =0 ; i < rs->raid_disks; i++)
Signature · 1 line
2.13.6
PATCH v2 7/12 dm raid: avoid array_in_sync variable
In reply to Heinz MauelshagenThe raid_status() function passes the bool array_in_sync variable around providing synchronization state of the MD array. Replace it by a runtime flag preparing for a following patch which needs to pass another state between raid_status() and its callees thus avoiding function argument bloat.
--- drivers/md/dm-raid.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-)
drivers/md/dm-raid.c +16 -14
@@ -209,6 +209,7 @@ struct raid_dev {#define RT_FLAG_UPDATE_SBS 3#define RT_FLAG_RESHAPE_RS 4#define RT_FLAG_RS_SUSPENDED 5 +#define RT_FLAG_RS_IN_SYNC 6/* Array elements of 64 bit needed for rebuild/failed disk bits */ #define DISKS_ARRAY_ELEMS ((MAX_RAID_DEVICES + (sizeof(uint64_t) * 8 - 1)) / sizeof(uint64_t) / 8)
@@ -3318,7 +3319,7 @@ static const char *decipher_sync_action(struct mddev *mddev, unsigned long recov* 'A' = Alive and in-sync raid set component _or_ alive raid4/5/6 'write_through' journal device * '-' = Non-existing device (i.e. uspace passed '- -' into the ctr) */ -static const char *__raid_dev_status (struct raid_set *rs,struct md_rdev *rdev,bool array_in_sync) +static const char *__raid_dev_status (struct raid_set *rs,struct md_rdev *rdev) {if (!rdev->bdev)return "-" ;
@@ -3326,25 +3327,27 @@ static const char *__raid_dev_status(struct raid_set *rs, struct md_rdev *rdev,return "D" ; else if (test_bit(Journal, &rdev->flags)) return (rs->journal_dev.mode == R5C_JOURNAL_MODE_WRITE_THROUGH) ? "A" : "a"; - else if (!array_in_sync || !test_bit(In_sync, &rdev->flags)) + else if (!test_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags) && + !test_bit(In_sync, &rdev->flags))return "a" ; else return "A"; } -/* Helper to return resync/reshape progress for @rs and @array_in_sync */ +/* Helper to return resync/reshape progress for @rs and runtime flags for raid set in sync / resynching */ 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) {sector_t r, curr_resync_completed;struct mddev *mddev = &rs->md; +clear_bit (RT_FLAG_RS_IN_SYNC , &rs->runtime_flags); + curr_resync_completed = mddev->curr_resync_completed ?: mddev->recovery_cp; - *array_in_sync = false;if (rs_is_raid0 (rs)) { r = resync_max_sectors; - *array_in_sync = true; +set_bit (RT_FLAG_RS_IN_SYNC , &rs->runtime_flags); }else { r = mddev->reshape_position;
@@ -3353,7 +3356,7 @@ static sector_t rs_get_progress(struct raid_set *rs, unsigned long recovery,if (test_bit (MD_RECOVERY_RESHAPE , &recovery) || r != MaxSector) {if (r == MaxSector) { - *array_in_sync = true; +set_bit (RT_FLAG_RS_IN_SYNC , &rs->runtime_flags); r = resync_max_sectors; }else {/* Got to reverse on backward reshape */
@@ -3376,7 +3379,7 @@ static sector_t rs_get_progress(struct raid_set *rs, unsigned long recovery,/* * Sync complete. */ - *array_in_sync = true; +set_bit (RT_FLAG_RS_IN_SYNC , &rs->runtime_flags); r = resync_max_sectors; }else if (test_bit (MD_RECOVERY_REQUESTED , &recovery)) {/*
@@ -3384,7 +3387,7 @@ static sector_t rs_get_progress(struct raid_set *rs, unsigned long recovery,* undergone an initial sync and the health characters * should not be 'a' anymore. */ - *array_in_sync = true; +set_bit (RT_FLAG_RS_IN_SYNC , &rs->runtime_flags); }else {struct md_rdev *rdev;
@@ -3397,7 +3400,7 @@ static sector_t rs_get_progress(struct raid_set *rs, unsigned long recovery,rdev_for_each (rdev, mddev)if (!test_bit (Journal, &rdev->flags) && !test_bit (In_sync, &rdev->flags)) - *array_in_sync = true; +set_bit (RT_FLAG_RS_IN_SYNC , &rs->runtime_flags);#if 0 r =0 ;/* HM FIXME: TESTME: https://bugzilla.redhat.com/show_bug.cgi?id=1210637 ? */ #endif
@@ -3420,7 +3423,6 @@ static void raid_status(struct dm_target *ti, status_type_t type,struct mddev *mddev = &rs->md;struct r5conf *conf = mddev->private;int i, max_nr_stripes = conf ? conf->max_nr_stripes :0 ; -bool array_in_sync;unsigned long recovery;unsigned int raid_param_cnt =1 ;/* at least 1 for chunksize */ unsigned int sz =0 ;
@@ -3445,14 +3447,14 @@ static void raid_status(struct dm_target *ti, status_type_t type,/* Get sensible max sectors even if raid set not yet started */ resync_max_sectors =test_bit (RT_FLAG_RS_PRERESUMED , &rs->runtime_flags) ? mddev->resync_max_sectors : mddev->dev_sectors; - progress =rs_get_progress (rs, recovery, resync_max_sectors, &array_in_sync); + progress =rs_get_progress (rs, recovery, resync_max_sectors); resync_mismatches = (mddev->last_sync_action && !strcasecmp (mddev->last_sync_action,"check" )) ?atomic64_read (&mddev->resync_mismatches) :0 ; sync_action =decipher_sync_action (&rs->md, recovery);/* HM FIXME: do we want another state char for raid0? It shows 'D'/'A'/'-' now */ for (i =0 ; i < rs->raid_disks; i++) -DMEMIT (__raid_dev_status (rs, &rs->dev[i].rdev, array_in_sync)); +DMEMIT (__raid_dev_status (rs, &rs->dev[i].rdev));/* * In-sync/Reshape ratio:
@@ -3503,7 +3505,7 @@ static void raid_status(struct dm_target *ti, status_type_t type,* v1.10.0+: */ DMEMIT (" %s" ,test_bit (__CTR_FLAG_JOURNAL_DEV, &rs->ctr_flags) ? -__raid_dev_status (rs, &rs->journal_dev.rdev,0 ) :"-" ); +__raid_dev_status (rs, &rs->journal_dev.rdev) :"-" );break ;case STATUSTYPE_TABLE :
Signature · 1 line
2.13.6
PATCH v2 8/12 dm raid: fix rs_get_progress() synchronization state/ratio
In reply to Heinz MauelshagenFix various sync state issues causing racy/bogus sync ratio, sync_action ad health chars in dm_status() info output.
Sync ratio could be N/N (i.e. 100%) shortly after raid set creation, i.e. creating a new RaidLV or upconverting a linear LV to raid1 thus
"0 2097152 raid raid1 2 Aa 2097162/2097152 recover 0 0 -" instead of
"0 2097152 raid raid1 2 Aa 0/2097152 idle 0 0 -"
Sync action could be non-idle, when the MD thread was done with io.
Health chars could be 'A' when they should be 'a' for a short time before a resynchonization started.
This is the followup patch adding a runtime flag to pass array 'resync' state around.
--- drivers/md/dm-raid.c | 90 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 61 insertions(+), 29 deletions(-)
drivers/md/dm-raid.c +61 -29
@@ -210,6 +210,7 @@ struct raid_dev {#define RT_FLAG_RESHAPE_RS 4#define RT_FLAG_RS_SUSPENDED 5#define RT_FLAG_RS_IN_SYNC 6 +#define RT_FLAG_RS_RESYNCING 7/* Array elements of 64 bit needed for rebuild/failed disk bits */ #define DISKS_ARRAY_ELEMS ((MAX_RAID_DEVICES + (sizeof(uint64_t) * 8 - 1)) / sizeof(uint64_t) / 8)
@@ -3288,6 +3289,7 @@ static const char *decipher_sync_action(struct mddev *mddev, unsigned long recovif (test_bit (MD_RECOVERY_FROZEN , &recovery))return "frozen" ; +/* The MD sync thread can be done with io but still be running */ if (!test_bit (MD_RECOVERY_DONE , &recovery) && (test_bit (MD_RECOVERY_RUNNING , &recovery) || (!mddev->ro &&test_bit (MD_RECOVERY_NEEDED , &recovery)))) {
@@ -3327,8 +3329,9 @@ static const char *__raid_dev_status(struct raid_set *rs, struct md_rdev *rdev)return "D" ; else if (test_bit(Journal, &rdev->flags)) return (rs->journal_dev.mode == R5C_JOURNAL_MODE_WRITE_THROUGH) ? "A" : "a"; - else if (!test_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags) && - !test_bit(In_sync, &rdev->flags)) + else if (test_bit(RT_FLAG_RS_RESYNCING, &rs->runtime_flags) || + (!test_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags) && + !test_bit(In_sync, &rdev->flags))) return "a"; else return "A";
@@ -3338,49 +3341,70 @@ static const char *__raid_dev_status(struct raid_set *rs, struct md_rdev *rdev)static sector_t rs_get_progress (struct raid_set *rs,unsigned long recovery,sector_t resync_max_sectors) { -sector_t r, curr_resync_completed; +sector_t r;struct mddev *mddev = &rs->md;clear_bit (RT_FLAG_RS_IN_SYNC , &rs->runtime_flags); - - curr_resync_completed = mddev->curr_resync_completed ?: mddev->recovery_cp; +clear_bit (RT_FLAG_RS_RESYNCING , &rs->runtime_flags);if (rs_is_raid0 (rs)) { r = resync_max_sectors;set_bit (RT_FLAG_RS_IN_SYNC , &rs->runtime_flags); }else { - r = mddev->reshape_position; -/* Reshape is relative to the array size */ -if (test_bit (MD_RECOVERY_RESHAPE , &recovery) || - r != MaxSector) { -if (r == MaxSector) { -set_bit (RT_FLAG_RS_IN_SYNC , &rs->runtime_flags); - r = resync_max_sectors; - }else { +if (test_bit (MD_RECOVERY_RESHAPE , &recovery)) { + r = mddev->reshape_position; +if (r != MaxSector) {/* Got to reverse on backward reshape */ if (mddev->reshape_backwards) r = mddev->array_sectors - r; -/* Devide by # of data stripes */ -sector_div (r,mddev_data_stripes (rs)); +/* Divide by # of data stripes unless raid1 */ +if (!rs_is_raid1 (rs)) +sector_div (r,mddev_data_stripes (rs)); } -/* Sync is relative to the component device size */ - }else if (test_bit (MD_RECOVERY_RUNNING , &recovery)) - r = curr_resync_completed; +/* +* Sync/recover is relative to the component device size. +* +* MD_RECOVERY_NEEDED for https://bugzilla.redhat.com/show_bug.cgi?id=1508070 +*/ + }else if (test_bit (MD_RECOVERY_NEEDED , &recovery) || +test_bit (MD_RECOVERY_RUNNING , &recovery)) + r = mddev->curr_resync_completed; +else r = mddev->recovery_cp; -if ((r == MaxSector) || - (test_bit (MD_RECOVERY_DONE , &recovery) && - (mddev->curr_resync_completed == resync_max_sectors))) { +if (r >= resync_max_sectors && + (!test_bit (MD_RECOVERY_REQUESTED , &recovery) || + (!test_bit (MD_RECOVERY_FROZEN , &recovery) && + !test_bit (MD_RECOVERY_NEEDED , &recovery) && + !test_bit (MD_RECOVERY_RUNNING , &recovery)))) {/* * Sync complete. */ -set_bit (RT_FLAG_RS_IN_SYNC , &rs->runtime_flags); - r = resync_max_sectors; +/* In case we have finished recovering, the array is in sync. */ +if (test_bit (MD_RECOVERY_RECOVER , &recovery)) +set_bit (RT_FLAG_RS_IN_SYNC , &rs->runtime_flags); + + }else if (test_bit (MD_RECOVERY_RECOVER , &recovery)) { +/* +* In case we are recovering, the array is not in sync +* and health chars should show the recovering legs. +*/ + ; + + }else if (test_bit (MD_RECOVERY_SYNC , &recovery) && + !test_bit (MD_RECOVERY_REQUESTED , &recovery)) { +/* +* If "resync" is occurring, the raid set +* is or may be out of sync hence the health +* characters shall be 'a'. +*/ +set_bit (RT_FLAG_RS_RESYNCING , &rs->runtime_flags); + }else if (test_bit (MD_RECOVERY_REQUESTED , &recovery)) {/* * If "check" or "repair" is occurring, the raid set has
@@ -3388,26 +3412,34 @@ static sector_t rs_get_progress(struct raid_set *rs, unsigned long recovery,* should not be 'a' anymore. */ set_bit (RT_FLAG_RS_IN_SYNC , &rs->runtime_flags); + }else {struct md_rdev *rdev;/* +* We are idle and recovery is needed, prevent 'A' chars race +* caused by components still set to in-sync by constrcuctor. +*/ +if (test_bit (MD_RECOVERY_NEEDED , &recovery)) +set_bit (RT_FLAG_RS_RESYNCING , &rs->runtime_flags); + +/* * The raid set may be doing an initial sync, or it may * be rebuilding individual components. If all the * devices are In_sync, then it is the raid set that is * being initialized. */ +set_bit (RT_FLAG_RS_IN_SYNC , &rs->runtime_flags);rdev_for_each (rdev, mddev)if (!test_bit (Journal, &rdev->flags) && - !test_bit (In_sync, &rdev->flags)) -set_bit (RT_FLAG_RS_IN_SYNC , &rs->runtime_flags); -#if 0 - r =0 ;/* HM FIXME: TESTME: https://bugzilla.redhat.com/show_bug.cgi?id=1210637 ? */ -#endif + !test_bit (In_sync, &rdev->flags)) { +clear_bit (RT_FLAG_RS_IN_SYNC , &rs->runtime_flags); +break ; + } } } -return r; +return min (r, resync_max_sectors); }/* Helper to return @dev name or "-" if !@dev */
Signature · 1 line
2.13.6
PATCH v2 9/12 dm raid: group rw and in_sync definitions with mddev_resume()
In reply to Heinz Mauelshagen--- drivers/md/dm-raid.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/md/dm-raid.c +2 -3
@@ -3950,9 +3950,6 @@ static void raid_resume(struct dm_target *ti)attempt_restore_of_faulty_devices (rs); } - mddev->ro =0 ; - mddev->in_sync =0 ; -/* Only reduce raid set size before running a disk removing reshape. */ if (mddev->delta_disks <0 )rs_set_capacity (rs);
@@ -3976,6 +3973,8 @@ static void raid_resume(struct dm_target *ti)if (test_and_clear_bit (RT_FLAG_RS_SUSPENDED , &rs->runtime_flags)) {mddev_lock_nointr (mddev); + mddev->ro =0 ; + mddev->in_sync =0 ;mddev_resume (mddev);mddev_unlock (mddev); }
Signature · 1 line
2.13.6
PATCH v2 10/12 dm raid: remove unused "struct raid_set" member
In reply to Heinz Mauelshagen--- drivers/md/dm-raid.c | 1 - 1 file changed, 1 deletion(-)
drivers/md/dm-raid.c +0 -1
@@ -227,7 +227,6 @@ struct rs_layout {struct raid_set {struct dm_target *ti; -uint32_t bitmap_loaded;uint32_t stripe_cache_entries;unsigned long ctr_flags;unsigned long runtime_flags;
Signature · 1 line
2.13.6
PATCH v2 11/12 dm raid: comments
In reply to Heinz Mauelshagen--- drivers/md/dm-raid.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/md/dm-raid.c +3 -3
@@ -2837,13 +2837,13 @@ static int rs_setup_reshape(struct raid_set *rs)/* * Adjust array size: * -* - in case of adding disks, array size has +* - in case of adding disk(s), array size has * to grow after the disk adding reshape, * which'll hapen in the event handler; * reshape will happen forward, so space has to * be available at the beginning of each disk * -* - in case of removing disks, array size +* - in case of removing disk(s), array size * has to shrink before starting the reshape, * which'll happen here; * reshape will happen backward, so space has to
@@ -2874,7 +2874,7 @@ static int rs_setup_reshape(struct raid_set *rs) rdev->recovery_offset =rs_is_raid1 (rs) ?0 : MaxSector; } - mddev->reshape_backwards =0 ;/* adding disks -> forward reshape */ + mddev->reshape_backwards =0 ;/* adding disk(s) -> forward reshape */ /* Remove disk(s) */ }else if (rs->delta_disks <0 ) {
Signature · 1 line
2.13.6
PATCH v2 12/12 dm raid: add component device size check
In reply to Heinz MauelshagenCheck all component data device sizes versus calculated size. Reject in case device(s) are too small.
--- drivers/md/dm-raid.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/md/dm-raid.c +19 -1
@@ -1581,6 +1581,24 @@ static sector_t __rdev_sectors(struct raid_set *rs)return 0 ; } +/* Check that calculated dev_sectors fits all component devices. */ +static int _check_data_dev_sectors (struct raid_set *rs) +{ +sector_t ds = ~0 ; +struct md_rdev *rdev; + +rdev_for_each (rdev, &rs->md) +if (!test_bit (Journal, &rdev->flags) && rdev->bdev) { + ds =min (ds,to_sector (i_size_read (rdev->bdev->bd_inode))); +if (ds < rs->md.dev_sectors) { + rs->ti->error ="Component device(s) too small" ; +return -EINVAL ; + } + } + +return 0 ; +} +/* Calculate the sectors per device and per array used for @rs */ static int rs_set_dev_and_array_sectors (struct raid_set *rs,bool use_mddev) {
@@ -1630,7 +1648,7 @@ static int rs_set_dev_and_array_sectors(struct raid_set *rs, bool use_mddev) mddev->array_sectors = array_sectors; mddev->dev_sectors = dev_sectors; -return 0 ; +return _check_data_dev_sectors (rs); bad: rs->ti->error ="Target length not divisible by number of data devices" ;return -EINVAL ;
Signature · 1 line
2.13.6