Whamcloud - gitweb
Branch: b_new_cmd
authorwangdi <wangdi>
Thu, 3 Aug 2006 08:43:58 +0000 (08:43 +0000)
committerwangdi <wangdi>
Thu, 3 Aug 2006 08:43:58 +0000 (08:43 +0000)
1)add get_maxsize to get max md and cookiesize
2)add upcall mechnaism from mds_obd-> mdd and mdd->cmm->mdt
  to update max md and cookie size when new ost added.

lustre/cmm/cmm_device.c
lustre/include/md_object.h
lustre/mdd/mdd_handler.c
lustre/mdd/mdd_internal.h
lustre/mdd/mdd_lov.c
lustre/mds/mds_lov.c
lustre/mdt/mdt_handler.c

index 2cd13a4..cf2e1c7 100644 (file)
@@ -74,9 +74,21 @@ static int cmm_statfs(const struct lu_context *ctxt, struct md_device *md,
         RETURN (rc);
 }
 
+static int cmm_get_maxsize(const struct lu_context *ctxt, struct md_device *md,
+                           int *md_size, int *cookie_size)
+{
+        struct cmm_device *cmm_dev = md2cmm_dev(md);
+        int rc;
+        ENTRY;
+        rc = cmm_child_ops(cmm_dev)->mdo_get_maxsize(ctxt,
+                                     cmm_dev->cmm_child, md_size, cookie_size);
+        RETURN(rc);
+}
+
 static struct md_device_operations cmm_md_ops = {
         .mdo_root_get       = cmm_root_get,
         .mdo_statfs         = cmm_statfs,
+        .mdo_get_maxsize    = cmm_get_maxsize,
 };
 
 extern struct lu_device_type mdc_device_type;
@@ -191,6 +203,20 @@ static struct lu_device_operations cmm_lu_ops = {
 };
 
 /* --- lu_device_type operations --- */
+static int cmm_upcall(const struct lu_context *ctxt, struct md_device *md,
+                      enum md_upcall_event ev)
+{
+        struct md_device *upcall_dev;
+        int rc;
+        ENTRY;
+
+        upcall_dev = md->md_upcall.mu_upcall_dev;
+
+        LASSERT(upcall_dev);
+        rc = upcall_dev->md_upcall.mu_upcall(ctxt, md->md_upcall.mu_upcall_dev, ev);
+
+        RETURN(rc);
+}
 
 static struct lu_device *cmm_device_alloc(const struct lu_context *ctx,
                                           struct lu_device_type *t,
@@ -207,6 +233,7 @@ static struct lu_device *cmm_device_alloc(const struct lu_context *ctx,
         } else {
                 md_device_init(&m->cmm_md_dev, t);
                 m->cmm_md_dev.md_ops = &cmm_md_ops;
+                m->cmm_md_dev.md_upcall.mu_upcall = cmm_upcall;
                l = cmm2lu_dev(m);
                 l->ld_ops = &cmm_lu_ops;
         }
index 559d6c9..3c30766 100644 (file)
@@ -145,11 +145,26 @@ struct md_device_operations {
                             struct md_device *m, struct lu_fid *f);
         int (*mdo_statfs)(const struct lu_context *ctx,
                           struct md_device *m, struct kstatfs *sfs);
+        int (*mdo_get_maxsize)(const struct lu_context *ctx,
+                               struct md_device *m, int *md_size,
+                               int *cookie_size);
+};
+
+enum md_upcall_event {
+        /*sync the md layer*/
+        MD_LOV_SYNC
+};
+
+struct md_upcall {
+        struct md_device            *mu_upcall_dev;
+        int (*mu_upcall)(const struct lu_context *ctxt, struct md_device *md, 
+                         enum md_upcall_event ev);
 };
 
 struct md_device {
         struct lu_device             md_lu_dev;
         struct md_device_operations *md_ops;
+        struct md_upcall             md_upcall;
 };
 
 struct md_object {
@@ -373,4 +388,5 @@ static inline int mdo_rename_tgt(const struct lu_context *cx,
                 return p->mo_dir_ops->mdo_rename_tgt(cx, p, t, lf, name);
         }
 }
+
 #endif /* _LINUX_MD_OBJECT_H */
index 04c6538..a7046f2 100644 (file)
@@ -1185,7 +1185,8 @@ static int mdd_root_get(const struct lu_context *ctx,
 }
 
 static int mdd_statfs(const struct lu_context *ctx,
-                      struct md_device *m, struct kstatfs *sfs) {
+                      struct md_device *m, struct kstatfs *sfs) 
+{
        struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
         int rc;
 
@@ -1196,6 +1197,23 @@ static int mdd_statfs(const struct lu_context *ctx,
         RETURN(rc);
 }
 
+static int mdd_get_maxsize(const struct lu_context *ctx,
+                           struct md_device *m, int *md_size,
+                           int *cookie_size) 
+{
+       struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
+        int rc;
+
+        ENTRY;
+
+        rc = mdd_lov_mdsize(ctx, mdd, md_size);
+        if (rc)
+                RETURN(rc);
+        rc = mdd_lov_cookiesize(ctx, mdd, cookie_size);
+        
+        RETURN(rc);
+}
+
 static void __mdd_ref_add(const struct lu_context *ctxt, struct mdd_object *obj,
                          struct thandle *handle)
 {
@@ -1293,6 +1311,7 @@ static int mdd_readpage(const struct lu_context *ctxt, struct md_object *obj,
 struct md_device_operations mdd_ops = {
         .mdo_root_get       = mdd_root_get,
         .mdo_statfs         = mdd_statfs,
+        .mdo_get_maxsize    = mdd_get_maxsize,
 };
 
 static struct md_dir_operations mdd_dir_ops = {
index 3afea42..f24e624 100644 (file)
@@ -122,4 +122,9 @@ static inline struct obd_device *mdd2_obd(struct mdd_device *mdd)
 {
         return mdd->mdd_md_dev.md_lu_dev.ld_obd; 
 }
+
+int mdd_lov_mdsize(const struct lu_context *ctxt, struct mdd_device *mdd,
+                   int *md_size);
+int mdd_lov_cookiesize(const struct lu_context *ctxt, struct mdd_device *mdd,
+                       int *cookie_size);
 #endif
index 53e9dc2..9bed82f 100644 (file)
@@ -154,6 +154,26 @@ static struct md_lov_ops mdd_lov_ops = {
         .ml_write_catlist = mdd_lov_write_catlist
 };
 
+static int mdd_lov_update(struct obd_device *host,
+                          struct obd_device *watched,
+                          enum obd_notify_event ev, void *owner)
+{
+        struct mdd_device *mdd = owner;
+        struct obd_device *obd;
+        struct md_device *upcall_dev;
+        int rc;
+        ENTRY;
+        
+        LASSERT(owner != NULL);
+        obd = mdd2_obd(mdd);
+
+        upcall_dev = mdd->mdd_md_dev.md_upcall.mu_upcall_dev;
+
+        rc = upcall_dev->md_upcall.mu_upcall(NULL, upcall_dev, MD_LOV_SYNC);
+
+        RETURN(rc);
+}
+
 /*The obd is created for handling data stack for mdd*/
 int mdd_init_obd(const struct lu_context *ctxt, struct mdd_device *mdd, 
                  char *dev)
@@ -201,7 +221,11 @@ int mdd_init_obd(const struct lu_context *ctxt, struct mdd_device *mdd,
         rc = class_setup(obd, lcfg);
         if (rc)
                 GOTO(class_detach, rc);
+        /*Add here for obd notify mechiasm,
+         *when adding a new ost, the mds will notify this mdd*/
 
+        obd->obd_upcall.onu_owner = mdd;
+        obd->obd_upcall.onu_upcall = mdd_lov_update;
         mdd->mdd_md_dev.md_lu_dev.ld_obd = obd;
 class_detach:
         if (rc)
@@ -397,3 +421,20 @@ int mdd_unlink_log(const struct lu_context *ctxt, struct mdd_device *mdd,
         }
         return 0;
 }
+
+int mdd_lov_mdsize(const struct lu_context *ctxt, struct mdd_device *mdd,
+                   int *md_size)
+{
+        struct obd_device *obd = mdd2_obd(mdd);
+        *md_size = obd->u.mds.mds_max_mdsize;  
+        RETURN(0);
+}
+
+int mdd_lov_cookiesize(const struct lu_context *ctxt, struct mdd_device *mdd,
+                       int *cookie_size)
+{
+        struct obd_device *obd = mdd2_obd(mdd);
+        *cookie_size = obd->u.mds.mds_max_cookiesize;
+        RETURN(0);
+}
+
index 8b314a4..2c3268a 100644 (file)
@@ -732,7 +732,14 @@ static int __mds_lov_synchronize(void *data)
                        obd->obd_name, rc);
                 GOTO(out, rc);
         }
-
+        if (obd->obd_upcall.onu_owner) {
+                /*This is an hack for mds_notify->mdd_notify,
+                 *When the mds obd in mdd is removed, 
+                 *This hack should be removed*/
+                LASSERT(obd->obd_upcall.onu_upcall != NULL);
+                obd->obd_upcall.onu_upcall(NULL, NULL, 0,
+                                 obd->obd_upcall.onu_owner);
+        }
 out:
         class_decref(obd);
         RETURN(rc);
index 4169b5f..8f2dd34 100644 (file)
@@ -657,7 +657,7 @@ static int mdt_reint(struct mdt_thread_info *info)
         opc = mdt_reint_opcode(info, reint_fmts);
         if (opc >= 0) {
                 OBD_FAIL_RETURN(OBD_FAIL_MDS_REINT_NET, 0);
-
+                
                 rc = req_capsule_pack(&info->mti_pill);
                 if (rc == 0)
                         rc = mdt_reint_internal(info, opc);
@@ -2135,7 +2135,7 @@ static struct lu_device *mdt_layer_setup(const struct lu_context *ctx,
                 GOTO(out_alloc, rc);
         }
         lu_device_get(d);
-
+      
         RETURN(d);
 out_alloc:
         ldt->ldt_ops->ldto_device_free(ctx, d);
@@ -2151,6 +2151,7 @@ static int mdt_stack_init(const struct lu_context *ctx,
 {
         struct lu_device  *d = &m->mdt_md_dev.md_lu_dev;
         struct lu_device  *tmp;
+        struct md_device *md;
         int rc;
         ENTRY;
 
@@ -2166,11 +2167,20 @@ static int mdt_stack_init(const struct lu_context *ctx,
                 GOTO(out, rc = PTR_ERR(tmp));
         }
         d = tmp;
+        md = lu2md_dev(d);
+        
         tmp = mdt_layer_setup(ctx, LUSTRE_CMM0_NAME, d, cfg);
         if (IS_ERR(tmp)) {
                 GOTO(out, rc = PTR_ERR(tmp));
         }
         d = tmp;
+        /*set mdd upcall device*/
+        md->md_upcall.mu_upcall_dev = lu2md_dev(d);
+       
+        md = lu2md_dev(d);
+        /*set cmm upcall device*/
+        md->md_upcall.mu_upcall_dev = &m->mdt_md_dev;
+
         m->mdt_child = lu2md_dev(d);
 
         /* process setup config */
@@ -2325,7 +2335,9 @@ err_free_site:
 static int mdt_process_config(const struct lu_context *ctx,
                               struct lu_device *d, struct lustre_cfg *cfg)
 {
-        struct lu_device *next = md2lu_dev(mdt_dev(d)->mdt_child);
+        struct mdt_device *m = mdt_dev(d);
+        struct md_device *md_next  = m->mdt_child;
+        struct lu_device *next = md2lu_dev(md_next);
         int err;
         ENTRY;
 
@@ -2340,10 +2352,10 @@ static int mdt_process_config(const struct lu_context *ctx,
                         CERROR("can't initialize controller export, "
                                "rc %d\n", err);
                 }
-                /* all MDT specific commands should be here */
         default:
                 /* others are passed further */
                 err = next->ld_ops->ldo_process_config(ctx, next, cfg);
+                break;
         }
         RETURN(err);
 }
@@ -2603,6 +2615,30 @@ static int mdt_destroy_export(struct obd_export *export)
         RETURN(rc);
 }
 
+static int mdt_upcall(const struct lu_context *ctx, struct md_device *md,
+                      enum md_upcall_event ev)
+{
+        struct mdt_device *m = mdt_dev(&md->md_lu_dev);
+        struct md_device  *next  = m->mdt_child;
+        int rc = 0;
+        ENTRY;
+        
+        switch (ev) {
+                case MD_LOV_SYNC:
+                        rc = next->md_ops->mdo_get_maxsize(ctx, next, 
+                                    &m->mdt_max_mdsize, &m->mdt_max_cookiesize);
+                        CDEBUG(D_INFO, "get max mdsize %d max cookiesize %d \n",
+                                     m->mdt_max_mdsize, m->mdt_max_cookiesize);
+                        break;
+                default:
+                        CERROR("invalid event\n");
+                        rc = -EINVAL;
+                        break;
+        }
+        RETURN(rc);
+}
+
+
 static struct obd_ops mdt_obd_device_ops = {
         .o_owner          = THIS_MODULE,
         .o_connect        = mdt_obd_connect,
@@ -2636,6 +2672,7 @@ static struct lu_device *mdt_device_alloc(const struct lu_context *ctx,
                         OBD_FREE_PTR(m);
                         l = ERR_PTR(result);
                 }
+                m->mdt_md_dev.md_upcall.mu_upcall = mdt_upcall;
         } else
                 l = ERR_PTR(-ENOMEM);
         return l;