Whamcloud - gitweb
Branch:
authorwangdi <wangdi>
Sun, 16 Apr 2006 12:30:24 +0000 (12:30 +0000)
committerwangdi <wangdi>
Sun, 16 Apr 2006 12:30:24 +0000 (12:30 +0000)
update fld prototype according to nikita's review

lustre/fld/fld_internal.h
lustre/fld/fld_seq.c
lustre/include/linux/lu_object.h
lustre/include/linux/md_object.h
lustre/mdd/mdd_handler.c
lustre/mdt/mdt_handler.c

index e83829f..2b386ef 100644 (file)
@@ -36,4 +36,21 @@ struct fld_cache_info {
         spinlock_t fld_lock;
         int fld_hash_mask;
 };
+/*XXX use linked list temp for fld in this prototype*/
+struct fld_list {
+        struct list_head fld_list;
+        spinlock_t       fld_lock;
+};
+struct fld_item{
+        struct list_head fld_list;
+        __u64 fld_seq;
+        __u64 fld_mds;
+};
+
+enum fld_op {
+        FLD_CREATE = 0,
+        FLD_DELETE = 1,
+        FLD_GET    = 2
+};
+
 #endif
index 2faf34e..301d750 100644 (file)
@@ -275,6 +275,109 @@ static void __exit fld_mod_exit(void)
         return;
 }
 
+
+struct fld_list fld_list_head;
+
+int fld_server_init(struct fld *fld, struct dt_device *dt)
+{
+        fld->fld_dt = dt;
+        INIT_LIST_HEAD(&fld_list_head.fld_list);
+        spin_lock_init(&fld_list_head.fld_lock);
+        return 0;
+}
+EXPORT_SYMBOL(fld_server_init);
+
+void fld_server_fini(struct fld *fld)
+{
+        struct list_head *pos, *n;
+       
+        spin_lock(&fld_list_head.fld_lock);
+        list_for_each_safe(pos, n, &fld_list_head.fld_list) {
+                struct fld_item *fld = list_entry(pos, struct fld_item,
+                                                  fld_list);
+                list_del_init(&fld->fld_list);
+                OBD_FREE_PTR(fld);
+        }
+        spin_unlock(&fld_list_head.fld_lock); 
+}
+EXPORT_SYMBOL(fld_server_fini);
+
+static int fld_handle_create(struct fld *pfld, __u64 seq_num, __u64 mds_num)
+{
+        struct fld_item *fld;
+        
+        OBD_ALLOC_PTR(fld);
+        fld->fld_seq = seq_num;
+        fld->fld_mds = mds_num;
+        INIT_LIST_HEAD(&fld->fld_list); 
+        spin_lock(&fld_list_head.fld_lock);
+        list_add_tail(&fld_list_head.fld_list, &fld->fld_list);
+        spin_unlock(&fld_list_head.fld_lock);
+        return 0;
+}
+
+static int fld_handle_delete(struct fld *pfld, __u64 seq_num, __u64 mds_num)
+{
+        struct list_head *pos, *n;
+        spin_lock(&fld_list_head.fld_lock);
+        list_for_each_safe(pos, n, &fld_list_head.fld_list) {
+                struct fld_item *fld = list_entry(pos, struct fld_item,
+                                                  fld_list);
+                if (fld->fld_seq == seq_num) {
+                        LASSERT(fld->fld_mds == mds_num);
+                        list_del_init(&fld->fld_list);
+                        OBD_FREE_PTR(fld);
+                        spin_unlock(&fld_list_head.fld_lock);
+                        RETURN(0);
+                }
+        }
+        spin_unlock(&fld_list_head.fld_lock);
+        RETURN(0);
+}
+
+static int fld_handle_get(struct fld *pfld, __u64 seq_num, __u64 *mds_num)
+{
+        struct list_head *pos, *n;
+       
+        spin_lock(&fld_list_head.fld_lock);
+        list_for_each_safe(pos, n, &fld_list_head.fld_list) {
+                struct fld_item *fld = list_entry(pos, struct fld_item,
+                                                  fld_list);
+                if (fld->fld_seq == seq_num) {
+                        *mds_num = fld->fld_mds;
+                        spin_unlock(&fld_list_head.fld_lock);
+                        RETURN(0);
+                }
+        }
+        spin_unlock(&fld_list_head.fld_lock);
+        return -ENOENT;
+}
+
+int fld_handle(struct fld *fld, __u32 opts, void *mf)
+{
+        struct md_fld *pmf = mf;
+        int rc;
+        ENTRY;
+
+        switch (opts) {
+        case FLD_CREATE:
+                rc = fld_handle_create(fld, pmf->mf_seq, pmf->mf_mds);
+                break;
+        case FLD_DELETE:
+                rc = fld_handle_delete(fld, pmf->mf_seq, pmf->mf_mds);
+                break;
+        case FLD_GET:
+                rc = fld_handle_get(fld, pmf->mf_seq, &pmf->mf_mds);
+                break;
+        default:
+                rc = -EINVAL;
+                break; 
+        }
+        RETURN(rc);
+
+}
+EXPORT_SYMBOL(fld_handle);
+
 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
 MODULE_DESCRIPTION("Lustre fld Prototype");
 MODULE_LICENSE("GPL");
index 48623e5..d0e2fd1 100644 (file)
@@ -319,6 +319,7 @@ struct lu_object_header {
        struct list_head  loh_layers;
 };
 
+struct fld;
 /*
  * lu_site is a "compartment" within which objects are unique, and LRU
  * discipline is maintained.
@@ -374,6 +375,11 @@ struct lu_site {
         */
        struct lu_device  *ls_top_dev;
 
+        /*
+         * Fid location database
+         */
+        struct fld        *ls_fld;
+
        /* statistical counters. Protected by nothing, races are accepted. */
        struct {
                __u32 s_created;
@@ -569,6 +575,14 @@ struct txn_param {
         unsigned int tp_credits;
 };
 
+struct fld {
+        struct dt_device        *fld_dt;
+};
+
+extern int fld_server_init(struct fld *fld, struct dt_device *dt);
+extern void fld_server_fini(struct fld *fld);
+extern int fld_handle(struct fld *fld, __u32 opts, void *mf);
+
 #define TXN_PARAM_INIT(credits) {               \
         .tp_credits = (credits)                 \
 }
index b1437f8..8413ec4 100644 (file)
@@ -84,12 +84,6 @@ struct md_device_operations {
                             struct md_device *m, struct lu_fid *f);
         int (*mdo_statfs)(struct lu_context *ctx,
                           struct md_device *m, struct kstatfs *sfs);
-
-        int (*mdo_fld)(struct lu_context *ctx, struct md_device *m, 
-                       __u32 opt, void *mf);
-        
-        int (*mdo_set_info)(struct lu_context *ctx, struct md_device *m, 
-                            __u32 keylen, void *key, __u32 vallen, void *val);
 };
 
 struct md_device {
@@ -145,9 +139,4 @@ static inline void md_device_fini(struct md_device *md)
        lu_device_fini(&md->md_lu_dev);
 }
 
-enum fld_op {
-        FLD_CREATE = 0,
-        FLD_DELETE = 1,
-        FLD_GET    = 2
-};
 #endif /* _LINUX_MD_OBJECT_H */
index d08b563..30aa2d7 100644 (file)
@@ -679,119 +679,8 @@ static int mdd_statfs(struct lu_context *ctx,
         RETURN(rc);
 }
 
-/*XXX use linked list temp for fld in this prototype*/
-struct fld_list {
-        struct list_head fld_list;
-        spinlock_t       fld_lock;
-};
-struct fld_item{
-        struct list_head fld_list;
-        __u64 fld_seq;
-        __u64 fld_mds;
-};
-
-struct fld_list fld_list_head;
-
-static void mdd_fld_init(struct mdd_device *mdd)
-{
-        INIT_LIST_HEAD(&fld_list_head.fld_list);
-        spin_lock_init(&fld_list_head.fld_lock);
-}
-
-static void mdd_fld_fini(struct mdd_device *mdd)
-{
-        struct list_head *pos, *n;
-       
-        spin_lock(&fld_list_head.fld_lock);
-        list_for_each_safe(pos, n, &fld_list_head.fld_list) {
-                struct fld_item *fld = list_entry(pos, struct fld_item,
-                                                  fld_list);
-                list_del_init(&fld->fld_list);
-                OBD_FREE_PTR(fld);
-        }
-        spin_unlock(&fld_list_head.fld_lock); 
-}
-
-static int mdd_fld_create(struct mdd_device *mdd, __u64 seq_num, __u64 mds_num)
-{
-        struct fld_item *fld;
-        
-        OBD_ALLOC_PTR(fld);
-        fld->fld_seq = seq_num;
-        fld->fld_mds = mds_num;
-        INIT_LIST_HEAD(&fld->fld_list); 
-        spin_lock(&fld_list_head.fld_lock);
-        list_add_tail(&fld_list_head.fld_list, &fld->fld_list);
-        spin_unlock(&fld_list_head.fld_lock);
-        return 0;
-}
-
-static int mdd_fld_delete(struct mdd_device *mdd, __u64 seq_num, __u64 mds_num)
-{
-        struct list_head *pos, *n;
-        spin_lock(&fld_list_head.fld_lock);
-        list_for_each_safe(pos, n, &fld_list_head.fld_list) {
-                struct fld_item *fld = list_entry(pos, struct fld_item,
-                                                  fld_list);
-                if (fld->fld_seq == seq_num) {
-                        LASSERT(fld->fld_mds == mds_num);
-                        list_del_init(&fld->fld_list);
-                        OBD_FREE_PTR(fld);
-                        spin_unlock(&fld_list_head.fld_lock);
-                        RETURN(0);
-                }
-        }
-        spin_unlock(&fld_list_head.fld_lock);
-        RETURN(0);
-}
-
-static int mdd_fld_get(struct mdd_device *mdd, __u64 seq_num, __u64 *mds_num)
-{
-        struct list_head *pos, *n;
-       
-        spin_lock(&fld_list_head.fld_lock);
-        list_for_each_safe(pos, n, &fld_list_head.fld_list) {
-                struct fld_item *fld = list_entry(pos, struct fld_item,
-                                                  fld_list);
-                if (fld->fld_seq == seq_num) {
-                        *mds_num = fld->fld_mds;
-                        spin_unlock(&fld_list_head.fld_lock);
-                        RETURN(0);
-                }
-        }
-        spin_unlock(&fld_list_head.fld_lock);
-        return -ENOENT;
-}
-
-static int mdd_fld(struct lu_context *ctx, struct md_device *m,
-                   __u32 opts, void *mf)
-{
-        struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
-        struct md_fld *pmf = mf;
-        int rc;
-        ENTRY;
-
-        switch (opts) {
-        case FLD_CREATE:
-                rc = mdd_fld_create(mdd, pmf->mf_seq, pmf->mf_mds);
-                break;
-        case FLD_DELETE:
-                rc = mdd_fld_delete(mdd, pmf->mf_seq, pmf->mf_mds);
-                break;
-        case FLD_GET:
-                rc = mdd_fld_get(mdd, pmf->mf_seq, &pmf->mf_mds);
-                break;
-        default:
-                rc = -EINVAL;
-                break; 
-        }
-        RETURN(rc);
-
-}
-
 struct md_device_operations mdd_ops = {
         .mdo_root_get   = mdd_root_get,
-        .mdo_fld        = mdd_fld,
         .mdo_config     = mdd_config,
         .mdo_statfs     = mdd_statfs
 };
@@ -829,7 +718,6 @@ struct lu_device *mdd_device_alloc(struct lu_device_type *t,
                 l = mdd2lu_dev(m);
                l->ld_ops = &mdd_lu_ops;
                 m->mdd_md_dev.md_ops = &mdd_ops;
-                mdd_fld_init(m);
                 /* get next layer */
                 obd = class_name2obd(child);
                 if (obd && obd->obd_lu_dev) {
@@ -850,7 +738,6 @@ void mdd_device_free(struct lu_device *lu)
         struct mdd_device *m = lu2mdd_dev(lu);
 
         LASSERT(atomic_read(&lu->ld_ref) == 0);
-        mdd_fld_fini(m);       
         md_device_fini(&m->mdd_md_dev);
 
         OBD_FREE_PTR(m);
index 7bb7052..b7db5d2 100644 (file)
@@ -201,32 +201,6 @@ static int mdt_getattr(struct mdt_thread_info *info,
         RETURN(result);
 }
 
-static int mdt_fld(struct mdt_thread_info *info,
-                   struct ptlrpc_request *req, int offset)
-{
-        struct md_device *next  = info->mti_mdt->mdt_child;
-        struct md_fld mf, *p, *reply;
-        int size = sizeof(*reply);
-        __u32 *opt; 
-        int rc;
-        ENTRY;
-
-        rc = lustre_pack_reply(req, 1, &size, NULL);
-        if (rc)
-                RETURN(rc);
-
-        opt = lustre_swab_reqbuf(req, 0, sizeof(*opt), 
-                                         lustre_swab_generic_32s);
-
-        p = lustre_swab_reqbuf(req, 1, sizeof(mf), lustre_swab_md_fld);
-        mf = *p;
-        rc = next->md_ops->mdo_fld(info->mti_ctxt, next, *opt, &mf);
-        reply = lustre_msg_buf(req->rq_repmsg, 0, size);
-        *reply = mf;
-
-        RETURN(rc);
-}
-
 static struct lu_device_operations mdt_lu_ops;
 
 static int lu_device_is_mdt(struct lu_device *d)
@@ -1117,6 +1091,72 @@ err_mdt_svc:
         RETURN(rc);
 }
 
+static int mdt_fld(struct mdt_thread_info *info,
+                   struct ptlrpc_request *req, int offset)
+{
+        struct lu_site *ls  = info->mti_mdt->mdt_md_dev.md_lu_dev.ld_site;
+        struct md_fld mf, *p, *reply;
+        int size = sizeof(*reply);
+        __u32 *opt; 
+        int rc;
+        ENTRY;
+
+        rc = lustre_pack_reply(req, 1, &size, NULL);
+        if (rc)
+                RETURN(rc);
+
+        opt = lustre_swab_reqbuf(req, 0, sizeof(*opt), lustre_swab_generic_32s);
+        p = lustre_swab_reqbuf(req, 1, sizeof(mf), lustre_swab_md_fld);
+        mf = *p;
+        
+        rc = fld_handle(ls->ls_fld, *opt, &mf);
+        if (rc)
+                RETURN(rc);        
+
+        reply = lustre_msg_buf(req->rq_repmsg, 0, size);
+        *reply = mf;
+        RETURN(rc);
+}
+
+struct dt_device *md2_bottom_dev(struct mdt_device *m)
+{
+        /*FIXME: get dt device here*/
+        RETURN (NULL);
+}
+
+static int mdt_fld_init(struct mdt_device *m)
+{
+        struct dt_device *dt;
+        struct lu_site   *ls;
+        int rc;
+        ENTRY;
+
+        dt = md2_bottom_dev(m);
+       
+        ls = m->mdt_md_dev.md_lu_dev.ld_site;
+        
+        OBD_ALLOC_PTR(ls->ls_fld);
+        
+        if (!ls->ls_fld)
+             RETURN(-ENOMEM);
+        
+        rc = fld_server_init(ls->ls_fld, dt);
+        
+        RETURN(rc);
+}
+
+static int mdt_fld_fini(struct mdt_device *m)
+{
+        struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
+        int rc = 0;
+        if (ls && ls->ls_fld) {
+                fld_server_fini(ls->ls_fld);
+                OBD_FREE_PTR(ls->ls_fld);
+        }
+        RETURN(rc);
+}
+
 static int mdt_init0(struct mdt_device *m,
                      struct lu_device_type *t, struct lustre_cfg *cfg)
 {
@@ -1183,11 +1223,17 @@ static int mdt_init0(struct mdt_device *m,
                 GOTO(err_fini_site, rc = -ENOMEM);
 
         ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
+       
+        rc = mdt_fld_init(m); 
+        if (rc) 
+                GOTO(err_free_ns, rc);
 
         rc = mdt_start_ptlrpc_service(m);
         if (rc)
-                GOTO(err_free_ns, rc);
+                GOTO(err_free_fld, rc);
         RETURN(0);
+err_free_fld:
+        mdt_fld_fini(m);
 err_free_ns:
         ldlm_namespace_free(m->mdt_namespace, 0);
         m->mdt_namespace = NULL;