Whamcloud - gitweb
Branch b1_4_mountconf
[fs/lustre-release.git] / lustre / mgs / mgs_handler.c
index 21ae4fb..7d17a0a 100644 (file)
 
 #include <linux/obd_class.h>
 #include <linux/lustre_dlm.h>
-#include <linux/lustre_mgs.h>
 #include <linux/lprocfs_status.h>
 #include <linux/lustre_fsfilt.h>
 #include <linux/lustre_commit_confd.h>
+#include <linux/lustre_disk.h>
 #include "mgs_internal.h"
 
 static int mgs_postsetup(struct obd_device *obd);
@@ -54,48 +54,30 @@ static int mgs_connect(struct lustre_handle *conn, struct obd_device *obd,
                        struct obd_uuid *cluuid, struct obd_connect_data *data)
 {
         struct obd_export *exp;
-        struct mgs_export_data *med;
-        struct mgs_client_data *mcd;
         int rc, abort_recovery;
         ENTRY;
 
         if (!conn || !obd || !cluuid)
                 RETURN(-EINVAL);
 
-        /* Check for aborted recovery. */
-        spin_lock_bh(&obd->obd_processing_task_lock);
-        abort_recovery = obd->obd_abort_recovery;
-        spin_unlock_bh(&obd->obd_processing_task_lock);
-        if (abort_recovery)
-                target_abort_recovery(obd);
-
         rc = class_connect(conn, obd, cluuid);
         if (rc)
                 RETURN(rc);
         exp = class_conn2export(conn);
         LASSERT(exp);
-        med = &exp->exp_mgs_data;
 
         if (data != NULL) {
-                data->ocd_connect_flags &= MGS_CONNECT_SUPPORTED;
+                data->ocd_connect_flags &= MGMT_CONNECT_SUPPORTED;
                 exp->exp_connect_flags = data->ocd_connect_flags;
         }
 
-        OBD_ALLOC(mcd, sizeof(*mcd));
-        if (!mcd) {
-                CERROR("mgs: out of memory for client data\n");
-                GOTO(out, rc = -ENOMEM);
-        }
-
-        memcpy(mcd->mcd_uuid, cluuid, sizeof(mcd->mcd_uuid));
-        med->med_mcd = mcd;
-
+#if 0
+        /* FIXME: recovery of connection*/
+        rc = mgs_client_add(obd, &obd->u.mgs, med, -1);
+        GOTO(out, rc);
+#endif 
 out:
         if (rc) {
-                if (mcd) {
-                        OBD_FREE(mcd, sizeof(*mcd));
-                        med->med_mcd = NULL;
-                }
                 class_disconnect(exp);
         } else {
                 class_export_put(exp);
@@ -104,15 +86,6 @@ out:
         RETURN(rc);
 }
 
-static int mgs_init_export(struct obd_export *exp)
-{
-        struct mgs_export_data *med = &exp->exp_mgs_data;
-
-        INIT_LIST_HEAD(&med->med_open_head);
-        spin_lock_init(&med->med_open_lock);
-        RETURN(0);
-}
-
 static int mgs_disconnect(struct obd_export *exp)
 {
         unsigned long irqflags;
@@ -124,6 +97,7 @@ static int mgs_disconnect(struct obd_export *exp)
 
         /* Disconnect early so that clients can't keep using export */
         rc = class_disconnect(exp);
+        ldlm_cancel_locks_for_export(exp);
 
         /* complete all outstanding replies */
         spin_lock_irqsave(&exp->exp_lock, irqflags);
@@ -144,52 +118,36 @@ static int mgs_disconnect(struct obd_export *exp)
         RETURN(rc);
 }
 
-/* mount the file system (secretly) */
+/* Start the MGS obd */
 static int mgs_setup(struct obd_device *obd, obd_count len, void *buf)
 {
         struct lprocfs_static_vars lvars;
-        struct lustre_cfg* lcfg = buf;
-        char *options = NULL;
+        char *ns_name = "MGS";
         struct mgs_obd *mgs = &obd->u.mgs;
+        struct lustre_mount_info *lmi;
+        struct lustre_sb_info *lsi;
         struct vfsmount *mnt;
-        unsigned long page;
         int rc = 0;
         ENTRY;
 
-        /* setup 1:/dev/loop/0 2:ext3 3:mgs 4:errors=remount-ro,iopen_nopriv*/
+        CDEBUG(D_CONFIG, "Starting MGS\n");
 
-        if (lcfg->lcfg_bufcount < 3)
+        lmi = server_get_mount(obd->obd_name);
+        if (!lmi) 
                 RETURN(rc = -EINVAL);
 
-        if (LUSTRE_CFG_BUFLEN(lcfg, 1) == 0 || LUSTRE_CFG_BUFLEN(lcfg, 2) == 0)
-                RETURN(rc = -EINVAL);
-
-        obd->obd_fsops = fsfilt_get_ops(lustre_cfg_string(lcfg, 2));
+        mnt = lmi->lmi_mnt;
+        lsi = s2lsi(lmi->lmi_sb);
+        obd->obd_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd));
         if (IS_ERR(obd->obd_fsops))
-                RETURN(rc = PTR_ERR(obd->obd_fsops));
-
-        page = __get_free_page(GFP_KERNEL);
-        if (!page)
-                RETURN(-ENOMEM);
-
-        options = (char *)page;
-        memset(options, 0, PAGE_SIZE);
-
-        if (LUSTRE_CFG_BUFLEN(lcfg, 4) > 0 && lustre_cfg_buf(lcfg, 4))
-                sprintf(options , ",%s", lustre_cfg_string(lcfg, 4));
-
-        //FIXME mount was already done in lustre_fill_super,
-        //we just need to access it
-        mnt = do_kern_mount(lustre_cfg_string(lcfg, 2), 0,
-                            lustre_cfg_string(lcfg, 1), (void *)options);
-        free_page(page);
-        if (IS_ERR(mnt)) {
-                rc = PTR_ERR(mnt);
-                CERROR("do_kern_mount failed: rc = %d\n", rc);
-                GOTO(err_ops, rc);
-        }
+                GOTO(err_put, rc = PTR_ERR(obd->obd_fsops));
 
-        CDEBUG(D_SUPER, "%s: mnt = %p\n", lustre_cfg_string(lcfg, 1), mnt);
+        /* namespace for mgs llog */
+        obd->obd_namespace = ldlm_namespace_new(ns_name, LDLM_NAMESPACE_SERVER);
+        if (obd->obd_namespace == NULL) {
+                mgs_cleanup(obd);
+                GOTO(err_ops, rc = -ENOMEM);
+        }
 
         LASSERT(!lvfs_check_rdonly(lvfs_sbdev(mnt->mnt_sb)));
 
@@ -197,18 +155,12 @@ static int mgs_setup(struct obd_device *obd, obd_count len, void *buf)
         if (rc) {
                 CERROR("%s: MGS filesystem method init failed: rc = %d\n",
                        obd->obd_name, rc);
-                GOTO(err_put, rc);
+                GOTO(err_ns, rc);
         }
 
         rc = llog_start_commit_thread();
         if (rc < 0)
                 GOTO(err_fs, rc);
-#if 0  
-        //FIXME: no LDLM support for llog now
-        ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
-                           "mgs_ldlm_client", &obd->obd_ldlm_client);
-#endif
-        obd->obd_replayable = 1;
 
         rc = mgs_postsetup(obd);
         if (rc)
@@ -217,28 +169,8 @@ static int mgs_setup(struct obd_device *obd, obd_count len, void *buf)
         lprocfs_init_vars(mgs, &lvars);
         lprocfs_obd_setup(obd, lvars.obd_vars);
 
-        if (obd->obd_recovering) {
-                LCONSOLE_WARN("MGT %s now serving %s, but will be in recovery "
-                              "until %d %s reconnect, or if no clients "
-                              "reconnect for %d:%.02d; during that time new "
-                              "clients will not be allowed to connect. "
-                              "Recovery progress can be monitored by watching "
-                              "/proc/fs/lustre/mgs/%s/recovery_status.\n",
-                              obd->obd_name,
-                              lustre_cfg_string(lcfg, 1),
-                              obd->obd_recoverable_clients,
-                              (obd->obd_recoverable_clients == 1) 
-                              ? "client" : "clients",
-                              (int)(OBD_RECOVERY_TIMEOUT / HZ) / 60,
-                              (int)(OBD_RECOVERY_TIMEOUT / HZ) % 60,
-                              obd->obd_name);
-        } else {
-                LCONSOLE_INFO("MGT %s now serving %s with recovery %s.\n",
-                              obd->obd_name,
-                              lustre_cfg_string(lcfg, 1),
-                              obd->obd_replayable ? "enabled" : "disabled");
-        }
-//FIXME: no ldlm support now
+        LCONSOLE_INFO("MGS %s started\n", obd->obd_name);
+
         ldlm_timeout = 6;
         ping_evictor_start();
 
@@ -247,13 +179,14 @@ static int mgs_setup(struct obd_device *obd, obd_count len, void *buf)
 err_fs:
         /* No extra cleanup needed for llog_init_commit_thread() */
         mgs_fs_cleanup(obd);
-err_put:
-        unlock_kernel();
-        mntput(mgs->mgs_vfsmnt);
-        mgs->mgs_sb = 0;
-        lock_kernel();
+err_ns:
+        ldlm_namespace_free(obd->obd_namespace, 0);
+        obd->obd_namespace = NULL;
 err_ops:
         fsfilt_put_ops(obd->obd_fsops);
+err_put:
+        server_put_mount(obd->obd_name, mgs->mgs_vfsmnt);
+        mgs->mgs_sb = 0;
         return rc;
 }
 
@@ -281,7 +214,6 @@ static int mgs_cleanup(struct obd_device *obd)
 {
         struct mgs_obd *mgs = &obd->u.mgs;
         lvfs_sbdev_type save_dev;
-        int must_relock = 0;
         ENTRY;
 
         ping_evictor_stop();
@@ -290,26 +222,17 @@ static int mgs_cleanup(struct obd_device *obd)
                 RETURN(0);
         save_dev = lvfs_sbdev(mgs->mgs_sb);
 
-        lprocfs_obd_cleanup(obd);
+//       lprocfs_obd_cleanup(obd);
 
-        mgs_update_server_data(obd, 1);
//       mgs_update_server_data(obd, 1);
 
-        mgs_fs_cleanup(obd);
-
-        if (atomic_read(&obd->u.mgs.mgs_vfsmnt->mnt_count) > 2)
-                CERROR("%s: mount busy, mnt_count %d != 2\n", obd->obd_name,
-                       atomic_read(&obd->u.mgs.mgs_vfsmnt->mnt_count));
-
-        /* We can only unlock kernel if we are in the context of sys_ioctl,
-           otherwise we never called lock_kernel */
-        if (kernel_locked()) {
-                unlock_kernel();
-                must_relock++;
-        }
+        //mgs_fs_cleanup(obd);
 
-        mntput(mgs->mgs_vfsmnt);
+        server_put_mount(obd->obd_name, mgs->mgs_vfsmnt);
         mgs->mgs_sb = NULL;
 
+        ldlm_namespace_free(obd->obd_namespace, obd->obd_force);
+
         spin_lock_bh(&obd->obd_processing_task_lock);
         if (obd->obd_recovering) {
                 target_cancel_recovery_timer(obd);
@@ -319,334 +242,102 @@ static int mgs_cleanup(struct obd_device *obd)
 
         lvfs_clear_rdonly(save_dev);
 
-        if (must_relock)
-                lock_kernel();
-
         fsfilt_put_ops(obd->obd_fsops);
 
-        LCONSOLE_INFO("MDT %s has stopped.\n", obd->obd_name);
+        LCONSOLE_INFO("MGS %s has stopped.\n", obd->obd_name);
 
         RETURN(0);
 }
 
-/* Look up an entry by inode number. */
-/* this function ONLY returns valid dget'd dentries with an initialized inode
-   or errors */
-struct dentry *mgs_fid2dentry(struct mgs_obd *mgs, struct ll_fid *fid,
-                              struct vfsmount **mnt)
-{
-        unsigned long ino = fid->id;
-        __u32 generation = fid->generation;
-        struct mgs_open_llogs *mollog, *n;
-        struct list_head *llog_list = &mgs->mgs_open_llogs;
-        struct inode *inode;
-        struct dentry *result = NULL;
-
-        if (ino == 0)
-                RETURN(ERR_PTR(-ESTALE));
-
-
-        CDEBUG(D_DENTRY, "--> mgs_fid2dentry: ino/gen %lu/%u, sb %p\n",
-               ino, generation, mgs->mgs_sb);
-
-        list_for_each_entry_safe(mollog, n, llog_list, mol_list) {
-                if (mollog->mod_id == ino) {
-                        result = mollog->mol_dentry;
-                        dget(result);
-                }
-        }
-
-        if (!result)
-                RETURN(NULL);
-
-        inode = result->d_inode;
-        if (!inode)
-                RETURN(ERR_PTR(-ENOENT));
-
-        if (generation && inode->i_generation != generation) {
-                /* we didn't find the right inode.. */
-                CERROR("bad inode %lu, link: %lu ct: %d or generation %u/%u\n",
-                       inode->i_ino, (unsigned long)inode->i_nlink,
-                       atomic_read(&inode->i_count), inode->i_generation,
-                       generation);
-                dput(result);
-                RETURN(ERR_PTR(-ENOENT));
-        }
-
-        if (mnt) {
-                *mnt = mgs->mgs_vfsmnt;
-                mntget(*mnt);
-        }
-
-        RETURN(result);
-}
-
-static struct dentry *mgs_lvfs_fid2dentry(__u64 id, __u32 gen, __u64 gr,
-                                          void *data)
-{
-        struct obd_device *obd = data;
-        struct ll_fid fid;
-        fid.id = id;
-        fid.generation = gen;
-        return mgs_fid2dentry(&obd->u.mgs, &fid, NULL);
-}
-
-
-int mgs_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
-                  void *karg, void *uarg)
-{
-        static struct obd_uuid cfg_uuid = { .uuid = "config_uuid" };
-        struct obd_device *obd = exp->exp_obd;
+static int mgs_handle_target_add(struct ptlrpc_request *req)
+{    
+        struct obd_device *obd = &req->rq_export->exp_obd;
         struct mgs_obd *mgs = &obd->u.mgs;
-        struct obd_ioctl_data *data = karg;
-        struct lvfs_run_ctxt saved;
-        int rc = 0;
-
-        ENTRY;
-        CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
-
-        switch (cmd) {
-        case OBD_IOC_RECORD: {
-                char *name = data->ioc_inlbuf1;
-                if (mgs->mgs_cfg_llh)
-                        RETURN(-EBUSY);
-
-                push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-                rc = llog_create(llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT),
-                                 &mgs->mgs_cfg_llh, NULL, name);
-                if (rc == 0)
-                        llog_init_handle(mgs->mgs_cfg_llh, LLOG_F_IS_PLAIN,
-                                         &cfg_uuid);
-                else
-                        mgs->mgs_cfg_llh = NULL;
-                pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-
-                RETURN(rc);
-        }
-
-        case OBD_IOC_ENDRECORD: {
-                if (!mgs->mgs_cfg_llh)
-                        RETURN(-EBADF);
-
-                push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-                rc = llog_close(mgs->mgs_cfg_llh);
-                pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-
-                mgs->mgs_cfg_llh = NULL;
-                RETURN(rc);
-        }
-
-        case OBD_IOC_CLEAR_LOG: {
-                char *name = data->ioc_inlbuf1;
-                if (mgs->mgs_cfg_llh)
-                        RETURN(-EBUSY);
-
-                push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-                rc = llog_create(llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT),
-                                 &mgs->mgs_cfg_llh, NULL, name);
-                if (rc == 0) {
-                        llog_init_handle(mgs->mgs_cfg_llh, LLOG_F_IS_PLAIN,
-                                         NULL);
-
-                        rc = llog_destroy(mgs->mgs_cfg_llh);
-                        llog_free_handle(mgs->mgs_cfg_llh);
-                }
-                pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-
-                mgs->mgs_cfg_llh = NULL;
-                RETURN(rc);
-        }
-
-        case OBD_IOC_DORECORD: {
-                char *cfg_buf;
-                struct llog_rec_hdr rec;
-                if (!mgs->mgs_cfg_llh)
-                        RETURN(-EBADF);
-
-                rec.lrh_len = llog_data_len(data->ioc_plen1);
-
-                if (data->ioc_type == LUSTRE_CFG_TYPE) {
-                        rec.lrh_type = OBD_CFG_REC;
-                } else {
-                        CERROR("unknown cfg record type:%d \n", data->ioc_type);
-                        RETURN(-EINVAL);
-                }
-
-                OBD_ALLOC(cfg_buf, data->ioc_plen1);
-                if (cfg_buf == NULL)
-                        RETURN(-EINVAL);
-                rc = copy_from_user(cfg_buf, data->ioc_pbuf1, data->ioc_plen1);
-                if (rc) {
-                        OBD_FREE(cfg_buf, data->ioc_plen1);
-                        RETURN(rc);
-                }
-
-                push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-                rc = llog_write_rec(mgs->mgs_cfg_llh, &rec, NULL, 0,
-                                    cfg_buf, -1);
-                pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-
-                OBD_FREE(cfg_buf, data->ioc_plen1);
-                RETURN(rc);
-        }
-
-        case OBD_IOC_PARSE: {
-                struct llog_ctxt *ctxt =
-                        llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
-                push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-                rc = class_config_parse_llog(ctxt, data->ioc_inlbuf1, NULL);
-                pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-                if (rc)
-                        RETURN(rc);
-
-                RETURN(rc);
-        }
-
-        case OBD_IOC_DUMP_LOG: {
-                struct llog_ctxt *ctxt =
-                        llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
-                push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-                rc = class_config_dump_llog(ctxt, data->ioc_inlbuf1, NULL);
-                pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-                if (rc)
-                        RETURN(rc);
-
-                RETURN(rc);
-        }
-
-        case OBD_IOC_SYNC: {
-                CDEBUG(D_HA, "syncing mgs %s\n", obd->obd_name);
-                rc = fsfilt_sync(obd, obd->u.mgs.mgs_sb);
-                RETURN(rc);
-        }
-
-        case OBD_IOC_SET_READONLY: {
-                void *handle;
-                struct inode *inode = obd->u.mgs.mgs_sb->s_root->d_inode;
-                BDEVNAME_DECLARE_STORAGE(tmp);
-                CERROR("*** setting device %s read-only ***\n",
-                       ll_bdevname(obd->u.mgs.mgs_sb, tmp));
-
-                handle = fsfilt_start(obd, inode, FSFILT_OP_MKNOD, NULL);
-                if (!IS_ERR(handle))
-                        rc = fsfilt_commit(obd, inode, handle, 1);
-
-                CDEBUG(D_HA, "syncing mgs %s\n", obd->obd_name);
-                rc = fsfilt_sync(obd, obd->u.mgs.mgs_sb);
-
-                lvfs_set_rdonly(lvfs_sbdev(obd->u.mgs.mgs_sb));
-                RETURN(0);
-        }
-
-
-        case OBD_IOC_LLOG_CHECK:
-        case OBD_IOC_LLOG_CANCEL:
-        case OBD_IOC_LLOG_REMOVE: {
-                struct llog_ctxt *ctxt =
-                        llog_get_context(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);
-
-                RETURN(rc);
-        }
-        case OBD_IOC_LLOG_INFO:
-        case OBD_IOC_LLOG_PRINT: {
-                struct llog_ctxt *ctxt =
-                        llog_get_context(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);
+        struct mgmt_target_info *req_mti, *mti, *rep_mti;
+        int rep_size = sizeof(*mti);
+        int index, rc;
 
-                RETURN(rc);
+        OBD_ALLOC(mti, sizeof(*mti));
+        if (!mti)
+                GOTO(out, rc = -ENOMEM);
+        req_mti = lustre_swab_reqbuf(req, 0, sizeof(*mti),
+                                     lustre_swab_mgmt_target_info);
+        memcpy(mti, req_mti, sizeof(*mti));
+        
+        /* NEED_INDEX implies NEED_REGISTER, but not vice-versa */
+        if (mti->mti_flags & LDD_F_NEED_INDEX) {
+                rc = mgs_get_index(mti);
+               // rc = mgmt_handle_first_connect(req);
         }
 
-        case OBD_IOC_ABORT_RECOVERY:
-                CERROR("aborting recovery for device %s\n", obd->obd_name);
-                target_abort_recovery(obd);
-                RETURN(0);
-
-        default:
-                CDEBUG(D_INFO, "unknown command %x\n", cmd);
-                RETURN(-EINVAL);
+        if (mti->mti_flags & LDD_F_SV_TYPE_MDT) {
+                rc = llog_add_mds(obd, mti);
         }
-        RETURN(0);
 
+out:
+        lustre_pack_reply(req, 1, &rep_size, NULL); 
+        rep_mti = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*rep_mti));
+        memcpy(rep_mti, mti, sizeof(*rep_mti));
+        if (rc)
+                rep_mti->mti_stripe_index = rc;
+        return rc;
 }
 
-
 int mgs_handle(struct ptlrpc_request *req)
 {
-        int should_process, fail = OBD_FAIL_MGS_ALL_REPLY_NET;
+        int fail = OBD_FAIL_MGMT_ALL_REPLY_NET;
         int rc = 0;
-        struct mgs_obd *mgs = NULL; /* quell gcc overwarning */
-        struct obd_device *obd = NULL;
         ENTRY;
 
-        OBD_FAIL_RETURN(OBD_FAIL_MGS_ALL_REQUEST_NET | OBD_FAIL_ONCE, 0);
+        OBD_FAIL_RETURN(OBD_FAIL_MGMT_ALL_REQUEST_NET | OBD_FAIL_ONCE, 0);
 
         LASSERT(current->journal_info == NULL);
-        /* XXX identical to MDS */
-        if (req->rq_reqmsg->opc != MGS_CONNECT) {
-                struct mgs_export_data *med;
-                int abort_recovery;
-
+        if (req->rq_reqmsg->opc != MGMT_CONNECT) {
                 if (req->rq_export == NULL) {
                         CERROR("lustre_mgs: operation %d on unconnected MGS\n",
                                req->rq_reqmsg->opc);
                         req->rq_status = -ENOTCONN;
                         GOTO(out, rc = -ENOTCONN);
                 }
-
-                med = &req->rq_export->exp_mgs_data;
-                obd = req->rq_export->exp_obd;
-                mgs = &obd->u.mgs;
-
-                /* sanity check: if the xid matches, the request must
-                 * be marked as a resent or replayed */
-                if (req->rq_xid == med->med_mcd->mcd_last_xid)
-                        LASSERTF(lustre_msg_get_flags(req->rq_reqmsg) &
-                                 (MSG_RESENT | MSG_REPLAY),
-                                 "rq_xid "LPU64" matches last_xid, "
-                                 "expected RESENT flag\n",
-                                 req->rq_xid);
-                /* else: note the opposite is not always true; a
-                 * RESENT req after a failover will usually not match
-                 * the last_xid, since it was likely never
-                 * committed. A REPLAYed request will almost never
-                 * match the last xid, however it could for a
-                 * committed, but still retained, open. */
-
-                /* Check for aborted recovery. */
-                spin_lock_bh(&obd->obd_processing_task_lock);
-                abort_recovery = obd->obd_abort_recovery;
-                spin_unlock_bh(&obd->obd_processing_task_lock);
-                if (abort_recovery) {
-                        target_abort_recovery(obd);
-                } 
         }
 
         switch (req->rq_reqmsg->opc) {
-        case MGS_CONNECT:
+        case MGMT_CONNECT:
                 DEBUG_REQ(D_INODE, req, "connect");
-                OBD_FAIL_RETURN(OBD_FAIL_MGS_CONNECT_NET, 0);
+                OBD_FAIL_RETURN(OBD_FAIL_MGMT_CONNECT_NET, 0);
                 rc = target_handle_connect(req, mgs_handle);
-                if (!rc) {
-                        /* Now that we have an export, set mgs. */
-                        obd = req->rq_export->exp_obd;
-                        mgs = mgs_req2mgs(req);
-                }
                 break;
-
-        case MGS_DISCONNECT:
+        case MGMT_DISCONNECT:
                 DEBUG_REQ(D_INODE, req, "disconnect");
-                OBD_FAIL_RETURN(OBD_FAIL_MGS_DISCONNECT_NET, 0);
+                OBD_FAIL_RETURN(OBD_FAIL_MGMT_DISCONNECT_NET, 0);
                 rc = target_handle_disconnect(req);
                 req->rq_status = rc;            /* superfluous? */
                 break;
 
+        case MGMT_TARGET_ADD:
+                CDEBUG(D_INODE, "target add\n");
+                rc = mgs_handle_target_add(req);
+                break;
+        case MGMT_TARGET_DEL:
+                CDEBUG(D_INODE, "target del\n");
+                //rc = mgs_handle_target_del(req);
+                break;
+
+        case LDLM_ENQUEUE:
+                DEBUG_REQ(D_INODE, req, "enqueue");
+                OBD_FAIL_RETURN(OBD_FAIL_LDLM_ENQUEUE, 0);
+                rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
+                                         ldlm_server_blocking_ast, NULL);
+                fail = OBD_FAIL_LDLM_REPLY;
+                break;
+        case LDLM_BL_CALLBACK:
+        case LDLM_CP_CALLBACK:
+                DEBUG_REQ(D_INODE, req, "callback");
+                CERROR("callbacks should not happen on MDS\n");
+                LBUG();
+                OBD_FAIL_RETURN(OBD_FAIL_LDLM_BL_CALLBACK, 0);
+                break;
+
         case OBD_PING:
                 DEBUG_REQ(D_INODE, req, "ping");
                 rc = target_handle_ping(req);
@@ -691,29 +382,9 @@ int mgs_handle(struct ptlrpc_request *req)
 
         LASSERT(current->journal_info == NULL);
 
-        /* If we're DISCONNECTing, the mgs_export_data is already freed */
-        if (!rc && req->rq_reqmsg->opc != MGS_DISCONNECT) {
-                struct mgs_export_data *med = &req->rq_export->exp_mgs_data;
-                req->rq_repmsg->last_xid =
-                        le64_to_cpu(med->med_mcd->mcd_last_xid);
-
-                target_committed_to_req(req);
-        }
-
-        EXIT;
  out:
-
-        if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_LAST_REPLAY) {
-                if (obd && obd->obd_recovering) {
-                        DEBUG_REQ(D_HA, req, "LAST_REPLAY, queuing reply");
-                        return target_queue_final_reply(req, rc);
-                }
-                /* Lost a race with recovery; let the error path DTRT. */
-                rc = req->rq_status = -ENOTCONN;
-        }
-
         target_send_reply(req, rc, fail);
-        return 0;
+        RETURN(0);
 }
 
 static int mgt_setup(struct obd_device *obd, obd_count len, void *buf)
@@ -723,22 +394,22 @@ static int mgt_setup(struct obd_device *obd, obd_count len, void *buf)
         int rc = 0;
         ENTRY;
 
-        lprocfs_init_vars(mgt, &lvars);
-        lprocfs_obd_setup(obd, lvars.obd_vars);
+       lprocfs_init_vars(mgt, &lvars);
+       lprocfs_obd_setup(obd, lvars.obd_vars);
 
         mgs->mgs_service =
                 ptlrpc_init_svc(MGS_NBUFS, MGS_BUFSIZE, MGS_MAXREQSIZE,
-                                MGS_REQUEST_PORTAL, MGC_REPLY_PORTAL,
-                                MGS_SERVICE_WATCHDOG_TIMEOUT,
-                                mgs_handle, "mgs", obd->obd_proc_entry, NULL);
+                                MGS_MAXREPSIZE, MGS_REQUEST_PORTAL, 
+                                MGC_REPLY_PORTAL, MGS_SERVICE_WATCHDOG_TIMEOUT,
+                                mgs_handle, "mgs", obd->obd_proc_entry, NULL,
+                                MGT_NUM_THREADS);
 
         if (!mgs->mgs_service) {
                 CERROR("failed to start service\n");
                 GOTO(err_lprocfs, rc = -ENOMEM);
         }
 
-        rc = ptlrpc_start_n_threads(obd, mgs->mgs_service, MGT_NUM_THREADS,
-                                    "ll_mgt");
+        rc = ptlrpc_start_threads(obd, mgs->mgs_service, "ll_mgt");
         if (rc)
                 GOTO(err_thread, rc);
 
@@ -751,6 +422,7 @@ err_lprocfs:
         return rc;
 }
 
+
 static int mgt_cleanup(struct obd_device *obd)
 {
         struct mgs_obd *mgs = &obd->u.mgs;
@@ -764,14 +436,14 @@ static int mgt_cleanup(struct obd_device *obd)
 }
 
 struct lvfs_callback_ops mgs_lvfs_ops = {
-        l_fid2dentry:     mgs_lvfs_fid2dentry,
+     //     l_fid2dentry:     mgs_lvfs_fid2dentry,
+    //    l_open_llog:      mgs_lvfs_open_llog,
 };
 
 /* use obd ops to offer management infrastructure */
 static struct obd_ops mgs_obd_ops = {
         .o_owner           = THIS_MODULE,
         .o_connect         = mgs_connect,
-        .o_init_export     = mgs_init_export,
         .o_disconnect      = mgs_disconnect,
         .o_setup           = mgs_setup,
         .o_precleanup      = mgs_precleanup,
@@ -787,7 +459,6 @@ static struct obd_ops mgt_obd_ops = {
 
 static int __init mgs_init(void)
 {
-        int rc;
         struct lprocfs_static_vars lvars;
 
         lprocfs_init_vars(mgs, &lvars);