Whamcloud - gitweb
dt_object: add di_is_dir() helper
authornikita <nikita>
Sun, 2 Jul 2006 21:14:43 +0000 (21:14 +0000)
committernikita <nikita>
Sun, 2 Jul 2006 21:14:43 +0000 (21:14 +0000)
lustre/include/dt_object.h
lustre/mdd/mdd_handler.c
lustre/obdclass/dt_object.c

index 172138e..f062e08 100644 (file)
@@ -166,7 +166,7 @@ struct dt_object_operations {
          * precondition: lu_object_exists(ctxt, &dt->do_lu);
          */
         int   (*do_xattr_set)(const struct lu_context *ctxt,
-                              struct dt_object *dt, 
+                              struct dt_object *dt,
                               const void *buf, int buf_len,
                               const char *name, struct thandle *handle);
         /*
@@ -345,6 +345,7 @@ int dt_txn_hook_stop(const struct lu_context *ctx,
 int dt_txn_hook_commit(const struct lu_context *ctx,
                        struct dt_device *dev, struct thandle *txn);
 
+int dt_is_dir(const struct lu_context *ctx, struct dt_object *obj);
 struct dt_object *dt_store_open(const struct lu_context *ctx,
                                 struct dt_device *dt, const char *name,
                                 struct lu_fid *fid);
index d29f0bf..0fb2fb4 100644 (file)
@@ -65,7 +65,7 @@ static struct lu_object_operations mdd_lu_obj_ops;
 static struct lu_context_key       mdd_thread_key;
 
 
-const char *mdd_root_dir_name = "ROOT";
+const char *mdd_root_dir_name = "root";
 
 struct mdd_thread_info *mdd_ctx_info(const struct lu_context *ctx)
 {
@@ -567,7 +567,7 @@ static int __mdd_index_insert(const struct lu_context *ctxt,
         struct dt_object *next = mdd_object_child(pobj);
         ENTRY;
 
-        if (next->do_index_ops != NULL)
+        if (dt_is_dir(ctxt, next))
                 rc = next->do_index_ops->dio_insert(ctxt, next,
                                          (struct dt_rec *)lf,
                                          (struct dt_key *)name, handle);
@@ -584,7 +584,7 @@ static int __mdd_index_delete(const struct lu_context *ctxt,
         struct dt_object *next = mdd_object_child(pobj);
         ENTRY;
 
-        if (next->do_index_ops != NULL)
+        if (dt_is_dir(ctxt, next))
                 rc = next->do_index_ops->dio_delete(ctxt, next,
                                         (struct dt_key *)name, handle);
         else
@@ -721,13 +721,13 @@ cleanup:
 static int mdd_lookup(const struct lu_context *ctxt, struct md_object *pobj,
                       const char *name, struct lu_fid* fid)
 {
-        struct dt_object *dir    = mdd_object_child(md2mdd_obj(pobj));
-        struct dt_rec    *rec    = (struct dt_rec *)fid;
+        struct dt_object    *dir    = mdd_object_child(md2mdd_obj(pobj));
+        struct dt_rec       *rec    = (struct dt_rec *)fid;
         const struct dt_key *key = (const struct dt_key *)name;
         int result;
         ENTRY;
 
-        if (dir->do_index_ops != NULL)
+        if (dt_is_dir(ctxt, dir))
                 result = dir->do_index_ops->dio_lookup(ctxt, dir, rec, key);
         else
                 result = -ENOTDIR;
@@ -975,7 +975,8 @@ static void mdd_device_free(const struct lu_context *ctx, struct lu_device *lu)
         LASSERT(atomic_read(&lu->ld_ref) == 0);
         md_device_fini(&m->mdd_md_dev);
 
-        class_put_type(dt_lov->dd_lu_dev.ld_type->ldt_obd_type);
+        if (dt_lov->dd_lu_dev.ld_type != NULL)
+                class_put_type(dt_lov->dd_lu_dev.ld_type->ldt_obd_type);
 
         OBD_FREE_PTR(m);
 }
index 70ea23b..30201d3 100644 (file)
@@ -129,6 +129,15 @@ void dt_object_fini(struct dt_object *obj)
 }
 EXPORT_SYMBOL(dt_object_fini);
 
+int dt_is_dir(const struct lu_context *ctx, struct dt_object *obj)
+{
+        if (obj->do_index_ops == NULL)
+                obj->do_ops->do_object_index_try(ctx, obj,
+                                                 &dt_directory_features);
+        return obj->do_index_ops != NULL;
+}
+EXPORT_SYMBOL(dt_is_dir);
+
 static int dt_lookup(const struct lu_context *ctx, struct dt_object *dir,
                      const char *name, struct lu_fid *fid)
 {
@@ -136,7 +145,7 @@ static int dt_lookup(const struct lu_context *ctx, struct dt_object *dir,
         const struct dt_key *key = (const struct dt_key *)name;
         int result;
 
-        if (dir->do_index_ops != NULL)
+        if (dt_is_dir(ctx, dir))
                 result = dir->do_index_ops->dio_lookup(ctx, dir, rec, key);
         else
                 result = -ENOTDIR;