Skip to contentSkip to conversation

md raid: fix hang when stopping arrays with metadata through dm-raid

PATCH Superseded Heinz Mauelshagen 5 participants 9 messages Sep 18, 2025 – Jan 26 3 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 md raid: fix hang when stopping arrays with metadata through dm-raid

When using device-mapper's dm-raid target, stopping a RAID array can cause the system to hang under specific conditions.

This occurs when:

- A dm-raid managed device tree is suspended from top to bottom (the top-level RAID device is suspended first, followed by its underlying metadata and data devices)

- The top-level RAID device is then removed

The hang happens because removing the top-level device triggers md_stop() from the dm-raid destructor. This function attempts to flush the write-intent bitmap, which requires writing bitmap superblocks to the metadata sub-devices. However, since these metadata devices are already suspended, the write operations cannot complete, causing the system to hang.

Fix:

- Prevent bitmap flushing when md_stop() is called from dm-raid contexts and avoid a quiescing/unquescing cycle which could also cause I/O

- Avoid any I/O operations that might occur during the quiesce/unquiesce process in md_stop()

This ensures that RAID array teardown can complete successfully even when the underlying devices are in a suspended state.

---
 drivers/md/md.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/md/md.c +7 -5
index 4e033c26fdd4..53e15bdd9ab2 100644
@@ -6541,12 +6541,14 @@ static void __md_stop_writes(struct mddev *mddev)
 {
 	timer_delete_sync(&mddev->safemode_timer);
 
-	if (mddev->pers && mddev->pers->quiesce) {
-		mddev->pers->quiesce(mddev, 1);
-		mddev->pers->quiesce(mddev, 0);
-	}
+	if (!mddev_is_dm(mddev)) {
+		if (mddev->pers && mddev->pers->quiesce) {
+			mddev->pers->quiesce(mddev, 1);
+			mddev->pers->quiesce(mddev, 0);
+		}
 
-	mddev->bitmap_ops->flush(mddev);
+		mddev->bitmap_ops->flush(mddev);
+	}
 
 	if (md_is_rdwr(mddev) &&
 	    ((!mddev->in_sync && !mddev_is_clustered(mddev)) ||
Signature · 1 line
2.51.0
#2 lore raw

Hi,

Quoted 17 lines · Heinz Mauelshagen

When using device-mapper's dm-raid target, stopping a RAID array can cause the system to hang under specific conditions.

This occurs when:

(quoted diff) +0 -2
-  A dm-raid managed device tree is suspended from top to bottom
    (the top-level RAID device is suspended first, followed by its
     underlying metadata and data devices)
 
-  The top-level RAID device is then removed

The hang happens because removing the top-level device triggers md_stop() from the dm-raid destructor. This function attempts to flush the write-intent bitmap, which requires writing bitmap superblocks to the metadata sub-devices. However, since these metadata devices are already suspended, the write operations cannot complete, causing the system to hang.

Quoted 4 lines

Fix:

- Prevent bitmap flushing when md_stop() is called from dm-raid contexts and avoid a quiescing/unquescing cycle which could also cause I/O

If bitmap flush is skipped, then bitmap can still be dirty after dm-raid is stopped, and the next time when dm-raid is reloaded, looks like there will be unnecessary data resync because there are dirty bits?

Thanks,
Kuai

Quoted 36 lines

- Avoid any I/O operations that might occur during the quiesce/unquiesce process in md_stop()

This ensures that RAID array teardown can complete successfully even when the underlying devices are in a suspended state.

---
  drivers/md/md.c | 12 +++++++-----
  1 file changed, 7 insertions(+), 5 deletions(-)
drivers/md/md.c +7 -5
index 4e033c26fdd4..53e15bdd9ab2 100644
@@ -6541,12 +6541,14 @@ static void __md_stop_writes(struct mddev *mddev)
  {
  	timer_delete_sync(&mddev->safemode_timer);
 
-	if (mddev->pers && mddev->pers->quiesce) {
-		mddev->pers->quiesce(mddev, 1);
-		mddev->pers->quiesce(mddev, 0);
-	}
+	if (!mddev_is_dm(mddev)) {
+		if (mddev->pers && mddev->pers->quiesce) {
+			mddev->pers->quiesce(mddev, 1);
+			mddev->pers->quiesce(mddev, 0);
+		}
 
-	mddev->bitmap_ops->flush(mddev);
+		mddev->bitmap_ops->flush(mddev);
+	}
 
  	if (md_is_rdwr(mddev) &&
  	    ((!mddev->in_sync && !mddev_is_clustered(mddev)) ||

A message that is not in the archive (sent off-list or not yet received): CAM23Vxp0wKNvo2+SvfEny+-BubGxebyErCiKR31G8HyA=9DH6g@mail.gmail.com

#4 lore raw

Hi,

Quoted 7 lines · Heinz Mauelshagen

Hi Kuai,

you're right, it should be flushed in the dm-raid's raid_postsuspend() function by calling md_stop_writes() when upstack I/O is quiesced already. So we can't use mddev_is_dm() in __md_stop_writes() as it prevents flushing the bitmap with the current patch.

Quoted 9 lines

md_is_rdwr() looks is the appropriate condition, i.e. when true flush, when false, don't.

If md_is_rdwr() is ok for that logic, I'll create another patch leaving it true in postsuspend and false in the destructor call to md_stop() from dm-raid.

Thoughts?

Yeah, this sounds correct.

Thanks,
Kuai

Quoted 83 lines

- lvmguy

Quoted 77 lines · Yu Kuai

Hi,

Quoted 1 line · Heinz Mauelshagen

When using device-mapper's dm-raid target, stopping a RAID array can

cause the

Quoted 11 lines

system to hang under specific conditions.

This occurs when:

(quoted diff) +0 -2
-  A dm-raid managed device tree is suspended from top to bottom
     (the top-level RAID device is suspended first, followed by its
      underlying metadata and data devices)
 
-  The top-level RAID device is then removed

The hang happens because removing the top-level device triggers

md_stop() from the

Quoted 1 line

dm-raid destructor. This function attempts to flush the write-intent

bitmap, which

Quoted 1 line

requires writing bitmap superblocks to the metadata sub-devices.

However, since

Quoted 1 line

these metadata devices are already suspended, the write operations

cannot complete,

Quoted 6 lines

causing the system to hang.

Fix:

- Prevent bitmap flushing when md_stop() is called from dm-raid contexts and avoid a quiescing/unquescing cycle which could also cause I/O

If bitmap flush is skipped, then bitmap can still be dirty after dm-raid is stopped, and the next time when dm-raid is reloaded, looks like there will be unnecessary data resync because there are dirty bits?

Thanks,
Kuai

Quoted 2 lines

- Avoid any I/O operations that might occur during the

quiesce/unquiesce process in md_stop()

Quoted 2 lines

This ensures that RAID array teardown can complete successfully even

when the

Quoted 32 lines

underlying devices are in a suspended state.

---
   drivers/md/md.c | 12 +++++++-----
   1 file changed, 7 insertions(+), 5 deletions(-)
drivers/md/md.c +7 -5
index 4e033c26fdd4..53e15bdd9ab2 100644
@@ -6541,12 +6541,14 @@ static void __md_stop_writes(struct mddev *mddev)
   {
       timer_delete_sync(&mddev->safemode_timer);
 
-     if (mddev->pers && mddev->pers->quiesce) {
-             mddev->pers->quiesce(mddev, 1);
-             mddev->pers->quiesce(mddev, 0);
-     }
+     if (!mddev_is_dm(mddev)) {
+             if (mddev->pers && mddev->pers->quiesce) {
+                     mddev->pers->quiesce(mddev, 1);
+                     mddev->pers->quiesce(mddev, 0);
+             }
 
-     mddev->bitmap_ops->flush(mddev);
+             mddev->bitmap_ops->flush(mddev);
+     }
 
       if (md_is_rdwr(mddev) &&
           ((!mddev->in_sync && !mddev_is_clustered(mddev)) ||
#5 lore raw

PATCH v2 1/1 md raid: fix hang when stopping arrays with metadata through dm-raid

When using device-mapper's dm-raid target, stopping a RAID array can cause the system to hang under specific conditions.

This occurs when:

- A dm-raid managed device tree is suspended from top to bottom (the top-level RAID device is suspended first, followed by its underlying metadata and data devices)

- The top-level RAID device is then removed

Removing the top-level device triggers a hang in the following sequence: the dm-raid destructor calls md_stop(), which tries to flush the write-intent bitmap by writing to the metadata sub-devices. However, these devices are already suspended, making them unable to complete the write operations and causing an indefinite block.

Fix:

- Prevent bitmap flushing when md_stop() is called from dm-raid destructor context and avoid a quiescing/unquescing cycle which could also cause I/O

- Still allow write-intent bitmap flushing when called from dm-raid suspend context

This ensures that RAID array teardown can complete successfully even when the underlying devices are in a suspended state.

This second patch uses md_is_rdwr() to distinguish between suspend and destructor paths as elaborated on above.

---
 drivers/md/md.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/md/md.c +7 -5
index 4e033c26fdd4..78408d2f78fc 100644
@@ -6541,12 +6541,14 @@ static void __md_stop_writes(struct mddev *mddev)
 {
 	timer_delete_sync(&mddev->safemode_timer);
 
-	if (mddev->pers && mddev->pers->quiesce) {
-		mddev->pers->quiesce(mddev, 1);
-		mddev->pers->quiesce(mddev, 0);
-	}
+	if (md_is_rdwr(mddev) || !mddev_is_dm(mddev)) {
+		if (mddev->pers && mddev->pers->quiesce) {
+			mddev->pers->quiesce(mddev, 1);
+			mddev->pers->quiesce(mddev, 0);
+		}
 
-	mddev->bitmap_ops->flush(mddev);
+		mddev->bitmap_ops->flush(mddev);
+	}
 
 	if (md_is_rdwr(mddev) &&
 	    ((!mddev->in_sync && !mddev_is_clustered(mddev)) ||
Signature · 1 line
2.51.0
#6 lore raw

PATCH v2 1/1 md raid: fix hang when stopping arrays with metadata through dm-raid

Resending, as it seems to have gotten lost.

---------- Forwarded message ---------
From: Heinz Mauelshagen <[email protected]>
Date: Tue, Sep 23, 2025 at 2:58 PM
Subject: [PATCH V2] md raid: fix hang when stopping arrays with metadata through dm-raid
To: <[email protected]>, <[email protected]>
Cc: <[email protected]>, <[email protected]>, Heinz Mauelshagen <[email protected]>

When using device-mapper's dm-raid target, stopping a RAID array can cause the system to hang under specific conditions.

This occurs when:

- A dm-raid managed device tree is suspended from top to bottom (the top-level RAID device is suspended first, followed by its underlying metadata and data devices)

- The top-level RAID device is then removed

Removing the top-level device triggers a hang in the following
sequence: the dm-raid
destructor calls md_stop(), which tries to flush the write-intent bitmap by writing
to the metadata sub-devices. However, these devices are already suspended, making
them unable to complete the write operations and causing an indefinite block.

Fix:

- Prevent bitmap flushing when md_stop() is called from dm-raid destructor context
and avoid a quiescing/unquescing cycle which could also cause I/O

- Still allow write-intent bitmap flushing when called from dm-raid suspend context

This ensures that RAID array teardown can complete successfully even when the underlying devices are in a suspended state.

This second patch uses md_is_rdwr() to distinguish between suspend and destructor paths as elaborated on above.

---
 drivers/md/md.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/md/md.c +7 -5
index 4e033c26fdd4..78408d2f78fc 100644
@@ -6541,12 +6541,14 @@ static void __md_stop_writes(struct mddev *mddev)
 {
        timer_delete_sync(&mddev->safemode_timer);
 
-       if (mddev->pers && mddev->pers->quiesce) {
-               mddev->pers->quiesce(mddev, 1);
-               mddev->pers->quiesce(mddev, 0);
-       }
+       if (md_is_rdwr(mddev) || !mddev_is_dm(mddev)) {
+               if (mddev->pers && mddev->pers->quiesce) {
+                       mddev->pers->quiesce(mddev, 1);
+                       mddev->pers->quiesce(mddev, 0);
+               }
 
-       mddev->bitmap_ops->flush(mddev);
+               mddev->bitmap_ops->flush(mddev);
+       }
 
        if (md_is_rdwr(mddev) &&
            ((!mddev->in_sync && !mddev_is_clustered(mddev)) ||

--
2.51.0

#7 lore raw
Quoted 31 lines · Heinz Mauelshagen

hen using device-mapper's dm-raid target, stopping a RAID array can cause the system to hang under specific conditions.

This occurs when:

- A dm-raid managed device tree is suspended from top to bottom (the top-level RAID device is suspended first, followed by its underlying metadata and data devices)

- The top-level RAID device is then removed

Removing the top-level device triggers a hang in the following
sequence: the dm-raid
destructor calls md_stop(), which tries to flush the write-intent bitmap by writing
to the metadata sub-devices. However, these devices are already suspended, making
them unable to complete the write operations and causing an indefinite block.

Fix:

- Prevent bitmap flushing when md_stop() is called from dm-raid destructor context
and avoid a quiescing/unquescing cycle which could also cause I/O

- Still allow write-intent bitmap flushing when called from dm-raid suspend context

This ensures that RAID array teardown can complete successfully even when the underlying devices are in a suspended state.

Quoted 7 lines

This second patch uses md_is_rdwr() to distinguish between suspend and destructor paths as elaborated on above.

---
  drivers/md/md.c | 12 +++++++-----
  1 file changed, 7 insertions(+), 5 deletions(-)

There are conflicts now, applied with some rebasing:

drivers/md/md.c +8 -6
index 606f616190d7..59cd303548de 100644
@@ -6851,13 +6851,15 @@ static void __md_stop_writes(struct mddev *mddev)
  {
         timer_delete_sync(&mddev->safemode_timer);
 
-       if (mddev->pers && mddev->pers->quiesce) {
-               mddev->pers->quiesce(mddev, 1);
-               mddev->pers->quiesce(mddev, 0);
-       }
+       if (md_is_rdwr(mddev) || !mddev_is_dm(mddev)) {
+               if (mddev->pers && mddev->pers->quiesce) {
+                       mddev->pers->quiesce(mddev, 1);
+                       mddev->pers->quiesce(mddev, 0);
+               }
 
-       if (md_bitmap_enabled(mddev, true))
-               mddev->bitmap_ops->flush(mddev);
+               if (md_bitmap_enabled(mddev, true))
+                       mddev->bitmap_ops->flush(mddev);
+       }
 
         if (md_is_rdwr(mddev) &&
             ((!mddev->in_sync && !mddev_is_clustered(mddev)) ||
Signature · 2 lines
Thansk,
Kuai
#8 lore raw

PATCH 1/1 dm raid: use proper md_ro_state enumerators

In reply to a message not in the archive

The dm-raid code was using hardcoded integer values to represent the read-only/read-write state of RAID arrays instead of the proper enumeration constants defined in the md_ro_state enumerator type.

Changes:

- Replace hardcoded integers with the appropriate md_ro_state enumerator values

- Add the missing MD_RDONLY setting in the post_suspend function

This improves code clarity and maintainability by using the defined enumeration constants rather than magic numbers, ensuring the code properly conforms to the established API interface.

---
 drivers/md/dm-raid.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/md/dm-raid.c +7 -6
index 79ea85d18e24..6cdfd7ca998c 100644
@@ -3247,7 +3247,7 @@ static int raid_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 	rs_reset_inconclusive_reshape(rs);
 
 	/* Start raid set read-only and assumed clean to change in raid_resume() */
-	rs->md.ro = 1;
+	rs->md.ro = MD_RDONLY;
 	rs->md.in_sync = 1;
 
 	/* Has to be held on running the array */
@@ -3385,7 +3385,7 @@ static enum sync_state decipher_sync_action(struct mddev *mddev, unsigned long r
 	/* The MD sync thread can be done with io or be interrupted 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)))) {
+	     (md_is_rdwr(mddev) && test_bit(MD_RECOVERY_NEEDED, &recovery)))) {
 		if (test_bit(MD_RECOVERY_RESHAPE, &recovery))
 			return st_reshape;
 
@@ -3775,11 +3775,11 @@ static int raid_message(struct dm_target *ti, unsigned int argc, char **argv,
 		} else
 			return -EINVAL;
 	}
-	if (mddev->ro == 2) {
+	if (mddev->ro == MD_AUTO_READ) {
 		/* A write to sync_action is enough to justify
 		 * canceling read-auto mode
 		 */
-		mddev->ro = 0;
+		mddev->ro = MD_RDWR;
 		if (!mddev->suspended)
 			md_wakeup_thread(mddev->sync_thread);
 	}
@@ -3858,6 +3858,7 @@ static void raid_postsuspend(struct dm_target *ti)
 		 */
 		md_stop_writes(&rs->md);
 		mddev_suspend(&rs->md, false);
+		rs->md.ro = MD_RDONLY;
 	}
 }
 
@@ -3968,7 +3969,7 @@ static void rs_update_sbs(struct raid_set *rs)
 	int ro = mddev->ro;
 
 	set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags);
-	mddev->ro = 0;
+	mddev->ro = MD_RDWR;
 	md_update_sb(mddev, 1);
 	mddev->ro = ro;
 }
@@ -4125,7 +4126,7 @@ static void raid_resume(struct dm_target *ti)
 		WARN_ON_ONCE(rcu_dereference_protected(mddev->sync_thread,
 						       lockdep_is_held(&mddev->reconfig_mutex)));
 		clear_bit(RT_FLAG_RS_FROZEN, &rs->runtime_flags);
-		mddev->ro = 0;
+		mddev->ro = MD_RDWR;
 		mddev->in_sync = 0;
 		md_unfrozen_sync_thread(mddev);
 		mddev_unlock_and_resume(mddev);
Signature · 1 line
2.51.0
#9 lore raw

Re: [PATCH] dm raid: use proper md_ro_state enumerators

Hi Heinz

Quoted 9 lines · Heinz Mauelshagen

The dm-raid code was using hardcoded integer values to represent the read-only/read-write state of RAID arrays instead of the proper enumeration constants defined in the md_ro_state enumerator type.

Changes:

- Replace hardcoded integers with the appropriate md_ro_state enumerator values

- Add the missing MD_RDONLY setting in the post_suspend function

It should be the most important change in this patch. Mind adding the reproducer in the commit message? And explain why you say missing it?

Best Regards
Xiao

Quoted 75 lines

This improves code clarity and maintainability by using the defined enumeration constants rather than magic numbers, ensuring the code properly conforms to the established API interface.

---
 drivers/md/dm-raid.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/md/dm-raid.c +7 -7
index 79ea85d18e24..6cdfd7ca998c 100644
@@ -3247,7 +3247,7 @@ static int raid_ctr(struct dm_target *ti, unsigned int argc, char **argv)
        rs_reset_inconclusive_reshape(rs);
 
        /* Start raid set read-only and assumed clean to change in raid_resume() */
-       rs->md.ro = 1;
+       rs->md.ro = MD_RDONLY;
        rs->md.in_sync = 1;
 
        /* Has to be held on running the array */
@@ -3385,7 +3385,7 @@ static enum sync_state decipher_sync_action(struct mddev *mddev, unsigned long r
        /* The MD sync thread can be done with io or be interrupted 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)))) {
+            (md_is_rdwr(mddev) && test_bit(MD_RECOVERY_NEEDED, &recovery)))) {
                if (test_bit(MD_RECOVERY_RESHAPE, &recovery))
                        return st_reshape;
 
@@ -3775,11 +3775,11 @@ static int raid_message(struct dm_target *ti, unsigned int argc, char **argv,
                } else
                        return -EINVAL;
        }
-       if (mddev->ro == 2) {
+       if (mddev->ro == MD_AUTO_READ) {
                /* A write to sync_action is enough to justify
                 * canceling read-auto mode
                 */
-               mddev->ro = 0;
+               mddev->ro = MD_RDWR;
                if (!mddev->suspended)
                        md_wakeup_thread(mddev->sync_thread);
        }
@@ -3858,6 +3858,7 @@ static void raid_postsuspend(struct dm_target *ti)
                 */
                md_stop_writes(&rs->md);
                mddev_suspend(&rs->md, false);
+               rs->md.ro = MD_RDONLY;
        }
 }
 
@@ -3968,7 +3969,7 @@ static void rs_update_sbs(struct raid_set *rs)
        int ro = mddev->ro;
 
        set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags);
-       mddev->ro = 0;
+       mddev->ro = MD_RDWR;
        md_update_sb(mddev, 1);
        mddev->ro = ro;
 }
@@ -4125,7 +4126,7 @@ static void raid_resume(struct dm_target *ti)
                WARN_ON_ONCE(rcu_dereference_protected(mddev->sync_thread,
                                                       lockdep_is_held(&mddev->reconfig_mutex)));
                clear_bit(RT_FLAG_RS_FROZEN, &rs->runtime_flags);
-               mddev->ro = 0;
+               mddev->ro = MD_RDWR;
                mddev->in_sync = 0;
                md_unfrozen_sync_thread(mddev);
                mddev_unlock_and_resume(mddev);
--

2.51.0

A message that is not in the archive (sent off-list or not yet received): CAM23VxqDkph_BtVdPqFXNAa85VAjabAJeG4-4qvooTrwHpD4BQ@mail.gmail.com

maintainer
#11 lore raw

Re: [PATCH] dm raid: use proper md_ro_state enumerators

Quoted 8 lines · Heinz Mauelshagen

Xiao,

This aspect of the patch corrects an asymmetry in device-mapper suspend/resume handling where MD_RDWR/MD_RDONLY flag management is unbalanced (resume sets read-write, but post_suspend does't properly set read-only).  Not setting MD_RDONLY would e.g. cause md_submit_bio() to not error any writes when it should.

Although no failures have been attributed to this inconsistency, the fix ensures correct state transitions for completeness. However, we could additionally catch writes to a read-only array in the target's map function.

OK, thanks. I staged the patch and added this explanation to the patch header.

Mikulas

Quoted 99 lines

- lvmguy

On Fri, Sep 19, 2025 at 3:20 AM Xiao Ni <[email protected]> wrote:

      Hi Heinz

      On Thu, Sep 18, 2025 at 9:55 PM Heinz Mauelshagen <[email protected]> wrote:
      >
      > The dm-raid code was using hardcoded integer values to represent the read-only/read-write state
      > of RAID arrays instead of the proper enumeration constants defined in the md_ro_state enumerator type.
      >
      > Changes:
      >
      > - Replace hardcoded integers with the appropriate md_ro_state enumerator values
      >
      > - Add the missing MD_RDONLY setting in the post_suspend function

      It should be the most important change in this patch. Mind adding the
      reproducer in the commit message? And explain why you say missing it?

      Best Regards
      Xiao
      >
      > This improves code clarity and maintainability by using the defined enumeration constants
      > rather than magic numbers, ensuring the code properly conforms to the established API interface.
      >
      > Signed-off-by: Heinz Mauelshagen <[email protected]>
      > ---
      >  drivers/md/dm-raid.c | 13 +++++++------
      >  1 file changed, 7 insertions(+), 6 deletions(-)
      >
      > diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c
      > index 79ea85d18e24..6cdfd7ca998c 100644
      > --- a/drivers/md/dm-raid.c
      > +++ b/drivers/md/dm-raid.c
      > @@ -3247,7 +3247,7 @@ static int raid_ctr(struct dm_target *ti, unsigned int argc, char **argv)
      >         rs_reset_inconclusive_reshape(rs);
      >
      >         /* Start raid set read-only and assumed clean to change in raid_resume() */
      > -       rs->md.ro = 1;
      > +       rs->md.ro = MD_RDONLY;
      >         rs->md.in_sync = 1;
      >
      >         /* Has to be held on running the array */
      > @@ -3385,7 +3385,7 @@ static enum sync_state decipher_sync_action(struct mddev *mddev, unsigned long r
      >         /* The MD sync thread can be done with io or be interrupted 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)))) {
      > +            (md_is_rdwr(mddev) && test_bit(MD_RECOVERY_NEEDED, &recovery)))) {
      >                 if (test_bit(MD_RECOVERY_RESHAPE, &recovery))
      >                         return st_reshape;
      >
      > @@ -3775,11 +3775,11 @@ static int raid_message(struct dm_target *ti, unsigned int argc, char **argv,
      >                 } else
      >                         return -EINVAL;
      >         }
      > -       if (mddev->ro == 2) {
      > +       if (mddev->ro == MD_AUTO_READ) {
      >                 /* A write to sync_action is enough to justify
      >                  * canceling read-auto mode
      >                  */
      > -               mddev->ro = 0;
      > +               mddev->ro = MD_RDWR;
      >                 if (!mddev->suspended)
      >                         md_wakeup_thread(mddev->sync_thread);
      >         }
      > @@ -3858,6 +3858,7 @@ static void raid_postsuspend(struct dm_target *ti)
      >                  */
      >                 md_stop_writes(&rs->md);
      >                 mddev_suspend(&rs->md, false);
      > +               rs->md.ro = MD_RDONLY;
      >         }
      >  }
      >
      > @@ -3968,7 +3969,7 @@ static void rs_update_sbs(struct raid_set *rs)
      >         int ro = mddev->ro;
      >
      >         set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags);
      > -       mddev->ro = 0;
      > +       mddev->ro = MD_RDWR;
      >         md_update_sb(mddev, 1);
      >         mddev->ro = ro;
      >  }
      > @@ -4125,7 +4126,7 @@ static void raid_resume(struct dm_target *ti)
      >                 WARN_ON_ONCE(rcu_dereference_protected(mddev->sync_thread,
      >                                                        lockdep_is_held(&mddev->reconfig_mutex)));
      >                 clear_bit(RT_FLAG_RS_FROZEN, &rs->runtime_flags);
      > -               mddev->ro = 0;
      > +               mddev->ro = MD_RDWR;
      >                 mddev->in_sync = 0;
      >                 md_unfrozen_sync_thread(mddev);
      >                 mddev_unlock_and_resume(mddev);
      > --
      > 2.51.0
      >
      >