md/raid6: use valid sector values to determine if an I/O should wait on the reshape
PATCH 1/1 md/raid6: use valid sector values to determine if an I/O should wait on the reshape
During a reshape or a RAID6 array such as expanding by adding an additional disk, I/Os to the region of the array which have not yet been reshaped can stall indefinitely. This is from errors in the stripe_ahead_of_reshape function causing md to think the I/O is to a region in the actively undergoing the reshape.
stripe_ahead_of_reshape fails to account for the q disk having a sector value of 0. By not excluding the q disk from the for loop, raid6 will always generate a min_sector value of 0, causing a return value which stalls.
The function's max_sector calculation also uses min() when it should use max(), causing the max_sector value to always be 0. During a backwards rebuild this can cause the opposite problem where it allows I/O to advance when it should wait.
Fixing these errors will allow safe I/O to advance in a timely manner and delay only I/O which is unsafe due to stripes in the middle of undergoing the reshape.
--- drivers/md/raid5.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/raid5.c +2 -2
@@ -5892,11 +5892,11 @@ static bool stripe_ahead_of_reshape(struct mddev *mddev, struct r5conf *conf,int dd_idx;for (dd_idx =0 ; dd_idx < sh->disks; dd_idx++) { -if (dd_idx == sh->pd_idx) +if (dd_idx == sh->pd_idx || dd_idx == sh->qd_idx)continue ; min_sector =min (min_sector, sh->dev[dd_idx].sector); - max_sector =min (max_sector, sh->dev[dd_idx].sector); + max_sector =max (max_sector, sh->dev[dd_idx].sector); }spin_lock_irq (&conf->device_lock);
Signature · 1 line
2.43.0
Song Liu
maintainerHi David and Laurence,
Quoted 16 lines · David Jeffery
During a reshape or a RAID6 array such as expanding by adding an additional disk, I/Os to the region of the array which have not yet been reshaped can stall indefinitely. This is from errors in the
stripe_ahead_of_reshapefunction causing md to think the I/O is to a region in the actively undergoing the reshape.
stripe_ahead_of_reshapefails to account for the q disk having a sector value of 0. By not excluding the q disk from the for loop, raid6 will always generate amin_sectorvalue of 0, causing a return value which stalls.The function's
max_sectorcalculation also usesmin()when it should usemax(), causing themax_sectorvalue to always be 0. During a backwards rebuild this can cause the opposite problem where it allows I/O to advance when it should wait.
Quoted 7 lines
Fixing these errors will allow safe I/O to advance in a timely manner and delay only I/O which is unsafe due to stripes in the middle of undergoing the reshape.
Fixes 486f60558607 ("md/raid5: Check all disks in a stripe_head for reshape progress")Signed-off-by David Jeffery <[email protected]>Tested-by Laurence Oberman <[email protected]>
Thanks for the fix!
Can we add a test to mdadm/tests to cover this case? (Not sure how reliable the test will be).
Song
Quoted 26 lines
--- drivers/md/raid5.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/md/raid5.c +2
-3@@ -5892,11 +5892,11 @@ static bool stripe_ahead_of_reshape(struct mddev *mddev, struct r5conf *conf,int dd_idx;for (dd_idx =0 ; dd_idx < sh->disks; dd_idx++) { -if (dd_idx == sh->pd_idx) +if (dd_idx == sh->pd_idx || dd_idx == sh->qd_idx)continue ; min_sector =min (min_sector, sh->dev[dd_idx].sector); - max_sector =min (max_sector, sh->dev[dd_idx].sector); + max_sector =max (max_sector, sh->dev[dd_idx].sector); }spin_lock_irq (&conf->device_lock); --2.43.0
Quoted 49 lines · David Jeffery
During a reshape or a RAID6 array such as expanding by adding an additional
disk, I/Os to the region of the array which have not yet been reshaped can
stall indefinitely. This is from errors in thestripe_ahead_of_reshape
function causing md to think the I/O is to a region in the actively undergoing the reshape.
stripe_ahead_of_reshapefails to account for the q disk having a sector
value of 0. By not excluding the q disk from the for loop, raid6 will always
generate amin_sectorvalue of 0, causing a return value which stalls.The function's
max_sectorcalculation also usesmin()when it should usemax(), causing themax_sectorvalue to always be 0. During a backwards
rebuild this can cause the opposite problem where it allows I/O to advance
when it should wait.Fixing these errors will allow safe I/O to advance in a timely manner and
delay only I/O which is unsafe due to stripes in the middle of undergoing
the reshape.Fixes 486f60558607 ("md/raid5: Check all disks in a stripe_head forreshape progress")
Signed-off-by David Jeffery <[email protected]>Tested-by Laurence Oberman <[email protected]>---
drivers/md/raid5.c | 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)drivers/md/raid5.c +0
-0@@ -5892,11 +5892,11 @@ static bool stripe_ahead_of_reshape(struct mddev *mddev, struct r5conf *conf, int dd_idx;
for (dd_idx= 0;dd_idx<sh->disks; dd_idx++) { - if (dd_idx==sh->pd_idx)
+ if (dd_idx==sh->pd_idx||dd_idx==sh->qd_idx)
Quoted 8 lines
continue;
min_sector =min(min_sector, sh->dev[dd_idx].sector); - max_sector =min(max_sector, sh->dev[dd_idx].sector); + max_sector =max(max_sector, sh->dev[dd_idx].sector); }
spin_lock_irq(&conf->device_lock);
Nice work David as usual, this issue has lurked for a while it seems. Thanks for all you do for Red Hat and upstream.
Regards
Laurence
Quoted 40 lines · Song Liu
Hi David and Laurence,
Quoted 31 lines · David Jeffery
During a reshape or a RAID6 array such as expanding by adding an additional
disk, I/Os to the region of the array which have not yet been reshaped can
stall indefinitely. This is from errors in thestripe_ahead_of_reshape
function causing md to think the I/O is to a region in the actively undergoing the reshape.
stripe_ahead_of_reshapefails to account for the q disk having a sector
value of 0. By not excluding the q disk from the for loop, raid6 will always
generate amin_sectorvalue of 0, causing a return value which stalls.The function's
max_sectorcalculation also usesmin()when it should usemax(), causing themax_sectorvalue to always be 0. During a backwards
rebuild this can cause the opposite problem where it allows I/O to advance
when it should wait.Fixing these errors will allow safe I/O to advance in a timely manner and
delay only I/O which is unsafe due to stripes in the middle of undergoing
the reshape.Quoted 4 lines
Fixes 486f60558607 ("md/raid5: Check all disks in a stripe_headfor reshape progress")
Signed-off-by David Jeffery <[email protected]>Tested-by Laurence Oberman <[email protected]>
Quoted 39 lines
Thanks for the fix!
Can we add a test to mdadm/tests to cover this case? (Not sure how reliable
the test will be).Song
Quoted 30 lines
---
drivers/md/raid5.c | 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)drivers/md/raid5.c +1
-1@@ -5892,11 +5892,11 @@ static bool stripe_ahead_of_reshape(struct mddev *mddev, struct r5conf *conf, int dd_idx; for (dd_idx = 0; dd_idx < sh->disks; dd_idx++) { - if (dd_idx == sh->pd_idx) + if (dd_idx == sh->pd_idx || dd_idx == sh->qd_idx) continue;
min_sector= min(min_sector, sh-Quoted 1 line
dev[dd_idx].sector);
-
max_sector= min(max_sector, sh-Quoted 1 line
dev[dd_idx].sector);
+
max_sector= max(max_sector, sh-Quoted 1 line
dev[dd_idx].sector);
}
spin_lock_irq(&conf->device_lock);
--
2.43.0
Hello Song
The way this was discovered is the customer forced a reshape of a raid6 device by adding an additional device.
The reshape then sess the hang.
# mdadm /dev/md0 -a /dev/nvme18n1 mdadm: added /dev/nvme18n1
# mdadm --grow --raid-devices=6 /dev/md0
The problem was we needed a test kernel just for the customer to recover, because on reboot the reshape starts again and hangs the device access.
Such steps could be added for a test but David will know maybe an easier way for a test.
Regards
Laurence