Whamcloud - gitweb
LU-3810 obd: Cleanup client import if client_obd_setup fails
[fs/lustre-release.git] / lustre / mgc / mgc_request.c
index f91f8a1..64ab255 100644 (file)
@@ -360,7 +360,15 @@ static int config_log_add(struct obd_device *obd, char *logname,
         LASSERT(lsi->lsi_lmd);
         if (!(lsi->lsi_lmd->lmd_flags & LMD_FLG_NOIR)) {
                 struct config_llog_data *recover_cld;
-                *strrchr(seclogname, '-') = 0;
+               ptr = strrchr(seclogname, '-');
+               if (ptr != NULL) {
+                       *ptr = 0;
+               }
+               else {
+                       CERROR("sptlrpc log name not correct: %s", seclogname);
+                       config_log_put(cld);
+                       RETURN(-EINVAL);
+               }
                 recover_cld = config_recover_log_add(obd, seclogname, cfg, sb);
                if (IS_ERR(recover_cld))
                        GOTO(out_err3, rc = PTR_ERR(recover_cld));
@@ -488,11 +496,12 @@ int lprocfs_mgc_rd_ir_state(char *page, char **start, off_t off,
 #define RQ_LATER   0x4
 #define RQ_STOP    0x8
 static int                    rq_state = 0;
-static cfs_waitq_t            rq_waitq;
+static wait_queue_head_t      rq_waitq;
 static DECLARE_COMPLETION(rq_exit);
 
 static void do_requeue(struct config_llog_data *cld)
 {
+       int rc = 0;
         ENTRY;
         LASSERT(cfs_atomic_read(&cld->cld_refcount) > 0);
 
@@ -500,13 +509,15 @@ static void do_requeue(struct config_llog_data *cld)
            export which is being disconnected. Take the client
            semaphore to make the check non-racy. */
        down_read(&cld->cld_mgcexp->exp_obd->u.cli.cl_sem);
-        if (cld->cld_mgcexp->exp_obd->u.cli.cl_conn_count != 0) {
-                CDEBUG(D_MGC, "updating log %s\n", cld->cld_logname);
-                mgc_process_log(cld->cld_mgcexp->exp_obd, cld);
-        } else {
-                CDEBUG(D_MGC, "disconnecting, won't update log %s\n",
-                       cld->cld_logname);
-        }
+       if (cld->cld_mgcexp->exp_obd->u.cli.cl_conn_count != 0) {
+               CDEBUG(D_MGC, "updating log %s\n", cld->cld_logname);
+               rc = mgc_process_log(cld->cld_mgcexp->exp_obd, cld);
+               if (rc && rc != -ENOENT)
+                       CERROR("failed processing log: %d\n", rc);
+       } else {
+               CDEBUG(D_MGC, "disconnecting, won't update log %s\n",
+                      cld->cld_logname);
+       }
        up_read(&cld->cld_mgcexp->exp_obd->u.cli.cl_sem);
 
         EXIT;
@@ -540,13 +551,13 @@ static int mgc_requeue_thread(void *data)
                rq_state &= ~(RQ_NOW | RQ_LATER);
                spin_unlock(&config_list_lock);
 
-                /* Always wait a few seconds to allow the server who
-                   caused the lock revocation to finish its setup, plus some
-                   random so everyone doesn't try to reconnect at once. */
-                to = MGC_TIMEOUT_MIN_SECONDS * CFS_HZ;
-                to += rand * CFS_HZ / 100; /* rand is centi-seconds */
-                lwi = LWI_TIMEOUT(to, NULL, NULL);
-                l_wait_event(rq_waitq, rq_state & RQ_STOP, &lwi);
+               /* Always wait a few seconds to allow the server who
+                  caused the lock revocation to finish its setup, plus some
+                  random so everyone doesn't try to reconnect at once. */
+               to = MGC_TIMEOUT_MIN_SECONDS * HZ;
+               to += rand * HZ / 100; /* rand is centi-seconds */
+               lwi = LWI_TIMEOUT(to, NULL, NULL);
+               l_wait_event(rq_waitq, rq_state & RQ_STOP, &lwi);
 
                 /*
                  * iterate & processing through the list. for each cld, process
@@ -637,7 +648,7 @@ static void mgc_requeue_add(struct config_llog_data *cld)
        } else {
                rq_state |= RQ_NOW;
                spin_unlock(&config_list_lock);
-               cfs_waitq_signal(&rq_waitq);
+               wake_up(&rq_waitq);
        }
        EXIT;
 }
@@ -847,7 +858,7 @@ static int mgc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
                                rq_state |= RQ_STOP;
                        spin_unlock(&config_list_lock);
                        if (running) {
-                               cfs_waitq_signal(&rq_waitq);
+                               wake_up(&rq_waitq);
                                wait_for_completion(&rq_exit);
                         }
                 }
@@ -880,29 +891,31 @@ static int mgc_cleanup(struct obd_device *obd)
 
 static int mgc_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
 {
-        struct lprocfs_static_vars lvars;
-        int rc;
-        ENTRY;
+       struct lprocfs_static_vars      lvars;
+       int                             rc;
+       ENTRY;
 
-        ptlrpcd_addref();
+       rc = ptlrpcd_addref();
+       if (rc < 0)
+               RETURN(rc);
 
-        rc = client_obd_setup(obd, lcfg);
-        if (rc)
-                GOTO(err_decref, rc);
+       rc = client_obd_setup(obd, lcfg);
+       if (rc)
+               GOTO(err_decref, rc);
 
        rc = mgc_llog_init(NULL, obd);
-        if (rc) {
-                CERROR("failed to setup llogging subsystems\n");
-                GOTO(err_cleanup, rc);
-        }
+       if (rc) {
+               CERROR("failed to setup llogging subsystems\n");
+               GOTO(err_cleanup, rc);
+       }
 
-        lprocfs_mgc_init_vars(&lvars);
-        lprocfs_obd_setup(obd, lvars.obd_vars);
-        sptlrpc_lprocfs_cliobd_attach(obd);
+       lprocfs_mgc_init_vars(&lvars);
+       lprocfs_obd_setup(obd, lvars.obd_vars);
+       sptlrpc_lprocfs_cliobd_attach(obd);
 
-        if (cfs_atomic_inc_return(&mgc_count) == 1) {
+       if (cfs_atomic_inc_return(&mgc_count) == 1) {
                rq_state = 0;
-               cfs_waitq_init(&rq_waitq);
+               init_waitqueue_head(&rq_waitq);
 
                /* start requeue thread */
                rc = PTR_ERR(kthread_run(mgc_requeue_thread, NULL,
@@ -915,15 +928,15 @@ static int mgc_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
                }
                /* rc is the task_struct pointer of mgc_requeue_thread. */
                rc = 0;
-        }
+       }
 
-        RETURN(rc);
+       RETURN(rc);
 
 err_cleanup:
-        client_obd_cleanup(obd);
+       client_obd_cleanup(obd);
 err_decref:
-        ptlrpcd_decref();
-        RETURN(rc);
+       ptlrpcd_decref();
+       RETURN(rc);
 }
 
 /* based on ll_mdc_blocking_ast */
@@ -1092,7 +1105,7 @@ static void mgc_notify_active(struct obd_device *unused)
        spin_lock(&config_list_lock);
        rq_state |= RQ_NOW;
        spin_unlock(&config_list_lock);
-       cfs_waitq_signal(&rq_waitq);
+       wake_up(&rq_waitq);
 
        /* TODO: Help the MGS rebuild nidtbl. -jay */
 }