Whamcloud - gitweb
LU-1301 mgs: env and mgs_device to pass around
authorAlex Zhuravlev <bzzz@whamcloud.com>
Thu, 9 Aug 2012 10:51:46 +0000 (14:51 +0400)
committerOleg Drokin <green@whamcloud.com>
Wed, 12 Sep 2012 04:35:45 +0000 (00:35 -0400)
a trivial part of orion changes:
 - introduce mgs_device (old mgs_obd)
 - pass lu_env around

Signed-off-by: Alex Zhuravlev <bzzz@whamcloud.com>
Change-Id: I53d55c9f0a91c16c9eb65ab41d9660c3699bac45
Reviewed-on: http://review.whamcloud.com/3668
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Jinshan Xiong <jinshan.xiong@whamcloud.com>
lustre/include/obd.h
lustre/mgs/lproc_mgs.c
lustre/mgs/mgs_fs.c
lustre/mgs/mgs_handler.c
lustre/mgs/mgs_internal.h
lustre/mgs/mgs_llog.c
lustre/mgs/mgs_nids.c

index 57a0e2a..bc1883d 100644 (file)
@@ -552,7 +552,7 @@ struct client_obd {
 
 #define CL_NOT_QUOTACHECKED 1   /* client->cl_qchk_stat init value */
 
-struct mgs_obd {
+struct mgs_device {
         struct obd_device_target         mgs_obt;
         struct ptlrpc_service           *mgs_service;
         struct vfsmount                 *mgs_vfsmnt;
@@ -562,6 +562,7 @@ struct mgs_obd {
         cfs_mutex_t                      mgs_mutex;
         cfs_proc_dir_entry_t            *mgs_proc_live;
         cfs_time_t                       mgs_start_time;
+       struct obd_device               *mgs_obd;
 };
 
 struct mds_obd {
@@ -1154,7 +1155,7 @@ struct obd_device {
                 struct echo_obd echo;
                 struct lov_obd lov;
                 struct lmv_obd lmv;
-                struct mgs_obd mgs;
+               struct mgs_device mgs;
         } u;
         /* Fields used by LProcFS */
         unsigned int           obd_cntr_base;
index fad189e..01268ac 100644 (file)
@@ -61,18 +61,23 @@ static int lprocfs_mgs_rd_mntdev(char *page, char **start, off_t off, int count,
 static int mgs_fs_seq_show(struct seq_file *seq, void *v)
 {
         struct obd_device *obd = seq->private;
-        struct mgs_obd *mgs = &obd->u.mgs;
+       struct mgs_device *mgs = &obd->u.mgs;
         cfs_list_t dentry_list;
         struct l_linux_dirent *dirent, *n;
+       struct lu_env env;
         int rc, len;
         ENTRY;
 
         LASSERT(obd != NULL);
-        rc = class_dentry_readdir(obd, mgs->mgs_configs_dir,
-                                  mgs->mgs_vfsmnt, &dentry_list);
+
+       rc = lu_env_init(&env, LCT_MG_THREAD);
+       if (rc)
+               RETURN(rc);
+
+       rc = class_dentry_readdir(&env, mgs, &dentry_list);
         if (rc) {
                 CERROR("Can't read config dir\n");
-                RETURN(rc);
+               GOTO(out, rc);
         }
         cfs_list_for_each_entry_safe(dirent, n, &dentry_list, lld_list) {
                 cfs_list_del(&dirent->lld_list);
@@ -84,6 +89,8 @@ static int mgs_fs_seq_show(struct seq_file *seq, void *v)
                 OBD_FREE(dirent, sizeof(*dirent));
         }
 
+out:
+       lu_env_fini(&env);
         RETURN(0);
 }
 
@@ -122,24 +129,33 @@ static void seq_show_srpc_rules(struct seq_file *seq, const char *tgtname,
 static int mgsself_srpc_seq_show(struct seq_file *seq, void *v)
 {
         struct obd_device *obd = seq->private;
+       struct mgs_device *mgs = &obd->u.mgs;
         struct fs_db      *fsdb;
+       struct lu_env      env;
         int                rc;
 
-        rc = mgs_find_or_make_fsdb(obd, MGSSELF_NAME, &fsdb);
+       rc = lu_env_init(&env, LCT_MG_THREAD);
+       if (rc)
+               return rc;
+
+       rc = mgs_find_or_make_fsdb(&env, mgs, MGSSELF_NAME, &fsdb);
         if (rc)
-                return rc;
+               goto out;
 
         cfs_mutex_lock(&fsdb->fsdb_mutex);
         seq_show_srpc_rules(seq, fsdb->fsdb_name, &fsdb->fsdb_srpc_gen);
         cfs_mutex_unlock(&fsdb->fsdb_mutex);
+
+out:
+       lu_env_fini(&env);
         return 0;
 }
 
 LPROC_SEQ_FOPS_RO(mgsself_srpc);
 
-int lproc_mgs_setup(struct obd_device *obd)
+int lproc_mgs_setup(struct mgs_device *mgs)
 {
-        struct mgs_obd *mgs = &obd->u.mgs;
+       struct obd_device *obd = mgs->mgs_obd;
         int rc;
 
         rc = lprocfs_obd_seq_create(obd, "filesystems", 0444,
@@ -167,14 +183,13 @@ int lproc_mgs_setup(struct obd_device *obd)
         return rc;
 }
 
-int lproc_mgs_cleanup(struct obd_device *obd)
+int lproc_mgs_cleanup(struct mgs_device *mgs)
 {
-        struct mgs_obd *mgs;
+       struct obd_device *obd = mgs->mgs_obd;
 
         if (!obd)
                 return -EINVAL;
 
-        mgs = &obd->u.mgs;
         if (mgs->mgs_proc_live) {
                 /* Should be no live entries */
                 LASSERT(mgs->mgs_proc_live->subdir == NULL);
@@ -238,9 +253,8 @@ static ssize_t mgs_live_seq_write(struct file *file, const char *buf,
 }
 LPROC_SEQ_FOPS(mgs_live);
 
-int lproc_mgs_add_live(struct obd_device *obd, struct fs_db *fsdb)
+int lproc_mgs_add_live(struct mgs_device *mgs, struct fs_db *fsdb)
 {
-        struct mgs_obd *mgs = &obd->u.mgs;
         int rc;
 
         if (!mgs->mgs_proc_live)
@@ -251,10 +265,8 @@ int lproc_mgs_add_live(struct obd_device *obd, struct fs_db *fsdb)
         return 0;
 }
 
-int lproc_mgs_del_live(struct obd_device *obd, struct fs_db *fsdb)
+int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb)
 {
-        struct mgs_obd *mgs = &obd->u.mgs;
-
         if (!mgs->mgs_proc_live)
                 return 0;
 
index c756066..4c7e1ac 100644 (file)
@@ -143,7 +143,7 @@ struct lvfs_callback_ops mgs_lvfs_ops = {
 
 int mgs_fs_setup(struct obd_device *obd, struct vfsmount *mnt)
 {
-        struct mgs_obd *mgs = &obd->u.mgs;
+       struct mgs_device *mgs = &obd->u.mgs;
         struct lvfs_run_ctxt saved;
         struct dentry *dentry;
         int rc;
@@ -198,7 +198,7 @@ err_pop:
 
 int mgs_fs_cleanup(struct obd_device *obd)
 {
-        struct mgs_obd *mgs = &obd->u.mgs;
+       struct mgs_device *mgs = &obd->u.mgs;
         struct lvfs_run_ctxt saved;
         int rc = 0;
 
index 8cd2799..c2a30de 100644 (file)
@@ -169,7 +169,7 @@ static int mgs_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
 {
        static struct ptlrpc_service_conf       conf;
         struct lprocfs_static_vars lvars;
-        struct mgs_obd *mgs = &obd->u.mgs;
+       struct mgs_device *mgs = &obd->u.mgs;
         struct lustre_mount_info *lmi;
         struct lustre_sb_info *lsi;
         struct vfsmount *mnt;
@@ -197,6 +197,7 @@ static int mgs_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
 
         obd->u.obt.obt_magic = OBT_MAGIC;
         obd->u.obt.obt_instance = 0;
+       mgs->mgs_obd = obd;
 
         /* namespace for mgs llog */
         obd->obd_namespace = ldlm_namespace_new(obd ,"MGS",
@@ -225,14 +226,14 @@ static int mgs_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
         obd->obd_replayable = 0;
 
         /* Internal mgs setup */
-        mgs_init_fsdb_list(obd);
+       mgs_init_fsdb_list(mgs);
         cfs_mutex_init(&mgs->mgs_mutex);
         mgs->mgs_start_time = cfs_time_current_sec();
 
         /* Setup proc */
         lprocfs_mgs_init_vars(&lvars);
         if (lprocfs_obd_setup(obd, lvars.obd_vars) == 0) {
-                lproc_mgs_setup(obd);
+               lproc_mgs_setup(mgs);
                 rc = lprocfs_alloc_md_stats(obd, LPROC_MGS_LAST);
                 if (rc)
                         GOTO(err_llog, rc);
@@ -275,7 +276,7 @@ static int mgs_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
         RETURN(0);
 
 err_llog:
-        lproc_mgs_cleanup(obd);
+       lproc_mgs_cleanup(mgs);
         obd_llog_finish(obd, 0);
 err_fs:
         /* No extra cleanup needed for llog_init_commit_thread() */
@@ -293,7 +294,7 @@ err_put:
 
 static int mgs_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
 {
-        struct mgs_obd *mgs = &obd->u.mgs;
+       struct mgs_device *mgs = &obd->u.mgs;
         int rc = 0;
         ENTRY;
 
@@ -303,9 +304,9 @@ static int mgs_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
         case OBD_CLEANUP_EXPORTS:
                 ping_evictor_stop();
                 ptlrpc_unregister_service(mgs->mgs_service);
-                mgs_cleanup_fsdb_list(obd);
+               mgs_cleanup_fsdb_list(mgs);
                 rc = obd_llog_finish(obd, 0);
-                lproc_mgs_cleanup(obd);
+               lproc_mgs_cleanup(mgs);
                 break;
         }
         RETURN(rc);
@@ -316,7 +317,7 @@ static int mgs_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
  */
 static int mgs_cleanup(struct obd_device *obd)
 {
-        struct mgs_obd *mgs = &obd->u.mgs;
+       struct mgs_device *mgs = &obd->u.mgs;
         ENTRY;
 
         if (mgs->mgs_sb == NULL)
@@ -385,7 +386,7 @@ static int mgs_completion_ast_ir(struct ldlm_lock *lock, int flags,
         RETURN(ldlm_completion_ast(lock, flags, cbdata));
 }
 
-void mgs_revoke_lock(struct obd_device *obd, struct fs_db *fsdb, int type)
+void mgs_revoke_lock(struct mgs_device *mgs, struct fs_db *fsdb, int type)
 {
         ldlm_completion_callback cp = NULL;
         struct lustre_handle     lockh = { 0 };
@@ -412,10 +413,10 @@ void mgs_revoke_lock(struct obd_device *obd, struct fs_db *fsdb, int type)
 
         if (!rc) {
                 LASSERT(cp != NULL);
-                rc = ldlm_cli_enqueue_local(obd->obd_namespace, &res_id,
-                                            LDLM_PLAIN, NULL, LCK_EX, &flags,
-                                            ldlm_blocking_ast, cp, NULL,
-                                            fsdb, 0, NULL, &lockh);
+               rc = ldlm_cli_enqueue_local(mgs->mgs_obd->obd_namespace,
+                                           &res_id, LDLM_PLAIN, NULL, LCK_EX,
+                                           &flags, ldlm_blocking_ast, cp,
+                                           NULL, fsdb, 0, NULL, &lockh);
                 if (rc != ELDLM_OK) {
                         CERROR("can't take cfg lock for "LPX64"/"LPX64"(%d)\n",
                                le64_to_cpu(res_id.name[0]),
@@ -434,12 +435,14 @@ void mgs_revoke_lock(struct obd_device *obd, struct fs_db *fsdb, int type)
 /* rc=0 means ok
       1 means update
      <0 means error */
-static int mgs_check_target(struct obd_device *obd, struct mgs_target_info *mti)
+static int mgs_check_target(const struct lu_env *env,
+                           struct mgs_device *mgs,
+                           struct mgs_target_info *mti)
 {
         int rc;
         ENTRY;
 
-        rc = mgs_check_index(obd, mti);
+       rc = mgs_check_index(env, mgs, mti);
         if (rc == 0) {
                 LCONSOLE_ERROR_MSG(0x13b, "%s claims to have registered, but "
                                    "this MGS does not know about it, preventing "
@@ -456,7 +459,7 @@ static int mgs_check_target(struct obd_device *obd, struct mgs_target_info *mti)
 
                 /* If the logs don't contain the mti_nids then add
                    them as failover nids */
-                rc = mgs_check_failnid(obd, mti);
+               rc = mgs_check_failnid(env, mgs, mti);
         }
 
         RETURN(rc);
@@ -490,6 +493,8 @@ static int mgs_check_failover_reg(struct mgs_target_info *mti)
 static int mgs_handle_target_reg(struct ptlrpc_request *req)
 {
         struct obd_device *obd = req->rq_export->exp_obd;
+       struct mgs_device *mgs = exp2mgs_dev(req->rq_export);
+       struct lu_env     *env = req->rq_svc_thread->t_env;
         struct mgs_target_info *mti, *rep_mti;
         struct fs_db *fsdb;
         int opc;
@@ -504,7 +509,7 @@ static int mgs_handle_target_reg(struct ptlrpc_request *req)
         if (opc == LDD_F_OPC_READY) {
                 CDEBUG(D_MGS, "fs: %s index: %d is ready to reconnect.\n",
                        mti->mti_fsname, mti->mti_stripe_index);
-                rc = mgs_ir_update(obd, mti);
+               rc = mgs_ir_update(env, mgs, mti);
                 if (rc) {
                         LASSERT(!(mti->mti_flags & LDD_F_IR_CAPABLE));
                         CERROR("Update IR return with %d(ignore and IR "
@@ -528,7 +533,7 @@ static int mgs_handle_target_reg(struct ptlrpc_request *req)
                 /* We're just here as a startup ping. */
                 CDEBUG(D_MGS, "Server %s is running on %s\n",
                        mti->mti_svname, obd_export_nid2str(req->rq_export));
-                rc = mgs_check_target(obd, mti);
+               rc = mgs_check_target(env, mgs, mti);
                 /* above will set appropriate mti flags */
                 if (rc <= 0)
                         /* Nothing wrong, or fatal error */
@@ -544,14 +549,14 @@ static int mgs_handle_target_reg(struct ptlrpc_request *req)
         if (mti->mti_flags & LDD_F_WRITECONF) {
                 if (mti->mti_flags & LDD_F_SV_TYPE_MDT &&
                     mti->mti_stripe_index == 0) {
-                        rc = mgs_erase_logs(obd, mti->mti_fsname);
+                       rc = mgs_erase_logs(env, mgs, mti->mti_fsname);
                         LCONSOLE_WARN("%s: Logs for fs %s were removed by user "
                                       "request.  All servers must be restarted "
                                       "in order to regenerate the logs."
                                       "\n", obd->obd_name, mti->mti_fsname);
                 } else if (mti->mti_flags &
                            (LDD_F_SV_TYPE_OST | LDD_F_SV_TYPE_MDT)) {
-                        rc = mgs_erase_log(obd, mti->mti_svname);
+                       rc = mgs_erase_log(env, mgs, mti->mti_svname);
                         LCONSOLE_WARN("%s: Regenerating %s log by user "
                                       "request.\n",
                                       obd->obd_name, mti->mti_svname);
@@ -561,7 +566,7 @@ static int mgs_handle_target_reg(struct ptlrpc_request *req)
                 mti->mti_flags &= ~LDD_F_UPGRADE14;
         }
 
-        rc = mgs_find_or_make_fsdb(obd, mti->mti_fsname, &fsdb);
+       rc = mgs_find_or_make_fsdb(env, mgs, mti->mti_fsname, &fsdb);
         if (rc) {
                 CERROR("Can't get db for %s: %d\n", mti->mti_fsname, rc);
                 GOTO(out_nolock, rc);
@@ -577,7 +582,7 @@ static int mgs_handle_target_reg(struct ptlrpc_request *req)
 
         /* COMPAT_146 */
         if (mti->mti_flags & LDD_F_UPGRADE14) {
-                rc = mgs_upgrade_sv_14(obd, mti, fsdb);
+               rc = mgs_upgrade_sv_14(env, mgs, mti, fsdb);
                 if (rc) {
                         CERROR("Can't upgrade from 1.4 (%d)\n", rc);
                         GOTO(out, rc);
@@ -594,7 +599,7 @@ static int mgs_handle_target_reg(struct ptlrpc_request *req)
 
                 /* create or update the target log
                    and update the client/mdt logs */
-                rc = mgs_write_log_target(obd, mti, fsdb);
+               rc = mgs_write_log_target(env, mgs, mti, fsdb);
                 if (rc) {
                         CERROR("Failed to write %s log (%d)\n",
                                mti->mti_svname, rc);
@@ -608,7 +613,7 @@ static int mgs_handle_target_reg(struct ptlrpc_request *req)
         }
 
 out:
-        mgs_revoke_lock(obd, fsdb, CONFIG_T_CONFIG);
+       mgs_revoke_lock(mgs, fsdb, CONFIG_T_CONFIG);
 
 out_nolock:
         CDEBUG(D_MGS, "replying with %s, index=%d, rc=%d\n", mti->mti_svname,
@@ -634,7 +639,8 @@ out_nolock:
 
 static int mgs_set_info_rpc(struct ptlrpc_request *req)
 {
-        struct obd_device *obd = req->rq_export->exp_obd;
+       struct mgs_device *mgs = exp2mgs_dev(req->rq_export);
+       struct lu_env     *env = req->rq_svc_thread->t_env;
         struct mgs_send_param *msp, *rep_msp;
         int rc;
         struct lustre_cfg_bufs bufs;
@@ -649,7 +655,7 @@ static int mgs_set_info_rpc(struct ptlrpc_request *req)
         lustre_cfg_bufs_reset(&bufs, NULL);
         lustre_cfg_bufs_set_string(&bufs, 1, msp->mgs_param);
         lcfg = lustre_cfg_new(LCFG_PARAM, &bufs);
-        rc = mgs_setparam(obd, lcfg, fsname);
+       rc = mgs_setparam(env, mgs, lcfg, fsname);
         if (rc) {
                 CERROR("Error %d in setting the parameter %s for fs %s\n",
                        rc, msp->mgs_param, fsname);
@@ -699,13 +705,14 @@ static int mgs_config_read(struct ptlrpc_request *req)
 static int mgs_connect_check_sptlrpc(struct ptlrpc_request *req)
 {
         struct obd_export     *exp = req->rq_export;
-        struct obd_device     *obd = exp->exp_obd;
+       struct mgs_device     *mgs = exp2mgs_dev(req->rq_export);
+       struct lu_env         *env = req->rq_svc_thread->t_env;
         struct fs_db          *fsdb;
         struct sptlrpc_flavor  flvr;
         int                    rc = 0;
 
         if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
-                rc = mgs_find_or_make_fsdb(obd, MGSSELF_NAME, &fsdb);
+               rc = mgs_find_or_make_fsdb(env, mgs, MGSSELF_NAME, &fsdb);
                 if (rc)
                         return rc;
 
@@ -803,7 +810,7 @@ static int mgs_handle_fslog_hack(struct ptlrpc_request *req)
 
         strncpy(fsname, logname, rc);
         fsname[rc] = 0;
-        rc = mgs_fsc_attach(req->rq_export, fsname);
+       rc = mgs_fsc_attach(req->rq_svc_thread->t_env, req->rq_export, fsname);
         if (rc < 0 && rc != -EEXIST)
                 CERROR("add fs client %s returns %d\n", fsname, rc);
 
@@ -999,7 +1006,8 @@ static int mgs_extract_fs_pool(char * arg, char *fsname, char *poolname)
         RETURN(0);
 }
 
-static int mgs_iocontrol_pool(struct obd_device *obd,
+static int mgs_iocontrol_pool(const struct lu_env *env,
+                             struct mgs_device *mgs,
                               struct obd_ioctl_data *data)
 {
         int rc;
@@ -1052,28 +1060,28 @@ static int mgs_iocontrol_pool(struct obd_device *obd,
         case LCFG_POOL_NEW: {
                 if (lcfg->lcfg_bufcount != 2)
                         RETURN(-EINVAL);
-                rc = mgs_pool_cmd(obd, LCFG_POOL_NEW, fsname,
+               rc = mgs_pool_cmd(env, mgs, LCFG_POOL_NEW, fsname,
                                   poolname, NULL);
                 break;
         }
         case LCFG_POOL_ADD: {
                 if (lcfg->lcfg_bufcount != 3)
                         RETURN(-EINVAL);
-                rc = mgs_pool_cmd(obd, LCFG_POOL_ADD, fsname, poolname,
+               rc = mgs_pool_cmd(env, mgs, LCFG_POOL_ADD, fsname, poolname,
                                   lustre_cfg_string(lcfg, 2));
                 break;
         }
         case LCFG_POOL_REM: {
                 if (lcfg->lcfg_bufcount != 3)
                         RETURN(-EINVAL);
-                rc = mgs_pool_cmd(obd, LCFG_POOL_REM, fsname, poolname,
+               rc = mgs_pool_cmd(env, mgs, LCFG_POOL_REM, fsname, poolname,
                                   lustre_cfg_string(lcfg, 2));
                 break;
         }
         case LCFG_POOL_DEL: {
                 if (lcfg->lcfg_bufcount != 2)
                         RETURN(-EINVAL);
-                rc = mgs_pool_cmd(obd, LCFG_POOL_DEL, fsname,
+               rc = mgs_pool_cmd(env, mgs, LCFG_POOL_DEL, fsname,
                                   poolname, NULL);
                 break;
         }
@@ -1106,14 +1114,19 @@ out_pool:
 int mgs_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                   void *karg, void *uarg)
 {
-        struct obd_device *obd = exp->exp_obd;
+       struct mgs_device *mgs = exp2mgs_dev(exp);
         struct obd_ioctl_data *data = karg;
         struct lvfs_run_ctxt saved;
+       struct lu_env env;
         int rc = 0;
 
         ENTRY;
         CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
 
+       rc = lu_env_init(&env, LCT_MG_THREAD);
+       if (rc)
+               RETURN(rc);
+
         switch (cmd) {
 
         case OBD_IOC_PARAM: {
@@ -1127,62 +1140,65 @@ int mgs_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                         rec.lrh_type = OBD_CFG_REC;
                 } else {
                         CERROR("unknown cfg record type:%d \n", data->ioc_type);
-                        RETURN(-EINVAL);
+                       GOTO(out, rc = -EINVAL);
                 }
 
                 OBD_ALLOC(lcfg, data->ioc_plen1);
                 if (lcfg == NULL)
-                        RETURN(-ENOMEM);
+                       GOTO(out, rc = -ENOMEM);
                 if (cfs_copy_from_user(lcfg, data->ioc_pbuf1, data->ioc_plen1))
                         GOTO(out_free, rc = -EFAULT);
 
                 if (lcfg->lcfg_bufcount < 1)
                         GOTO(out_free, rc = -EINVAL);
 
-                rc = mgs_setparam(obd, lcfg, fsname);
+               rc = mgs_setparam(&env, mgs, lcfg, fsname);
                 if (rc) {
                         CERROR("setparam err %d\n", rc);
                         GOTO(out_free, rc);
                 }
 out_free:
                 OBD_FREE(lcfg, data->ioc_plen1);
-                RETURN(rc);
+               break;
         }
 
-        case OBD_IOC_POOL: {
-                RETURN(mgs_iocontrol_pool(obd, data));
-        }
+       case OBD_IOC_POOL:
+               rc = mgs_iocontrol_pool(&env, mgs, data);
+               break;
 
         case OBD_IOC_DUMP_LOG: {
                 struct llog_ctxt *ctxt;
-                ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
-                push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+               ctxt = llog_get_context(mgs->mgs_obd, LLOG_CONFIG_ORIG_CTXT);
+               push_ctxt(&saved, &mgs->mgs_obd->obd_lvfs_ctxt, NULL);
                 rc = class_config_dump_llog(ctxt, data->ioc_inlbuf1, NULL);
-                pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+               pop_ctxt(&saved, &mgs->mgs_obd->obd_lvfs_ctxt, NULL);
                 llog_ctxt_put(ctxt);
 
-                RETURN(rc);
+               break;
         }
 
         case OBD_IOC_LLOG_CHECK:
         case OBD_IOC_LLOG_INFO:
         case OBD_IOC_LLOG_PRINT: {
                 struct llog_ctxt *ctxt;
-                ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
+               ctxt = llog_get_context(mgs->mgs_obd, LLOG_CONFIG_ORIG_CTXT);
 
                 push_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL);
                 rc = llog_ioctl(ctxt, cmd, data);
                 pop_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL);
                 llog_ctxt_put(ctxt);
 
-                RETURN(rc);
+               break;
         }
 
         default:
                 CDEBUG(D_INFO, "unknown command %x\n", cmd);
-                RETURN(-EINVAL);
+               rc = -EINVAL;
+               break;
         }
-        RETURN(0);
+out:
+       lu_env_fini(&env);
+       RETURN(rc);
 }
 
 /* use obd ops to offer management infrastructure */
index bf5a298..0e1fb7e 100644 (file)
@@ -154,6 +154,7 @@ struct fs_db {
 
         /* async thread to notify clients */
         struct obd_device   *fsdb_obd;
+       struct mgs_device   *fsdb_mgs;
         cfs_waitq_t          fsdb_notify_waitq;
         cfs_completion_t     fsdb_notify_comp;
         cfs_time_t           fsdb_notify_start;
@@ -167,39 +168,45 @@ struct fs_db {
 };
 
 /* mgs_llog.c */
-int class_dentry_readdir(struct obd_device *obd, struct dentry *dir,
-                         struct vfsmount *inmnt,
-                         cfs_list_t *dentry_list);
+int class_dentry_readdir(const struct lu_env *env,
+                        struct mgs_device *mgs, cfs_list_t *list);
 
-int mgs_init_fsdb_list(struct obd_device *obd);
-int mgs_cleanup_fsdb_list(struct obd_device *obd);
-int mgs_find_or_make_fsdb(struct obd_device *obd, char *name,
+int mgs_init_fsdb_list(struct mgs_device *mgs);
+int mgs_cleanup_fsdb_list(struct mgs_device *mgs);
+int mgs_find_or_make_fsdb(const struct lu_env *env, struct mgs_device *mgs, char *name,
                           struct fs_db **dbh);
-struct fs_db *mgs_find_fsdb(struct obd_device *obd, char *fsname);
-int mgs_get_fsdb_srpc_from_llog(struct obd_device *obd, struct fs_db *fsdb);
-int mgs_check_index(struct obd_device *obd, struct mgs_target_info *mti);
-int mgs_check_failnid(struct obd_device *obd, struct mgs_target_info *mti);
-int mgs_write_log_target(struct obd_device *obd, struct mgs_target_info *mti,
+struct fs_db *mgs_find_fsdb(struct mgs_device *mgs, char *fsname);
+int mgs_get_fsdb_srpc_from_llog(const struct lu_env *env, struct mgs_device *mgs, struct fs_db *fsdb);
+int mgs_check_index(const struct lu_env *env, struct mgs_device *mgs, struct mgs_target_info *mti);
+int mgs_check_failnid(const struct lu_env *env, struct mgs_device *mgs, struct mgs_target_info *mti);
+int mgs_write_log_target(const struct lu_env *env, struct mgs_device *mgs, struct mgs_target_info *mti,
                          struct fs_db *fsdb);
-int mgs_upgrade_sv_14(struct obd_device *obd, struct mgs_target_info *mti,
-                      struct fs_db *fsdb);
-int mgs_erase_log(struct obd_device *obd, char *name);
-int mgs_erase_logs(struct obd_device *obd, char *fsname);
-int mgs_setparam(struct obd_device *obd, struct lustre_cfg *lcfg, char *fsname);
-
-int mgs_pool_cmd(struct obd_device *obd, enum lcfg_command_type cmd,
-                 char *poolname, char *fsname, char *ostname);
+int mgs_upgrade_sv_14(const struct lu_env *env, struct mgs_device *mgs,
+                     struct mgs_target_info *mti, struct fs_db *fsdb);
+int mgs_erase_log(const struct lu_env *env, struct mgs_device *mgs,
+                 char *name);
+int mgs_erase_logs(const struct lu_env *env, struct mgs_device *mgs,
+                  char *fsname);
+int mgs_setparam(const struct lu_env *env, struct mgs_device *mgs,
+                struct lustre_cfg *lcfg, char *fsname);
+int mgs_list_logs(const struct lu_env *env, struct mgs_device *mgs,
+                 struct obd_ioctl_data *data);
+int mgs_pool_cmd(const struct lu_env *env, struct mgs_device *mgs,
+                enum lcfg_command_type cmd, char *poolname, char *fsname,
+                char *ostname);
 
 /* mgs_handler.c */
 int  mgs_get_lock(struct obd_device *obd, struct ldlm_res_id *res,
                   struct lustre_handle *lockh);
 int  mgs_put_lock(struct lustre_handle *lockh);
-void mgs_revoke_lock(struct obd_device *obd, struct fs_db *fsdb, int type);
+void mgs_revoke_lock(struct mgs_device *mgs, struct fs_db *fsdb, int type);
 
 /* mgs_nids.c */
-int  mgs_ir_update(struct obd_device *obd, struct mgs_target_info *mti);
-int  mgs_ir_init_fs(struct obd_device *obd, struct fs_db *fsdb);
-void mgs_ir_fini_fs(struct obd_device *obd, struct fs_db *fsdb);
+int  mgs_ir_update(const struct lu_env *env, struct mgs_device *mgs,
+                  struct mgs_target_info *mti);
+int mgs_ir_init_fs(const struct lu_env *env, struct mgs_device *mgs,
+                  struct fs_db *fsdb);
+void mgs_ir_fini_fs(struct mgs_device *mgs, struct fs_db *fsdb);
 void mgs_ir_notify_complete(struct fs_db *fsdb);
 int  mgs_get_ir_logs(struct ptlrpc_request *req);
 int  lprocfs_wr_ir_state(struct file *file, const char *buffer,
@@ -211,7 +218,8 @@ int  lprocfs_rd_ir_timeout(char *page, char **start, off_t off, int count,
                            int *eof, void *data);
 void mgs_fsc_cleanup(struct obd_export *exp);
 void mgs_fsc_cleanup_by_fsdb(struct fs_db *fsdb);
-int  mgs_fsc_attach(struct obd_export *exp, char *fsname);
+int  mgs_fsc_attach(const struct lu_env *env, struct obd_export *exp,
+                   char *fsname);
 
 /* mgs_fs.c */
 int mgs_export_stats_init(struct obd_device *obd, struct obd_export *exp,
@@ -222,19 +230,19 @@ int mgs_fs_cleanup(struct obd_device *obddev);
 
 #define strsuf(buf, suffix) (strcmp((buf)+strlen(buf)-strlen(suffix), (suffix)))
 #ifdef LPROCFS
-int lproc_mgs_setup(struct obd_device *dev);
-int lproc_mgs_cleanup(struct obd_device *obd);
-int lproc_mgs_add_live(struct obd_device *obd, struct fs_db *fsdb);
-int lproc_mgs_del_live(struct obd_device *obd, struct fs_db *fsdb);
+int lproc_mgs_setup(struct mgs_device *mgs);
+int lproc_mgs_cleanup(struct mgs_device *mgs);
+int lproc_mgs_add_live(struct mgs_device *mgs, struct fs_db *fsdb);
+int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb);
 void lprocfs_mgs_init_vars(struct lprocfs_static_vars *lvars);
 #else
 static inline int lproc_mgs_setup(struct obd_device *dev)
 {return 0;}
 static inline int lproc_mgs_cleanup(struct obd_device *obd)
 {return 0;}
-static inline int lproc_mgs_add_live(struct obd_device *obd, struct fs_db *fsdb)
+static inline int lproc_mgs_add_live(struct mgs_device *obd, struct fs_db *fsdb)
 {return 0;}
-static inline int lproc_mgs_del_live(struct obd_device *obd, struct fs_db *fsdb)
+static inline int lproc_mgs_del_live(struct mgs_device *obd, struct fs_db *fsdb)
 {return 0;}
 static void lprocfs_mgs_init_vars(struct lprocfs_static_vars *lvars)
 {
@@ -254,4 +262,9 @@ enum {
 void mgs_counter_incr(struct obd_export *exp, int opcode);
 void mgs_stats_counter_init(struct lprocfs_stats *stats);
 
+static inline struct mgs_device *exp2mgs_dev(struct obd_export *exp)
+{
+       return &exp->exp_obd->u.mgs;
+}
+
 #endif /* _MGS_INTERNAL_H */
index afb1e6b..d1a9b2c 100644 (file)
@@ -66,9 +66,9 @@
 /********************** 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,
-                                cfs_list_t *dentry_list){
+int class_dentry_readdir(const struct lu_env *env,
+                        struct mgs_device *mgs, cfs_list_t *dentry_list)
+{
         /* see mds_cleanup_pending */
         struct lvfs_run_ctxt saved;
         struct file *file;
@@ -77,11 +77,11 @@ int class_dentry_readdir(struct obd_device *obd, struct dentry *dir,
         int rc = 0;
         ENTRY;
 
-        push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-        dentry = dget(dir);
+       push_ctxt(&saved, &mgs->mgs_obd->obd_lvfs_ctxt, NULL);
+       dentry = dget(mgs->mgs_configs_dir);
         if (IS_ERR(dentry))
                 GOTO(out_pop, rc = PTR_ERR(dentry));
-        mnt = mntget(inmnt);
+       mnt = mntget(mgs->mgs_vfsmnt);
         if (IS_ERR(mnt)) {
                 l_dput(dentry);
                 GOTO(out_pop, rc = PTR_ERR(mnt));
@@ -98,7 +98,7 @@ int class_dentry_readdir(struct obd_device *obd, struct dentry *dir,
         /*  filp_close->fput() drops the dentry, mnt refs */
 
 out_pop:
-        pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+       pop_ctxt(&saved, &mgs->mgs_obd->obd_lvfs_ctxt, NULL);
         RETURN(rc);
 }
 
@@ -261,7 +261,9 @@ static int mgs_fsdb_handler(const struct lu_env *env, struct llog_handle *llh,
 }
 
 /* fsdb->fsdb_mutex is already held  in mgs_find_or_make_fsdb*/
-static int mgs_get_fsdb_from_llog(struct obd_device *obd, struct fs_db *fsdb)
+static int mgs_get_fsdb_from_llog(const struct lu_env *env,
+                                 struct mgs_device *mgs,
+                                 struct fs_db *fsdb)
 {
         char *logname;
         struct llog_handle *loghandle;
@@ -271,11 +273,11 @@ static int mgs_get_fsdb_from_llog(struct obd_device *obd, struct fs_db *fsdb)
         int rc, rc2;
         ENTRY;
 
-        ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
+       ctxt = llog_get_context(mgs->mgs_obd, LLOG_CONFIG_ORIG_CTXT);
         LASSERT(ctxt != NULL);
         name_create(&logname, fsdb->fsdb_name, "-client");
         cfs_mutex_lock(&fsdb->fsdb_mutex);
-        push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+       push_ctxt(&saved, &mgs->mgs_obd->obd_lvfs_ctxt, NULL);
        rc = llog_open_create(NULL, ctxt, &loghandle, NULL, logname);
        if (rc)
                GOTO(out_pop, rc);
@@ -294,7 +296,7 @@ out_close:
         if (!rc)
                 rc = rc2;
 out_pop:
-        pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+       pop_ctxt(&saved, &mgs->mgs_obd->obd_lvfs_ctxt, NULL);
         cfs_mutex_unlock(&fsdb->fsdb_mutex);
         name_destroy(&logname);
         llog_ctxt_put(ctxt);
@@ -322,9 +324,8 @@ static void mgs_free_fsdb_srpc(struct fs_db *fsdb)
         sptlrpc_rule_set_free(&fsdb->fsdb_srpc_gen);
 }
 
-struct fs_db *mgs_find_fsdb(struct obd_device *obd, char *fsname)
+struct fs_db *mgs_find_fsdb(struct mgs_device *mgs, char *fsname)
 {
-        struct mgs_obd *mgs = &obd->u.mgs;
         struct fs_db *fsdb;
         cfs_list_t *tmp;
 
@@ -337,9 +338,9 @@ struct fs_db *mgs_find_fsdb(struct obd_device *obd, char *fsname)
 }
 
 /* caller must hold the mgs->mgs_fs_db_lock */
-static struct fs_db *mgs_new_fsdb(struct obd_device *obd, char *fsname)
+static struct fs_db *mgs_new_fsdb(const struct lu_env *env,
+                                 struct mgs_device *mgs, char *fsname)
 {
-        struct mgs_obd *mgs = &obd->u.mgs;
         struct fs_db *fsdb;
         int rc;
         ENTRY;
@@ -381,9 +382,9 @@ static struct fs_db *mgs_new_fsdb(struct obd_device *obd, char *fsname)
                         GOTO(err, rc);
 
                 /* initialise data for NID table */
-                mgs_ir_init_fs(obd, fsdb);
+               mgs_ir_init_fs(env, mgs, fsdb);
 
-                lproc_mgs_add_live(obd, fsdb);
+               lproc_mgs_add_live(mgs, fsdb);
         }
 
         cfs_list_add(&fsdb->fsdb_list, &mgs->mgs_fs_db_list);
@@ -402,15 +403,15 @@ err:
         RETURN(NULL);
 }
 
-static void mgs_free_fsdb(struct obd_device *obd, struct fs_db *fsdb)
+static void mgs_free_fsdb(struct mgs_device *mgs, struct fs_db *fsdb)
 {
         /* wait for anyone with the sem */
         cfs_mutex_lock(&fsdb->fsdb_mutex);
-        lproc_mgs_del_live(obd, fsdb);
+       lproc_mgs_del_live(mgs, fsdb);
         cfs_list_del(&fsdb->fsdb_list);
 
         /* deinitialize fsr */
-        mgs_ir_fini_fs(obd, fsdb);
+       mgs_ir_fini_fs(mgs, fsdb);
 
         if (fsdb->fsdb_ost_index_map)
                 OBD_FREE(fsdb->fsdb_ost_index_map, INDEX_MAP_SIZE);
@@ -426,36 +427,34 @@ static void mgs_free_fsdb(struct obd_device *obd, struct fs_db *fsdb)
         OBD_FREE_PTR(fsdb);
 }
 
-int mgs_init_fsdb_list(struct obd_device *obd)
+int mgs_init_fsdb_list(struct mgs_device *mgs)
 {
-        struct mgs_obd *mgs = &obd->u.mgs;
         CFS_INIT_LIST_HEAD(&mgs->mgs_fs_db_list);
         return 0;
 }
 
-int mgs_cleanup_fsdb_list(struct obd_device *obd)
+int mgs_cleanup_fsdb_list(struct mgs_device *mgs)
 {
-        struct mgs_obd *mgs = &obd->u.mgs;
         struct fs_db *fsdb;
         cfs_list_t *tmp, *tmp2;
         cfs_mutex_lock(&mgs->mgs_mutex);
         cfs_list_for_each_safe(tmp, tmp2, &mgs->mgs_fs_db_list) {
                 fsdb = cfs_list_entry(tmp, struct fs_db, fsdb_list);
-                mgs_free_fsdb(obd, fsdb);
+               mgs_free_fsdb(mgs, fsdb);
         }
         cfs_mutex_unlock(&mgs->mgs_mutex);
         return 0;
 }
 
-int mgs_find_or_make_fsdb(struct obd_device *obd, char *name,
+int mgs_find_or_make_fsdb(const struct lu_env *env,
+                         struct mgs_device *mgs, char *name,
                           struct fs_db **dbh)
 {
-        struct mgs_obd *mgs = &obd->u.mgs;
         struct fs_db *fsdb;
         int rc = 0;
 
         cfs_mutex_lock(&mgs->mgs_mutex);
-        fsdb = mgs_find_fsdb(obd, name);
+       fsdb = mgs_find_fsdb(mgs, name);
         if (fsdb) {
                 cfs_mutex_unlock(&mgs->mgs_mutex);
                 *dbh = fsdb;
@@ -463,26 +462,26 @@ 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);
+       fsdb = mgs_new_fsdb(env, mgs, name);
         cfs_mutex_unlock(&mgs->mgs_mutex);
         if (!fsdb)
                 return -ENOMEM;
 
         if (!cfs_test_bit(FSDB_MGS_SELF, &fsdb->fsdb_flags)) {
                 /* populate the db from the client llog */
-                rc = mgs_get_fsdb_from_llog(obd, fsdb);
+               rc = mgs_get_fsdb_from_llog(env, mgs, fsdb);
                 if (rc) {
                         CERROR("Can't get db from client log %d\n", rc);
-                        mgs_free_fsdb(obd, fsdb);
+                       mgs_free_fsdb(mgs, fsdb);
                         return rc;
                 }
         }
 
         /* populate srpc rules from params llog */
-        rc = mgs_get_fsdb_srpc_from_llog(obd, fsdb);
+       rc = mgs_get_fsdb_srpc_from_llog(env, mgs, fsdb);
         if (rc) {
                 CERROR("Can't get db from params log %d\n", rc);
-                mgs_free_fsdb(obd, fsdb);
+               mgs_free_fsdb(mgs, fsdb);
                 return rc;
         }
 
@@ -494,7 +493,9 @@ int mgs_find_or_make_fsdb(struct obd_device *obd, char *name,
 /* 1 = index in use
    0 = index unused
    -1= empty client log */
-int mgs_check_index(struct obd_device *obd, struct mgs_target_info *mti)
+int mgs_check_index(const struct lu_env *env,
+                   struct mgs_device *mgs,
+                   struct mgs_target_info *mti)
 {
         struct fs_db *fsdb;
         void *imap;
@@ -503,7 +504,7 @@ 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(env, mgs, mti->mti_fsname, &fsdb);
         if (rc) {
                 CERROR("Can't get db for %s\n", mti->mti_fsname);
                 RETURN(rc);
@@ -539,14 +540,16 @@ static __inline__ int next_index(void *index_map, int map_len)
         0  newly marked as in use
         <0 err
         +EALREADY for update of an old index */
-static int mgs_set_index(struct obd_device *obd, struct mgs_target_info *mti)
+static int mgs_set_index(const struct lu_env *env,
+                        struct mgs_device *mgs,
+                        struct mgs_target_info *mti)
 {
         struct fs_db *fsdb;
         void *imap;
         int rc = 0;
         ENTRY;
 
-        rc = mgs_find_or_make_fsdb(obd, mti->mti_fsname, &fsdb);
+       rc = mgs_find_or_make_fsdb(env, mgs, mti->mti_fsname, &fsdb);
         if (rc) {
                 CERROR("Can't get db for %s\n", mti->mti_fsname);
                 RETURN(rc);
@@ -667,9 +670,9 @@ static int mgs_modify_handler(const struct lu_env *env,
 }
 
 /* Modify an existing config log record (for CM_SKIP or CM_EXCLUDE) */
-static int mgs_modify(struct obd_device *obd, struct fs_db *fsdb,
-                      struct mgs_target_info *mti, char *logname,
-                      char *devname, char *comment, int flags)
+static int mgs_modify(const struct lu_env *env, struct mgs_device *mgs,
+                     struct fs_db *fsdb, struct mgs_target_info *mti,
+                     char *logname, char *devname, char *comment, int flags)
 {
         struct llog_handle *loghandle;
         struct lvfs_run_ctxt saved;
@@ -681,9 +684,9 @@ static int mgs_modify(struct obd_device *obd, struct fs_db *fsdb,
         CDEBUG(D_MGS, "modify %s/%s/%s fl=%x\n", logname, devname, comment,
                flags);
 
-        ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
+       ctxt = llog_get_context(mgs->mgs_obd, LLOG_CONFIG_ORIG_CTXT);
         LASSERT(ctxt != NULL);
-       push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+       push_ctxt(&saved, &mgs->mgs_obd->obd_lvfs_ctxt, NULL);
        rc = llog_open(NULL, ctxt, &loghandle, NULL, logname,
                       LLOG_OPEN_EXISTS);
        if (rc < 0) {
@@ -719,7 +722,7 @@ out_close:
         if (!rc)
                 rc = rc2;
 out_pop:
-        pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+       pop_ctxt(&saved, &mgs->mgs_obd->obd_lvfs_ctxt, NULL);
         if (rc && rc != -ENODEV)
                 CERROR("modify %s/%s failed %d\n",
                        mti->mti_svname, comment, rc);
@@ -729,12 +732,13 @@ out_pop:
 
 /******************** config log recording functions *********************/
 
-static int record_lcfg(struct obd_device *obd, struct llog_handle *llh,
+static int record_lcfg(const struct lu_env *env, struct llog_handle *llh,
                          struct lustre_cfg *lcfg)
 {
         struct lvfs_run_ctxt   saved;
         struct llog_rec_hdr    rec;
         int buflen, rc;
+       struct obd_device *obd = llh->lgh_ctxt->loc_obd;
 
         if (!lcfg || !llh)
                 return -ENOMEM;
@@ -755,7 +759,7 @@ static int record_lcfg(struct obd_device *obd, struct llog_handle *llh,
         return rc;
 }
 
-static int record_base(struct obd_device *obd, struct llog_handle *llh,
+static int record_base(const struct lu_env *env, struct llog_handle *llh,
                      char *cfgname, lnet_nid_t nid, int cmd,
                      char *s1, char *s2, char *s3, char *s4)
 {
@@ -781,7 +785,7 @@ static int record_base(struct obd_device *obd, struct llog_handle *llh,
                 return -ENOMEM;
         lcfg->lcfg_nid = nid;
 
-        rc = record_lcfg(obd, llh, lcfg);
+       rc = record_lcfg(env, llh, lcfg);
 
         lustre_cfg_free(lcfg);
 
@@ -793,37 +797,37 @@ static int record_base(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)
+static inline int record_add_uuid(const struct lu_env *env,
+                                 struct llog_handle *llh,
+                                 uint64_t nid, char *uuid)
 {
-        return record_base(obd,llh,NULL,nid,LCFG_ADD_UUID,uuid,0,0,0);
+       return record_base(env, llh, NULL, nid, LCFG_ADD_UUID, uuid, 0, 0, 0);
 
 }
 
-static inline int record_add_conn(struct obd_device *obd,
-                                  struct llog_handle *llh,
-                                  char *devname,
-                                  char *uuid)
+static inline int record_add_conn(const struct lu_env *env,
+                                 struct llog_handle *llh,
+                                 char *devname, char *uuid)
 {
-        return record_base(obd,llh,devname,0,LCFG_ADD_CONN,uuid,0,0,0);
+       return record_base(env, llh, devname, 0, LCFG_ADD_CONN, uuid, 0, 0, 0);
 }
 
-static inline int record_attach(struct obd_device *obd, struct llog_handle *llh,
-                                char *devname, char *type, char *uuid)
+static inline int record_attach(const struct lu_env *env,
+                               struct llog_handle *llh, char *devname,
+                               char *type, char *uuid)
 {
-        return record_base(obd,llh,devname,0,LCFG_ATTACH,type,uuid,0,0);
+       return record_base(env, llh,devname, 0, LCFG_ATTACH, type, uuid, 0, 0);
 }
 
-static inline int record_setup(struct obd_device *obd, struct llog_handle *llh,
-                               char *devname,
-                               char *s1, char *s2, char *s3, char *s4)
+static inline int record_setup(const struct lu_env *env,
+                              struct llog_handle *llh, char *devname,
+                              char *s1, char *s2, char *s3, char *s4)
 {
-        return record_base(obd,llh,devname,0,LCFG_SETUP,s1,s2,s3,s4);
+       return record_base(env, llh, devname, 0, LCFG_SETUP, s1, s2, s3, s4);
 }
 
-static int record_lov_setup(struct obd_device *obd, struct llog_handle *llh,
-                            char *devname, struct lov_desc *desc)
+static int record_lov_setup(const struct lu_env *env, struct llog_handle *llh,
+                           char *devname, struct lov_desc *desc)
 {
         struct lustre_cfg_bufs bufs;
         struct lustre_cfg *lcfg;
@@ -834,13 +838,13 @@ static int record_lov_setup(struct obd_device *obd, struct llog_handle *llh,
         lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
         if (!lcfg)
                 return -ENOMEM;
-        rc = record_lcfg(obd, llh, lcfg);
+       rc = record_lcfg(env, llh, lcfg);
 
         lustre_cfg_free(lcfg);
         return rc;
 }
 
-static int record_lmv_setup(struct obd_device *obd, struct llog_handle *llh,
+static int record_lmv_setup(const struct lu_env *env, struct llog_handle *llh,
                             char *devname, struct lmv_desc *desc)
 {
         struct lustre_cfg_bufs bufs;
@@ -851,41 +855,42 @@ static int record_lmv_setup(struct obd_device *obd, struct llog_handle *llh,
         lustre_cfg_bufs_set(&bufs, 1, desc, sizeof(*desc));
         lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
 
-        rc = record_lcfg(obd, llh, lcfg);
+       rc = record_lcfg(env, llh, lcfg);
 
         lustre_cfg_free(lcfg);
         return rc;
 }
 
-static inline int record_mdc_add(struct obd_device *obd,
+static inline int record_mdc_add(const struct lu_env *env,
                                  struct llog_handle *llh,
                                  char *logname, char *mdcuuid,
                                  char *mdtuuid, char *index,
                                  char *gen)
 {
-        return record_base(obd,llh,logname,0,LCFG_ADD_MDC,
+       return record_base(env,llh,logname,0,LCFG_ADD_MDC,
                            mdtuuid,index,gen,mdcuuid);
 }
 
-static inline int record_lov_add(struct obd_device *obd,
+static inline int record_lov_add(const struct lu_env *env,
                                  struct llog_handle *llh,
                                  char *lov_name, char *ost_uuid,
                                  char *index, char *gen)
 {
-        return record_base(obd,llh,lov_name,0,LCFG_LOV_ADD_OBD,
+       return record_base(env,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(const struct lu_env *env,
                                    struct llog_handle *llh,
                                    char *profile, char *lov_name,
                                    char *mdc_name)
 {
-        return record_base(obd,llh,NULL,0,LCFG_MOUNTOPT,
+       return record_base(env,llh,NULL,0,LCFG_MOUNTOPT,
                            profile,lov_name,mdc_name,0);
 }
 
-static int record_marker(struct obd_device *obd, struct llog_handle *llh,
+static int record_marker(const struct lu_env *env,
+                        struct llog_handle *llh,
                          struct fs_db *fsdb, __u32 flags,
                          char *tgtname, char *comment)
 {
@@ -908,13 +913,14 @@ static int record_marker(struct obd_device *obd, struct llog_handle *llh,
         lcfg = lustre_cfg_new(LCFG_MARKER, &bufs);
         if (!lcfg)
                 return -ENOMEM;
-        rc = record_lcfg(obd, llh, lcfg);
+       rc = record_lcfg(env, llh, lcfg);
 
         lustre_cfg_free(lcfg);
         return rc;
 }
 
-static int record_start_log(struct obd_device *obd,
+static int record_start_log(const struct lu_env *env,
+                           struct mgs_device *mgs,
                             struct llog_handle **llh, char *name)
 {
         static struct obd_uuid cfg_uuid = { .uuid = "config_uuid" };
@@ -925,11 +931,12 @@ static int record_start_log(struct obd_device *obd,
         if (*llh)
                 GOTO(out, rc = -EBUSY);
 
-        ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
+       ctxt = llog_get_context(mgs->mgs_obd, LLOG_CONFIG_ORIG_CTXT);
         if (!ctxt)
                 GOTO(out, rc = -ENODEV);
+       LASSERT(ctxt->loc_obd == mgs->mgs_obd);
 
-        push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+       push_ctxt(&saved, &mgs->mgs_obd->obd_lvfs_ctxt, NULL);
        rc = llog_open_create(NULL, ctxt, llh, NULL, name);
        if (rc)
                GOTO(out_ctxt, rc);
@@ -939,7 +946,7 @@ static int record_start_log(struct obd_device *obd,
                *llh = NULL;
        }
 out_ctxt:
-       pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+       pop_ctxt(&saved, &mgs->mgs_obd->obd_lvfs_ctxt, NULL);
        llog_ctxt_put(ctxt);
 out:
        if (rc)
@@ -947,9 +954,10 @@ out:
        RETURN(rc);
 }
 
-static int record_end_log(struct obd_device *obd, struct llog_handle **llh)
+static int record_end_log(const struct lu_env *env, struct llog_handle **llh)
 {
         struct lvfs_run_ctxt saved;
+       struct obd_device *obd = (*llh)->lgh_ctxt->loc_obd;
         int rc = 0;
 
         push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
@@ -961,16 +969,17 @@ static int record_end_log(struct obd_device *obd, struct llog_handle **llh)
         RETURN(rc);
 }
 
-static int mgs_log_is_empty(struct obd_device *obd, char *name)
+static int mgs_log_is_empty(const struct lu_env *env,
+                           struct mgs_device *mgs, char *name)
 {
         struct lvfs_run_ctxt saved;
         struct llog_handle *llh;
         struct llog_ctxt *ctxt;
         int rc = 0;
 
-        ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
+       ctxt = llog_get_context(mgs->mgs_obd, LLOG_CONFIG_ORIG_CTXT);
         LASSERT(ctxt != NULL);
-        push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+       push_ctxt(&saved, &mgs->mgs_obd->obd_lvfs_ctxt, NULL);
        rc = llog_open(NULL, ctxt, &llh, NULL, name, LLOG_OPEN_EXISTS);
        if (rc < 0) {
                if (rc == -ENOENT)
@@ -986,7 +995,7 @@ static int mgs_log_is_empty(struct obd_device *obd, char *name)
 out_close:
        llog_close(NULL, llh);
 out_ctxt:
-       pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+       pop_ctxt(&saved, &mgs->mgs_obd->obd_lvfs_ctxt, NULL);
        llog_ctxt_put(ctxt);
        /* header is record 1 */
        return (rc <= 1);
@@ -995,7 +1004,8 @@ out_ctxt:
 /******************** config "macros" *********************/
 
 /* write an lcfg directly into a log (with markers) */
-static int mgs_write_log_direct(struct obd_device *obd, struct fs_db *fsdb,
+static int mgs_write_log_direct(const struct lu_env *env,
+                               struct mgs_device *mgs, struct fs_db *fsdb,
                                 char *logname, struct lustre_cfg *lcfg,
                                 char *devname, char *comment)
 {
@@ -1006,29 +1016,30 @@ static int mgs_write_log_direct(struct obd_device *obd, struct fs_db *fsdb,
         if (!lcfg)
                 RETURN(-ENOMEM);
 
-        rc = record_start_log(obd, &llh, logname);
+       rc = record_start_log(env, mgs, &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_marker(env, llh, fsdb, CM_START, devname, comment);
 
-        rc = record_lcfg(obd, llh, lcfg);
+       rc = record_lcfg(env, llh, lcfg);
 
-        rc = record_marker(obd, llh, fsdb, CM_END, devname, comment);
-        rc = record_end_log(obd, &llh);
+       rc = record_marker(env, llh, fsdb, CM_END, devname, comment);
+       rc = record_end_log(env, &llh);
 
         RETURN(rc);
 }
 
 /* write the lcfg in all logs for the given fs */
-int mgs_write_log_direct_all(struct obd_device *obd, struct fs_db *fsdb,
+int mgs_write_log_direct_all(const struct lu_env *env,
+                            struct mgs_device *mgs,
+                            struct fs_db *fsdb,
                             struct mgs_target_info *mti,
                             struct lustre_cfg *lcfg,
                             char *devname, char *comment,
                             int server_only)
 {
-        struct mgs_obd *mgs = &obd->u.mgs;
         cfs_list_t dentry_list;
         struct l_linux_dirent *dirent, *n;
         char *fsname = mti->mti_fsname;
@@ -1041,18 +1052,17 @@ int mgs_write_log_direct_all(struct obd_device *obd, struct fs_db *fsdb,
            Actually, we should store as params (text), not llogs.  Or
            in a database. */
         name_create(&logname, fsname, "-params");
-        if (mgs_log_is_empty(obd, logname)) {
-                struct llog_handle *llh = NULL;
-                rc = record_start_log(obd, &llh, logname);
-                record_end_log(obd, &llh);
+       if (mgs_log_is_empty(env, mgs, logname)) {
+               struct llog_handle *llh = NULL;
+               rc = record_start_log(env, mgs, &llh, logname);
+               record_end_log(env, &llh);
         }
         name_destroy(&logname);
         if (rc)
                 RETURN(rc);
 
         /* Find all the logs in the CONFIGS directory */
-        rc = class_dentry_readdir(obd, mgs->mgs_configs_dir,
-                                  mgs->mgs_vfsmnt, &dentry_list);
+       rc = class_dentry_readdir(env, mgs, &dentry_list);
         if (rc) {
                 CERROR("Can't read %s dir\n", MOUNT_CONFIGS_DIR);
                 RETURN(rc);
@@ -1072,11 +1082,11 @@ int mgs_write_log_direct_all(struct obd_device *obd, struct fs_db *fsdb,
                if (strncmp(fsname, dirent->lld_name, len) == 0) {
                         CDEBUG(D_MGS, "Changing log %s\n", dirent->lld_name);
                         /* Erase any old settings of this same parameter */
-                        mgs_modify(obd, fsdb, mti, dirent->lld_name, devname,
-                                   comment, CM_SKIP);
+                       mgs_modify(env, mgs, fsdb, mti, dirent->lld_name,
+                                  devname, comment, CM_SKIP);
                         /* Write the new one */
                         if (lcfg) {
-                                rc = mgs_write_log_direct(obd, fsdb,
+                               rc = mgs_write_log_direct(env, mgs, fsdb,
                                                           dirent->lld_name,
                                                           lcfg, devname,
                                                           comment);
@@ -1097,12 +1107,18 @@ 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 mgs_device        *comp_mgs;
+       const struct lu_env      *comp_env;
 };
 
-static int mgs_write_log_mdc_to_mdt(struct obd_device *, struct fs_db *,
-                                    struct mgs_target_info *, char *);
-static int mgs_write_log_osc_to_lov(struct obd_device *obd, struct fs_db *fsdb,
+static int mgs_write_log_mdc_to_mdt(const struct lu_env *env,
+                                   struct mgs_device *mgs,
+                                   struct fs_db *fsdb,
+                                   struct mgs_target_info *mti,
+                                   char *logname);
+static int mgs_write_log_osc_to_lov(const struct lu_env *env,
+                                   struct mgs_device *mgs,
+                                   struct fs_db *fsdb,
                                     struct mgs_target_info *mti,
                                     char *logname, char *suffix, char *lovname,
                                     enum lustre_sec_part sec_part, int flags);
@@ -1113,7 +1129,7 @@ static int mgs_steal_llog_handler(const struct lu_env *env,
                                  struct llog_handle *llh,
                                  struct llog_rec_hdr *rec, void *data)
 {
-        struct obd_device * obd;
+       struct mgs_device *mgs;
         struct mgs_target_info *mti, *tmti;
         struct fs_db *fsdb;
         int cfg_len = rec->lrh_len;
@@ -1133,7 +1149,7 @@ static int mgs_steal_llog_handler(const struct lu_env *env,
         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;
+       mgs = ((struct temp_comp*)data)->comp_mgs;
 
         if (rec->lrh_type != OBD_CFG_REC) {
                 CERROR("unhandled lrh_type: %#x\n", rec->lrh_type);
@@ -1156,10 +1172,11 @@ static int mgs_steal_llog_handler(const struct lu_env *env,
                         got_an_osc_or_mdc = 1;
                         strncpy(tmti->mti_svname, marker->cm_tgtname,
                                 sizeof(tmti->mti_svname));
-                        rc = record_start_log(obd, &mdt_llh, mti->mti_svname);
-                        rc = record_marker(obd, mdt_llh, fsdb, CM_START,
+                       rc = record_start_log(env, mgs, &mdt_llh,
+                                             mti->mti_svname);
+                       rc = record_marker(env, mdt_llh, fsdb, CM_START,
                                            mti->mti_svname,"add osc(copied)");
-                        rc = record_end_log(obd, &mdt_llh);
+                       rc = record_end_log(env, &mdt_llh);
                         last_step = marker->cm_step;
                         RETURN(rc);
                 }
@@ -1168,10 +1185,11 @@ static int mgs_steal_llog_handler(const struct lu_env *env,
                         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,
+                       rc = record_start_log(env, mgs, &mdt_llh,
+                                             mti->mti_svname);
+                       rc = record_marker(env, mdt_llh, fsdb, CM_END,
                                            mti->mti_svname,"add osc(copied)");
-                        rc = record_end_log(obd, &mdt_llh);
+                       rc = record_end_log(env, &mdt_llh);
                         RETURN(rc);
                 }
                 if (!strncmp(marker->cm_comment,"add mdc",7) &&
@@ -1227,7 +1245,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(obd, fsdb, tmti, mti->mti_svname);
+               mgs_write_log_mdc_to_mdt(env, mgs, fsdb,
+                                        tmti, mti->mti_svname);
                 memset(tmti, 0, sizeof(*tmti));
                 RETURN(rc);
         }
@@ -1248,7 +1267,7 @@ static int mgs_steal_llog_handler(const struct lu_env *env,
                 }
 
                 tmti->mti_stripe_index = index;
-                mgs_write_log_osc_to_lov(obd, fsdb, tmti, logname,
+               mgs_write_log_osc_to_lov(env, mgs, fsdb, tmti, logname,
                                          mdt_index, lovname,
                                          LUSTRE_SP_MDT, 0);
                 name_destroy(&logname);
@@ -1260,7 +1279,8 @@ static int mgs_steal_llog_handler(const struct lu_env *env,
 
 /* fsdb->fsdb_mutex 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,
+static int mgs_steal_llog_for_mdt_from_client(const struct lu_env *env,
+                                             struct mgs_device *mgs,
                                               char *client_name,
                                               struct temp_comp* comp)
 {
@@ -1272,7 +1292,7 @@ static int mgs_steal_llog_for_mdt_from_client(struct obd_device *obd,
 
         ENTRY;
 
-        ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
+       ctxt = llog_get_context(mgs->mgs_obd, LLOG_CONFIG_ORIG_CTXT);
         LASSERT(ctxt != NULL);
 
         OBD_ALLOC_PTR(tmti);
@@ -1280,9 +1300,9 @@ static int mgs_steal_llog_for_mdt_from_client(struct obd_device *obd,
                GOTO(out_ctxt, rc = -ENOMEM);
 
        comp->comp_tmti = tmti;
-       comp->comp_obd = obd;
+       comp->comp_mgs = mgs;
 
-       push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+       push_ctxt(&saved, &mgs->mgs_obd->obd_lvfs_ctxt, NULL);
 
        rc = llog_open(NULL, ctxt, &loghandle, NULL, client_name,
                       LLOG_OPEN_EXISTS);
@@ -1302,7 +1322,7 @@ static int mgs_steal_llog_for_mdt_from_client(struct obd_device *obd,
 out_close:
        llog_close(NULL, loghandle);
 out_pop:
-       pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+       pop_ctxt(&saved, &mgs->mgs_obd->obd_lvfs_ctxt, NULL);
        OBD_FREE_PTR(tmti);
 out_ctxt:
        llog_ctxt_put(ctxt);
@@ -1311,7 +1331,9 @@ out_ctxt:
 
 /* 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,
+static int mgs_write_log_lmv(const struct lu_env *env,
+                            struct mgs_device *mgs,
+                            struct fs_db *fsdb,
                              struct mgs_target_info *mti,
                              char *logname, char *lmvname)
 {
@@ -1331,20 +1353,20 @@ static int mgs_write_log_lmv(struct obd_device *obd, struct fs_db *fsdb,
         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);
+       rc = record_start_log(env, mgs, &llh, logname);
+       rc = record_marker(env, llh, fsdb, CM_START, lmvname, "lmv setup");
+       rc = record_attach(env, llh, lmvname, "lmv", uuid);
+       rc = record_lmv_setup(env, llh, lmvname, lmvdesc);
+       rc = record_marker(env, llh, fsdb, CM_END, lmvname, "lmv setup");
+       rc = record_end_log(env, &llh);
 
         OBD_FREE_PTR(lmvdesc);
         RETURN(rc);
 }
 
 /* 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,
-                             struct mgs_target_info *mti,
+static int mgs_write_log_lov(const struct lu_env *env, struct mgs_device *mgs,
+                            struct fs_db *fsdb, struct mgs_target_info *mti,
                              char *logname, char *lovname)
 {
         struct llog_handle *llh = NULL;
@@ -1379,15 +1401,15 @@ static int mgs_write_log_lov(struct obd_device *obd, struct fs_db *fsdb,
 
         /* This should always be the first entry in a log.
         rc = mgs_clear_log(obd, logname); */
-        rc = record_start_log(obd, &llh, logname);
+       rc = record_start_log(env, mgs, &llh, logname);
         if (rc)
                 GOTO(out, rc);
         /* FIXME these should be a single journal transaction */
-        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_end_log(obd, &llh);
+       rc = record_marker(env, llh, fsdb, CM_START, lovname, "lov setup");
+       rc = record_attach(env, llh, lovname, "lov", uuid);
+       rc = record_lov_setup(env, llh, lovname, lovdesc);
+       rc = record_marker(env, llh, fsdb, CM_END, lovname, "lov setup");
+       rc = record_end_log(env, &llh);
 
         EXIT;
 out:
@@ -1396,7 +1418,7 @@ out:
 }
 
 /* add failnids to open log */
-static int mgs_write_log_failnids(struct obd_device *obd,
+static int mgs_write_log_failnids(const struct lu_env *env,
                                   struct mgs_target_info *mti,
                                   struct llog_handle *llh,
                                   char *cliname)
@@ -1429,10 +1451,10 @@ static int mgs_write_log_failnids(struct obd_device *obd,
                         CDEBUG(D_MGS, "add nid %s for failover uuid %s, "
                                "client %s\n", libcfs_nid2str(nid),
                                failnodeuuid, cliname);
-                        rc = record_add_uuid(obd, llh, nid, failnodeuuid);
+                       rc = record_add_uuid(env, llh, nid, failnodeuuid);
                 }
                 if (failnodeuuid) {
-                        rc = record_add_conn(obd, llh, cliname, failnodeuuid);
+                       rc = record_add_conn(env, llh, cliname, failnodeuuid);
                         name_destroy(&failnodeuuid);
                         failnodeuuid = NULL;
                 }
@@ -1441,7 +1463,9 @@ static int mgs_write_log_failnids(struct obd_device *obd,
         return rc;
 }
 
-static int mgs_write_log_mdc_to_lmv(struct obd_device *obd, struct fs_db *fsdb,
+static int mgs_write_log_mdc_to_lmv(const struct lu_env *env,
+                                   struct mgs_device *mgs,
+                                   struct fs_db *fsdb,
                                     struct mgs_target_info *mti,
                                     char *logname, char *lmvname)
 {
@@ -1451,7 +1475,7 @@ static int mgs_write_log_mdc_to_lmv(struct obd_device *obd, struct fs_db *fsdb,
         int i, rc;
         ENTRY;
 
-        if (mgs_log_is_empty(obd, logname)) {
+       if (mgs_log_is_empty(env, mgs, logname)) {
                 CERROR("log is empty! Logical error\n");
                 RETURN(-EINVAL);
         }
@@ -1464,26 +1488,26 @@ static int mgs_write_log_mdc_to_lmv(struct obd_device *obd, struct fs_db *fsdb,
         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,
+       rc = record_start_log(env, mgs, &llh, logname);
+       rc = record_marker(env, 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_add_uuid(env, 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 = mgs_write_log_failnids(obd, mti, llh, mdcname);
+       rc = record_attach(env, llh, mdcname, LUSTRE_MDC_NAME, lmvuuid);
+       rc = record_setup(env, llh, mdcname, mti->mti_uuid, nodeuuid, 0, 0);
+       rc = mgs_write_log_failnids(env, mti, llh, mdcname);
         snprintf(index, sizeof(index), "%d", mti->mti_stripe_index);
-        rc = record_mdc_add(obd, llh, lmvname, mdcuuid, mti->mti_uuid,
+       rc = record_mdc_add(env, llh, lmvname, mdcuuid, mti->mti_uuid,
                             index, "1");
-        rc = record_marker(obd, llh, fsdb, CM_END, mti->mti_svname,
+       rc = record_marker(env, llh, fsdb, CM_END, mti->mti_svname,
                            "add mdc");
-        rc = record_end_log(obd, &llh);
+       rc = record_end_log(env, &llh);
 
         name_destroy(&lmvuuid);
         name_destroy(&mdcuuid);
@@ -1493,8 +1517,11 @@ static int mgs_write_log_mdc_to_lmv(struct obd_device *obd, struct fs_db *fsdb,
 }
 
 /* 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, char *logname)
+static int mgs_write_log_mdc_to_mdt(const struct lu_env *env,
+                                   struct mgs_device *mgs,
+                                   struct fs_db *fsdb,
+                                   struct mgs_target_info *mti,
+                                   char *logname)
 {
         struct llog_handle *llh = NULL;
         char *nodeuuid, *mdcname, *mdcuuid, *mdtuuid;
@@ -1503,7 +1530,7 @@ static int mgs_write_log_mdc_to_mdt(struct obd_device *obd, struct fs_db *fsdb,
         int i, rc;
 
         ENTRY;
-        if (mgs_log_is_empty(obd, logname)) {
+       if (mgs_log_is_empty(env, mgs, logname)) {
                 CERROR("log is empty! Logical error\n");
                 RETURN (-EINVAL);
         }
@@ -1516,22 +1543,22 @@ static int mgs_write_log_mdc_to_mdt(struct obd_device *obd, struct fs_db *fsdb,
         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");
+       rc = record_start_log(env, mgs, &llh, logname);
+       rc = record_marker(env, 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_add_uuid(env, 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_attach(env, llh, mdcname, LUSTRE_MDC_NAME, mdcuuid);
+       rc = record_setup(env, llh, mdcname, mti->mti_uuid, nodeuuid, 0, 0);
+       rc = mgs_write_log_failnids(env, mti, llh, mdcname);
         snprintf(index, sizeof(index), "%d", idx);
 
-        rc = record_mdc_add(obd, llh, logname, mdcuuid, mti->mti_uuid,
+       rc = record_mdc_add(env, 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);
+       rc = record_marker(env, llh, fsdb, CM_END, mti->mti_svname, "add mdc");
+       rc = record_end_log(env, &llh);
 
         name_destroy(&mdcuuid);
         name_destroy(&mdcname);
@@ -1540,8 +1567,10 @@ static int mgs_write_log_mdc_to_mdt(struct obd_device *obd, struct fs_db *fsdb,
         RETURN(rc);
 }
 
-static int mgs_write_log_mdt0(struct obd_device *obd, struct fs_db *fsdb,
-                              struct mgs_target_info *mti)
+static int mgs_write_log_mdt0(const struct lu_env *env,
+                             struct mgs_device *mgs,
+                             struct fs_db *fsdb,
+                             struct mgs_target_info *mti)
 {
         char *log = mti->mti_svname;
         struct llog_handle *llh = NULL;
@@ -1559,25 +1588,25 @@ static int mgs_write_log_mdt0(struct obd_device *obd, struct fs_db *fsdb,
                 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);
+       if (mgs_log_is_empty(env, mgs, log))
+               rc = mgs_write_log_lov(env, mgs, 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);
+       rc = record_start_log(env, mgs, &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,
+       rc = record_marker(env, llh, fsdb, CM_START, log, "add mdt");
+       rc = record_attach(env, llh, log, LUSTRE_MDT_NAME, uuid);
+       rc = record_mount_opt(env, llh, log, lovname, NULL);
+       rc = record_setup(env, 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);
+       rc = record_marker(env, llh, fsdb, CM_END, log, "add mdt");
+       rc = record_end_log(env, &llh);
 out:
         name_destroy(&lovname);
         OBD_FREE(uuid, sizeof(struct obd_uuid));
@@ -1616,8 +1645,10 @@ static inline void name_create_mdt_osc(char **oscname, char *ostname,
 }
 
 /* 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)
+static int mgs_write_log_mdt(const struct lu_env *env,
+                            struct mgs_device *mgs,
+                            struct fs_db *fsdb,
+                            struct mgs_target_info *mti)
 {
         struct llog_handle *llh = NULL;
         char *cliname;
@@ -1650,16 +1681,16 @@ static int mgs_write_log_mdt(struct obd_device *obd, struct fs_db *fsdb,
         }
 
         /* add mdt */
-        rc = mgs_write_log_mdt0(obd, fsdb, mti);
+       rc = mgs_write_log_mdt0(env, mgs, fsdb, mti);
 
         /* Append the mdt info to the client log */
         name_create(&cliname, mti->mti_fsname, "-client");
 
-        if (mgs_log_is_empty(obd, cliname)) {
+       if (mgs_log_is_empty(env, mgs, cliname)) {
                 /* Start client log */
-                rc = mgs_write_log_lov(obd, fsdb, mti, cliname,
+               rc = mgs_write_log_lov(env, mgs, fsdb, mti, cliname,
                                        fsdb->fsdb_clilov);
-                rc = mgs_write_log_lmv(obd, fsdb, mti, cliname,
+               rc = mgs_write_log_lmv(env, mgs, fsdb, mti, cliname,
                                        fsdb->fsdb_clilmv);
         }
 
@@ -1700,25 +1731,25 @@ static int mgs_write_log_mdt(struct obd_device *obd, struct fs_db *fsdb,
                 comp.comp_mti = mti;
                 comp.comp_fsdb = fsdb;
 
-                rc = mgs_steal_llog_for_mdt_from_client(obd, cliname,
+               rc = mgs_steal_llog_for_mdt_from_client(env, mgs, cliname,
                                                         &comp);
 
-                rc = mgs_write_log_mdc_to_lmv(obd, fsdb, mti, cliname,
+               rc = mgs_write_log_mdc_to_lmv(env, mgs, fsdb, mti, cliname,
                                               fsdb->fsdb_clilmv);
                 /* add mountopts */
-                rc = record_start_log(obd, &llh, cliname);
+               rc = record_start_log(env, mgs, &llh, cliname);
                 if (rc)
                         GOTO(out, rc);
 
-                rc = record_marker(obd, llh, fsdb, CM_START, cliname,
+               rc = record_marker(env, llh, fsdb, CM_START, cliname,
                                    "mount opts");
-                rc = record_mount_opt(obd, llh, cliname, fsdb->fsdb_clilov,
+               rc = record_mount_opt(env, llh, cliname, fsdb->fsdb_clilov,
                                       fsdb->fsdb_clilmv);
-                rc = record_marker(obd, llh, fsdb, CM_END, cliname,
+               rc = record_marker(env, llh, fsdb, CM_END, cliname,
                                    "mount opts");
         }
 
-        rc = record_end_log(obd, &llh);
+       rc = record_end_log(env, &llh);
 out:
         name_destroy(&cliname);
 
@@ -1728,7 +1759,8 @@ out:
                 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(obd, fsdb, mti, mdtname);
+                       rc = mgs_write_log_mdc_to_mdt(env, mgs, fsdb,
+                                                     mti, mdtname);
                         name_destroy(&mdtname);
                 }
         }
@@ -1737,7 +1769,8 @@ out:
 }
 
 /* Add the ost info to the client/mdt lov */
-static int mgs_write_log_osc_to_lov(struct obd_device *obd, struct fs_db *fsdb,
+static int mgs_write_log_osc_to_lov(const struct lu_env *env,
+                                   struct mgs_device *mgs, struct fs_db *fsdb,
                                     struct mgs_target_info *mti,
                                     char *logname, char *suffix, char *lovname,
                                     enum lustre_sec_part sec_part, int flags)
@@ -1751,7 +1784,7 @@ static int mgs_write_log_osc_to_lov(struct obd_device *obd, struct fs_db *fsdb,
         CDEBUG(D_INFO, "adding osc for %s to log %s\n",
                mti->mti_svname, logname);
 
-        if (mgs_log_is_empty(obd, logname)) {
+       if (mgs_log_is_empty(env, mgs, logname)) {
                 CERROR("log is empty! Logical error\n");
                 RETURN (-EINVAL);
         }
@@ -1774,24 +1807,24 @@ static int mgs_write_log_osc_to_lov(struct obd_device *obd, struct fs_db *fsdb,
         #08 L lov_modify_tgts add 0:lov1  1:ost1_UUID  2(index):0  3(gen):1
         */
 
-        rc = record_start_log(obd, &llh, logname);
+       rc = record_start_log(env, mgs, &llh, logname);
         if (rc)
                 GOTO(out, rc);
         /* FIXME these should be a single journal transaction */
-        rc = record_marker(obd, llh, fsdb, CM_START | flags, mti->mti_svname,
+       rc = record_marker(env, llh, fsdb, CM_START | flags, mti->mti_svname,
                            "add osc");
         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_add_uuid(env, llh, mti->mti_nids[i], nodeuuid);
         }
-        rc = record_attach(obd, llh, oscname, LUSTRE_OSC_NAME, lovuuid);
-        rc = record_setup(obd, llh, oscname, mti->mti_uuid, nodeuuid, 0, 0);
-        rc = mgs_write_log_failnids(obd, mti, llh, oscname);
+       rc = record_attach(env, llh, oscname, LUSTRE_OSC_NAME, lovuuid);
+       rc = record_setup(env, llh, oscname, mti->mti_uuid, nodeuuid, 0, 0);
+       rc = mgs_write_log_failnids(env, mti, llh, oscname);
         snprintf(index, sizeof(index), "%d", mti->mti_stripe_index);
-        rc = record_lov_add(obd, llh, lovname, mti->mti_uuid, index, "1");
-        rc = record_marker(obd, llh, fsdb, CM_END | flags, mti->mti_svname,
+       rc = record_lov_add(env, llh, lovname, mti->mti_uuid, index, "1");
+       rc = record_marker(env, llh, fsdb, CM_END | flags, mti->mti_svname,
                            "add osc");
-        rc = record_end_log(obd, &llh);
+       rc = record_end_log(env, &llh);
 out:
         name_destroy(&lovuuid);
         name_destroy(&oscuuid);
@@ -1801,7 +1834,8 @@ out:
         RETURN(rc);
 }
 
-static int mgs_write_log_ost(struct obd_device *obd, struct fs_db *fsdb,
+static int mgs_write_log_ost(const struct lu_env *env,
+                            struct mgs_device *mgs, struct fs_db *fsdb,
                              struct mgs_target_info *mti)
 {
         struct llog_handle *llh = NULL;
@@ -1816,7 +1850,7 @@ 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)) {
+       if (!mgs_log_is_empty(env, mgs, 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, "
@@ -1831,21 +1865,21 @@ static int mgs_write_log_ost(struct obd_device *obd, struct fs_db *fsdb,
         */
         if (class_find_param(ptr, PARAM_FAILMODE, &ptr) == 0)
                 failout = (strncmp(ptr, "failout", 7) == 0);
-        rc = record_start_log(obd, &llh, mti->mti_svname);
+       rc = record_start_log(env, mgs, &llh, mti->mti_svname);
         if (rc)
                 RETURN(rc);
         /* FIXME these should be a single journal transaction */
-        rc = record_marker(obd, llh, fsdb, CM_START, mti->mti_svname,"add ost");
+       rc = record_marker(env, llh, fsdb, CM_START, mti->mti_svname,"add ost");
         if (*mti->mti_uuid == '\0')
                 snprintf(mti->mti_uuid, sizeof(mti->mti_uuid),
                          "%s_UUID", mti->mti_svname);
-        rc = record_attach(obd, llh, mti->mti_svname,
+       rc = record_attach(env, llh, mti->mti_svname,
                            "obdfilter"/*LUSTRE_OST_NAME*/, mti->mti_uuid);
-        rc = record_setup(obd, llh, mti->mti_svname,
+       rc = record_setup(env, llh, mti->mti_svname,
                           "dev"/*ignored*/, "type"/*ignored*/,
                           failout ? "n" : "f", 0/*options*/);
-        rc = record_marker(obd, llh, fsdb, CM_END, mti->mti_svname, "add ost");
-        rc = record_end_log(obd, &llh);
+       rc = record_marker(env, llh, fsdb, CM_END, mti->mti_svname, "add ost");
+       rc = record_end_log(env, &llh);
 
         /* We also have to update the other logs where this osc is part of
            the lov */
@@ -1873,7 +1907,7 @@ static int mgs_write_log_ost(struct obd_device *obd, struct fs_db *fsdb,
 
                         name_create_mdt_and_lov(&logname, &lovname, fsdb, i);
                         sprintf(mdt_index, "-MDT%04x", i);
-                        mgs_write_log_osc_to_lov(obd, fsdb, mti, logname,
+                       mgs_write_log_osc_to_lov(env, mgs, fsdb, mti, logname,
                                                  mdt_index, lovname,
                                                  LUSTRE_SP_MDT, flags);
                         name_destroy(&logname);
@@ -1883,14 +1917,14 @@ static int mgs_write_log_ost(struct obd_device *obd, struct fs_db *fsdb,
 
         /* Append ost info to the client log */
         name_create(&logname, mti->mti_fsname, "-client");
-        if (mgs_log_is_empty(obd, logname)) {
+       if (mgs_log_is_empty(env, mgs, logname)) {
                 /* Start client log */
-                rc = mgs_write_log_lov(obd, fsdb, mti, logname,
+               rc = mgs_write_log_lov(env, mgs, fsdb, mti, logname,
                                        fsdb->fsdb_clilov);
-                rc = mgs_write_log_lmv(obd, fsdb, mti, logname,
+               rc = mgs_write_log_lmv(env, mgs, fsdb, mti, logname,
                                        fsdb->fsdb_clilmv);
         }
-        mgs_write_log_osc_to_lov(obd, fsdb, mti, logname, "",
+       mgs_write_log_osc_to_lov(env, mgs, fsdb, mti, logname, "",
                                  fsdb->fsdb_clilov, LUSTRE_SP_CLI, flags);
         name_destroy(&logname);
         RETURN(rc);
@@ -1905,7 +1939,8 @@ static __inline__ int mgs_param_empty(char *ptr)
         return 0;
 }
 
-static int mgs_write_log_failnid_internal(struct obd_device *obd,
+static int mgs_write_log_failnid_internal(const struct lu_env *env,
+                                         struct mgs_device *mgs,
                                           struct fs_db *fsdb,
                                           struct mgs_target_info *mti,
                                           char *logname, char *cliname)
@@ -1915,21 +1950,21 @@ static int mgs_write_log_failnid_internal(struct obd_device *obd,
 
         if (mgs_param_empty(mti->mti_params)) {
                 /* Remove _all_ failnids */
-                rc = mgs_modify(obd, fsdb, mti, logname,
+               rc = mgs_modify(env, mgs, fsdb, mti, logname,
                                 mti->mti_svname, "add failnid", CM_SKIP);
                 return rc;
         }
 
         /* Otherwise failover nids are additive */
-        rc = record_start_log(obd, &llh, logname);
+       rc = record_start_log(env, mgs, &llh, logname);
         if (!rc) {
                 /* FIXME this should be a single journal transaction */
-                rc = record_marker(obd, llh, fsdb, CM_START,
+               rc = record_marker(env, llh, fsdb, CM_START,
                                    mti->mti_svname, "add failnid");
-                rc = mgs_write_log_failnids(obd, mti, llh, cliname);
-                rc = record_marker(obd, llh, fsdb, CM_END,
+               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(obd, &llh);
+               rc = record_end_log(env, &llh);
         }
 
         return rc;
@@ -1940,7 +1975,9 @@ static int mgs_write_log_failnid_internal(struct obd_device *obd,
    The mdc/osc must have been added to logs first */
 /* tcp nids must be in dotted-quad ascii -
    we can't resolve hostnames from the kernel. */
-static int mgs_write_log_add_failnid(struct obd_device *obd, struct fs_db *fsdb,
+static int mgs_write_log_add_failnid(const struct lu_env *env,
+                                    struct mgs_device *mgs,
+                                    struct fs_db *fsdb,
                                      struct mgs_target_info *mti)
 {
         char *logname, *cliname;
@@ -1952,7 +1989,7 @@ static int mgs_write_log_add_failnid(struct obd_device *obd, struct fs_db *fsdb,
          * an "add uuid" stanza */
 
         /* Verify that we know about this target */
-        if (mgs_log_is_empty(obd, mti->mti_svname)) {
+       if (mgs_log_is_empty(env, mgs, 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);
@@ -1970,7 +2007,7 @@ static int mgs_write_log_add_failnid(struct obd_device *obd, struct fs_db *fsdb,
 
         /* Add failover nids to the client log */
         name_create(&logname, mti->mti_fsname, "-client");
-        rc = mgs_write_log_failnid_internal(obd, fsdb, mti, logname, cliname);
+       rc = mgs_write_log_failnid_internal(env, mgs, fsdb,mti,logname,cliname);
         name_destroy(&logname);
         name_destroy(&cliname);
 
@@ -1983,7 +2020,7 @@ static int mgs_write_log_add_failnid(struct obd_device *obd, struct fs_db *fsdb,
                                 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(obd, fsdb, mti,
+                       rc = mgs_write_log_failnid_internal(env, mgs, fsdb, mti,
                                                             logname, cliname);
                         name_destroy(&cliname);
                         name_destroy(&logname);
@@ -1993,7 +2030,8 @@ static int mgs_write_log_add_failnid(struct obd_device *obd, struct fs_db *fsdb,
         RETURN(rc);
 }
 
-static int mgs_wlp_lcfg(struct obd_device *obd, struct fs_db *fsdb,
+static int mgs_wlp_lcfg(const struct lu_env *env,
+                       struct mgs_device *mgs, struct fs_db *fsdb,
                         struct mgs_target_info *mti,
                         char *logname, struct lustre_cfg_bufs *bufs,
                         char *tgtname, char *ptr)
@@ -2010,7 +2048,7 @@ static int mgs_wlp_lcfg(struct obd_device *obd, struct fs_db *fsdb,
         if ((tmp = strchr(comment, '=')))
             *tmp = 0;
         /* FIXME we should skip settings that are the same as old values */
-        rc = mgs_modify(obd, fsdb, mti, logname, tgtname, comment, CM_SKIP);
+       rc = mgs_modify(env, mgs, fsdb, mti, logname, tgtname, comment,CM_SKIP);
         del = mgs_param_empty(ptr);
 
         LCONSOLE_INFO("%sing parameter %s.%s in log %s\n", del ? "Disabl" : rc ?
@@ -2023,14 +2061,15 @@ static int mgs_wlp_lcfg(struct obd_device *obd, struct fs_db *fsdb,
         lcfg = lustre_cfg_new(LCFG_PARAM, bufs);
         if (!lcfg)
                 return -ENOMEM;
-        rc = mgs_write_log_direct(obd, fsdb, logname, lcfg, tgtname, comment);
+       rc = mgs_write_log_direct(env, mgs, fsdb, logname,lcfg,tgtname,comment);
         lustre_cfg_free(lcfg);
         return rc;
 }
 
 /* write global variable settings into log */
-static int mgs_write_log_sys(struct obd_device *obd, struct fs_db *fsdb,
-                       struct mgs_target_info *mti, char *sys, char *ptr)
+static int mgs_write_log_sys(const struct lu_env *env,
+                            struct mgs_device *mgs, struct fs_db *fsdb,
+                            struct mgs_target_info *mti, char *sys, char *ptr)
 {
        struct lustre_cfg_bufs bufs;
        struct lustre_cfg *lcfg;
@@ -2071,7 +2110,7 @@ static int mgs_write_log_sys(struct obd_device *obd, struct fs_db *fsdb,
        sep = *ptr;
        *ptr = '\0';
        /* modify all servers and clients */
-       rc = mgs_write_log_direct_all(obd, fsdb, mti,
+       rc = mgs_write_log_direct_all(env, mgs, fsdb, mti,
                                      *tmp == '\0' ? NULL : lcfg,
                                      mti->mti_fsname, sys, 0);
        if (rc == 0 && *tmp != '\0') {
@@ -2094,9 +2133,9 @@ static int mgs_write_log_sys(struct obd_device *obd, struct fs_db *fsdb,
 }
 
 /* write quota settings into log */
-static int mgs_write_log_quota(struct obd_device *obd, struct fs_db *fsdb,
-                              struct mgs_target_info *mti, char *quota,
-                              char *ptr)
+static int mgs_write_log_quota(const struct lu_env *env, struct mgs_device *mgs,
+                              struct fs_db *fsdb, struct mgs_target_info *mti,
+                              char *quota, char *ptr)
 {
        struct lustre_cfg_bufs bufs;
        struct lustre_cfg *lcfg;
@@ -2137,7 +2176,7 @@ static int mgs_write_log_quota(struct obd_device *obd, struct fs_db *fsdb,
         *     config logs, it should be moved to a separate config
         *     log once we cleanup the config log for global param. */
        /* modify all servers */
-       rc = mgs_write_log_direct_all(obd, fsdb, mti,
+       rc = mgs_write_log_direct_all(env, mgs, fsdb, mti,
                                      *tmp == '\0' ? NULL : lcfg,
                                      mti->mti_fsname, quota, 1);
        *ptr = sep;
@@ -2145,7 +2184,8 @@ static int mgs_write_log_quota(struct obd_device *obd, struct fs_db *fsdb,
        return rc;
 }
 
-static int mgs_srpc_set_param_disk(struct obd_device *obd,
+static int mgs_srpc_set_param_disk(const struct lu_env *env,
+                                  struct mgs_device *mgs,
                                    struct fs_db *fsdb,
                                    struct mgs_target_info *mti,
                                    char *param)
@@ -2181,18 +2221,19 @@ static int mgs_srpc_set_param_disk(struct obd_device *obd,
         if (rc)
                 GOTO(out_lcfg, rc);
 
-        if (mgs_log_is_empty(obd, logname)) {
-                rc = record_start_log(obd, &llh, logname);
-                record_end_log(obd, &llh);
+       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);
         }
 
         /* obsolete old one */
-        mgs_modify(obd, fsdb, mti, logname, mti->mti_svname, comment, CM_SKIP);
+       mgs_modify(env, mgs, fsdb, mti, logname, mti->mti_svname,
+                  comment, CM_SKIP);
 
         /* write the new one */
-        rc = mgs_write_log_direct(obd, fsdb, logname, lcfg,
+       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);
@@ -2326,7 +2367,8 @@ static int mgs_srpc_set_param_mem(struct fs_db *fsdb,
         RETURN(rc);
 }
 
-static int mgs_srpc_set_param(struct obd_device *obd,
+static int mgs_srpc_set_param(const struct lu_env *env,
+                             struct mgs_device *mgs,
                               struct fs_db *fsdb,
                               struct mgs_target_info *mti,
                               char *param)
@@ -2351,7 +2393,7 @@ static int mgs_srpc_set_param(struct obd_device *obd,
                 goto out_free;
 
         /* previous steps guaranteed the syntax is correct */
-        rc = mgs_srpc_set_param_disk(obd, fsdb, mti, copy);
+       rc = mgs_srpc_set_param_disk(env, mgs, fsdb, mti, copy);
         if (rc)
                 goto out_free;
 
@@ -2360,7 +2402,8 @@ static int mgs_srpc_set_param(struct obd_device *obd,
                  * for mgs rules, make them effective immediately.
                  */
                 LASSERT(fsdb->fsdb_srpc_tgt == NULL);
-                sptlrpc_target_update_exp_flavor(obd, &fsdb->fsdb_srpc_gen);
+               sptlrpc_target_update_exp_flavor(mgs->mgs_obd,
+                                                &fsdb->fsdb_srpc_gen);
         }
 
 out_free:
@@ -2437,7 +2480,8 @@ static int mgs_srpc_read_handler(const struct lu_env *env,
         RETURN(0);
 }
 
-int mgs_get_fsdb_srpc_from_llog(struct obd_device *obd,
+int mgs_get_fsdb_srpc_from_llog(const struct lu_env *env,
+                               struct mgs_device *mgs,
                                 struct fs_db *fsdb)
 {
         struct llog_handle        *llh = NULL;
@@ -2453,13 +2497,13 @@ int mgs_get_fsdb_srpc_from_llog(struct obd_device *obd,
         if (rc)
                 RETURN(rc);
 
-        ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
+       ctxt = llog_get_context(mgs->mgs_obd, LLOG_CONFIG_ORIG_CTXT);
         LASSERT(ctxt != NULL);
 
-        if (mgs_log_is_empty(obd, logname))
+       if (mgs_log_is_empty(env, mgs, logname))
                 GOTO(out, rc = 0);
 
-        push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+       push_ctxt(&saved, &mgs->mgs_obd->obd_lvfs_ctxt, NULL);
 
        rc = llog_open(NULL, ctxt, &llh, NULL, logname,
                       LLOG_OPEN_EXISTS);
@@ -2485,7 +2529,7 @@ int mgs_get_fsdb_srpc_from_llog(struct obd_device *obd,
 out_close:
        llog_close(NULL, llh);
 out_pop:
-        pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+       pop_ctxt(&saved, &mgs->mgs_obd->obd_lvfs_ctxt, NULL);
 out:
         llog_ctxt_put(ctxt);
         name_destroy(&logname);
@@ -2500,7 +2544,8 @@ out:
  * A parameter with null value ("<param>='\0'") means to erase it out of
  * the logs.
  */
-static int mgs_write_log_param(struct obd_device *obd, struct fs_db *fsdb,
+static int mgs_write_log_param(const struct lu_env *env,
+                              struct mgs_device *mgs, struct fs_db *fsdb,
                                struct mgs_target_info *mti, char *ptr)
 {
         struct lustre_cfg_bufs bufs;
@@ -2536,7 +2581,7 @@ static int mgs_write_log_param(struct obd_device *obd, struct fs_db *fsdb,
         }
 
         if (class_match_param(ptr, PARAM_SRPC, NULL) == 0) {
-                rc = mgs_srpc_set_param(obd, fsdb, mti, ptr);
+               rc = mgs_srpc_set_param(env, mgs, fsdb, mti, ptr);
                 GOTO(end, rc);
         }
 
@@ -2547,18 +2592,18 @@ static int mgs_write_log_param(struct obd_device *obd, struct fs_db *fsdb,
                    targets in mgs_write_log_target */
                 if (mti->mti_flags & LDD_F_PARAM) {
                         CDEBUG(D_MGS, "Adding failnode\n");
-                        rc = mgs_write_log_add_failnid(obd, fsdb, mti);
+                       rc = mgs_write_log_add_failnid(env, mgs, fsdb, mti);
                 }
                 GOTO(end, rc);
         }
 
         if (class_match_param(ptr, PARAM_SYS, &tmp) == 0) {
-                rc = mgs_write_log_sys(obd, fsdb, mti, ptr, tmp);
+               rc = mgs_write_log_sys(env, mgs, fsdb, mti, ptr, tmp);
                 GOTO(end, rc);
         }
 
        if (class_match_param(ptr, PARAM_QUOTA, &tmp) == 0) {
-               rc = mgs_write_log_quota(obd, fsdb, mti, ptr, tmp);
+               rc = mgs_write_log_quota(env, mgs, fsdb, mti, ptr, tmp);
                GOTO(end, rc);
        }
 
@@ -2577,7 +2622,7 @@ static int mgs_write_log_param(struct obd_device *obd, struct fs_db *fsdb,
                               flag ? "de": "re", mti->mti_svname);
                 /* Modify clilov */
                 name_create(&logname, mti->mti_fsname, "-client");
-                rc = mgs_modify(obd, fsdb, mti, logname,
+               rc = mgs_modify(env, mgs, fsdb, mti, logname,
                                 mti->mti_svname, "add osc", flag);
                 name_destroy(&logname);
                 if (rc)
@@ -2588,7 +2633,7 @@ static int mgs_write_log_param(struct obd_device *obd, struct fs_db *fsdb,
                         if (!cfs_test_bit(i, fsdb->fsdb_mdt_index_map))
                                 continue;
                         name_create_mdt(&logname, mti->mti_fsname, i);
-                        rc = mgs_modify(obd, fsdb, mti, logname,
+                       rc = mgs_modify(env, mgs, fsdb, mti, logname,
                                         mti->mti_svname, "add osc", flag);
                         name_destroy(&logname);
                         if (rc)
@@ -2629,12 +2674,12 @@ static int mgs_write_log_param(struct obd_device *obd, struct fs_db *fsdb,
                 }
 
                 /* Modify mdtlov */
-                if (mgs_log_is_empty(obd, mti->mti_svname))
+               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 = mgs_wlp_lcfg(obd, fsdb, mti, mti->mti_svname,
+               rc = mgs_wlp_lcfg(env, mgs, fsdb, mti, mti->mti_svname,
                                   &bufs, mdtlovname, ptr);
                 name_destroy(&logname);
                 name_destroy(&mdtlovname);
@@ -2643,7 +2688,7 @@ static int mgs_write_log_param(struct obd_device *obd, struct fs_db *fsdb,
 
                 /* Modify clilov */
                 name_create(&logname, mti->mti_fsname, "-client");
-                rc = mgs_wlp_lcfg(obd, fsdb, mti, logname, &bufs,
+               rc = mgs_wlp_lcfg(env, mgs, fsdb, mti, logname, &bufs,
                                   fsdb->fsdb_clilov, ptr);
                 name_destroy(&logname);
                 GOTO(end, rc);
@@ -2689,7 +2734,7 @@ static int mgs_write_log_param(struct obd_device *obd, struct fs_db *fsdb,
 
                 /* Modify client */
                 name_create(&logname, mti->mti_fsname, "-client");
-                rc = mgs_wlp_lcfg(obd, fsdb, mti, logname, &bufs,
+               rc = mgs_wlp_lcfg(env, mgs, fsdb, mti, logname, &bufs,
                                   cname, ptr);
 
                 /* osc params affect the MDT as well */
@@ -2704,9 +2749,10 @@ static int mgs_write_log_param(struct obd_device *obd, struct fs_db *fsdb,
                                                     fsdb, i);
                                 name_destroy(&logname);
                                 name_create_mdt(&logname, mti->mti_fsname, i);
-                                if (!mgs_log_is_empty(obd, logname))
-                                        rc = mgs_wlp_lcfg(obd, fsdb,mti,logname,
-                                                          &bufs, cname, ptr);
+                               if (!mgs_log_is_empty(env, mgs, logname))
+                                       rc = mgs_wlp_lcfg(env, mgs, fsdb, mti,
+                                                         logname, &bufs, cname,
+                                                         ptr);
                                 if (rc)
                                         break;
                         }
@@ -2738,7 +2784,7 @@ static int mgs_write_log_param(struct obd_device *obd, struct fs_db *fsdb,
                                                   fsdb->fsdb_mdt_index_map))
                                         continue;
                                 name_create_mdt(&logname, mti->mti_fsname, i);
-                                rc = mgs_wlp_lcfg(obd, fsdb, mti,
+                               rc = mgs_wlp_lcfg(env, mgs, fsdb, mti,
                                                   logname, &bufs,
                                                   logname, ptr);
                                 name_destroy(&logname);
@@ -2746,7 +2792,7 @@ static int mgs_write_log_param(struct obd_device *obd, struct fs_db *fsdb,
                                         goto active_err;
                         }
                 } else {
-                        rc = mgs_wlp_lcfg(obd, fsdb, mti,
+                       rc = mgs_wlp_lcfg(env, mgs, fsdb, mti,
                                           mti->mti_svname, &bufs,
                                           mti->mti_svname, ptr);
                         if (rc)
@@ -2759,10 +2805,10 @@ static int mgs_write_log_param(struct obd_device *obd, struct fs_db *fsdb,
         if ((class_match_param(ptr, PARAM_MDD, NULL) == 0) ||
             (class_match_param(ptr, PARAM_OST, NULL) == 0)) {
                 CDEBUG(D_MGS, "%.3s param %s\n", ptr, ptr + 4);
-                if (mgs_log_is_empty(obd, mti->mti_svname))
+               if (mgs_log_is_empty(env, mgs, mti->mti_svname))
                         GOTO(end, rc = -ENODEV);
 
-                rc = mgs_wlp_lcfg(obd, fsdb, mti, mti->mti_svname,
+               rc = mgs_wlp_lcfg(env, mgs, fsdb, mti, mti->mti_svname,
                                   &bufs, mti->mti_svname, ptr);
                 GOTO(end, rc);
         }
@@ -2778,7 +2824,8 @@ end:
 }
 
 /* Not implementing automatic failover nid addition at this time. */
-int mgs_check_failnid(struct obd_device *obd, struct mgs_target_info *mti)
+int mgs_check_failnid(const struct lu_env *env, struct mgs_device *mgs,
+                     struct mgs_target_info *mti)
 {
 #if 0
         struct fs_db *fsdb;
@@ -2808,7 +2855,8 @@ int mgs_check_failnid(struct obd_device *obd, struct mgs_target_info *mti)
         return 0;
 }
 
-int mgs_write_log_target(struct obd_device *obd,
+int mgs_write_log_target(const struct lu_env *env,
+                        struct mgs_device *mgs,
                          struct mgs_target_info *mti,
                          struct fs_db *fsdb)
 {
@@ -2817,7 +2865,7 @@ int mgs_write_log_target(struct obd_device *obd,
         ENTRY;
 
         /* set/check the new target index */
-        rc = mgs_set_index(obd, mti);
+       rc = mgs_set_index(env, mgs, mti);
         if (rc < 0) {
                 CERROR("Can't get index (%d)\n", rc);
                 RETURN(rc);
@@ -2862,9 +2910,9 @@ int mgs_write_log_target(struct obd_device *obd,
             (LDD_F_VIRGIN | LDD_F_UPGRADE14 | LDD_F_WRITECONF)) {
                 /* Generate a log from scratch */
                 if (mti->mti_flags & LDD_F_SV_TYPE_MDT) {
-                        rc = mgs_write_log_mdt(obd, fsdb, mti);
+                       rc = mgs_write_log_mdt(env, mgs, fsdb, mti);
                 } else if (mti->mti_flags & LDD_F_SV_TYPE_OST) {
-                        rc = mgs_write_log_ost(obd, fsdb, mti);
+                       rc = mgs_write_log_ost(env, mgs, fsdb, mti);
                 } else {
                         CERROR("Unknown target type %#x, can't create log for "
                                "%s\n", mti->mti_flags, mti->mti_svname);
@@ -2897,7 +2945,7 @@ int mgs_write_log_target(struct obd_device *obd,
                 }
                 CDEBUG(D_MGS, "remaining string: '%s', param: '%s'\n",
                        params, buf);
-                rc = mgs_write_log_param(obd, fsdb, mti, buf);
+               rc = mgs_write_log_param(env, mgs, fsdb, mti, buf);
                 if (rc)
                         break;
         }
@@ -2911,8 +2959,8 @@ out_up:
 
 /* COMPAT_146 */
 /* verify that we can handle the old config logs */
-int mgs_upgrade_sv_14(struct obd_device *obd, struct mgs_target_info *mti,
-                      struct fs_db *fsdb)
+int mgs_upgrade_sv_14(const struct lu_env *env, struct mgs_device *mgs,
+                     struct mgs_target_info *mti, struct fs_db *fsdb)
 {
         int rc = 0;
         ENTRY;
@@ -2946,7 +2994,7 @@ 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)) {
+               if (mgs_log_is_empty(env, mgs, mti->mti_svname)) {
                         LCONSOLE_ERROR_MSG(0x14b, "The old MDT log %s is "
                                            "missing. Was tunefs.lustre "
                                            "successful?\n",
@@ -2976,11 +3024,12 @@ int mgs_upgrade_sv_14(struct obd_device *obd, struct mgs_target_info *mti,
 }
 /* end COMPAT_146 */
 
-int mgs_erase_log(struct obd_device *obd, char *name)
+int mgs_erase_log(const struct lu_env *env, struct mgs_device *mgs, char *name)
 {
        struct lvfs_run_ctxt     saved;
        struct llog_ctxt        *ctxt;
        int                      rc = 0;
+       struct obd_device *obd = mgs->mgs_obd;
 
        ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
        if (ctxt == NULL) {
@@ -3005,9 +3054,8 @@ int mgs_erase_log(struct obd_device *obd, char *name)
 }
 
 /* erase all logs for the given fs */
-int mgs_erase_logs(struct obd_device *obd, char *fsname)
+int mgs_erase_logs(const struct lu_env *env, struct mgs_device *mgs, char *fsname)
 {
-        struct mgs_obd *mgs = &obd->u.mgs;
         struct fs_db *fsdb;
         cfs_list_t dentry_list;
         struct l_linux_dirent *dirent, *n;
@@ -3016,8 +3064,7 @@ int mgs_erase_logs(struct obd_device *obd, char *fsname)
         ENTRY;
 
         /* Find all the logs in the CONFIGS directory */
-        rc = class_dentry_readdir(obd, mgs->mgs_configs_dir,
-                                  mgs->mgs_vfsmnt, &dentry_list);
+       rc = class_dentry_readdir(env, mgs, &dentry_list);
         if (rc) {
                 CERROR("Can't read %s dir\n", MOUNT_CONFIGS_DIR);
                 RETURN(rc);
@@ -3026,9 +3073,9 @@ int mgs_erase_logs(struct obd_device *obd, char *fsname)
         cfs_mutex_lock(&mgs->mgs_mutex);
 
         /* Delete the fs db */
-        fsdb = mgs_find_fsdb(obd, fsname);
+       fsdb = mgs_find_fsdb(mgs, fsname);
         if (fsdb)
-                mgs_free_fsdb(obd, fsdb);
+               mgs_free_fsdb(mgs, fsdb);
 
         cfs_list_for_each_entry_safe(dirent, n, &dentry_list, lld_list) {
                 cfs_list_del(&dirent->lld_list);
@@ -3038,7 +3085,7 @@ int mgs_erase_logs(struct obd_device *obd, char *fsname)
                             (strncmp(fsname, dirent->lld_name, len) == 0)) {
                                 CDEBUG(D_MGS, "Removing log %s\n",
                                        dirent->lld_name);
-                                mgs_erase_log(obd, dirent->lld_name);
+                               mgs_erase_log(env, mgs, dirent->lld_name);
                         }
                 }
                 OBD_FREE(dirent, sizeof(*dirent));
@@ -3077,7 +3124,8 @@ static void print_lustre_cfg(struct lustre_cfg *lcfg)
  * \param lcfg buf0 may contain the device (testfs-MDT0000) name
  *             buf1 contains the single parameter
  */
-int mgs_setparam(struct obd_device *obd, struct lustre_cfg *lcfg, char *fsname)
+int mgs_setparam(const struct lu_env *env, struct mgs_device *mgs,
+                struct lustre_cfg *lcfg, char *fsname)
 {
         struct fs_db *fsdb;
         struct mgs_target_info *mti;
@@ -3123,14 +3171,14 @@ int mgs_setparam(struct obd_device *obd, struct lustre_cfg *lcfg, char *fsname)
         fsname[MTI_NAME_MAXLEN - 1] = 0;
         CDEBUG(D_MGS, "setparam fs='%s' device='%s'\n", fsname, devname);
 
-        rc = mgs_find_or_make_fsdb(obd, fsname, &fsdb);
+       rc = mgs_find_or_make_fsdb(env, mgs, fsname, &fsdb);
         if (rc)
                 RETURN(rc);
         if (!cfs_test_bit(FSDB_MGS_SELF, &fsdb->fsdb_flags) &&
             cfs_test_bit(FSDB_LOG_EMPTY, &fsdb->fsdb_flags)) {
                 CERROR("No filesystem targets for %s.  cfg_device from lctl "
                        "is '%s'\n", fsname, devname);
-                mgs_free_fsdb(obd, fsdb);
+               mgs_free_fsdb(mgs, fsdb);
                 RETURN(-EINVAL);
         }
 
@@ -3154,7 +3202,7 @@ int mgs_setparam(struct obd_device *obd, struct lustre_cfg *lcfg, char *fsname)
         mti->mti_flags = rc | LDD_F_PARAM;
 
         cfs_mutex_lock(&fsdb->fsdb_mutex);
-        rc = mgs_write_log_param(obd, fsdb, mti, mti->mti_params);
+       rc = mgs_write_log_param(env, mgs, fsdb, mti, mti->mti_params);
         cfs_mutex_unlock(&fsdb->fsdb_mutex);
 
         /*
@@ -3163,13 +3211,14 @@ int mgs_setparam(struct obd_device *obd, struct lustre_cfg *lcfg, char *fsname)
          * so we don't really need to hold the lock while we're
          * writing (above).
          */
-        mgs_revoke_lock(obd, fsdb, CONFIG_T_CONFIG);
+       mgs_revoke_lock(mgs, fsdb, CONFIG_T_CONFIG);
 out:
         OBD_FREE_PTR(mti);
         RETURN(rc);
 }
 
-static int mgs_write_log_pool(struct obd_device *obd, char *logname,
+static int mgs_write_log_pool(const struct lu_env *env,
+                             struct mgs_device *mgs, char *logname,
                               struct fs_db *fsdb, char *lovname,
                               enum lcfg_command_type cmd,
                               char *poolname, char *fsname,
@@ -3178,19 +3227,20 @@ static int mgs_write_log_pool(struct obd_device *obd, char *logname,
         struct llog_handle *llh = NULL;
         int rc;
 
-        rc = record_start_log(obd, &llh, logname);
+       rc = record_start_log(env, mgs, &llh, logname);
         if (rc)
                 return rc;
-        rc = record_marker(obd, llh, fsdb, CM_START, lovname, comment);
-        record_base(obd, llh, lovname, 0, cmd, poolname, fsname, ostname, 0);
-        rc = record_marker(obd, llh, fsdb, CM_END, lovname, comment);
-        rc = record_end_log(obd, &llh);
+       rc = record_marker(env, llh, fsdb, CM_START, lovname, comment);
+       record_base(env, llh, lovname, 0, cmd, poolname, fsname, ostname, 0);
+       rc = record_marker(env, llh, fsdb, CM_END, lovname, comment);
+       rc = record_end_log(env, &llh);
 
         return rc;
 }
 
-int mgs_pool_cmd(struct obd_device *obd, enum lcfg_command_type cmd,
-                 char *fsname, char *poolname, char *ostname)
+int mgs_pool_cmd(const struct lu_env *env, struct mgs_device *mgs,
+                enum lcfg_command_type cmd, char *fsname,
+                char *poolname, char *ostname)
 {
         struct fs_db *fsdb;
         char *lovname;
@@ -3201,14 +3251,14 @@ int mgs_pool_cmd(struct obd_device *obd, enum lcfg_command_type cmd,
         int rc, i;
         ENTRY;
 
-        rc = mgs_find_or_make_fsdb(obd, fsname, &fsdb);
+       rc = mgs_find_or_make_fsdb(env, mgs, fsname, &fsdb);
         if (rc) {
                 CERROR("Can't get db for %s\n", fsname);
                 RETURN(rc);
         }
         if (cfs_test_bit(FSDB_LOG_EMPTY, &fsdb->fsdb_flags)) {
                 CERROR("%s is not defined\n", fsname);
-                mgs_free_fsdb(obd, fsdb);
+               mgs_free_fsdb(mgs, fsdb);
                 RETURN(-EINVAL);
         }
 
@@ -3230,17 +3280,15 @@ int mgs_pool_cmd(struct obd_device *obd, enum lcfg_command_type cmd,
                 GOTO(out, rc = -ENOMEM);
 
         switch(cmd) {
-        case LCFG_POOL_NEW: {
+       case LCFG_POOL_NEW:
                 sprintf(label,
                         "new %s.%s", fsname, poolname);
                 break;
-        }
-        case LCFG_POOL_ADD: {
+       case LCFG_POOL_ADD:
                 sprintf(label,
                         "add %s.%s.%s", fsname, poolname, ostname);
                 break;
-        }
-        case LCFG_POOL_REM: {
+       case LCFG_POOL_REM:
                 OBD_ALLOC(canceled_label, label_sz);
                 if (canceled_label == NULL)
                          GOTO(out, rc = -ENOMEM);
@@ -3249,8 +3297,7 @@ int mgs_pool_cmd(struct obd_device *obd, enum lcfg_command_type cmd,
                 sprintf(canceled_label,
                         "add %s.%s.%s", fsname, poolname, ostname);
                 break;
-        }
-        case LCFG_POOL_DEL: {
+       case LCFG_POOL_DEL:
                 OBD_ALLOC(canceled_label, label_sz);
                 if (canceled_label == NULL)
                          GOTO(out, rc = -ENOMEM);
@@ -3259,11 +3306,9 @@ int mgs_pool_cmd(struct obd_device *obd, enum lcfg_command_type cmd,
                 sprintf(canceled_label,
                         "new %s.%s", fsname, poolname);
                 break;
-        }
-        default: {
+       default:
                 break;
         }
-        }
 
         cfs_mutex_lock(&fsdb->fsdb_mutex);
 
@@ -3280,11 +3325,12 @@ int mgs_pool_cmd(struct obd_device *obd, enum lcfg_command_type cmd,
 
                         if (canceled_label != NULL) {
                                 strcpy(mti->mti_svname, "lov pool");
-                                mgs_modify(obd, fsdb, mti, logname, lovname,
-                                           canceled_label, CM_SKIP);
+                               mgs_modify(env, mgs, fsdb, mti, logname,
+                                          lovname, canceled_label,
+                                          CM_SKIP);
                         }
 
-                        mgs_write_log_pool(obd, logname, fsdb, lovname,
+                       mgs_write_log_pool(env, mgs, logname, fsdb, lovname,
                                            cmd, fsname, poolname, ostname,
                                            label);
                         name_destroy(&logname);
@@ -3294,16 +3340,16 @@ int mgs_pool_cmd(struct obd_device *obd, enum lcfg_command_type cmd,
 
         name_create(&logname, fsname, "-client");
         if (canceled_label != NULL)
-                mgs_modify(obd, fsdb, mti, logname, fsdb->fsdb_clilov,
+               mgs_modify(env, mgs, fsdb, mti, logname, fsdb->fsdb_clilov,
                            canceled_label, CM_SKIP);
 
-        mgs_write_log_pool(obd, logname, fsdb, fsdb->fsdb_clilov,
+       mgs_write_log_pool(env, mgs, logname, fsdb, fsdb->fsdb_clilov,
                            cmd, fsname, poolname, ostname, label);
         name_destroy(&logname);
 
         cfs_mutex_unlock(&fsdb->fsdb_mutex);
         /* request for update */
-        mgs_revoke_lock(obd, fsdb, CONFIG_T_CONFIG);
+       mgs_revoke_lock(mgs, fsdb, CONFIG_T_CONFIG);
 
         EXIT;
 out:
index a9a9769..0c9c13d 100644 (file)
@@ -234,7 +234,9 @@ out:
         RETURN(rc);
 }
 
-static int nidtbl_update_version(struct obd_device *obd, struct mgs_nidtbl *tbl)
+static int nidtbl_update_version(const struct lu_env *env,
+                                struct mgs_device *mgs,
+                                struct mgs_nidtbl *tbl)
 {
         struct lvfs_run_ctxt saved;
         struct file         *file = NULL;
@@ -242,6 +244,7 @@ static int nidtbl_update_version(struct obd_device *obd, struct mgs_nidtbl *tbl)
         u64                  version;
         loff_t               off = 0;
         int                  rc;
+       struct obd_device   *obd = tbl->mn_fsdb->fsdb_obd;
         ENTRY;
 
         LASSERT(cfs_mutex_is_locked(&tbl->mn_lock));
@@ -270,7 +273,8 @@ static int nidtbl_update_version(struct obd_device *obd, struct mgs_nidtbl *tbl)
 
 #define MGS_NIDTBL_VERSION_INIT 2
 
-static int nidtbl_read_version(struct obd_device *obd, struct mgs_nidtbl *tbl)
+static int nidtbl_read_version(const struct lu_env *env,
+                              struct mgs_device *mgs, struct mgs_nidtbl *tbl)
 {
         struct lvfs_run_ctxt saved;
         struct file         *file = NULL;
@@ -278,6 +282,7 @@ static int nidtbl_read_version(struct obd_device *obd, struct mgs_nidtbl *tbl)
         u64                  version;
         loff_t               off = 0;
         int                  rc;
+       struct obd_device   *obd = tbl->mn_fsdb->fsdb_obd;
         ENTRY;
 
         LASSERT(cfs_mutex_is_locked(&tbl->mn_lock));
@@ -308,7 +313,8 @@ static int nidtbl_read_version(struct obd_device *obd, struct mgs_nidtbl *tbl)
         RETURN(rc);
 }
 
-static int mgs_nidtbl_write(struct fs_db *fsdb, struct mgs_target_info *mti)
+static int mgs_nidtbl_write(const struct lu_env *env, struct fs_db *fsdb,
+                           struct mgs_target_info *mti)
 {
         struct mgs_nidtbl        *tbl;
         struct mgs_nidtbl_target *tgt;
@@ -348,7 +354,7 @@ static int mgs_nidtbl_write(struct fs_db *fsdb, struct mgs_target_info *mti)
 
         cfs_list_move_tail(&tgt->mnt_list, &tbl->mn_targets);
 
-        rc = nidtbl_update_version(fsdb->fsdb_obd, tbl);
+       rc = nidtbl_update_version(env, fsdb->fsdb_mgs, tbl);
         EXIT;
 
 out:
@@ -377,7 +383,7 @@ static void mgs_nidtbl_fini_fs(struct fs_db *fsdb)
         }
 }
 
-static int mgs_nidtbl_init_fs(struct fs_db *fsdb)
+static int mgs_nidtbl_init_fs(const struct lu_env *env, struct fs_db *fsdb)
 {
         struct mgs_nidtbl *tbl = &fsdb->fsdb_nidtbl;
 
@@ -386,7 +392,7 @@ static int mgs_nidtbl_init_fs(struct fs_db *fsdb)
         tbl->mn_nr_targets = 0;
         tbl->mn_fsdb = fsdb;
         cfs_mutex_lock(&tbl->mn_lock);
-        tbl->mn_version = nidtbl_read_version(fsdb->fsdb_obd, tbl);
+       tbl->mn_version = nidtbl_read_version(env, fsdb->fsdb_mgs, tbl);
         cfs_mutex_unlock(&tbl->mn_lock);
         CDEBUG(D_MGS, "IR: current version is %llu\n", tbl->mn_version);
 
@@ -443,16 +449,16 @@ static int mgs_ir_notify(void *arg)
                        name, cfs_atomic_read(&fsdb->fsdb_notify_phase));
 
                 fsdb->fsdb_notify_start = cfs_time_current();
-                mgs_revoke_lock(fsdb->fsdb_obd, fsdb, CONFIG_T_RECOVER);
+               mgs_revoke_lock(fsdb->fsdb_mgs, fsdb, CONFIG_T_RECOVER);
         }
 
         cfs_complete(&fsdb->fsdb_notify_comp);
         return 0;
 }
 
-int mgs_ir_init_fs(struct obd_device *obd, struct fs_db *fsdb)
+int mgs_ir_init_fs(const struct lu_env *env, struct mgs_device *mgs,
+                  struct fs_db *fsdb)
 {
-        struct mgs_obd *mgs = &obd->u.mgs;
         int rc;
 
         if (!ir_timeout)
@@ -466,7 +472,8 @@ int mgs_ir_init_fs(struct obd_device *obd, struct fs_db *fsdb)
         CFS_INIT_LIST_HEAD(&fsdb->fsdb_clients);
 
         /* start notify thread */
-        fsdb->fsdb_obd = obd;
+       fsdb->fsdb_obd = mgs->mgs_obd;
+       fsdb->fsdb_mgs = mgs;
         cfs_atomic_set(&fsdb->fsdb_notify_phase, 0);
         cfs_waitq_init(&fsdb->fsdb_notify_waitq);
         cfs_init_completion(&fsdb->fsdb_notify_comp);
@@ -476,11 +483,11 @@ int mgs_ir_init_fs(struct obd_device *obd, struct fs_db *fsdb)
         else
                 CERROR("Start notify thread error %d\n", rc);
 
-        mgs_nidtbl_init_fs(fsdb);
+       mgs_nidtbl_init_fs(env, fsdb);
         return 0;
 }
 
-void mgs_ir_fini_fs(struct obd_device *obd, struct fs_db *fsdb)
+void mgs_ir_fini_fs(struct mgs_device *mgs, struct fs_db *fsdb)
 {
         if (cfs_test_bit(FSDB_MGS_SELF, &fsdb->fsdb_flags))
                 return;
@@ -499,10 +506,8 @@ void mgs_ir_fini_fs(struct obd_device *obd, struct fs_db *fsdb)
 /* caller must have held fsdb_mutex */
 static inline void ir_state_graduate(struct fs_db *fsdb)
 {
-        struct mgs_obd *mgs = &fsdb->fsdb_obd->u.mgs;
-
         if (fsdb->fsdb_ir_state == IR_STARTUP) {
-                if (cfs_time_before(mgs->mgs_start_time + ir_timeout,
+               if (cfs_time_before(fsdb->fsdb_mgs->mgs_start_time + ir_timeout,
                                     cfs_time_current_sec())) {
                         fsdb->fsdb_ir_state = IR_FULL;
                         if (fsdb->fsdb_nonir_clients)
@@ -511,7 +516,8 @@ static inline void ir_state_graduate(struct fs_db *fsdb)
         }
 }
 
-int mgs_ir_update(struct obd_device *obd, struct mgs_target_info *mti)
+int mgs_ir_update(const struct lu_env *env, struct mgs_device *mgs,
+                 struct mgs_target_info *mti)
 {
         struct fs_db *fsdb;
         bool notify = true;
@@ -520,11 +526,11 @@ int mgs_ir_update(struct obd_device *obd, struct mgs_target_info *mti)
         if (mti->mti_instance == 0)
                 return -EINVAL;
 
-        rc = mgs_find_or_make_fsdb(obd, mti->mti_fsname, &fsdb);
+       rc = mgs_find_or_make_fsdb(env, mgs, mti->mti_fsname, &fsdb);
         if (rc)
                 return rc;
 
-        rc = mgs_nidtbl_write(fsdb, mti);
+       rc = mgs_nidtbl_write(env, fsdb, mti);
         if (rc)
                 return rc;
 
@@ -594,7 +600,8 @@ static int delogname(char *logname, char *fsname, int *typ)
 
 int mgs_get_ir_logs(struct ptlrpc_request *req)
 {
-        struct obd_device *obd = req->rq_export->exp_obd;
+       struct lu_env     *env = req->rq_svc_thread->t_env;
+       struct mgs_device *mgs = exp2mgs_dev(req->rq_export);
         struct fs_db      *fsdb;
         struct mgs_config_body  *body;
         struct mgs_config_res   *res;
@@ -603,7 +610,6 @@ int mgs_get_ir_logs(struct ptlrpc_request *req)
         char               fsname[16];
         long               bufsize;
         int                unit_size;
-
         int                type;
         int                rc = 0;
         int                i;
@@ -624,9 +630,9 @@ int mgs_get_ir_logs(struct ptlrpc_request *req)
         if (rc)
                 RETURN(rc);
 
-        rc = mgs_find_or_make_fsdb(obd, fsname, &fsdb);
+       rc = mgs_find_or_make_fsdb(env, mgs, fsname, &fsdb);
         if (rc)
-                GOTO(out, rc);
+               RETURN(rc);
 
         bufsize = body->mcb_units << body->mcb_bits;
         nrpages = (bufsize + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT;
@@ -841,10 +847,11 @@ int lprocfs_wr_ir_timeout(struct file *file, const char *buffer,
 
 /* --------------- Handle non IR support clients --------------- */
 /* attach a lustre file system to an export */
-int mgs_fsc_attach(struct obd_export *exp, char *fsname)
+int mgs_fsc_attach(const struct lu_env *env, struct obd_export *exp,
+                  char *fsname)
 {
         struct mgs_export_data *data = &exp->u.eu_mgs_data;
-        struct obd_device *obd       = exp->exp_obd;
+       struct mgs_device *mgs = exp2mgs_dev(exp);
         struct fs_db      *fsdb;
         struct mgs_fsc    *fsc     = NULL;
         struct mgs_fsc    *new_fsc = NULL;
@@ -852,7 +859,7 @@ int mgs_fsc_attach(struct obd_export *exp, char *fsname)
         int                rc;
         ENTRY;
 
-        rc = mgs_find_or_make_fsdb(obd, fsname, &fsdb);
+       rc = mgs_find_or_make_fsdb(env, mgs, fsname, &fsdb);
         if (rc)
                 RETURN(rc);