Whamcloud - gitweb
LU-327 cleanup the client import of mgc
[fs/lustre-release.git] / lustre / mgc / mgc_request.c
index 47eb2bf..cfc2797 100644 (file)
@@ -146,9 +146,6 @@ static void config_log_put(struct config_llog_data *cld)
 
                 class_export_put(cld->cld_mgcexp);
                 OBD_FREE(cld->cld_logname, strlen(cld->cld_logname) + 1);
-                if (cld->cld_cfg.cfg_instance != NULL)
-                        OBD_FREE(cld->cld_cfg.cfg_instance,
-                                 strlen(cld->cld_cfg.cfg_instance) + 1);
                 OBD_FREE(cld, sizeof(*cld));
         } else {
                 cfs_spin_unlock(&config_list_lock);
@@ -164,13 +161,11 @@ struct config_llog_data *config_log_find(char *logname,
 {
         struct config_llog_data *cld;
         char *logid = logname;
-        int match_instance = 0;
         ENTRY;
 
-        if (cfg && cfg->cfg_instance) {
-                match_instance++;
+        if (cfg)
                 logid = cfg->cfg_instance;
-        }
+
         if (!logid) {
                 CERROR("No log specified\n");
                 RETURN(ERR_PTR(-EINVAL));
@@ -178,11 +173,10 @@ struct config_llog_data *config_log_find(char *logname,
 
         cfs_spin_lock(&config_list_lock);
         cfs_list_for_each_entry(cld, &config_llog_list, cld_list_chain) {
-                if (match_instance && cld->cld_cfg.cfg_instance &&
-                    strcmp(logid, cld->cld_cfg.cfg_instance) == 0)
-                        goto out_found;
-                if (!match_instance &&
-                    strcmp(logid, cld->cld_logname) == 0)
+                char *name = cld->cld_logname;
+                if (cfg)
+                        name = cld->cld_cfg.cfg_instance;
+                if (strcmp(logid, name) == 0)
                         goto out_found;
         }
         cfs_spin_unlock(&config_list_lock);
@@ -231,12 +225,6 @@ struct config_llog_data *do_config_log_add(struct obd_device *obd,
         /* Keep the mgc around until we are done */
         cld->cld_mgcexp = class_export_get(obd->obd_self_export);
 
-        if (cfg && cfg->cfg_instance != NULL) {
-                OBD_ALLOC(cld->cld_cfg.cfg_instance,
-                          strlen(cfg->cfg_instance) + 1);
-                strcpy(cld->cld_cfg.cfg_instance, cfg->cfg_instance);
-        }
-
         if (is_sptlrpc) {
                 sptlrpc_conf_log_start(logname);
                 cld->cld_cfg.cfg_obdname = obd->obd_name;
@@ -419,7 +407,7 @@ static int mgc_requeue_thread(void *data)
                 /* 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. */
-                lwi_now = LWI_TIMEOUT(3 * CFS_HZ + (ll_rand() & 0xff) * \
+                lwi_now = LWI_TIMEOUT(3 * CFS_HZ + (cfs_rand() & 0xff) * \
                                       (CFS_HZ / 100),
                                       NULL, NULL);
                 l_wait_event(rq_waitq, rq_state & RQ_STOP, &lwi_now);
@@ -513,8 +501,8 @@ static int mgc_requeue_add(struct config_llog_data *cld, int later)
                 LASSERT(rq_state == 0);
                 rq_state = RQ_RUNNING | (later ? RQ_LATER : RQ_NOW);
                 cfs_spin_unlock(&config_list_lock);
-                rc = cfs_kernel_thread(mgc_requeue_thread, 0,
-                                       CLONE_VM | CLONE_FILES);
+                rc = cfs_create_thread(mgc_requeue_thread, NULL,
+                                       CFS_DAEMON_FLAGS);
                 if (rc < 0) {
                         CERROR("log %s: cannot start requeue thread (%d),"
                                "no more log updates!\n", cld->cld_logname, rc);
@@ -571,8 +559,8 @@ static int mgc_fs_setup(struct obd_device *obd, struct super_block *sb,
         obd->obd_lvfs_ctxt.fs = get_ds();
 
         push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-        dentry = lookup_one_len(MOUNT_CONFIGS_DIR, cfs_fs_pwd(current->fs),
-                                strlen(MOUNT_CONFIGS_DIR));
+        dentry = ll_lookup_one_len(MOUNT_CONFIGS_DIR, cfs_fs_pwd(current->fs),
+                                   strlen(MOUNT_CONFIGS_DIR));
         pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
         if (IS_ERR(dentry)) {
                 err = PTR_ERR(dentry);
@@ -645,6 +633,7 @@ static int mgc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
                         cfs_spin_unlock(&config_list_lock);
                         cfs_waitq_signal(&rq_waitq);
                 }
+                obd_cleanup_client_import(obd);
                 rc = obd_llog_finish(obd, 0);
                 if (rc != 0)
                         CERROR("failed to cleanup llogging subsystems\n");
@@ -1059,6 +1048,9 @@ static int mgc_import_event(struct obd_device *obd,
                 break;
         case IMP_EVENT_OCD:
                 break;
+        case IMP_EVENT_DEACTIVATE:
+        case IMP_EVENT_ACTIVATE:
+                break;
         default:
                 CERROR("Unknown import event %#x\n", event);
                 LBUG();
@@ -1254,7 +1246,7 @@ int mgc_process_log(struct obd_device *mgc,
         struct llog_ctxt *ctxt, *lctxt;
         struct lustre_handle lockh;
         struct client_obd *cli = &mgc->u.cli;
-        struct lvfs_run_ctxt saved;
+        struct lvfs_run_ctxt *saved_ctxt;
         struct lustre_sb_info *lsi = NULL;
         int rc = 0, rcl, flags = 0, must_pop = 0;
         ENTRY;
@@ -1287,6 +1279,12 @@ int mgc_process_log(struct obd_device *mgc,
                 RETURN(-EINVAL);
         }
 
+        OBD_ALLOC_PTR(saved_ctxt);
+        if (saved_ctxt == NULL) {
+                cfs_mutex_unlock(&cld->cld_lock);
+                RETURN(-ENOMEM);
+        }
+
         /* Get the cfg lock on the llog */
         rcl = mgc_enqueue(mgc->u.cli.cl_mgc_mgsexp, NULL, LDLM_PLAIN, NULL,
                           LCK_CR, &flags, NULL, NULL, NULL,
@@ -1308,7 +1306,7 @@ int mgc_process_log(struct obd_device *mgc,
         if (lctxt && lsi && (lsi->lsi_flags & LSI_SERVER) &&
             (lsi->lsi_srv_mnt == cli->cl_mgc_vfsmnt) &&
             !IS_MGS(lsi->lsi_ldd)) {
-                push_ctxt(&saved, &mgc->obd_lvfs_ctxt, NULL);
+                push_ctxt(saved_ctxt, &mgc->obd_lvfs_ctxt, NULL);
                 must_pop++;
                 if (rcl == 0)
                         /* Only try to copy log if we have the lock. */
@@ -1344,8 +1342,9 @@ out_pop:
         if (ctxt != lctxt)
                 llog_ctxt_put(lctxt);
         if (must_pop)
-                pop_ctxt(&saved, &mgc->obd_lvfs_ctxt, NULL);
+                pop_ctxt(saved_ctxt, &mgc->obd_lvfs_ctxt, NULL);
 
+        OBD_FREE_PTR(saved_ctxt);
         /*
          * update settings on existing OBDs. doing it inside
          * of llog_process_lock so no device is attaching/detaching
@@ -1382,11 +1381,12 @@ out_pop:
 static int mgc_process_config(struct obd_device *obd, obd_count len, void *buf)
 {
         struct lustre_cfg *lcfg = buf;
-        int cmd;
+        struct config_llog_instance *cfg = NULL;
+        char *logname;
         int rc = 0;
         ENTRY;
 
-        switch(cmd = lcfg->lcfg_command) {
+        switch(lcfg->lcfg_command) {
         case LCFG_LOV_ADD_OBD: {
                 /* Overloading this cfg command: register a new target */
                 struct mgs_target_info *mti;
@@ -1412,9 +1412,9 @@ static int mgc_process_config(struct obd_device *obd, obd_count len, void *buf)
         }
         case LCFG_LOG_START: {
                 struct config_llog_data *cld;
-                struct config_llog_instance *cfg;
                 struct super_block *sb;
-                char *logname = lustre_cfg_string(lcfg, 1);
+
+                logname = lustre_cfg_string(lcfg, 1);
                 cfg = (struct config_llog_instance *)lustre_cfg_buf(lcfg, 2);
                 sb = *(struct super_block **)lustre_cfg_buf(lcfg, 3);
 
@@ -1442,8 +1442,8 @@ static int mgc_process_config(struct obd_device *obd, obd_count len, void *buf)
                 break;
         }
         case LCFG_LOG_END: {
-                struct config_llog_instance *cfg = NULL;
-                char *logname = lustre_cfg_string(lcfg, 1);
+                logname = lustre_cfg_string(lcfg, 1);
+
                 if (lcfg->lcfg_bufcount >= 2)
                         cfg = (struct config_llog_instance *)lustre_cfg_buf(
                                 lcfg, 2);