Whamcloud - gitweb
LU-5710 all: second batch of corrected typos and grammar errors
[fs/lustre-release.git] / lustre / osp / osp_object.c
index ed26ee1..e838544 100644 (file)
  * or osp_declare_xattr_get(). That is usually for LFSCK purpose,
  * but it also can be shared by others.
  *
+ *
+ * XXX: NOT prepare out RPC for remote transaction. ((please refer to the
+ *     comment of osp_trans_create() for remote transaction)
+ *
+ * According to our current transaction/dt_object_lock framework (to make
+ * the cross-MDTs modification for DNE1 to be workable), the transaction
+ * sponsor will start the transaction firstly, then try to acquire related
+ * dt_object_lock if needed. Under such rules, if we want to prepare the
+ * OUT RPC in the transaction declare phase, then related attr/xattr
+ * should be known without dt_object_lock. But such condition maybe not
+ * true for some remote transaction case. For example:
+ *
+ * For linkEA repairing (by LFSCK) case, before the LFSCK thread obtained
+ * the dt_object_lock on the target MDT-object, it cannot know whether
+ * the MDT-object has linkEA or not, neither invalid or not.
+ *
+ * Since the LFSCK thread cannot hold dt_object_lock before the remote
+ * transaction start (otherwise there will be some potential deadlock),
+ * it cannot prepare related OUT RPC for repairing during the declare
+ * phase as other normal transactions do.
+ *
+ * To resolve the trouble, we will make OSP to prepare related OUT RPC
+ * after remote transaction started, and trigger the remote updating
+ * (send RPC) when trans_stop. Then the up layer users, such as LFSCK,
+ * can follow the general rule to handle trans_start/dt_object_lock
+ * for repairing linkEA inconsistency without distinguishing remote
+ * MDT-object.
+ *
+ * In fact, above solution for remote transaction should be the normal
+ * model without considering DNE1. The trouble brought by DNE1 will be
+ * resolved in DNE2. At that time, this patch can be removed.
+ *
+ *
  * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
  * Author: Mikhail Pershin <mike.tappro@intel.com>
  */
@@ -286,7 +319,7 @@ osp_oac_xattr_find_or_add(struct osp_object *obj, const char *name, size_t len)
  *
  * \param[in] obj      pointer to the OSP object
  * \param[in,out] poxe double pointer to the OSP object extended attribute
- *                     entry: the new extended attribute entry is transfered
+ *                     entry: the new extended attribute entry is transferred
  *                     via such pointer target, and if old the extended
  *                     attribute entry exists, then it will be returned back
  *                     via such pointer target.
@@ -460,13 +493,11 @@ static int osp_attr_get_interpterer(const struct lu_env *env,
  *
  * \param[in] env      pointer to the thread context
  * \param[in] dt       pointer to the OSP layer dt_object
- * \param[in] capa     the capability for this operation
  *
  * \retval             0 for success
  * \retval             negative error number on failure
  */
-static int osp_declare_attr_get(const struct lu_env *env, struct dt_object *dt,
-                               struct lustre_capa *capa)
+static int osp_declare_attr_get(const struct lu_env *env, struct dt_object *dt)
 {
        struct osp_object       *obj    = dt2osp_obj(dt);
        struct osp_device       *osp    = lu2osp_dev(dt->do_lu.lo_dev);
@@ -500,13 +531,12 @@ static int osp_declare_attr_get(const struct lu_env *env, struct dt_object *dt,
  * \param[in] env      pointer to the thread context
  * \param[in] dt       pointer to the OSP layer dt_object
  * \param[out] attr    pointer to the buffer to hold the output attribute
- * \param[in] capa     the capability for this operation
  *
  * \retval             0 for success
  * \retval             negative error number on failure
  */
 int osp_attr_get(const struct lu_env *env, struct dt_object *dt,
-                struct lu_attr *attr, struct lustre_capa *capa)
+                struct lu_attr *attr)
 {
        struct osp_device               *osp = lu2osp_dev(dt->do_lu.lo_dev);
        struct osp_object               *obj = dt2osp_obj(dt);
@@ -545,7 +575,7 @@ int osp_attr_get(const struct lu_env *env, struct dt_object *dt,
                GOTO(out, rc);
        }
 
-       rc = out_remote_sync(env, osp->opd_obd->u.cli.cl_import, update, &req);
+       rc = osp_remote_sync(env, osp, update, &req);
        if (rc != 0) {
                if (rc == -ENOENT) {
                        osp2lu_obj(obj)->lo_header->loh_attr &= ~LOHA_EXISTS;
@@ -582,15 +612,29 @@ out:
        return rc;
 }
 
-static int __osp_attr_set(const struct lu_env *env, struct dt_object *dt,
-                         const struct lu_attr *attr, struct thandle *th)
+/**
+ * Implement OSP layer dt_object_operations::do_declare_attr_set() interface.
+ *
+ * If the transaction is not remote one, then declare the credits that will
+ * be used for the subsequent llog record for the object's attributes.
+ *
+ * \param[in] env      pointer to the thread context
+ * \param[in] dt       pointer to the OSP layer dt_object
+ * \param[in] attr     pointer to the attribute to be set
+ * \param[in] th       pointer to the transaction handler
+ *
+ * \retval             0 for success
+ * \retval             negative error number on failure
+ */
+static int osp_declare_attr_set(const struct lu_env *env, struct dt_object *dt,
+                               const struct lu_attr *attr, struct thandle *th)
 {
        struct osp_device       *d = lu2osp_dev(dt->do_lu.lo_dev);
        struct osp_object       *o = dt2osp_obj(dt);
-       struct lu_attr          *la;
-       int                      rc = 0;
-       ENTRY;
+       int                     rc;
 
+       if (is_only_remote_trans(th))
+               return osp_md_declare_attr_set(env, dt, attr, th);
        /*
         * Usually we don't allow server stack to manipulate size
         * but there is a special case when striping is created
@@ -619,97 +663,17 @@ static int __osp_attr_set(const struct lu_env *env, struct dt_object *dt,
                LASSERT(!dt_object_exists(dt));
                osp_object_assign_fid(env, d, o);
                rc = osp_object_truncate(env, dt, attr->la_size);
-               if (rc)
+               if (rc != 0)
                        RETURN(rc);
        }
 
        if (!(attr->la_valid & (LA_UID | LA_GID)))
                RETURN(0);
 
-       if (!is_only_remote_trans(th)) {
-               if (o->opo_new)
-                       /* no need in logging for new objects being created */
-                       RETURN(0);
-
-               /*
-                * track all UID/GID changes via llog
-                */
-               rc = osp_sync_declare_add(env, o, MDS_SETATTR64_REC, th);
-       } else {
-               /* It is for OST-object attr_set directly without updating
-                * local MDT-object attribute. It is usually used by LFSCK. */
-               rc = __osp_md_attr_set(env, dt, attr, th);
-       }
-
-       if (rc != 0 || o->opo_ooa == NULL)
-               RETURN(rc);
-
-       /* Update the OSP object attributes cache. */
-       la = &o->opo_ooa->ooa_attr;
-       spin_lock(&o->opo_lock);
-       if (attr->la_valid & LA_UID) {
-               la->la_uid = attr->la_uid;
-               la->la_valid |= LA_UID;
-       }
-
-       if (attr->la_valid & LA_GID) {
-               la->la_gid = attr->la_gid;
-               la->la_valid |= LA_GID;
-       }
-       spin_unlock(&o->opo_lock);
-
-       RETURN(0);
-}
-
-/**
- * Implement OSP layer dt_object_operations::do_declare_attr_set() interface.
- * XXX: NOT prepare set_{attr,xattr} RPC for remote transaction.
- *
- * According to our current transaction/dt_object_lock framework (to make
- * the cross-MDTs modification for DNE1 to be workable), the transaction
- * sponsor will start the transaction firstly, then try to acquire related
- * dt_object_lock if needed. Under such rules, if we want to prepare the
- * set_{attr,xattr} RPC in the RPC declare phase, then related attr/xattr
- * should be known without dt_object_lock. But such condition maybe not
- * true for some remote transaction case. For example:
- *
- * For linkEA repairing (by LFSCK) case, before the LFSCK thread obtained
- * the dt_object_lock on the target MDT-object, it cannot know whether
- * the MDT-object has linkEA or not, neither invalid or not.
- *
- * Since the LFSCK thread cannot hold dt_object_lock before the (remote)
- * transaction start (otherwise there will be some potential deadlock),
- * it cannot prepare related RPC for repairing during the declare phase
- * as other normal transactions do.
- *
- * To resolve the trouble, we will make OSP to prepare related RPC
- * (set_attr/set_xattr/del_xattr) after remote transaction started,
- * and trigger the remote updating (RPC sending) when trans_stop.
- * Then the up layer users, such as LFSCK, can follow the general
- * rule to handle trans_start/dt_object_lock for repairing linkEA
- * inconsistency without distinguishing remote MDT-object.
- *
- * In fact, above solution for remote transaction should be the normal
- * model without considering DNE1. The trouble brought by DNE1 will be
- * resolved in DNE2. At that time, this patch can be removed.
- *
- * \param[in] env      pointer to the thread context
- * \param[in] dt       pointer to the OSP layer dt_object
- * \param[in] attr     pointer to the attribute to be set
- * \param[in] th       pointer to the transaction handler
- *
- * \retval             0 for success
- * \retval             negative error number on failure
- */
-static int osp_declare_attr_set(const struct lu_env *env, struct dt_object *dt,
-                               const struct lu_attr *attr, struct thandle *th)
-{
-       int rc = 0;
-
-       if (!is_only_remote_trans(th))
-               rc = __osp_attr_set(env, dt, attr, th);
+       /* track all UID/GID changes via llog */
+       rc = osp_sync_declare_add(env, o, MDS_SETATTR64_REC, th);
 
-       return rc;
+       return 0;
 }
 
 /**
@@ -717,11 +681,10 @@ static int osp_declare_attr_set(const struct lu_env *env, struct dt_object *dt,
  *
  * Set attribute to the specified OST object.
  *
- * If the transaction is a remote transaction, then related modification
- * sub-request has been added in the declare phase and related OUT RPC
- * has been triggered at transaction start. Otherwise it will generate
- * a MDS_SETATTR64_REC record in the llog. There is a dedicated thread
- * to handle the llog asynchronously.
+ * If the transaction is a remote one, then add OUT_ATTR_SET sub-request
+ * in the OUT RPC that will be flushed when the remote transaction stop.
+ * Otherwise, it will generate a MDS_SETATTR64_REC record in the llog that
+ * will be handled by a dedicated thread asynchronously.
  *
  * If the attribute entry exists in the OSP object attributes cache,
  * then update the cached attribute according to given attribute.
@@ -730,42 +693,50 @@ static int osp_declare_attr_set(const struct lu_env *env, struct dt_object *dt,
  * \param[in] dt       pointer to the OSP layer dt_object
  * \param[in] attr     pointer to the attribute to be set
  * \param[in] th       pointer to the transaction handler
- * \param[in] capa     the capability for this operation
  *
  * \retval             0 for success
  * \retval             negative error number on failure
  */
 static int osp_attr_set(const struct lu_env *env, struct dt_object *dt,
-                       const struct lu_attr *attr, struct thandle *th,
-                       struct lustre_capa *capa)
+                       const struct lu_attr *attr, struct thandle *th)
 {
        struct osp_object       *o = dt2osp_obj(dt);
        int                      rc = 0;
        ENTRY;
 
-       if (is_only_remote_trans(th)) {
-               rc = __osp_attr_set(env, dt, attr, th);
-               if (rc == 0 && o->opo_new)
-                       o->opo_new = 0;
-
-               RETURN(rc);
-       }
-
        /* we're interested in uid/gid changes only */
        if (!(attr->la_valid & (LA_UID | LA_GID)))
                RETURN(0);
 
-       /* new object, the very first ->attr_set()
-        * initializing attributes needs no logging
-        * all subsequent one are subject to the
-        * logging and synchronization with OST */
-       if (o->opo_new) {
-               o->opo_new = 0;
-               RETURN(0);
-       }
+       if (!is_only_remote_trans(th)) {
+               rc = osp_sync_add(env, o, MDS_SETATTR64_REC, th, attr);
+               /* XXX: send new uid/gid to OST ASAP? */
+       } else {
+               struct lu_attr  *la;
+
+               /* It is for OST-object attr_set directly without updating
+                * local MDT-object attribute. It is usually used by LFSCK. */
+               rc = osp_md_attr_set(env, dt, attr, th);
+               CDEBUG(D_INFO, "(1) set attr "DFID": rc = %d\n",
+                      PFID(&dt->do_lu.lo_header->loh_fid), rc);
 
-       rc = osp_sync_add(env, o, MDS_SETATTR64_REC, th, attr);
-       /* XXX: send new uid/gid to OST ASAP? */
+               if (rc != 0 || o->opo_ooa == NULL)
+                       RETURN(rc);
+
+               /* Update the OSP object attributes cache. */
+               la = &o->opo_ooa->ooa_attr;
+               spin_lock(&o->opo_lock);
+               if (attr->la_valid & LA_UID) {
+                       la->la_uid = attr->la_uid;
+                       la->la_valid |= LA_UID;
+               }
+
+               if (attr->la_valid & LA_GID) {
+                       la->la_gid = attr->la_gid;
+                       la->la_valid |= LA_GID;
+               }
+               spin_unlock(&o->opo_lock);
+       }
 
        RETURN(rc);
 }
@@ -848,14 +819,12 @@ static int osp_xattr_get_interpterer(const struct lu_env *env,
  * \param[in] dt       pointer to the OSP layer dt_object
  * \param[out] buf     pointer to the lu_buf to hold the extended attribute
  * \param[in] name     the name for the expected extended attribute
- * \param[in] capa     the capability for this operation
  *
  * \retval             0 for success
  * \retval             negative error number on failure
  */
 static int osp_declare_xattr_get(const struct lu_env *env, struct dt_object *dt,
-                                struct lu_buf *buf, const char *name,
-                                struct lustre_capa *capa)
+                                struct lu_buf *buf, const char *name)
 {
        struct osp_object       *obj     = dt2osp_obj(dt);
        struct osp_device       *osp     = lu2osp_dev(dt->do_lu.lo_dev);
@@ -928,14 +897,12 @@ static int osp_declare_xattr_get(const struct lu_env *env, struct dt_object *dt,
  * \param[in] dt       pointer to the OSP layer dt_object
  * \param[out] buf     pointer to the lu_buf to hold the extended attribute
  * \param[in] name     the name for the expected extended attribute
- * \param[in] capa     the capability for this operation
  *
  * \retval             0 for success
  * \retval             negative error number on failure
  */
 int osp_xattr_get(const struct lu_env *env, struct dt_object *dt,
-                 struct lu_buf *buf, const char *name,
-                 struct lustre_capa *capa)
+                 struct lu_buf *buf, const char *name)
 {
        struct osp_device       *osp    = lu2osp_dev(dt->do_lu.lo_dev);
        struct osp_object       *obj    = dt2osp_obj(dt);
@@ -1004,7 +971,7 @@ unlock:
                GOTO(out, rc);
        }
 
-       rc = out_remote_sync(env, osp->opd_obd->u.cli.cl_import, update, &req);
+       rc = osp_remote_sync(env, osp, update, &req);
        if (rc != 0) {
                if (rc == -ENOENT) {
                        dt->do_lu.lo_header->loh_attr &= ~LOHA_EXISTS;
@@ -1118,9 +1085,60 @@ out:
        return rc;
 }
 
-static int __osp_xattr_set(const struct lu_env *env, struct dt_object *dt,
-                          const struct lu_buf *buf, const char *name,
-                          int flag, struct thandle *th)
+/**
+ * Implement OSP layer dt_object_operations::do_declare_xattr_set() interface.
+ *
+ * Declare that the caller will set extended attribute to the specified
+ * MDT/OST object.
+ *
+ * If it is non-remote transaction, it will add an OUT_XATTR_SET sub-request
+ * to the OUT RPC that will be flushed when the transaction start. And if the
+ * OSP attributes cache is initialized, then check whether the name extended
+ * attribute entry exists in the cache or not. If yes, replace it; otherwise,
+ * add the extended attribute to the cache.
+ *
+ * \param[in] env      pointer to the thread context
+ * \param[in] dt       pointer to the OSP layer dt_object
+ * \param[in] buf      pointer to the lu_buf to hold the extended attribute
+ * \param[in] name     the name of the extended attribute to be set
+ * \param[in] flag     to indicate the detailed set operation: LU_XATTR_CREATE
+ *                     or LU_XATTR_REPLACE or others
+ * \param[in] th       pointer to the transaction handler
+ *
+ * \retval             0 for success
+ * \retval             negative error number on failure
+ */
+int osp_declare_xattr_set(const struct lu_env *env, struct dt_object *dt,
+                         const struct lu_buf *buf, const char *name,
+                         int flag, struct thandle *th)
+{
+       return osp_trans_update_request_create(th);
+}
+
+/**
+ * Implement OSP layer dt_object_operations::do_xattr_set() interface.
+ *
+ * Set extended attribute to the specified MDT/OST object.
+ *
+ * Add an OUT_XATTR_SET sub-request into the OUT RPC that will be flushed in
+ * the transaction stop. And if the OSP attributes cache is initialized, then
+ * check whether the name extended attribute entry exists in the cache or not.
+ * If yes, replace it; otherwise, add the extended attribute to the cache.
+ *
+ * \param[in] env      pointer to the thread context
+ * \param[in] dt       pointer to the OSP layer dt_object
+ * \param[in] buf      pointer to the lu_buf to hold the extended attribute
+ * \param[in] name     the name of the extended attribute to be set
+ * \param[in] fl       to indicate the detailed set operation: LU_XATTR_CREATE
+ *                     or LU_XATTR_REPLACE or others
+ * \param[in] th       pointer to the transaction handler
+ *
+ * \retval             0 for success
+ * \retval             negative error number on failure
+ */
+int osp_xattr_set(const struct lu_env *env, struct dt_object *dt,
+                 const struct lu_buf *buf, const char *name, int fl,
+                 struct thandle *th)
 {
        struct osp_object       *o = dt2osp_obj(dt);
        struct dt_update_request *update;
@@ -1129,26 +1147,21 @@ static int __osp_xattr_set(const struct lu_env *env, struct dt_object *dt,
        ENTRY;
 
        LASSERT(buf->lb_len > 0 && buf->lb_buf != NULL);
+       update = thandle_to_dt_update_request(th);
+       LASSERT(update != NULL);
 
-       update = dt_update_request_find_or_create(th, dt);
-       if (IS_ERR(update)) {
-               CERROR("%s: Get OSP update buf failed "DFID": rc = %d\n",
-                      dt->do_lu.lo_dev->ld_obd->obd_name,
-                      PFID(lu_object_fid(&dt->do_lu)),
-                      (int)PTR_ERR(update));
-
-               RETURN(PTR_ERR(update));
-       }
+       CDEBUG(D_INODE, DFID" set xattr '%s' with size %zd\n",
+              PFID(lu_object_fid(&dt->do_lu)), name, buf->lb_len);
 
        rc = out_xattr_set_pack(env, &update->dur_buf,
                                lu_object_fid(&dt->do_lu),
-                               buf, name, flag, update->dur_batchid);
+                               buf, name, fl, update->dur_batchid);
        if (rc != 0 || o->opo_ooa == NULL)
-               RETURN(rc);
+               return rc;
 
        oxe = osp_oac_xattr_find_or_add(o, name, buf->lb_len);
        if (oxe == NULL) {
-               CWARN("%s: Fail to add xattr (%s) to cache for "DFID,
+               CWARN("%s: cannot cache xattr '%s' of "DFID"\n",
                      dt->do_lu.lo_dev->ld_obd->obd_name,
                      name, PFID(lu_object_fid(&dt->do_lu)));
 
@@ -1163,7 +1176,7 @@ static int __osp_xattr_set(const struct lu_env *env, struct dt_object *dt,
                osp_oac_xattr_put(oxe);
                oxe = tmp;
                if (tmp == NULL) {
-                       CWARN("%s: Fail to update xattr (%s) to cache for "DFID,
+                       CWARN("%s: cannot update cached xattr '%s' of "DFID"\n",
                              dt->do_lu.lo_dev->ld_obd->obd_name,
                              name, PFID(lu_object_fid(&dt->do_lu)));
                        spin_lock(&o->opo_lock);
@@ -1189,99 +1202,62 @@ static int __osp_xattr_set(const struct lu_env *env, struct dt_object *dt,
 }
 
 /**
- * Implement OSP layer dt_object_operations::do_declare_xattr_set() interface.
+ * Implement OSP layer dt_object_operations::do_declare_xattr_del() interface.
  *
- * Declare that the caller will set extended attribute to the specified
+ * Declare that the caller will delete extended attribute on the specified
  * MDT/OST object.
  *
- * This function will add an OUT_XATTR_SET sub-request to the per
- * OSP-transaction based request queue which will be flushed when
- * the transaction starts.
+ * If it is non-remote transaction, it will add an OUT_XATTR_DEL sub-request
+ * to the OUT RPC that will be flushed when the transaction start. And if the
+ * name extended attribute entry exists in the OSP attributes cache, then remove
+ * it from the cache.
  *
  * \param[in] env      pointer to the thread context
  * \param[in] dt       pointer to the OSP layer dt_object
- * \param[in] buf      pointer to the lu_buf to hold the extended attribute
  * \param[in] name     the name of the extended attribute to be set
- * \param[in] flag     to indicate the detailed set operation: LU_XATTR_CREATE
- *                     or LU_XATTR_REPLACE or others
  * \param[in] th       pointer to the transaction handler
  *
  * \retval             0 for success
  * \retval             negative error number on failure
  */
-int osp_declare_xattr_set(const struct lu_env *env, struct dt_object *dt,
-                         const struct lu_buf *buf, const char *name,
-                         int flag, struct thandle *th)
+int osp_declare_xattr_del(const struct lu_env *env, struct dt_object *dt,
+                         const char *name, struct thandle *th)
 {
-       int rc = 0;
-
-       /* Please check the comment in osp_attr_set() for handling
-        * remote transaction. */
-       if (!is_only_remote_trans(th))
-               rc = __osp_xattr_set(env, dt, buf, name, flag, th);
-
-       return rc;
+       return osp_trans_update_request_create(th);
 }
 
 /**
- * Implement OSP layer dt_object_operations::do_xattr_set() interface.
- *
- * Set extended attribute to the specified MDT/OST object.
+ * Implement OSP layer dt_object_operations::do_xattr_del() interface.
  *
- * The real modification sub-request has been added in the declare phase
- * and related (OUT) RPC has been triggered when transaction start.
+ * Delete extended attribute on the specified MDT/OST object.
  *
- * If the OSP attributes cache is initialized, then check whether the name
- * extended attribute entry exists in the cache or not. If yes, replace it;
- * otherwise, add the extended attribute to the cache.
+ * If it is remote transaction, it will add an OUT_XATTR_DEL sub-request into
+ * the OUT RPC that will be flushed when the transaction stop. And if the name
+ * extended attribute entry exists in the OSP attributes cache, then remove it
+ * from the cache.
  *
  * \param[in] env      pointer to the thread context
  * \param[in] dt       pointer to the OSP layer dt_object
- * \param[in] buf      pointer to the lu_buf to hold the extended attribute
  * \param[in] name     the name of the extended attribute to be set
- * \param[in] fl       to indicate the detailed set operation: LU_XATTR_CREATE
- *                     or LU_XATTR_REPLACE or others
  * \param[in] th       pointer to the transaction handler
- * \param[in] capa     the capability for this operation
  *
  * \retval             0 for success
  * \retval             negative error number on failure
  */
-int osp_xattr_set(const struct lu_env *env, struct dt_object *dt,
-                 const struct lu_buf *buf, const char *name, int fl,
-                 struct thandle *th, struct lustre_capa *capa)
-{
-       int rc = 0;
-
-       CDEBUG(D_INFO, "xattr %s set object "DFID"\n", name,
-              PFID(&dt->do_lu.lo_header->loh_fid));
-
-       /* Please check the comment in osp_attr_set() for handling
-        * remote transaction. */
-       if (is_only_remote_trans(th))
-               rc = __osp_xattr_set(env, dt, buf, name, fl, th);
-
-       return rc;
-}
-
-static int __osp_xattr_del(const struct lu_env *env, struct dt_object *dt,
-                          const char *name, struct thandle *th)
+int osp_xattr_del(const struct lu_env *env, struct dt_object *dt,
+                 const char *name, struct thandle *th)
 {
        struct dt_update_request *update;
-       const struct lu_fid      *fid;
-       struct osp_object        *o     = dt2osp_obj(dt);
+       const struct lu_fid      *fid = lu_object_fid(&dt->do_lu);
+       struct osp_object        *o = dt2osp_obj(dt);
        struct osp_xattr_entry   *oxe;
        int                       rc;
 
-       update = dt_update_request_find_or_create(th, dt);
-       if (IS_ERR(update))
-               return PTR_ERR(update);
-
-       fid = lu_object_fid(&dt->do_lu);
+       update = thandle_to_dt_update_request(th);
+       LASSERT(update != NULL);
 
        rc = out_xattr_del_pack(env, &update->dur_buf, fid, name,
                                update->dur_batchid);
-
        if (rc != 0 || o->opo_ooa == NULL)
                return rc;
 
@@ -1294,87 +1270,17 @@ static int __osp_xattr_del(const struct lu_env *env, struct dt_object *dt,
 }
 
 /**
- * Implement OSP layer dt_object_operations::do_declare_xattr_del() interface.
- *
- * Declare that the caller will delete extended attribute on the specified
- * MDT/OST object.
- *
- * This function will add an OUT_XATTR_DEL sub-request to the per
- * OSP-transaction based request queue which will be flushed when
- * transaction start.
- *
- * \param[in] env      pointer to the thread context
- * \param[in] dt       pointer to the OSP layer dt_object
- * \param[in] name     the name of the extended attribute to be set
- * \param[in] th       pointer to the transaction handler
- *
- * \retval             0 for success
- * \retval             negative error number on failure
- */
-int osp_declare_xattr_del(const struct lu_env *env, struct dt_object *dt,
-                         const char *name, struct thandle *th)
-{
-       int rc = 0;
-
-       /* Please check the comment in osp_attr_set() for handling
-        * remote transaction. */
-       if (!is_only_remote_trans(th))
-               rc = __osp_xattr_del(env, dt, name, th);
-
-       return rc;
-}
-
-/**
- * Implement OSP layer dt_object_operations::do_xattr_del() interface.
- *
- * Delete extended attribute on the specified MDT/OST object.
- *
- * The real modification sub-request has been added in the declare phase
- * and related (OUT) RPC has been triggered when transaction start.
- *
- * If the name extended attribute entry exists in the OSP attributes
- * cache, then remove it from the cache.
- *
- * \param[in] env      pointer to the thread context
- * \param[in] dt       pointer to the OSP layer dt_object
- * \param[in] name     the name of the extended attribute to be set
- * \param[in] th       pointer to the transaction handler
- * \param[in] capa     the capability for this operation
- *
- * \retval             0 for success
- * \retval             negative error number on failure
- */
-int osp_xattr_del(const struct lu_env *env, struct dt_object *dt,
-                 const char *name, struct thandle *th,
-                 struct lustre_capa *capa)
-{
-       int rc = 0;
-
-       CDEBUG(D_INFO, "xattr %s del object "DFID"\n", name,
-              PFID(&dt->do_lu.lo_header->loh_fid));
-
-       /* Please check the comment in osp_attr_set() for handling
-        * remote transaction. */
-       if (is_only_remote_trans(th))
-               rc = __osp_xattr_del(env, dt, name, th);
-
-       return rc;
-}
-
-/**
  * Implement OSP layer dt_object_operations::do_declare_create() interface.
  *
  * Declare that the caller will create the OST object.
  *
- * If the transaction is a remote transaction (please refer to the
- * comment of osp_trans_create() for remote transaction), then the FID
- * for the OST object has been assigned already, and will be handled
- * as create (remote) MDT object via osp_md_declare_object_create().
- * This function is usually used for LFSCK to re-create the lost OST
- * object. Otherwise, if it is not replay case, the OSP will reserve
- * pre-created object for the subsequent create operation; if the MDT
- * side cached pre-created objects are less than some threshold, then
- * it will wakeup the pre-create thread.
+ * If the transaction is a remote transaction and the FID for the OST-object
+ * has been assigned already, then handle it as creating (remote) MDT object
+ * via osp_md_declare_object_create(). This function is usually used for LFSCK
+ * to re-create the lost OST object. Otherwise, if it is not replay case, the
+ * OSP will reserve pre-created object for the subsequent create operation;
+ * if the MDT side cached pre-created objects are less than some threshold,
+ * then it will wakeup the pre-create thread.
  *
  * \param[in] env      pointer to the thread context
  * \param[in] dt       pointer to the OSP layer dt_object
@@ -1398,11 +1304,12 @@ static int osp_declare_object_create(const struct lu_env *env,
        struct osp_device       *d = lu2osp_dev(dt->do_lu.lo_dev);
        struct osp_object       *o = dt2osp_obj(dt);
        const struct lu_fid     *fid = lu_object_fid(&dt->do_lu);
+       struct thandle          *local_th;
        int                      rc = 0;
 
        ENTRY;
 
-       if (is_only_remote_trans(th)) {
+       if (is_only_remote_trans(th) && !fid_is_zero(fid)) {
                LASSERT(fid_is_sane(fid));
 
                rc = osp_md_declare_object_create(env, dt, attr, hint, dof, th);
@@ -1426,13 +1333,19 @@ static int osp_declare_object_create(const struct lu_env *env,
         */
        /* rc = osp_sync_declare_add(env, o, MDS_UNLINK64_REC, th); */
 
+       local_th = osp_get_storage_thandle(env, th, d);
+       if (IS_ERR(local_th))
+               RETURN(PTR_ERR(local_th));
+
        if (unlikely(!fid_is_zero(fid))) {
                /* replay case: caller knows fid */
                osi->osi_off = sizeof(osi->osi_id) * d->opd_index;
                osi->osi_lb.lb_len = sizeof(osi->osi_id);
                osi->osi_lb.lb_buf = NULL;
+
                rc = dt_declare_record_write(env, d->opd_last_used_oid_file,
-                                            &osi->osi_lb, osi->osi_off, th);
+                                            &osi->osi_lb, osi->osi_off,
+                                            local_th);
                RETURN(rc);
        }
 
@@ -1457,7 +1370,8 @@ static int osp_declare_object_create(const struct lu_env *env,
                osi->osi_lb.lb_len = sizeof(osi->osi_id);
                osi->osi_lb.lb_buf = NULL;
                rc = dt_declare_record_write(env, d->opd_last_used_oid_file,
-                                            &osi->osi_lb, osi->osi_off, th);
+                                            &osi->osi_lb, osi->osi_off,
+                                            local_th);
        } else {
                /* not needed in the cache anymore */
                set_bit(LU_OBJECT_HEARD_BANSHEE,
@@ -1471,12 +1385,9 @@ static int osp_declare_object_create(const struct lu_env *env,
  *
  * Create the OST object.
  *
- * For remote transaction case, the real create sub-request has been
- * added in the declare phase and related (OUT) RPC has been triggered
- * at transaction start. Here, like creating (remote) MDT object, the
- * OSP will mark the object existence via osp_md_object_create().
- *
- * For non-remote transaction case, the OSP will assign FID to the
+ * If the transaction is a remote transaction and the FID for the OST-object
+ * has been assigned already, then handle it as handling MDT object via the
+ * osp_md_object_create(). For other cases, the OSP will assign FID to the
  * object to be created, and update last_used Object ID (OID) file.
  *
  * \param[in] env      pointer to the thread context
@@ -1500,9 +1411,11 @@ static int osp_object_create(const struct lu_env *env, struct dt_object *dt,
        struct osp_object       *o = dt2osp_obj(dt);
        int                     rc = 0;
        struct lu_fid           *fid = &osi->osi_fid;
+       struct thandle          *local_th;
        ENTRY;
 
-       if (is_only_remote_trans(th)) {
+       if (is_only_remote_trans(th) &&
+           !fid_is_zero(lu_object_fid(&dt->do_lu))) {
                LASSERT(fid_is_sane(lu_object_fid(&dt->do_lu)));
 
                rc = osp_md_object_create(env, dt, attr, hint, dof, th);
@@ -1541,6 +1454,9 @@ static int osp_object_create(const struct lu_env *env, struct dt_object *dt,
        if (osp_precreate_end_seq(env, d) && osp_is_fid_client(d))
                th->th_sync = 1;
 
+       local_th = osp_get_storage_thandle(env, th, d);
+       if (IS_ERR(local_th))
+               RETURN(PTR_ERR(local_th));
        /*
         * it's OK if the import is inactive by this moment - id was created
         * by OST earlier, we just need to maintain it consistently on the disk
@@ -1569,17 +1485,13 @@ static int osp_object_create(const struct lu_env *env, struct dt_object *dt,
                }
        }
 
-       /* new object, the very first ->attr_set()
-        * initializing attributes needs no logging */
-       o->opo_new = 1;
-
        /* Only need update last_used oid file, seq file will only be update
         * during seq rollover */
        osp_objid_buf_prep(&osi->osi_lb, &osi->osi_off,
                           &d->opd_last_used_fid.f_oid, d->opd_index);
 
        rc = dt_record_write(env, d->opd_last_used_oid_file, &osi->osi_lb,
-                            &osi->osi_off, th);
+                            &osi->osi_off, local_th);
 
        CDEBUG(D_HA, "%s: Wrote last used FID: "DFID", index %d: %d\n",
               d->opd_obd->obd_name, PFID(fid), d->opd_index, rc);
@@ -1606,13 +1518,12 @@ int osp_declare_object_destroy(const struct lu_env *env,
                               struct dt_object *dt, struct thandle *th)
 {
        struct osp_object       *o = dt2osp_obj(dt);
+       struct osp_device       *osp = lu2osp_dev(dt->do_lu.lo_dev);
        int                      rc = 0;
 
        ENTRY;
 
-       /*
-        * track objects to be destroyed via llog
-        */
+       LASSERT(!osp->opd_connect_mdt);
        rc = osp_sync_declare_add(env, o, MDS_UNLINK64_REC, th);
 
        RETURN(rc);
@@ -1635,20 +1546,22 @@ int osp_declare_object_destroy(const struct lu_env *env,
  * \retval             0 for success
  * \retval             negative error number on failure
  */
-int osp_object_destroy(const struct lu_env *env, struct dt_object *dt,
-                      struct thandle *th)
+static int osp_object_destroy(const struct lu_env *env, struct dt_object *dt,
+                             struct thandle *th)
 {
        struct osp_object       *o = dt2osp_obj(dt);
+       struct osp_device       *osp = lu2osp_dev(dt->do_lu.lo_dev);
        int                      rc = 0;
 
        ENTRY;
-
        o->opo_non_exist = 1;
-       /*
-        * once transaction is committed put proper command on
-        * the queue going to our OST
-        */
+
+       LASSERT(!osp->opd_connect_mdt);
+       /* once transaction is committed put proper command on
+        * the queue going to our OST. */
        rc = osp_sync_add(env, o, MDS_UNLINK64_REC, th, NULL);
+       if (rc < 0)
+               RETURN(rc);
 
        /* not needed in cache any more */
        set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags);
@@ -1659,8 +1572,7 @@ int osp_object_destroy(const struct lu_env *env, struct dt_object *dt,
 static int osp_orphan_index_lookup(const struct lu_env *env,
                                   struct dt_object *dt,
                                   struct dt_rec *rec,
-                                  const struct dt_key *key,
-                                  struct lustre_capa *capa)
+                                  const struct dt_key *key)
 {
        return -EOPNOTSUPP;
 }
@@ -1679,7 +1591,6 @@ static int osp_orphan_index_insert(const struct lu_env *env,
                                   const struct dt_rec *rec,
                                   const struct dt_key *key,
                                   struct thandle *handle,
-                                  struct lustre_capa *capa,
                                   int ignore_quota)
 {
        return -EOPNOTSUPP;
@@ -1696,8 +1607,7 @@ static int osp_orphan_index_declare_delete(const struct lu_env *env,
 static int osp_orphan_index_delete(const struct lu_env *env,
                                   struct dt_object *dt,
                                   const struct dt_key *key,
-                                  struct thandle *handle,
-                                  struct lustre_capa *capa)
+                                  struct thandle *handle)
 {
        return -EOPNOTSUPP;
 }
@@ -1708,13 +1618,12 @@ static int osp_orphan_index_delete(const struct lu_env *env,
  * \param[in] env      pointer to the thread context
  * \param[in] dt       pointer to the index object to be iterated
  * \param[in] attr     unused
- * \param[in] capa     the capability for this operation
  *
  * \retval             pointer to the iteration structure
  * \retval             negative error number on failure
  */
 struct dt_it *osp_it_init(const struct lu_env *env, struct dt_object *dt,
-                         __u32 attr, struct lustre_capa *capa)
+                         __u32 attr)
 {
        struct osp_it *it;
 
@@ -1724,6 +1633,7 @@ struct dt_it *osp_it_init(const struct lu_env *env, struct dt_object *dt,
 
        it->ooi_pos_ent = -1;
        it->ooi_obj = dt;
+       it->ooi_attr = attr;
 
        return (struct dt_it *)it;
 }
@@ -1760,7 +1670,7 @@ void osp_it_fini(const struct lu_env *env, struct dt_it *di)
  * Get more records for the iteration from peer.
  *
  * The new records will be filled in an array of pages. The OSP side
- * allows 1MB bulk data to be transfered.
+ * allows 1MB bulk data to be transferred.
  *
  * \param[in] env      pointer to the thread context
  * \param[in] it       pointer to the iteration structure
@@ -1819,15 +1729,16 @@ static int osp_it_fetch(const struct lu_env *env, struct osp_it *it)
                ii->ii_fid.f_oid = osp->opd_index;
                ii->ii_fid.f_ver = 0;
                ii->ii_flags = II_FL_NOHASH;
+               ii->ii_attrs = osp_dev2node(osp);
        } else {
                ii->ii_fid = *lu_object_fid(&it->ooi_obj->do_lu);
                ii->ii_flags = II_FL_NOHASH | II_FL_NOKEY | II_FL_VARKEY |
                               II_FL_VARREC;
+               ii->ii_attrs = it->ooi_attr;
        }
        ii->ii_magic = IDX_INFO_MAGIC;
        ii->ii_count = npages * LU_PAGE_COUNT;
        ii->ii_hash_start = it->ooi_next;
-       ii->ii_attrs = osp_dev2node(osp);
 
        ptlrpc_at_set_req_timeout(req);
 
@@ -1890,6 +1801,7 @@ out:
  * \param[in] env      pointer to the thread context
  * \param[in] di       pointer to the iteration structure
  *
+ * \retval             positive for end of the directory
  * \retval             0 for success
  * \retval             negative error number on failure
  */
@@ -1915,6 +1827,7 @@ again2:
                }
                it->ooi_cur_idxpage = NULL;
                it->ooi_pos_lu_page++;
+
 again1:
                if (it->ooi_pos_lu_page < LU_PAGE_COUNT) {
                        it->ooi_cur_idxpage = (void *)it->ooi_cur_page +
@@ -1987,10 +1900,11 @@ again0:
  * \param[in] env      pointer to the thread context
  * \param[in] di       pointer to the iteration structure
  *
+ * \retval             positive for end of the directory
  * \retval             0 for success
  * \retval             negative error number on failure
  */
-int osp_orphan_it_next(const struct lu_env *env, struct dt_it *di)
+static int osp_orphan_it_next(const struct lu_env *env, struct dt_it *di)
 {
        struct osp_it           *it = (struct osp_it *)di;
        struct lu_idxpage       *idxpage;
@@ -2031,8 +1945,8 @@ void osp_it_put(const struct lu_env *env, struct dt_it *di)
 {
 }
 
-struct dt_key *osp_orphan_it_key(const struct lu_env *env,
-                                const struct dt_it *di)
+static struct dt_key *osp_orphan_it_key(const struct lu_env *env,
+                                       const struct dt_it *di)
 {
        struct osp_it   *it  = (struct osp_it *)di;
        struct lu_orphan_ent    *ent = (struct lu_orphan_ent *)it->ooi_ent;
@@ -2043,13 +1957,14 @@ struct dt_key *osp_orphan_it_key(const struct lu_env *env,
        return NULL;
 }
 
-int osp_orphan_it_key_size(const struct lu_env *env, const struct dt_it *di)
+static int osp_orphan_it_key_size(const struct lu_env *env,
+                                 const struct dt_it *di)
 {
        return sizeof(struct lu_fid);
 }
 
-int osp_orphan_it_rec(const struct lu_env *env, const struct dt_it *di,
-                     struct dt_rec *rec, __u32 attr)
+static int osp_orphan_it_rec(const struct lu_env *env, const struct dt_it *di,
+                            struct dt_rec *rec, __u32 attr)
 {
        struct osp_it   *it  = (struct osp_it *)di;
        struct lu_orphan_ent    *ent = (struct lu_orphan_ent *)it->ooi_ent;
@@ -2153,7 +2068,7 @@ static int osp_index_try(const struct lu_env *env,
        return 0;
 }
 
-struct dt_object_operations osp_obj_ops = {
+static struct dt_object_operations osp_obj_ops = {
        .do_declare_attr_get    = osp_declare_attr_get,
        .do_attr_get            = osp_attr_get,
        .do_declare_attr_set    = osp_declare_attr_set,
@@ -2201,8 +2116,7 @@ static int osp_object_init(const struct lu_env *env, struct lu_object *o,
 
                po->opo_obj.do_ops = &osp_md_obj_ops;
                po->opo_obj.do_body_ops = &osp_md_body_ops;
-               rc = po->opo_obj.do_ops->do_attr_get(env, lu2dt_obj(o),
-                                                    la, NULL);
+               rc = po->opo_obj.do_ops->do_attr_get(env, lu2dt_obj(o), la);
                if (rc == 0)
                        o->lo_header->loh_attr |=
                                LOHA_EXISTS | (la->la_mode & S_IFMT);