Whamcloud - gitweb
add layers setup and initialization.
authortappro <tappro>
Sat, 8 Apr 2006 08:17:25 +0000 (08:17 +0000)
committertappro <tappro>
Sat, 8 Apr 2006 08:17:25 +0000 (08:17 +0000)
lustre/cmm/cmm_device.c
lustre/mdd/mdd_handler.c
lustre/mdd/mdd_internal.h
lustre/mdt/mdt_handler.c
lustre/mgs/mgs_llog.c

index d9743c7..b401545 100644 (file)
@@ -231,12 +231,24 @@ static int cmm_init(struct cmm_device *m,
                     struct lu_device_type *t, struct lustre_cfg *cfg)
 {
         struct lu_device *lu_dev = cmm2lu_dev(m);
+        struct obd_device * obd = NULL;
+        char * child = lustre_cfg_string(cfg, 1);
+
         ENTRY;
 
        md_device_init(&m->cmm_md_dev, t);
         
         m->cmm_md_dev.md_ops = &cmm_md_ops;
        lu_dev->ld_ops = &cmm_lu_ops;
+        
+        /* get next layer */
+        obd = class_name2obd(child);
+        if (obd && obd->obd_lu_dev) {
+                CDEBUG(D_INFO, "Child device is %s\n", child);
+                m->cmm_child = lu2md_dev(obd->obd_lu_dev);
+        } else {
+                CDEBUG(D_INFO, "Child device %s not found\n", child);
+        }
 
        return 0;
 }
@@ -246,42 +258,23 @@ struct lu_device *cmm_device_alloc(struct lu_device_type *t,
 {
         struct lu_device  *l;
         struct cmm_device *m;
+        struct obd_device * obd = NULL;
+        char * child = lustre_cfg_string(cfg, 1);
+
         int err;
         
         ENTRY;
         
         OBD_ALLOC_PTR(m);
         if (m == NULL) {
-                return ERR_PTR(-ENOMEM);
-        } 
-        
-        err = cmm_init(m, t, cfg);
-        if (err) {
-                return ERR_PTR(err);
-        }
-
-        for (err = 0; err < cfg->lcfg_bufcount; err++) {
-                char * name = lustre_cfg_string(cfg, err);
-                if (name) {
-                        name = "NULL"; 
-                }
-                CDEBUG(D_INFO, "lcfg#%i: %s\n", err, name);
-                
-        }
-        /* get next layer from mountopt */
-        if (LUSTRE_CFG_BUFLEN(cfg, 2)) {
-                struct obd_device * obd = NULL;
-                char * child = lustre_cfg_string(cfg, 2);
-                
-                obd = class_name2obd(child);
-                if (obd && obd->obd_lu_dev) {
-                        CDEBUG(D_INFO, "Child device is %s\n", child);
-                        m->cmm_child = lu2md_dev(obd->obd_lu_dev);
-                } else {
-                        CDEBUG(D_INFO, "Child device %s not found\n", child);
-                }
+                l = ERR_PTR(-ENOMEM);
+        } else {
+                err = cmm_init(m, t, cfg);
+                if (err)
+                        l = ERR_PTR(err);
+                else
+                        l = cmm2lu_dev(m);
         }
-        l = cmm2lu_dev(m);
 
         EXIT;
         return l;
index d7de9bb..5186cb2 100644 (file)
@@ -245,7 +245,7 @@ static void mdd_object_release(struct lu_object *o)
 
 static int mdd_object_print(struct seq_file *f, const struct lu_object *o)
 {
-        return seq_printf(f, LUSTRE_MDD_NAME"-object@%p", o);
+        return seq_printf(f, LUSTRE_MDD0_NAME"-object@%p", o);
 }
 
 static struct lu_device_operations mdd_lu_ops = {
@@ -600,12 +600,26 @@ static int mdd_init(struct mdd_device *mdd, struct lu_device_type *t,
                     struct lustre_cfg* lcfg)
 {
         struct lu_device *lu_dev = mdd2lu_dev(mdd);
+        struct obd_device * obd = NULL;
+        char *child = lustre_cfg_string(lcfg, 1);
+        char *lov = lustre_cfg_string(lcfg, 2);
         int rc = 0;
         ENTRY;
 
        md_device_init(&mdd->mdd_md_dev, t);
 
        lu_dev->ld_ops = &mdd_lu_ops;
+        mdd->mdd_md_dev.md_ops = &mdd_ops;
+        
+        /* get next layer */
+        obd = class_name2obd(child);
+        if (obd && obd->obd_lu_dev) {
+                CDEBUG(D_INFO, "Child device is %s\n", child);
+                mdd->mdd_child = container_of(obd->obd_lu_dev,
+                                              struct dt_device, dd_lu_dev);
+        } else {
+                CDEBUG(D_INFO, "Child device %s not found\n", child);
+        }
 
         rc = mdd_fs_setup(mdd);
         if (rc)
@@ -678,7 +692,7 @@ static struct lu_device_type_operations mdd_device_type_ops = {
 
 static struct lu_device_type mdd_device_type = {
         .ldt_tags = LU_DEVICE_MD,
-        .ldt_name = LUSTRE_MDD_NAME,
+        .ldt_name = LUSTRE_MDD0_NAME,
         .ldt_ops  = &mdd_device_type_ops
 };
 
@@ -700,25 +714,25 @@ static int __init mdd_mod_init(void)
 
         lprocfs_init_vars(mdd, &lvars);
         result = class_register_type(&mdd_obd_device_ops,
-                                     lvars.module_vars, LUSTRE_MDD_NAME);
+                                     lvars.module_vars, LUSTRE_MDD0_NAME);
         if (result == 0) {
-                type = class_get_type(LUSTRE_MDD_NAME);
+                type = class_get_type(LUSTRE_MDD0_NAME);
                 LASSERT(type != NULL);
                 type->typ_lu = &mdd_device_type;
                 result = type->typ_lu->ldt_ops->ldto_init(type->typ_lu);
                 if (result != 0)
-                        class_unregister_type(LUSTRE_MDD_NAME);
+                        class_unregister_type(LUSTRE_MDD0_NAME);
         }
         return result;
 }
 
 static void __exit mdd_mod_exit(void)
 {
-        class_unregister_type(LUSTRE_MDD_NAME);
+        class_unregister_type(LUSTRE_MDD0_NAME);
 }
 
 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
-MODULE_DESCRIPTION("Lustre Meta-data Device Prototype ("LUSTRE_MDD_NAME")");
+MODULE_DESCRIPTION("Lustre Meta-data Device Prototype ("LUSTRE_MDD0_NAME")");
 MODULE_LICENSE("GPL");
 
 cfs_module(mdd, "0.0.2", mdd_mod_init, mdd_mod_exit);
index de3d2fa..236bd1e 100644 (file)
@@ -4,9 +4,6 @@
 #ifndef _MDD_INTERNAL_H
 #define _MDD_INTERNAL_H
 
-#define LUSTRE_MDD_NAME "mdd"
-#define LUSTRE_OSD_NAME "osd"
-
 struct mdd_device {
         struct md_device                 mdd_md_dev;
         struct dt_device                *mdd_child;
index f6d5a9f..dcf6fe3 100644 (file)
@@ -854,6 +854,8 @@ static int mdt_init0(struct mdt_device *m,
 {
         struct lu_site *s;
         char   ns_name[48];
+        struct obd_device * obd = NULL;
+        char *child = lustre_cfg_string(cfg, 1);
 
         ENTRY;
 
@@ -865,6 +867,15 @@ static int mdt_init0(struct mdt_device *m,
 
         m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
 
+        /* get next layer */
+        obd = class_name2obd(child);
+        if (obd && obd->obd_lu_dev) {
+                CDEBUG(D_INFO, "Child device is %s\n", child);
+                m->mdt_child = lu2md_dev(obd->obd_lu_dev);
+        } else {
+                CDEBUG(D_INFO, "Child device %s is not found\n", child);
+        }
+
         m->mdt_service_conf.psc_nbufs            = MDS_NBUFS;
         m->mdt_service_conf.psc_bufsize          = MDS_BUFSIZE;
         m->mdt_service_conf.psc_max_req_size     = MDS_MAXREQSIZE;
@@ -1011,8 +1022,6 @@ static struct lu_device *mdt_device_alloc(struct lu_device_type *t,
         OBD_ALLOC_PTR(m);
         if (m != NULL) {
                 int result;
-                struct obd_device * obd = NULL;
-                char *child = "lustre-mdtcmm";
 
                 l = &m->mdt_md_dev.md_lu_dev;
                 result = mdt_init0(m, t, cfg);
@@ -1020,16 +1029,7 @@ static struct lu_device *mdt_device_alloc(struct lu_device_type *t,
                         mdt_fini(m);
                         return ERR_PTR(result);
                 }
-
-                /* get next layer */
-                obd = class_name2obd(child);
-                if (obd && obd->obd_lu_dev) {
-                       CDEBUG(D_INFO, "Child device is %s\n", child);
-                       m->mdt_child = lu2md_dev(obd->obd_lu_dev);
-                } else {
-                       CDEBUG(D_INFO, "Child device %s is not found\n", child);
                 
-                }
         } else
                 l = ERR_PTR(-ENOMEM);
         return l;
index 577925d..aa8d5af 100644 (file)
@@ -566,6 +566,25 @@ static int record_lov_setup(struct obd_device *obd, struct llog_handle *llh,
         return rc;
 }
 
+static int record_cmm0_setup(struct obd_device *obd, struct llog_handle *llh,
+                             char *devname, char *child, struct cmm_desc *desc)
+{
+        struct lustre_cfg_bufs bufs;
+        struct lustre_cfg *lcfg;
+        int rc;
+
+        lustre_cfg_bufs_reset(&bufs, devname);
+        /* put child device info */
+        lustre_cfg_bufs_set_string(&bufs, 1, child);
+        /* put private layer data */
+        lustre_cfg_bufs_set(&bufs, 2, desc, sizeof(*desc));
+        lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
+
+        rc = record_lcfg(obd, llh, lcfg);
+
+        lustre_cfg_free(lcfg);
+        return rc;
+}
 static int record_cmm_setup(struct obd_device *obd, struct llog_handle *llh,
                             char *devname, struct cmm_desc *desc)
 {
@@ -1020,8 +1039,6 @@ out_pop:
 
 
 /***************************************BEGIN PROTO**********************/
-/* cmm is the second thing for MDT logs */
-/* copied from mgs_write_log_lov. Please refer to that.  */
 static int mgs_write_log_cmm(struct obd_device *obd, struct fs_db *fsdb, 
                              struct mgs_target_info *mti,
                              char *logname, char *cmmname)
@@ -1032,7 +1049,7 @@ static int mgs_write_log_cmm(struct obd_device *obd, struct fs_db *fsdb,
         int rc = 0;
         ENTRY;
 
-        CDEBUG(D_MGS, "Writing cmm(%s) log for %s\n", cmmname, logname);
+        CDEBUG(D_MGS, "Writing cmm(%s) log for %s\n", cmmname,logname);
 
         OBD_ALLOC(cmmdesc, sizeof(*cmmdesc));
         if (cmmdesc == NULL)
@@ -1044,7 +1061,7 @@ static int mgs_write_log_cmm(struct obd_device *obd, struct fs_db *fsdb,
 
         rc = record_start_log(obd, &llh, logname);
         rc = record_marker(obd, llh, fsdb, CM_START, cmmname, "cmm setup"); 
-        rc = record_attach(obd, llh, cmmname, LUSTRE_CMM0_NAME, uuid);
+        rc = record_attach(obd, llh, cmmname, "cmm", uuid);
         rc = record_cmm_setup(obd, llh, cmmname, cmmdesc);
         rc = record_marker(obd, llh, fsdb, CM_END, cmmname, "cmm setup"); 
         rc = record_end_log(obd, &llh);
@@ -1052,11 +1069,6 @@ static int mgs_write_log_cmm(struct obd_device *obd, struct fs_db *fsdb,
         OBD_FREE(cmmdesc, sizeof(*cmmdesc));
         RETURN(rc);
 }
-/***************************************END PROTO**********************/
-
-
-
-/***************************************BEGIN PROTO**********************/
 /* 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, 
@@ -1391,43 +1403,160 @@ static int mgs_write_log_mdt(struct obd_device *obd, struct fs_db *fsdb,
         name_destroy(cmmname);
         RETURN(rc);
 }
+/************************** setup mds layers ******************************/
+static int mgs_write_log_cmm0(struct obd_device *obd, struct fs_db *fsdb, 
+                             char *log, char *dev, char *child)
+{
+        struct llog_handle *llh = NULL;
+        struct cmm_desc *desc;
+        char *uuid;
+        int rc = 0;
+        ENTRY;
+
+        CDEBUG(D_MGS, "Writing cmm(%s) log for %s\n", dev, log);
+
+        OBD_ALLOC(desc, sizeof(*desc));
+        if (desc == NULL)
+                RETURN(-ENOMEM);
+        
+        desc->ld_active_tgt_count = 0;
+        desc->ld_tgt_count = 0;
+        sprintf((char *)desc->ld_uuid.uuid, "%s_UUID", dev);
+        uuid = (char *)desc->ld_uuid.uuid;
+
+        rc = record_start_log(obd, &llh, log);
+        rc = record_marker(obd, llh, fsdb, CM_START, dev, "cmm setup"); 
+        rc = record_attach(obd, llh, dev, LUSTRE_CMM0_NAME, uuid);
+        rc = record_cmm0_setup(obd, llh, dev, child, desc);
+        rc = record_marker(obd, llh, fsdb, CM_END, dev, "cmm setup"); 
+        rc = record_end_log(obd, &llh);
+        
+        OBD_FREE(desc, sizeof(*desc));
+        RETURN(rc);
+}
+
+static int mgs_write_log_mdd(struct obd_device *obd, struct fs_db *fsdb, 
+                             char *log, char *dev, char *child, char *lov)
+{
+        struct llog_handle *llh = NULL;
+        char *uuid;
+        int rc = 0;
+        ENTRY;
+
+        CDEBUG(D_MGS, "Writing mdd(%s) log for %s\n", dev, log);
+
+        OBD_ALLOC(uuid, sizeof (struct obd_uuid));
+        if (uuid == NULL)
+                RETURN(-ENOMEM);
+    
+        sprintf((char *)uuid, "%s_UUID", dev);
+
+        rc = record_start_log(obd, &llh, log);
+        rc = record_marker(obd, llh, fsdb, CM_START, log, "mdd setup"); 
+        rc = record_attach(obd, llh, dev, LUSTRE_MDD0_NAME, uuid);
+        rc = record_setup(obd, llh, dev, child, lov, uuid, 0);
+        rc = record_marker(obd, llh, fsdb, CM_END, log, "mdd setup"); 
+        rc = record_end_log(obd, &llh);
+        
+        OBD_FREE(uuid, sizeof(*uuid));
+        RETURN(rc);
+}
+
+static int mgs_write_log_osd(struct obd_device *obd, struct fs_db *fsdb, 
+                             char *log, char *dev)
+{
+        struct llog_handle *llh = NULL;
+        char *uuid;
+        int rc = 0;
+        ENTRY;
+
+        CDEBUG(D_MGS, "Writing osd(%s) log for %s\n", dev, log);
+
+        OBD_ALLOC(uuid, sizeof(struct obd_uuid));
+        if (uuid == NULL)
+                RETURN(-ENOMEM);
+        
+        sprintf((char *)uuid, "%s_UUID", dev);
+
+        rc = record_start_log(obd, &llh, log);
+        rc = record_marker(obd, llh, fsdb, CM_START, log, "osd setup"); 
+        rc = record_attach(obd, llh, dev, LUSTRE_OSD0_NAME, uuid);
+        rc = record_setup(obd, llh, dev, uuid, 0, 0, 0);
+        rc = record_marker(obd, llh, fsdb, CM_END, log, "osd setup"); 
+        rc = record_end_log(obd, &llh);
+        
+        OBD_FREE(uuid, sizeof(*uuid));
+        RETURN(rc);
+}
 
 static int mgs_write_log_mdt0(struct obd_device *obd, struct fs_db *fsdb,
+                              char *log, char *dev, char *child)
+{
+        struct llog_handle *llh = NULL;
+        char *uuid;
+        int rc = 0;
+        ENTRY;
+
+        CDEBUG(D_MGS, "writing new mdt %s for %s\n", dev, log);
+
+        OBD_ALLOC(uuid, sizeof(struct obd_uuid));
+        if (uuid == NULL)
+                RETURN(-ENOMEM);
+        
+        sprintf((char *)uuid, "%s_UUID", dev);
+        /* add MDT itself */
+        rc = record_start_log(obd, &llh, log);
+        rc = record_marker(obd, llh, fsdb, CM_START, log, "add mdt"); 
+        rc = record_attach(obd, llh, log, LUSTRE_MDT0_NAME, uuid);
+        rc = record_setup(obd, llh, log, child, uuid, 0, 0);
+        rc = record_marker(obd, llh, fsdb, CM_END, log, "add mdt"); 
+        rc = record_end_log(obd, &llh);
+        
+        OBD_FREE(uuid, sizeof(*uuid));
+        RETURN(rc);
+}
+
+/* envelope method for all layers log */
+static int mgs_write_log_mds(struct obd_device *obd, struct fs_db *fsdb,
                               struct mgs_target_info *mti)
 {
         struct llog_handle *llh = NULL;
-        char *cliname, *tmpname, *cmmname, *lmvname;
+        char *cliname, *osdname, *lovname, *mddname;
+        char *mdtname, *cmmname, *lmvname;
         int rc, i, first_log = 0;
         char mdt_index[9];
         struct temp_comp comp;
         ENTRY;
 
-        CDEBUG(D_MGS, "writing new mdt %s\n", mti->mti_svname);
+        CDEBUG(D_MGS, "writing new mds %s\n", mti->mti_svname);
 
         /* Make up our own uuid */
         snprintf(mti->mti_uuid, sizeof(mti->mti_uuid), "%s_UUID", mti->mti_svname);
         
-        name_create(mti->mti_fsname, "-mdtcmm", &cmmname);
+        name_create(mti->mti_fsname, "-mdscmm", &cmmname);
+        name_create(mti->mti_fsname, "-mdsmdd", &mddname);
+        name_create(mti->mti_fsname, "-mdsosd", &osdname);
+        name_create(mti->mti_fsname, "-mdsmdt", &mdtname);
+        name_create(mti->mti_fsname, "-mdslov", &lovname);
+
+        /* add osd */
+        rc = mgs_write_log_osd(obd, fsdb, mti->mti_svname, osdname);
+        /* add lov */
+        rc = mgs_write_log_lov(obd, fsdb, mti, mti->mti_svname, lovname);
+        /* add mdd */
+        rc = mgs_write_log_mdd(obd, fsdb, mti->mti_svname, mddname,
+                               osdname, lovname);
+        /* add cmm */
+        rc = mgs_write_log_cmm0(obd, fsdb, mti->mti_svname, cmmname,
+                               mddname);
+        /* add mdt */
+        rc = mgs_write_log_mdt0(obd, fsdb, mti->mti_svname, mdtname,
+                                cmmname);
+        name_destroy(lovname);
+        name_destroy(osdname);
+        name_destroy(mddname);
+        name_destroy(mdtname);
 
-        /* Append layers info to mds log */
-        if (mgs_log_is_empty(obd, mti->mti_svname)) {
-                first_log++;
-#if 0
-                /* add osd */
-                name_create(mti->mti_fsname, "-mdtosd", &tmpname);
-                rc = mgs_write_log_osd(obd, fsdb, mti, mti->mti_svname,
-                                       tmpname);
-                name_destroy(tmpname);
-                /* add mdd */
-                name_create(mti->mti_fsname, "-mdtmdd", &tmpname);
-                rc = mgs_write_log_mdd(obd, fsdb, mti, mti->mti_svname, 
-                                       tmpname);
-                name_destroy(tmpname);
-#endif
-                /* add CMM */
-                rc = mgs_write_log_cmm(obd, fsdb, mti, mti->mti_svname,
-                                       cmmname);
-        } 
         /* copy client info about lov/lmv */
         name_create(mti->mti_fsname, "-client", &cliname);
         comp.comp_obd = obd;
@@ -1435,26 +1564,13 @@ static int mgs_write_log_mdt0(struct obd_device *obd, struct fs_db *fsdb,
         comp.comp_fsdb = fsdb;
         rc = mgs_steal_llog_for_mdt_from_client(obd,cliname,&comp);
 
-        /* add MDT itself */
-        rc = record_start_log(obd, &llh, mti->mti_svname);
-        rc = record_marker(obd, llh, fsdb, CM_START, mti->mti_svname,"add mdt"); 
-        /* mark that CMM is child for MDT */
-        rc = record_mount_opt(obd, llh, mti->mti_svname, cmmname, 0);
-        rc = record_attach(obd, llh, mti->mti_svname, LUSTRE_MDT0_NAME, 
-                           mti->mti_uuid);
-        rc = record_setup(obd, llh, mti->mti_svname,
-                          "dev"/*ignored*/, "type"/*ignored*/,
-                          mti->mti_svname, 0/*options*/);
-        rc = record_marker(obd, llh, fsdb, CM_END, mti->mti_svname, "add mdt"); 
-        rc = record_end_log(obd, &llh);
-
         /* Append the mdt info to the client log */
         name_create(mti->mti_fsname, "-clilmv", &lmvname);
         if (mgs_log_is_empty(obd, cliname)) {
                 /* Start client log */
-                name_create(mti->mti_fsname, "-clilov", &tmpname);
-                rc = mgs_write_log_lov(obd, fsdb, mti, cliname, tmpname);
-                name_destroy(tmpname);
+                name_create(mti->mti_fsname, "-clilov", &lovname);
+                rc = mgs_write_log_lov(obd, fsdb, mti, cliname, lovname);
+                name_destroy(lovname);
 
                 rc = mgs_write_log_lmv(obd, fsdb, mti, cliname, lmvname);
         }
@@ -1469,10 +1585,10 @@ static int mgs_write_log_mdt0(struct obd_device *obd, struct fs_db *fsdb,
                      test_bit(i,  fsdb->fsdb_mdt_index_map)) {
                         sprintf(mdt_index,"-MDT%04x",i);
                         
-                        name_create(mti->mti_fsname, mdt_index, &tmpname);
+                        name_create(mti->mti_fsname, mdt_index, &mdtname);
                         rc = mgs_write_log_mdc_to_cmm(obd, fsdb, mti,
-                                                      tmpname, cmmname);
-                        name_destroy(tmpname);
+                                                      mdtname, cmmname);
+                        name_destroy(mdtname);
                 }
         }
         name_destroy(cmmname);
@@ -1853,7 +1969,7 @@ int mgs_write_log_target(struct obd_device *obd,
         down(&fsdb->fsdb_sem);
 
         if (mti->mti_flags & LDD_F_SV_TYPE_MDT) {
-                rc = mgs_write_log_mdt0(obd, fsdb, mti);
+                rc = mgs_write_log_mds(obd, fsdb, mti);
         } else if (mti->mti_flags & LDD_F_SV_TYPE_OST) {
                 rc = mgs_write_log_ost(obd, fsdb, mti);
         } else {