Whamcloud - gitweb
LU-5506 lfsck: skip orphan MDT-object handling for failed MDTs
[fs/lustre-release.git] / lustre / osp / osp_object.c
index fae592f..2835bbb 100644 (file)
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, 2013, Intel Corporation.
+ * Copyright (c) 2014, Intel Corporation.
  */
 /*
- * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
- *
  * lustre/osp/osp_object.c
  *
- * Lustre OST Proxy Device
+ * Lustre OST Proxy Device (OSP) is the agent on the local MDT for the OST
+ * or remote MDT.
+ *
+ * OSP object attributes cache
+ * ---------------------------
+ * OSP object is the stub of the remote OST-object or MDT-object. Both the
+ * attribute and the extended attributes are stored on the peer side remotely.
+ * It is inefficient to send RPC to peer to fetch those attributes when every
+ * get_attr()/get_xattr() called. For a large system, the LFSCK synchronous
+ * mode scanning is prohibitively inefficient.
+ *
+ * So the OSP maintains the OSP object attributes cache to cache some
+ * attributes on the local MDT. The cache is organized against the OSP
+ * object as follows:
+ *
+ * struct osp_xattr_entry {
+ *     struct list_head         oxe_list;
+ *     atomic_t                 oxe_ref;
+ *     void                    *oxe_value;
+ *     int                      oxe_buflen;
+ *     int                      oxe_namelen;
+ *     int                      oxe_vallen;
+ *     unsigned int             oxe_exist:1,
+ *                              oxe_ready:1;
+ *     char                     oxe_buf[0];
+ * };
+ *
+ * struct osp_object_attr {
+ *     struct lu_attr          ooa_attr;
+ *     struct list_head        ooa_xattr_list;
+ * };
+ *
+ * struct osp_object {
+ *     ...
+ *     struct osp_object_attr *opo_ooa;
+ *     spinlock_t              opo_lock;
+ *     ...
+ * };
+ *
+ * The basic attributes, such as owner/mode/flags, are stored in the
+ * osp_object_attr::ooa_attr. The extended attributes will be stored
+ * as osp_xattr_entry. Every extended attribute has an independent
+ * osp_xattr_entry, and all the osp_xattr_entry are linked into the
+ * osp_object_attr::ooa_xattr_list. The OSP object attributes cache
+ * is protected by the osp_object::opo_lock.
+ *
+ * Not all OSP objects have an attributes cache because maintaining
+ * the cache requires some resources. Currently, the OSP object
+ * attributes cache will be initialized when the attributes or the
+ * extended attributes are pre-fetched via osp_declare_attr_get()
+ * or osp_declare_xattr_get(). That is usually for LFSCK purpose,
+ * but it also can be shared by others.
  *
  * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
  * Author: Mikhail Pershin <mike.tappro@intel.com>
 
 #include "osp_internal.h"
 
+static inline __u32 osp_dev2node(struct osp_device *osp)
+{
+       return osp->opd_storage->dd_lu_dev.ld_site->ld_seq_site->ss_node_id;
+}
+
 static inline bool is_ost_obj(struct lu_object *lo)
 {
        return !lu2osp_dev(lo->lo_dev)->opd_connect_mdt;
 }
 
+/**
+ * Assign FID to the OST object.
+ *
+ * This function will assign the FID to the OST object of a striped file.
+ *
+ * \param[in] env      pointer to the thread context
+ * \param[in] d                pointer to the OSP device
+ * \param[in] o                pointer to the OSP object that the FID will be
+ *                     assigned to
+ */
 static void osp_object_assign_fid(const struct lu_env *env,
-                                struct osp_device *d, struct osp_object *o)
+                                 struct osp_device *d, struct osp_object *o)
 {
        struct osp_thread_info *osi = osp_env_info(env);
 
@@ -64,6 +127,14 @@ static void osp_object_assign_fid(const struct lu_env *env,
        lu_object_assign_fid(env, &o->opo_obj.do_lu, &osi->osi_fid);
 }
 
+/**
+ * Initialize the OSP object attributes cache.
+ *
+ * \param[in] obj      pointer to the OSP object
+ *
+ * \retval             0 for success
+ * \retval             negative error number on failure
+ */
 static int osp_oac_init(struct osp_object *obj)
 {
        struct osp_object_attr *ooa;
@@ -85,53 +156,97 @@ static int osp_oac_init(struct osp_object *obj)
        return 0;
 }
 
+/**
+ * Find the named extended attribute in the OSP object attributes cache.
+ *
+ * The caller should take the osp_object::opo_lock before calling
+ * this function.
+ *
+ * \param[in] ooa      pointer to the OSP object attributes cache
+ * \param[in] name     the name of the extended attribute
+ * \param[in] namelen  the name length of the extended attribute
+ *
+ * \retval             pointer to the found extended attribute entry
+ * \retval             NULL if the specified extended attribute is not
+ *                     in the cache
+ */
 static struct osp_xattr_entry *
 osp_oac_xattr_find_locked(struct osp_object_attr *ooa,
-                         const char *name, int namelen, bool unlink)
+                         const char *name, size_t namelen)
 {
        struct osp_xattr_entry *oxe;
 
        list_for_each_entry(oxe, &ooa->ooa_xattr_list, oxe_list) {
                if (namelen == oxe->oxe_namelen &&
-                   strncmp(name, oxe->oxe_buf, namelen) == 0) {
-                       if (unlink)
-                               list_del_init(&oxe->oxe_list);
-                       else
-                               atomic_inc(&oxe->oxe_ref);
-
+                   strncmp(name, oxe->oxe_buf, namelen) == 0)
                        return oxe;
-               }
        }
 
        return NULL;
 }
 
+/**
+ * Find the named extended attribute in the OSP object attributes cache.
+ *
+ * Call osp_oac_xattr_find_locked() with the osp_object::opo_lock held.
+ *
+ * \param[in] obj      pointer to the OSP object
+ * \param[in] name     the name of the extended attribute
+ * \param[in] unlink   true if the extended attribute entry is to be removed
+ *                     from the cache
+ *
+ * \retval             pointer to the found extended attribute entry
+ * \retval             NULL if the specified extended attribute is not
+ *                     in the cache
+ */
 static struct osp_xattr_entry *osp_oac_xattr_find(struct osp_object *obj,
-                                                 const char *name)
+                                                 const char *name, bool unlink)
 {
        struct osp_xattr_entry *oxe = NULL;
 
        spin_lock(&obj->opo_lock);
-       if (obj->opo_ooa != NULL)
+       if (obj->opo_ooa != NULL) {
                oxe = osp_oac_xattr_find_locked(obj->opo_ooa, name,
-                                               strlen(name), false);
+                                               strlen(name));
+               if (oxe != NULL) {
+                       if (unlink)
+                               list_del_init(&oxe->oxe_list);
+                       else
+                               atomic_inc(&oxe->oxe_ref);
+               }
+       }
        spin_unlock(&obj->opo_lock);
 
        return oxe;
 }
 
+/**
+ * Find the named extended attribute in the OSP object attributes cache.
+ *
+ * If it is not in the cache, then add an empty entry (that will be
+ * filled later) to cache with the given name.
+ *
+ * \param[in] obj      pointer to the OSP object
+ * \param[in] name     the name of the extended attribute
+ * \param[in] len      the length of the extended attribute value
+ *
+ * \retval             pointer to the found or new-created extended
+ *                     attribute entry
+ * \retval             NULL if the specified extended attribute is not in the
+ *                     cache or fail to add new empty entry to the cache.
+ */
 static struct osp_xattr_entry *
-osp_oac_xattr_find_or_add(struct osp_object *obj, const char *name, int len)
+osp_oac_xattr_find_or_add(struct osp_object *obj, const char *name, size_t len)
 {
        struct osp_object_attr *ooa     = obj->opo_ooa;
        struct osp_xattr_entry *oxe;
        struct osp_xattr_entry *tmp     = NULL;
-       int                     namelen = strlen(name);
-       int                     size    = sizeof(*oxe) + namelen + 1 + len;
+       size_t                  namelen = strlen(name);
+       size_t                  size    = sizeof(*oxe) + namelen + 1 + len;
 
        LASSERT(ooa != NULL);
 
-       oxe = osp_oac_xattr_find(obj, name);
+       oxe = osp_oac_xattr_find(obj, name, false);
        if (oxe != NULL)
                return oxe;
 
@@ -148,9 +263,11 @@ osp_oac_xattr_find_or_add(struct osp_object *obj, const char *name, int len)
        atomic_set(&oxe->oxe_ref, 2);
 
        spin_lock(&obj->opo_lock);
-       tmp = osp_oac_xattr_find_locked(ooa, name, namelen, false);
+       tmp = osp_oac_xattr_find_locked(ooa, name, namelen);
        if (tmp == NULL)
                list_add_tail(&oxe->oxe_list, &ooa->ooa_xattr_list);
+       else
+               atomic_inc(&tmp->oxe_ref);
        spin_unlock(&obj->opo_lock);
 
        if (tmp != NULL) {
@@ -161,16 +278,31 @@ osp_oac_xattr_find_or_add(struct osp_object *obj, const char *name, int len)
        return oxe;
 }
 
+/**
+ * Add the given extended attribute to the OSP object attributes cache.
+ *
+ * If there is an old extended attributed entry with the same name,
+ * remove it from the cache and return it via the parameter \a poxe.
+ *
+ * \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
+ *                     via such pointer target, and if old the extended
+ *                     attribute entry exists, then it will be returned back
+ *                     via such pointer target.
+ * \param[in] len      the length of the (new) extended attribute value
+ *
+ * \retval             pointer to the new extended attribute entry
+ * \retval             NULL for failure cases.
+ */
 static struct osp_xattr_entry *
 osp_oac_xattr_replace(struct osp_object *obj,
-                     struct osp_xattr_entry **poxe, int len)
+                     struct osp_xattr_entry **poxe, size_t len)
 {
        struct osp_object_attr *ooa     = obj->opo_ooa;
-       struct osp_xattr_entry *old     = *poxe;
        struct osp_xattr_entry *oxe;
-       struct osp_xattr_entry *tmp     = NULL;
-       int                     namelen = old->oxe_namelen;
-       int                     size    = sizeof(*oxe) + namelen + 1 + len;
+       size_t                  namelen = (*poxe)->oxe_namelen;
+       size_t                  size    = sizeof(*oxe) + namelen + 1 + len;
 
        LASSERT(ooa != NULL);
 
@@ -181,22 +313,29 @@ osp_oac_xattr_replace(struct osp_object *obj,
        INIT_LIST_HEAD(&oxe->oxe_list);
        oxe->oxe_buflen = size;
        oxe->oxe_namelen = namelen;
-       memcpy(oxe->oxe_buf, old->oxe_buf, namelen);
+       memcpy(oxe->oxe_buf, (*poxe)->oxe_buf, namelen);
        oxe->oxe_value = oxe->oxe_buf + namelen + 1;
        /* One ref is for the caller, the other is for the entry on the list. */
        atomic_set(&oxe->oxe_ref, 2);
 
        spin_lock(&obj->opo_lock);
-       tmp = osp_oac_xattr_find_locked(ooa, oxe->oxe_buf, namelen, true);
+       *poxe = osp_oac_xattr_find_locked(ooa, oxe->oxe_buf, namelen);
+       LASSERT(*poxe != NULL);
+
+       list_del_init(&(*poxe)->oxe_list);
        list_add_tail(&oxe->oxe_list, &ooa->ooa_xattr_list);
        spin_unlock(&obj->opo_lock);
 
-       *poxe = tmp;
-       LASSERT(tmp != NULL);
-
        return oxe;
 }
 
+/**
+ * Release reference from the OSP object extended attribute entry.
+ *
+ * If it is the last reference, then free the entry.
+ *
+ * \param[in] oxe      pointer to the OSP object extended attribute entry.
+ */
 static inline void osp_oac_xattr_put(struct osp_xattr_entry *oxe)
 {
        if (atomic_dec_and_test(&oxe->oxe_ref)) {
@@ -206,8 +345,25 @@ static inline void osp_oac_xattr_put(struct osp_xattr_entry *oxe)
        }
 }
 
+/**
+ * Parse the OSP object attribute from the RPC reply.
+ *
+ * If the attribute is valid, then it will be added to the OSP object
+ * attributes cache.
+ *
+ * \param[in] env      pointer to the thread context
+ * \param[in] reply    pointer to the RPC reply
+ * \param[in] req      pointer to the RPC request
+ * \param[out] attr    pointer to buffer to hold the output attribute
+ * \param[in] obj      pointer to the OSP object
+ * \param[in] index    the index of the attribute buffer in the reply
+ *
+ * \retval             0 for success
+ * \retval             negative error number on failure
+ */
 static int osp_get_attr_from_reply(const struct lu_env *env,
-                                  struct update_reply *reply,
+                                  struct object_update_reply *reply,
+                                  struct ptlrpc_request *req,
                                   struct lu_attr *attr,
                                   struct osp_object *obj, int index)
 {
@@ -215,9 +371,9 @@ static int osp_get_attr_from_reply(const struct lu_env *env,
        struct lu_buf           *rbuf   = &osi->osi_lb2;
        struct obdo             *lobdo  = &osi->osi_obdo;
        struct obdo             *wobdo;
-       int                      rc;
+       int                     rc;
 
-       rc = update_get_reply_buf(reply, rbuf, index);
+       rc = object_update_result_data_get(reply, rbuf, index);
        if (rc < 0)
                return rc;
 
@@ -225,7 +381,10 @@ static int osp_get_attr_from_reply(const struct lu_env *env,
        if (rbuf->lb_len != sizeof(*wobdo))
                return -EPROTO;
 
-       obdo_le_to_cpu(wobdo, wobdo);
+       LASSERT(req != NULL);
+       if (ptlrpc_req_need_swab(req))
+               lustre_swab_obdo(wobdo);
+
        lustre_get_wire_obdo(NULL, lobdo, wobdo);
        spin_lock(&obj->opo_lock);
        if (obj->opo_ooa != NULL) {
@@ -242,8 +401,26 @@ static int osp_get_attr_from_reply(const struct lu_env *env,
        return 0;
 }
 
+/**
+ * Interpreter function for getting OSP object attribute asynchronously.
+ *
+ * Called to interpret the result of an async mode RPC for getting the
+ * OSP object attribute.
+ *
+ * \param[in] env      pointer to the thread context
+ * \param[in] reply    pointer to the RPC reply
+ * \param[in] req      pointer to the RPC request
+ * \param[in] obj      pointer to the OSP object
+ * \param[out] data    pointer to buffer to hold the output attribute
+ * \param[in] index    the index of the attribute buffer in the reply
+ * \param[in] rc       the result for handling the RPC
+ *
+ * \retval             0 for success
+ * \retval             negative error number on failure
+ */
 static int osp_attr_get_interpterer(const struct lu_env *env,
-                                   struct update_reply *reply,
+                                   struct object_update_reply *reply,
+                                   struct ptlrpc_request *req,
                                    struct osp_object *obj,
                                    void *data, int index, int rc)
 {
@@ -255,7 +432,8 @@ static int osp_attr_get_interpterer(const struct lu_env *env,
                osp2lu_obj(obj)->lo_header->loh_attr |= LOHA_EXISTS;
                obj->opo_non_exist = 0;
 
-               return osp_get_attr_from_reply(env, reply, NULL, obj, index);
+               return osp_get_attr_from_reply(env, reply, req, NULL, obj,
+                                              index);
        } else {
                if (rc == -ENOENT) {
                        osp2lu_obj(obj)->lo_header->loh_attr &= ~LOHA_EXISTS;
@@ -270,12 +448,28 @@ static int osp_attr_get_interpterer(const struct lu_env *env,
        return 0;
 }
 
+/**
+ * Implement OSP layer dt_object_operations::do_declare_attr_get() interface.
+ *
+ * Declare that the caller will get attribute from the specified OST object.
+ *
+ * This function adds an Object Unified Target (OUT) sub-request to the per-OSP
+ * based shared asynchronous request queue. The osp_attr_get_interpterer()
+ * is registered as the interpreter function to handle the result of this
+ * sub-request.
+ *
+ * \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)
 {
        struct osp_object       *obj    = dt2osp_obj(dt);
        struct osp_device       *osp    = lu2osp_dev(dt->do_lu.lo_dev);
-       struct update_request   *update;
        int                      rc     = 0;
 
        if (obj->opo_ooa == NULL) {
@@ -285,29 +479,42 @@ static int osp_declare_attr_get(const struct lu_env *env, struct dt_object *dt,
        }
 
        mutex_lock(&osp->opd_async_requests_mutex);
-       update = osp_find_or_create_async_update_request(osp);
-       if (IS_ERR(update))
-               rc = PTR_ERR(update);
-       else
-               rc = osp_insert_async_update(env, update, OBJ_ATTR_GET, obj, 0,
-                                            NULL, NULL,
-                                            &obj->opo_ooa->ooa_attr,
-                                            osp_attr_get_interpterer);
+       rc = osp_insert_async_request(env, OUT_ATTR_GET, obj, 0, NULL, NULL,
+                                     &obj->opo_ooa->ooa_attr,
+                                     osp_attr_get_interpterer);
        mutex_unlock(&osp->opd_async_requests_mutex);
 
        return rc;
 }
 
+/**
+ * Implement OSP layer dt_object_operations::do_attr_get() interface.
+ *
+ * Get attribute from the specified MDT/OST object.
+ *
+ * If the attribute is in the OSP object attributes cache, then return
+ * the cached attribute directly. Otherwise it will trigger an OUT RPC
+ * to the peer to get the attribute synchronously, if successful, add it
+ * to the OSP attributes cache. (\see lustre/osp/osp_trans.c for OUT RPC.)
+ *
+ * \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 osp_device       *osp    = lu2osp_dev(dt->do_lu.lo_dev);
-       struct osp_object       *obj    = dt2osp_obj(dt);
-       struct dt_device        *dev    = &osp->opd_dt_dev;
-       struct update_request   *update;
-       struct update_reply     *reply;
-       struct ptlrpc_request   *req    = NULL;
-       int                      rc     = 0;
+       struct osp_device               *osp = lu2osp_dev(dt->do_lu.lo_dev);
+       struct osp_object               *obj = dt2osp_obj(dt);
+       struct dt_device                *dev = &osp->opd_dt_dev;
+       struct dt_update_request        *update;
+       struct object_update_reply      *reply;
+       struct ptlrpc_request           *req = NULL;
+       int                             rc = 0;
        ENTRY;
 
        if (is_ost_obj(&dt->do_lu) && obj->opo_non_exist)
@@ -324,12 +531,12 @@ int osp_attr_get(const struct lu_env *env, struct dt_object *dt,
                spin_unlock(&obj->opo_lock);
        }
 
-       update = out_create_update_req(dev);
+       update = dt_update_request_create(dev);
        if (IS_ERR(update))
                RETURN(PTR_ERR(update));
 
-       rc = out_insert_update(env, update, OBJ_ATTR_GET,
-                              lu_object_fid(&dt->do_lu), 0, NULL, NULL);
+       rc = out_attr_get_pack(env, &update->dur_buf,
+                              lu_object_fid(&dt->do_lu));
        if (rc != 0) {
                CERROR("%s: Insert update error "DFID": rc = %d\n",
                       dev->dd_lu_dev.ld_obd->obd_name,
@@ -354,47 +561,40 @@ int osp_attr_get(const struct lu_env *env, struct dt_object *dt,
 
        osp2lu_obj(obj)->lo_header->loh_attr |= LOHA_EXISTS;
        obj->opo_non_exist = 0;
-       reply = req_capsule_server_sized_get(&req->rq_pill, &RMF_UPDATE_REPLY,
-                                            UPDATE_BUFFER_SIZE);
-       if (reply == NULL || reply->ur_version != UPDATE_REPLY_V1)
+       reply = req_capsule_server_sized_get(&req->rq_pill,
+                                            &RMF_OUT_UPDATE_REPLY,
+                                            OUT_UPDATE_REPLY_SIZE);
+       if (reply == NULL || reply->ourp_magic != UPDATE_REPLY_MAGIC)
                GOTO(out, rc = -EPROTO);
 
-       rc = osp_get_attr_from_reply(env, reply, attr, obj, 0);
+       rc = osp_get_attr_from_reply(env, reply, req, attr, obj, 0);
        if (rc != 0)
                GOTO(out, rc);
 
-       if (!is_ost_obj(&dt->do_lu)) {
-               if (attr->la_flags == 1)
-                       obj->opo_empty = 0;
-               else
-                       obj->opo_empty = 1;
-       }
-
        GOTO(out, rc = 0);
 
 out:
        if (req != NULL)
                ptlrpc_req_finished(req);
 
-       out_destroy_update_req(update);
+       dt_update_request_destroy(update);
 
        return rc;
 }
 
-static int osp_declare_attr_set(const struct lu_env *env, struct dt_object *dt,
-                               const struct lu_attr *attr, struct thandle *th)
+static int __osp_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;
 
        /*
         * Usually we don't allow server stack to manipulate size
         * but there is a special case when striping is created
-        * late, after stripless file got truncated to non-zero.
+        * late, after stripeless file got truncated to non-zero.
         *
         * In this case we do the following:
         *
@@ -423,10 +623,9 @@ static int osp_declare_attr_set(const struct lu_env *env, struct dt_object *dt,
                        RETURN(rc);
        }
 
-       if (o->opo_new) {
+       if (o->opo_new)
                /* no need in logging for new objects being created */
                RETURN(0);
-       }
 
        if (!(attr->la_valid & (LA_UID | LA_GID)))
                RETURN(0);
@@ -444,6 +643,7 @@ static int osp_declare_attr_set(const struct lu_env *env, struct dt_object *dt,
        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) {
@@ -460,15 +660,94 @@ static int osp_declare_attr_set(const struct lu_env *env, struct dt_object *dt,
        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);
+
+       return rc;
+}
+
+/**
+ * Implement OSP layer dt_object_operations::do_attr_set() interface.
+ *
+ * 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 attribute entry exists in the OSP object attributes cache,
+ * then update the cached attribute according to given attribute.
+ *
+ * \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
+ * \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)
 {
        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)
+                       RETURN(rc);
+       }
+
        /* we're interested in uid/gid changes only */
        if (!(attr->la_valid & (LA_UID | LA_GID)))
                RETURN(0);
@@ -497,8 +776,26 @@ static int osp_attr_set(const struct lu_env *env, struct dt_object *dt,
        RETURN(rc);
 }
 
+/**
+ * Interpreter function for getting OSP object extended attribute asynchronously
+ *
+ * Called to interpret the result of an async mode RPC for getting the
+ * OSP object extended attribute.
+ *
+ * \param[in] env      pointer to the thread context
+ * \param[in] reply    pointer to the RPC reply
+ * \param[in] req      pointer to the RPC request
+ * \param[in] obj      pointer to the OSP object
+ * \param[out] data    pointer to OSP object attributes cache
+ * \param[in] index    the index of the attribute buffer in the reply
+ * \param[in] rc       the result for handling the RPC
+ *
+ * \retval             0 for success
+ * \retval             negative error number on failure
+ */
 static int osp_xattr_get_interpterer(const struct lu_env *env,
-                                    struct update_reply *reply,
+                                    struct object_update_reply *reply,
+                                    struct ptlrpc_request *req,
                                     struct osp_object *obj,
                                     void *data, int index, int rc)
 {
@@ -509,9 +806,9 @@ static int osp_xattr_get_interpterer(const struct lu_env *env,
        LASSERT(ooa != NULL);
 
        if (rc == 0) {
-               int len = sizeof(*oxe) + oxe->oxe_namelen + 1;
+               size_t len = sizeof(*oxe) + oxe->oxe_namelen + 1;
 
-               rc = update_get_reply_buf(reply, rbuf, index);
+               rc = object_update_result_data_get(reply, rbuf, index);
                if (rc < 0 || rbuf->lb_len > (oxe->oxe_buflen - len)) {
                        spin_lock(&obj->opo_lock);
                        oxe->oxe_ready = 0;
@@ -543,15 +840,33 @@ static int osp_xattr_get_interpterer(const struct lu_env *env,
        return 0;
 }
 
+/**
+ * Implement OSP dt_object_operations::do_declare_xattr_get() interface.
+ *
+ * Declare that the caller will get extended attribute from the specified
+ * OST object.
+ *
+ * This function will add an OUT_XATTR_GET sub-request to the per OSP
+ * based shared asynchronous request queue with the interpreter function:
+ * osp_xattr_get_interpterer().
+ *
+ * \param[in] env      pointer to the thread context
+ * \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 osp_object       *obj     = dt2osp_obj(dt);
        struct osp_device       *osp     = lu2osp_dev(dt->do_lu.lo_dev);
-       struct update_request   *update;
        struct osp_xattr_entry  *oxe;
-       int                      namelen = strlen(name);
+       __u16                    namelen = strlen(name);
        int                      rc      = 0;
 
        LASSERT(buf != NULL);
@@ -572,39 +887,58 @@ static int osp_declare_xattr_get(const struct lu_env *env, struct dt_object *dt,
                return -ENOMEM;
 
        mutex_lock(&osp->opd_async_requests_mutex);
-       update = osp_find_or_create_async_update_request(osp);
-       if (IS_ERR(update)) {
-               rc = PTR_ERR(update);
+       rc = osp_insert_async_request(env, OUT_XATTR_GET, obj, 1,
+                                     &namelen, (const void **)&name, oxe,
+                                     osp_xattr_get_interpterer);
+       if (rc != 0) {
                mutex_unlock(&osp->opd_async_requests_mutex);
                osp_oac_xattr_put(oxe);
        } else {
-               rc = osp_insert_async_update(env, update, OBJ_XATTR_GET, obj,
-                                            1, &namelen, &name, oxe,
-                                            osp_xattr_get_interpterer);
-               if (rc != 0) {
+               struct dt_update_request *update;
+
+               /* XXX: Currently, we trigger the batched async OUT
+                *      RPC via dt_declare_xattr_get(). It is not
+                *      perfect solution, but works well now.
+                *
+                *      We will improve it in the future. */
+               update = osp->opd_async_requests;
+               if (update != NULL && update->dur_buf.ub_req != NULL &&
+                   update->dur_buf.ub_req->ourq_count > 0) {
+                       osp->opd_async_requests = NULL;
                        mutex_unlock(&osp->opd_async_requests_mutex);
-                       osp_oac_xattr_put(oxe);
+                       rc = osp_unplug_async_request(env, osp, update);
                } else {
-                       /* XXX: Currently, we trigger the batched async OUT
-                        *      RPC via dt_declare_xattr_get(). It is not
-                        *      perfect solution, but works well now.
-                        *
-                        *      We will improve it in the future. */
-                       update = osp->opd_async_requests;
-                       if (update != NULL && update->ur_buf != NULL &&
-                           update->ur_buf->ub_count > 0) {
-                               osp->opd_async_requests = NULL;
-                               mutex_unlock(&osp->opd_async_requests_mutex);
-                               rc = osp_unplug_async_update(env, osp, update);
-                       } else {
-                               mutex_unlock(&osp->opd_async_requests_mutex);
-                       }
+                       mutex_unlock(&osp->opd_async_requests_mutex);
                }
        }
 
        return rc;
 }
 
+/**
+ * Implement OSP layer dt_object_operations::do_xattr_get() interface.
+ *
+ * Get extended attribute from the specified MDT/OST object.
+ *
+ * If the extended attribute is in the OSP object attributes cache, then
+ * return the cached extended attribute directly. Otherwise it will get
+ * the extended attribute synchronously, if successful, add it to the OSP
+ * attributes cache. (\see lustre/osp/osp_trans.c for OUT RPC.)
+ *
+ * There is a race condition: some other thread has added the named extended
+ * attributed entry to the OSP object attributes cache during the current
+ * OUT_XATTR_GET handling. If such case happens, the OSP will replace the
+ * (just) existing extended attribute entry with the new replied one.
+ *
+ * \param[in] env      pointer to the thread context
+ * \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)
@@ -613,22 +947,32 @@ int osp_xattr_get(const struct lu_env *env, struct dt_object *dt,
        struct osp_object       *obj    = dt2osp_obj(dt);
        struct dt_device        *dev    = &osp->opd_dt_dev;
        struct lu_buf           *rbuf   = &osp_env_info(env)->osi_lb2;
-       struct update_request   *update = NULL;
+       struct dt_update_request *update = NULL;
        struct ptlrpc_request   *req    = NULL;
-       struct update_reply     *reply;
+       struct object_update_reply *reply;
        struct osp_xattr_entry  *oxe    = NULL;
        const char              *dname  = dt->do_lu.lo_dev->ld_obd->obd_name;
-       int                      namelen;
        int                      rc     = 0;
        ENTRY;
 
        LASSERT(buf != NULL);
        LASSERT(name != NULL);
 
+       if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_NETWORK) &&
+           osp->opd_index == cfs_fail_val) {
+               if (is_ost_obj(&dt->do_lu)) {
+                       if (osp_dev2node(osp) == cfs_fail_val)
+                               RETURN(-ENOTCONN);
+               } else {
+                       if (strcmp(name, XATTR_NAME_LINK) == 0)
+                               RETURN(-ENOTCONN);
+               }
+       }
+
        if (unlikely(obj->opo_non_exist))
                RETURN(-ENOENT);
 
-       oxe = osp_oac_xattr_find(obj, name);
+       oxe = osp_oac_xattr_find(obj, name, false);
        if (oxe != NULL) {
                spin_lock(&obj->opo_lock);
                if (oxe->oxe_ready) {
@@ -654,22 +998,25 @@ unlock:
                spin_unlock(&obj->opo_lock);
        }
 
-       update = out_create_update_req(dev);
+       update = dt_update_request_create(dev);
        if (IS_ERR(update))
                GOTO(out, rc = PTR_ERR(update));
 
-       namelen = strlen(name);
-       rc = out_insert_update(env, update, OBJ_XATTR_GET,
-                              lu_object_fid(&dt->do_lu), 1, &namelen, &name);
+       rc = out_xattr_get_pack(env, &update->dur_buf,
+                               lu_object_fid(&dt->do_lu), name);
        if (rc != 0) {
                CERROR("%s: Insert update error "DFID": rc = %d\n",
                       dname, PFID(lu_object_fid(&dt->do_lu)), rc);
-
                GOTO(out, rc);
        }
 
        rc = out_remote_sync(env, osp->opd_obd->u.cli.cl_import, update, &req);
        if (rc != 0) {
+               if (rc == -ENOENT) {
+                       dt->do_lu.lo_header->loh_attr &= ~LOHA_EXISTS;
+                       obj->opo_non_exist = 1;
+               }
+
                if (obj->opo_ooa == NULL)
                        GOTO(out, rc);
 
@@ -696,22 +1043,21 @@ unlock:
                GOTO(out, rc);
        }
 
-       reply = req_capsule_server_sized_get(&req->rq_pill, &RMF_UPDATE_REPLY,
-                                           UPDATE_BUFFER_SIZE);
-       if (reply->ur_version != UPDATE_REPLY_V1) {
+       reply = req_capsule_server_sized_get(&req->rq_pill,
+                                            &RMF_OUT_UPDATE_REPLY,
+                                            OUT_UPDATE_REPLY_SIZE);
+       if (reply->ourp_magic != UPDATE_REPLY_MAGIC) {
                CERROR("%s: Wrong version %x expected %x "DFID": rc = %d\n",
-                      dname, reply->ur_version, UPDATE_REPLY_V1,
+                      dname, reply->ourp_magic, UPDATE_REPLY_MAGIC,
                       PFID(lu_object_fid(&dt->do_lu)), -EPROTO);
 
                GOTO(out, rc = -EPROTO);
        }
 
-       rc = update_get_reply_buf(reply, rbuf, 0);
+       rc = object_update_result_data_get(reply, rbuf, 0);
        if (rc < 0)
                GOTO(out, rc);
 
-       LASSERT(rbuf->lb_len > 0 && rbuf->lb_len < PAGE_CACHE_SIZE);
-
        if (buf->lb_buf == NULL)
                GOTO(out, rc = rbuf->lb_len);
 
@@ -746,7 +1092,7 @@ unlock:
                              "cache for "DFID": rc = %d\n",
                              dname, name, PFID(lu_object_fid(&dt->do_lu)), rc);
                        spin_lock(&obj->opo_lock);
-                       oxe->oxe_ready = 0;
+                       old->oxe_ready = 0;
                        spin_unlock(&obj->opo_lock);
 
                        GOTO(out, rc);
@@ -770,7 +1116,7 @@ out:
                ptlrpc_req_finished(req);
 
        if (update != NULL && !IS_ERR(update))
-               out_destroy_update_req(update);
+               dt_update_request_destroy(update);
 
        if (oxe != NULL)
                osp_oac_xattr_put(oxe);
@@ -778,47 +1124,41 @@ out:
        return rc;
 }
 
-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)
+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)
 {
-       struct osp_object       *o       = dt2osp_obj(dt);
-       struct update_request   *update;
-       struct lu_fid           *fid;
+       struct osp_object       *o = dt2osp_obj(dt);
+       struct dt_update_request *update;
        struct osp_xattr_entry  *oxe;
-       int                     sizes[3] = {strlen(name), buf->lb_len,
-                                           sizeof(int)};
-       char                    *bufs[3] = {(char *)name, (char *)buf->lb_buf };
        int                     rc;
+       ENTRY;
 
        LASSERT(buf->lb_len > 0 && buf->lb_buf != NULL);
 
-       update = out_find_create_update_loc(th, dt);
+       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);
+               RETURN(PTR_ERR(update));
        }
 
-       flag = cpu_to_le32(flag);
-       bufs[2] = (char *)&flag;
-
-       fid = (struct lu_fid *)lu_object_fid(&dt->do_lu);
-       rc = out_insert_update(env, update, OBJ_XATTR_SET, fid,
-                              ARRAY_SIZE(sizes), sizes, (const char **)bufs);
+       rc = out_xattr_set_pack(env, &update->dur_buf,
+                               lu_object_fid(&dt->do_lu),
+                               buf, name, flag, 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
-                     ": rc = %d\n", dt->do_lu.lo_dev->ld_obd->obd_name,
-                     name, PFID(lu_object_fid(&dt->do_lu)), rc);
+               CWARN("%s: Fail to add xattr (%s) to cache for "DFID,
+                     dt->do_lu.lo_dev->ld_obd->obd_name,
+                     name, PFID(lu_object_fid(&dt->do_lu)));
 
-               return 0;
+               RETURN(0);
        }
 
        if (oxe->oxe_buflen - oxe->oxe_namelen - 1 < buf->lb_len) {
@@ -829,14 +1169,14 @@ int osp_declare_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
-                             ": rc = %d\n", dt->do_lu.lo_dev->ld_obd->obd_name,
-                             name, PFID(lu_object_fid(&dt->do_lu)), rc);
+                       CWARN("%s: Fail to update xattr (%s) to cache for "DFID,
+                             dt->do_lu.lo_dev->ld_obd->obd_name,
+                             name, PFID(lu_object_fid(&dt->do_lu)));
                        spin_lock(&o->opo_lock);
-                       oxe->oxe_ready = 0;
+                       old->oxe_ready = 0;
                        spin_unlock(&o->opo_lock);
 
-                       return 0;
+                       RETURN(0);
                }
 
                /* Drop the ref for entry on list. */
@@ -851,19 +1191,208 @@ int osp_declare_xattr_set(const struct lu_env *env, struct dt_object *dt,
        spin_unlock(&o->opo_lock);
        osp_oac_xattr_put(oxe);
 
-       return 0;
+       RETURN(0);
 }
 
+/**
+ * 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.
+ *
+ * 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.
+ *
+ * \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 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;
+}
+
+/**
+ * Implement OSP layer dt_object_operations::do_xattr_set() interface.
+ *
+ * Set extended attribute to 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 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
+ * \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)
+{
+       struct dt_update_request *update;
+       const struct lu_fid      *fid;
+       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);
+
+       rc = out_xattr_del_pack(env, &update->dur_buf, fid, name,
+                               update->dur_batchid);
+
+       if (rc != 0 || o->opo_ooa == NULL)
+               return rc;
+
+       oxe = osp_oac_xattr_find(o, name, true);
+       if (oxe != NULL)
+               /* Drop the ref for entry on list. */
+               osp_oac_xattr_put(oxe);
+
        return 0;
 }
 
+/**
+ * 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.
+ *
+ * \param[in] env      pointer to the thread context
+ * \param[in] dt       pointer to the OSP layer dt_object
+ * \param[in] attr     the attribute for the object to be created
+ * \param[in] hint     pointer to the hint for creating the object, such as
+ *                     the parent object
+ * \param[in] dof      pointer to the dt_object_format for help the creation
+ * \param[in] th       pointer to the transaction handler
+ *
+ * \retval             0 for success
+ * \retval             negative error number on failure
+ */
 static int osp_declare_object_create(const struct lu_env *env,
                                     struct dt_object *dt,
                                     struct lu_attr *attr,
@@ -906,9 +1435,10 @@ static int osp_declare_object_create(const struct lu_env *env,
        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,
-                                            sizeof(osi->osi_id), osi->osi_off,
-                                            th);
+                                            &osi->osi_lb, osi->osi_off, th);
                RETURN(rc);
        }
 
@@ -930,9 +1460,10 @@ static int osp_declare_object_create(const struct lu_env *env,
 
                /* common for all OSPs file hystorically */
                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,
-                                            sizeof(osi->osi_id), osi->osi_off,
-                                            th);
+                                            &osi->osi_lb, osi->osi_off, th);
        } else {
                /* not needed in the cache anymore */
                set_bit(LU_OBJECT_HEARD_BANSHEE,
@@ -941,6 +1472,30 @@ static int osp_declare_object_create(const struct lu_env *env,
        RETURN(rc);
 }
 
+/**
+ * Implement OSP layer dt_object_operations::do_create() interface.
+ *
+ * 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
+ * object to be created, and update last_used Object ID (OID) file.
+ *
+ * \param[in] env      pointer to the thread context
+ * \param[in] dt       pointer to the OSP layer dt_object
+ * \param[in] attr     the attribute for the object to be created
+ * \param[in] hint     pointer to the hint for creating the object, such as
+ *                     the parent object
+ * \param[in] dof      pointer to the dt_object_format for help the creation
+ * \param[in] th       pointer to the transaction handler
+ *
+ * \retval             0 for success
+ * \retval             negative error number on failure
+ */
 static int osp_object_create(const struct lu_env *env, struct dt_object *dt,
                             struct lu_attr *attr,
                             struct dt_allocation_hint *hint,
@@ -965,7 +1520,7 @@ static int osp_object_create(const struct lu_env *env, struct dt_object *dt,
 
        o->opo_non_exist = 0;
        if (o->opo_reserved) {
-               /* regular case, fid is assigned holding trunsaction open */
+               /* regular case, fid is assigned holding transaction open */
                 osp_object_assign_fid(env, d, o);
        }
 
@@ -1011,7 +1566,7 @@ static int osp_object_create(const struct lu_env *env, struct dt_object *dt,
                        d->opd_gap_count = 0;
                        spin_unlock(&d->opd_pre_lock);
 
-                       CDEBUG(D_HA, "Writting gap "DFID"+%d in llog\n",
+                       CDEBUG(D_HA, "Writing gap "DFID"+%d in llog\n",
                               PFID(&d->opd_gap_start_fid), count);
                        /* real gap handling is disabled intil ORI-692 will be
                         * fixed, now we only report gaps */
@@ -1038,6 +1593,21 @@ static int osp_object_create(const struct lu_env *env, struct dt_object *dt,
        RETURN(rc);
 }
 
+/**
+ * Implement OSP layer dt_object_operations::do_declare_destroy() interface.
+ *
+ * Declare that the caller will destroy the specified OST object.
+ *
+ * The OST object destroy will be handled via llog asynchronously. This
+ * function will declare the credits for generating MDS_UNLINK64_REC llog.
+ *
+ * \param[in] env      pointer to the thread context
+ * \param[in] dt       pointer to the OSP layer dt_object to be destroyed
+ * \param[in] th       pointer to the transaction handler
+ *
+ * \retval             0 for success
+ * \retval             negative error number on failure
+ */
 int osp_declare_object_destroy(const struct lu_env *env,
                               struct dt_object *dt, struct thandle *th)
 {
@@ -1054,6 +1624,23 @@ int osp_declare_object_destroy(const struct lu_env *env,
        RETURN(rc);
 }
 
+/**
+ * Implement OSP layer dt_object_operations::do_destroy() interface.
+ *
+ * Destroy the specified OST object.
+ *
+ * The OSP generates a MDS_UNLINK64_REC record in the llog. There
+ * will be some dedicated thread to handle the llog asynchronously.
+ *
+ * It also marks the object as non-cached.
+ *
+ * \param[in] env      pointer to the thread context
+ * \param[in] dt       pointer to the OSP layer dt_object to be destroyed
+ * \param[in] th       pointer to the transaction handler
+ *
+ * \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)
 {
@@ -1075,21 +1662,6 @@ int osp_object_destroy(const struct lu_env *env, struct dt_object *dt,
        RETURN(rc);
 }
 
-struct osp_orphan_it {
-       int                       ooi_pos0;
-       int                       ooi_pos1;
-       int                       ooi_pos2;
-       int                       ooi_total_npages;
-       int                       ooi_valid_npages;
-       unsigned int              ooi_swab:1;
-       __u64                     ooi_next;
-       struct dt_object         *ooi_obj;
-       struct lu_orphan_ent     *ooi_ent;
-       struct page              *ooi_cur_page;
-       struct lu_idxpage        *ooi_cur_idxpage;
-       struct page             **ooi_pages;
-};
-
 static int osp_orphan_index_lookup(const struct lu_env *env,
                                   struct dt_object *dt,
                                   struct dt_rec *rec,
@@ -1136,30 +1708,44 @@ static int osp_orphan_index_delete(const struct lu_env *env,
        return -EOPNOTSUPP;
 }
 
-static struct dt_it *osp_orphan_it_init(const struct lu_env *env,
-                                       struct dt_object *dt,
-                                       __u32 attr,
-                                       struct lustre_capa *capa)
+/**
+ * Initialize the OSP layer index iteration.
+ *
+ * \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)
 {
-       struct osp_orphan_it *it;
+       struct osp_it *it;
 
        OBD_ALLOC_PTR(it);
        if (it == NULL)
                return ERR_PTR(-ENOMEM);
 
-       it->ooi_pos2 = -1;
+       it->ooi_pos_ent = -1;
        it->ooi_obj = dt;
 
        return (struct dt_it *)it;
 }
 
-static void osp_orphan_it_fini(const struct lu_env *env,
-                              struct dt_it *di)
+/**
+ * Finalize the OSP layer index iteration.
+ *
+ * \param[in] env      pointer to the thread context
+ * \param[in] di       pointer to the iteration structure
+ */
+void osp_it_fini(const struct lu_env *env, struct dt_it *di)
 {
-       struct osp_orphan_it     *it            = (struct osp_orphan_it *)di;
-       struct page             **pages         = it->ooi_pages;
-       int                       npages        = it->ooi_total_npages;
-       int                       i;
+       struct osp_it   *it = (struct osp_it *)di;
+       struct page     **pages = it->ooi_pages;
+       int             npages = it->ooi_total_npages;
+       int             i;
 
        if (pages != NULL) {
                for (i = 0; i < npages; i++) {
@@ -1176,8 +1762,19 @@ static void osp_orphan_it_fini(const struct lu_env *env,
        OBD_FREE_PTR(it);
 }
 
-static int osp_orphan_it_fetch(const struct lu_env *env,
-                              struct osp_orphan_it *it)
+/**
+ * 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.
+ *
+ * \param[in] env      pointer to the thread context
+ * \param[in] it       pointer to the iteration structure
+ *
+ * \retval             0 for success
+ * \retval             negative error number on failure
+ */
+static int osp_it_fetch(const struct lu_env *env, struct osp_it *it)
 {
        struct lu_device         *dev   = it->ooi_obj->do_lu.lo_dev;
        struct osp_device        *osp   = lu2osp_dev(dev);
@@ -1217,7 +1814,27 @@ static int osp_orphan_it_fetch(const struct lu_env *env,
                RETURN(rc);
        }
 
-       req->rq_request_portal = OST_IDX_PORTAL;
+       req->rq_request_portal = OUT_PORTAL;
+       ii = req_capsule_client_get(&req->rq_pill, &RMF_IDX_INFO);
+       memset(ii, 0, sizeof(*ii));
+       if (fid_is_last_id(lu_object_fid(&it->ooi_obj->do_lu))) {
+               /* LFSCK will iterate orphan object[FID_SEQ_LAYOUT_BTREE,
+                * ost_index, 0] with LAST_ID FID, so it needs to replace
+                * the FID with orphan FID here */
+               ii->ii_fid.f_seq = FID_SEQ_LAYOUT_RBTREE;
+               ii->ii_fid.f_oid = osp->opd_index;
+               ii->ii_fid.f_ver = 0;
+               ii->ii_flags = II_FL_NOHASH;
+       } 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_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);
 
        desc = ptlrpc_prep_bulk_imp(req, npages, 1, BULK_PUT_SINK,
@@ -1230,18 +1847,6 @@ static int osp_orphan_it_fetch(const struct lu_env *env,
        for (i = 0; i < npages; i++)
                ptlrpc_prep_bulk_page_pin(desc, pages[i], 0, PAGE_CACHE_SIZE);
 
-       ii = req_capsule_client_get(&req->rq_pill, &RMF_IDX_INFO);
-       memset(ii, 0, sizeof(*ii));
-       ii->ii_fid.f_seq = FID_SEQ_LAYOUT_RBTREE;
-       ii->ii_fid.f_oid = osp->opd_index;
-       ii->ii_fid.f_ver = 0;
-       ii->ii_magic = IDX_INFO_MAGIC;
-       ii->ii_flags = II_FL_NOHASH;
-       ii->ii_count = npages * LU_PAGE_COUNT;
-       ii->ii_hash_start = it->ooi_next;
-       ii->ii_attrs =
-               osp->opd_storage->dd_lu_dev.ld_site->ld_seq_site->ss_node_id;
-
        ptlrpc_request_set_replen(req);
        rc = ptlrpc_queue_wait(req);
        if (rc != 0)
@@ -1251,6 +1856,7 @@ static int osp_orphan_it_fetch(const struct lu_env *env,
                                          req->rq_bulk->bd_nob_transferred);
        if (rc < 0)
                GOTO(out, rc);
+       rc = 0;
 
        ii = req_capsule_server_get(&req->rq_pill, &RMF_IDX_INFO);
        if (ii->ii_magic != IDX_INFO_MAGIC)
@@ -1270,22 +1876,36 @@ static int osp_orphan_it_fetch(const struct lu_env *env,
 
        it->ooi_next = ii->ii_hash_end;
 
-       GOTO(out, rc = 0);
-
 out:
        ptlrpc_req_finished(req);
 
        return rc;
 }
 
-static int osp_orphan_it_next(const struct lu_env *env,
-                             struct dt_it *di)
+/**
+ * Move the iteration cursor to the next lu_page.
+ *
+ * One system page (PAGE_SIZE) may contain multiple lu_page (4KB),
+ * that depends on the LU_PAGE_COUNT. If it is not the last lu_page
+ * in current system page, then move the iteration cursor to the next
+ * lu_page in current system page. Otherwise, if there are more system
+ * pages in the cache, then move the iteration cursor to the next system
+ * page. If all the cached records (pages) have been iterated, then fetch
+ * more records via osp_it_fetch().
+ *
+ * \param[in] env      pointer to the thread context
+ * \param[in] di       pointer to the iteration structure
+ *
+ * \retval             0 for success
+ * \retval             negative error number on failure
+ */
+int osp_it_next_page(const struct lu_env *env, struct dt_it *di)
 {
-       struct osp_orphan_it     *it            = (struct osp_orphan_it *)di;
-       struct lu_idxpage        *idxpage;
+       struct osp_it           *it = (struct osp_it *)di;
+       struct lu_idxpage       *idxpage;
        struct page             **pages;
-       int                       rc;
-       int                       i;
+       int                     rc;
+       int                     i;
        ENTRY;
 
 again2:
@@ -1294,23 +1914,17 @@ again2:
                if (idxpage->lip_nr == 0)
                        RETURN(1);
 
-               it->ooi_pos2++;
-               if (it->ooi_pos2 < idxpage->lip_nr) {
-                       it->ooi_ent =
-                               (struct lu_orphan_ent *)idxpage->lip_entries +
-                               it->ooi_pos2;
-                       if (it->ooi_swab)
-                               lustre_swab_orphan_ent(it->ooi_ent);
+               if (it->ooi_pos_ent < idxpage->lip_nr) {
+                       CDEBUG(D_INFO, "ooi_pos %d nr %d\n",
+                              (int)it->ooi_pos_ent, (int)idxpage->lip_nr);
                        RETURN(0);
                }
-
                it->ooi_cur_idxpage = NULL;
-               it->ooi_pos1++;
-
+               it->ooi_pos_lu_page++;
 again1:
-               if (it->ooi_pos1 < LU_PAGE_COUNT) {
+               if (it->ooi_pos_lu_page < LU_PAGE_COUNT) {
                        it->ooi_cur_idxpage = (void *)it->ooi_cur_page +
-                                             LU_PAGE_SIZE * it->ooi_pos1;
+                                        LU_PAGE_SIZE * it->ooi_pos_lu_page;
                        if (it->ooi_swab)
                                lustre_swab_lip_header(it->ooi_cur_idxpage);
                        if (it->ooi_cur_idxpage->lip_magic != LIP_MAGIC) {
@@ -1321,24 +1935,25 @@ again1:
                                       "%d/%d while read layout orphan index\n",
                                       osp->opd_obd->obd_name,
                                       it->ooi_cur_idxpage->lip_magic,
-                                      LIP_MAGIC, it->ooi_pos0, it->ooi_pos1);
+                                      LIP_MAGIC, it->ooi_pos_page,
+                                      it->ooi_pos_lu_page);
                                /* Skip this lu_page next time. */
-                               it->ooi_pos2 = idxpage->lip_nr - 1;
+                               it->ooi_pos_ent = idxpage->lip_nr - 1;
                                RETURN(-EINVAL);
                        }
-                       it->ooi_pos2 = -1;
+                       it->ooi_pos_ent = -1;
                        goto again2;
                }
 
                kunmap(it->ooi_cur_page);
                it->ooi_cur_page = NULL;
-               it->ooi_pos0++;
+               it->ooi_pos_page++;
 
 again0:
                pages = it->ooi_pages;
-               if (it->ooi_pos0 < it->ooi_valid_npages) {
-                       it->ooi_cur_page = kmap(pages[it->ooi_pos0]);
-                       it->ooi_pos1 = 0;
+               if (it->ooi_pos_page < it->ooi_valid_npages) {
+                       it->ooi_cur_page = kmap(pages[it->ooi_pos_page]);
+                       it->ooi_pos_lu_page = 0;
                        goto again1;
                }
 
@@ -1348,7 +1963,7 @@ again0:
                }
                OBD_FREE(pages, it->ooi_total_npages * sizeof(*pages));
 
-               it->ooi_pos0 = 0;
+               it->ooi_pos_page = 0;
                it->ooi_total_npages = 0;
                it->ooi_valid_npages = 0;
                it->ooi_swab = 0;
@@ -1361,30 +1976,72 @@ again0:
        if (it->ooi_next == II_END_OFF)
                RETURN(1);
 
-       rc = osp_orphan_it_fetch(env, it);
+       rc = osp_it_fetch(env, it);
        if (rc == 0)
                goto again0;
 
        RETURN(rc);
 }
 
-static int osp_orphan_it_get(const struct lu_env *env,
-                            struct dt_it *di,
-                            const struct dt_key *key)
+/**
+ * Move the iteration cursor to the next record.
+ *
+ * If there are more records in the lu_page, then move the iteration
+ * cursor to the next record directly. Otherwise, move the iteration
+ * cursor to the record in the next lu_page via osp_it_next_page()
+ *
+ * \param[in] env      pointer to the thread context
+ * \param[in] di       pointer to the iteration structure
+ *
+ * \retval             0 for success
+ * \retval             negative error number on failure
+ */
+int osp_orphan_it_next(const struct lu_env *env, struct dt_it *di)
 {
-       return -ENOSYS;
+       struct osp_it           *it = (struct osp_it *)di;
+       struct lu_idxpage       *idxpage;
+       int                     rc;
+       ENTRY;
+
+again:
+       idxpage = it->ooi_cur_idxpage;
+       if (idxpage != NULL) {
+               if (idxpage->lip_nr == 0)
+                       RETURN(1);
+
+               it->ooi_pos_ent++;
+               if (it->ooi_pos_ent < idxpage->lip_nr) {
+                       it->ooi_ent =
+                               (struct lu_orphan_ent *)idxpage->lip_entries +
+                                                       it->ooi_pos_ent;
+                       if (it->ooi_swab)
+                               lustre_swab_orphan_ent(it->ooi_ent);
+                       RETURN(0);
+               }
+       }
+
+       rc = osp_it_next_page(env, di);
+       if (rc == 0)
+               goto again;
+
+       RETURN(rc);
+}
+
+int osp_it_get(const struct lu_env *env, struct dt_it *di,
+              const struct dt_key *key)
+{
+       return 1;
 }
 
-static void osp_orphan_it_put(const struct lu_env *env,
-                             struct dt_it *di)
+void osp_it_put(const struct lu_env *env, struct dt_it *di)
 {
 }
 
-static struct dt_key *osp_orphan_it_key(const struct lu_env *env,
-                                       const struct dt_it *di)
+struct dt_key *osp_orphan_it_key(const struct lu_env *env,
+                                const struct dt_it *di)
 {
-       struct osp_orphan_it    *it  = (struct osp_orphan_it *)di;
-       struct lu_orphan_ent    *ent = it->ooi_ent;
+       struct osp_it   *it  = (struct osp_it *)di;
+       struct lu_orphan_ent    *ent = (struct lu_orphan_ent *)it->ooi_ent;
 
        if (likely(ent != NULL))
                return (struct dt_key *)(&ent->loe_key);
@@ -1392,19 +2049,16 @@ static struct dt_key *osp_orphan_it_key(const struct lu_env *env,
        return NULL;
 }
 
-static int osp_orphan_it_key_size(const struct lu_env *env,
-                                 const struct dt_it *di)
+int osp_orphan_it_key_size(const struct lu_env *env, const struct dt_it *di)
 {
        return sizeof(struct lu_fid);
 }
 
-static int osp_orphan_it_rec(const struct lu_env *env,
-                            const struct dt_it *di,
-                            struct dt_rec *rec,
-                            __u32 attr)
+int osp_orphan_it_rec(const struct lu_env *env, const struct dt_it *di,
+                     struct dt_rec *rec, __u32 attr)
 {
-       struct osp_orphan_it    *it  = (struct osp_orphan_it *)di;
-       struct lu_orphan_ent    *ent = it->ooi_ent;
+       struct osp_it   *it  = (struct osp_it *)di;
+       struct lu_orphan_ent    *ent = (struct lu_orphan_ent *)it->ooi_ent;
 
        if (likely(ent != NULL)) {
                *(struct lu_orphan_rec *)rec = ent->loe_rec;
@@ -1414,26 +2068,30 @@ static int osp_orphan_it_rec(const struct lu_env *env,
        return -EINVAL;
 }
 
-static __u64 osp_orphan_it_store(const struct lu_env *env,
-                                const struct dt_it *di)
+__u64 osp_it_store(const struct lu_env *env, const struct dt_it *di)
 {
-       struct osp_orphan_it    *it     = (struct osp_orphan_it *)di;
+       struct osp_it   *it = (struct osp_it *)di;
 
        return it->ooi_next;
 }
 
 /**
- * \retval      +1: locate to the exactly position
- * \retval       0: cannot locate to the exactly position,
- *                  call next() to move to a valid position.
- * \retval     -ve: on error
+ * Locate the iteration cursor to the specified position (cookie).
+ *
+ * \param[in] env      pointer to the thread context
+ * \param[in] di       pointer to the iteration structure
+ * \param[in] hash     the specified position
+ *
+ * \retval             positive number for locating to the exactly position
+ *                     or the next
+ * \retval             0 for arriving at the end of the iteration
+ * \retval             negative error number on failure
  */
-static int osp_orphan_it_load(const struct lu_env *env,
-                             const struct dt_it *di,
-                             __u64 hash)
+int osp_orphan_it_load(const struct lu_env *env, const struct dt_it *di,
+                      __u64 hash)
 {
-       struct osp_orphan_it    *it     = (struct osp_orphan_it *)di;
-       int                      rc;
+       struct osp_it   *it     = (struct osp_it *)di;
+       int              rc;
 
        it->ooi_next = hash;
        rc = osp_orphan_it_next(env, (struct dt_it *)di);
@@ -1446,9 +2104,8 @@ static int osp_orphan_it_load(const struct lu_env *env,
        return rc;
 }
 
-static int osp_orphan_it_key_rec(const struct lu_env *env,
-                               const struct dt_it *di,
-                               void *key_rec)
+int osp_it_key_rec(const struct lu_env *env, const struct dt_it *di,
+                  void *key_rec)
 {
        return 0;
 }
@@ -1460,31 +2117,46 @@ static const struct dt_index_operations osp_orphan_index_ops = {
        .dio_declare_delete     = osp_orphan_index_declare_delete,
        .dio_delete             = osp_orphan_index_delete,
        .dio_it = {
-               .init           = osp_orphan_it_init,
-               .fini           = osp_orphan_it_fini,
+               .init           = osp_it_init,
+               .fini           = osp_it_fini,
                .next           = osp_orphan_it_next,
-               .get            = osp_orphan_it_get,
-               .put            = osp_orphan_it_put,
+               .get            = osp_it_get,
+               .put            = osp_it_put,
                .key            = osp_orphan_it_key,
                .key_size       = osp_orphan_it_key_size,
                .rec            = osp_orphan_it_rec,
-               .store          = osp_orphan_it_store,
+               .store          = osp_it_store,
                .load           = osp_orphan_it_load,
-               .key_rec        = osp_orphan_it_key_rec,
+               .key_rec        = osp_it_key_rec,
        }
 };
 
+/**
+ * Implement OSP layer dt_object_operations::do_index_try() interface.
+ *
+ * Negotiate the index type.
+ *
+ * If the target index is an IDIF object, then use osp_orphan_index_ops.
+ * Otherwise, assign osp_md_index_ops to the dt_object::do_index_ops.
+ * (\see lustre/include/lustre_fid.h for IDIF.)
+ *
+ * \param[in] env      pointer to the thread context
+ * \param[in] dt       pointer to the OSP layer dt_object
+ * \param[in] feat     unused
+ *
+ * \retval             0 for success
+ */
 static int osp_index_try(const struct lu_env *env,
                         struct dt_object *dt,
                         const struct dt_index_features *feat)
 {
-       if (fid_is_last_id(lu_object_fid(&dt->do_lu))) {
-               dt->do_index_ops = &osp_orphan_index_ops;
+       const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
 
-               return 0;
-       }
-
-       return -EINVAL;
+       if (fid_is_last_id(fid) && fid_is_idif(fid))
+               dt->do_index_ops = &osp_orphan_index_ops;
+       else
+               dt->do_index_ops = &osp_md_index_ops;
+       return 0;
 }
 
 struct dt_object_operations osp_obj_ops = {
@@ -1503,6 +2175,21 @@ struct dt_object_operations osp_obj_ops = {
        .do_index_try           = osp_index_try,
 };
 
+/**
+ * Implement OSP layer lu_object_operations::loo_object_init() interface.
+ *
+ * Initialize the object.
+ *
+ * If it is a remote MDT object, then call do_attr_get() to fetch
+ * the attribute from the peer.
+ *
+ * \param[in] env      pointer to the thread context
+ * \param[in] o                pointer to the OSP layer lu_object
+ * \param[in] conf     unused
+ *
+ * \retval             0 for success
+ * \retval             negative error number on failure
+ */
 static int osp_object_init(const struct lu_env *env, struct lu_object *o,
                           const struct lu_object_conf *conf)
 {
@@ -1519,6 +2206,7 @@ static int osp_object_init(const struct lu_env *env, struct lu_object *o,
                struct lu_attr *la = &osp_env_info(env)->osi_attr;
 
                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);
                if (rc == 0)
@@ -1533,6 +2221,17 @@ static int osp_object_init(const struct lu_env *env, struct lu_object *o,
        RETURN(rc);
 }
 
+/**
+ * Implement OSP layer lu_object_operations::loo_object_free() interface.
+ *
+ * Finalize the object.
+ *
+ * If the OSP object has attributes cache, then destroy the cache.
+ * Free the object finally.
+ *
+ * \param[in] env      pointer to the thread context
+ * \param[in] o                pointer to the OSP layer lu_object
+ */
 static void osp_object_free(const struct lu_env *env, struct lu_object *o)
 {
        struct osp_object       *obj = lu2osp_obj(o);
@@ -1552,7 +2251,7 @@ static void osp_object_free(const struct lu_env *env, struct lu_object *o)
                        count = atomic_read(&oxe->oxe_ref);
                        LASSERTF(count == 1,
                                 "Still has %d users on the xattr entry %.*s\n",
-                                count - 1, oxe->oxe_namelen, oxe->oxe_buf);
+                                count-1, (int)oxe->oxe_namelen, oxe->oxe_buf);
 
                        OBD_FREE(oxe, oxe->oxe_buflen);
                }
@@ -1561,6 +2260,17 @@ static void osp_object_free(const struct lu_env *env, struct lu_object *o)
        OBD_SLAB_FREE_PTR(obj, osp_object_kmem);
 }
 
+/**
+ * Implement OSP layer lu_object_operations::loo_object_release() interface.
+ *
+ * Cleanup (not free) the object.
+ *
+ * If it is a reserved object but failed to be created, or it is an OST
+ * object, then mark the object as non-cached.
+ *
+ * \param[in] env      pointer to the thread context
+ * \param[in] o                pointer to the OSP layer lu_object
+ */
 static void osp_object_release(const struct lu_env *env, struct lu_object *o)
 {
        struct osp_object       *po = lu2osp_obj(o);