- if (rcl == 0) {
- /* Get the cld, it will be released in mgc_blocking_ast. */
- config_log_get(cld);
- rc = ldlm_lock_set_data(&lockh, (void *)cld);
- LASSERT(rc == 0);
- } else {
- CDEBUG(D_MGC, "Can't get cfg lock: %d\n", rcl);
-
- /* mark cld_lostlock so that it will requeue
- * after MGC becomes available. */
- cld->cld_lostlock = 1;
- /* Get extra reference, it will be put in requeue thread */
- config_log_get(cld);
- }
-
+ if (rcl == 0) {
+ /* Get the cld, it will be released in mgc_blocking_ast. */
+ config_log_get(cld);
+ rc = ldlm_lock_set_data(&lockh, (void *)cld);
+ LASSERT(!lustre_handle_is_used(&cld->cld_lockh));
+ LASSERT(rc == 0);
+ cld->cld_lockh = lockh;
+ } else {
+ CDEBUG(D_MGC, "Can't get cfg lock: %d\n", rcl);
+ cld->cld_lockh.cookie = 0;
+
+ if (rcl == -ESHUTDOWN &&
+ atomic_read(&mgc->u.cli.cl_mgc_refcount) > 0 && !retry) {
+ struct obd_import *imp;
+ struct l_wait_info lwi;
+ long timeout = cfs_time_seconds(obd_timeout);
+
+ mutex_unlock(&cld->cld_lock);
+ imp = class_exp2cliimp(mgc->u.cli.cl_mgc_mgsexp);
+
+ /* Let's force the pinger, and wait the import to be
+ * connected, note: since mgc import is non-replayable,
+ * and even the import state is disconnected, it does
+ * not mean the "recovery" is stopped, so we will keep
+ * waitting until timeout or the import state is
+ * FULL or closed */
+ ptlrpc_pinger_force(imp);
+
+ lwi = LWI_TIMEOUT(timeout, NULL, NULL);
+ l_wait_event(imp->imp_recovery_waitq,
+ !mgc_import_in_recovery(imp), &lwi);
+
+ if (imp->imp_state == LUSTRE_IMP_FULL) {
+ retry = true;
+ goto restart;
+ } else {
+ mutex_lock(&cld->cld_lock);
+ /* unlock/lock mutex, so check stopping again */
+ if (cld->cld_stopping) {
+ mutex_unlock(&cld->cld_lock);
+ RETURN(0);
+ }
+ spin_lock(&config_list_lock);
+ cld->cld_lostlock = 1;
+ spin_unlock(&config_list_lock);
+ }
+ } else {
+ /* mark cld_lostlock so that it will requeue
+ * after MGC becomes available. */
+ spin_lock(&config_list_lock);
+ cld->cld_lostlock = 1;
+ spin_unlock(&config_list_lock);
+ }
+ }