[PATCH] md: merge md_enter_safemode into md_check_recovery
authorNeilBrown <neilb@cse.unsw.edu.au>
Wed, 22 Jun 2005 00:17:11 +0000 (17:17 -0700)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Wed, 22 Jun 2005 02:07:42 +0000 (19:07 -0700)
md_enter_safemode checks if it is time to mark the md superblock as 'clean'.
i.e.  if all writes have completed and a suitable delay has passed.

This is currently called from md_handle_safemode which in-turn is called
(almost) every time md_check_recovery is called, and from the end of
md_do_sync which causes the mddev->thread to run, which will always call
md_check_recovery as well.

So it doesn't need to be a separate function and fits quite well into
md_check_recovery.

The "almost" is because multipathd calls md_check_recovery but not
md_handle_safemode.  This is OK because the code from md_enter_safemode is a
no-op if mddev->safemode == 0, which it always is for a multipathd (providing
we don't allow it to be set to 2 on a signal...)

Signed-off-by: Neil Brown <neilb@cse.unsw.edu.au>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
drivers/md/md.c
drivers/md/raid1.c
drivers/md/raid10.c
drivers/md/raid5.c
drivers/md/raid6main.c

index 60835dfd058e5fd895b91d00e9128929dbc20bd8..c842e34d850eea6a89a9f54e9ed53b1fa7b6087c 100644 (file)
@@ -3203,37 +3203,6 @@ void md_write_end(mddev_t *mddev)
        }
 }
 
-static inline void md_enter_safemode(mddev_t *mddev)
-{
-       if (!mddev->safemode) return;
-       if (mddev->safemode == 2 &&
-           (atomic_read(&mddev->writes_pending) || mddev->in_sync ||
-                   mddev->recovery_cp != MaxSector))
-               return; /* avoid the lock */
-       mddev_lock_uninterruptible(mddev);
-       if (mddev->safemode && !atomic_read(&mddev->writes_pending) &&
-           !mddev->in_sync && mddev->recovery_cp == MaxSector) {
-               mddev->in_sync = 1;
-               md_update_sb(mddev);
-       }
-       mddev_unlock(mddev);
-
-       if (mddev->safemode == 1)
-               mddev->safemode = 0;
-}
-
-void md_handle_safemode(mddev_t *mddev)
-{
-       if (signal_pending(current)) {
-               printk(KERN_INFO "md: %s in immediate safe mode\n",
-                       mdname(mddev));
-               mddev->safemode = 2;
-               flush_signals(current);
-       }
-       md_enter_safemode(mddev);
-}
-
-
 static DECLARE_WAIT_QUEUE_HEAD(resync_wait);
 
 #define SYNC_MARKS     10
@@ -3449,7 +3418,6 @@ static void md_do_sync(mddev_t *mddev)
                        mddev->recovery_cp = MaxSector;
        }
 
-       md_enter_safemode(mddev);
  skip:
        mddev->curr_resync = 0;
        wake_up(&resync_wait);
@@ -3490,14 +3458,37 @@ void md_check_recovery(mddev_t *mddev)
 
        if (mddev->ro)
                return;
+
+       if (signal_pending(current)) {
+               if (mddev->pers->sync_request) {
+                       printk(KERN_INFO "md: %s in immediate safe mode\n",
+                              mdname(mddev));
+                       mddev->safemode = 2;
+               }
+               flush_signals(current);
+       }
+
        if ( ! (
                mddev->sb_dirty ||
                test_bit(MD_RECOVERY_NEEDED, &mddev->recovery) ||
-               test_bit(MD_RECOVERY_DONE, &mddev->recovery)
+               test_bit(MD_RECOVERY_DONE, &mddev->recovery) ||
+               (mddev->safemode == 1) ||
+               (mddev->safemode == 2 && ! atomic_read(&mddev->writes_pending)
+                && !mddev->in_sync && mddev->recovery_cp == MaxSector)
                ))
                return;
+
        if (mddev_trylock(mddev)==0) {
                int spares =0;
+
+               if (mddev->safemode && !atomic_read(&mddev->writes_pending) &&
+                   !mddev->in_sync && mddev->recovery_cp == MaxSector) {
+                       mddev->in_sync = 1;
+                       mddev->sb_dirty = 1;
+               }
+               if (mddev->safemode == 1)
+                       mddev->safemode = 0;
+
                if (mddev->sb_dirty)
                        md_update_sb(mddev);
                if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) &&
@@ -3741,7 +3732,6 @@ EXPORT_SYMBOL(md_error);
 EXPORT_SYMBOL(md_done_sync);
 EXPORT_SYMBOL(md_write_start);
 EXPORT_SYMBOL(md_write_end);
-EXPORT_SYMBOL(md_handle_safemode);
 EXPORT_SYMBOL(md_register_thread);
 EXPORT_SYMBOL(md_unregister_thread);
 EXPORT_SYMBOL(md_wakeup_thread);
index 4947f599b652f342bce4709d08355a5c6b888d6a..b34ad56362dffe26b41014d70c336ea1df1b649f 100644 (file)
@@ -931,7 +931,6 @@ static void raid1d(mddev_t *mddev)
        mdk_rdev_t *rdev;
 
        md_check_recovery(mddev);
-       md_handle_safemode(mddev);
        
        for (;;) {
                char b[BDEVNAME_SIZE];
index 3c37be6423d75a1a576cd545d80c0d76e25a246e..9ae21504db8a4c6df6ab25c50666392898d14a27 100644 (file)
@@ -1216,7 +1216,6 @@ static void raid10d(mddev_t *mddev)
        mdk_rdev_t *rdev;
 
        md_check_recovery(mddev);
-       md_handle_safemode(mddev);
 
        for (;;) {
                char b[BDEVNAME_SIZE];
index 3cb11ac232fa8ca9ada29fb9cdb99e15cf1ba0f2..63b1c59d36ff9f5c950e3c6a5e4e4135a9360bf2 100644 (file)
@@ -1546,7 +1546,6 @@ static void raid5d (mddev_t *mddev)
        PRINTK("+++ raid5d active\n");
 
        md_check_recovery(mddev);
-       md_handle_safemode(mddev);
 
        handled = 0;
        spin_lock_irq(&conf->device_lock);
index 908edd78a792b35740844a5048f507cb13f1285b..9d0e0e42a3be205a5e6028ebac76f857f2bdaed3 100644 (file)
@@ -1705,7 +1705,6 @@ static void raid6d (mddev_t *mddev)
        PRINTK("+++ raid6d active\n");
 
        md_check_recovery(mddev);
-       md_handle_safemode(mddev);
 
        handled = 0;
        spin_lock_irq(&conf->device_lock);