Whamcloud - gitweb
new llog open mechanism
authorlincent <lincent>
Mon, 22 Aug 2005 16:38:13 +0000 (16:38 +0000)
committerlincent <lincent>
Mon, 22 Aug 2005 16:38:13 +0000 (16:38 +0000)
   next step:
       update llogs

24 files changed:
lustre/include/linux/lustre_cfg.h
lustre/include/linux/lustre_disk.h
lustre/include/linux/lustre_log.h
lustre/include/linux/lvfs.h
lustre/include/linux/obd.h
lustre/include/linux/obd_class.h
lustre/lov/lov_obd.c
lustre/lvfs/lvfs_common.c
lustre/mds/mds_lov.c
lustre/mgc/mgc_request.c
lustre/mgs/mgs_fs.c
lustre/mgs/mgs_handler.c
lustre/mgs/mgs_internal.h
lustre/mgs/mgs_llog.c [new file with mode: 0644]
lustre/obdclass/llog_cat.c
lustre/obdclass/llog_ioctl.c
lustre/obdclass/llog_lvfs.c
lustre/obdclass/llog_obd.c
lustre/obdclass/llog_swab.c
lustre/obdclass/llog_test.c
lustre/obdclass/obd_config.c
lustre/obdclass/obd_mount.c
lustre/ptlrpc/llog_server.c
lustre/ptlrpc/recov_thread.c

index f2996bc..40408f5 100644 (file)
@@ -27,7 +27,8 @@
  * 1cf6
  * lcfG
  */
-#define LUSTRE_CFG_VERSION 0x1cf60001
+#define LUSTRE_CFG_MAGIC 0x1cf60001
+#define LUSTRE_CFG_START_VERSION 0x10000001
 #define LUSTRE_CFG_MAX_BUFCOUNT 8
 
 #define LCFG_HDR_SIZE(count) \
@@ -57,6 +58,7 @@ struct lustre_cfg_bufs {
 };
 
 struct lustre_cfg {
+        uint32_t lcfg_magic;
         uint32_t lcfg_version;
         uint32_t lcfg_command;
 
@@ -182,7 +184,8 @@ static inline struct lustre_cfg *lustre_cfg_new(int cmd,
         if (!lcfg)
                 RETURN(lcfg);
 
-        lcfg->lcfg_version = LUSTRE_CFG_VERSION;
+        lcfg->lcfg_magic = LUSTRE_CFG_MAGIC;
+        lcfg->lcfg_version = LUSTRE_CFG_START_VERSION;
         lcfg->lcfg_command = cmd;
         lcfg->lcfg_bufcount = bufs->lcfg_bufcount;
 
@@ -216,7 +219,7 @@ static inline int lustre_cfg_sanity_check(void *buf, int len)
         if (len < LCFG_HDR_SIZE(0))
                 RETURN(-EINVAL);
 
-        if (lcfg->lcfg_version != LUSTRE_CFG_VERSION)
+        if (lcfg->lcfg_magic != LUSTRE_CFG_MAGIC)
                 RETURN(-EINVAL);
         if (lcfg->lcfg_bufcount >= LUSTRE_CFG_MAX_BUFCOUNT)
                 RETURN(-EINVAL);
index 4b7e07d..91ae67d 100644 (file)
@@ -72,12 +72,12 @@ struct host_desc {
 
 struct lustre_disk_data {
         __u32     ldd_magic;
-        __u32     ldd_flags;           /* LDD_SV_TYPE */
-        struct host_desc ldd_mgmtnid;  /* mgmt nid; lmd can override */
-        char      ldd_fsname[64];      /* filesystem this server is part of */
-        char      ldd_svname[64];      /* this server's name (lustre-mdt0001) */
-        enum ldd_mount_type ldd_mount_type; /* target fs type LDD_MT_* */
-        char      ldd_mount_opts[128]; /* target fs mount opts */
+        __u32     ldd_flags;                 /* LDD_SV_TYPE */
+        char      ldd_fsname[64];            /* filesystem this server is part of */
+        char      ldd_svname[64];            /* this server's name (lustre-mdt0001) */
+        char      ldd_mount_opts[128];       /* target fs mount opts */
+        struct host_desc    ldd_mgmtnid;     /* mgmt nid; lmd can override */
+        enum ldd_mount_type ldd_mount_type;  /* target fs type LDD_MT_* */
 };
         
 #define IS_MDT(data)   ((data)->ldd_flags & LDD_F_SV_TYPE_MDT)
index c412cd5..3b1ebc6 100644 (file)
@@ -182,6 +182,8 @@ struct llog_operations {
         int (*lop_connect)(struct llog_ctxt *ctxt, int count,
                            struct llog_logid *logid, struct llog_gen *gen,
                            struct obd_uuid *uuid);
+        int (*lop_update)(struct llog_ctxt *ctxt, struct llog_handle **,
+                           struct llog_logid *logid, void *data);
         /* XXX add 2 more: commit callbacks and llog recovery functions */
 };
 
@@ -362,7 +364,7 @@ static inline int llog_next_block(struct llog_handle *loghandle, int *cur_idx,
 }
 
 static inline int llog_create(struct llog_ctxt *ctxt, struct llog_handle **res,
-                              struct llog_logid *logid, char *name)
+                              struct llog_logid *logid, char*fsname, char *name)
 {
         struct llog_operations *lop;
         int rc;
@@ -374,7 +376,7 @@ static inline int llog_create(struct llog_ctxt *ctxt, struct llog_handle **res,
         if (lop->lop_create == NULL)
                 RETURN(-EOPNOTSUPP);
 
-        rc = lop->lop_create(ctxt, res, logid, NULL/*fsname*/, name);
+        rc = lop->lop_create(ctxt, res, logid, fsname, name);
         RETURN(rc);
 }
 
index 34abec8..11d97cb 100644 (file)
@@ -48,6 +48,7 @@ struct lvfs_ucred {
 
 struct lvfs_callback_ops {
         struct dentry *(*l_fid2dentry)(__u64 id_ino, __u32 gen, __u64 gr, void *data);
+        int (*l_open_llog) (__u64 id_ino, struct dentry *dentry, void *data);
 };
 
 #define OBD_RUN_CTXT_MAGIC      0xC0FFEEAA
@@ -72,10 +73,11 @@ struct lvfs_run_ctxt {
 
 /* lvfs_common.c */
 struct dentry *lvfs_fid2dentry(struct lvfs_run_ctxt *, __u64, __u32, __u64 ,void *data);
+int lvfs_open_llog(struct lvfs_run_ctxt*, __u64, struct dentry*, void *data);
 
 void push_ctxt(struct lvfs_run_ctxt *save, struct lvfs_run_ctxt *new_ctx,
                struct lvfs_ucred *cred);
-void pop_ctxt(struct lvfs_run_ctxt *saved, struct lvfs_run_ctxt *new_ctx,
+void pop_ctxt(struct lvfs_run_ctxt *saveu, struct lvfs_run_ctxt *new_ctx,
               struct lvfs_ucred *cred);
 
 #ifdef __KERNEL__
index 820633b..cb5e1fc 100644 (file)
@@ -319,6 +319,7 @@ struct mgs_obd {
         struct vfsmount                 *mgs_vfsmnt;
         struct super_block              *mgs_sb;
         struct dentry                   *mgs_configs_dir;
+        spinlock_t                       mgs_llogs_lock;
         struct list_head                 mgs_open_llogs;
         struct llog_handle              *mgs_cfg_llh;
 };
index b77e892..9475cea 100644 (file)
@@ -31,6 +31,7 @@
 #include <asm/uaccess.h>
 #include <linux/types.h>
 #include <linux/fs.h>
+#include <linux/dcache.h>
 #include <linux/time.h>
 #include <linux/timer.h>
 #endif
@@ -580,6 +581,15 @@ obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
                                exp->exp_obd);
 }
 
+static inline int 
+obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
+{
+        LASSERT(exp->exp_obd);
+
+        return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino, 
+                              dentry, exp->exp_obd);
+}
+
 #ifndef time_before
 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
 #endif
index 22120b5..9629989 100644 (file)
@@ -250,6 +250,9 @@ static int lov_disconnect_obd(struct obd_device *obd, struct lov_tgt_desc *tgt)
         RETURN(0);
 }
 
+static int
+lov_del_obd(struct obd_device *obd, struct obd_uuid *uuidp, int index, int gen);
+
 static int lov_disconnect(struct obd_export *exp)
 {
         struct obd_device *obd = class_exp2obd(exp);
@@ -272,7 +275,7 @@ static int lov_disconnect(struct obd_export *exp)
         for (i = 0, tgt = lov->tgts; i < lov->desc.ld_tgt_count; i++, tgt++) {
                 if (tgt->ltd_exp) {
                         /* Disconnect and delete from list */
-                        lov_del_obd(obd, obd->obd_uuid, i, tgt->ltd_gen);
+                        lov_del_obd(obd, &obd->obd_uuid, i, tgt->ltd_gen);
                         /* Cleanup the osc now - can't do it from 
                            lov_cleanup because we lose our only reference to 
                            it right now. */ 
index d8ab4a3..e5593da 100644 (file)
@@ -32,4 +32,15 @@ struct dentry *lvfs_fid2dentry(struct lvfs_run_ctxt *ctxt, __u64 id,
 {
         return ctxt->cb_ops.l_fid2dentry(id, gen, gr, data);
 }
+
+int lvfs_open_llog(struct lvfs_run_ctxt *ctxt, __u64 id,
+                   struct dentry *dentry, void *data)
+{
+        if (ctxt->cb_ops.l_open_llog)
+                return ctxt->cb_ops.l_open_llog(id, dentry, data);
+        else
+                return 0;
+}
+
 EXPORT_SYMBOL(lvfs_fid2dentry);
+EXPORT_SYMBOL(lvfs_open_llog);
index fa562fe..6a5b8b0 100644 (file)
@@ -262,7 +262,7 @@ int mds_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
 
                 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
                 rc = llog_create(llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT),
-                                 &mds->mds_cfg_llh, NULL, name);
+                                 &mds->mds_cfg_llh, NULL, NULL, name);
                 if (rc == 0)
                         llog_init_handle(mds->mds_cfg_llh, LLOG_F_IS_PLAIN,
                                          &cfg_uuid);
@@ -292,7 +292,7 @@ int mds_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
 
                 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
                 rc = llog_create(llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT),
-                                 &mds->mds_cfg_llh, NULL, name);
+                                 &mds->mds_cfg_llh, NULL, NULL, name);
                 if (rc == 0) {
                         llog_init_handle(mds->mds_cfg_llh, LLOG_F_IS_PLAIN,
                                          NULL);
index 77d95a1..26251db 100644 (file)
 #include <linux/lustre_log.h>
 #include <linux/lustre_fsfilt.h>
 #include <linux/lustre_disk.h>
-//#include <linux/lprocfs_status.h>
 
 #include "mgc_internal.h"
-
           
 static int mgc_fs_setup(struct obd_device *obd, struct super_block *sb, 
                         struct vfsmount *mnt)
index ad60989..9a9b0e8 100644 (file)
@@ -50,7 +50,7 @@ int mgs_fs_setup(struct obd_device *obd, struct vfsmount *mnt)
 {
         struct mgs_obd *mgs = &obd->u.mgs;
         struct lvfs_run_ctxt saved;
-        struct dentry *dentry;
+        struct dentry *logs_dentry;
         int rc;
         ENTRY;
 
@@ -72,17 +72,15 @@ int mgs_fs_setup(struct obd_device *obd, struct vfsmount *mnt)
         /* setup the directory tree */
         push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
 
-        dentry = simple_mkdir(current->fs->pwd, MOUNT_CONFIGS_DIR, 0777, 1);
-        if (IS_ERR(dentry)) {
-                rc = PTR_ERR(dentry);
+        logs_dentry = simple_mkdir(current->fs->pwd, MOUNT_CONFIGS_DIR, 0777, 1);
+        if (IS_ERR(logs_dentry)) {
+                rc = PTR_ERR(logs_dentry);
                 CERROR("cannot create %s directory: rc = %d\n", 
                        MOUNT_CONFIGS_DIR, rc);
                 GOTO(err_pop, rc);
         }
 
-        mgs->mgs_configs_dir = dentry;
-     
-        INIT_LIST_HEAD(&mgs->mgs_open_llogs);
+        mgs->mgs_configs_dir = logs_dentry;
 
 err_pop:
         pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
index 21ae4fb..40a25c3 100644 (file)
@@ -40,7 +40,6 @@
 
 #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>
@@ -200,6 +199,8 @@ static int mgs_setup(struct obd_device *obd, obd_count len, void *buf)
                 GOTO(err_put, rc);
         }
 
+        INIT_LIST_HEAD(&mgs->mgs_open_llogs);
+
         rc = llog_start_commit_thread();
         if (rc < 0)
                 GOTO(err_fs, rc);
@@ -337,7 +338,7 @@ struct dentry *mgs_fid2dentry(struct mgs_obd *mgs, struct ll_fid *fid,
 {
         unsigned long ino = fid->id;
         __u32 generation = fid->generation;
-        struct mgs_open_llogs *mollog, *n;
+        struct mgs_open_llog *mollog, *n;
         struct list_head *llog_list = &mgs->mgs_open_llogs;
         struct inode *inode;
         struct dentry *result = NULL;
@@ -350,7 +351,7 @@ struct dentry *mgs_fid2dentry(struct mgs_obd *mgs, struct ll_fid *fid,
                ino, generation, mgs->mgs_sb);
 
         list_for_each_entry_safe(mollog, n, llog_list, mol_list) {
-                if (mollog->mod_id == ino) {
+                if (mollog->mol_id == ino) {
                         result = mollog->mol_dentry;
                         dget(result);
                 }
@@ -391,195 +392,40 @@ static struct dentry *mgs_lvfs_fid2dentry(__u64 id, __u32 gen, __u64 gr,
         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 int mgs_lvfs_open_llog(__u64 id, struct dentry *dentry , void *data)
 {
-        static struct obd_uuid cfg_uuid = { .uuid = "config_uuid" };
-        struct obd_device *obd = exp->exp_obd;
+        struct obd_device *obd = data; 
         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);
+        struct mgs_open_llog *mollog, *n;
+        struct list_head *llog_list = &mgs->mgs_open_llogs;
+         
+        list_for_each_entry_safe(mollog, n, llog_list, mol_list) {
+                if (mollog->mol_id == id) {
+                        dget(dentry);
+                        return 0;
                 }
-
-                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);
+        /* add a new open llog  to mgs_open_llogs */
+        OBD_ALLOC(mollog, sizeof(*mollog));
+        if (!mollog) {
+                CERROR("No memory for mollog.\n");
+                return -ENOMEM;
         }
+        mollog->mol_id = id;
+        mollog->mol_dentry = dentry;
+        mollog->mol_update = 0;
 
-        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);
-
-                RETURN(rc);
-        }
-
-        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);
-        }
-        RETURN(0);
+        spin_lock(&mgs->mgs_llogs_lock);
+        list_add(&mollog->mol_list, &mgs->mgs_open_llogs);
+        spin_unlock(&mgs->mgs_llogs_lock);
 
+        return 0;
 }
 
-
 int mgs_handle(struct ptlrpc_request *req)
 {
-        int should_process, fail = OBD_FAIL_MGS_ALL_REPLY_NET;
+        int fail = OBD_FAIL_MGS_ALL_REPLY_NET;
         int rc = 0;
         struct mgs_obd *mgs = NULL; /* quell gcc overwarning */
         struct obd_device *obd = NULL;
@@ -765,6 +611,7 @@ static int mgt_cleanup(struct obd_device *obd)
 
 struct lvfs_callback_ops mgs_lvfs_ops = {
         l_fid2dentry:     mgs_lvfs_fid2dentry,
+        l_open_llog:      mgs_lvfs_open_llog,
 };
 
 /* use obd ops to offer management infrastructure */
@@ -787,7 +634,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);
index 5aafc7b..fe69daf 100644 (file)
@@ -5,19 +5,15 @@
 #ifndef _MGS_INTERNAL_H
 #define _MGS_INTERNAL_H
 
+#include <linux/lustre_mgs.h>
+
 #define MGS_SERVICE_WATCHDOG_TIMEOUT (obd_timeout * 1000)
 
+extern struct lvfs_callback_ops mgs_lvfs_ops;
+
 static inline struct mgs_obd *mgs_req2mgs(struct ptlrpc_request *req)
 {
         return &req->rq_export->exp_obd->u.mgs;
 }
 
-struct mgs_open_llogs {
-        struct list_head    mol_list;
-        struct dentry       *mol_dentry;
-        __u64               mod_id;
-};
-
-extern struct lvfs_callback_ops mgs_lvfs_ops;
-
-#endif /* _MGS_INTERNAL_H */
+#endif
diff --git a/lustre/mgs/mgs_llog.c b/lustre/mgs/mgs_llog.c
new file mode 100644 (file)
index 0000000..4c59819
--- /dev/null
@@ -0,0 +1,245 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ *  lustre/mgs/mgs_llog.c
+ *  Lustre Management Server (mgs) llog controller
+ *
+ *  Copyright (C) 2001-2005 Cluster File Systems, Inc.
+ *   Author LinSongTao <lincent@clusterfs.com>
+ *
+ *   This file is part of Lustre, http://www.lustre.org.
+ *
+ *   Lustre is free software; you can redistribute it and/or
+ *   modify it under the terms of version 2 of the GNU General Public
+ *   License as published by the Free Software Foundation.
+ *
+ *   Lustre is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Lustre; if not, write to the Free Software
+ *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef EXPORT_SYMTAB
+# define EXPORT_SYMTAB
+#endif
+#define DEBUG_SUBSYSTEM S_MGS
+
+#ifdef __KERNEL__
+# include <linux/module.h>
+# include <linux/pagemap.h>
+#endif
+
+#include <linux/obd_class.h>
+#include <linux/lustre_mgs.h>
+#include <linux/lustre_fsfilt.h>
+#include "mgs_internal.h"
+
+static int mgs_start_record(struct obd_device *obd, 
+                            struct obd_ioctl_data *data)
+{
+        static struct obd_uuid cfg_uuid = { .uuid = "config_uuid" };
+        struct mgs_obd *mgs = &obd->u.mgs;
+                struct lvfs_run_ctxt saved;
+                struct llog_handle **llog_handle;
+                char *name = data->ioc_inlbuf1;
+                char *fsname = data->ioc_inlbuf2;
+                int rc = 0;
+
+                push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+                rc = llog_create(llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT),
+                                 llog_handle, NULL, fsname, name);
+                if (rc == 0)
+                        llog_init_handle(llog_handle, LLOG_F_IS_PLAIN, 
+                                         &cfg_uuid);
+                pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+
+                RETURN(rc);
+}
+
+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;
+        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;
+                char *fsname = data->ioc_inlbuf2;
+                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, fsname, 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);
+
+                RETURN(rc);
+        }
+
+        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);
+        }
+        RETURN(0);
+}
index 1ebbc30..6f1cbac 100644 (file)
@@ -77,7 +77,7 @@ static struct llog_handle *llog_cat_new_log(struct llog_handle *cathandle)
                 llh->llh_tail.lrt_index = index;
         }
 
-        rc = llog_create(cathandle->lgh_ctxt, &loghandle, NULL, NULL);
+        rc = llog_create(cathandle->lgh_ctxt, &loghandle, NULL, NULL, NULL);
         if (rc)
                 RETURN(ERR_PTR(rc));
 
@@ -149,7 +149,7 @@ int llog_cat_id2handle(struct llog_handle *cathandle, struct llog_handle **res,
                 }
         }
 
-        rc = llog_create(cathandle->lgh_ctxt, &loghandle, logid, NULL);
+        rc = llog_create(cathandle->lgh_ctxt, &loghandle, logid, NULL, NULL);
         if (rc) {
                 CERROR("error opening log id "LPX64":%x: rc %d\n",
                        logid->lgl_oid, logid->lgl_ogen, rc);
index c4ec77d..03adc1a 100644 (file)
@@ -254,12 +254,12 @@ int llog_ioctl(struct llog_ctxt *ctxt, int cmd, struct obd_ioctl_data *data)
                 err = str2logid(&logid, data->ioc_inlbuf1, data->ioc_inllen1);
                 if (err)
                         GOTO(out, err);
-                err = llog_create(ctxt, &handle, &logid, NULL);
+                err = llog_create(ctxt, &handle, &logid, NULL, NULL);
                 if (err)
                         GOTO(out, err);
         } else if (*data->ioc_inlbuf1 == '$') {
                 char *name = data->ioc_inlbuf1 + 1;
-                err = llog_create(ctxt, &handle, NULL, name);
+                err = llog_create(ctxt, &handle, NULL, NULL, name);
                 if (err)
                         GOTO(out, err);
         } else {
index 772e801..d061501 100644 (file)
@@ -432,10 +432,10 @@ static struct file *llog_filp_open(char* fsname, char *name,
         OBD_ALLOC(logname, PATH_MAX);
         if (logname == NULL)
                 return ERR_PTR(-ENOMEM); 
-//FIXME: Need to changing mkfs
-//        if (fsname)
-//              len = snprintf(logname, PATH_MAX, "%s/%s/%s", MOUNT_CONFIGS_DIR, fsname, name);
-//        else
+        if (fsname)
+              len = snprintf(logname, PATH_MAX, "%s/%s/%s",
+                             MOUNT_CONFIGS_DIR, fsname, name);
+        else
               len = snprintf(logname, PATH_MAX, "%s/%s", 
                              MOUNT_CONFIGS_DIR, name);
 
@@ -507,15 +507,22 @@ static int llog_lvfs_create(struct llog_ctxt *ctxt, struct llog_handle **res,
                 handle->lgh_id = *logid;
 
         } else if (name) {
-                handle->lgh_file = llog_filp_open(fsname, name, open_flags, 0644);
+                handle->lgh_file = llog_filp_open(fsname, 
+                                                      name, open_flags, 0644);
+
                 if (IS_ERR(handle->lgh_file))
                         GOTO(cleanup, rc = PTR_ERR(handle->lgh_file));
-
+                rc = obd_lvfs_open_llog(ctxt->loc_exp, 
+                                   handle->lgh_file->f_dentry->d_inode->i_ino,
+                                   handle->lgh_file->f_dentry);
+                if (rc)
+                        GOTO(cleanup, rc);
                 handle->lgh_id.lgl_ogr = 1;
                 handle->lgh_id.lgl_oid =
                         handle->lgh_file->f_dentry->d_inode->i_ino;
                 handle->lgh_id.lgl_ogen =
                         handle->lgh_file->f_dentry->d_inode->i_generation;
+                
         } else {
                 oa = obdo_alloc();
                 if (oa == NULL)
index ca5144c..c328873 100644 (file)
@@ -195,9 +195,9 @@ int llog_obd_origin_setup(struct obd_device *obd, int index,
         llog_gen_init(ctxt);
 
         if (logid->lgl_oid)
-                rc = llog_create(ctxt, &handle, logid, NULL);
+                rc = llog_create(ctxt, &handle, logid, NULL, NULL);
         else {
-                rc = llog_create(ctxt, &handle, NULL, NULL);
+                rc = llog_create(ctxt, &handle, NULL, NULL, NULL);
                 if (!rc)
                         *logid = handle->lgh_id;
         }
index 3ae0a36..22b185a 100644 (file)
@@ -206,6 +206,7 @@ static void print_lustre_cfg(struct lustre_cfg *lcfg)
         if (!(portal_debug & D_OTHER)) /* don't loop on nothing */
                 return;
         CDEBUG(D_OTHER, "lustre_cfg: %p\n", lcfg);
+        CDEBUG(D_OTHER, "\tlcfg->lcfg_magic: %#x\n", lcfg->lcfg_magic);
         CDEBUG(D_OTHER, "\tlcfg->lcfg_version: %#x\n", lcfg->lcfg_version);
 
         CDEBUG(D_OTHER, "\tlcfg->lcfg_command: %#x\n", lcfg->lcfg_command);
@@ -226,15 +227,16 @@ void lustre_swab_lustre_cfg(struct lustre_cfg *lcfg)
         int i;
         ENTRY;
 
-        __swab32s(&lcfg->lcfg_version);
+        __swab32s(&lcfg->lcfg_magic);
 
-        if (lcfg->lcfg_version != LUSTRE_CFG_VERSION) {
-                CERROR("not swabbing lustre_cfg version %#x (expecting %#x)\n",
-                       lcfg->lcfg_version, LUSTRE_CFG_VERSION);
+        if (lcfg->lcfg_magic != LUSTRE_CFG_MAGIC) {
+                CERROR("not swabbing lustre_cfg magic %#x (expecting %#x)\n",
+                       lcfg->lcfg_magic, LUSTRE_CFG_MAGIC);
                 EXIT;
                 return;
         }
 
+        __swab32s(&lcfg->lcfg_version);
         __swab32s(&lcfg->lcfg_command);
 
         __swab32s(&lcfg->lcfg_num);
index 7007632..2160e57 100644 (file)
@@ -89,7 +89,7 @@ static int llog_test_1(struct obd_device *obd, char *name)
         CWARN("1a: create a log with name: %s\n", name);
         LASSERT(ctxt);
 
-        rc = llog_create(ctxt, &llh, NULL, name);
+        rc = llog_create(ctxt, &llh, NULL, NULL, name);
         if (rc) {
                 CERROR("1a: llog_create with name %s failed: %d\n", name, rc);
                 RETURN(rc);
@@ -121,7 +121,7 @@ static int llog_test_2(struct obd_device *obd, char *name,
         ENTRY;
 
         CWARN("2a: re-open a log with name: %s\n", name);
-        rc = llog_create(ctxt, llh, NULL, name);
+        rc = llog_create(ctxt, llh, NULL, NULL, name);
         if (rc) {
                 CERROR("2a: re-open log with name %s failed: %d\n", name, rc);
                 RETURN(rc);
@@ -132,7 +132,7 @@ static int llog_test_2(struct obd_device *obd, char *name,
                 RETURN(rc);
 
         CWARN("2b: create a log without specified NAME & LOGID\n");
-        rc = llog_create(ctxt, &loghandle, NULL, NULL);
+        rc = llog_create(ctxt, &loghandle, NULL, NULL, NULL);
         if (rc) {
                 CERROR("2b: create log failed\n");
                 RETURN(rc);
@@ -142,7 +142,7 @@ static int llog_test_2(struct obd_device *obd, char *name,
         llog_close(loghandle);
 
         CWARN("2b: re-open the log by LOGID\n");
-        rc = llog_create(ctxt, &loghandle, &logid, NULL);
+        rc = llog_create(ctxt, &loghandle, &logid, NULL, NULL);
         if (rc) {
                 CERROR("2b: re-open log by LOGID failed\n");
                 RETURN(rc);
@@ -242,7 +242,7 @@ static int llog_test_4(struct obd_device *obd)
 
         sprintf(name, "%x", llog_test_rand+1);
         CWARN("4a: create a catalog log with name: %s\n", name);
-        rc = llog_create(ctxt, &cath, NULL, name);
+        rc = llog_create(ctxt, &cath, NULL, NULL, name);
         if (rc) {
                 CERROR("1a: llog_create with name %s failed: %d\n", name, rc);
                 GOTO(out, rc);
@@ -379,7 +379,7 @@ static int llog_test_5(struct obd_device *obd)
         lmr.lmr_hdr.lrh_type = 0xf00f00;
 
         CWARN("5a: re-open catalog by id\n");
-        rc = llog_create(ctxt, &llh, &cat_logid, NULL);
+        rc = llog_create(ctxt, &llh, &cat_logid, NULL, NULL);
         if (rc) {
                 CERROR("5a: llog_create with logid failed: %d\n", rc);
                 GOTO(out, rc);
@@ -460,7 +460,7 @@ static int llog_test_6(struct obd_device *obd, char *name)
         exp = class_conn2export(&exph);
 
         nctxt = llog_get_context(mdc_obd, LLOG_CONFIG_REPL_CTXT);
-        rc = llog_create(nctxt, &llh, NULL, name);
+        rc = llog_create(nctxt, &llh, NULL, NULL, name);
         if (rc) {
                 CERROR("6: llog_create failed %d\n", rc);
                 RETURN(rc);
@@ -500,7 +500,7 @@ static int llog_test_7(struct obd_device *obd)
         CWARN("7: create a log with name: %s\n", name);
         LASSERT(ctxt);
 
-        rc = llog_create(ctxt, &llh, NULL, name);
+        rc = llog_create(ctxt, &llh, NULL, NULL, name);
         if (rc) {
                 CERROR("7: llog_create with name %s failed: %d\n", name, rc);
                 RETURN(rc);
index 93ca5c6..1345bbb 100644 (file)
@@ -682,7 +682,7 @@ static int class_config_llog_handler(struct llog_handle * handle,
                 int inst = 0;
 
                 lcfg = (struct lustre_cfg *)cfg_buf;
-                if (lcfg->lcfg_version == __swab32(LUSTRE_CFG_VERSION))
+                if (lcfg->lcfg_magic == __swab32(LUSTRE_CFG_MAGIC))
                         lustre_swab_lustre_cfg(lcfg);
 
                 rc = lustre_cfg_sanity_check(cfg_buf, cfg_len);
@@ -758,7 +758,7 @@ int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
         ENTRY;
 
         CDEBUG(D_INFO, "looking up llog %s\n", name);
-        rc = llog_create(ctxt, &llh, NULL, name);
+        rc = llog_create(ctxt, &llh, NULL, NULL, name);
         if (rc)
                 RETURN(rc);
 
@@ -826,7 +826,7 @@ int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
         int rc, rc2;
         ENTRY;
 
-        rc = llog_create(ctxt, &llh, NULL, name);
+        rc = llog_create(ctxt, &llh, NULL, NULL, name);
         if (rc)
                 RETURN(rc);
 
index 6162123..7f6641f 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/lvfs.h>
 #include <linux/lustre_disk.h>
 #include <linux/lustre_fsfilt.h>
+#include <linux/lustre_mgs.h>
 #include <linux/obd_class.h>
 #include <lustre/lustre_user.h>
 #include <linux/version.h> 
@@ -420,8 +421,7 @@ out:
 /* Process all local logs.
 FIXME clients and servers should use the same fn. No need to have MDS 
 do client and confobd do servers. MGC should do both. */
-int lustre_process_logs(struct super_block *sb,
-                        struct config_llog_instance *cfg, int allow_recov)
+int lustre_process_logs(struct super_block *sb, int allow_recov)
 {
         struct obd_ioctl_data ioc_data = { 0 };
         struct list_head dentry_list;
@@ -459,7 +459,7 @@ int lustre_process_logs(struct super_block *sb,
                         continue;
                 }
                 logname[len] = 0;
-                                                                                       
+                                        
                 CERROR("starting log %s\n", logname);
                 ioc_data.ioc_inllen1 = len + 1;
                 ioc_data.ioc_inlbuf1 = logname;
@@ -518,38 +518,119 @@ static int do_lcfg(char *cfgname, ptl_nid_t nid, int cmd,
         return(err);
 }
 
+/* Set up a mgsobd to process startup logs */
+static int lustre_start_mgs(struct super_block *sb, struct vfsmount *mnt)
+{
+        struct config_llog_instance cfg;
+        char*  mgsname;
+        int    mgsname_size, err = 0;
+
+        mgsname_size = 2 * sizeof(sb) + 5;
+        OBD_ALLOC(mgsname, mgsname_size);
+        if (!mgsname)
+                GOTO(out, err = -ENOMEM);
+        sprintf(mgsname, "MGS_%p", sb);
+
+        err = lustre_register_mount(mgsname, sb, mnt);
+        if (err)
+               GOTO(out_free, err);
+
+        cfg.cfg_instance = mgsname;
+        snprintf(cfg.cfg_uuid.uuid, sizeof(cfg.cfg_uuid.uuid), mgsname);
+        err = do_lcfg(mgsname, 0, LCFG_ATTACH, LUSTRE_MGS_NAME, cfg.cfg_uuid.uuid, 0, 0);
+        if (err)
+                GOTO(out_dereg, err);
+                                                                                       
+        err = do_lcfg(mgsname, 0, LCFG_SETUP, 0, 0, 0, 0);
+        if (err) {
+                CERROR("mgsobd setup error %d\n", err);
+                do_lcfg(mgsname, 0, LCFG_DETACH, 0, 0, 0, 0);
+                GOTO(out_dereg, err);
+        }
+
+out_free:
+        OBD_FREE(mgsname, mgsname_size);
+out:
+        return err;
+out_dereg:
+        lustre_deregister_mount(mgsname);
+        goto out_free;
+}
+
+static void lustre_stop_mgs(struct super_block *sb)
+{
+        struct obd_device *obd;
+        char mgsname[2 * sizeof(sb) + 5];
+
+        sprintf(mgsname, "MGS_%p", sb);
+        obd = class_name2obd(mgsname);
+        if (!obd) {
+                CERROR("Can not get mgs obd!\n");
+                goto out;
+        }
+        class_manual_cleanup(obd, NULL);
+out:
+        return;
+}
+
 /* Set up a mgcobd to process startup logs */
-static int lustre_start_mgc(char *mgcname, struct super_block *sb)
+static int lustre_start_mgc(struct super_block *sb, struct vfsmount *mnt)
 {
         struct config_llog_instance cfg;
         struct lustre_sb_info *sbi = s2sbi(sb);
         struct obd_device *obd;
-        int err = 0;
+        char*  mgcname;
+        int    mgcname_size, err = 0;
+
+        mgcname_size = 2 * sizeof(sb) + 5;
+        OBD_ALLOC(mgcname, mgcname_size);
+        if (!mgcname)
+                GOTO(out, err = -ENOMEM);
+        sprintf(mgcname, "MGC_%p", sb);
+
+        /* register a mount for the mgc so it can call mgc_fs_setup() */
+        if (mnt != NULL) {
+                err = lustre_register_mount(mgcname, sb, mnt);
+                if (err) 
+                        GOTO(out_free, err);
+        }
 
         cfg.cfg_instance = mgcname;
         snprintf(cfg.cfg_uuid.uuid, sizeof(cfg.cfg_uuid.uuid), mgcname);
  
         err = do_lcfg(mgcname, 0, LCFG_ATTACH, LUSTRE_MGC_NAME, cfg.cfg_uuid.uuid, 0, 0);
         if (err)
-                goto out_free;
+                GOTO(out_dereg, err);
                                                                                        
         err = do_lcfg(mgcname, 0, LCFG_SETUP, 0, 0, 0, 0);
         if (err) {
                 CERROR("mgcobd setup error %d\n", err);
                 do_lcfg(mgcname, 0, LCFG_DETACH, 0, 0, 0, 0);
-                goto out_free;
+                GOTO(out_dereg, err);
+        }
+
+        if (sbi->lsi_ldd->ldd_flags & LDD_F_NEED_INDEX) {
+                // FIXME implement
+                CERROR("Need new server index from MGS!\n");
+                // rewrite last_rcvd, ldd (for new svname)
         }
 
         obd = class_name2obd(mgcname);
         if (!obd) {
                 CERROR("Can't find mgcobd %s\n", mgcname);
-                err = -ENOTCONN;
-                goto out_free;
+                GOTO(out_dereg, err = -ENOTCONN);
         }
         sbi->lsi_mgc = obd;
 
 out_free:
+        OBD_FREE(mgcname, mgcname_size);
+out:
         return err;
+out_dereg:
+        lustre_deregister_mount(mgcname);
+        goto out_free;
 }
 
 static void lustre_stop_mgc(struct super_block *sb)
@@ -626,7 +707,6 @@ static struct vfsmount *lustre_kern_mount(struct super_block *sb)
         mount_ctxt.pwdmnt = mnt;
         mount_ctxt.pwd = mnt->mnt_root;
         mount_ctxt.fs = get_ds();
-        //mount_ctxt.cb_ops = mds_lvfs_ops;
 
         err = parse_mount_data(&mount_ctxt, ldd); 
         unlock_mntput(mnt);
@@ -814,21 +894,11 @@ static int server_fill_super_common(struct super_block *sb)
      
 static int server_fill_super(struct super_block *sb)
 {
-        struct config_llog_instance cfg;
         struct lustre_sb_info *sbi = s2sbi(sb);
         struct vfsmount *mnt;
-        char *mgcname;
-        int mgcname_sz = sizeof(sb) * 2 + 5;
-        int err;
+        int mgs_service = 0, err;
         ENTRY;
 
-        /* Generate a string unique to this super, let's try
-           the address of the super itself.*/
-        OBD_ALLOC(mgcname, mgcname_sz);
-        if (!mgcname)
-                GOTO(out, err = -ENOMEM);
-        sprintf(mgcname, "MGC_%p", sb);
-
         /* mount to read server info */
         mnt = lustre_kern_mount(sb);
         if (IS_ERR(mnt)) {
@@ -840,40 +910,31 @@ static int server_fill_super(struct super_block *sb)
         CERROR("Found service %s for fs %s on device %s\n",
                sbi->lsi_ldd->ldd_svname, sbi->lsi_ldd->ldd_fsname, 
                sbi->lsi_lmd->lmd_dev);
-        
-        /* register a mount for the mgc so it can call mgc_fs_setup() */
-        err = lustre_register_mount(mgcname, sb, mnt);
+
+        err = lustre_register_mount(sbi->lsi_ldd->ldd_svname, sb, mnt);
         if (err) 
                 GOTO(out, err);
 
-        err = lustre_start_mgc(mgcname, sb);
-        //part of mgc_startup err = mgc_fs_setup(sb, mnt);
+        if (sbi->lsi_ldd->ldd_flags & LDD_F_SV_TYPE_MGMT) {
+                CERROR("Found MGS service for fs %s on device %s\n",
+                       sbi->lsi_ldd->ldd_fsname, sbi->lsi_lmd->lmd_dev);
+                mgs_service++;
+                err = lustre_start_mgs(sb, mnt);
+                if (err) 
+                       GOTO(out_dereg, err);
+        }
+
+        err = lustre_start_mgc(sb, mnt);
         if (err) 
                 GOTO(out_dereg, err);
         
-        /* we also need to register a mount for the real server */
-        err = lustre_register_mount(sbi->lsi_ldd->ldd_svname, sb, mnt);
-        if (err) 
-                GOTO(out_dereg, err);
-
-
-        if (sbi->lsi_ldd->ldd_flags & LDD_F_NEED_INDEX) {
-                // FIXME implement
-                CERROR("Need new server index from MGS!\n");
-                // rewrite last_rcvd, ldd (for new svname)
-        }
-        // FIXME register with MGS
         /* Set up all obd devices for service */
-        cfg.cfg_instance = mgcname;
-        snprintf(cfg.cfg_uuid.uuid, sizeof(cfg.cfg_uuid.uuid), mgcname);
-        err = lustre_process_logs(sb, &cfg, 0);
+        err = lustre_process_logs(sb, 0);
         if (err < 0) {
                 CERROR("Unable to process log: %d\n", err);
                 GOTO(out_dereg, err);
         }
         
-        /* Finally, put something at the mount point. */
         CERROR("Mounting server\n");
         err = server_fill_super_common(sb);
         if (err) 
@@ -884,14 +945,13 @@ static int server_fill_super(struct super_block *sb)
            have to fix up the s_ops after! */
 out:
         //FIXME mntput
-        if (mgcname)
-                OBD_FREE(mgcname, mgcname_sz);
         if (sbi->lsi_ldd)
                 // FIXME ??
                 class_del_profile(sbi->lsi_ldd->ldd_svname);
         RETURN(err);
 out_dereg:
-        lustre_deregister_mount(mgcname);
+        if (mgs_service)
+                lustre_stop_mgs(sb);
         lustre_deregister_mount(sbi->lsi_ldd->ldd_svname);
         goto out;     
 }
@@ -932,7 +992,6 @@ int lustre_fill_super(struct super_block *sb, void *data, int silent)
         }
         memcpy(sbi->lsi_lmd, lmd, sizeof(*lmd));
         
-
         if (lmd_is_client(lmd)) {
                 if (!client_fill_super) {
                         CERROR("Nothing registered for client_fill_super!\n"
@@ -943,7 +1002,7 @@ int lustre_fill_super(struct super_block *sb, void *data, int silent)
                         snprintf(mgcname, sizeof(mgcname), "mgc-client-%s", 
                                  lmd->lmd_dev);
                         CERROR("Mounting client\n");
-                        err = lustre_start_mgc(mgcname, sb);
+                        err = lustre_start_mgc(sb, NULL);
                         if (err) {
                                 lustre_free_sbi(sb);
                                 RETURN(err);
index 5c7af41..949fdf2 100644 (file)
@@ -83,7 +83,7 @@ int llog_origin_handle_create(struct ptlrpc_request *req)
         disk_obd = ctxt->loc_exp->exp_obd;
         push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
 
-        rc = llog_create(ctxt, &loghandle, logid, name);
+        rc = llog_create(ctxt, &loghandle, logid, NULL, name);
         if (rc)
                 GOTO(out_pop, rc);
 
@@ -138,7 +138,7 @@ int llog_origin_handle_next_block(struct ptlrpc_request *req)
         disk_obd = ctxt->loc_exp->exp_obd;
         push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
 
-        rc = llog_create(ctxt, &loghandle, &body->lgd_logid, NULL);
+        rc = llog_create(ctxt, &loghandle, &body->lgd_logid, NULL, NULL);
         if (rc)
                 GOTO(out_pop, rc);
 
@@ -205,7 +205,7 @@ int llog_origin_handle_read_header(struct ptlrpc_request *req)
         disk_obd = ctxt->loc_exp->exp_obd;
         push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
 
-        rc = llog_create(ctxt, &loghandle, &body->lgd_logid, NULL);
+        rc = llog_create(ctxt, &loghandle, &body->lgd_logid, NULL, NULL);
         if (rc)
                 GOTO(out_pop, rc);
 
@@ -327,7 +327,7 @@ static int llog_catinfo_config(struct obd_device *obd, char *buf, int buf_len,
 
         for (i = 0; i < 4; i++) {
                 int index, uncanceled = 0;
-                rc = llog_create(ctxt, &handle, NULL, name[i]);
+                rc = llog_create(ctxt, &handle, NULL, NULL, name[i]);
                 if (rc)
                         GOTO(out_pop, rc);
                 rc = llog_init_handle(handle, 0, NULL);
@@ -389,7 +389,7 @@ static int llog_catinfo_cb(struct llog_handle *cat,
 
         lir = (struct llog_logid_rec *)rec;
         logid = &lir->lid_id;
-        rc = llog_create(ctxt, &handle, logid, NULL);
+        rc = llog_create(ctxt, &handle, logid, NULL, NULL);
         if (rc)
                 RETURN(-EINVAL);
         rc = llog_init_handle(handle, 0, NULL);
@@ -458,7 +458,7 @@ static int llog_catinfo_deletions(struct obd_device *obd, char *buf,
                 int l, index, uncanceled = 0;
 
                 id = &idarray[i].lci_logid;
-                rc = llog_create(ctxt, &handle, id, NULL);
+                rc = llog_create(ctxt, &handle, id, NULL, NULL);
                 if (rc)
                         GOTO(out_pop, rc);
                 rc = llog_init_handle(handle, 0, NULL);
index 3a78b18..241625b 100644 (file)
@@ -525,7 +525,7 @@ static int log_process_thread(void *args)
         SIGNAL_MASK_UNLOCK(current, flags);
         unlock_kernel();
 
-        rc = llog_create(ctxt, &llh, &logid, NULL);
+        rc = llog_create(ctxt, &llh, &logid, NULL, NULL);
         if (rc) {
                 CERROR("llog_create failed %d\n", rc);
                 RETURN(rc);