Whamcloud - gitweb
LU-1399 config: check lustre_cfg_new() return
[fs/lustre-release.git] / lustre / mgc / mgc_request.c
index 8935814..9f2d005 100644 (file)
@@ -96,7 +96,8 @@ int mgc_fsname2resid(char *fsname, struct ldlm_res_id *res_id, int type)
 }
 EXPORT_SYMBOL(mgc_fsname2resid);
 
-int mgc_logname2resid(char *logname, struct ldlm_res_id *res_id, int type)
+static int mgc_logname2resid(char *logname, struct ldlm_res_id *res_id,
+                            int type)
 {
        char *name_end;
        int len;
@@ -113,7 +114,7 @@ int mgc_logname2resid(char *logname, struct ldlm_res_id *res_id, int type)
 }
 
 /********************** config llog list **********************/
-static CFS_LIST_HEAD(config_llog_list);
+static struct list_head config_llog_list = LIST_HEAD_INIT(config_llog_list);
 static DEFINE_SPINLOCK(config_list_lock);
 
 /* Take a reference to a config log */
@@ -138,7 +139,7 @@ static void config_log_put(struct config_llog_data *cld)
 
        /* spinlock to make sure no item with 0 refcount in the list */
        if (atomic_dec_and_lock(&cld->cld_refcount, &config_list_lock)) {
-               cfs_list_del(&cld->cld_list_chain);
+               list_del(&cld->cld_list_chain);
                spin_unlock(&config_list_lock);
 
                 CDEBUG(D_MGC, "dropping config log %s\n", cld->cld_logname);
@@ -173,7 +174,7 @@ struct config_llog_data *config_log_find(char *logname,
 
         instance = cfg ? cfg->cfg_instance : NULL;
        spin_lock(&config_list_lock);
-        cfs_list_for_each_entry(cld, &config_llog_list, cld_list_chain) {
+       list_for_each_entry(cld, &config_llog_list, cld_list_chain) {
                 /* check if instance equals */
                 if (instance != cld->cld_cfg.cfg_instance)
                         continue;
@@ -233,7 +234,7 @@ struct config_llog_data *do_config_log_add(struct obd_device *obd,
         rc = mgc_logname2resid(logname, &cld->cld_resid, type);
 
        spin_lock(&config_list_lock);
-       cfs_list_add(&cld->cld_list_chain, &config_llog_list);
+       list_add(&cld->cld_list_chain, &config_llog_list);
        spin_unlock(&config_list_lock);
 
         if (rc) {
@@ -365,7 +366,8 @@ static int config_log_add(struct obd_device *obd, char *logname,
                        *ptr = 0;
                }
                else {
-                       CERROR("sptlrpc log name not correct: %s", seclogname);
+                       CERROR("%s: sptlrpc log name not correct, %s: "
+                              "rc = %d\n", obd->obd_name, seclogname, -EINVAL);
                        config_log_put(cld);
                        RETURN(-EINVAL);
                }
@@ -465,18 +467,23 @@ static int config_log_end(char *logname, struct config_llog_instance *cfg)
 #ifdef LPROCFS
 int lprocfs_mgc_rd_ir_state(struct seq_file *m, void *data)
 {
-        struct obd_device       *obd = data;
-        struct obd_import       *imp = obd->u.cli.cl_import;
-        struct obd_connect_data *ocd = &imp->imp_connect_data;
-        struct config_llog_data *cld;
-        ENTRY;
+       struct obd_device       *obd = data;
+       struct obd_import       *imp;
+       struct obd_connect_data *ocd;
+       struct config_llog_data *cld;
+       ENTRY;
+
+       LASSERT(obd != NULL);
+       LPROCFS_CLIMP_CHECK(obd);
+       imp = obd->u.cli.cl_import;
+       ocd = &imp->imp_connect_data;
 
        seq_printf(m, "imperative_recovery: %s\n",
                   OCD_HAS_FLAG(ocd, IMP_RECOV) ? "ENABLED" : "DISABLED");
        seq_printf(m, "client_state:\n");
 
        spin_lock(&config_list_lock);
-       cfs_list_for_each_entry(cld, &config_llog_list, cld_list_chain) {
+       list_for_each_entry(cld, &config_llog_list, cld_list_chain) {
                if (cld->cld_recover == NULL)
                        continue;
                seq_printf(m,  "    - { client: %s, nidtbl_version: %u }\n",
@@ -485,18 +492,21 @@ int lprocfs_mgc_rd_ir_state(struct seq_file *m, void *data)
        }
        spin_unlock(&config_list_lock);
 
+       LPROCFS_CLIMP_EXIT(obd);
        RETURN(0);
 }
 #endif
 
 /* reenqueue any lost locks */
-#define RQ_RUNNING 0x1
-#define RQ_NOW     0x2
-#define RQ_LATER   0x4
-#define RQ_STOP    0x8
+#define RQ_RUNNING     0x1
+#define RQ_NOW         0x2
+#define RQ_LATER       0x4
+#define RQ_STOP                0x8
+#define RQ_PRECLEANUP  0x10
 static int                    rq_state = 0;
 static wait_queue_head_t      rq_waitq;
 static DECLARE_COMPLETION(rq_exit);
+static DECLARE_COMPLETION(rq_start);
 
 static void do_requeue(struct config_llog_data *cld)
 {
@@ -532,12 +542,13 @@ static void do_requeue(struct config_llog_data *cld)
 
 static int mgc_requeue_thread(void *data)
 {
-        int rc = 0;
-        ENTRY;
+       int rc = 0;
+       bool first = true;
+       ENTRY;
 
-        CDEBUG(D_MGC, "Starting requeue thread\n");
+       CDEBUG(D_MGC, "Starting requeue thread\n");
 
-        /* Keep trying failed locks periodically */
+       /* Keep trying failed locks periodically */
        spin_lock(&config_list_lock);
        rq_state |= RQ_RUNNING;
        while (1) {
@@ -551,13 +562,20 @@ static int mgc_requeue_thread(void *data)
                rq_state &= ~(RQ_NOW | RQ_LATER);
                spin_unlock(&config_list_lock);
 
+               if (first) {
+                       first = false;
+                       complete(&rq_start);
+               }
+
                /* 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 */
+               to = msecs_to_jiffies(MGC_TIMEOUT_MIN_SECONDS * MSEC_PER_SEC);
+               /* rand is centi-seconds */
+               to += msecs_to_jiffies(rand * MSEC_PER_SEC / 100);
                lwi = LWI_TIMEOUT(to, NULL, NULL);
-               l_wait_event(rq_waitq, rq_state & RQ_STOP, &lwi);
+               l_wait_event(rq_waitq, rq_state & (RQ_STOP | RQ_PRECLEANUP),
+                            &lwi);
 
                 /*
                  * iterate & processing through the list. for each cld, process
@@ -570,7 +588,8 @@ static int mgc_requeue_thread(void *data)
                 cld_prev = NULL;
 
                spin_lock(&config_list_lock);
-               cfs_list_for_each_entry(cld, &config_llog_list,
+               rq_state &= ~RQ_PRECLEANUP;
+               list_for_each_entry(cld, &config_llog_list,
                                        cld_list_chain) {
                        if (!cld->cld_lostlock)
                                continue;
@@ -710,8 +729,6 @@ static int mgc_fs_setup(struct obd_device *obd, struct super_block *sb)
        /* The mgc fs exclusion mutex. Only one fs can be setup at a time. */
        mutex_lock(&cli->cl_mgc_mutex);
 
-       cfs_cleanup_group_info();
-
        /* Setup the configs dir */
        rc = lu_env_init(env, LCT_MG_THREAD);
        if (rc)
@@ -843,6 +860,7 @@ static atomic_t mgc_count = ATOMIC_INIT(0);
 static int mgc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
 {
        int rc = 0;
+       int temp;
        ENTRY;
 
        switch (stage) {
@@ -850,18 +868,19 @@ static int mgc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
                break;
        case OBD_CLEANUP_EXPORTS:
                if (atomic_dec_and_test(&mgc_count)) {
-                       int running;
+                       LASSERT(rq_state & RQ_RUNNING);
                        /* stop requeue thread */
-                       spin_lock(&config_list_lock);
-                       running = rq_state & RQ_RUNNING;
-                       if (running)
-                               rq_state |= RQ_STOP;
-                       spin_unlock(&config_list_lock);
-                       if (running) {
-                               wake_up(&rq_waitq);
-                               wait_for_completion(&rq_exit);
-                       }
+                       temp = RQ_STOP;
+               } else {
+                       /* wakeup requeue thread to clean our cld */
+                       temp = RQ_NOW | RQ_PRECLEANUP;
                }
+               spin_lock(&config_list_lock);
+               rq_state |= temp;
+               spin_unlock(&config_list_lock);
+               wake_up(&rq_waitq);
+               if (temp & RQ_STOP)
+                       wait_for_completion(&rq_exit);
                obd_cleanup_client_import(obd);
                rc = mgc_llog_fini(NULL, obd);
                if (rc != 0)
@@ -891,7 +910,8 @@ static int mgc_cleanup(struct obd_device *obd)
 
 static int mgc_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
 {
-       int                             rc;
+       struct task_struct      *task;
+       int                      rc;
        ENTRY;
 
        rc = ptlrpcd_addref();
@@ -910,7 +930,7 @@ static int mgc_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
 
 #ifdef LPROCFS
        obd->obd_vars = lprocfs_mgc_obd_vars;
-       lprocfs_seq_obd_setup(obd);
+       lprocfs_obd_setup(obd);
 #endif
        sptlrpc_lprocfs_cliobd_attach(obd);
 
@@ -919,16 +939,17 @@ static int mgc_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
                init_waitqueue_head(&rq_waitq);
 
                /* start requeue thread */
-               rc = PTR_ERR(kthread_run(mgc_requeue_thread, NULL,
-                                            "ll_cfg_requeue"));
-               if (IS_ERR_VALUE(rc)) {
-                       CERROR("%s: Cannot start requeue thread (%d),"
-                              "no more log updates!\n",
+               task = kthread_run(mgc_requeue_thread, NULL, "ll_cfg_requeue");
+               if (IS_ERR(task)) {
+                       rc = PTR_ERR(task);
+                       CERROR("%s: cannot start requeue thread: rc = %d; "
+                              "no more log updates\n",
                               obd->obd_name, rc);
                        GOTO(err_cleanup, rc);
                }
                /* rc is the task_struct pointer of mgc_requeue_thread. */
                rc = 0;
+               wait_for_completion(&rq_start);
        }
 
        RETURN(rc);
@@ -1000,7 +1021,10 @@ static int mgc_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
 }
 
 /* Not sure where this should go... */
-#define  MGC_ENQUEUE_LIMIT 50
+/* This is the timeout value for MGS_CONNECT request plus a ping interval, such
+ * that we can have a chance to try the secondary MGS if any. */
+#define  MGC_ENQUEUE_LIMIT (INITIAL_CONNECT_TIMEOUT + (AT_OFF ? 0 : at_min) \
+                               + PING_INTERVAL)
 #define  MGC_TARGET_REG_LIMIT 10
 #define  MGC_SEND_PARAM_LIMIT 10
 
@@ -1151,9 +1175,9 @@ static int mgc_target_register(struct obd_export *exp,
         RETURN(rc);
 }
 
-int mgc_set_info_async(const struct lu_env *env, struct obd_export *exp,
-                       obd_count keylen, void *key, obd_count vallen,
-                       void *val, struct ptlrpc_request_set *set)
+static int mgc_set_info_async(const struct lu_env *env, struct obd_export *exp,
+                             obd_count keylen, void *key, obd_count vallen,
+                             void *val, struct ptlrpc_request_set *set)
 {
         int rc = -EINVAL;
         ENTRY;
@@ -1371,7 +1395,7 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,
 
         while (datalen > 0) {
                 int   entry_len = sizeof(*entry);
-                int   is_ost;
+               int   is_ost, i;
                 struct obd_device *obd;
                 char *obdname;
                 char *cname;
@@ -1477,11 +1501,17 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,
                        continue;
                }
 
-                /* TODO: iterate all nids to find one */
-                /* find uuid by nid */
-                rc = client_import_find_conn(obd->u.cli.cl_import,
-                                             entry->u.nids[0],
-                                             (struct obd_uuid *)uuid);
+               /* iterate all nids to find one */
+               /* find uuid by nid */
+               rc = -ENOENT;
+               for (i = 0; i < entry->mne_nid_count; i++) {
+                       rc = client_import_find_conn(obd->u.cli.cl_import,
+                                                    entry->u.nids[i],
+                                                    (struct obd_uuid *)uuid);
+                       if (rc == 0)
+                               break;
+               }
+
                up_read(&obd->u.cli.cl_sem);
                 if (rc < 0) {
                         CERROR("mgc: cannot find uuid by nid %s\n",
@@ -1498,12 +1528,11 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,
 
                 lustre_cfg_bufs_set_string(&bufs, 1, params);
 
-                rc = -ENOMEM;
-                lcfg = lustre_cfg_new(LCFG_PARAM, &bufs);
-                if (lcfg == NULL) {
-                        CERROR("mgc: cannot allocate memory\n");
-                        break;
-                }
+               lcfg = lustre_cfg_new(LCFG_PARAM, &bufs);
+               if (lcfg == NULL) {
+                       rc = -ENOMEM;
+                       break;
+               }
 
                 CDEBUG(D_INFO, "ir apply logs "LPD64"/"LPD64" for %s -> %s\n",
                        prev_version, max_version, obdname, params);
@@ -1617,27 +1646,25 @@ again:
                 GOTO(out, rc = ealen);
 
        if (ealen > nrpages << PAGE_CACHE_SHIFT)
-                GOTO(out, rc = -EINVAL);
+               GOTO(out, rc = -EINVAL);
 
-        if (ealen == 0) { /* no logs transferred */
-                if (!eof)
-                        rc = -EINVAL;
-                GOTO(out, rc);
-        }
+       if (ealen == 0) { /* no logs transferred */
+               if (!eof)
+                       rc = -EINVAL;
+               GOTO(out, rc);
+       }
 
        mne_swab = !!ptlrpc_rep_need_swab(req);
-#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 2, 50, 0)
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
        /* This import flag means the server did an extra swab of IR MNE
         * records (fixed in LU-1252), reverse it here if needed. LU-1644 */
        if (unlikely(req->rq_import->imp_need_mne_swab))
                mne_swab = !mne_swab;
-#else
-#warning "LU-1644: Remove old OBD_CONNECT_MNE_SWAB fixup and imp_need_mne_swab"
 #endif
 
-        for (i = 0; i < nrpages && ealen > 0; i++) {
-                int rc2;
-                void *ptr;
+       for (i = 0; i < nrpages && ealen > 0; i++) {
+               int rc2;
+               void *ptr;
 
                ptr = kmap(pages[i]);
                rc2 = mgc_apply_recover_logs(obd, cld, res->mcr_offset, ptr,
@@ -1764,7 +1791,8 @@ static int mgc_process_cfg_log(struct obd_device *mgc,
                        rc = mgc_llog_local_copy(env, mgc, ctxt, lctxt,
                                                 cld->cld_logname);
                if (local_only || rc) {
-                       if (llog_is_empty(env, lctxt, cld->cld_logname)) {
+                       if (strcmp(cld->cld_logname, PARAMS_FILENAME) != 0 &&
+                           llog_is_empty(env, lctxt, cld->cld_logname)) {
                                LCONSOLE_ERROR_MSG(0x13a, "Failed to get MGS "
                                                   "log %s and no local copy."
                                                   "\n", cld->cld_logname);
@@ -1773,6 +1801,7 @@ static int mgc_process_cfg_log(struct obd_device *mgc,
                        CDEBUG(D_MGC, "Failed to get MGS log %s, using local "
                               "copy for now, will try to update later.\n",
                               cld->cld_logname);
+                       rc = 0;
                }
                /* Now, whether we copied or not, start using the local llog.
                 * If we failed to copy, we'll start using whatever the old
@@ -1973,7 +2002,7 @@ static int mgc_process_config(struct obd_device *obd, obd_count len, void *buf)
                if (rc == 0 && cld->cld_params != NULL) {
                        rc = mgc_process_log(obd, cld->cld_params);
                        if (rc == -ENOENT) {
-                               CDEBUG(D_MGC, "There is no params"
+                               CDEBUG(D_MGC, "There is no params "
                                              "config file yet\n");
                                rc = 0;
                        }
@@ -2005,7 +2034,7 @@ out:
         RETURN(rc);
 }
 
-struct obd_ops mgc_obd_ops = {
+static struct obd_ops mgc_obd_ops = {
         .o_owner        = THIS_MODULE,
         .o_setup        = mgc_setup,
         .o_precleanup   = mgc_precleanup,
@@ -2020,16 +2049,12 @@ struct obd_ops mgc_obd_ops = {
         .o_process_config = mgc_process_config,
 };
 
-int __init mgc_init(void)
+static int __init mgc_init(void)
 {
-        return class_register_type(&mgc_obd_ops, NULL, NULL,
-#ifndef HAVE_ONLY_PROCFS_SEQ
-                                       NULL,
-#endif
-                                       LUSTRE_MGC_NAME, NULL);
+       return class_register_type(&mgc_obd_ops, NULL, true, NULL,
+                                  LUSTRE_MGC_NAME, NULL);
 }
 
-#ifdef __KERNEL__
 static void /*__exit*/ mgc_exit(void)
 {
         class_unregister_type(LUSTRE_MGC_NAME);
@@ -2041,4 +2066,3 @@ MODULE_LICENSE("GPL");
 
 module_init(mgc_init);
 module_exit(mgc_exit);
-#endif