Whamcloud - gitweb
LU-365 Update copyright for files modified by Whamcloud
[fs/lustre-release.git] / lustre / mgc / mgc_request.c
index bc1cc5f..fd120ae 100644 (file)
@@ -28,6 +28,9 @@
 /*
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2011 Whamcloud, Inc.
+ *
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -146,9 +149,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);
@@ -163,37 +163,31 @@ struct config_llog_data *config_log_find(char *logname,
                                          struct config_llog_instance *cfg)
 {
         struct config_llog_data *cld;
-        char *logid = logname;
-        int match_instance = 0;
+        struct config_llog_data *found = NULL;
+        void *                   instance;
         ENTRY;
 
-        if (cfg && cfg->cfg_instance) {
-                match_instance++;
-                logid = cfg->cfg_instance;
-        }
-        if (!logid) {
-                CERROR("No log specified\n");
-                RETURN(ERR_PTR(-EINVAL));
-        }
+        LASSERT(logname != NULL);
 
+        instance = cfg ? cfg->cfg_instance : NULL;
         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)
-                        goto out_found;
-        }
-        cfs_spin_unlock(&config_list_lock);
+                /* check if instance equals */
+                if (instance != cld->cld_cfg.cfg_instance)
+                        continue;
 
-        CDEBUG(D_CONFIG, "can't get log %s\n", logid);
-        RETURN(ERR_PTR(-ENOENT));
-out_found:
-        cfs_atomic_inc(&cld->cld_refcount);
+                /* instance may be NULL, should check name */
+                if (strcmp(logname, cld->cld_logname) == 0) {
+                        found = cld;
+                        break;
+                }
+        }
+        if (found) {
+                cfs_atomic_inc(&found->cld_refcount);
+                LASSERT(found->cld_stopping == 0 || found->cld_is_sptlrpc == 0);
+        }
         cfs_spin_unlock(&config_list_lock);
-        LASSERT(cld->cld_stopping == 0 || cld->cld_is_sptlrpc == 0);
-        RETURN(cld);
+        RETURN(found);
 }
 
 static
@@ -207,8 +201,8 @@ struct config_llog_data *do_config_log_add(struct obd_device *obd,
         int                      rc;
         ENTRY;
 
-        CDEBUG(D_MGC, "do adding config log %s:%s\n", logname,
-               cfg ? cfg->cfg_instance : "NULL");
+        CDEBUG(D_MGC, "do adding config log %s:%p\n", logname,
+               cfg ? cfg->cfg_instance : 0);
 
         OBD_ALLOC(cld, sizeof(*cld));
         if (!cld)
@@ -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;
@@ -276,7 +264,7 @@ static int config_log_add(struct obd_device *obd, char *logname,
         char                    *ptr;
         ENTRY;
 
-        CDEBUG(D_MGC, "adding config log %s:%s\n", logname, cfg->cfg_instance);
+        CDEBUG(D_MGC, "adding config log %s:%p\n", logname, cfg->cfg_instance);
 
         /*
          * for each regular log, the depended sptlrpc log name is
@@ -292,7 +280,7 @@ static int config_log_add(struct obd_device *obd, char *logname,
         strcpy(seclogname + (ptr - logname), "-sptlrpc");
 
         sptlrpc_cld = config_log_find(seclogname, NULL);
-        if (IS_ERR(sptlrpc_cld)) {
+        if (sptlrpc_cld == NULL) {
                 sptlrpc_cld = do_config_log_add(obd, seclogname, 1, NULL, NULL);
                 if (IS_ERR(sptlrpc_cld)) {
                         CERROR("can't create sptlrpc log: %s\n", seclogname);
@@ -323,8 +311,8 @@ static int config_log_end(char *logname, struct config_llog_instance *cfg)
         ENTRY;
 
         cld = config_log_find(logname, cfg);
-        if (IS_ERR(cld))
-                RETURN(PTR_ERR(cld));
+        if (cld == NULL)
+                RETURN(-ENOENT);
 
         cfs_mutex_lock(&cld->cld_lock);
         /*
@@ -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");
@@ -1257,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;
@@ -1280,7 +1269,7 @@ int mgc_process_log(struct obd_device *mgc,
         if (cld->cld_cfg.cfg_sb)
                 lsi = s2lsi(cld->cld_cfg.cfg_sb);
 
-        CDEBUG(D_MGC, "Process log %s:%s from %d\n", cld->cld_logname,
+        CDEBUG(D_MGC, "Process log %s:%p from %d\n", cld->cld_logname,
                cld->cld_cfg.cfg_instance, cld->cld_cfg.cfg_last_idx + 1);
 
         ctxt = llog_get_context(mgc, LLOG_CONFIG_REPL_CTXT);
@@ -1290,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,
@@ -1311,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. */
@@ -1347,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
@@ -1385,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;
@@ -1415,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);
 
@@ -1429,8 +1426,8 @@ static int mgc_process_config(struct obd_device *obd, obd_count len, void *buf)
                 if (rc)
                         break;
                 cld = config_log_find(logname, cfg);
-                if (IS_ERR(cld)) {
-                        rc = PTR_ERR(cld);
+                if (cld == NULL) {
+                        rc = -ENOENT;
                         break;
                 }
 
@@ -1445,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);