Whamcloud - gitweb
- make HEAD from b_post_cmd3
[fs/lustre-release.git] / lustre / mgs / mgs_llog.c
index 0cb5b69..5e4db6a 100644 (file)
 #include <lustre_fsfilt.h>
 #include <lustre_disk.h>
 #include <lustre_param.h>
+#include <lustre_sec.h>
 #include "mgs_internal.h"
 
-/******************** Class functions *********************/
+/********************** Class functions ********************/
 
 /* Caller must list_del and OBD_FREE each dentry from the list */
 int class_dentry_readdir(struct obd_device *obd, struct dentry *dir,
-                         struct vfsmount *inmnt, 
-                         struct list_head *dentry_list){
+                                struct vfsmount *inmnt,
+                                struct list_head *dentry_list){
         /* see mds_cleanup_pending */
         struct lvfs_run_ctxt saved;
         struct file *file;
@@ -138,21 +139,21 @@ static int mgs_fsdb_handler(struct llog_handle *llh, struct llog_rec_hdr *rec,
 
         lcfg = (struct lustre_cfg *)cfg_buf;
 
-        CDEBUG(D_INFO, "cmd %x %s %s\n", lcfg->lcfg_command, 
+        CDEBUG(D_INFO, "cmd %x %s %s\n", lcfg->lcfg_command,
                lustre_cfg_string(lcfg, 0), lustre_cfg_string(lcfg, 1));
 
-        /* Figure out ost indicies */ 
+        /* Figure out ost indicies */
         /* lov_modify_tgts add 0:lov1  1:ost1_UUID  2(index):0  3(gen):1 */
         if (lcfg->lcfg_command == LCFG_LOV_ADD_OBD ||
             lcfg->lcfg_command == LCFG_LOV_DEL_OBD) {
                 index = simple_strtoul(lustre_cfg_string(lcfg, 2),
                                        NULL, 10);
                 CDEBUG(D_MGS, "OST index for %s is %u (%s)\n",
-                       lustre_cfg_string(lcfg, 1), index, 
+                       lustre_cfg_string(lcfg, 1), index,
                        lustre_cfg_string(lcfg, 2));
                 set_bit(index, fsdb->fsdb_ost_index_map);
         }
-        
+
         /* Figure out mdt indicies */
         /* attach   0:MDC_uml1_mdsA_MNT_client  1:mdc  2:1d834_MNT_client_03f */
         if ((lcfg->lcfg_command == LCFG_ATTACH) &&
@@ -219,6 +220,7 @@ static int mgs_fsdb_handler(struct llog_handle *llh, struct llog_rec_hdr *rec,
         RETURN(rc);
 }
 
+/* fsdb->fsdb_sem is already held  in mgs_find_or_make_fsdb*/
 static int mgs_get_fsdb_from_llog(struct obd_device *obd, struct fs_db *fsdb)
 {
         char *logname;
@@ -230,7 +232,7 @@ static int mgs_get_fsdb_from_llog(struct obd_device *obd, struct fs_db *fsdb)
         name_create(&logname, fsdb->fsdb_name, "-client");
         down(&fsdb->fsdb_sem);
         push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-        
+
         rc = llog_create(llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT),
                          &loghandle, NULL, logname);
         if (rc)
@@ -279,9 +281,9 @@ static struct fs_db *mgs_new_fsdb(struct obd_device *obd, char *fsname)
         struct fs_db *fsdb;
         int rc;
         ENTRY;
-        
+
         OBD_ALLOC_PTR(fsdb);
-        if (!fsdb) 
+        if (!fsdb)
                 RETURN(NULL);
 
         OBD_ALLOC(fsdb->fsdb_ost_index_map, INDEX_MAP_SIZE);
@@ -290,28 +292,37 @@ static struct fs_db *mgs_new_fsdb(struct obd_device *obd, char *fsname)
                 CERROR("No memory for index maps\n");
                 GOTO(err, 0);
         }
-        
+
         strncpy(fsdb->fsdb_name, fsname, sizeof(fsdb->fsdb_name));
         fsdb->fsdb_name[sizeof(fsdb->fsdb_name) - 1] = 0;
         rc = name_create(&fsdb->fsdb_mdtlov, fsname, "-mdtlov");
         if (rc) 
                 GOTO(err, rc);
+        rc = name_create(&fsdb->fsdb_mdtlmv, fsname, "-mdtlmv");
+        if (rc) 
+                GOTO(err, rc);
         rc = name_create(&fsdb->fsdb_clilov, fsname, "-clilov");
         if (rc) 
                 GOTO(err, rc);
 
+        rc = name_create(&fsdb->fsdb_clilmv, fsname, "-clilmv");
+        if (rc) 
+                GOTO(err, rc);
+
         sema_init(&fsdb->fsdb_sem, 1);
         list_add(&fsdb->fsdb_list, &mgs->mgs_fs_db_list);
         lproc_mgs_add_live(obd, fsdb);
 
         RETURN(fsdb);
 err:
-        if (fsdb->fsdb_ost_index_map) 
+        if (fsdb->fsdb_ost_index_map)
                 OBD_FREE(fsdb->fsdb_ost_index_map, INDEX_MAP_SIZE);
-        if (fsdb->fsdb_mdt_index_map) 
+        if (fsdb->fsdb_mdt_index_map)
                 OBD_FREE(fsdb->fsdb_mdt_index_map, INDEX_MAP_SIZE);
-        name_destroy(&fsdb->fsdb_clilov); 
+        name_destroy(&fsdb->fsdb_clilov);
+        name_destroy(&fsdb->fsdb_clilmv);
         name_destroy(&fsdb->fsdb_mdtlov); 
+        name_destroy(&fsdb->fsdb_mdtlmv); 
         OBD_FREE_PTR(fsdb);
         RETURN(NULL);
 }
@@ -325,7 +336,9 @@ static void mgs_free_fsdb(struct obd_device *obd, struct fs_db *fsdb)
         OBD_FREE(fsdb->fsdb_ost_index_map, INDEX_MAP_SIZE);
         OBD_FREE(fsdb->fsdb_mdt_index_map, INDEX_MAP_SIZE);
         name_destroy(&fsdb->fsdb_clilov); 
+        name_destroy(&fsdb->fsdb_clilmv); 
         name_destroy(&fsdb->fsdb_mdtlov); 
+        name_destroy(&fsdb->fsdb_mdtlmv); 
         name_destroy(&fsdb->fsdb_mdc); 
         OBD_FREE_PTR(fsdb);
 }
@@ -369,7 +382,7 @@ static int mgs_find_or_make_fsdb(struct obd_device *obd, char *name,
         CDEBUG(D_MGS, "Creating new db\n");
         fsdb = mgs_new_fsdb(obd, name);
         up(&mgs->mgs_sem);
-        if (!fsdb) 
+        if (!fsdb)
                 return -ENOMEM;
 
         /* populate the db from the client llog */
@@ -381,12 +394,12 @@ static int mgs_find_or_make_fsdb(struct obd_device *obd, char *name,
         }
 
         *dbh = fsdb;
-        
+
         return 0;
 }
 
 /* 1 = index in use
-   0 = index unused 
+   0 = index unused
    -1= empty client log */
 int mgs_check_index(struct obd_device *obd, struct mgs_target_info *mti)
 {
@@ -397,23 +410,23 @@ int mgs_check_index(struct obd_device *obd, struct mgs_target_info *mti)
 
         LASSERT(!(mti->mti_flags & LDD_F_NEED_INDEX));
 
-        rc = mgs_find_or_make_fsdb(obd, mti->mti_fsname, &fsdb); 
+        rc = mgs_find_or_make_fsdb(obd, mti->mti_fsname, &fsdb);
         if (rc) {
                 CERROR("Can't get db for %s\n", mti->mti_fsname);
                 RETURN(rc);
         }
 
-        if (fsdb->fsdb_flags & FSDB_LOG_EMPTY) 
+        if (fsdb->fsdb_flags & FSDB_LOG_EMPTY)
                 RETURN(-1);
 
-        if (mti->mti_flags & LDD_F_SV_TYPE_OST) 
+        if (mti->mti_flags & LDD_F_SV_TYPE_OST)
                 imap = fsdb->fsdb_ost_index_map;
-        else if (mti->mti_flags & LDD_F_SV_TYPE_MDT) 
+        else if (mti->mti_flags & LDD_F_SV_TYPE_MDT)
                 imap = fsdb->fsdb_mdt_index_map;
         else
                 RETURN(-EINVAL);
 
-        if (test_bit(mti->mti_stripe_index, imap)) 
+        if (test_bit(mti->mti_stripe_index, imap))
                 RETURN(1);
         RETURN(0);
 }
@@ -440,15 +453,15 @@ int mgs_set_index(struct obd_device *obd, struct mgs_target_info *mti)
         int rc = 0;
         ENTRY;
 
-        rc = mgs_find_or_make_fsdb(obd, mti->mti_fsname, &fsdb); 
+        rc = mgs_find_or_make_fsdb(obd, mti->mti_fsname, &fsdb);
         if (rc) {
                 CERROR("Can't get db for %s\n", mti->mti_fsname);
                 RETURN(rc);
         }
 
-        if (mti->mti_flags & LDD_F_SV_TYPE_OST) 
+        if (mti->mti_flags & LDD_F_SV_TYPE_OST)
                 imap = fsdb->fsdb_ost_index_map;
-        else if (mti->mti_flags & LDD_F_SV_TYPE_MDT) 
+        else if (mti->mti_flags & LDD_F_SV_TYPE_MDT)
                 imap = fsdb->fsdb_mdt_index_map;
         else
                 RETURN(-EINVAL);
@@ -460,27 +473,20 @@ int mgs_set_index(struct obd_device *obd, struct mgs_target_info *mti)
                 mti->mti_stripe_index = rc;
         }
 
-        /* Remove after CMD */
-        if ((mti->mti_flags & LDD_F_SV_TYPE_MDT) && 
-            (mti->mti_stripe_index > 0)) {
-                LCONSOLE_ERROR("MDT index must = 0 (until Clustered MetaData "
-                               "feature is ready.)\n");
-                mti->mti_stripe_index = 0;
-        }
-
         if (mti->mti_stripe_index >= INDEX_MAP_SIZE * 8) {
-                LCONSOLE_ERROR("Server %s requested index %d, but the"
-                               "max index is %d.\n", 
-                               mti->mti_svname, mti->mti_stripe_index,
-                               INDEX_MAP_SIZE * 8);
+                LCONSOLE_ERROR_MSG(0x13f, "Server %s requested index %d, "
+                                   "but the max index is %d.\n",
+                                   mti->mti_svname, mti->mti_stripe_index,
+                                   INDEX_MAP_SIZE * 8);
                 RETURN(-ERANGE);
         }
-         
+
         if (test_bit(mti->mti_stripe_index, imap)) {
                 if (mti->mti_flags & LDD_F_VIRGIN) {
-                        LCONSOLE_ERROR("Server %s requested index %d, but that "
-                                       "index is already in use\n",
-                                       mti->mti_svname, mti->mti_stripe_index);
+                        LCONSOLE_ERROR_MSG(0x140, "Server %s requested index "
+                                           "%d, but that index is already in "
+                                           "use\n", mti->mti_svname,
+                                           mti->mti_stripe_index);
                         RETURN(-EADDRINUSE);
                 } else {
                         CDEBUG(D_MGS, "Server %s updating index %d\n",
@@ -494,7 +500,7 @@ int mgs_set_index(struct obd_device *obd, struct mgs_target_info *mti)
         server_make_name(mti->mti_flags, mti->mti_stripe_index,
                          mti->mti_fsname, mti->mti_svname);
 
-        CDEBUG(D_MGS, "Set index for %s to %d\n", mti->mti_svname, 
+        CDEBUG(D_MGS, "Set index for %s to %d\n", mti->mti_svname,
                mti->mti_stripe_index);
 
         RETURN(0);
@@ -611,7 +617,6 @@ out_pop:
         RETURN(rc);
 }
 
-                           
 /******************** config log recording functions *********************/
 
 static int record_lcfg(struct obd_device *obd, struct llog_handle *llh,
@@ -630,6 +635,7 @@ static int record_lcfg(struct obd_device *obd, struct llog_handle *llh,
                                 lcfg->lcfg_buflens);
         rec.lrh_len = llog_data_len(buflen);
         rec.lrh_type = OBD_CFG_REC;
+
         push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
         /* idx = -1 means append */
         rc = llog_write_rec(llh, &rec, NULL, 0, (void *)lcfg, -1);
@@ -646,18 +652,18 @@ static int record_base(struct obd_device *obd, struct llog_handle *llh,
         struct lustre_cfg_bufs bufs;
         struct lustre_cfg     *lcfg;
         int rc;
-               
+
         CDEBUG(D_MGS, "lcfg %s %#x %s %s %s %s\n", cfgname,
-               cmd, s1, s2, s3, s4); 
+               cmd, s1, s2, s3, s4);
 
         lustre_cfg_bufs_reset(&bufs, cfgname);
-        if (s1) 
+        if (s1)
                 lustre_cfg_bufs_set_string(&bufs, 1, s1);
-        if (s2) 
+        if (s2)
                 lustre_cfg_bufs_set_string(&bufs, 2, s2);
-        if (s3) 
+        if (s3)
                 lustre_cfg_bufs_set_string(&bufs, 3, s3);
-        if (s4) 
+        if (s4)
                 lustre_cfg_bufs_set_string(&bufs, 4, s4);
 
         lcfg = lustre_cfg_new(cmd, &bufs);
@@ -666,26 +672,26 @@ static int record_base(struct obd_device *obd, struct llog_handle *llh,
         lcfg->lcfg_nid = nid;
 
         rc = record_lcfg(obd, llh, lcfg);
-        
+
         lustre_cfg_free(lcfg);
-        
+
         if (rc) {
                 CERROR("error %d: lcfg %s %#x %s %s %s %s\n", rc, cfgname,
-                       cmd, s1, s2, s3, s4); 
+                       cmd, s1, s2, s3, s4);
         }
         return(rc);
 }
 
 
-static inline int record_add_uuid(struct obd_device *obd, 
-                                  struct llog_handle *llh, 
+static inline int record_add_uuid(struct obd_device *obd,
+                                  struct llog_handle *llh,
                                   uint64_t nid, char *uuid)
 {
         return record_base(obd,llh,NULL,nid,LCFG_ADD_UUID,uuid,0,0,0);
 
 }
 
-static inline int record_add_conn(struct obd_device *obd, 
+static inline int record_add_conn(struct obd_device *obd,
                                   struct llog_handle *llh,
                                   char *devname,
                                   char *uuid)
@@ -700,12 +706,30 @@ static inline int record_attach(struct obd_device *obd, struct llog_handle *llh,
 }
 
 static inline int record_setup(struct obd_device *obd, struct llog_handle *llh,
-                               char *devname, 
+                               char *devname,
                                char *s1, char *s2, char *s3, char *s4)
 {
         return record_base(obd,llh,devname,0,LCFG_SETUP,s1,s2,s3,s4);
 }
 
+static inline int record_sec_flavor(struct obd_device *obd,
+                                    struct llog_handle *llh, char *devname,
+                                    struct sec_flavor_config *conf)
+{
+        struct lustre_cfg_bufs bufs;
+        struct lustre_cfg *lcfg;
+        int rc;
+
+        lustre_cfg_bufs_reset(&bufs, devname);
+        lustre_cfg_bufs_set(&bufs, 1, conf, sizeof(*conf));
+        lcfg = lustre_cfg_new(LCFG_SEC_FLAVOR, &bufs);
+
+        rc = record_lcfg(obd, llh, lcfg);
+
+        lustre_cfg_free(lcfg);
+        return rc;
+}
+
 static int record_lov_setup(struct obd_device *obd, struct llog_handle *llh,
                             char *devname, struct lov_desc *desc)
 {
@@ -724,6 +748,33 @@ static int record_lov_setup(struct obd_device *obd, struct llog_handle *llh,
         return rc;
 }
 
+static int record_lmv_setup(struct obd_device *obd, struct llog_handle *llh,
+                            char *devname, struct lmv_desc *desc)
+{
+        struct lustre_cfg_bufs bufs;
+        struct lustre_cfg *lcfg;
+        int rc;
+
+        lustre_cfg_bufs_reset(&bufs, devname);
+        lustre_cfg_bufs_set(&bufs, 1, desc, sizeof(*desc));
+        lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
+
+        rc = record_lcfg(obd, llh, lcfg);
+
+        lustre_cfg_free(lcfg);
+        return rc;
+}
+
+static inline int record_mdc_add(struct obd_device *obd,
+                                 struct llog_handle *llh,
+                                 char *logname, char *mdcuuid,
+                                 char *mdtuuid, char *index,
+                                 char *gen)
+{
+        return record_base(obd,llh,logname,0,LCFG_ADD_MDC,
+                           mdtuuid,index,gen,mdcuuid);
+}
+
 static inline int record_lov_add(struct obd_device *obd,
                                  struct llog_handle *llh,
                                  char *lov_name, char *ost_uuid,
@@ -731,16 +782,16 @@ static inline int record_lov_add(struct obd_device *obd,
 {
         return record_base(obd,llh,lov_name,0,LCFG_LOV_ADD_OBD,
                            ost_uuid,index,gen,0);
-}                                  
+}
 
-static inline int record_mount_opt(struct obd_device *obd, 
+static inline int record_mount_opt(struct obd_device *obd,
                                    struct llog_handle *llh,
                                    char *profile, char *lov_name,
                                    char *mdc_name)
 {
         return record_base(obd,llh,NULL,0,LCFG_MOUNTOPT,
                            profile,lov_name,mdc_name,0);
-}                
+}
 
 static int record_marker(struct obd_device *obd, struct llog_handle *llh,
                          struct fs_db *fsdb, __u32 flags,
@@ -751,7 +802,7 @@ static int record_marker(struct obd_device *obd, struct llog_handle *llh,
         struct lustre_cfg *lcfg;
         int rc;
 
-        if (flags & CM_START) 
+        if (flags & CM_START)
                 fsdb->fsdb_gen++;
         marker.cm_step = fsdb->fsdb_gen;
         marker.cm_flags = flags;
@@ -771,13 +822,13 @@ static int record_marker(struct obd_device *obd, struct llog_handle *llh,
         return rc;
 }
 
-static int record_start_log(struct obd_device *obd, 
+static int record_start_log(struct obd_device *obd,
                             struct llog_handle **llh, char *name)
 {
         static struct obd_uuid cfg_uuid = { .uuid = "config_uuid" };
         struct lvfs_run_ctxt saved;
         int rc = 0;
-        
+
         if (*llh) {
                 GOTO(out, rc = -EBUSY);
         }
@@ -806,10 +857,10 @@ static int record_end_log(struct obd_device *obd, struct llog_handle **llh)
         int rc = 0;
 
         push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-        
+
         rc = llog_close(*llh);
         *llh = NULL;
-        
+
         pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
         RETURN(rc);
 }
@@ -850,15 +901,15 @@ static int mgs_write_log_direct(struct obd_device *obd, struct fs_db *fsdb,
         rc = record_start_log(obd, &llh, logname);
         if (rc) 
                 RETURN(rc);
-        
+
         /* FIXME These should be a single journal transaction */
         rc = record_marker(obd, llh, fsdb, CM_START, devname, comment); 
         
         rc = record_lcfg(obd, llh, lcfg);
 
-        rc = record_marker(obd, llh, fsdb, CM_END, devname, comment); 
+        rc = record_marker(obd, llh, fsdb, CM_END, devname, comment);
         rc = record_end_log(obd, &llh);
-        
+
         RETURN(rc);
 }
 
@@ -897,7 +948,7 @@ int mgs_write_log_direct_all(struct obd_device *obd, struct fs_db *fsdb,
                 CERROR("Can't read %s dir\n", MOUNT_CONFIGS_DIR);
                 RETURN(rc);
         }
-                                                                                
+
         /* Could use fsdb index maps instead of directory listing */
         list_for_each_entry_safe(dirent, n, &dentry_list, lld_list) {
                 list_del(&dirent->lld_list);
@@ -915,12 +966,228 @@ int mgs_write_log_direct_all(struct obd_device *obd, struct fs_db *fsdb,
                 }
                 OBD_FREE(dirent, sizeof(*dirent));
         }
+
+        RETURN(rc);
+}
+
+struct temp_comp
+{
+        struct mgs_target_info   *comp_tmti;
+        struct mgs_target_info   *comp_mti;
+        struct fs_db             *comp_fsdb;
+        struct obd_device        *comp_obd;
+        struct sec_flavor_config  comp_sec;
+};
+
+static int mgs_write_log_mdc_to_mdt(struct obd_device *, struct fs_db *,
+                                    struct mgs_target_info *,
+                                    struct sec_flavor_config *, char *);
+
+static int mgs_steal_llog_handler(struct llog_handle *llh,
+                                  struct llog_rec_hdr *rec,
+                                  void *data)
+{
+        struct obd_device * obd;
+        struct mgs_target_info *mti, *tmti;
+        struct fs_db *fsdb;
+        int cfg_len = rec->lrh_len;
+        char *cfg_buf = (char*) (rec + 1);
+        struct lustre_cfg *lcfg;
+        struct sec_flavor_config *sec_conf;
+        int rc = 0;
+        struct llog_handle *mdt_llh = NULL;
+        static int got_an_osc_or_mdc = 0;
+        /* 0: not found any osc/mdc;
+           1: found osc;
+           2: found mdc;
+        */
+        static int last_step = -1;
+
+        ENTRY;
+
+        mti = ((struct temp_comp*)data)->comp_mti;
+        tmti = ((struct temp_comp*)data)->comp_tmti;
+        fsdb = ((struct temp_comp*)data)->comp_fsdb;
+        obd = ((struct temp_comp*)data)->comp_obd;
+        sec_conf = &((struct temp_comp*)data)->comp_sec;
+
+        if (rec->lrh_type != OBD_CFG_REC) {
+                CERROR("unhandled lrh_type: %#x\n", rec->lrh_type);
+                RETURN(-EINVAL);
+        }
+
+        rc = lustre_cfg_sanity_check(cfg_buf, cfg_len);
+        if (rc) {
+                CERROR("Insane cfg\n");
+                RETURN(rc);
+        }
+
+        lcfg = (struct lustre_cfg *)cfg_buf;
+
+        if (lcfg->lcfg_command == LCFG_MARKER) {
+                struct cfg_marker *marker;
+                marker = lustre_cfg_buf(lcfg, 1);
+                if (!strncmp(marker->cm_comment,"add osc",7) &&
+                    (marker->cm_flags & CM_START)){
+                        got_an_osc_or_mdc = 1;
+                        rc = record_start_log(obd, &mdt_llh, mti->mti_svname);
+                        rc = record_marker(obd, mdt_llh, fsdb, CM_START,
+                                           mti->mti_svname,"add osc(copied)");
+                        rc = record_end_log(obd, &mdt_llh);
+                        last_step = marker->cm_step;
+                        RETURN(rc);
+                }
+                if (!strncmp(marker->cm_comment,"add osc",7) &&
+                    (marker->cm_flags & CM_END)){
+                        LASSERT(last_step == marker->cm_step);
+                        last_step = -1;
+                        got_an_osc_or_mdc = 0;
+                        rc = record_start_log(obd, &mdt_llh, mti->mti_svname);
+                        rc = record_marker(obd, mdt_llh, fsdb, CM_END,
+                                           mti->mti_svname,"add osc(copied)");
+                        rc = record_end_log(obd, &mdt_llh);
+                        RETURN(rc);
+                }
+                if (!strncmp(marker->cm_comment,"add mdc",7) &&
+                    (marker->cm_flags & CM_START)){
+                        got_an_osc_or_mdc = 2;
+                        last_step = marker->cm_step;
+                        memcpy(tmti->mti_svname, marker->cm_tgtname,
+                               strlen(marker->cm_tgtname));
+
+                        RETURN(rc);
+                }
+                if (!strncmp(marker->cm_comment,"add mdc",7) &&
+                    (marker->cm_flags & CM_END)){
+                        LASSERT(last_step == marker->cm_step);
+                        last_step = -1;
+                        got_an_osc_or_mdc = 0;
+                        RETURN(rc);
+                }
+        }
+
+        if (got_an_osc_or_mdc == 0 || last_step < 0)
+                RETURN(rc);
         
+        if (lcfg->lcfg_command == LCFG_ADD_UUID) {
+                uint64_t nodenid;
+                nodenid = lcfg->lcfg_nid;
+                
+                tmti->mti_nids[tmti->mti_nid_count] = nodenid;
+                tmti->mti_nid_count++;
+
+                RETURN(rc);
+        }
+
+        if (lcfg->lcfg_command == LCFG_SETUP) {
+                char *target;
+
+                target = lustre_cfg_string(lcfg, 1);
+                memcpy(tmti->mti_uuid, target, strlen(target));
+                RETURN(rc);
+        }
+
+        if (lcfg->lcfg_command == LCFG_SEC_FLAVOR) {
+                memcpy(sec_conf, lustre_cfg_buf(lcfg, 1), sizeof(*sec_conf));
+                RETURN(rc);
+        }
+
+        if (lcfg->lcfg_command == LCFG_ADD_MDC) {
+                int index;
+
+                if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1)
+                        RETURN (-EINVAL);
+
+                memcpy(tmti->mti_fsname, mti->mti_fsname,
+                       strlen(mti->mti_fsname));
+                tmti->mti_stripe_index = index;
+
+                mgs_write_log_mdc_to_mdt(obd, fsdb, tmti, sec_conf,
+                                         mti->mti_svname);
+                memset(tmti, 0, sizeof(*tmti));
+                RETURN(rc);
+        }
         RETURN(rc);
 }
 
+/* fsdb->fsdb_sem is already held  in mgs_write_log_target*/
+/* stealed from mgs_get_fsdb_from_llog*/
+static int mgs_steal_llog_for_mdt_from_client(struct obd_device *obd,
+                                              char *client_name,
+                                              struct temp_comp* comp)
+{
+        struct llog_handle *loghandle;
+        struct lvfs_run_ctxt saved;
+        struct mgs_target_info *tmti;
+        int rc, rc2;
+        ENTRY;
+
+        OBD_ALLOC_PTR(tmti);
+        if (tmti == NULL)
+                RETURN(-ENOMEM);
+
+        comp->comp_tmti = tmti;
+        comp->comp_obd = obd;
+
+        push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+
+        rc = llog_create(llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT),
+                         &loghandle, NULL, client_name);
+        if (rc)
+                GOTO(out_pop, rc);
+
+        rc = llog_init_handle(loghandle, LLOG_F_IS_PLAIN, NULL);
+        if (rc)
+                GOTO(out_close, rc);
+
+        rc = llog_process(loghandle, mgs_steal_llog_handler, (void *)comp, NULL);
+        CDEBUG(D_MGS, "steal llog re = %d\n", rc);
+out_close:
+        rc2 = llog_close(loghandle);
+        if (!rc)
+                rc = rc2;
+out_pop:
+        pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+        OBD_FREE_PTR(tmti);
+        RETURN(rc);
+}
+
+/* lmv is the second thing for client logs */
+/* copied from mgs_write_log_lov. Please refer to that.  */
+static int mgs_write_log_lmv(struct obd_device *obd, struct fs_db *fsdb,
+                             struct mgs_target_info *mti,
+                             char *logname, char *lmvname)
+{
+        struct llog_handle *llh = NULL;
+        struct lmv_desc *lmvdesc;
+        char *uuid;
+        int rc = 0;
+        ENTRY;
+
+        CDEBUG(D_MGS, "Writing lmv(%s) log for %s\n", lmvname,logname);
+
+        OBD_ALLOC(lmvdesc, sizeof(*lmvdesc));
+        if (lmvdesc == NULL)
+                RETURN(-ENOMEM);
+        lmvdesc->ld_active_tgt_count = 0;
+        lmvdesc->ld_tgt_count = 0;
+        sprintf((char*)lmvdesc->ld_uuid.uuid, "%s_UUID", lmvname);
+        uuid = (char *)lmvdesc->ld_uuid.uuid;
+
+        rc = record_start_log(obd, &llh, logname);
+        rc = record_marker(obd, llh, fsdb, CM_START, lmvname, "lmv setup");
+        rc = record_attach(obd, llh, lmvname, "lmv", uuid);
+        rc = record_lmv_setup(obd, llh, lmvname, lmvdesc);
+        rc = record_marker(obd, llh, fsdb, CM_END, lmvname, "lmv setup");
+        rc = record_end_log(obd, &llh);
+
+        OBD_FREE(lmvdesc, sizeof(*lmvdesc));
+        RETURN(rc);
+}
+/***************************************END PROTO**********************/
+
 /* lov is the first thing in the mdt and client logs */
-static int mgs_write_log_lov(struct obd_device *obd, struct fs_db *fsdb, 
+static int mgs_write_log_lov(struct obd_device *obd, struct fs_db *fsdb,
                              struct mgs_target_info *mti,
                              char *logname, char *lovname)
 {
@@ -930,7 +1197,7 @@ static int mgs_write_log_lov(struct obd_device *obd, struct fs_db *fsdb,
         int rc = 0;
         ENTRY;
 
-        CDEBUG(D_MGS, "Writing log %s\n", logname);
+        CDEBUG(D_MGS, "Writing lov(%s) log for %s\n", lovname, logname);
 
         /*
         #01 L attach   0:lov_mdsA  1:lov  2:71ccb_lov_mdsA_19f961a9e1
@@ -944,7 +1211,7 @@ static int mgs_write_log_lov(struct obd_device *obd, struct fs_db *fsdb,
                 RETURN(-ENOMEM);
         lovdesc->ld_magic = LOV_DESC_MAGIC;
         lovdesc->ld_tgt_count = 0;
-        /* Defaults.  Can be changed later by lcfg config_param */ 
+        /* Defaults.  Can be changed later by lcfg config_param */
         lovdesc->ld_default_stripe_count = 1;
         lovdesc->ld_pattern = LOV_PATTERN_RAID0;
         lovdesc->ld_default_stripe_size = 1024 * 1024;
@@ -963,7 +1230,7 @@ static int mgs_write_log_lov(struct obd_device *obd, struct fs_db *fsdb,
         rc = record_marker(obd, llh, fsdb, CM_START, lovname, "lov setup"); 
         rc = record_attach(obd, llh, lovname, "lov", uuid);
         rc = record_lov_setup(obd, llh, lovname, lovdesc);
-        rc = record_marker(obd, llh, fsdb, CM_END, lovname, "lov setup"); 
+        rc = record_marker(obd, llh, fsdb, CM_END, lovname, "lov setup");
         rc = record_end_log(obd, &llh);
 out:        
         OBD_FREE(lovdesc, sizeof(*lovdesc));
@@ -994,7 +1261,7 @@ static int mgs_write_log_failnids(struct obd_device *obd,
         while (class_find_param(ptr, PARAM_FAILNODE, &ptr) == 0) {
                 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
                         if (failnodeuuid == NULL) {
-                                /* We don't know the failover node name, 
+                                /* We don't know the failover node name,
                                    so just use the first nid as the uuid */
                                 rc = name_create(&failnodeuuid,
                                                  libcfs_nid2str(nid), "");
@@ -1016,67 +1283,242 @@ static int mgs_write_log_failnids(struct obd_device *obd,
         return rc;
 }
 
+static
+void extract_sec_flavor(char *params, char *key, char **ptr)
+{
+        char *val = NULL, *tail;
+        int   len;
+
+        *ptr = NULL;
+
+        if (class_find_param(params, key, &val))
+                return;
+
+        tail = strchr(val, ' ');
+        if (tail == NULL)
+                len = strlen(val);
+        else
+                len = tail - val;
+
+        OBD_ALLOC(*ptr, len + 1);
+        if (*ptr == NULL)
+                return;
+
+        memcpy(*ptr, val, len);
+        (*ptr)[len] = '\0';
+}
+
+static int mgs_write_log_mdc_to_lmv(struct obd_device *obd, struct fs_db *fsdb,
+                                    struct mgs_target_info *mti,
+                                    struct sec_flavor_config *sec_conf,
+                                    char *logname, char *lmvname)
+{
+        struct llog_handle *llh = NULL;
+        char *mdcname, *nodeuuid, *mdcuuid, *lmvuuid;
+        char index[5];
+        int i, rc;
+        ENTRY;
+        
+        if (mgs_log_is_empty(obd, logname)) {
+                CERROR("log is empty! Logical error\n");
+                RETURN(-EINVAL);
+        }
+
+        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 = record_start_log(obd, &llh, logname);
+        rc = record_marker(obd, llh, fsdb, CM_START, mti->mti_svname,
+                           "add mdc");
+
+        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(obd, llh, mti->mti_nids[i], nodeuuid);
+        }
+
+        rc = record_attach(obd, llh, mdcname, LUSTRE_MDC_NAME, lmvuuid);
+        rc = record_setup(obd, llh, mdcname, mti->mti_uuid, nodeuuid, 0, 0);
+        rc = record_sec_flavor(obd, llh, mdcname, sec_conf);
+        rc = mgs_write_log_failnids(obd, mti, llh, mdcname);
+        snprintf(index, sizeof(index), "%d", mti->mti_stripe_index);
+        rc = record_mdc_add(obd, llh, lmvname, mdcuuid, mti->mti_uuid,
+                            index, "1");
+        rc = record_marker(obd, llh, fsdb, CM_END, mti->mti_svname,
+                           "add mdc"); 
+        rc = record_end_log(obd, &llh);
+
+        name_destroy(&lmvuuid);
+        name_destroy(&mdcuuid);
+        name_destroy(&mdcname);
+        name_destroy(&nodeuuid);
+        RETURN(rc);
+}
+
+/* add new mdc to already existent MDS */
+static int mgs_write_log_mdc_to_mdt(struct obd_device *obd, struct fs_db *fsdb,
+                                    struct mgs_target_info *mti,
+                                    struct sec_flavor_config *sec_conf,
+                                    char *logname)
+{
+        struct llog_handle *llh = NULL;
+        char *nodeuuid, *mdcname, *mdcuuid, *mdtuuid;
+        int idx = mti->mti_stripe_index;
+        char index[9];
+        int i, rc;
+
+        ENTRY;
+        if (mgs_log_is_empty(obd, mti->mti_svname)) {
+                CERROR("log is empty! Logical error\n");
+                RETURN (-EINVAL);
+        }
+
+        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 = record_start_log(obd, &llh, logname);
+        rc = record_marker(obd, llh, fsdb, CM_START, mti->mti_svname, "add mdc");
+        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(obd, llh, mti->mti_nids[i], nodeuuid);
+        }
+        rc = record_attach(obd, llh, mdcname, LUSTRE_MDC_NAME, mdcuuid);
+        rc = record_setup(obd, llh, mdcname, mti->mti_uuid, nodeuuid, 0, 0);
+        rc = record_sec_flavor(obd, llh, mdcname, sec_conf);
+        rc = mgs_write_log_failnids(obd, mti, llh, mdcname);
+        snprintf(index, sizeof(index), "%d", idx);
+
+        rc = record_mdc_add(obd, llh, logname, mdcuuid, mti->mti_uuid,
+                            index, "1");
+        rc = record_marker(obd, llh, fsdb, CM_END, mti->mti_svname, "add mdc"); 
+        rc = record_end_log(obd, &llh);
+
+        name_destroy(&mdcuuid);
+        name_destroy(&mdcname);
+        name_destroy(&nodeuuid);
+        name_destroy(&mdtuuid);
+        RETURN(rc);
+}
+
+static int mgs_write_log_mdt0(struct obd_device *obd, struct fs_db *fsdb,
+                              struct mgs_target_info *mti)
+{
+        char *log = mti->mti_svname;
+        struct llog_handle *llh = NULL;
+        char *uuid, *lovname;
+        char mdt_index[5];
+        char *ptr = mti->mti_params;
+        int rc = 0, failout = 0;
+        ENTRY;
+
+        OBD_ALLOC(uuid, sizeof(struct obd_uuid));
+        if (uuid == NULL)
+                RETURN(-ENOMEM);
+
+        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(obd, log))
+                rc = mgs_write_log_lov(obd, fsdb, mti, log, lovname);
+
+        sprintf(uuid, "%s_UUID", log);
+        sprintf(mdt_index,"%d",mti->mti_stripe_index);        
+
+        /* add MDT itself */
+        rc = record_start_log(obd, &llh, log);
+        if (rc) 
+                GOTO(out, rc);
+        
+        /* FIXME this whole fn should be a single journal transaction */
+        rc = record_marker(obd, llh, fsdb, CM_START, log, "add mdt");
+        rc = record_attach(obd, llh, log, LUSTRE_MDT_NAME, uuid);
+        rc = record_mount_opt(obd, llh, log, lovname, NULL);
+        rc = record_setup(obd, llh, log, uuid, mdt_index, lovname, 
+                        failout ? "n" : "f");
+        rc = record_marker(obd, llh, fsdb, CM_END, log, "add mdt");
+        rc = record_end_log(obd, &llh);
+out:
+        name_destroy(&lovname);
+        OBD_FREE(uuid, sizeof(struct obd_uuid));
+        RETURN(rc);
+}
+
+/* envelope method for all layers log */
 static int mgs_write_log_mdt(struct obd_device *obd, struct fs_db *fsdb,
-                             struct mgs_target_info *mti)
+                              struct mgs_target_info *mti)
 {
+        char *cliname, *sec;
         struct llog_handle *llh = NULL;
-        char *cliname, *mdcname, *nodeuuid, *mdcuuid;
-        int rc, i, first_log = 0;
+        struct temp_comp comp = { 0 };
+        struct sec_flavor_config sec_conf_mdt, sec_conf_cli;
+        char mdt_index[9];
+        int rc, i = 0;
         ENTRY;
 
         CDEBUG(D_MGS, "writing new mdt %s\n", mti->mti_svname);
-        
+
+#if 0
+        /* COMPAT_146 */
+        if (mti->mti_flags & LDD_F_UPGRADE14) {
+                /* We're starting with an old uuid.  Assume old name for lov
+                   as well since the lov entry already exists in the log. */
+                CDEBUG(D_MGS, "old mds uuid %s\n", mti->mti_uuid);
+                if (strncmp(mti->mti_uuid, fsdb->fsdb_mdtlov + 4, 
+                            strlen(fsdb->fsdb_mdtlov) - 4) != 0) {
+                        CERROR("old mds uuid %s doesn't match log %s (%s)\n",
+                               mti->mti_uuid, fsdb->fsdb_mdtlov, 
+                               fsdb->fsdb_mdtlov + 4);
+                        RETURN(-EINVAL);
+                }
+        }
+        /* end COMPAT_146 */
+#endif
         if (mti->mti_uuid[0] == '\0') {
                 /* Make up our own uuid */
                 snprintf(mti->mti_uuid, sizeof(mti->mti_uuid),
                          "%s_UUID", mti->mti_svname);
         }
 
-        /* Append mdt info to mdt log */
-        if (mgs_log_is_empty(obd, mti->mti_svname)) {
-                /* This is the first time for all logs for this fs, 
-                   since any ost should have already started the mdt log. */
-                first_log++;
-                rc = mgs_write_log_lov(obd, fsdb, mti, mti->mti_svname,
-                                       fsdb->fsdb_mdtlov);
-        } 
-        /* else there's already some ost entries in the mdt log. */
+        /* security flavor */
+        extract_sec_flavor(mti->mti_params, PARAM_SEC_RPC_MDT, &sec);
+        rc = sptlrpc_parse_flavor(LUSTRE_MDT, LUSTRE_MDT, sec, &sec_conf_mdt);
+        name_destroy(&sec);
+        if (rc)
+                RETURN(rc);
 
-        /* We added the lov, maybe some osc's, now for the mdt.
-           We might add more ost's after this. Note that during the parsing
-           of this log, this is when the mdt will start. (This was not 
-           formerly part of the old mds log, it was directly executed by
-           lconf.) */ 
-        /*
-        mount_option 0:  1:mdsA  2:lov_mdsA
-        attach mds mdsA mdsA_UUID
-        setup /dev/loop2 ldiskfs mdsA errors=remount-ro,user_xattr
-        */
-        rc = record_start_log(obd, &llh, mti->mti_svname);
-        if (rc) 
+        extract_sec_flavor(mti->mti_params, PARAM_SEC_RPC_CLI, &sec);
+        rc = sptlrpc_parse_flavor(LUSTRE_CLI, LUSTRE_MDT, sec, &sec_conf_cli);
+        name_destroy(&sec);
+        if (rc)
                 RETURN(rc);
-        /* FIXME this whole fn should be a single journal transaction */
-        rc = record_marker(obd, llh, fsdb, CM_START, mti->mti_svname,"add mdt"); 
-        rc = record_mount_opt(obd, llh, mti->mti_svname, fsdb->fsdb_mdtlov, 0);
-        rc = record_attach(obd, llh, mti->mti_svname, LUSTRE_MDS_NAME, 
-                           mti->mti_uuid);
-        rc = record_setup(obd, llh, mti->mti_svname,
-                          "dev"/*ignored*/, "type"/*ignored*/,
-                          mti->mti_svname, 0/*options*/);
-        rc = record_marker(obd, llh, fsdb, CM_END, mti->mti_svname, "add mdt"); 
-        rc = record_end_log(obd, &llh);
 
+        /* add mdt */
+        rc = mgs_write_log_mdt0(obd, fsdb, mti);
+        
         /* Append the mdt info to the client log */
         name_create(&cliname, mti->mti_fsname, "-client");
-        if (first_log) { 
+        
+        if (mgs_log_is_empty(obd, cliname)) { 
                 /* Start client log */
-                rc = mgs_write_log_lov(obd, fsdb, mti, cliname,
+                rc = mgs_write_log_lov(obd, fsdb, mti, cliname, 
                                        fsdb->fsdb_clilov);
+                rc = mgs_write_log_lmv(obd, fsdb, mti, cliname, 
+                                       fsdb->fsdb_clilmv);
         }
 
-        name_create(&nodeuuid, libcfs_nid2str(mti->mti_nids[0]),/*"_UUID"*/"");
-        name_create(&mdcname, mti->mti_svname, "-mdc");
-        name_create(&mdcuuid, mdcname, "_UUID");
         /* 
         #09 L add_uuid nid=uml1@tcp(0x20000c0a80201) 0:  1:uml1_UUID
         #10 L attach   0:MDC_uml1_mdsA_MNT_client  1:mdc  2:1d834_MNT_client_03f
@@ -1085,12 +1527,17 @@ static int mgs_write_log_mdt(struct obd_device *obd, struct fs_db *fsdb,
         #13 L add_conn 0:MDC_uml1_mdsA_MNT_client  1:uml2_UUID
         #14 L mount_option 0:  1:client  2:lov1  3:MDC_uml1_mdsA_MNT_client
         */
-        rc = record_start_log(obd, &llh, cliname);
-        if (rc) 
-                GOTO(out, rc);
-        rc = record_marker(obd, llh, fsdb, CM_START, mti->mti_svname,"add mdc");
+        
+#if 0
         /* COMPAT_146 */
-        if (fsdb->fsdb_flags & FSDB_OLDLOG14) {
+        if (mti->mti_flags & LDD_F_UPGRADE14) { 
+                rc = record_start_log(obd, &llh, cliname);
+                if (rc) 
+                        GOTO(out, rc);
+        
+                rc = record_marker(obd, llh, fsdb, CM_START, 
+                                   mti->mti_svname,"add mdc");
+                                   
                 /* Old client log already has MDC entry, but needs mount opt 
                    for new client name (lustre-client) */
                 /* FIXME Old MDT log already has an old mount opt 
@@ -1098,55 +1545,81 @@ static int mgs_write_log_mdt(struct obd_device *obd, struct fs_db *fsdb,
                    class_del_profiles()) */
                 rc = record_mount_opt(obd, llh, cliname, fsdb->fsdb_clilov,
                                       fsdb->fsdb_mdc);
-                /* Only add failnids with --writeconf 
-                rc = mgs_write_log_failnids(obd, mti, llh, fsdb->fsdb_mdc);
-                */
                 /* end COMPAT_146 */
-        } else {
-                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(obd, llh, mti->mti_nids[i],
-                                             nodeuuid);
-                }
-                rc = record_attach(obd, llh, mdcname, LUSTRE_MDC_NAME, mdcuuid);
-                rc = record_setup(obd, llh, mdcname, mti->mti_uuid,nodeuuid,
-                                  0, 0);
-                rc = mgs_write_log_failnids(obd, mti, llh, mdcname);
+                
+                rc = record_marker(obd, llh, fsdb, CM_END, 
+                                   mti->mti_svname, "add mdc");
+        } else
+#endif
+        {
+                /* copy client info about lov/lmv */
+                comp.comp_mti = mti;
+                comp.comp_fsdb = fsdb;
+                
+                rc = mgs_steal_llog_for_mdt_from_client(obd, cliname, 
+                                                        &comp);
+
+                rc = mgs_write_log_mdc_to_lmv(obd, fsdb, mti, &sec_conf_cli,
+                                              cliname, fsdb->fsdb_clilmv);
+                /* add mountopts */
+                rc = record_start_log(obd, &llh, cliname);
+                if (rc) 
+                        GOTO(out, rc);
+
+                rc = record_marker(obd, llh, fsdb, CM_START, cliname, 
+                                   "mount opts");
                 rc = record_mount_opt(obd, llh, cliname, fsdb->fsdb_clilov,
-                                      mdcname);
+                                      fsdb->fsdb_clilmv);
+                rc = record_marker(obd, llh, fsdb, CM_END, cliname, 
+                                   "mount opts"); 
         }
-        rc = record_marker(obd, llh, fsdb, CM_END, mti->mti_svname, "add mdc"); 
+                           
         rc = record_end_log(obd, &llh);
 out:
-        name_destroy(&mdcuuid);
-        name_destroy(&mdcname);
-        name_destroy(&nodeuuid);
         name_destroy(&cliname);
+        
+        // for_all_existing_mdt except current one
+        for (i = 0; i < INDEX_MAP_SIZE * 8; i++){
+                char *mdtname;
+                if (i !=  mti->mti_stripe_index &&
+                    test_bit(i,  fsdb->fsdb_mdt_index_map)) {
+                        sprintf(mdt_index,"-MDT%04x",i);
+                        
+                        name_create(&mdtname, mti->mti_fsname, mdt_index);
+                        rc = mgs_write_log_mdc_to_mdt(obd, fsdb, mti,
+                                                      &sec_conf_mdt, mdtname);
+                        name_destroy(&mdtname);
+                }
+        }
+        
         RETURN(rc);
 }
 
 /* Add the ost info to the client/mdt lov */
-static int mgs_write_log_osc(struct obd_device *obd, struct fs_db *fsdb,
-                             struct mgs_target_info *mti,
-                             char *logname, char *lovname, int flags)
+static int mgs_write_log_osc_to_lov(struct obd_device *obd, struct fs_db *fsdb,
+                                    struct mgs_target_info *mti,
+                                    char *logname, char *suffix, char *lovname,
+                                    struct sec_flavor_config *sec_conf,
+                                    int flags)
 {
         struct llog_handle *llh = NULL;
-        char *nodeuuid, *oscname, *oscuuid, *lovuuid;
+        char *nodeuuid, *oscname, *oscuuid, *lovuuid, *svname;
         char index[5];
         int i, rc;
 
+        ENTRY;
+        CDEBUG(D_INFO, "adding osc for %s to log %s\n",
+               mti->mti_svname, logname);
+        
         if (mgs_log_is_empty(obd, logname)) {
                 /* The first item in the log must be the lov, so we have
                    somewhere to add our osc. */
                 rc = mgs_write_log_lov(obd, fsdb, mti, logname, lovname);
         }
   
-        CDEBUG(D_MGS, "adding osc for %s to log %s\n",
-               mti->mti_svname, logname);
-
         name_create(&nodeuuid, libcfs_nid2str(mti->mti_nids[0]), "");
-        name_create(&oscname, mti->mti_svname, "-osc");
+        name_create(&svname, mti->mti_svname, "-osc");
+        name_create(&oscname, svname, suffix);
         name_create(&oscuuid, oscname, "_UUID");
         name_create(&lovuuid, lovname, "_UUID");
 
@@ -1161,6 +1634,7 @@ static int mgs_write_log_osc(struct obd_device *obd, struct fs_db *fsdb,
         #07 L add_conn 0:OSC_uml1_ost1_MNT_client  1:uml2_UUID
         #08 L lov_modify_tgts add 0:lov1  1:ost1_UUID  2(index):0  3(gen):1
         */
+        
         rc = record_start_log(obd, &llh, logname);
         if (rc) 
                 GOTO(out, rc);
@@ -1173,6 +1647,7 @@ static int mgs_write_log_osc(struct obd_device *obd, struct fs_db *fsdb,
         }
         rc = record_attach(obd, llh, oscname, LUSTRE_OSC_NAME, lovuuid);
         rc = record_setup(obd, llh, oscname, mti->mti_uuid, nodeuuid, 0, 0);
+        rc = record_sec_flavor(obd, llh, oscname, sec_conf);
         rc = mgs_write_log_failnids(obd, mti, llh, oscname);
         snprintf(index, sizeof(index), "%d", mti->mti_stripe_index);
         rc = record_lov_add(obd, llh, lovname, mti->mti_uuid, index, "1");
@@ -1183,17 +1658,20 @@ out:
         name_destroy(&lovuuid);
         name_destroy(&oscuuid);
         name_destroy(&oscname);
+        name_destroy(&svname);
         name_destroy(&nodeuuid);
-        return rc;
+        RETURN(rc);
 }
 
 static int mgs_write_log_ost(struct obd_device *obd, struct fs_db *fsdb,
                              struct mgs_target_info *mti)
 {
         struct llog_handle *llh = NULL;
-        char *logname;
+        char *logname, *lovname, *sec;
+        char mdt_index[9];
         char *ptr = mti->mti_params;
-        int rc, flags = 0, failout = 0;
+        struct sec_flavor_config sec_conf_mdt, sec_conf_cli;
+        int rc, flags = 0, failout = 0, i;
         ENTRY;
         
         CDEBUG(D_MGS, "writing new ost %s\n", mti->mti_svname);
@@ -1203,13 +1681,27 @@ static int mgs_write_log_ost(struct obd_device *obd, struct fs_db *fsdb,
         /* If the ost log already exists, that means that someone reformatted
            the ost and it called target_add again. */
         if (!mgs_log_is_empty(obd, mti->mti_svname)) {
-                LCONSOLE_ERROR("The config log for %s already exists, yet the "
-                               "server claims it never registered.  It may have"
-                               " been reformatted, or the index changed. "
-                               "writeconf the MDT to regenerate all logs.\n", 
-                               mti->mti_svname);
+                LCONSOLE_ERROR_MSG(0x141, "The config log for %s already "
+                                   "exists, yet the server claims it never "
+                                   "registered. It may have been reformatted, "
+                                   "or the index changed. writeconf the MDT to "
+                                   "regenerate all logs.\n", mti->mti_svname);
                 RETURN(-EALREADY);
         }
+
+        /* security flavors */
+        extract_sec_flavor(mti->mti_params, PARAM_SEC_RPC_MDT, &sec);
+        rc = sptlrpc_parse_flavor(LUSTRE_MDT, LUSTRE_OST, sec, &sec_conf_mdt);
+        name_destroy(&sec);
+        if (rc)
+                RETURN(rc);
+
+        extract_sec_flavor(mti->mti_params, PARAM_SEC_RPC_CLI, &sec);
+        rc = sptlrpc_parse_flavor(LUSTRE_CLI, LUSTRE_OST, sec, &sec_conf_cli);
+        name_destroy(&sec);
+        if (rc)
+                RETURN(rc);
+
         /*
         attach obdfilter ost1 ost1_UUID
         setup /dev/loop2 ldiskfs f|n errors=remount-ro,user_xattr
@@ -1241,27 +1733,34 @@ static int mgs_write_log_ost(struct obd_device *obd, struct fs_db *fsdb,
                 /* Note that we can't add any new failnids, since we don't
                    know the old osc names. */
                 flags = CM_SKIP | CM_UPGRADE146;
+        
         } else if ((mti->mti_flags & LDD_F_UPDATE) != LDD_F_UPDATE) {
-                /* If the update flag isn't set, don't really update
-                   client/mdt logs. */
+                /* If the update flag isn't set, don't update client/mdt
+                   logs. */
                 flags |= CM_SKIP;
                 LCONSOLE_WARN("Client log for %s was not updated; writeconf "
                               "the MDT first to regenerate it.\n",
                               mti->mti_svname);
         }
-        
-        /* Append ost info to mdt log */
-        /* FIXME add to all MDT logs for CMD */
-        /* FIXME need real MDT name, but MDT may not have registered yet! */
-        name_create(&logname, mti->mti_fsname, "-MDT0000");
-        rc = mgs_write_log_osc(obd, fsdb, mti, logname, fsdb->fsdb_mdtlov,
-                               flags);
-        name_destroy(&logname);
-        
+
+        // for_all_existing_mdt
+        for (i = 0; i < INDEX_MAP_SIZE * 8; i++){
+                 if (test_bit(i,  fsdb->fsdb_mdt_index_map)) {
+                        sprintf(mdt_index,"-MDT%04x",i);
+                        name_create(&logname, mti->mti_fsname, mdt_index);
+                        name_create(&lovname, logname, "-mdtlov");
+                        mgs_write_log_osc_to_lov(obd, fsdb, mti, logname,
+                                                 mdt_index, lovname,
+                                                 &sec_conf_mdt, flags);
+                        name_destroy(&logname);
+                        name_destroy(&lovname);
+                }
+        }
+    
         /* Append ost info to the client log */
         name_create(&logname, mti->mti_fsname, "-client");
-        rc = mgs_write_log_osc(obd, fsdb, mti, logname, fsdb->fsdb_clilov, 
-                               flags);
+        mgs_write_log_osc_to_lov(obd, fsdb, mti, logname, "",
+                                 fsdb->fsdb_clilov, &sec_conf_cli, 0);
         name_destroy(&logname);
         
         RETURN(rc);
@@ -1287,29 +1786,16 @@ static int mgs_write_log_add_failnid(struct obd_device *obd, struct fs_db *fsdb,
 
         /* Verify that we know about this target */
         if (mgs_log_is_empty(obd, mti->mti_svname)) {
-                LCONSOLE_ERROR("The target %s has not registered yet. "
-                               "It must be started before failnids can "
-                               "be added.\n", mti->mti_svname);
+                LCONSOLE_ERROR_MSG(0x142, "The target %s has not registered "
+                                   "yet. It must be started before failnids "
+                                   "can be added.\n", mti->mti_svname);
                 RETURN(-ENOENT);
         }
 
         /* Create mdc/osc client name (e.g. lustre-OST0001-osc) */
         if (mti->mti_flags & LDD_F_SV_TYPE_MDT) {
-                /* COMPAT_146 */ 
-                if (fsdb->fsdb_mdc)
-                        name_create(&cliname, fsdb->fsdb_mdc, "");
-                else 
-                        name_create(&cliname, mti->mti_svname, "-mdc");
+                name_create(&cliname, mti->mti_svname, "-mdc");
         } else if (mti->mti_flags & LDD_F_SV_TYPE_OST) {
-                /* COMPAT_146 */
-                if (fsdb->fsdb_flags & FSDB_OLDLOG14) {
-                        LCONSOLE_ERROR("Failover NIDs cannot be added to "
-                                       "upgraded client logs for %s. Consider "
-                                       "updating the configuration with "
-                                       "--writeconf.\n", 
-                                       mti->mti_svname);
-                        RETURN(-EINVAL);
-                }
                 name_create(&cliname, mti->mti_svname, "-osc");
         } else {
                 RETURN(-EINVAL);
@@ -1410,18 +1896,22 @@ static int mgs_write_log_params(struct obd_device *obd, struct fs_db *fsdb,
 
                 /* Processed in lustre_start_mgc */
                 if (class_match_param(ptr, PARAM_MGSNODE, NULL) == 0) 
-                        goto end_while;
+                        GOTO(end_while, rc);
 
                 /* Processed in mgs_write_log_ost */
                 if (class_match_param(ptr, PARAM_FAILMODE, NULL) == 0) {
                         if (mti->mti_flags & LDD_F_PARAM) {
-                                LCONSOLE_ERROR("%s can only be changed with "
-                                              "tunefs.lustre and --writeconf\n",
-                                              ptr);
+                                LCONSOLE_ERROR_MSG(0x169, "%s can only be "
+                                                   "changed with tunefs.lustre"
+                                                   "and --writeconf\n", ptr);
                                 rc = -EPERM;
                         }
-                        goto end_while;
+                        GOTO(end_while, rc);
                 }
+                /* Processed in mgs_write_log_mdt/mgs_write_log_ost */
+                if (class_match_param(ptr, PARAM_SEC_RPC_MDT, NULL) == 0 ||
+                    class_match_param(ptr, PARAM_SEC_RPC_CLI, NULL) == 0)
+                        GOTO(end_while, rc);
 
                 if (class_match_param(ptr, PARAM_FAILNODE, NULL) == 0) {
                         /* Add a failover nidlist */
@@ -1432,7 +1922,7 @@ static int mgs_write_log_params(struct obd_device *obd, struct fs_db *fsdb,
                                 CDEBUG(D_MGS, "Adding failnode\n");
                                 rc = mgs_write_log_add_failnid(obd, fsdb, mti);
                         }
-                        goto end_while;
+                        GOTO(end_while, rc);
                 }
 
                 if (class_match_param(ptr, PARAM_SYS_TIMEOUT, &tmp) == 0) {
@@ -1441,7 +1931,6 @@ static int mgs_write_log_params(struct obd_device *obd, struct fs_db *fsdb,
                         timeout = simple_strtoul(tmp, NULL, 0);
 
                         CDEBUG(D_MGS, "obd timeout %d\n", timeout);
-                        
                         lustre_cfg_bufs_reset(&bufs, NULL);
                         lcfg = lustre_cfg_new(LCFG_SET_TIMEOUT, &bufs);
                         lcfg->lcfg_num = timeout;
@@ -1450,15 +1939,19 @@ static int mgs_write_log_params(struct obd_device *obd, struct fs_db *fsdb,
                                                       mti->mti_fsname,
                                                       "timeout"); 
                         lustre_cfg_free(lcfg);
-                        goto end_while;
+                        GOTO(end_while, rc);
                 }
 
-                if (class_match_param(ptr, PARAM_OSC""PARAM_ACTIVE, &tmp) == 0){ 
+                if (class_match_param(ptr, PARAM_OSC""PARAM_ACTIVE, &tmp) == 0) 
                         /* active=0 means off, anything else means on */
+                        char mdt_index[16];
                         int flag = (*tmp == '0') ? CM_EXCLUDE : 0;
+                        int i;
+
                         if (!(mti->mti_flags & LDD_F_SV_TYPE_OST)) {
-                                LCONSOLE_ERROR("%s: Only OSCs can be (de)activ"
-                                               "ated.\n", mti->mti_svname);
+                                LCONSOLE_ERROR_MSG(0x144, "%s: Only OSCs can "
+                                                   "be (de)activated.\n",
+                                                   mti->mti_svname);
                                 rc = -EINVAL;
                                 goto end_while;
                         }
@@ -1473,59 +1966,78 @@ static int mgs_write_log_params(struct obd_device *obd, struct fs_db *fsdb,
                                 goto active_err;
                         /* Modify mdtlov */
                         /* FIXME add to all MDT logs for CMD */
-                        name_create(&logname, mti->mti_fsname, "-MDT0000");
-                        rc = mgs_modify(obd, fsdb, mti, logname, 
-                                        mti->mti_svname, "add osc", flag);
-                        name_destroy(&logname);
+                        for (i = 0; i < INDEX_MAP_SIZE * 8; i++) {
+                                if (!test_bit(i, fsdb->fsdb_mdt_index_map))
+                                        continue;
+                                sprintf(mdt_index,"-MDT%04x", i);
+                                name_create(&logname, mti->mti_fsname, mdt_index);
+                                rc = mgs_modify(obd, fsdb, mti, logname, 
+                                                mti->mti_svname, "add osc", flag);
+                                name_destroy(&logname);
+                                if (rc)
+                                        goto active_err;
+                        }
 active_err:
                         if (rc) {
-                                LCONSOLE_ERROR("Couldn't find %s in log (%d). "
-                                   "No permanent changes were made to the "
-                                   "config log.\n", mti->mti_svname, rc);
+                                LCONSOLE_ERROR_MSG(0x145, "Couldn't find %s in"
+                                                   "log (%d). No permanent "
+                                                   "changes were made to the "
+                                                   "config log.\n",
+                                                   mti->mti_svname, rc);
                                 if (fsdb->fsdb_flags & FSDB_OLDLOG14) 
-                                        LCONSOLE_ERROR("This may be because the"
-                                        " log is in the old 1.4 style. Consider"
-                                        " --writeconf to update the logs.\n");
+                                        LCONSOLE_ERROR_MSG(0x146, "This may be"
+                                                           " because the log "
+                                                           "is in the old 1.4"
+                                                           "style. Consider "
+                                                           " --writeconf to "
+                                                           "update the logs.\n");
                                 goto end_while;
                         }
                         /* Fall through to osc proc for deactivating 
                            live OSC on running MDT / clients. */
                 }
-
                 /* Below here, let obd's XXX_process_config methods handle it */
-
                 /* All lov. in proc */
                 if (class_match_param(ptr, PARAM_LOV, NULL) == 0) {
+                        char mdt_index[16];
+                        char *mdtlovname;
+                        
                         CDEBUG(D_MGS, "lov param %s\n", ptr);
                         if (!(mti->mti_flags & LDD_F_SV_TYPE_MDT)) {
-                                LCONSOLE_ERROR("LOV params must be set on the "
-                                               "MDT, not %s. Ignoring.\n",
-                                               mti->mti_svname);
+                                LCONSOLE_ERROR_MSG(0x147, "LOV params must be "
+                                                   "set on the MDT, not %s. "
+                                                   "Ignoring.\n", 
+                                                   mti->mti_svname);
                                 rc = 0;
                                 goto end_while;
                         }
 
                         /* Modify mdtlov */
-                        if (mgs_log_is_empty(obd, mti->mti_svname)) {
-                                rc = -ENODEV;
-                                goto end_while;
-                        }
+                        if (mgs_log_is_empty(obd, mti->mti_svname))
+                                GOTO(end_while, rc = -ENODEV);
+
+                        sprintf(mdt_index,"-MDT%04x", mti->mti_stripe_index);
+                        name_create(&logname, mti->mti_fsname, mdt_index);
+                        name_create(&mdtlovname, logname, "-mdtlov");
                         rc = mgs_wlp_lcfg(obd, fsdb, mti, mti->mti_svname, 
-                                          &bufs, fsdb->fsdb_mdtlov, ptr);
-                        if (rc) 
-                                goto end_while;
+                                          &bufs, mdtlovname, ptr);
+                        name_destroy(&logname);
+                        name_destroy(&mdtlovname);
+                        if (rc)
+                                GOTO(end_while, rc);
 
                         /* Modify clilov */
                         name_create(&logname, mti->mti_fsname, "-client");
                         rc = mgs_wlp_lcfg(obd, fsdb, mti, logname, &bufs,
                                           fsdb->fsdb_clilov, ptr);
                         name_destroy(&logname);
-                        goto end_while;
+                        GOTO(end_while, rc);
                 }
 
                 /* All osc., mdc., llite. params in proc */
                 if ((class_match_param(ptr, PARAM_OSC, NULL) == 0) || 
-                    (class_match_param(ptr, PARAM_MDC, NULL) == 0) || 
+                    (class_match_param(ptr, PARAM_MDC, NULL) == 0) ||
                     (class_match_param(ptr, PARAM_LLITE, NULL) == 0)) {
                         char *cname;
                         if (memcmp(ptr, PARAM_LLITE, strlen(PARAM_LLITE)) == 0) {
@@ -1537,16 +2049,19 @@ active_err:
                                 if (fsdb->fsdb_mdc)
                                         name_create(&cname, fsdb->fsdb_mdc, "");
                                 else
-                                        name_create(&cname, mti->mti_svname, 
+                                        name_create(&cname, mti->mti_svname,
                                                     "-mdc");
                         } else if (mti->mti_flags & LDD_F_SV_TYPE_OST) {
                                 /* COMPAT_146 */
                                 if (fsdb->fsdb_flags & FSDB_OLDLOG14) {
-                                      LCONSOLE_ERROR("Upgraded client logs "
-                                           "for %s cannot be modified. "
-                                           "Consider updating the "
-                                           "configuration with --writeconf\n",
-                                           mti->mti_svname);
+                                        LCONSOLE_ERROR_MSG(0x148, "Upgraded "
+                                                           "client logs for %s"
+                                                           " cannot be "
+                                                           "modified. Consider"
+                                                           " updating the "
+                                                           "configuration with"
+                                                           " --writeconf\n",
+                                                           mti->mti_svname);
                                         /* We don't know the names of all the
                                            old oscs*/
                                         rc = -EINVAL;
@@ -1562,23 +2077,37 @@ active_err:
                         
                         /* Modify client */
                         name_create(&logname, mti->mti_fsname, "-client");
-                        rc = mgs_wlp_lcfg(obd, fsdb, mti, logname, &bufs, 
+                        rc = mgs_wlp_lcfg(obd, fsdb, mti, logname, &bufs,
                                           cname, ptr);
-                        name_destroy(&logname);
-                        
+
                         /* osc params affect the MDT as well */
-                        if (mti->mti_flags & LDD_F_SV_TYPE_OST) {
-                                /* FIXME add to all MDT logs for CMD */
-                                name_create(&logname, mti->mti_fsname,
-                                            "-MDT0000");
-                                if (!mgs_log_is_empty(obd, logname))
-                                        rc = mgs_wlp_lcfg(obd, fsdb, mti,
-                                                          logname, &bufs, 
-                                                          cname, ptr);
-                                name_destroy(&logname);
+                        if (!rc && (mti->mti_flags & LDD_F_SV_TYPE_OST)) {
+                                char mdt_index[16];
+                                int i;
+
+                                for (i = 0; i < INDEX_MAP_SIZE * 8; i++){
+                                        if (!test_bit(i, fsdb->fsdb_mdt_index_map))
+                                                continue;
+                                        name_destroy(&cname);
+                                        sprintf(mdt_index, "-osc-MDT%04x", i);
+                                        name_create(&cname, mti->mti_svname,
+                                                    mdt_index);
+                                        name_destroy(&logname);
+                                        sprintf(mdt_index, "-MDT%04x", i);
+                                        name_create(&logname, mti->mti_fsname,
+                                                    mdt_index);
+                                        if (!mgs_log_is_empty(obd, logname))
+                                                rc = mgs_wlp_lcfg(obd, fsdb,
+                                                                  mti, logname,
+                                                                  &bufs, cname,
+                                                                  ptr);
+                                        if (rc)
+                                                break;
+                                }
                         }
+                        name_destroy(&logname);
                         name_destroy(&cname);
-                        goto end_while;
+                        GOTO(end_while, rc);
                 }
 
                 /* All mdt., ost. params in proc */
@@ -1591,7 +2120,7 @@ active_err:
                         }
                         rc = mgs_wlp_lcfg(obd, fsdb, mti, mti->mti_svname,
                                           &bufs, mti->mti_svname, ptr);
-                        goto end_while;
+                        GOTO(end_while, rc);
                 }
 
                 LCONSOLE_WARN("Ignoring unrecognized param '%s'\n", ptr);
@@ -1613,10 +2142,9 @@ end_while:
         RETURN(rc);
 }
 
+/* Not implementing automatic failover nid addition at this time. */
 int mgs_check_failnid(struct obd_device *obd, struct mgs_target_info *mti)
 {
-        /* Not implementing automatic failover nid addition at this time. */
-        return 0;
 #if 0
         struct fs_db *fsdb;
         int rc;
@@ -1642,6 +2170,7 @@ int mgs_check_failnid(struct obd_device *obd, struct mgs_target_info *mti)
 
         RETURN(rc);
 #endif
+        return 0;
 }
 
 int mgs_write_log_target(struct obd_device *obd,
@@ -1657,6 +2186,7 @@ int mgs_write_log_target(struct obd_device *obd,
                 CERROR("Can't get index (%d)\n", rc);
                 RETURN(rc);
         }
+
         /* COMPAT_146 */
         if (mti->mti_flags & LDD_F_UPGRADE14) {
                 if (rc == EALREADY) {
@@ -1664,11 +2194,12 @@ int mgs_write_log_target(struct obd_device *obd,
                                       "upgrading\n", mti->mti_stripe_index, 
                                       mti->mti_svname);
                 } else {
-                        LCONSOLE_ERROR("Failed to find %s in the old client "
-                                       "log. Apparently it is not part of this "
-                                       "filesystem, or the old log is wrong.\n"
-                                       "Use 'writeconf' on the MDT to force log"
-                                       " regeneration.\n", mti->mti_svname);
+                        LCONSOLE_ERROR_MSG(0x149, "Failed to find %s in the old"
+                                           " client log. Apparently it is not "
+                                           "part of this filesystem, or the old"
+                                           " log is wrong.\nUse 'writeconf' on "
+                                           "the MDT to force log regeneration."
+                                           "\n", mti->mti_svname);
                         /* Not in client log?  Upgrade anyhow...*/
                         /* Argument against upgrading: reformat MDT,
                            upgrade OST, then OST will start but will be SKIPped
@@ -1678,10 +2209,6 @@ int mgs_write_log_target(struct obd_device *obd,
                 /* end COMPAT_146 */
         } else {
                 if (rc == EALREADY) {
-                        /* This might be a params update, or a 
-                           local writeconf. (For "full" writeconf, the client
-                           log won't have an entry for this target, so we 
-                           won't get here.) */
                         LCONSOLE_WARN("Found index %d for %s, updating log\n", 
                                       mti->mti_stripe_index, mti->mti_svname);
                         /* We would like to mark old log sections as invalid 
@@ -1756,11 +2283,11 @@ int mgs_upgrade_sv_14(struct obd_device *obd, struct mgs_target_info *mti)
         rc = mgs_find_or_make_fsdb(obd, mti->mti_fsname, &fsdb);
         if (rc) 
                 RETURN(rc);
-        
+
         if (fsdb->fsdb_flags & FSDB_LOG_EMPTY) {
-                LCONSOLE_ERROR("The old client log %s-client is missing.  Was "
-                               "tunefs.lustre successful?\n",
-                               mti->mti_fsname);
+                LCONSOLE_ERROR_MSG(0x14a, "The old client log %s-client is "
+                                   "missing.  Was tunefs.lustre successful?\n",
+                                   mti->mti_fsname);
                 RETURN(-ENOENT);
         }
 
@@ -1772,12 +2299,12 @@ int mgs_upgrade_sv_14(struct obd_device *obd, struct mgs_target_info *mti)
 
         if (mti->mti_flags & LDD_F_SV_TYPE_MDT) {
                 if (mgs_log_is_empty(obd, mti->mti_svname)) {
-                        LCONSOLE_ERROR("The old MDT log %s is missing.  Was "
-                                       "tunefs.lustre successful?\n",
-                                       mti->mti_svname);
+                        LCONSOLE_ERROR_MSG(0x14b, "The old MDT log %s is "
+                                           "missing. Was tunefs.lustre "
+                                           "successful?\n",
+                                           mti->mti_svname);
                         RETURN(-ENOENT);
                 }
-
                 /* We're starting with an old uuid.  Assume old name for lov
                    as well since the lov entry already exists in the log. */
                 CDEBUG(D_MGS, "old mds uuid %s\n", mti->mti_uuid);
@@ -1791,10 +2318,10 @@ int mgs_upgrade_sv_14(struct obd_device *obd, struct mgs_target_info *mti)
         }
 
         if (!(fsdb->fsdb_flags & FSDB_OLDLOG14)) {
-                LCONSOLE_ERROR("%s-client is supposedly an old log, but no old "
-                               "LOV or MDT was found. Consider updating the "
-                               "configuration with --writeconf.\n",
-                               mti->mti_fsname);
+                LCONSOLE_ERROR_MSG(0x14c, "%s-client is supposedly an old "
+                                   "log, but no old LOV or MDT was found. "
+                                   "Consider updating the configuration with"
+                                   " --writeconf.\n", mti->mti_fsname);
         }
 
         RETURN(rc);
@@ -1912,7 +2439,7 @@ int mgs_setparam(struct obd_device *obd, struct lustre_cfg *lcfg, char *fsname)
                 }
         }
         if (!devname) {
-                LCONSOLE_ERROR("No target specified: %s\n", param);
+                LCONSOLE_ERROR_MSG(0x14d, "No target specified: %s\n", param);
                 RETURN(-ENOSYS);
         }
 
@@ -1966,7 +2493,6 @@ out:
         RETURN(rc);
 }
 
-
 #if 0
 /******************** unused *********************/
 static int mgs_backup_llog(struct obd_device *obd, char* fsname)
@@ -2026,6 +2552,4 @@ out:
         return rc;
 }
 
-
-
 #endif