Whamcloud - gitweb
LU-1301 mgs: improve error handling
authorAlex Zhuravlev <bzzz@whamcloud.com>
Thu, 9 Aug 2012 15:16:28 +0000 (19:16 +0400)
committerOleg Drokin <green@whamcloud.com>
Wed, 12 Sep 2012 16:53:59 +0000 (12:53 -0400)
taken as is from orion

Signed-off-by: Alex Zhuravlev <bzzz@whamcloud.com>
Change-Id: Ib26c5f519f686a77fa1057af214a4823d0c16359
Reviewed-on: http://review.whamcloud.com/3670
Tested-by: Hudson
Reviewed-by: Jinshan Xiong <jinshan.xiong@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Maloo <whamcloud.maloo@gmail.com>
lustre/mgs/mgs_handler.c
lustre/mgs/mgs_llog.c

index b9e3df2..270883d 100644 (file)
@@ -77,7 +77,8 @@ static int mgs_connect(const struct lu_env *env,
                 RETURN(rc);
 
         lexp = class_conn2export(&conn);
-        LASSERT(lexp);
+       if (lexp == NULL)
+               GOTO(out, rc = -EFAULT);
 
         mgs_counter_incr(lexp, LPROC_MGS_CONNECT);
 
@@ -89,6 +90,7 @@ static int mgs_connect(const struct lu_env *env,
 
         rc = mgs_export_stats_init(obd, lexp, localdata);
 
+out:
         if (rc) {
                 class_disconnect(lexp);
         } else {
@@ -564,6 +566,8 @@ static int mgs_handle_target_reg(struct ptlrpc_request *req)
                 mti->mti_flags |= LDD_F_UPDATE;
                 /* Erased logs means start from scratch. */
                 mti->mti_flags &= ~LDD_F_UPGRADE14;
+               if (rc)
+                       GOTO(out_nolock, rc);
         }
 
        rc = mgs_find_or_make_fsdb(env, mgs, mti->mti_fsname, &fsdb);
@@ -654,20 +658,23 @@ static int mgs_set_info_rpc(struct ptlrpc_request *req)
        lustre_cfg_bufs_reset(&mgi->mgi_bufs, NULL);
        lustre_cfg_bufs_set_string(&mgi->mgi_bufs, 1, msp->mgs_param);
        lcfg = lustre_cfg_new(LCFG_PARAM, &mgi->mgi_bufs);
+       if (IS_ERR(lcfg))
+               GOTO(out, rc = PTR_ERR(lcfg));
        rc = mgs_setparam(env, mgs, lcfg, mgi->mgi_fsname);
         if (rc) {
                 CERROR("Error %d in setting the parameter %s for fs %s\n",
                       rc, msp->mgs_param, mgi->mgi_fsname);
-                RETURN(rc);
+               GOTO(out_cfg, rc);
         }
 
-        lustre_cfg_free(lcfg);
-
         rc = req_capsule_server_pack(&req->rq_pill);
         if (rc == 0) {
                 rep_msp = req_capsule_server_get(&req->rq_pill, &RMF_MGS_SEND_PARAM);
                 rep_msp = msp;
         }
+out_cfg:
+       lustre_cfg_free(lcfg);
+out:
         RETURN(rc);
 }
 
@@ -1025,52 +1032,50 @@ static int mgs_iocontrol_pool(const struct lu_env *env,
                 rec.lrh_type = OBD_CFG_REC;
         } else {
                 CERROR("unknown cfg record type:%d \n", data->ioc_type);
-                rc = -EINVAL;
-                GOTO(out_pool, rc);
+               GOTO(out_pool, rc = -EINVAL);
         }
 
-        if (data->ioc_plen1 > CFS_PAGE_SIZE) {
-                rc = -E2BIG;
-                GOTO(out_pool, rc);
-        }
+       if (data->ioc_plen1 > CFS_PAGE_SIZE)
+               GOTO(out_pool, rc = -E2BIG);
 
         OBD_ALLOC(lcfg, data->ioc_plen1);
         if (lcfg == NULL)
                 GOTO(out_pool, rc = -ENOMEM);
 
         if (cfs_copy_from_user(lcfg, data->ioc_pbuf1, data->ioc_plen1))
-                GOTO(out_pool, rc = -EFAULT);
+               GOTO(out_lcfg, rc = -EFAULT);
 
-        if (lcfg->lcfg_bufcount < 2) {
-                GOTO(out_pool, rc = -EFAULT);
-        }
+       if (lcfg->lcfg_bufcount < 2)
+               GOTO(out_lcfg, rc = -EFAULT);
 
         /* first arg is always <fsname>.<poolname> */
-       mgs_extract_fs_pool(lustre_cfg_string(lcfg, 1), mgi->mgi_fsname,
-                            poolname);
+       rc = mgs_extract_fs_pool(lustre_cfg_string(lcfg, 1), mgi->mgi_fsname,
+                                poolname);
+       if (rc)
+               GOTO(out_lcfg, rc);
 
         switch (lcfg->lcfg_command) {
        case LCFG_POOL_NEW:
                 if (lcfg->lcfg_bufcount != 2)
-                        RETURN(-EINVAL);
+                       GOTO(out_lcfg, rc = -EINVAL);
                rc = mgs_pool_cmd(env, mgs, LCFG_POOL_NEW, mgi->mgi_fsname,
                                   poolname, NULL);
                 break;
        case LCFG_POOL_ADD:
                 if (lcfg->lcfg_bufcount != 3)
-                        RETURN(-EINVAL);
+                       GOTO(out_lcfg, rc = -EINVAL);
                rc = mgs_pool_cmd(env, mgs, LCFG_POOL_ADD, mgi->mgi_fsname,
                                  poolname, lustre_cfg_string(lcfg, 2));
                 break;
        case LCFG_POOL_REM:
                 if (lcfg->lcfg_bufcount != 3)
-                        RETURN(-EINVAL);
+                       GOTO(out_lcfg, rc = -EINVAL);
                rc = mgs_pool_cmd(env, mgs, LCFG_POOL_REM, mgi->mgi_fsname,
                                  poolname, lustre_cfg_string(lcfg, 2));
                 break;
        case LCFG_POOL_DEL:
                 if (lcfg->lcfg_bufcount != 2)
-                        RETURN(-EINVAL);
+                       GOTO(out_lcfg, rc = -EINVAL);
                rc = mgs_pool_cmd(env, mgs, LCFG_POOL_DEL, mgi->mgi_fsname,
                                   poolname, NULL);
                 break;
@@ -1081,16 +1086,13 @@ static int mgs_iocontrol_pool(const struct lu_env *env,
         if (rc) {
                 CERROR("OBD_IOC_POOL err %d, cmd %X for pool %s.%s\n",
                       rc, lcfg->lcfg_command, mgi->mgi_fsname, poolname);
-                GOTO(out_pool, rc);
+               GOTO(out_lcfg, rc);
         }
 
+out_lcfg:
+       OBD_FREE(lcfg, data->ioc_plen1);
 out_pool:
-        if (lcfg != NULL)
-                OBD_FREE(lcfg, data->ioc_plen1);
-
-        if (poolname != NULL)
-                OBD_FREE(poolname, LOV_MAXPOOLNAME + 1);
-
+       OBD_FREE(poolname, LOV_MAXPOOLNAME + 1);
         RETURN(rc);
 }
 
@@ -1137,10 +1139,9 @@ int mgs_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                         GOTO(out_free, rc = -EINVAL);
 
                rc = mgs_setparam(&env, mgs, lcfg, mgi->mgi_fsname);
-                if (rc) {
-                        CERROR("setparam err %d\n", rc);
-                        GOTO(out_free, rc);
-                }
+               if (rc)
+                       CERROR("%s: setparam err: rc = %d\n",
+                              exp->exp_obd->obd_name, rc);
 out_free:
                 OBD_FREE(lcfg, data->ioc_plen1);
                break;
index bae69a4..7a971da 100644 (file)
@@ -275,7 +275,9 @@ static int mgs_get_fsdb_from_llog(const struct lu_env *env,
 
        ctxt = llog_get_context(mgs->mgs_obd, LLOG_CONFIG_ORIG_CTXT);
         LASSERT(ctxt != NULL);
-        name_create(&logname, fsdb->fsdb_name, "-client");
+       rc = name_create(&logname, fsdb->fsdb_name, "-client");
+       if (rc)
+               GOTO(out_put, rc);
         cfs_mutex_lock(&fsdb->fsdb_mutex);
        push_ctxt(&saved, &mgs->mgs_obd->obd_lvfs_ctxt, NULL);
        rc = llog_open_create(NULL, ctxt, &loghandle, NULL, logname);
@@ -300,6 +302,7 @@ out_pop:
        pop_ctxt(&saved, &mgs->mgs_obd->obd_lvfs_ctxt, NULL);
         cfs_mutex_unlock(&fsdb->fsdb_mutex);
         name_destroy(&logname);
+out_put:
         llog_ctxt_put(ctxt);
 
         RETURN(rc);
@@ -366,7 +369,7 @@ static struct fs_db *mgs_new_fsdb(const struct lu_env *env,
                 OBD_ALLOC(fsdb->fsdb_mdt_index_map, INDEX_MAP_SIZE);
                 if (!fsdb->fsdb_ost_index_map || !fsdb->fsdb_mdt_index_map) {
                         CERROR("No memory for index maps\n");
-                        GOTO(err, 0);
+                       GOTO(err, rc = -ENOMEM);
                 }
 
                 rc = name_create(&fsdb->fsdb_mdtlov, fsname, "-mdtlov");
@@ -715,7 +718,7 @@ static int mgs_modify(const struct lu_env *env, struct mgs_device *mgs,
        rc = llog_process_or_fork(env, loghandle, mgs_modify_handler,
                                  (void *)mml, NULL, false);
         if (!rc && !mml->mml_modified)
-                rc = -ENODEV;
+               rc = 1;
         OBD_FREE_PTR(mml);
 
 out_close:
@@ -724,7 +727,7 @@ out_close:
                 rc = rc2;
 out_pop:
        pop_ctxt(&saved, &mgs->mgs_obd->obd_lvfs_ctxt, NULL);
-        if (rc && rc != -ENODEV)
+       if (rc < 0)
                 CERROR("modify %s/%s failed %d\n",
                        mti->mti_svname, comment, rc);
         llog_ctxt_put(ctxt);
@@ -1025,12 +1028,16 @@ static int mgs_write_log_direct(const struct lu_env *env,
 
         /* FIXME These should be a single journal transaction */
        rc = record_marker(env, llh, fsdb, CM_START, devname, comment);
-
+       if (rc)
+               GOTO(out_end, rc);
        rc = record_lcfg(env, llh, lcfg);
-
+       if (rc)
+               GOTO(out_end, rc);
        rc = record_marker(env, llh, fsdb, CM_END, devname, comment);
-       rc = record_end_log(env, &llh);
-
+       if (rc)
+               GOTO(out_end, rc);
+out_end:
+       record_end_log(env, &llh);
         RETURN(rc);
 }
 
@@ -1054,7 +1061,9 @@ int mgs_write_log_direct_all(const struct lu_env *env,
            as well. FIXME Append this file to every new log.
            Actually, we should store as params (text), not llogs.  Or
            in a database. */
-        name_create(&logname, fsname, "-params");
+       rc = name_create(&logname, fsname, "-params");
+       if (rc)
+               RETURN(rc);
        if (mgs_log_is_empty(env, mgs, logname)) {
                struct llog_handle *llh = NULL;
                rc = record_start_log(env, mgs, &llh, logname);
@@ -1116,8 +1125,8 @@ static int mgs_write_log_osc_to_lov(const struct lu_env *env,
                                     struct mgs_target_info *mti,
                                     char *logname, char *suffix, char *lovname,
                                     enum lustre_sec_part sec_part, int flags);
-static void name_create_mdt_and_lov(char **logname, char **lovname,
-                                    struct fs_db *fsdb, int i);
+static int name_create_mdt_and_lov(char **logname, char **lovname,
+                                  struct fs_db *fsdb, int i);
 
 static int mgs_steal_llog_handler(const struct lu_env *env,
                                  struct llog_handle *llh,
@@ -1168,9 +1177,11 @@ static int mgs_steal_llog_handler(const struct lu_env *env,
                                 sizeof(tmti->mti_svname));
                        rc = record_start_log(env, mgs, &mdt_llh,
                                              mti->mti_svname);
+                       if (rc)
+                               RETURN(rc);
                        rc = record_marker(env, mdt_llh, fsdb, CM_START,
                                            mti->mti_svname,"add osc(copied)");
-                       rc = record_end_log(env, &mdt_llh);
+                       record_end_log(env, &mdt_llh);
                         last_step = marker->cm_step;
                         RETURN(rc);
                 }
@@ -1181,9 +1192,11 @@ static int mgs_steal_llog_handler(const struct lu_env *env,
                         got_an_osc_or_mdc = 0;
                        rc = record_start_log(env, mgs, &mdt_llh,
                                              mti->mti_svname);
+                       if (rc)
+                               RETURN(rc);
                        rc = record_marker(env, mdt_llh, fsdb, CM_END,
                                            mti->mti_svname,"add osc(copied)");
-                       rc = record_end_log(env, &mdt_llh);
+                       record_end_log(env, &mdt_llh);
                         RETURN(rc);
                 }
                 if (!strncmp(marker->cm_comment,"add mdc",7) &&
@@ -1239,8 +1252,8 @@ static int mgs_steal_llog_handler(const struct lu_env *env,
                        strlen(mti->mti_fsname));
                 tmti->mti_stripe_index = index;
 
-               mgs_write_log_mdc_to_mdt(env, mgs, fsdb,
-                                        tmti, mti->mti_svname);
+               rc = mgs_write_log_mdc_to_mdt(env, mgs, fsdb, tmti,
+                                             mti->mti_svname);
                 memset(tmti, 0, sizeof(*tmti));
                 RETURN(rc);
         }
@@ -1250,8 +1263,10 @@ static int mgs_steal_llog_handler(const struct lu_env *env,
                 char mdt_index[9];
                 char *logname, *lovname;
 
-                name_create_mdt_and_lov(&logname, &lovname, fsdb,
-                                        mti->mti_stripe_index);
+               rc = name_create_mdt_and_lov(&logname, &lovname, fsdb,
+                                            mti->mti_stripe_index);
+               if (rc)
+                       RETURN(rc);
                 sprintf(mdt_index, "-MDT%04x", mti->mti_stripe_index);
 
                 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1) {
@@ -1261,7 +1276,7 @@ static int mgs_steal_llog_handler(const struct lu_env *env,
                 }
 
                 tmti->mti_stripe_index = index;
-               mgs_write_log_osc_to_lov(env, mgs, fsdb, tmti, logname,
+               rc = mgs_write_log_osc_to_lov(env, mgs, fsdb, tmti, logname,
                                          mdt_index, lovname,
                                          LUSTRE_SP_MDT, 0);
                 name_destroy(&logname);
@@ -1348,12 +1363,23 @@ static int mgs_write_log_lmv(const struct lu_env *env,
         uuid = (char *)lmvdesc->ld_uuid.uuid;
 
        rc = record_start_log(env, mgs, &llh, logname);
+       if (rc)
+               GOTO(out_free, rc);
        rc = record_marker(env, llh, fsdb, CM_START, lmvname, "lmv setup");
+       if (rc)
+               GOTO(out_end, rc);
        rc = record_attach(env, llh, lmvname, "lmv", uuid);
+       if (rc)
+               GOTO(out_end, rc);
        rc = record_lmv_setup(env, llh, lmvname, lmvdesc);
+       if (rc)
+               GOTO(out_end, rc);
        rc = record_marker(env, llh, fsdb, CM_END, lmvname, "lmv setup");
-       rc = record_end_log(env, &llh);
-
+       if (rc)
+               GOTO(out_end, rc);
+out_end:
+       record_end_log(env, &llh);
+out_free:
         OBD_FREE_PTR(lmvdesc);
         RETURN(rc);
 }
@@ -1397,16 +1423,24 @@ static int mgs_write_log_lov(const struct lu_env *env, struct mgs_device *mgs,
         rc = mgs_clear_log(obd, logname); */
        rc = record_start_log(env, mgs, &llh, logname);
         if (rc)
-                GOTO(out, rc);
+               GOTO(out_free, rc);
         /* FIXME these should be a single journal transaction */
        rc = record_marker(env, llh, fsdb, CM_START, lovname, "lov setup");
+       if (rc)
+               GOTO(out_end, rc);
        rc = record_attach(env, llh, lovname, "lov", uuid);
+       if (rc)
+               GOTO(out_end, rc);
        rc = record_lov_setup(env, llh, lovname, lovdesc);
+       if (rc)
+               GOTO(out_end, rc);
        rc = record_marker(env, llh, fsdb, CM_END, lovname, "lov setup");
-       rc = record_end_log(env, &llh);
-
+       if (rc)
+               GOTO(out_end, rc);
         EXIT;
-out:
+out_end:
+       record_end_log(env, &llh);
+out_free:
         OBD_FREE_PTR(lovdesc);
         return rc;
 }
@@ -1447,13 +1481,11 @@ static int mgs_write_log_failnids(const struct lu_env *env,
                                failnodeuuid, cliname);
                        rc = record_add_uuid(env, llh, nid, failnodeuuid);
                 }
-                if (failnodeuuid) {
+               if (failnodeuuid)
                        rc = record_add_conn(env, llh, cliname, failnodeuuid);
-                        name_destroy(&failnodeuuid);
-                        failnodeuuid = NULL;
-                }
         }
 
+       name_destroy(&failnodeuuid);
         return rc;
 }
 
@@ -1464,7 +1496,10 @@ static int mgs_write_log_mdc_to_lmv(const struct lu_env *env,
                                     char *logname, char *lmvname)
 {
         struct llog_handle *llh = NULL;
-        char *mdcname, *nodeuuid, *mdcuuid, *lmvuuid;
+       char *mdcname = NULL;
+       char *nodeuuid = NULL;
+       char *mdcuuid = NULL;
+       char *lmvuuid = NULL;
         char index[6];
         int i, rc;
         ENTRY;
@@ -1477,32 +1512,56 @@ static int mgs_write_log_mdc_to_lmv(const struct lu_env *env,
         CDEBUG(D_MGS, "adding mdc for %s to log %s:lmv(%s)\n",
                mti->mti_svname, logname, lmvname);
 
-        name_create(&nodeuuid, libcfs_nid2str(mti->mti_nids[0]), "");
-        name_create(&mdcname, mti->mti_svname, "-mdc");
-        name_create(&mdcuuid, mdcname, "_UUID");
-        name_create(&lmvuuid, lmvname, "_UUID");
+       rc = name_create(&nodeuuid, libcfs_nid2str(mti->mti_nids[0]), "");
+       if (rc)
+               RETURN(rc);
+       rc = name_create(&mdcname, mti->mti_svname, "-mdc");
+       if (rc)
+               GOTO(out_free, rc);
+       rc = name_create(&mdcuuid, mdcname, "_UUID");
+       if (rc)
+               GOTO(out_free, rc);
+       rc = name_create(&lmvuuid, lmvname, "_UUID");
+       if (rc)
+               GOTO(out_free, rc);
 
        rc = record_start_log(env, mgs, &llh, logname);
+       if (rc)
+               GOTO(out_free, rc);
        rc = record_marker(env, llh, fsdb, CM_START, mti->mti_svname,
                            "add mdc");
-
+       if (rc)
+               GOTO(out_end, rc);
         for (i = 0; i < mti->mti_nid_count; i++) {
                 CDEBUG(D_MGS, "add nid %s for mdt\n",
                        libcfs_nid2str(mti->mti_nids[i]));
 
                rc = record_add_uuid(env, llh, mti->mti_nids[i], nodeuuid);
+               if (rc)
+                       GOTO(out_end, rc);
         }
 
        rc = record_attach(env, llh, mdcname, LUSTRE_MDC_NAME, lmvuuid);
+       if (rc)
+               GOTO(out_end, rc);
        rc = record_setup(env, llh, mdcname, mti->mti_uuid, nodeuuid, 0, 0);
+       if (rc)
+               GOTO(out_end, rc);
        rc = mgs_write_log_failnids(env, mti, llh, mdcname);
+       if (rc)
+               GOTO(out_end, rc);
         snprintf(index, sizeof(index), "%d", mti->mti_stripe_index);
        rc = record_mdc_add(env, llh, lmvname, mdcuuid, mti->mti_uuid,
                             index, "1");
+       if (rc)
+               GOTO(out_end, rc);
        rc = record_marker(env, llh, fsdb, CM_END, mti->mti_svname,
                            "add mdc");
-       rc = record_end_log(env, &llh);
-
+       if (rc)
+               GOTO(out_end, rc);
+out_end:
+       record_end_log(env, &llh);
+out_free:
         name_destroy(&lmvuuid);
         name_destroy(&mdcuuid);
         name_destroy(&mdcname);
@@ -1518,7 +1577,10 @@ static int mgs_write_log_mdc_to_mdt(const struct lu_env *env,
                                    char *logname)
 {
         struct llog_handle *llh = NULL;
-        char *nodeuuid, *mdcname, *mdcuuid, *mdtuuid;
+       char *nodeuuid = NULL;
+       char *mdcname = NULL;
+       char *mdcuuid = NULL;
+       char *mdtuuid = NULL;
         int idx = mti->mti_stripe_index;
         char index[9];
         int i, rc;
@@ -1531,33 +1593,58 @@ static int mgs_write_log_mdc_to_mdt(const struct lu_env *env,
 
         CDEBUG(D_MGS, "adding mdc index %d to %s\n", idx, logname);
 
-        name_create(&nodeuuid, libcfs_nid2str(mti->mti_nids[0]), "");
-        snprintf(index, sizeof(index), "-mdc%04x", idx);
-        name_create(&mdcname, logname, index);
-        name_create(&mdcuuid, mdcname, "_UUID");
-        name_create(&mdtuuid, logname, "_UUID");
+       rc = name_create(&nodeuuid, libcfs_nid2str(mti->mti_nids[0]), "");
+       if (rc)
+               RETURN(rc);
+       snprintf(index, sizeof(index), "-mdc%04x", idx);
+       rc = name_create(&mdcname, logname, index);
+       if (rc)
+               GOTO(out_free, rc);
+       rc = name_create(&mdcuuid, mdcname, "_UUID");
+       if (rc)
+               GOTO(out_free, rc);
+       rc = name_create(&mdtuuid, logname, "_UUID");
+       if (rc)
+               GOTO(out_free, rc);
 
        rc = record_start_log(env, mgs, &llh, logname);
+       if (rc)
+               GOTO(out_free, rc);
        rc = record_marker(env, llh, fsdb, CM_START, mti->mti_svname, "add mdc");
+       if (rc)
+               GOTO(out_end, rc);
         for (i = 0; i < mti->mti_nid_count; i++) {
                 CDEBUG(D_MGS, "add nid %s for mdt\n",
                        libcfs_nid2str(mti->mti_nids[i]));
                rc = record_add_uuid(env, llh, mti->mti_nids[i], nodeuuid);
+               if (rc)
+                       GOTO(out_end, rc);
         }
        rc = record_attach(env, llh, mdcname, LUSTRE_MDC_NAME, mdcuuid);
+       if (rc)
+               GOTO(out_end, rc);
        rc = record_setup(env, llh, mdcname, mti->mti_uuid, nodeuuid, 0, 0);
+       if (rc)
+               GOTO(out_end, rc);
        rc = mgs_write_log_failnids(env, mti, llh, mdcname);
+       if (rc)
+               GOTO(out_end, rc);
         snprintf(index, sizeof(index), "%d", idx);
 
        rc = record_mdc_add(env, llh, logname, mdcuuid, mti->mti_uuid,
                             index, "1");
+       if (rc)
+               GOTO(out_end, rc);
        rc = record_marker(env, llh, fsdb, CM_END, mti->mti_svname, "add mdc");
-       rc = record_end_log(env, &llh);
-
+       if (rc)
+               GOTO(out_end, rc);
+out_end:
+       record_end_log(env, &llh);
+out_free:
+       name_destroy(&mdtuuid);
         name_destroy(&mdcuuid);
         name_destroy(&mdcname);
         name_destroy(&nodeuuid);
-        name_destroy(&mdtuuid);
         RETURN(rc);
 }
 
@@ -1581,52 +1668,79 @@ static int mgs_write_log_mdt0(const struct lu_env *env,
         if (class_find_param(ptr, PARAM_FAILMODE, &ptr) == 0)
                 failout = (strncmp(ptr, "failout", 7) == 0);
 
-        name_create(&lovname, log, "-mdtlov");
-       if (mgs_log_is_empty(env, mgs, log))
+       rc = name_create(&lovname, log, "-mdtlov");
+       if (rc)
+               GOTO(out_free, rc);
+       if (mgs_log_is_empty(env, mgs, log)) {
                rc = mgs_write_log_lov(env, mgs, fsdb, mti, log, lovname);
+               if (rc)
+                       GOTO(out_lod, rc);
+       }
 
-        sprintf(uuid, "%s_UUID", log);
         sprintf(mdt_index, "%d", mti->mti_stripe_index);
 
-        /* add MDT itself */
        rc = record_start_log(env, mgs, &llh, log);
-        if (rc)
-                GOTO(out, rc);
+       if (rc)
+               GOTO(out_lod, rc);
+
+       /* add MDT itself */
 
         /* FIXME this whole fn should be a single journal transaction */
+       sprintf(uuid, "%s_UUID", log);
        rc = record_marker(env, llh, fsdb, CM_START, log, "add mdt");
+       if (rc)
+               GOTO(out_lod, rc);
        rc = record_attach(env, llh, log, LUSTRE_MDT_NAME, uuid);
+       if (rc)
+               GOTO(out_end, rc);
        rc = record_mount_opt(env, llh, log, lovname, NULL);
+       if (rc)
+               GOTO(out_end, rc);
        rc = record_setup(env, llh, log, uuid, mdt_index, lovname,
                         failout ? "n" : "f");
+       if (rc)
+               GOTO(out_end, rc);
        rc = record_marker(env, llh, fsdb, CM_END, log, "add mdt");
-       rc = record_end_log(env, &llh);
-out:
-        name_destroy(&lovname);
+       if (rc)
+               GOTO(out_end, rc);
+out_end:
+       record_end_log(env, &llh);
+out_lod:
+       name_destroy(&lovname);
+out_free:
         OBD_FREE(uuid, sizeof(struct obd_uuid));
         RETURN(rc);
 }
 
-static inline void name_create_mdt(char **logname, char *fsname, int i)
+static inline int name_create_mdt(char **logname, char *fsname, int i)
 {
         char mdt_index[9];
 
         sprintf(mdt_index, "-MDT%04x", i);
-        name_create(logname, fsname, mdt_index);
+       return name_create(logname, fsname, mdt_index);
 }
 
-static void name_create_mdt_and_lov(char **logname, char **lovname,
+static int name_create_mdt_and_lov(char **logname, char **lovname,
                                     struct fs_db *fsdb, int i)
 {
-        name_create_mdt(logname, fsdb->fsdb_name, i);
+       int rc;
+
+       rc = name_create_mdt(logname, fsdb->fsdb_name, i);
+       if (rc)
+               return rc;
         /* COMPAT_180 */
         if (i == 0 && cfs_test_bit(FSDB_OSCNAME18, &fsdb->fsdb_flags))
-                name_create(lovname, fsdb->fsdb_name, "-mdtlov");
+               rc = name_create(lovname, fsdb->fsdb_name, "-mdtlov");
         else
-                name_create(lovname, *logname, "-mdtlov");
+               rc = name_create(lovname, *logname, "-mdtlov");
+       if (rc) {
+               name_destroy(logname);
+               *logname = NULL;
+       }
+       return rc;
 }
 
-static inline void name_create_mdt_osc(char **oscname, char *ostname,
+static inline int name_create_mdt_osc(char **oscname, char *ostname,
                                        struct fs_db *fsdb, int i)
 {
         char suffix[16];
@@ -1635,7 +1749,7 @@ static inline void name_create_mdt_osc(char **oscname, char *ostname,
                 sprintf(suffix, "-osc");
         else
                 sprintf(suffix, "-osc-MDT%04x", i);
-        name_create(oscname, ostname, suffix);
+       return name_create(oscname, ostname, suffix);
 }
 
 /* envelope method for all layers log */
@@ -1676,16 +1790,23 @@ static int mgs_write_log_mdt(const struct lu_env *env,
 
         /* add mdt */
        rc = mgs_write_log_mdt0(env, mgs, fsdb, mti);
-
+       if (rc)
+               RETURN(rc);
         /* Append the mdt info to the client log */
-        name_create(&cliname, mti->mti_fsname, "-client");
+       rc = name_create(&cliname, mti->mti_fsname, "-client");
+       if (rc)
+               RETURN(rc);
 
        if (mgs_log_is_empty(env, mgs, cliname)) {
                 /* Start client log */
                rc = mgs_write_log_lov(env, mgs, fsdb, mti, cliname,
                                        fsdb->fsdb_clilov);
+               if (rc)
+                       GOTO(out_free, rc);
                rc = mgs_write_log_lmv(env, mgs, fsdb, mti, cliname,
                                        fsdb->fsdb_clilmv);
+               if (rc)
+                       GOTO(out_free, rc);
         }
 
         /*
@@ -1727,38 +1848,50 @@ static int mgs_write_log_mdt(const struct lu_env *env,
 
                rc = mgs_steal_llog_for_mdt_from_client(env, mgs, cliname,
                                                        &mgi->mgi_comp);
-
+               if (rc)
+                       GOTO(out_free, rc);
                rc = mgs_write_log_mdc_to_lmv(env, mgs, fsdb, mti, cliname,
                                               fsdb->fsdb_clilmv);
+               if (rc)
+                       GOTO(out_free, rc);
+
                 /* add mountopts */
                rc = record_start_log(env, mgs, &llh, cliname);
-                if (rc)
-                        GOTO(out, rc);
+               if (rc)
+                       GOTO(out_free, rc);
 
                rc = record_marker(env, llh, fsdb, CM_START, cliname,
                                    "mount opts");
+               if (rc)
+                       GOTO(out_end, rc);
                rc = record_mount_opt(env, llh, cliname, fsdb->fsdb_clilov,
                                       fsdb->fsdb_clilmv);
+               if (rc)
+                       GOTO(out_end, rc);
                rc = record_marker(env, llh, fsdb, CM_END, cliname,
                                    "mount opts");
-        }
-
-       rc = record_end_log(env, &llh);
-out:
-        name_destroy(&cliname);
+       }
 
-        // for_all_existing_mdt except current one
+       if (rc)
+               GOTO(out_end, rc);
+       /* for_all_existing_mdt except current one */
         for (i = 0; i < INDEX_MAP_SIZE * 8; i++){
                 char *mdtname;
                 if (i !=  mti->mti_stripe_index &&
                     cfs_test_bit(i,  fsdb->fsdb_mdt_index_map)) {
-                        name_create_mdt(&mdtname, mti->mti_fsname, i);
-                       rc = mgs_write_log_mdc_to_mdt(env, mgs, fsdb,
-                                                     mti, mdtname);
+                       rc = name_create_mdt(&mdtname, mti->mti_fsname, i);
+                       if (rc)
+                               GOTO(out_end, rc);
+                       rc = mgs_write_log_mdc_to_mdt(env, mgs, fsdb, mti, mdtname);
                         name_destroy(&mdtname);
+                       if (rc)
+                               GOTO(out_end, rc);
                 }
         }
-
+out_end:
+       record_end_log(env, &llh);
+out_free:
+       name_destroy(&cliname);
         RETURN(rc);
 }
 
@@ -1770,7 +1903,11 @@ static int mgs_write_log_osc_to_lov(const struct lu_env *env,
                                     enum lustre_sec_part sec_part, int flags)
 {
         struct llog_handle *llh = NULL;
-        char *nodeuuid, *oscname, *oscuuid, *lovuuid, *svname;
+       char *nodeuuid = NULL;
+       char *oscname = NULL;
+       char *oscuuid = NULL;
+       char *lovuuid = NULL;
+       char *svname = NULL;
         char index[6];
         int i, rc;
 
@@ -1783,11 +1920,21 @@ static int mgs_write_log_osc_to_lov(const struct lu_env *env,
                 RETURN (-EINVAL);
         }
 
-        name_create(&nodeuuid, libcfs_nid2str(mti->mti_nids[0]), "");
-        name_create(&svname, mti->mti_svname, "-osc");
-        name_create(&oscname, svname, suffix);
-        name_create(&oscuuid, oscname, "_UUID");
-        name_create(&lovuuid, lovname, "_UUID");
+       rc = name_create(&nodeuuid, libcfs_nid2str(mti->mti_nids[0]), "");
+       if (rc)
+               RETURN(rc);
+       rc = name_create(&svname, mti->mti_svname, "-osc");
+       if (rc)
+               GOTO(out_free, rc);
+       rc = name_create(&oscname, svname, suffix);
+       if (rc)
+               GOTO(out_free, rc);
+       rc = name_create(&oscuuid, oscname, "_UUID");
+       if (rc)
+               GOTO(out_free, rc);
+       rc = name_create(&lovuuid, lovname, "_UUID");
+       if (rc)
+               GOTO(out_free, rc);
 
         /*
         #03 L add_uuid nid=uml1@tcp(0x20000c0a80201) 0:  1:uml1_UUID
@@ -1803,28 +1950,43 @@ static int mgs_write_log_osc_to_lov(const struct lu_env *env,
 
        rc = record_start_log(env, mgs, &llh, logname);
         if (rc)
-                GOTO(out, rc);
+               GOTO(out_free, rc);
         /* FIXME these should be a single journal transaction */
        rc = record_marker(env, llh, fsdb, CM_START | flags, mti->mti_svname,
                            "add osc");
+       if (rc)
+               GOTO(out_end, rc);
         for (i = 0; i < mti->mti_nid_count; i++) {
                 CDEBUG(D_MGS, "add nid %s\n", libcfs_nid2str(mti->mti_nids[i]));
                rc = record_add_uuid(env, llh, mti->mti_nids[i], nodeuuid);
+               if (rc)
+                       GOTO(out_end, rc);
         }
        rc = record_attach(env, llh, oscname, LUSTRE_OSC_NAME, lovuuid);
+       if (rc)
+               GOTO(out_end, rc);
        rc = record_setup(env, llh, oscname, mti->mti_uuid, nodeuuid, 0, 0);
+       if (rc)
+               GOTO(out_end, rc);
        rc = mgs_write_log_failnids(env, mti, llh, oscname);
+       if (rc)
+               GOTO(out_end, rc);
         snprintf(index, sizeof(index), "%d", mti->mti_stripe_index);
        rc = record_lov_add(env, llh, lovname, mti->mti_uuid, index, "1");
+       if (rc)
+               GOTO(out_end, rc);
        rc = record_marker(env, llh, fsdb, CM_END | flags, mti->mti_svname,
                            "add osc");
-       rc = record_end_log(env, &llh);
-out:
-        name_destroy(&lovuuid);
-        name_destroy(&oscuuid);
-        name_destroy(&oscname);
-        name_destroy(&svname);
-        name_destroy(&nodeuuid);
+       if (rc)
+               GOTO(out_end, rc);
+out_end:
+       record_end_log(env, &llh);
+out_free:
+       name_destroy(&lovuuid);
+       name_destroy(&oscuuid);
+       name_destroy(&oscname);
+       name_destroy(&svname);
+       name_destroy(&nodeuuid);
         RETURN(rc);
 }
 
@@ -1864,17 +2026,27 @@ static int mgs_write_log_ost(const struct lu_env *env,
                 RETURN(rc);
         /* FIXME these should be a single journal transaction */
        rc = record_marker(env, llh, fsdb, CM_START, mti->mti_svname,"add ost");
+       if (rc)
+               GOTO(out_end, rc);
         if (*mti->mti_uuid == '\0')
                 snprintf(mti->mti_uuid, sizeof(mti->mti_uuid),
                          "%s_UUID", mti->mti_svname);
        rc = record_attach(env, llh, mti->mti_svname,
                            "obdfilter"/*LUSTRE_OST_NAME*/, mti->mti_uuid);
+       if (rc)
+               GOTO(out_end, rc);
        rc = record_setup(env, llh, mti->mti_svname,
                           "dev"/*ignored*/, "type"/*ignored*/,
                           failout ? "n" : "f", 0/*options*/);
+       if (rc)
+               GOTO(out_end, rc);
        rc = record_marker(env, llh, fsdb, CM_END, mti->mti_svname, "add ost");
-       rc = record_end_log(env, &llh);
-
+       if (rc)
+               GOTO(out_end, rc);
+out_end:
+       record_end_log(env, &llh);
+       if (rc)
+               RETURN(rc);
         /* We also have to update the other logs where this osc is part of
            the lov */
 
@@ -1899,27 +2071,40 @@ static int mgs_write_log_ost(const struct lu_env *env,
                 if (cfs_test_bit(i, fsdb->fsdb_mdt_index_map)) {
                         char mdt_index[9];
 
-                        name_create_mdt_and_lov(&logname, &lovname, fsdb, i);
+                       rc = name_create_mdt_and_lov(&logname, &lovname, fsdb,
+                                                    i);
+                       if (rc)
+                               RETURN(rc);
                         sprintf(mdt_index, "-MDT%04x", i);
-                       mgs_write_log_osc_to_lov(env, mgs, fsdb, mti, logname,
-                                                 mdt_index, lovname,
-                                                 LUSTRE_SP_MDT, flags);
+                       rc = mgs_write_log_osc_to_lov(env, mgs, fsdb, mti,
+                                                     logname, mdt_index,
+                                                     lovname, LUSTRE_SP_MDT,
+                                                     flags);
                         name_destroy(&logname);
                         name_destroy(&lovname);
+                       if (rc)
+                               RETURN(rc);
                 }
         }
 
         /* Append ost info to the client log */
-        name_create(&logname, mti->mti_fsname, "-client");
+       rc = name_create(&logname, mti->mti_fsname, "-client");
+       if (rc)
+               RETURN(rc);
        if (mgs_log_is_empty(env, mgs, logname)) {
                 /* Start client log */
                rc = mgs_write_log_lov(env, mgs, fsdb, mti, logname,
                                        fsdb->fsdb_clilov);
+               if (rc)
+                       GOTO(out_free, rc);
                rc = mgs_write_log_lmv(env, mgs, fsdb, mti, logname,
                                        fsdb->fsdb_clilmv);
+               if (rc)
+                       GOTO(out_free, rc);
         }
-       mgs_write_log_osc_to_lov(env, mgs, fsdb, mti, logname, "",
-                                 fsdb->fsdb_clilov, LUSTRE_SP_CLI, flags);
+       rc = mgs_write_log_osc_to_lov(env, mgs, fsdb, mti, logname, "",
+                                     fsdb->fsdb_clilov, LUSTRE_SP_CLI, 0);
+out_free:
         name_destroy(&logname);
         RETURN(rc);
 }
@@ -1946,21 +2131,25 @@ static int mgs_write_log_failnid_internal(const struct lu_env *env,
                 /* Remove _all_ failnids */
                rc = mgs_modify(env, mgs, fsdb, mti, logname,
                                 mti->mti_svname, "add failnid", CM_SKIP);
-                return rc;
+               return rc < 0 ? rc : 0;
         }
 
         /* Otherwise failover nids are additive */
        rc = record_start_log(env, mgs, &llh, logname);
-        if (!rc) {
+       if (rc)
+               return rc;
                 /* FIXME this should be a single journal transaction */
-               rc = record_marker(env, llh, fsdb, CM_START,
-                                   mti->mti_svname, "add failnid");
-               rc = mgs_write_log_failnids(env, mti, llh, cliname);
-               rc = record_marker(env, llh, fsdb, CM_END,
-                                   mti->mti_svname, "add failnid");
-               rc = record_end_log(env, &llh);
-        }
-
+       rc = record_marker(env, llh, fsdb, CM_START, mti->mti_svname,
+                          "add failnid");
+       if (rc)
+               goto out_end;
+       rc = mgs_write_log_failnids(env, mti, llh, cliname);
+       if (rc)
+               goto out_end;
+       rc = record_marker(env, llh, fsdb, CM_END,
+                          mti->mti_svname, "add failnid");
+out_end:
+       record_end_log(env, &llh);
         return rc;
 }
 
@@ -1992,18 +2181,25 @@ static int mgs_write_log_add_failnid(const struct lu_env *env,
 
         /* Create mdc/osc client name (e.g. lustre-OST0001-osc) */
         if (mti->mti_flags & LDD_F_SV_TYPE_MDT) {
-                name_create(&cliname, mti->mti_svname, "-mdc");
+               rc = name_create(&cliname, mti->mti_svname, "-mdc");
         } else if (mti->mti_flags & LDD_F_SV_TYPE_OST) {
-                name_create(&cliname, mti->mti_svname, "-osc");
+               rc = name_create(&cliname, mti->mti_svname, "-osc");
         } else {
                 RETURN(-EINVAL);
         }
-
+       if (rc)
+               RETURN(rc);
         /* Add failover nids to the client log */
-        name_create(&logname, mti->mti_fsname, "-client");
+       rc = name_create(&logname, mti->mti_fsname, "-client");
+       if (rc) {
+               name_destroy(&cliname);
+               RETURN(rc);
+       }
        rc = mgs_write_log_failnid_internal(env, mgs, fsdb,mti,logname,cliname);
         name_destroy(&logname);
         name_destroy(&cliname);
+       if (rc)
+               RETURN(rc);
 
         if (mti->mti_flags & LDD_F_SV_TYPE_OST) {
                 /* Add OST failover nids to the MDT logs as well */
@@ -2012,12 +2208,22 @@ static int mgs_write_log_add_failnid(const struct lu_env *env,
                 for (i = 0; i < INDEX_MAP_SIZE * 8; i++) {
                         if (!cfs_test_bit(i, fsdb->fsdb_mdt_index_map))
                                 continue;
-                        name_create_mdt(&logname, mti->mti_fsname, i);
-                        name_create_mdt_osc(&cliname, mti->mti_svname, fsdb, i);
-                       rc = mgs_write_log_failnid_internal(env, mgs, fsdb, mti,
-                                                            logname, cliname);
+                       rc = name_create_mdt(&logname, mti->mti_fsname, i);
+                       if (rc)
+                               RETURN(rc);
+                       rc = name_create_mdt_osc(&cliname, mti->mti_svname,
+                                                fsdb, i);
+                       if (rc) {
+                               name_destroy(&logname);
+                               RETURN(rc);
+                       }
+                       rc = mgs_write_log_failnid_internal(env, mgs, fsdb,
+                                                           mti, logname,
+                                                           cliname);
                         name_destroy(&cliname);
                         name_destroy(&logname);
+                       if (rc)
+                               RETURN(rc);
                 }
         }
 
@@ -2043,6 +2249,8 @@ static int mgs_wlp_lcfg(const struct lu_env *env,
             *tmp = 0;
         /* FIXME we should skip settings that are the same as old values */
        rc = mgs_modify(env, mgs, fsdb, mti, logname, tgtname, comment,CM_SKIP);
+       if (rc < 0)
+               return rc;
         del = mgs_param_empty(ptr);
 
         LCONSOLE_INFO("%sing parameter %s.%s in log %s\n", del ? "Disabl" : rc ?
@@ -2217,21 +2425,21 @@ static int mgs_srpc_set_param_disk(const struct lu_env *env,
 
        if (mgs_log_is_empty(env, mgs, logname)) {
                rc = record_start_log(env, mgs, &llh, logname);
-               record_end_log(env, &llh);
                 if (rc)
                         GOTO(out, rc);
+               record_end_log(env, &llh);
         }
 
         /* obsolete old one */
-       mgs_modify(env, mgs, fsdb, mti, logname, mti->mti_svname,
-                  comment, CM_SKIP);
-
+       rc = mgs_modify(env, mgs, fsdb, mti, logname, mti->mti_svname,
+                       comment, CM_SKIP);
+       if (rc < 0)
+               GOTO(out, rc);
         /* write the new one */
        rc = mgs_write_log_direct(env, mgs, fsdb, logname, lcfg,
                                   mti->mti_svname, comment);
-        if (rc)
-                CERROR("err %d writing log %s\n", rc, logname);
-
+       if (rc)
+               CERROR("err %d writing log %s\n", rc, logname);
 out:
         name_destroy(&logname);
 out_lcfg:
@@ -2615,7 +2823,9 @@ static int mgs_write_log_param(const struct lu_env *env,
                 LCONSOLE_WARN("Permanently %sactivating %s\n",
                               flag ? "de": "re", mti->mti_svname);
                 /* Modify clilov */
-                name_create(&logname, mti->mti_fsname, "-client");
+               rc = name_create(&logname, mti->mti_fsname, "-client");
+               if (rc)
+                       GOTO(end, rc);
                rc = mgs_modify(env, mgs, fsdb, mti, logname,
                                 mti->mti_svname, "add osc", flag);
                 name_destroy(&logname);
@@ -2626,9 +2836,11 @@ static int mgs_write_log_param(const struct lu_env *env,
                 for (i = 0; i < INDEX_MAP_SIZE * 8; i++) {
                         if (!cfs_test_bit(i, fsdb->fsdb_mdt_index_map))
                                 continue;
-                        name_create_mdt(&logname, mti->mti_fsname, i);
+                       rc = name_create_mdt(&logname, mti->mti_fsname, i);
+                       if (rc)
+                               GOTO(end, rc);
                        rc = mgs_modify(env, mgs, fsdb, mti, logname,
-                                        mti->mti_svname, "add osc", flag);
+                                       mti->mti_svname, "add osc", flag);
                         name_destroy(&logname);
                         if (rc)
                                 goto active_err;
@@ -2671,8 +2883,10 @@ static int mgs_write_log_param(const struct lu_env *env,
                if (mgs_log_is_empty(env, mgs, mti->mti_svname))
                         GOTO(end, rc = -ENODEV);
 
-                name_create_mdt_and_lov(&logname, &mdtlovname, fsdb,
-                                        mti->mti_stripe_index);
+               rc = name_create_mdt_and_lov(&logname, &mdtlovname, fsdb,
+                                            mti->mti_stripe_index);
+               if (rc)
+                       GOTO(end, rc);
                rc = mgs_wlp_lcfg(env, mgs, fsdb, mti, mti->mti_svname,
                                  &mgi->mgi_bufs, mdtlovname, ptr);
                 name_destroy(&logname);
@@ -2681,7 +2895,9 @@ static int mgs_write_log_param(const struct lu_env *env,
                         GOTO(end, rc);
 
                 /* Modify clilov */
-                name_create(&logname, mti->mti_fsname, "-client");
+               rc = name_create(&logname, mti->mti_fsname, "-client");
+               if (rc)
+                       GOTO(end, rc);
                rc = mgs_wlp_lcfg(env, mgs, fsdb, mti, logname, &mgi->mgi_bufs,
                                   fsdb->fsdb_clilov, ptr);
                 name_destroy(&logname);
@@ -2723,11 +2939,17 @@ static int mgs_write_log_param(const struct lu_env *env,
                 } else {
                         GOTO(end, rc = -EINVAL);
                 }
+               if (rc)
+                       GOTO(end, rc);
 
                 CDEBUG(D_MGS, "%.3s param %s\n", ptr, ptr + 4);
 
                 /* Modify client */
-                name_create(&logname, mti->mti_fsname, "-client");
+               rc = name_create(&logname, mti->mti_fsname, "-client");
+               if (rc) {
+                       name_destroy(&cname);
+                       GOTO(end, rc);
+               }
                rc = mgs_wlp_lcfg(env, mgs, fsdb, mti, logname, &mgi->mgi_bufs,
                                   cname, ptr);
 
@@ -2739,18 +2961,25 @@ static int mgs_write_log_param(const struct lu_env *env,
                                 if (!cfs_test_bit(i, fsdb->fsdb_mdt_index_map))
                                         continue;
                                 name_destroy(&cname);
-                                name_create_mdt_osc(&cname, mti->mti_svname,
-                                                    fsdb, i);
+                               rc = name_create_mdt_osc(&cname, mti->mti_svname,
+                                                        fsdb, i);
                                 name_destroy(&logname);
-                                name_create_mdt(&logname, mti->mti_fsname, i);
-                               if (!mgs_log_is_empty(env, mgs, logname))
-                                       rc = mgs_wlp_lcfg(env, mgs, fsdb, mti,
-                                                         logname, &mgi->mgi_bufs,
+                               if (rc)
+                                       break;
+                               rc = name_create_mdt(&logname,
+                                                    mti->mti_fsname, i);
+                               if (rc)
+                                       break;
+                               if (!mgs_log_is_empty(env, mgs, logname)) {
+                                       rc = mgs_wlp_lcfg(env, mgs, fsdb,
+                                                         mti, logname,
+                                                         &mgi->mgi_bufs,
                                                          cname, ptr);
-                                if (rc)
-                                        break;
-                        }
-                }
+                                       if (rc)
+                                               break;
+                               }
+                       }
+               }
                 name_destroy(&logname);
                 name_destroy(&cname);
                 GOTO(end, rc);
@@ -2777,7 +3006,10 @@ static int mgs_write_log_param(const struct lu_env *env,
                                 if (!cfs_test_bit(i,
                                                   fsdb->fsdb_mdt_index_map))
                                         continue;
-                                name_create_mdt(&logname, mti->mti_fsname, i);
+                               rc = name_create_mdt(&logname,
+                                               mti->mti_fsname, i);
+                               if (rc)
+                                       goto active_err;
                                rc = mgs_wlp_lcfg(env, mgs, fsdb, mti,
                                                  logname, &mgi->mgi_bufs,
                                                   logname, ptr);
@@ -3222,13 +3454,17 @@ static int mgs_write_log_pool(const struct lu_env *env,
         int rc;
 
        rc = record_start_log(env, mgs, &llh, logname);
-        if (rc)
-                return rc;
+       if (rc)
+               return rc;
        rc = record_marker(env, llh, fsdb, CM_START, lovname, comment);
-       record_base(env, llh, lovname, 0, cmd, poolname, fsname, ostname, 0);
+       if (rc)
+               goto out;
+       rc = record_base(env, llh, lovname, 0, cmd, poolname, fsname, ostname, 0);
+       if (rc)
+               goto out;
        rc = record_marker(env, llh, fsdb, CM_END, lovname, comment);
-       rc = record_end_log(env, &llh);
-
+out:
+       record_end_log(env, &llh);
         return rc;
 }
 
@@ -3271,7 +3507,7 @@ int mgs_pool_cmd(const struct lu_env *env, struct mgs_device *mgs,
 
         OBD_ALLOC(label, label_sz);
         if (label == NULL)
-                GOTO(out, rc = -ENOMEM);
+               RETURN(-ENOMEM);
 
         switch(cmd) {
        case LCFG_POOL_NEW:
@@ -3285,7 +3521,7 @@ int mgs_pool_cmd(const struct lu_env *env, struct mgs_device *mgs,
        case LCFG_POOL_REM:
                 OBD_ALLOC(canceled_label, label_sz);
                 if (canceled_label == NULL)
-                         GOTO(out, rc = -ENOMEM);
+                       GOTO(out_label, rc = -ENOMEM);
                 sprintf(label,
                         "rem %s.%s.%s", fsname, poolname, ostname);
                 sprintf(canceled_label,
@@ -3294,7 +3530,7 @@ int mgs_pool_cmd(const struct lu_env *env, struct mgs_device *mgs,
        case LCFG_POOL_DEL:
                 OBD_ALLOC(canceled_label, label_sz);
                 if (canceled_label == NULL)
-                         GOTO(out, rc = -ENOMEM);
+                       GOTO(out_label, rc = -ENOMEM);
                 sprintf(label,
                         "del %s.%s", fsname, poolname);
                 sprintf(canceled_label,
@@ -3309,53 +3545,70 @@ int mgs_pool_cmd(const struct lu_env *env, struct mgs_device *mgs,
         if (canceled_label != NULL) {
                 OBD_ALLOC_PTR(mti);
                 if (mti == NULL)
-                        GOTO(out, rc = -ENOMEM);
+                       GOTO(out_cancel, rc = -ENOMEM);
         }
 
         /* write pool def to all MDT logs */
         for (i = 0; i < INDEX_MAP_SIZE * 8; i++) {
                  if (cfs_test_bit(i,  fsdb->fsdb_mdt_index_map)) {
-                        name_create_mdt_and_lov(&logname, &lovname, fsdb, i);
-
+                       rc = name_create_mdt_and_lov(&logname, &lovname,
+                                                    fsdb, i);
+                       if (rc) {
+                               cfs_mutex_unlock(&fsdb->fsdb_mutex);
+                               GOTO(out_mti, rc);
+                       }
                         if (canceled_label != NULL) {
                                 strcpy(mti->mti_svname, "lov pool");
-                               mgs_modify(env, mgs, fsdb, mti, logname,
-                                          lovname, canceled_label,
-                                          CM_SKIP);
+                               rc = mgs_modify(env, mgs, fsdb, mti, logname,
+                                               lovname, canceled_label,
+                                               CM_SKIP);
                         }
 
-                       mgs_write_log_pool(env, mgs, logname, fsdb, lovname,
-                                           cmd, fsname, poolname, ostname,
-                                           label);
+                       if (rc >= 0)
+                               rc = mgs_write_log_pool(env, mgs, logname,
+                                                       fsdb, lovname, cmd,
+                                                       fsname, poolname,
+                                                       ostname, label);
                         name_destroy(&logname);
                         name_destroy(&lovname);
+                       if (rc) {
+                               cfs_mutex_unlock(&fsdb->fsdb_mutex);
+                               GOTO(out_mti, rc);
+                       }
                 }
         }
 
-        name_create(&logname, fsname, "-client");
-        if (canceled_label != NULL)
-               mgs_modify(env, mgs, fsdb, mti, logname, fsdb->fsdb_clilov,
-                           canceled_label, CM_SKIP);
-
-       mgs_write_log_pool(env, mgs, logname, fsdb, fsdb->fsdb_clilov,
-                           cmd, fsname, poolname, ostname, label);
-        name_destroy(&logname);
+       rc = name_create(&logname, fsname, "-client");
+       if (rc) {
+               cfs_mutex_unlock(&fsdb->fsdb_mutex);
+               GOTO(out_mti, rc);
+       }
+       if (canceled_label != NULL) {
+               rc = mgs_modify(env, mgs, fsdb, mti, logname,
+                               fsdb->fsdb_clilov, canceled_label, CM_SKIP);
+               if (rc < 0) {
+                       cfs_mutex_unlock(&fsdb->fsdb_mutex);
+                       name_destroy(&logname);
+                       GOTO(out_mti, rc);
+               }
+       }
 
+       rc = mgs_write_log_pool(env, mgs, logname, fsdb, fsdb->fsdb_clilov,
+                               cmd, fsname, poolname, ostname, label);
         cfs_mutex_unlock(&fsdb->fsdb_mutex);
+       name_destroy(&logname);
         /* request for update */
        mgs_revoke_lock(mgs, fsdb, CONFIG_T_CONFIG);
 
         EXIT;
-out:
-        if (label != NULL)
-                OBD_FREE(label, label_sz);
-
-        if (canceled_label != NULL)
-                OBD_FREE(canceled_label, label_sz);
-
+out_mti:
         if (mti != NULL)
                 OBD_FREE_PTR(mti);
-
+out_cancel:
+       if (canceled_label != NULL)
+               OBD_FREE(canceled_label, label_sz);
+out_label:
+       OBD_FREE(label, label_sz);
         return rc;
 }