Whamcloud - gitweb
move some method into per-object operation vectors. Add comments.
[fs/lustre-release.git] / lustre / cmm / cmm_object.c
index 06fe7ef..fa73d89 100644 (file)
 #include "cmm_internal.h"
 
 static struct md_object_operations cmm_mo_ops;
+static struct lu_object_operations cmm_obj_ops;
 
-struct lu_object *cmm_object_alloc(struct lu_context *ctx, struct lu_device *d)
+static int cmm_fld_lookup(struct lu_fid *fid)
+{
+        /* return master MDS for now */
+        return 0;
+}
+
+/* get child device by mdsnum*/
+static struct lu_device *cmm_get_child(struct cmm_device *d, __u32 num)
+{
+        struct lu_device *next;
+
+        if (likely(num != d->local_num)) {
+               next = &d->cmm_child->md_lu_dev;
+        } else {
+                next = &d->cmm_child->md_lu_dev;
+        }
+        return next;
+}
+
+struct lu_object *cmm_object_alloc(struct lu_context *ctx,
+                                   struct lu_device *d)
 {
        struct cmm_object *mo;
         ENTRY;
@@ -48,6 +69,7 @@ struct lu_object *cmm_object_alloc(struct lu_context *ctx, struct lu_device *d)
                o = &mo->cmo_obj.mo_lu;
                 lu_object_init(o, NULL, d);
                 mo->cmo_obj.mo_ops = &cmm_mo_ops;
+                o->lo_ops = &cmm_obj_ops;
                RETURN(o);
        } else
                RETURN(NULL);
@@ -58,10 +80,15 @@ int cmm_object_init(struct lu_context *ctxt, struct lu_object *o)
        struct cmm_device *d = lu2cmm_dev(o->lo_dev);
        struct lu_device  *under;
        struct lu_object  *below;
+        struct lu_fid     *fid = &o->lo_header->loh_fid;
+        int mdsnum;
         ENTRY;
 
-       under = &d->cmm_child->md_lu_dev;
-       below = under->ld_ops->ldo_object_alloc(ctxt, under);
+        /* under device can be MDD or MDC */
+        mdsnum = cmm_fld_lookup(fid);
+        under = cmm_get_child(d, mdsnum);
+
+        below = under->ld_ops->ldo_object_alloc(ctxt, under);
        if (below != NULL) {
                lu_object_add(o, below);
                RETURN(0);
@@ -71,7 +98,9 @@ int cmm_object_init(struct lu_context *ctxt, struct lu_object *o)
 
 void cmm_object_free(struct lu_context *ctx, struct lu_object *o)
 {
+        struct cmm_object *mo = lu2cmm_obj(o);
        lu_object_fini(o);
+        OBD_FREE_PTR(mo);
 }
 
 void cmm_object_release(struct lu_context *ctxt, struct lu_object *o)
@@ -79,8 +108,15 @@ void cmm_object_release(struct lu_context *ctxt, struct lu_object *o)
         return;
 }
 
-int cmm_object_print(struct lu_context *ctx,
-                     struct seq_file *f, const struct lu_object *o)
+static int cmm_object_exists(struct lu_context *ctx, struct lu_object *o)
+{
+        struct lu_object *next = lu_object_next(o);
+
+        return next->lo_ops->loo_object_exists(ctx, next);
+}
+
+static int cmm_object_print(struct lu_context *ctx,
+                            struct seq_file *f, const struct lu_object *o)
 {
        return seq_printf(f, LUSTRE_CMM0_NAME"-object@%p", o);
 }
@@ -166,9 +202,12 @@ static struct md_object_operations cmm_mo_ops = {
 //        .moo_link       = cmm_link,
 //        .moo_xattr_get   = cmm_xattr_get,
 //        .moo_xattr_set   = cmm_xattr_set,
-//        .moo_index_insert = cmm_index_insert,
-//        .moo_index_delete = cmm_index_delete,
-//        .moo_object_create = cmm_object_create,
 };
 
+static struct lu_object_operations cmm_obj_ops = {
+       .loo_object_init    = cmm_object_init,
+       .loo_object_release = cmm_object_release,
+       .loo_object_print   = cmm_object_print,
+       .loo_object_exists  = cmm_object_exists
+};