Whamcloud - gitweb
LU-572 ptlrpc: make ptlrpc_recover_import() async
authorJinshan Xiong <jay@whamcloud.com>
Fri, 5 Aug 2011 23:48:29 +0000 (16:48 -0700)
committerOleg Drokin <green@whamcloud.com>
Mon, 3 Oct 2011 19:06:28 +0000 (15:06 -0400)
Add an async argument for ptlrpc_recover_import() and with async nonzero,
ptlrpc_recover_import() will return immediately after sending connecting
RPC.

This is needed for imperative recovery since it may recover multiple
targets meanwhile.

Change-Id: Iccc40fca4d3d5d3fb0b2965e62beda23e2fb3b4c
Signed-off-by: Jinshan Xiong <jay@whamcloud.com>
Reviewed-on: http://review.whamcloud.com/1191
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/include/lustre_ha.h
lustre/mdc/mdc_request.c
lustre/osc/osc_request.c
lustre/ptlrpc/import.c
lustre/ptlrpc/recover.c
lustre/tests/sanity.sh
lustre/tests/sanityn.sh

index c88a281..78444e5 100644 (file)
@@ -52,7 +52,7 @@ int ptlrpc_replay(struct obd_import *imp);
 int ptlrpc_resend(struct obd_import *imp);
 void ptlrpc_free_committed(struct obd_import *imp);
 void ptlrpc_wake_delayed(struct obd_import *imp);
-int ptlrpc_recover_import(struct obd_import *imp, char *new_uuid);
+int ptlrpc_recover_import(struct obd_import *imp, char *new_uuid, int async);
 int ptlrpc_set_import_active(struct obd_import *imp, int active);
 void ptlrpc_activate_import(struct obd_import *imp);
 void ptlrpc_deactivate_import(struct obd_import *imp);
index 83eb2ae..873d274 100644 (file)
@@ -1397,7 +1397,7 @@ static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                 GOTO(out, rc);
         }
         case OBD_IOC_CLIENT_RECOVER:
-                rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1);
+                rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1, 0);
                 if (rc < 0)
                         GOTO(out, rc);
                 GOTO(out, rc = 0);
index b6948c1..be0027b 100644 (file)
@@ -3881,7 +3881,7 @@ static int osc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                 GOTO(out, err);
         case OBD_IOC_CLIENT_RECOVER:
                 err = ptlrpc_recover_import(obd->u.cli.cl_import,
-                                            data->ioc_inlbuf1);
+                                            data->ioc_inlbuf1, 0);
                 if (err > 0)
                         err = 0;
                 GOTO(out, err);
index 6188cc4..03311e5 100644 (file)
@@ -447,10 +447,9 @@ int ptlrpc_reconnect_import(struct obd_import *imp)
         /* Remove 'invalid' flag */
         ptlrpc_activate_import(imp);
         /* Attempt a new connect */
-        ptlrpc_recover_import(imp, NULL);
+        ptlrpc_recover_import(imp, NULL, 0);
         return 0;
 }
-
 EXPORT_SYMBOL(ptlrpc_reconnect_import);
 
 /**
index b7855d7..fade6b0 100644 (file)
@@ -58,8 +58,6 @@
 
 #include "ptlrpc_internal.h"
 
-static int ptlrpc_recover_import_no_retry(struct obd_import *, char *);
-
 /**
  * Start recovery on disconnected import.
  * This is done by just attempting a connect
@@ -274,36 +272,64 @@ int ptlrpc_set_import_active(struct obd_import *imp, int active)
         if (active) {
                 CDEBUG(D_HA, "setting import %s VALID\n",
                        obd2cli_tgt(imp->imp_obd));
-                rc = ptlrpc_recover_import(imp, NULL);
+
+                cfs_spin_lock(&imp->imp_lock);
+                imp->imp_deactive = 0;
+                cfs_spin_unlock(&imp->imp_lock);
+                obd_import_event(imp->imp_obd, imp, IMP_EVENT_ACTIVATE);
+
+                rc = ptlrpc_recover_import(imp, NULL, 0);
         }
 
         RETURN(rc);
 }
 
 /* Attempt to reconnect an import */
-int ptlrpc_recover_import(struct obd_import *imp, char *new_uuid)
+int ptlrpc_recover_import(struct obd_import *imp, char *new_uuid, int async)
 {
-        int rc;
+        int rc = 0;
         ENTRY;
 
         cfs_spin_lock(&imp->imp_lock);
-        if (cfs_atomic_read(&imp->imp_inval_count)) {
-                cfs_spin_unlock(&imp->imp_lock);
-                RETURN(-EINVAL);
-        }
+        if (imp->imp_state == LUSTRE_IMP_NEW || imp->imp_deactive ||
+            cfs_atomic_read(&imp->imp_inval_count))
+                rc = -EINVAL;
         cfs_spin_unlock(&imp->imp_lock);
+        if (rc)
+                GOTO(out, rc);
 
         /* force import to be disconnected. */
         ptlrpc_set_import_discon(imp, 0);
 
+        /* Check if reconnect is already in progress */
         cfs_spin_lock(&imp->imp_lock);
-        imp->imp_deactive = 0;
+        if (imp->imp_state != LUSTRE_IMP_DISCON)
+                rc = -EALREADY;
         cfs_spin_unlock(&imp->imp_lock);
-        obd_import_event(imp->imp_obd, imp, IMP_EVENT_ACTIVATE);
+        if (rc)
+                GOTO(out, rc);
 
-        rc = ptlrpc_recover_import_no_retry(imp, new_uuid);
+        rc = ptlrpc_connect_import(imp, new_uuid);
+        if (rc)
+                GOTO(out, rc);
 
-        RETURN(rc);
+        if (!async) {
+                struct l_wait_info lwi;
+                int secs = cfs_time_seconds(obd_timeout);
+
+                CDEBUG(D_HA, "%s: recovery started, waiting %u seconds\n",
+                       obd2cli_tgt(imp->imp_obd), secs);
+
+                lwi = LWI_TIMEOUT(secs, NULL, NULL);
+                rc = l_wait_event(imp->imp_recovery_waitq,
+                                  !ptlrpc_import_in_recovery(imp), &lwi);
+                CDEBUG(D_HA, "%s: recovery finished\n",
+                       obd2cli_tgt(imp->imp_obd));
+        }
+        EXIT;
+
+out:
+        return rc;
 }
 
 int ptlrpc_import_in_recovery(struct obd_import *imp)
@@ -317,38 +343,3 @@ int ptlrpc_import_in_recovery(struct obd_import *imp)
         cfs_spin_unlock(&imp->imp_lock);
         return in_recovery;
 }
-
-static int ptlrpc_recover_import_no_retry(struct obd_import *imp,
-                                          char *new_uuid)
-{
-        int rc;
-        int in_recovery = 0;
-        struct l_wait_info lwi;
-        ENTRY;
-
-        /* Check if reconnect is already in progress */
-        cfs_spin_lock(&imp->imp_lock);
-        if (imp->imp_state != LUSTRE_IMP_DISCON) {
-                in_recovery = 1;
-        }
-        cfs_spin_unlock(&imp->imp_lock);
-
-        if (in_recovery == 1)
-                RETURN(-EALREADY);
-
-        rc = ptlrpc_connect_import(imp, new_uuid);
-        if (rc)
-                RETURN(rc);
-
-        CDEBUG(D_HA, "%s: recovery started, waiting\n",
-               obd2cli_tgt(imp->imp_obd));
-
-        lwi = LWI_TIMEOUT(cfs_timeout_cap(cfs_time_seconds(obd_timeout)), 
-                          NULL, NULL);
-        rc = l_wait_event(imp->imp_recovery_waitq,
-                          !ptlrpc_import_in_recovery(imp), &lwi);
-        CDEBUG(D_HA, "%s: recovery finished\n",
-               obd2cli_tgt(imp->imp_obd));
-
-        RETURN(rc);
-}
index e0acee1..14920ee 100644 (file)
@@ -5090,7 +5090,7 @@ test_104a() {
        OSC=`lctl get_param -n devices | awk '/-osc-/ {print $4}' | head -n 1`
        lctl --device %$OSC deactivate
        lfs df || error "lfs df with deactivated OSC failed"
-       lctl --device %$OSC recover
+       lctl --device %$OSC activate
        lfs df || error "lfs df with reactivated OSC failed"
        rm -f $DIR/$tfile
 }
index a229c61..1978beb 100644 (file)
@@ -451,7 +451,7 @@ test_24a() {
 #      OSC=`lctl dl | awk '/-osc-/ {print $4}' | head -n 1`
        lctl --device %$OSC deactivate
        lfs df -i || error "lfs df -i with deactivated OSC failed"
-       lctl --device %$OSC recover
+       lctl --device %$OSC activate
        lfs df || error "lfs df with reactivated OSC failed"
 }
 run_test 24a "lfs df [-ih] [path] test ========================="