Whamcloud - gitweb
dt_store_open(): new helper function to open perisistent store object in the root...
authornikita <nikita>
Sat, 27 May 2006 15:36:59 +0000 (15:36 +0000)
committernikita <nikita>
Sat, 27 May 2006 15:36:59 +0000 (15:36 +0000)
lustre/fld/fld_iam.c
lustre/mdd/mdd_handler.c
lustre/obdclass/dt_object.c

index 7a07388..9e87f46 100644 (file)
@@ -65,14 +65,14 @@ enum {
         FLD_TXN_INDEX_DELETE_CREDITS  = 10
 };
 
-static int fld_keycmp(struct iam_container *c, struct iam_key *k1, 
+static int fld_keycmp(struct iam_container *c, struct iam_key *k1,
                       struct iam_key *k2)
 {
         __u64 p1 = le64_to_cpu(*(__u32 *)k1);
         __u64 p2 = le64_to_cpu(*(__u32 *)k2);
 
         return p1 > p2 ? +1 : (p1 < p2 ? -1 : 0);
+
 }
 
 int fld_handle_insert(const struct lu_context *ctx, struct fld *fld,
@@ -84,13 +84,13 @@ int fld_handle_insert(const struct lu_context *ctx, struct fld *fld,
         struct thandle *th;
         int    rc;
 
-      
-        /*stub here, will fix it later*/ 
+
+        /*stub here, will fix it later*/
         txn.tp_credits = FLD_TXN_INDEX_INSERT_CREDITS;
+
         th = dt->dd_ops->dt_trans_start(ctx, dt, &txn);
-        
-        rc = dt_obj->do_index_ops->dio_insert(ctx, dt_obj, 
+
+        rc = dt_obj->do_index_ops->dio_insert(ctx, dt_obj,
                                               (struct dt_rec*)(&mds_num),
                                               (struct dt_key*)(&seq_num), th);
         dt->dd_ops->dt_trans_stop(ctx, th);
@@ -107,10 +107,10 @@ int fld_handle_delete(const struct lu_context *ctx, struct fld *fld,
         struct thandle *th;
         int    rc;
 
-        
+
         txn.tp_credits = FLD_TXN_INDEX_DELETE_CREDITS;
         th = dt->dd_ops->dt_trans_start(ctx, dt, &txn);
-        rc = dt_obj->do_index_ops->dio_delete(ctx, dt_obj, 
+        rc = dt_obj->do_index_ops->dio_delete(ctx, dt_obj,
                                               (struct dt_rec*)(&mds_num),
                                               (struct dt_key*)(&seq_num), th);
         dt->dd_ops->dt_trans_stop(ctx, th);
@@ -121,48 +121,49 @@ int fld_handle_delete(const struct lu_context *ctx, struct fld *fld,
 int fld_handle_lookup(const struct lu_context *ctx,
                       struct fld *fld, fidseq_t seq_num, mdsno_t *mds_num)
 {
-        
-        struct dt_device *dt = fld->fld_dt;
+
         struct dt_object *dt_obj = fld->fld_obj;
-        
+
         return dt_obj->do_index_ops->dio_lookup(ctx, dt_obj,
                                              (struct dt_rec*)(&mds_num),
                                              (struct dt_key*)(&seq_num));
 }
 
-#define FLD_OBJ_FID {1000, 1000, 1000}
-#define FLD_OBJ_MODE S_IFDIR
-int fld_iam_init(struct lu_context *ctx, struct fld *fld)
+int fld_iam_init(const struct lu_context *ctx, struct fld *fld)
 {
-        struct lu_fid obj_fid = FLD_OBJ_FID; /* reserved fid */
         struct dt_device *dt = fld->fld_dt;
         struct dt_object *dt_obj;
-        struct iam_container *ic;
-        int rc = 0;
+        struct iam_container *ic = NULL;
+        int rc;
 
         ENTRY;
 
-        dt_obj = dt_object_find(ctx, dt, &obj_fid);
-        if (IS_ERR(dt_obj)) {
-                CERROR("can not find fld obj %lu \n", PTR_ERR(dt_obj));
-                RETURN(PTR_ERR(dt_obj));
+        dt_obj = dt_store_open(ctx, dt, "fld", &fld->fld_fid);
+        if (!IS_ERR(dt_obj)) {
+                fld->fld_obj = dt_obj;
+                if (dt_obj->do_index_ops != NULL) {
+                        rc = dt_obj->do_index_ops->dio_init(ctx, dt_obj,
+                                                            ic, &fld_param);
+                        fld_param.id_ops->id_keycmp = fld_keycmp;
+                } else {
+                        CERROR("fld is not an index!\n");
+                        rc = -EINVAL;
+                }
+        } else {
+                CERROR("Cannot find fld obj %lu \n", PTR_ERR(dt_obj));
+                rc = PTR_ERR(dt_obj);
         }
-        
-        lu_object_get(&dt_obj->do_lu);
-        fld->fld_obj = dt_obj;
-        OBD_ALLOC_PTR(ic);
 
-        rc = dt_obj->do_index_ops->dio_init(ctx, dt, dt_obj, ic, &fld_param);
-        fld_param.id_ops->id_keycmp = fld_keycmp; 
+
         RETURN(rc);
 }
 
-void fld_iam_fini(struct fld *fld)
+void fld_iam_fini(const struct lu_context *ctx, struct fld *fld)
 {
         struct dt_object *dt_obj = fld->fld_obj;
 
-        dt_obj->do_index_ops->dio_fini(dt_obj);
-        /*XXX Should put object here, 
+        dt_obj->do_index_ops->dio_fini(ctx, dt_obj);
+        /*XXX Should put object here,
           lu_object_put(fld->fld_obj->do_lu);
          *but no ctxt in this func, FIX later*/
         fld->fld_obj = NULL;
index 6443705..e76ad0d 100644 (file)
@@ -324,9 +324,8 @@ static int mdd_object_print(const struct lu_context *ctxt,
         return seq_printf(f, LUSTRE_MDD0_NAME"-object@%p", o);
 }
 
-static int mdd_dt_lookup(const struct lu_context *ctx, struct mdd_device *mdd,
-                         struct mdd_object *obj, const char *name,
-                         struct lu_fid *fid)
+static int mdd_dt_lookup(const struct lu_context *ctx, struct mdd_object *obj,
+                         const char *name, struct lu_fid *fid)
 {
         struct dt_object *dir    = mdd_object_child(obj);
         struct dt_rec    *rec    = (struct dt_rec *)fid;
@@ -343,35 +342,16 @@ static int mdd_dt_lookup(const struct lu_context *ctx, struct mdd_device *mdd,
 static int mdd_mount(const struct lu_context *ctx, struct mdd_device *mdd)
 {
         int result;
-        struct mdd_thread_info *info = lu_context_key_get(ctx,
-                                                          &mdd_thread_key);
-        struct lu_device *dev = &mdd->mdd_md_dev.md_lu_dev;
-
-        result = mdd_child_ops(mdd)->dt_root_get(ctx, mdd->mdd_child,
-                                                 &info->mti_fid);
-        if (result == 0) {
-                struct lu_object *root;
-
-                root = lu_object_find(ctx, dev->ld_site, &info->mti_fid);
-                if (!IS_ERR(root)) {
-                        struct mdd_object *obj;
-
-                        obj = mdd_obj(lu_object_locate(root->lo_header,
-                                                       dev->ld_type));
-                        if (obj != NULL)
-                                result = mdd_dt_lookup(ctx, mdd, obj,
-                                                       mdd_root_dir_name ,
-                                                       &mdd->mdd_root_fid);
-                        else {
-                                CERROR("No slice\n");
-                                result = -EINVAL;
-                        }
-                        lu_object_put(ctx, root);
-                } else {
-                        CERROR("No root\n");
-                        result = PTR_ERR(root);
-                }
-        }
+        struct dt_object *root;
+
+        root = dt_store_open(ctx, mdd->mdd_child, mdd_root_dir_name,
+                             &mdd->mdd_root_fid);
+        if (!IS_ERR(root)) {
+                LASSERT(root != NULL);
+                lu_object_put(ctx, &root->do_lu);
+                result = 0;
+        } else
+                result = PTR_ERR(root);
         return result;
 }
 
@@ -753,7 +733,7 @@ cleanup:
 static int mdd_lookup(const struct lu_context *ctxt, struct md_object *pobj,
                       const char *name, struct lu_fid* fid)
 {
-        return mdd_dt_lookup(ctxt, mdo2mdd(pobj), mdo2mddo(pobj), name, fid);
+        return mdd_dt_lookup(ctxt, mdo2mddo(pobj), name, fid);
 }
 
 static int mdd_create(const struct lu_context *ctxt,
index 47f1cc2..10a5b23 100644 (file)
@@ -127,3 +127,63 @@ void dt_object_fini(struct dt_object *obj)
         lu_object_fini(&obj->do_lu);
 }
 EXPORT_SYMBOL(dt_object_fini);
+
+static int dt_lookup(const struct lu_context *ctx, struct dt_object *dir,
+                     const char *name, struct lu_fid *fid)
+{
+        struct dt_rec       *rec = (struct dt_rec *)fid;
+        const struct dt_key *key = (const struct dt_key *)name;
+        int result;
+
+        if (dir->do_index_ops != NULL)
+                result = dir->do_index_ops->dio_lookup(ctx, dir, rec, key);
+        else
+                result = -ENOTDIR;
+        return result;
+}
+
+static struct dt_object *dt_locate(const struct lu_context *ctx,
+                                   struct dt_device *dev,
+                                   const struct lu_fid *fid)
+{
+        struct lu_object *obj;
+        struct dt_object *dt;
+
+        obj = lu_object_find(ctx, dev->dd_lu_dev.ld_site, fid);
+        if (!IS_ERR(obj)) {
+                obj = lu_object_locate(obj->lo_header, dev->dd_lu_dev.ld_type);
+                LASSERT(obj != NULL);
+                dt = container_of(obj, struct dt_object, do_lu);
+        } else
+                dt = (void *)obj;
+        return dt;
+}
+
+struct dt_object *dt_store_open(const struct lu_context *ctx,
+                                struct dt_device *dt, const char *name,
+                                struct lu_fid *fid)
+{
+        int result;
+
+        struct dt_object *root;
+        struct dt_object *child;
+
+        result = dt->dd_ops->dt_root_get(ctx, dt, fid);
+        if (result == 0) {
+                root = dt_locate(ctx, dt, fid);
+                if (!IS_ERR(root)) {
+                        result = dt_lookup(ctx, root, name, fid);
+                        if (result == 0)
+                                child = dt_locate(ctx, dt, fid);
+                        else
+                                child = ERR_PTR(result);
+                        lu_object_put(ctx, &root->do_lu);
+                } else {
+                        CERROR("No root\n");
+                        child = (void *)root;
+                }
+        } else
+                child = ERR_PTR(result);
+        return child;
+}
+EXPORT_SYMBOL(dt_store_open);