Whamcloud - gitweb
b=23289 no need to always start transaction for attr_set(atime) on close
[fs/lustre-release.git] / lustre / obdclass / dt_object.c
index a4bbb9a..3164187 100644 (file)
@@ -26,7 +26,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  */
 /*
@@ -60,7 +60,6 @@ struct dt_find_hint {
 
 struct dt_thread_info {
         char                    dti_buf[DT_MAX_PATH];
-        struct lu_fid_pack      dti_pack;
         struct dt_find_hint     dti_dfh;
 };
 
@@ -79,13 +78,13 @@ static struct lu_context_key dt_key = {
  */
 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb)
 {
-        list_add(&cb->dtc_linkage, &dev->dd_txn_callbacks);
+        cfs_list_add(&cb->dtc_linkage, &dev->dd_txn_callbacks);
 }
 EXPORT_SYMBOL(dt_txn_callback_add);
 
 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb)
 {
-        list_del_init(&cb->dtc_linkage);
+        cfs_list_del_init(&cb->dtc_linkage);
 }
 EXPORT_SYMBOL(dt_txn_callback_del);
 
@@ -96,8 +95,9 @@ int dt_txn_hook_start(const struct lu_env *env,
         struct dt_txn_callback *cb;
 
         result = 0;
-        list_for_each_entry(cb, &dev->dd_txn_callbacks, dtc_linkage) {
-                if (cb->dtc_txn_start == NULL)
+        cfs_list_for_each_entry(cb, &dev->dd_txn_callbacks, dtc_linkage) {
+                if (cb->dtc_txn_start == NULL ||
+                    !(cb->dtc_tag & env->le_ctx.lc_tags))
                         continue;
                 result = cb->dtc_txn_start(env, param, cb->dtc_cookie);
                 if (result < 0)
@@ -114,8 +114,9 @@ int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn)
         int                     result;
 
         result = 0;
-        list_for_each_entry(cb, &dev->dd_txn_callbacks, dtc_linkage) {
-                if (cb->dtc_txn_stop == NULL)
+        cfs_list_for_each_entry(cb, &dev->dd_txn_callbacks, dtc_linkage) {
+                if (cb->dtc_txn_stop == NULL ||
+                    !(cb->dtc_tag & env->le_ctx.lc_tags))
                         continue;
                 result = cb->dtc_txn_stop(env, txn, cb->dtc_cookie);
                 if (result < 0)
@@ -132,8 +133,9 @@ int dt_txn_hook_commit(const struct lu_env *env, struct thandle *txn)
         int                     result;
 
         result = 0;
-        list_for_each_entry(cb, &dev->dd_txn_callbacks, dtc_linkage) {
-                if (cb->dtc_txn_commit == NULL)
+        cfs_list_for_each_entry(cb, &dev->dd_txn_callbacks, dtc_linkage) {
+                if (cb->dtc_txn_commit == NULL ||
+                    !(cb->dtc_tag & env->le_ctx.lc_tags))
                         continue;
                 result = cb->dtc_txn_commit(env, txn, cb->dtc_cookie);
                 if (result < 0)
@@ -214,10 +216,7 @@ EXPORT_SYMBOL(dt_mode_to_dft);
 static int dt_lookup(const struct lu_env *env, struct dt_object *dir,
                      const char *name, struct lu_fid *fid)
 {
-        struct dt_thread_info *info = lu_context_key_get(&env->le_ctx,
-                                                         &dt_key);
-        struct lu_fid_pack *pack = &info->dti_pack;
-        struct dt_rec       *rec = (struct dt_rec *)pack;
+        struct dt_rec       *rec = (struct dt_rec *)fid;
         const struct dt_key *key = (const struct dt_key *)name;
         int result;
 
@@ -225,7 +224,7 @@ static int dt_lookup(const struct lu_env *env, struct dt_object *dir,
                 result = dir->do_index_ops->dio_lookup(env, dir, rec, key,
                                                        BYPASS_CAPA);
                 if (result > 0)
-                        result = fid_unpack(pack, fid);
+                        result = 0;
                 else if (result == 0)
                         result = -ENOENT;
         } else
@@ -313,7 +312,7 @@ static struct dt_object *dt_store_resolve(const struct lu_env *env,
         struct dt_thread_info *info = lu_context_key_get(&env->le_ctx,
                                                          &dt_key);
         struct dt_find_hint *dfh = &info->dti_dfh;
-        struct dt_object     *obj = dfh->dfh_o;
+        struct dt_object     *obj;
         char *local = info->dti_buf;
         int result;
 
@@ -331,6 +330,8 @@ static struct dt_object *dt_store_resolve(const struct lu_env *env,
                         result = dt_path_parser(env, local, dt_find_entry, dfh);
                         if (result != 0)
                                 obj = ERR_PTR(result);
+                        else
+                                obj = dfh->dfh_o;
                 }
         } else {
                 obj = ERR_PTR(result);
@@ -398,5 +399,38 @@ void dt_global_fini(void)
         lu_context_key_degister(&dt_key);
 }
 
+int dt_record_read(const struct lu_env *env, struct dt_object *dt,
+                   struct lu_buf *buf, loff_t *pos)
+{
+        int rc;
+
+        LASSERTF(dt != NULL, "dt is NULL when we want to read record\n");
+
+        rc = dt->do_body_ops->dbo_read(env, dt, buf, pos, BYPASS_CAPA);
+
+        if (rc == buf->lb_len)
+                rc = 0;
+        else if (rc >= 0)
+                rc = -EFAULT;
+        return rc;
+}
+EXPORT_SYMBOL(dt_record_read);
+
+int dt_record_write(const struct lu_env *env, struct dt_object *dt,
+                    const struct lu_buf *buf, loff_t *pos, struct thandle *th)
+{
+        int rc;
+
+        LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
+        LASSERT(th != NULL);
+        rc = dt->do_body_ops->dbo_write(env, dt, buf, pos, th, BYPASS_CAPA, 1);
+        if (rc == buf->lb_len)
+                rc = 0;
+        else if (rc >= 0)
+                rc = -EFAULT;
+        return rc;
+}
+EXPORT_SYMBOL(dt_record_write);
+
 const struct dt_index_features dt_directory_features;
 EXPORT_SYMBOL(dt_directory_features);