On Mon, 24 Sep 2012 15:14:43 -0700 Greg KH <[email protected]> wrote:

> So I've dropped it from there.  If someone wants to backport it properly
> to 3.0-stable, please resend a patch.

Here it is, fixed up for 3.0-stable.

thanks,
NeilBrown


From: NeilBrown <[email protected]>
Date: Wed, 19 Sep 2012 12:54:22 +1000
Subject: [PATCH] md: make sure metadata is updated when spares are activated
 or removed.

commit 6dafab6b1383e912cd252fa809570b484eb6e0dc upstream.

It isn't always necessary to update the metadata when spares are
removed as the presence-or-not of a spare isn't really important to
the integrity of an array.
Also activating a spare doesn't always require updating the metadata
as the update on 'recovery-completed' is usually sufficient.

However the introduction of 'replacement' devices have made these
transitions sometimes more important.  For example the 'Replacement'
flag isn't cleared until the original device is removed, so we need
to ensure a metadata update after that 'spare' is removed.

So set MD_CHANGE_DEVS whenever a spare is activated or removed, to
complement the current situation where it is set when a spare is added
or a device is failed (or a number of other less common situations).

This is suitable for -stable as out-of-data metadata could lead
to data corruption.
This is only relevant for 3.3 and later 9when 'replacement' as
introduced.

Cc: [email protected]
Signed-off-by: NeilBrown <[email protected]>

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 8b04a02..8aababe 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -7093,6 +7093,7 @@ static int remove_and_add_spares(mddev_t *mddev)
 {
        mdk_rdev_t *rdev;
        int spares = 0;
+       int removed = 0;
 
        mddev->curr_resync_completed = 0;
 
@@ -7108,6 +7109,7 @@ static int remove_and_add_spares(mddev_t *mddev)
                                sprintf(nm,"rd%d", rdev->raid_disk);
                                sysfs_remove_link(&mddev->kobj, nm);
                                rdev->raid_disk = -1;
+                               removed = 1;
                        }
                }
 
@@ -7136,6 +7138,8 @@ static int remove_and_add_spares(mddev_t *mddev)
                        }
                }
        }
+       if (removed)
+               set_bit(MD_CHANGE_DEVS, &mddev->flags);
        return spares;
 }
 
@@ -7149,9 +7153,11 @@ static void reap_sync_thread(mddev_t *mddev)
            !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) {
                /* success...*/
                /* activate any spares */
-               if (mddev->pers->spare_active(mddev))
+               if (mddev->pers->spare_active(mddev)) {
                        sysfs_notify(&mddev->kobj, NULL,
                                     "degraded");
+                       set_bit(MD_CHANGE_DEVS, &mddev->flags);
+               }
        }
        if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) &&
            mddev->pers->finish_reshape)

Attachment: signature.asc
Description: PGP signature

Reply via email to