Whamcloud - gitweb
LU-6401 headers: Create a header for obdo related functions
[fs/lustre-release.git] / lustre / target / out_handler.c
index 3cb6e83..ab902aa 100644 (file)
@@ -20,7 +20,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright (c) 2013, Intel Corporation.
+ * Copyright (c) 2013, 2015, Intel Corporation.
  *
  * lustre/target/out_handler.c
  *
 
 #define DEBUG_SUBSYSTEM S_CLASS
 
-#include <obd_class.h>
+#include <llog_swab.h>
+#include <lustre_obdo.h>
+#include <lustre_swab.h>
+#include <lustre_update.h>
 #include <md_object.h>
+#include <obd_class.h>
 #include "tgt_internal.h"
-#include <lustre_update.h>
-
-static int tx_extend_args(struct thandle_exec_args *ta, int new_alloc_ta)
-{
-       struct tx_arg   **new_ta;
-       int             i;
-       int             rc = 0;
-
-       if (ta->ta_alloc_args >= new_alloc_ta)
-               return 0;
-
-       OBD_ALLOC(new_ta, sizeof(*new_ta) * new_alloc_ta);
-       if (new_ta == NULL)
-               return -ENOMEM;
-
-       for (i = 0; i < new_alloc_ta; i++) {
-               if (i < ta->ta_alloc_args) {
-                       /* copy the old args to new one */
-                       new_ta[i] = ta->ta_args[i];
-               } else {
-                       OBD_ALLOC_PTR(new_ta[i]);
-                       if (new_ta[i] == NULL)
-                               GOTO(out, rc = -ENOMEM);
-               }
-       }
-
-       /* free the old args */
-       if (ta->ta_args != NULL)
-               OBD_FREE(ta->ta_args, sizeof(ta->ta_args[0]) *
-                                     ta->ta_alloc_args);
-
-       ta->ta_args = new_ta;
-       ta->ta_alloc_args = new_alloc_ta;
-out:
-       if (rc != 0) {
-               for (i = 0; i < new_alloc_ta; i++) {
-                       if (new_ta[i] != NULL)
-                               OBD_FREE_PTR(new_ta[i]);
-               }
-               OBD_FREE(new_ta, sizeof(*new_ta) * new_alloc_ta);
-       }
-       return rc;
-}
-
-#define TX_ALLOC_STEP  8
-static struct tx_arg *tx_add_exec(struct thandle_exec_args *ta,
-                                 tx_exec_func_t func, tx_exec_func_t undo,
-                                 char *file, int line)
-{
-       int rc;
-       int i;
-
-       LASSERT(ta != NULL);
-       LASSERT(func != NULL);
-
-       if (ta->ta_argno + 1 >= ta->ta_alloc_args) {
-               rc = tx_extend_args(ta, ta->ta_alloc_args + TX_ALLOC_STEP);
-               if (rc != 0)
-                       return ERR_PTR(rc);
-       }
-
-       i = ta->ta_argno;
-
-       ta->ta_argno++;
-
-       ta->ta_args[i]->exec_fn = func;
-       ta->ta_args[i]->undo_fn = undo;
-       ta->ta_args[i]->file    = file;
-       ta->ta_args[i]->line    = line;
-
-       return ta->ta_args[i];
-}
 
 static void out_reconstruct(const struct lu_env *env, struct dt_device *dt,
                            struct dt_object *obj,
@@ -137,6 +69,22 @@ static inline int out_check_resent(const struct lu_env *env,
                return 0;
 
        if (req_xid_is_last(req)) {
+               struct lsd_client_data *lcd;
+
+               /* XXX this does not support mulitple transactions yet, i.e.
+                * only 1 update RPC each time betwee MDTs */
+               lcd = req->rq_export->exp_target_data.ted_lcd;
+
+               req->rq_transno = lcd->lcd_last_transno;
+               req->rq_status = lcd->lcd_last_result;
+               if (req->rq_status != 0)
+                       req->rq_transno = 0;
+               lustre_msg_set_transno(req->rq_repmsg, req->rq_transno);
+               lustre_msg_set_status(req->rq_repmsg, req->rq_status);
+
+               DEBUG_REQ(D_RPCTRACE, req, "restoring transno "LPD64"status %d",
+                         req->rq_transno, req->rq_status);
+
                reconstruct(env, dt, obj, reply, index);
                return 1;
        }
@@ -145,101 +93,6 @@ static inline int out_check_resent(const struct lu_env *env,
        return 0;
 }
 
-static int out_obj_destroy(const struct lu_env *env, struct dt_object *dt_obj,
-                          struct thandle *th)
-{
-       int rc;
-
-       CDEBUG(D_INFO, "%s: destroy "DFID"\n", dt_obd_name(th->th_dev),
-              PFID(lu_object_fid(&dt_obj->do_lu)));
-
-       dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
-       rc = dt_destroy(env, dt_obj, th);
-       dt_write_unlock(env, dt_obj);
-
-       return rc;
-}
-
-/**
- * All of the xxx_undo will be used once execution failed,
- * But because all of the required resource has been reserved in
- * declare phase, i.e. if declare succeed, it should make sure
- * the following executing phase succeed in anyway, so these undo
- * should be useless for most of the time in Phase I
- */
-int out_tx_create_undo(const struct lu_env *env, struct thandle *th,
-                      struct tx_arg *arg)
-{
-       int rc;
-
-       rc = out_obj_destroy(env, arg->object, th);
-       if (rc != 0)
-               CERROR("%s: undo failure, we are doomed!: rc = %d\n",
-                      dt_obd_name(th->th_dev), rc);
-       return rc;
-}
-
-int out_tx_create_exec(const struct lu_env *env, struct thandle *th,
-                      struct tx_arg *arg)
-{
-       struct dt_object        *dt_obj = arg->object;
-       int                      rc;
-
-       CDEBUG(D_OTHER, "%s: create "DFID": dof %u, mode %o\n",
-              dt_obd_name(th->th_dev),
-              PFID(lu_object_fid(&arg->object->do_lu)),
-              arg->u.create.dof.dof_type,
-              arg->u.create.attr.la_mode & S_IFMT);
-
-       dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
-       rc = dt_create(env, dt_obj, &arg->u.create.attr,
-                      &arg->u.create.hint, &arg->u.create.dof, th);
-
-       dt_write_unlock(env, dt_obj);
-
-       CDEBUG(D_INFO, "%s: insert create reply %p index %d: rc = %d\n",
-              dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
-
-       object_update_result_insert(arg->reply, NULL, 0, arg->index, rc);
-
-       return rc;
-}
-
-static int __out_tx_create(const struct lu_env *env, struct dt_object *obj,
-                          struct lu_attr *attr, struct lu_fid *parent_fid,
-                          struct dt_object_format *dof,
-                          struct thandle_exec_args *ta,
-                          struct object_update_reply *reply,
-                          int index, char *file, int line)
-{
-       struct tx_arg *arg;
-       int rc;
-
-       LASSERT(ta->ta_handle != NULL);
-       rc = dt_declare_create(env, obj, attr, NULL, dof,
-                                      ta->ta_handle);
-       if (rc != 0)
-               return rc;
-
-       arg = tx_add_exec(ta, out_tx_create_exec, out_tx_create_undo, file,
-                         line);
-       if (IS_ERR(arg))
-               return PTR_ERR(arg);
-
-       /* release the object in out_trans_stop */
-       lu_object_get(&obj->do_lu);
-       arg->object = obj;
-       arg->u.create.attr = *attr;
-       if (parent_fid != NULL)
-               arg->u.create.fid = *parent_fid;
-       memset(&arg->u.create.hint, 0, sizeof(arg->u.create.hint));
-       arg->u.create.dof  = *dof;
-       arg->reply = reply;
-       arg->index = index;
-
-       return 0;
-}
-
 static int out_create(struct tgt_session_info *tsi)
 {
        struct tgt_thread_info  *tti = tgt_th_info(tsi->tsi_env);
@@ -250,16 +103,16 @@ static int out_create(struct tgt_session_info *tsi)
        struct lu_attr          *attr = &tti->tti_attr;
        struct lu_fid           *fid = NULL;
        struct obdo             *wobdo;
-       int                     size;
+       size_t                  size;
        int                     rc;
 
        ENTRY;
 
        wobdo = object_update_param_get(update, 0, &size);
-       if (wobdo == NULL || size != sizeof(*wobdo)) {
-               CERROR("%s: obdo is NULL, invalid RPC: rc = %d\n",
-                      tgt_name(tsi->tsi_tgt), -EPROTO);
-               RETURN(err_serious(-EPROTO));
+       if (IS_ERR(wobdo) || size != sizeof(*wobdo)) {
+               CERROR("%s: obdo is NULL, invalid RPC: rc = %ld\n",
+                      tgt_name(tsi->tsi_tgt), PTR_ERR(wobdo));
+               RETURN(PTR_ERR(wobdo));
        }
 
        if (ptlrpc_req_need_swab(tsi->tsi_pill->rc_req))
@@ -269,20 +122,18 @@ static int out_create(struct tgt_session_info *tsi)
 
        dof->dof_type = dt_mode_to_dft(attr->la_mode);
        if (update->ou_params_count > 1) {
-               int size;
-
                fid = object_update_param_get(update, 1, &size);
-               if (fid == NULL || size != sizeof(*fid)) {
-                       CERROR("%s: invalid fid: rc = %d\n",
-                              tgt_name(tsi->tsi_tgt), -EPROTO);
-                       RETURN(err_serious(-EPROTO));
+               if (IS_ERR(fid) || size != sizeof(*fid)) {
+                       CERROR("%s: invalid fid: rc = %ld\n",
+                              tgt_name(tsi->tsi_tgt), PTR_ERR(fid));
+                       RETURN(PTR_ERR(fid));
                }
                if (ptlrpc_req_need_swab(tsi->tsi_pill->rc_req))
                        lustre_swab_lu_fid(fid);
                if (!fid_is_sane(fid)) {
                        CERROR("%s: invalid fid "DFID": rc = %d\n",
                               tgt_name(tsi->tsi_tgt), PFID(fid), -EPROTO);
-                       RETURN(err_serious(-EPROTO));
+                       RETURN(-EPROTO);
                }
        }
 
@@ -290,72 +141,13 @@ static int out_create(struct tgt_session_info *tsi)
                RETURN(-EEXIST);
 
        rc = out_tx_create(tsi->tsi_env, obj, attr, fid, dof,
-                          &tti->tti_tea,
+                          &tti->tti_tea, tti->tti_tea.ta_handle,
                           tti->tti_u.update.tti_update_reply,
                           tti->tti_u.update.tti_update_reply_index);
 
        RETURN(rc);
 }
 
-static int out_tx_attr_set_undo(const struct lu_env *env,
-                               struct thandle *th, struct tx_arg *arg)
-{
-       CERROR("%s: attr set undo "DFID" unimplemented yet!: rc = %d\n",
-              dt_obd_name(th->th_dev),
-              PFID(lu_object_fid(&arg->object->do_lu)), -ENOTSUPP);
-
-       return -ENOTSUPP;
-}
-
-static int out_tx_attr_set_exec(const struct lu_env *env, struct thandle *th,
-                               struct tx_arg *arg)
-{
-       struct dt_object        *dt_obj = arg->object;
-       int                     rc;
-
-       CDEBUG(D_OTHER, "%s: attr set "DFID"\n", dt_obd_name(th->th_dev),
-              PFID(lu_object_fid(&dt_obj->do_lu)));
-
-       dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
-       rc = dt_attr_set(env, dt_obj, &arg->u.attr_set.attr, th, NULL);
-       dt_write_unlock(env, dt_obj);
-
-       CDEBUG(D_INFO, "%s: insert attr_set reply %p index %d: rc = %d\n",
-              dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
-
-       object_update_result_insert(arg->reply, NULL, 0, arg->index, rc);
-
-       return rc;
-}
-
-static int __out_tx_attr_set(const struct lu_env *env,
-                            struct dt_object *dt_obj,
-                            const struct lu_attr *attr,
-                            struct thandle_exec_args *th,
-                            struct object_update_reply *reply,
-                            int index, char *file, int line)
-{
-       struct tx_arg   *arg;
-       int             rc;
-
-       LASSERT(th->ta_handle != NULL);
-       rc = dt_declare_attr_set(env, dt_obj, attr, th->ta_handle);
-       if (rc != 0)
-               return rc;
-
-       arg = tx_add_exec(th, out_tx_attr_set_exec, out_tx_attr_set_undo,
-                         file, line);
-       if (IS_ERR(arg))
-               return PTR_ERR(arg);
-
-       lu_object_get(&dt_obj->do_lu);
-       arg->object = dt_obj;
-       arg->u.attr_set.attr = *attr;
-       arg->reply = reply;
-       arg->index = index;
-       return 0;
-}
-
 static int out_attr_set(struct tgt_session_info *tsi)
 {
        struct tgt_thread_info  *tti = tgt_th_info(tsi->tsi_env);
@@ -364,16 +156,16 @@ static int out_attr_set(struct tgt_session_info *tsi)
        struct dt_object        *obj = tti->tti_u.update.tti_dt_object;
        struct obdo             *lobdo = &tti->tti_u.update.tti_obdo;
        struct obdo             *wobdo;
-       int                      size;
+       size_t                   size;
        int                      rc;
 
        ENTRY;
 
        wobdo = object_update_param_get(update, 0, &size);
-       if (wobdo == NULL || size != sizeof(*wobdo)) {
-               CERROR("%s: empty obdo in the update: rc = %d\n",
-                      tgt_name(tsi->tsi_tgt), -EPROTO);
-               RETURN(err_serious(-EPROTO));
+       if (IS_ERR(wobdo) || size != sizeof(*wobdo)) {
+               CERROR("%s: empty obdo in the update: rc = %ld\n",
+                      tgt_name(tsi->tsi_tgt), PTR_ERR(wobdo));
+               RETURN(PTR_ERR(wobdo));
        }
 
        attr->la_valid = 0;
@@ -385,6 +177,7 @@ static int out_attr_set(struct tgt_session_info *tsi)
        la_from_obdo(attr, lobdo, lobdo->o_valid);
 
        rc = out_tx_attr_set(tsi->tsi_env, obj, attr, &tti->tti_tea,
+                            tti->tti_tea.ta_handle,
                             tti->tti_u.update.tti_update_reply,
                             tti->tti_u.update.tti_update_reply_index);
 
@@ -395,6 +188,7 @@ static int out_attr_get(struct tgt_session_info *tsi)
 {
        const struct lu_env     *env = tsi->tsi_env;
        struct tgt_thread_info  *tti = tgt_th_info(env);
+       struct object_update    *update = tti->tti_u.update.tti_update;
        struct obdo             *obdo = &tti->tti_u.update.tti_obdo;
        struct lu_attr          *la = &tti->tti_attr;
        struct dt_object        *obj = tti->tti_u.update.tti_dt_object;
@@ -403,6 +197,9 @@ static int out_attr_get(struct tgt_session_info *tsi)
 
        ENTRY;
 
+       if (unlikely(update->ou_result_size < sizeof(*obdo)))
+               return -EPROTO;
+
        if (!lu_object_exists(&obj->do_lu)) {
                /* Usually, this will be called when the master MDT try
                 * to init a remote object(see osp_object_init), so if
@@ -414,45 +211,9 @@ static int out_attr_get(struct tgt_session_info *tsi)
        }
 
        dt_read_lock(env, obj, MOR_TGT_CHILD);
-       rc = dt_attr_get(env, obj, la, NULL);
+       rc = dt_attr_get(env, obj, la);
        if (rc)
                GOTO(out_unlock, rc);
-       /*
-        * If it is a directory, we will also check whether the
-        * directory is empty.
-        * la_flags = 0 : Empty.
-        *          = 1 : Not empty.
-        */
-       la->la_flags = 0;
-       if (S_ISDIR(la->la_mode)) {
-               struct dt_it            *it;
-               const struct dt_it_ops  *iops;
-
-               if (!dt_try_as_dir(env, obj))
-                       GOTO(out_unlock, rc = -ENOTDIR);
-
-               iops = &obj->do_index_ops->dio_it;
-               it = iops->init(env, obj, LUDA_64BITHASH, BYPASS_CAPA);
-               if (!IS_ERR(it)) {
-                       int  result;
-                       result = iops->get(env, it, (const void *)"");
-                       if (result > 0) {
-                               int i;
-                               for (result = 0, i = 0; result == 0 && i < 3;
-                                    ++i)
-                                       result = iops->next(env, it);
-                               if (result == 0)
-                                       la->la_flags = 1;
-                       } else if (result == 0)
-                               /*
-                                * Huh? Index contains no zero key?
-                                */
-                               rc = -EIO;
-
-                       iops->put(env, it);
-                       iops->fini(env, it);
-               }
-       }
 
        obdo->o_valid = 0;
        obdo_from_la(obdo, la, la->la_valid);
@@ -493,36 +254,28 @@ static int out_xattr_get(struct tgt_session_info *tsi)
        }
 
        name = object_update_param_get(update, 0, NULL);
-       if (name == NULL) {
-               CERROR("%s: empty name for xattr get: rc = %d\n",
-                      tgt_name(tsi->tsi_tgt), -EPROTO);
-               RETURN(err_serious(-EPROTO));
+       if (IS_ERR(name)) {
+               CERROR("%s: empty name for xattr get: rc = %ld\n",
+                      tgt_name(tsi->tsi_tgt), PTR_ERR(name));
+               RETURN(PTR_ERR(name));
        }
 
        update_result = object_update_result_get(reply, 0, NULL);
        if (update_result == NULL) {
                CERROR("%s: empty name for xattr get: rc = %d\n",
                       tgt_name(tsi->tsi_tgt), -EPROTO);
-               RETURN(err_serious(-EPROTO));
+               RETURN(-EPROTO);
        }
 
+       lbuf->lb_len = (int)tti->tti_u.update.tti_update->ou_result_size;
        lbuf->lb_buf = update_result->our_data;
-       lbuf->lb_len = OUT_UPDATE_REPLY_SIZE -
-                      cfs_size_round((unsigned long)update_result->our_data -
-                                     (unsigned long)update_result);
+       if (lbuf->lb_len == 0)
+               lbuf->lb_buf = 0;
        dt_read_lock(env, obj, MOR_TGT_CHILD);
-       rc = dt_xattr_get(env, obj, lbuf, name, NULL);
+       rc = dt_xattr_get(env, obj, lbuf, name);
        dt_read_unlock(env, obj);
-       if (rc < 0) {
-               lbuf->lb_len = 0;
-               GOTO(out, rc);
-       }
-       if (rc == 0) {
+       if (rc < 0)
                lbuf->lb_len = 0;
-               GOTO(out, rc = -ENOENT);
-       }
-       lbuf->lb_len = rc;
-       rc = 0;
        CDEBUG(D_INFO, "%s: "DFID" get xattr %s len %d\n",
               tgt_name(tsi->tsi_tgt), PFID(lu_object_fid(&obj->do_lu)),
               name, (int)lbuf->lb_len);
@@ -531,7 +284,7 @@ static int out_xattr_get(struct tgt_session_info *tsi)
 
 out:
        object_update_result_insert(reply, lbuf->lb_buf, lbuf->lb_len, idx, rc);
-       RETURN(rc);
+       RETURN(0);
 }
 
 static int out_index_lookup(struct tgt_session_info *tsi)
@@ -545,14 +298,17 @@ static int out_index_lookup(struct tgt_session_info *tsi)
 
        ENTRY;
 
+       if (unlikely(update->ou_result_size < sizeof(tti->tti_fid1)))
+               return -EPROTO;
+
        if (!lu_object_exists(&obj->do_lu))
                RETURN(-ENOENT);
 
        name = object_update_param_get(update, 0, NULL);
-       if (name == NULL) {
-               CERROR("%s: empty name for lookup: rc = %d\n",
-                      tgt_name(tsi->tsi_tgt), -EPROTO);
-               RETURN(err_serious(-EPROTO));
+       if (IS_ERR(name)) {
+               CERROR("%s: empty name for lookup: rc = %ld\n",
+                      tgt_name(tsi->tsi_tgt), PTR_ERR(name));
+               RETURN(PTR_ERR(name));
        }
 
        dt_read_lock(env, obj, MOR_TGT_CHILD);
@@ -560,7 +316,7 @@ static int out_index_lookup(struct tgt_session_info *tsi)
                GOTO(out_unlock, rc = -ENOTDIR);
 
        rc = dt_lookup(env, obj, (struct dt_rec *)&tti->tti_fid1,
-               (struct dt_key *)name, NULL);
+                      (struct dt_key *)name);
 
        if (rc < 0)
                GOTO(out_unlock, rc);
@@ -585,70 +341,6 @@ out_unlock:
        RETURN(rc);
 }
 
-static int out_tx_xattr_set_exec(const struct lu_env *env,
-                                struct thandle *th,
-                                struct tx_arg *arg)
-{
-       struct dt_object *dt_obj = arg->object;
-       int rc;
-
-       CDEBUG(D_INFO, "%s: set xattr buf %p name %s flag %d\n",
-              dt_obd_name(th->th_dev), arg->u.xattr_set.buf.lb_buf,
-              arg->u.xattr_set.name, arg->u.xattr_set.flags);
-
-       if (!lu_object_exists(&dt_obj->do_lu))
-               GOTO(out, rc = -ENOENT);
-
-       dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
-       rc = dt_xattr_set(env, dt_obj, &arg->u.xattr_set.buf,
-                         arg->u.xattr_set.name, arg->u.xattr_set.flags,
-                         th, NULL);
-       dt_write_unlock(env, dt_obj);
-       /**
-        * Ignore errors if this is LINK EA
-        **/
-       if (unlikely(rc && !strcmp(arg->u.xattr_set.name, XATTR_NAME_LINK)))
-               rc = 0;
-out:
-       CDEBUG(D_INFO, "%s: insert xattr set reply %p index %d: rc = %d\n",
-              dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
-
-       object_update_result_insert(arg->reply, NULL, 0, arg->index, rc);
-
-       return rc;
-}
-
-static int __out_tx_xattr_set(const struct lu_env *env,
-                             struct dt_object *dt_obj,
-                             const struct lu_buf *buf,
-                             const char *name, int flags,
-                             struct thandle_exec_args *ta,
-                             struct object_update_reply *reply,
-                             int index, char *file, int line)
-{
-       struct tx_arg   *arg;
-       int             rc;
-
-       LASSERT(ta->ta_handle != NULL);
-       rc = dt_declare_xattr_set(env, dt_obj, buf, name, flags, ta->ta_handle);
-       if (rc != 0)
-               return rc;
-
-       arg = tx_add_exec(ta, out_tx_xattr_set_exec, NULL, file, line);
-       if (IS_ERR(arg))
-               return PTR_ERR(arg);
-
-       lu_object_get(&dt_obj->do_lu);
-       arg->object = dt_obj;
-       arg->u.xattr_set.name = name;
-       arg->u.xattr_set.flags = flags;
-       arg->u.xattr_set.buf = *buf;
-       arg->reply = reply;
-       arg->index = index;
-       arg->u.xattr_set.csum = 0;
-       return 0;
-}
-
 static int out_xattr_set(struct tgt_session_info *tsi)
 {
        struct tgt_thread_info  *tti = tgt_th_info(tsi->tsi_env);
@@ -658,34 +350,32 @@ static int out_xattr_set(struct tgt_session_info *tsi)
        char                    *name;
        char                    *buf;
        __u32                   *tmp;
-       int                      buf_len = 0;
+       size_t                   buf_len = 0;
        int                      flag;
-       int                      size = 0;
+       size_t                   size = 0;
        int                      rc;
        ENTRY;
 
        name = object_update_param_get(update, 0, NULL);
-       if (name == NULL) {
-               CERROR("%s: empty name for xattr set: rc = %d\n",
-                      tgt_name(tsi->tsi_tgt), -EPROTO);
-               RETURN(err_serious(-EPROTO));
+       if (IS_ERR(name)) {
+               CERROR("%s: empty name for xattr set: rc = %ld\n",
+                      tgt_name(tsi->tsi_tgt), PTR_ERR(name));
+               RETURN(PTR_ERR(name));
        }
 
+       /* If buffer == NULL (-ENODATA), then it might mean delete xattr */
        buf = object_update_param_get(update, 1, &buf_len);
-       if (buf == NULL || buf_len == 0) {
-               CERROR("%s: empty buf for xattr set: rc = %d\n",
-                      tgt_name(tsi->tsi_tgt), -EPROTO);
-               RETURN(err_serious(-EPROTO));
-       }
+       if (IS_ERR(buf) && PTR_ERR(buf) != -ENODATA)
+               RETURN(PTR_ERR(buf));
 
        lbuf->lb_buf = buf;
        lbuf->lb_len = buf_len;
 
        tmp = object_update_param_get(update, 2, &size);
-       if (tmp == NULL || size != sizeof(*tmp)) {
-               CERROR("%s: emptry or wrong size %d flag: rc = %d\n",
-                      tgt_name(tsi->tsi_tgt), size, -EPROTO);
-               RETURN(err_serious(-EPROTO));
+       if (IS_ERR(tmp) || size != sizeof(*tmp)) {
+               CERROR("%s: emptry or wrong size %zu flag: rc = %ld\n",
+                      tgt_name(tsi->tsi_tgt), size, PTR_ERR(tmp));
+               RETURN(PTR_ERR(tmp));
        }
 
        if (ptlrpc_req_need_swab(tsi->tsi_pill->rc_req))
@@ -693,83 +383,33 @@ static int out_xattr_set(struct tgt_session_info *tsi)
        flag = *tmp;
 
        rc = out_tx_xattr_set(tsi->tsi_env, obj, lbuf, name, flag,
-                             &tti->tti_tea,
+                             &tti->tti_tea, tti->tti_tea.ta_handle,
                              tti->tti_u.update.tti_update_reply,
                              tti->tti_u.update.tti_update_reply_index);
        RETURN(rc);
 }
 
-static int out_obj_ref_add(const struct lu_env *env,
-                          struct dt_object *dt_obj,
-                          struct thandle *th)
-{
-       int rc;
-
-       dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
-       rc = dt_ref_add(env, dt_obj, th);
-       dt_write_unlock(env, dt_obj);
-
-       return rc;
-}
-
-static int out_obj_ref_del(const struct lu_env *env,
-                          struct dt_object *dt_obj,
-                          struct thandle *th)
-{
-       int rc;
-
-       dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
-       rc = dt_ref_del(env, dt_obj, th);
-       dt_write_unlock(env, dt_obj);
-
-       return rc;
-}
-
-static int out_tx_ref_add_exec(const struct lu_env *env, struct thandle *th,
-                              struct tx_arg *arg)
-{
-       struct dt_object *dt_obj = arg->object;
-       int rc;
-
-       rc = out_obj_ref_add(env, dt_obj, th);
-
-       CDEBUG(D_INFO, "%s: insert ref_add reply %p index %d: rc = %d\n",
-              dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
-
-       object_update_result_insert(arg->reply, NULL, 0, arg->index, rc);
-       return rc;
-}
-
-static int out_tx_ref_add_undo(const struct lu_env *env, struct thandle *th,
-                              struct tx_arg *arg)
-{
-       return out_obj_ref_del(env, arg->object, th);
-}
-
-static int __out_tx_ref_add(const struct lu_env *env,
-                           struct dt_object *dt_obj,
-                           struct thandle_exec_args *ta,
-                           struct object_update_reply *reply,
-                           int index, char *file, int line)
+static int out_xattr_del(struct tgt_session_info *tsi)
 {
-       struct tx_arg   *arg;
-       int             rc;
-
-       LASSERT(ta->ta_handle != NULL);
-       rc = dt_declare_ref_add(env, dt_obj, ta->ta_handle);
-       if (rc != 0)
-               return rc;
+       struct tgt_thread_info  *tti = tgt_th_info(tsi->tsi_env);
+       struct object_update    *update = tti->tti_u.update.tti_update;
+       struct dt_object        *obj = tti->tti_u.update.tti_dt_object;
+       char                    *name;
+       int                      rc;
+       ENTRY;
 
-       arg = tx_add_exec(ta, out_tx_ref_add_exec, out_tx_ref_add_undo, file,
-                         line);
-       if (IS_ERR(arg))
-               return PTR_ERR(arg);
+       name = object_update_param_get(update, 0, NULL);
+       if (IS_ERR(name)) {
+               CERROR("%s: empty name for xattr set: rc = %ld\n",
+                      tgt_name(tsi->tsi_tgt), PTR_ERR(name));
+               RETURN(PTR_ERR(name));
+       }
 
-       lu_object_get(&dt_obj->do_lu);
-       arg->object = dt_obj;
-       arg->reply = reply;
-       arg->index = index;
-       return 0;
+       rc = out_tx_xattr_del(tsi->tsi_env, obj, name, &tti->tti_tea,
+                             tti->tti_tea.ta_handle,
+                             tti->tti_u.update.tti_update_reply,
+                             tti->tti_u.update.tti_update_reply_index);
+       RETURN(rc);
 }
 
 /**
@@ -784,59 +424,12 @@ static int out_ref_add(struct tgt_session_info *tsi)
        ENTRY;
 
        rc = out_tx_ref_add(tsi->tsi_env, obj, &tti->tti_tea,
+                           tti->tti_tea.ta_handle,
                            tti->tti_u.update.tti_update_reply,
                            tti->tti_u.update.tti_update_reply_index);
        RETURN(rc);
 }
 
-static int out_tx_ref_del_exec(const struct lu_env *env, struct thandle *th,
-                              struct tx_arg *arg)
-{
-       struct dt_object        *dt_obj = arg->object;
-       int                      rc;
-
-       rc = out_obj_ref_del(env, dt_obj, th);
-
-       CDEBUG(D_INFO, "%s: insert ref_del reply %p index %d: rc = %d\n",
-              dt_obd_name(th->th_dev), arg->reply, arg->index, 0);
-
-       object_update_result_insert(arg->reply, NULL, 0, arg->index, rc);
-
-       return rc;
-}
-
-static int out_tx_ref_del_undo(const struct lu_env *env, struct thandle *th,
-                              struct tx_arg *arg)
-{
-       return out_obj_ref_add(env, arg->object, th);
-}
-
-static int __out_tx_ref_del(const struct lu_env *env,
-                           struct dt_object *dt_obj,
-                           struct thandle_exec_args *ta,
-                           struct object_update_reply *reply,
-                           int index, char *file, int line)
-{
-       struct tx_arg   *arg;
-       int             rc;
-
-       LASSERT(ta->ta_handle != NULL);
-       rc = dt_declare_ref_del(env, dt_obj, ta->ta_handle);
-       if (rc != 0)
-               return rc;
-
-       arg = tx_add_exec(ta, out_tx_ref_del_exec, out_tx_ref_del_undo, file,
-                         line);
-       if (IS_ERR(arg))
-               return PTR_ERR(arg);
-
-       lu_object_get(&dt_obj->do_lu);
-       arg->object = dt_obj;
-       arg->reply = reply;
-       arg->index = index;
-       return 0;
-}
-
 static int out_ref_del(struct tgt_session_info *tsi)
 {
        struct tgt_thread_info  *tti = tgt_th_info(tsi->tsi_env);
@@ -849,137 +442,37 @@ static int out_ref_del(struct tgt_session_info *tsi)
                RETURN(-ENOENT);
 
        rc = out_tx_ref_del(tsi->tsi_env, obj, &tti->tti_tea,
+                           tti->tti_tea.ta_handle,
                            tti->tti_u.update.tti_update_reply,
                            tti->tti_u.update.tti_update_reply_index);
        RETURN(rc);
 }
 
-static int out_obj_index_insert(const struct lu_env *env,
-                               struct dt_object *dt_obj,
-                               const struct dt_rec *rec,
-                               const struct dt_key *key,
-                               struct thandle *th)
-{
-       int rc;
-
-       CDEBUG(D_INFO, "%s: index insert "DFID" name: %s fid "DFID"\n",
-              dt_obd_name(th->th_dev), PFID(lu_object_fid(&dt_obj->do_lu)),
-              (char *)key, PFID((struct lu_fid *)rec));
-
-       if (dt_try_as_dir(env, dt_obj) == 0)
-               return -ENOTDIR;
-
-       dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
-       rc = dt_insert(env, dt_obj, rec, key, th, NULL, 0);
-       dt_write_unlock(env, dt_obj);
-
-       return rc;
-}
-
-static int out_obj_index_delete(const struct lu_env *env,
-                               struct dt_object *dt_obj,
-                               const struct dt_key *key,
-                               struct thandle *th)
-{
-       int rc;
-
-       CDEBUG(D_INFO, "%s: index delete "DFID" name: %s\n",
-              dt_obd_name(th->th_dev), PFID(lu_object_fid(&dt_obj->do_lu)),
-              (char *)key);
-
-       if (dt_try_as_dir(env, dt_obj) == 0)
-               return -ENOTDIR;
-
-       dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
-       rc = dt_delete(env, dt_obj, key, th, NULL);
-       dt_write_unlock(env, dt_obj);
-
-       return rc;
-}
-
-static int out_tx_index_insert_exec(const struct lu_env *env,
-                                   struct thandle *th, struct tx_arg *arg)
-{
-       struct dt_object *dt_obj = arg->object;
-       int rc;
-
-       rc = out_obj_index_insert(env, dt_obj, arg->u.insert.rec,
-                                 arg->u.insert.key, th);
-
-       CDEBUG(D_INFO, "%s: insert idx insert reply %p index %d: rc = %d\n",
-              dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
-
-       object_update_result_insert(arg->reply, NULL, 0, arg->index, rc);
-
-       return rc;
-}
-
-static int out_tx_index_insert_undo(const struct lu_env *env,
-                                   struct thandle *th, struct tx_arg *arg)
-{
-       return out_obj_index_delete(env, arg->object, arg->u.insert.key, th);
-}
-
-static int __out_tx_index_insert(const struct lu_env *env,
-                                struct dt_object *dt_obj,
-                                char *name, struct lu_fid *fid,
-                                struct thandle_exec_args *ta,
-                                struct object_update_reply *reply,
-                                int index, char *file, int line)
-{
-       struct tx_arg   *arg;
-       int             rc;
-
-       LASSERT(ta->ta_handle != NULL);
-       if (dt_try_as_dir(env, dt_obj) == 0) {
-               rc = -ENOTDIR;
-               return rc;
-       }
-
-       rc = dt_declare_insert(env, dt_obj, (struct dt_rec *)fid,
-                              (struct dt_key *)name, ta->ta_handle);
-       if (rc != 0)
-               return rc;
-
-       arg = tx_add_exec(ta, out_tx_index_insert_exec,
-                         out_tx_index_insert_undo, file, line);
-       if (IS_ERR(arg))
-               return PTR_ERR(arg);
-
-       lu_object_get(&dt_obj->do_lu);
-       arg->object = dt_obj;
-       arg->reply = reply;
-       arg->index = index;
-       arg->u.insert.rec = (struct dt_rec *)fid;
-       arg->u.insert.key = (struct dt_key *)name;
-
-       return 0;
-}
-
 static int out_index_insert(struct tgt_session_info *tsi)
 {
-       struct tgt_thread_info  *tti = tgt_th_info(tsi->tsi_env);
-       struct object_update    *update = tti->tti_u.update.tti_update;
-       struct dt_object  *obj = tti->tti_u.update.tti_dt_object;
-       struct lu_fid     *fid;
-       char              *name;
-       int                rc = 0;
-       int                size;
-
+       struct tgt_thread_info  *tti    = tgt_th_info(tsi->tsi_env);
+       struct object_update    *update = tti->tti_u.update.tti_update;
+       struct dt_object        *obj    = tti->tti_u.update.tti_dt_object;
+       struct dt_insert_rec    *rec    = &tti->tti_rec;
+       struct lu_fid           *fid;
+       char                    *name;
+       __u32                   *ptype;
+       int                      rc     = 0;
+       size_t                   size;
        ENTRY;
 
        name = object_update_param_get(update, 0, NULL);
-       if (name == NULL) {
-               CERROR("%s: empty name for index insert: rc = %d\n",
-                      tgt_name(tsi->tsi_tgt), -EPROTO);
-               RETURN(err_serious(-EPROTO));
+       if (IS_ERR(name)) {
+               CERROR("%s: empty name for index insert: rc = %ld\n",
+                      tgt_name(tsi->tsi_tgt), PTR_ERR(name));
+               RETURN(PTR_ERR(name));
        }
 
        fid = object_update_param_get(update, 1, &size);
-       if (fid == NULL || size != sizeof(*fid)) {
-               CERROR("%s: invalid fid: rc = %d\n",
-                      tgt_name(tsi->tsi_tgt), -EPROTO);
-                      RETURN(err_serious(-EPROTO));
+       if (IS_ERR(fid) || size != sizeof(*fid)) {
+               CERROR("%s: invalid fid: rc = %ld\n",
+                      tgt_name(tsi->tsi_tgt), PTR_ERR(fid));
+               RETURN(PTR_ERR(fid));
        }
 
        if (ptlrpc_req_need_swab(tsi->tsi_pill->rc_req))
@@ -988,72 +481,28 @@ static int out_index_insert(struct tgt_session_info *tsi)
        if (!fid_is_sane(fid)) {
                CERROR("%s: invalid FID "DFID": rc = %d\n",
                       tgt_name(tsi->tsi_tgt), PFID(fid), -EPROTO);
-               RETURN(err_serious(-EPROTO));
+               RETURN(-EPROTO);
        }
 
-       rc = out_tx_index_insert(tsi->tsi_env, obj, name, fid,
-                                &tti->tti_tea,
-                                tti->tti_u.update.tti_update_reply,
-                                tti->tti_u.update.tti_update_reply_index);
-       RETURN(rc);
-}
-
-static int out_tx_index_delete_exec(const struct lu_env *env,
-                                   struct thandle *th,
-                                   struct tx_arg *arg)
-{
-       int rc;
-
-       rc = out_obj_index_delete(env, arg->object, arg->u.insert.key, th);
-
-       CDEBUG(D_INFO, "%s: insert idx insert reply %p index %d: rc = %d\n",
-              dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
-
-       object_update_result_insert(arg->reply, NULL, 0, arg->index, rc);
-
-       return rc;
-}
-
-static int out_tx_index_delete_undo(const struct lu_env *env,
-                                   struct thandle *th,
-                                   struct tx_arg *arg)
-{
-       CERROR("%s: Oops, can not rollback index_delete yet: rc = %d\n",
-              dt_obd_name(th->th_dev), -ENOTSUPP);
-       return -ENOTSUPP;
-}
-
-static int __out_tx_index_delete(const struct lu_env *env,
-                                struct dt_object *dt_obj, char *name,
-                                struct thandle_exec_args *ta,
-                                struct object_update_reply *reply,
-                                int index, char *file, int line)
-{
-       struct tx_arg   *arg;
-       int             rc;
-
-       if (dt_try_as_dir(env, dt_obj) == 0) {
-               rc = -ENOTDIR;
-               return rc;
+       ptype = object_update_param_get(update, 2, &size);
+       if (IS_ERR(ptype) || size != sizeof(*ptype)) {
+               CERROR("%s: invalid type for index insert: rc = %ld\n",
+                      tgt_name(tsi->tsi_tgt), PTR_ERR(ptype));
+               RETURN(PTR_ERR(ptype));
        }
 
-       LASSERT(ta->ta_handle != NULL);
-       rc = dt_declare_delete(env, dt_obj, (struct dt_key *)name,
-                              ta->ta_handle);
-       if (rc != 0)
-               return rc;
+       if (ptlrpc_req_need_swab(tsi->tsi_pill->rc_req))
+               __swab32s(ptype);
 
-       arg = tx_add_exec(ta, out_tx_index_delete_exec,
-                         out_tx_index_delete_undo, file, line);
-       if (IS_ERR(arg))
-               return PTR_ERR(arg);
+       rec->rec_fid = fid;
+       rec->rec_type = *ptype;
 
-       lu_object_get(&dt_obj->do_lu);
-       arg->object = dt_obj;
-       arg->reply = reply;
-       arg->index = index;
-       arg->u.insert.key = (struct dt_key *)name;
-       return 0;
+       rc = out_tx_index_insert(tsi->tsi_env, obj, (const struct dt_rec *)rec,
+                                (const struct dt_key *)name, &tti->tti_tea,
+                                tti->tti_tea.ta_handle,
+                                tti->tti_u.update.tti_update_reply,
+                                tti->tti_u.update.tti_update_reply_index);
+       RETURN(rc);
 }
 
 static int out_index_delete(struct tgt_session_info *tsi)
@@ -1068,67 +517,19 @@ static int out_index_delete(struct tgt_session_info *tsi)
                RETURN(-ENOENT);
 
        name = object_update_param_get(update, 0, NULL);
-       if (name == NULL) {
-               CERROR("%s: empty name for index delete: rc = %d\n",
-                      tgt_name(tsi->tsi_tgt), -EPROTO);
-               RETURN(err_serious(-EPROTO));
+       if (IS_ERR(name)) {
+               CERROR("%s: empty name for index delete: rc = %ld\n",
+                      tgt_name(tsi->tsi_tgt), PTR_ERR(name));
+               RETURN(PTR_ERR(name));
        }
 
-       rc = out_tx_index_delete(tsi->tsi_env, obj, name, &tti->tti_tea,
+       rc = out_tx_index_delete(tsi->tsi_env, obj, (const struct dt_key *)name,
+                                &tti->tti_tea, tti->tti_tea.ta_handle,
                                 tti->tti_u.update.tti_update_reply,
                                 tti->tti_u.update.tti_update_reply_index);
        RETURN(rc);
 }
 
-static int out_tx_destroy_exec(const struct lu_env *env, struct thandle *th,
-                              struct tx_arg *arg)
-{
-       struct dt_object *dt_obj = arg->object;
-       int rc;
-
-       rc = out_obj_destroy(env, dt_obj, th);
-
-       CDEBUG(D_INFO, "%s: insert destroy reply %p index %d: rc = %d\n",
-              dt_obd_name(th->th_dev), arg->reply, arg->index, rc);
-
-       object_update_result_insert(arg->reply, NULL, 0, arg->index, rc);
-
-       RETURN(rc);
-}
-
-static int out_tx_destroy_undo(const struct lu_env *env, struct thandle *th,
-                              struct tx_arg *arg)
-{
-       CERROR("%s: not support destroy undo yet!: rc = %d\n",
-              dt_obd_name(th->th_dev), -ENOTSUPP);
-       return -ENOTSUPP;
-}
-
-static int __out_tx_destroy(const struct lu_env *env, struct dt_object *dt_obj,
-                            struct thandle_exec_args *ta,
-                            struct object_update_reply *reply,
-                            int index, char *file, int line)
-{
-       struct tx_arg   *arg;
-       int             rc;
-
-       LASSERT(ta->ta_handle != NULL);
-       rc = dt_declare_destroy(env, dt_obj, ta->ta_handle);
-       if (rc != 0)
-               return rc;
-
-       arg = tx_add_exec(ta, out_tx_destroy_exec, out_tx_destroy_undo,
-                         file, line);
-       if (IS_ERR(arg))
-               return PTR_ERR(arg);
-
-       lu_object_get(&dt_obj->do_lu);
-       arg->object = dt_obj;
-       arg->reply = reply;
-       arg->index = index;
-       return 0;
-}
-
 static int out_destroy(struct tgt_session_info *tsi)
 {
        struct tgt_thread_info  *tti = tgt_th_info(tsi->tsi_env);
@@ -1142,66 +543,20 @@ static int out_destroy(struct tgt_session_info *tsi)
        if (!fid_is_sane(fid)) {
                CERROR("%s: invalid FID "DFID": rc = %d\n",
                       tgt_name(tsi->tsi_tgt), PFID(fid), -EPROTO);
-               RETURN(err_serious(-EPROTO));
+               RETURN(-EPROTO);
        }
 
        if (!lu_object_exists(&obj->do_lu))
                RETURN(-ENOENT);
 
        rc = out_tx_destroy(tsi->tsi_env, obj, &tti->tti_tea,
+                           tti->tti_tea.ta_handle,
                            tti->tti_u.update.tti_update_reply,
                            tti->tti_u.update.tti_update_reply_index);
 
        RETURN(rc);
 }
 
-static int out_tx_write_exec(const struct lu_env *env, struct thandle *th,
-                            struct tx_arg *arg)
-{
-       struct dt_object *dt_obj = arg->object;
-       int rc;
-
-       dt_write_lock(env, dt_obj, MOR_TGT_CHILD);
-       rc = dt_record_write(env, dt_obj, &arg->u.write.buf,
-                            &arg->u.write.pos, th);
-       dt_write_unlock(env, dt_obj);
-
-       if (rc == 0)
-               rc = arg->u.write.buf.lb_len;
-
-       object_update_result_insert(arg->reply, NULL, 0, arg->index, rc);
-
-       return rc > 0 ? 0 : rc;
-}
-
-static int __out_tx_write(const struct lu_env *env,
-                         struct dt_object *dt_obj,
-                         const struct lu_buf *buf,
-                         loff_t pos, struct thandle_exec_args *ta,
-                         struct object_update_reply *reply,
-                         int index, char *file, int line)
-{
-       struct tx_arg   *arg;
-       int             rc;
-
-       LASSERT(ta->ta_handle != NULL);
-       rc = dt_declare_record_write(env, dt_obj, buf, pos, ta->ta_handle);
-       if (rc != 0)
-               return rc;
-
-       arg = tx_add_exec(ta, out_tx_write_exec, NULL, file, line);
-       if (IS_ERR(arg))
-               return PTR_ERR(arg);
-
-       lu_object_get(&dt_obj->do_lu);
-       arg->object = dt_obj;
-       arg->u.write.buf = *buf;
-       arg->u.write.pos = pos;
-       arg->reply = reply;
-       arg->index = index;
-       return 0;
-}
-
 static int out_write(struct tgt_session_info *tsi)
 {
        struct tgt_thread_info  *tti = tgt_th_info(tsi->tsi_env);
@@ -1210,26 +565,26 @@ static int out_write(struct tgt_session_info *tsi)
        struct lu_buf           *lbuf = &tti->tti_buf;
        char                    *buf;
        __u64                   *tmp;
-       int                     size = 0;
-       int                     buf_len = 0;
+       size_t                  size = 0;
+       size_t                  buf_len = 0;
        loff_t                  pos;
        int                      rc;
        ENTRY;
 
        buf = object_update_param_get(update, 0, &buf_len);
-       if (buf == NULL || buf_len == 0) {
-               CERROR("%s: empty buf for xattr set: rc = %d\n",
-                      tgt_name(tsi->tsi_tgt), -EPROTO);
-               RETURN(err_serious(-EPROTO));
+       if (IS_ERR(buf) || buf_len == 0) {
+               CERROR("%s: empty buf for xattr set: rc = %ld\n",
+                      tgt_name(tsi->tsi_tgt), PTR_ERR(buf));
+               RETURN(PTR_ERR(buf));
        }
        lbuf->lb_buf = buf;
        lbuf->lb_len = buf_len;
 
        tmp = object_update_param_get(update, 1, &size);
-       if (tmp == NULL || size != sizeof(*tmp)) {
-               CERROR("%s: empty or wrong size %d pos: rc = %d\n",
-                      tgt_name(tsi->tsi_tgt), size, -EPROTO);
-               RETURN(err_serious(-EPROTO));
+       if (IS_ERR(tmp) || size != sizeof(*tmp)) {
+               CERROR("%s: empty or wrong size %zu pos: rc = %ld\n",
+                      tgt_name(tsi->tsi_tgt), size, PTR_ERR(tmp));
+               RETURN(PTR_ERR(tmp));
        }
 
        if (ptlrpc_req_need_swab(tsi->tsi_pill->rc_req))
@@ -1237,12 +592,120 @@ static int out_write(struct tgt_session_info *tsi)
        pos = *tmp;
 
        rc = out_tx_write(tsi->tsi_env, obj, lbuf, pos,
-                         &tti->tti_tea,
+                         &tti->tti_tea, tti->tti_tea.ta_handle,
                          tti->tti_u.update.tti_update_reply,
                          tti->tti_u.update.tti_update_reply_index);
        RETURN(rc);
 }
 
+static int out_read(struct tgt_session_info *tsi)
+{
+       const struct lu_env     *env = tsi->tsi_env;
+       struct tgt_thread_info  *tti = tgt_th_info(env);
+       struct object_update    *update = tti->tti_u.update.tti_update;
+       struct dt_object        *obj = tti->tti_u.update.tti_dt_object;
+       struct object_update_reply *reply = tti->tti_u.update.tti_update_reply;
+       int index = tti->tti_u.update.tti_update_reply_index;
+       struct lu_rdbuf *rdbuf;
+       struct object_update_result *update_result;
+       struct out_read_reply   *orr;
+       void *tmp;
+       size_t size;
+       size_t total_size = 0;
+       __u64 pos;
+       unsigned int i;
+       unsigned int nbufs;
+       int rc = 0;
+       ENTRY;
+
+       update_result = object_update_result_get(reply, index, NULL);
+       LASSERT(update_result != NULL);
+       update_result->our_datalen = sizeof(*orr);
+
+       if (!lu_object_exists(&obj->do_lu))
+               GOTO(out, rc = -ENOENT);
+
+       tmp = object_update_param_get(update, 0, NULL);
+       if (IS_ERR(tmp)) {
+               CERROR("%s: empty size for read: rc = %ld\n",
+                      tgt_name(tsi->tsi_tgt), PTR_ERR(tmp));
+               GOTO(out, rc = PTR_ERR(tmp));
+       }
+       size = le64_to_cpu(*(size_t *)(tmp));
+
+       tmp = object_update_param_get(update, 1, NULL);
+       if (IS_ERR(tmp)) {
+               CERROR("%s: empty pos for read: rc = %ld\n",
+                      tgt_name(tsi->tsi_tgt), PTR_ERR(tmp));
+               GOTO(out, rc = PTR_ERR(tmp));
+       }
+       pos = le64_to_cpu(*(__u64 *)(tmp));
+
+       /* Put the offset into the begining of the buffer in reply */
+       orr = (struct out_read_reply *)update_result->our_data;
+
+       nbufs = (size + OUT_BULK_BUFFER_SIZE - 1) / OUT_BULK_BUFFER_SIZE;
+       OBD_ALLOC(rdbuf, sizeof(struct lu_rdbuf) +
+                        nbufs * sizeof(rdbuf->rb_bufs[0]));
+       if (rdbuf == NULL)
+               GOTO(out, rc = -ENOMEM);
+
+       rdbuf->rb_nbufs = 0;
+       total_size = 0;
+       for (i = 0; i < nbufs; i++) {
+               __u32 read_size;
+
+               read_size = size > OUT_BULK_BUFFER_SIZE ?
+                           OUT_BULK_BUFFER_SIZE : size;
+               OBD_ALLOC(rdbuf->rb_bufs[i].lb_buf, read_size);
+               if (rdbuf->rb_bufs[i].lb_buf == NULL)
+                       GOTO(out_free, rc = -ENOMEM);
+
+               rdbuf->rb_bufs[i].lb_len = read_size;
+               dt_read_lock(env, obj, MOR_TGT_CHILD);
+               rc = dt_read(env, obj, &rdbuf->rb_bufs[i], &pos);
+               dt_read_unlock(env, obj);
+
+               total_size += rc < 0 ? 0 : rc;
+               if (rc <= 0)
+                       break;
+
+               rdbuf->rb_nbufs++;
+               size -= read_size;
+       }
+
+       /* send pages to client */
+       rc = tgt_send_buffer(tsi, rdbuf);
+       if (rc < 0)
+               GOTO(out_free, rc);
+
+       orr->orr_size = total_size;
+       orr->orr_offset = pos;
+
+       orr_cpu_to_le(orr, orr);
+       update_result->our_datalen += orr->orr_size;
+out_free:
+       for (i = 0; i < nbufs; i++) {
+               if (rdbuf->rb_bufs[i].lb_buf != NULL) {
+                       OBD_FREE(rdbuf->rb_bufs[i].lb_buf,
+                                rdbuf->rb_bufs[i].lb_len);
+               }
+       }
+       OBD_FREE(rdbuf, sizeof(struct lu_rdbuf) +
+                       nbufs * sizeof(rdbuf->rb_bufs[0]));
+out:
+       /* Insert read buffer */
+       update_result->our_rc = ptlrpc_status_hton(rc);
+       reply->ourp_lens[index] = cfs_size_round(update_result->our_datalen +
+                                                sizeof(*update_result));
+       RETURN(rc);
+}
+
+static int out_noop(struct tgt_session_info *tsi)
+{
+       return 0;
+}
+
 #define DEF_OUT_HNDL(opc, name, flags, fn)     \
 [opc - OUT_CREATE] = {                                 \
        .th_name    = name,                             \
@@ -1254,7 +717,6 @@ static int out_write(struct tgt_session_info *tsi)
        .th_version = 0,                                \
 }
 
-#define out_handler mdt_handler
 static struct tgt_handler out_update_ops[] = {
        DEF_OUT_HNDL(OUT_CREATE, "out_create", MUTABOR | HABEO_REFERO,
                     out_create),
@@ -1270,6 +732,8 @@ static struct tgt_handler out_update_ops[] = {
                     out_attr_get),
        DEF_OUT_HNDL(OUT_XATTR_SET, "out_xattr_set", MUTABOR | HABEO_REFERO,
                     out_xattr_set),
+       DEF_OUT_HNDL(OUT_XATTR_DEL, "out_xattr_del", MUTABOR | HABEO_REFERO,
+                    out_xattr_del),
        DEF_OUT_HNDL(OUT_XATTR_GET, "out_xattr_get", HABEO_REFERO,
                     out_xattr_get),
        DEF_OUT_HNDL(OUT_INDEX_LOOKUP, "out_index_lookup", HABEO_REFERO,
@@ -1279,9 +743,11 @@ static struct tgt_handler out_update_ops[] = {
        DEF_OUT_HNDL(OUT_INDEX_DELETE, "out_index_delete",
                     MUTABOR | HABEO_REFERO, out_index_delete),
        DEF_OUT_HNDL(OUT_WRITE, "out_write", MUTABOR | HABEO_REFERO, out_write),
+       DEF_OUT_HNDL(OUT_READ, "out_read", HABEO_REFERO, out_read),
+       DEF_OUT_HNDL(OUT_NOOP, "out_noop", HABEO_REFERO, out_noop),
 };
 
-struct tgt_handler *out_handler_find(__u32 opc)
+static struct tgt_handler *out_handler_find(__u32 opc)
 {
        struct tgt_handler *h;
 
@@ -1299,7 +765,7 @@ struct tgt_handler *out_handler_find(__u32 opc)
 static int out_tx_start(const struct lu_env *env, struct dt_device *dt,
                        struct thandle_exec_args *ta, struct obd_export *exp)
 {
-       memset(ta, 0, sizeof(*ta));
+       ta->ta_argno = 0;
        ta->ta_handle = dt_trans_create(env, dt);
        if (IS_ERR(ta->ta_handle)) {
                int rc;
@@ -1346,12 +812,14 @@ static int out_trans_stop(const struct lu_env *env,
                        ta->ta_args[i]->object = NULL;
                }
        }
+       ta->ta_handle = NULL;
+       ta->ta_argno = 0;
 
        return rc;
 }
 
-int out_tx_end(const struct lu_env *env, struct thandle_exec_args *ta,
-              int declare_ret)
+static int out_tx_end(const struct lu_env *env, struct thandle_exec_args *ta,
+                     int declare_ret)
 {
        struct tgt_session_info *tsi = tgt_ses_info(env);
        int                     i;
@@ -1394,8 +862,13 @@ int out_tx_end(const struct lu_env *env, struct thandle_exec_args *ta,
                       dt_obd_name(ta->ta_handle->th_dev), i, ta->ta_argno, rc);
        }
 
-       /* Only fail for real update */
-       tsi->tsi_reply_fail_id = OBD_FAIL_OUT_UPDATE_NET_REP;
+       /* Only fail for real updates, XXX right now llog updates will be
+       * ignore, whose updates count is usually 1, so failover test
+       * case will spot this FAIL_UPDATE_NET_REP precisely, and it will
+       * be removed after async update patch is landed. */
+       if (ta->ta_argno > 1)
+               tsi->tsi_reply_fail_id = OBD_FAIL_OUT_UPDATE_NET_REP;
+
 stop:
        rc1 = out_trans_stop(env, ta, rc);
        if (rc == 0)
@@ -1425,146 +898,245 @@ int out_handle(struct tgt_session_info *tsi)
        struct thandle_exec_args        *ta = &tti->tti_tea;
        struct req_capsule              *pill = tsi->tsi_pill;
        struct dt_device                *dt = tsi->tsi_tgt->lut_bottom;
-       struct object_update_request    *ureq;
+       struct out_update_header        *ouh;
+       struct out_update_buffer        *oub = NULL;
        struct object_update            *update;
        struct object_update_reply      *reply;
-       int                              bufsize;
-       int                              count;
-       int                              current_batchid = -1;
-       int                              i;
-       int                              rc = 0;
-       int                              rc1 = 0;
-
+       struct ptlrpc_bulk_desc         *desc = NULL;
+       struct l_wait_info              lwi;
+       void                            **update_bufs;
+       int                             current_batchid = -1;
+       __u32                           update_buf_count;
+       unsigned int                    i;
+       unsigned int                    reply_index = 0;
+       int                             rc = 0;
+       int                             rc1 = 0;
+       int                             ouh_size, reply_size;
+       int                             updates;
        ENTRY;
 
        req_capsule_set(pill, &RQF_OUT_UPDATE);
-       ureq = req_capsule_client_get(pill, &RMF_OUT_UPDATE);
-       if (ureq == NULL) {
-               CERROR("%s: No buf!: rc = %d\n", tgt_name(tsi->tsi_tgt),
-                      -EPROTO);
+       ouh_size = req_capsule_get_size(pill, &RMF_OUT_UPDATE_HEADER,
+                                       RCL_CLIENT);
+       if (ouh_size <= 0)
                RETURN(err_serious(-EPROTO));
-       }
 
-       bufsize = req_capsule_get_size(pill, &RMF_OUT_UPDATE, RCL_CLIENT);
-       if (bufsize != object_update_request_size(ureq)) {
-               CERROR("%s: invalid bufsize %d: rc = %d\n",
-                      tgt_name(tsi->tsi_tgt), bufsize, -EPROTO);
+       ouh = req_capsule_client_get(pill, &RMF_OUT_UPDATE_HEADER);
+       if (ouh == NULL)
                RETURN(err_serious(-EPROTO));
-       }
 
-       if (ureq->ourq_magic != UPDATE_REQUEST_MAGIC) {
+       if (ouh->ouh_magic != OUT_UPDATE_HEADER_MAGIC) {
                CERROR("%s: invalid update buffer magic %x expect %x: "
-                      "rc = %d\n", tgt_name(tsi->tsi_tgt), ureq->ourq_magic,
+                      "rc = %d\n", tgt_name(tsi->tsi_tgt), ouh->ouh_magic,
                       UPDATE_REQUEST_MAGIC, -EPROTO);
                RETURN(err_serious(-EPROTO));
        }
 
-       count = ureq->ourq_count;
-       if (count <= 0) {
-               CERROR("%s: empty update: rc = %d\n", tgt_name(tsi->tsi_tgt),
-                      -EPROTO);
+       update_buf_count = ouh->ouh_count;
+       if (update_buf_count == 0)
                RETURN(err_serious(-EPROTO));
+
+       OBD_ALLOC(update_bufs, sizeof(*update_bufs) * update_buf_count);
+       if (update_bufs == NULL)
+               RETURN(err_serious(-ENOMEM));
+
+       if (ouh->ouh_inline_length > 0) {
+               update_bufs[0] = ouh->ouh_inline_data;
+       } else {
+               struct out_update_buffer *tmp;
+
+               oub = req_capsule_client_get(pill, &RMF_OUT_UPDATE_BUF);
+               if (oub == NULL)
+                       GOTO(out_free, rc = err_serious(-EPROTO));
+
+               desc = ptlrpc_prep_bulk_exp(pill->rc_req, update_buf_count,
+                                           PTLRPC_BULK_OPS_COUNT,
+                                           PTLRPC_BULK_GET_SINK |
+                                           PTLRPC_BULK_BUF_KVEC,
+                                           MDS_BULK_PORTAL,
+                                           &ptlrpc_bulk_kvec_ops);
+               if (desc == NULL)
+                       GOTO(out_free, rc = err_serious(-ENOMEM));
+
+               tmp = oub;
+               for (i = 0; i < update_buf_count; i++, tmp++) {
+                       if (tmp->oub_size >= OUT_MAXREQSIZE)
+                               GOTO(out_free, rc = err_serious(-EPROTO));
+
+                       OBD_ALLOC(update_bufs[i], tmp->oub_size);
+                       if (update_bufs[i] == NULL)
+                               GOTO(out_free, rc = err_serious(-ENOMEM));
+
+                       desc->bd_frag_ops->add_iov_frag(desc, update_bufs[i],
+                                                       tmp->oub_size);
+               }
+
+               pill->rc_req->rq_bulk_write = 1;
+               rc = sptlrpc_svc_prep_bulk(pill->rc_req, desc);
+               if (rc != 0)
+                       GOTO(out_free, rc = err_serious(rc));
+
+               rc = target_bulk_io(pill->rc_req->rq_export, desc, &lwi);
+               if (rc < 0)
+                       GOTO(out_free, rc = err_serious(rc));
+       }
+       /* validate the request and calculate the total update count and
+        * set it to reply */
+       reply_size = 0;
+       updates = 0;
+       for (i = 0; i < update_buf_count; i++) {
+               struct object_update_request    *our;
+               int                              j;
+
+               our = update_bufs[i];
+               if (ptlrpc_req_need_swab(pill->rc_req))
+                       lustre_swab_object_update_request(our);
+
+               if (our->ourq_magic != UPDATE_REQUEST_MAGIC) {
+                       CERROR("%s: invalid update buffer magic %x"
+                              " expect %x: rc = %d\n",
+                              tgt_name(tsi->tsi_tgt), our->ourq_magic,
+                              UPDATE_REQUEST_MAGIC, -EPROTO);
+                       GOTO(out_free, rc = err_serious(-EPROTO));
+               }
+               updates += our->ourq_count;
+
+               /* need to calculate reply size */
+               for (j = 0; j < our->ourq_count; j++) {
+                       update = object_update_request_get(our, j, NULL);
+                       if (update == NULL)
+                               GOTO(out, rc = err_serious(-EPROTO));
+                       if (ptlrpc_req_need_swab(pill->rc_req))
+                               lustre_swab_object_update(update);
+
+                       if (!fid_is_sane(&update->ou_fid)) {
+                               CERROR("%s: invalid FID "DFID": rc = %d\n",
+                                      tgt_name(tsi->tsi_tgt),
+                                      PFID(&update->ou_fid), -EPROTO);
+                               GOTO(out, rc = err_serious(-EPROTO));
+                       }
+
+                       /* XXX: what ou_result_size can be considered safe? */
+
+                       reply_size += sizeof(reply->ourp_lens[0]);
+                       reply_size += sizeof(struct object_update_result);
+                       reply_size += update->ou_result_size;
+               }
+       }
+       reply_size += sizeof(*reply);
+
+       if (unlikely(reply_size > ouh->ouh_reply_size)) {
+               CERROR("%s: too small reply buf %u for %u, need %u at least\n",
+                      tgt_name(tsi->tsi_tgt), ouh->ouh_reply_size,
+                      updates, reply_size);
+               GOTO(out_free, rc = err_serious(-EPROTO));
        }
 
        req_capsule_set_size(pill, &RMF_OUT_UPDATE_REPLY, RCL_SERVER,
-                            OUT_UPDATE_REPLY_SIZE);
+                            ouh->ouh_reply_size);
        rc = req_capsule_server_pack(pill);
        if (rc != 0) {
                CERROR("%s: Can't pack response: rc = %d\n",
                       tgt_name(tsi->tsi_tgt), rc);
-               RETURN(rc);
+               GOTO(out_free, rc = err_serious(-EPROTO));
        }
 
        /* Prepare the update reply buffer */
        reply = req_capsule_server_get(pill, &RMF_OUT_UPDATE_REPLY);
        if (reply == NULL)
-               RETURN(err_serious(-EPROTO));
-       object_update_reply_init(reply, count);
+               GOTO(out_free, rc = -EPROTO);
+       reply->ourp_magic = UPDATE_REPLY_MAGIC;
+       reply->ourp_count = updates;
        tti->tti_u.update.tti_update_reply = reply;
        tti->tti_mult_trans = !req_is_replay(tgt_ses_req(tsi));
-
-       memset(ta, 0, sizeof(*ta));
-       /* Walk through updates in the request to execute them synchronously */
-       for (i = 0; i < count; i++) {
+       /* Walk through updates in the request to execute them */
+       for (i = 0; i < update_buf_count; i++) {
                struct tgt_handler      *h;
                struct dt_object        *dt_obj;
+               int                     update_count;
+               struct object_update_request *our;
+               int                     j;
+
+               our = update_bufs[i];
+               update_count = our->ourq_count;
+               for (j = 0; j < update_count; j++) {
+                       update = object_update_request_get(our, j, NULL);
+
+                       dt_obj = dt_locate(env, dt, &update->ou_fid);
+                       if (IS_ERR(dt_obj))
+                               GOTO(out, rc = PTR_ERR(dt_obj));
+
+                       if (dt->dd_record_fid_accessed) {
+                               lfsck_pack_rfa(&tti->tti_lr,
+                                              lu_object_fid(&dt_obj->do_lu),
+                                              LE_FID_ACCESSED,
+                                              LFSCK_TYPE_LAYOUT);
+                               tgt_lfsck_in_notify(env, dt, &tti->tti_lr,
+                                                   NULL);
+                       }
 
-               update = object_update_request_get(ureq, i, NULL);
-               if (update == NULL)
-                       GOTO(out, rc = -EPROTO);
-
-               if (ptlrpc_req_need_swab(pill->rc_req))
-                       lustre_swab_object_update(update);
-
-               if (!fid_is_sane(&update->ou_fid)) {
-                       CERROR("%s: invalid FID "DFID": rc = %d\n",
-                              tgt_name(tsi->tsi_tgt), PFID(&update->ou_fid),
-                              -EPROTO);
-                       GOTO(out, rc = err_serious(-EPROTO));
-               }
-
-               dt_obj = dt_locate(env, dt, &update->ou_fid);
-               if (IS_ERR(dt_obj))
-                       GOTO(out, rc = PTR_ERR(dt_obj));
-
-               if (dt->dd_record_fid_accessed) {
-                       lfsck_pack_rfa(&tti->tti_lr,
-                                      lu_object_fid(&dt_obj->do_lu));
-                       tgt_lfsck_in_notify(env, dt, &tti->tti_lr);
-               }
-
-               tti->tti_u.update.tti_dt_object = dt_obj;
-               tti->tti_u.update.tti_update = update;
-               tti->tti_u.update.tti_update_reply_index = i;
+                       tti->tti_u.update.tti_dt_object = dt_obj;
+                       tti->tti_u.update.tti_update = update;
+                       tti->tti_u.update.tti_update_reply_index = reply_index;
 
-               h = out_handler_find(update->ou_type);
-               if (unlikely(h == NULL)) {
-                       CERROR("%s: unsupported opc: 0x%x\n",
-                              tgt_name(tsi->tsi_tgt), update->ou_type);
-                       GOTO(next, rc = -ENOTSUPP);
-               }
+                       h = out_handler_find(update->ou_type);
+                       if (unlikely(h == NULL)) {
+                               CERROR("%s: unsupported opc: 0x%x\n",
+                                      tgt_name(tsi->tsi_tgt), update->ou_type);
+                               GOTO(next, rc = -ENOTSUPP);
+                       }
 
-               /* Check resend case only for modifying RPC */
-               if (h->th_flags & MUTABOR) {
-                       struct ptlrpc_request *req = tgt_ses_req(tsi);
+                       /* Check resend case only for modifying RPC */
+                       if (h->th_flags & MUTABOR) {
+                               struct ptlrpc_request *req = tgt_ses_req(tsi);
 
-                       if (out_check_resent(env, dt, dt_obj, req,
-                                            out_reconstruct, reply, i))
-                               GOTO(next, rc = 0);
-               }
+                               if (out_check_resent(env, dt, dt_obj, req,
+                                                    out_reconstruct, reply,
+                                                    reply_index))
+                                       GOTO(next, rc = 0);
+                       }
 
-               /* start transaction for modification RPC only */
-               if (h->th_flags & MUTABOR && current_batchid == -1) {
-                       current_batchid = update->ou_batchid;
-                       rc = out_tx_start(env, dt, ta, tsi->tsi_exp);
-                       if (rc != 0)
-                               GOTO(next, rc);
-               }
+                       /* start transaction for modification RPC only */
+                       if (h->th_flags & MUTABOR && current_batchid == -1) {
+                               current_batchid = update->ou_batchid;
+                               rc = out_tx_start(env, dt, ta, tsi->tsi_exp);
+                               if (rc != 0)
+                                       GOTO(next, rc);
 
-               /* Stop the current update transaction, if the update has
-                * different batchid, or read-only update */
-               if (((current_batchid != update->ou_batchid) ||
-                    !(h->th_flags & MUTABOR)) && ta->ta_handle != NULL) {
-                       rc = out_tx_end(env, ta, rc);
-                       current_batchid = -1;
-                       if (rc != 0)
-                               GOTO(next, rc);
+                               if (update->ou_flags & UPDATE_FL_SYNC)
+                                       ta->ta_handle->th_sync = 1;
+                       }
 
-                       /* start a new transaction if needed */
-                       if (h->th_flags & MUTABOR) {
-                               rc = out_tx_start(env, dt, ta, tsi->tsi_exp);
+                       /* Stop the current update transaction, if the update
+                        * has different batchid, or read-only update */
+                       if (((current_batchid != update->ou_batchid) ||
+                            !(h->th_flags & MUTABOR)) &&
+                            ta->ta_handle != NULL) {
+                               rc = out_tx_end(env, ta, rc);
+                               current_batchid = -1;
                                if (rc != 0)
                                        GOTO(next, rc);
 
-                               current_batchid = update->ou_batchid;
+                               /* start a new transaction if needed */
+                               if (h->th_flags & MUTABOR) {
+                                       rc = out_tx_start(env, dt, ta,
+                                                         tsi->tsi_exp);
+                                       if (rc != 0)
+                                               GOTO(next, rc);
+                                       if (update->ou_flags & UPDATE_FL_SYNC)
+                                               ta->ta_handle->th_sync = 1;
+                                       current_batchid = update->ou_batchid;
+                               }
                        }
-               }
 
-               rc = h->th_act(tsi);
+                       rc = h->th_act(tsi);
 next:
-               lu_object_put(env, &dt_obj->do_lu);
-               if (rc < 0)
-                       GOTO(out, rc);
+                       reply_index++;
+                       lu_object_put(env, &dt_obj->do_lu);
+                       if (rc < 0)
+                               GOTO(out, rc);
+               }
        }
 out:
        if (current_batchid != -1) {
@@ -1573,6 +1145,21 @@ out:
                        rc = rc1;
        }
 
+out_free:
+       if (update_bufs != NULL) {
+               if (oub != NULL) {
+                       for (i = 0; i < update_buf_count; i++, oub++) {
+                               if (update_bufs[i] != NULL)
+                                       OBD_FREE(update_bufs[i], oub->oub_size);
+                       }
+               }
+
+               OBD_FREE(update_bufs, sizeof(*update_bufs) * update_buf_count);
+       }
+
+       if (desc != NULL)
+               ptlrpc_free_bulk(desc);
+
        RETURN(rc);
 }