Whamcloud - gitweb
LU-9045 osp: Revert "LU-8840 osp: handle EA cache properly"
[fs/lustre-release.git] / lustre / osp / osp_object.c
index 2898da6..1fcbac7 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
@@ -27,7 +23,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2014, Intel Corporation.
+ * Copyright (c) 2012, 2016, Intel Corporation.
  */
 /*
  * lustre/osp/osp_object.c
  *     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;
+ *     struct lu_attr          opo_attr;
+ *     struct list_head        opo_xattr_list;
  *     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
+ * osp_object::opo_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
+ * osp_object::opo_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
 
 #define DEBUG_SUBSYSTEM S_MDS
 
+#include <lustre_obdo.h>
+#include <lustre_swab.h>
+
 #include "osp_internal.h"
 
 static inline __u32 osp_dev2node(struct osp_device *osp)
@@ -161,41 +156,12 @@ static void osp_object_assign_fid(const struct lu_env *env,
 }
 
 /**
- * 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;
-
-       OBD_ALLOC_PTR(ooa);
-       if (ooa == NULL)
-               return -ENOMEM;
-
-       INIT_LIST_HEAD(&ooa->ooa_xattr_list);
-       spin_lock(&obj->opo_lock);
-       if (likely(obj->opo_ooa == NULL)) {
-               obj->opo_ooa = ooa;
-               spin_unlock(&obj->opo_lock);
-       } else {
-               spin_unlock(&obj->opo_lock);
-               OBD_FREE_PTR(ooa);
-       }
-
-       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] obj      pointer to the OSP object
  * \param[in] name     the name of the extended attribute
  * \param[in] namelen  the name length of the extended attribute
  *
@@ -204,12 +170,12 @@ static int osp_oac_init(struct osp_object *obj)
  *                     in the cache
  */
 static struct osp_xattr_entry *
-osp_oac_xattr_find_locked(struct osp_object_attr *ooa,
-                         const char *name, size_t namelen)
+osp_oac_xattr_find_locked(struct osp_object *obj, const char *name,
+                         size_t namelen)
 {
        struct osp_xattr_entry *oxe;
 
-       list_for_each_entry(oxe, &ooa->ooa_xattr_list, oxe_list) {
+       list_for_each_entry(oxe, &obj->opo_xattr_list, oxe_list) {
                if (namelen == oxe->oxe_namelen &&
                    strncmp(name, oxe->oxe_buf, namelen) == 0)
                        return oxe;
@@ -238,15 +204,12 @@ static struct osp_xattr_entry *osp_oac_xattr_find(struct osp_object *obj,
        struct osp_xattr_entry *oxe = NULL;
 
        spin_lock(&obj->opo_lock);
-       if (obj->opo_ooa != NULL) {
-               oxe = osp_oac_xattr_find_locked(obj->opo_ooa, name,
-                                               strlen(name));
-               if (oxe != NULL) {
-                       if (unlink)
-                               list_del_init(&oxe->oxe_list);
-                       else
-                               atomic_inc(&oxe->oxe_ref);
-               }
+       oxe = osp_oac_xattr_find_locked(obj, name, strlen(name));
+       if (oxe != NULL) {
+               if (unlink)
+                       list_del_init(&oxe->oxe_list);
+               else
+                       atomic_inc(&oxe->oxe_ref);
        }
        spin_unlock(&obj->opo_lock);
 
@@ -271,14 +234,11 @@ static struct osp_xattr_entry *osp_oac_xattr_find(struct osp_object *obj,
 static struct osp_xattr_entry *
 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;
        size_t                  namelen = strlen(name);
        size_t                  size    = sizeof(*oxe) + namelen + 1 + len;
 
-       LASSERT(ooa != NULL);
-
        oxe = osp_oac_xattr_find(obj, name, false);
        if (oxe != NULL)
                return oxe;
@@ -296,9 +256,9 @@ osp_oac_xattr_find_or_add(struct osp_object *obj, const char *name, size_t len)
        atomic_set(&oxe->oxe_ref, 2);
 
        spin_lock(&obj->opo_lock);
-       tmp = osp_oac_xattr_find_locked(ooa, name, namelen);
+       tmp = osp_oac_xattr_find_locked(obj, name, namelen);
        if (tmp == NULL)
-               list_add_tail(&oxe->oxe_list, &ooa->ooa_xattr_list);
+               list_add_tail(&oxe->oxe_list, &obj->opo_xattr_list);
        else
                atomic_inc(&tmp->oxe_ref);
        spin_unlock(&obj->opo_lock);
@@ -319,7 +279,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.
@@ -332,13 +292,10 @@ static struct osp_xattr_entry *
 osp_oac_xattr_replace(struct osp_object *obj,
                      struct osp_xattr_entry **poxe, size_t len)
 {
-       struct osp_object_attr *ooa     = obj->opo_ooa;
        struct osp_xattr_entry *oxe;
        size_t                  namelen = (*poxe)->oxe_namelen;
        size_t                  size    = sizeof(*oxe) + namelen + 1 + len;
 
-       LASSERT(ooa != NULL);
-
        OBD_ALLOC(oxe, size);
        if (unlikely(oxe == NULL))
                return NULL;
@@ -352,11 +309,11 @@ osp_oac_xattr_replace(struct osp_object *obj,
        atomic_set(&oxe->oxe_ref, 2);
 
        spin_lock(&obj->opo_lock);
-       *poxe = osp_oac_xattr_find_locked(ooa, oxe->oxe_buf, namelen);
+       *poxe = osp_oac_xattr_find_locked(obj, oxe->oxe_buf, namelen);
        LASSERT(*poxe != NULL);
 
        list_del_init(&(*poxe)->oxe_list);
-       list_add_tail(&oxe->oxe_list, &ooa->ooa_xattr_list);
+       list_add_tail(&oxe->oxe_list, &obj->opo_xattr_list);
        spin_unlock(&obj->opo_lock);
 
        return oxe;
@@ -420,15 +377,9 @@ static int osp_get_attr_from_reply(const struct lu_env *env,
 
        lustre_get_wire_obdo(NULL, lobdo, wobdo);
        spin_lock(&obj->opo_lock);
-       if (obj->opo_ooa != NULL) {
-               la_from_obdo(&obj->opo_ooa->ooa_attr, lobdo, lobdo->o_valid);
-               if (attr != NULL)
-                       *attr = obj->opo_ooa->ooa_attr;
-       } else {
-               LASSERT(attr != NULL);
-
-               la_from_obdo(attr, lobdo, lobdo->o_valid);
-       }
+       la_from_obdo(&obj->opo_attr, lobdo, lobdo->o_valid);
+       if (attr != NULL)
+               *attr = obj->opo_attr;
        spin_unlock(&obj->opo_lock);
 
        return 0;
@@ -459,8 +410,6 @@ static int osp_attr_get_interpterer(const struct lu_env *env,
 {
        struct lu_attr *attr = data;
 
-       LASSERT(obj->opo_ooa != NULL);
-
        if (rc == 0) {
                osp2lu_obj(obj)->lo_header->loh_attr |= LOHA_EXISTS;
                obj->opo_non_exist = 0;
@@ -503,15 +452,9 @@ static int osp_declare_attr_get(const struct lu_env *env, struct dt_object *dt)
        struct osp_device       *osp    = lu2osp_dev(dt->do_lu.lo_dev);
        int                      rc     = 0;
 
-       if (obj->opo_ooa == NULL) {
-               rc = osp_oac_init(obj);
-               if (rc != 0)
-                       return rc;
-       }
-
        mutex_lock(&osp->opd_async_requests_mutex);
        rc = osp_insert_async_request(env, OUT_ATTR_GET, obj, 0, NULL, NULL,
-                                     &obj->opo_ooa->ooa_attr,
+                                     &obj->opo_attr, sizeof(struct obdo),
                                      osp_attr_get_interpterer);
        mutex_unlock(&osp->opd_async_requests_mutex);
 
@@ -541,7 +484,7 @@ int osp_attr_get(const struct lu_env *env, struct dt_object *dt,
        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 osp_update_request       *update;
        struct object_update_reply      *reply;
        struct ptlrpc_request           *req = NULL;
        int                             rc = 0;
@@ -550,23 +493,21 @@ int osp_attr_get(const struct lu_env *env, struct dt_object *dt,
        if (is_ost_obj(&dt->do_lu) && obj->opo_non_exist)
                RETURN(-ENOENT);
 
-       if (obj->opo_ooa != NULL) {
-               spin_lock(&obj->opo_lock);
-               if (obj->opo_ooa->ooa_attr.la_valid != 0) {
-                       *attr = obj->opo_ooa->ooa_attr;
-                       spin_unlock(&obj->opo_lock);
-
-                       RETURN(0);
-               }
+       spin_lock(&obj->opo_lock);
+       if (obj->opo_attr.la_valid != 0 && !obj->opo_stale) {
+               *attr = obj->opo_attr;
                spin_unlock(&obj->opo_lock);
+
+               RETURN(0);
        }
+       spin_unlock(&obj->opo_lock);
 
-       update = dt_update_request_create(dev);
+       update = osp_update_request_create(dev);
        if (IS_ERR(update))
                RETURN(PTR_ERR(update));
 
-       rc = out_attr_get_pack(env, &update->dur_buf,
-                              lu_object_fid(&dt->do_lu));
+       rc = osp_update_rpc_pack(env, attr_get, update, OUT_ATTR_GET,
+                                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,
@@ -601,13 +542,17 @@ int osp_attr_get(const struct lu_env *env, struct dt_object *dt,
        if (rc != 0)
                GOTO(out, rc);
 
-       GOTO(out, rc = 0);
+       spin_lock(&obj->opo_lock);
+       obj->opo_stale = 0;
+       spin_unlock(&obj->opo_lock);
+
+       GOTO(out, rc);
 
 out:
        if (req != NULL)
                ptlrpc_req_finished(req);
 
-       dt_update_request_destroy(update);
+       osp_update_request_destroy(env, update);
 
        return rc;
 }
@@ -720,11 +665,11 @@ static int osp_attr_set(const struct lu_env *env, struct dt_object *dt,
                CDEBUG(D_INFO, "(1) set attr "DFID": rc = %d\n",
                       PFID(&dt->do_lu.lo_header->loh_fid), rc);
 
-               if (rc != 0 || o->opo_ooa == NULL)
+               if (rc != 0)
                        RETURN(rc);
 
                /* Update the OSP object attributes cache. */
-               la = &o->opo_ooa->ooa_attr;
+               la = &o->opo_attr;
                spin_lock(&o->opo_lock);
                if (attr->la_valid & LA_UID) {
                        la->la_uid = attr->la_uid;
@@ -764,12 +709,9 @@ static int osp_xattr_get_interpterer(const struct lu_env *env,
                                     struct osp_object *obj,
                                     void *data, int index, int rc)
 {
-       struct osp_object_attr  *ooa  = obj->opo_ooa;
        struct osp_xattr_entry  *oxe  = data;
        struct lu_buf           *rbuf = &osp_env_info(env)->osi_lb2;
 
-       LASSERT(ooa != NULL);
-
        if (rc == 0) {
                size_t len = sizeof(*oxe) + oxe->oxe_namelen + 1;
 
@@ -829,47 +771,46 @@ static int osp_declare_xattr_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);
        struct osp_xattr_entry  *oxe;
-       __u16                    namelen = strlen(name);
+       __u16 namelen;
        int                      rc      = 0;
 
        LASSERT(buf != NULL);
        LASSERT(name != NULL);
 
+       namelen = strlen(name);
+
        /* If only for xattr size, return directly. */
        if (unlikely(buf->lb_len == 0))
                return 0;
 
-       if (obj->opo_ooa == NULL) {
-               rc = osp_oac_init(obj);
-               if (rc != 0)
-                       return rc;
-       }
-
        oxe = osp_oac_xattr_find_or_add(obj, name, buf->lb_len);
        if (oxe == NULL)
                return -ENOMEM;
 
        mutex_lock(&osp->opd_async_requests_mutex);
        rc = osp_insert_async_request(env, OUT_XATTR_GET, obj, 1,
-                                     &namelen, (const void **)&name, oxe,
+                                     &namelen, (const void **)&name,
+                                     oxe, buf->lb_len,
                                      osp_xattr_get_interpterer);
        if (rc != 0) {
                mutex_unlock(&osp->opd_async_requests_mutex);
                osp_oac_xattr_put(oxe);
        } else {
-               struct dt_update_request *update;
+               struct osp_update_request *our;
+               struct osp_update_request_sub *ours;
 
                /* 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) {
+               our = osp->opd_async_requests;
+               ours = osp_current_object_update_request(our);
+               if (ours != NULL && ours->ours_req != NULL &&
+                   ours->ours_req->ourq_count > 0) {
                        osp->opd_async_requests = NULL;
                        mutex_unlock(&osp->opd_async_requests_mutex);
-                       rc = osp_unplug_async_request(env, osp, update);
+                       rc = osp_unplug_async_request(env, osp, our);
                } else {
                        mutex_unlock(&osp->opd_async_requests_mutex);
                }
@@ -908,7 +849,7 @@ 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 dt_update_request *update = NULL;
+       struct osp_update_request *update = NULL;
        struct ptlrpc_request   *req    = NULL;
        struct object_update_reply *reply;
        struct osp_xattr_entry  *oxe    = NULL;
@@ -946,7 +887,8 @@ int osp_xattr_get(const struct lu_env *env, struct dt_object *dt,
                        if (buf->lb_len < oxe->oxe_vallen)
                                GOTO(unlock, rc = -ERANGE);
 
-                       memcpy(buf->lb_buf, oxe->oxe_value, oxe->oxe_vallen);
+                       memcpy(buf->lb_buf, oxe->oxe_value,
+                              oxe->oxe_vallen);
 
                        GOTO(unlock, rc = oxe->oxe_vallen);
 
@@ -958,13 +900,12 @@ unlock:
                }
                spin_unlock(&obj->opo_lock);
        }
-
-       update = dt_update_request_create(dev);
+       update = osp_update_request_create(dev);
        if (IS_ERR(update))
                GOTO(out, rc = PTR_ERR(update));
 
-       rc = out_xattr_get_pack(env, &update->dur_buf,
-                               lu_object_fid(&dt->do_lu), name);
+       rc = osp_update_rpc_pack(env, xattr_get, update, OUT_XATTR_GET,
+                                lu_object_fid(&dt->do_lu), name, buf->lb_len);
        if (rc != 0) {
                CERROR("%s: Insert update error "DFID": rc = %d\n",
                       dname, PFID(lu_object_fid(&dt->do_lu)), rc);
@@ -972,15 +913,12 @@ unlock:
        }
 
        rc = osp_remote_sync(env, osp, update, &req);
-       if (rc != 0) {
+       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);
-
                if (oxe == NULL)
                        oxe = osp_oac_xattr_find_or_add(obj, name, buf->lb_len);
 
@@ -1020,15 +958,12 @@ unlock:
                GOTO(out, rc);
 
        if (buf->lb_buf == NULL)
-               GOTO(out, rc = rbuf->lb_len);
+               GOTO(out, rc);
 
        if (unlikely(buf->lb_len < rbuf->lb_len))
                GOTO(out, rc = -ERANGE);
 
        memcpy(buf->lb_buf, rbuf->lb_buf, rbuf->lb_len);
-       rc = rbuf->lb_len;
-       if (obj->opo_ooa == NULL)
-               GOTO(out, rc);
 
        if (oxe == NULL) {
                oxe = osp_oac_xattr_find_or_add(obj, name, rbuf->lb_len);
@@ -1077,7 +1012,7 @@ out:
                ptlrpc_req_finished(req);
 
        if (update != NULL && !IS_ERR(update))
-               dt_update_request_destroy(update);
+               osp_update_request_destroy(env, update);
 
        if (oxe != NULL)
                osp_oac_xattr_put(oxe);
@@ -1141,23 +1076,31 @@ int osp_xattr_set(const struct lu_env *env, struct dt_object *dt,
                  struct thandle *th)
 {
        struct osp_object       *o = dt2osp_obj(dt);
-       struct dt_update_request *update;
+       struct osp_update_request *update;
        struct osp_xattr_entry  *oxe;
        int                     rc;
        ENTRY;
 
-       LASSERT(buf->lb_len > 0 && buf->lb_buf != NULL);
-       update = thandle_to_dt_update_request(th);
+       update = thandle_to_osp_update_request(th);
        LASSERT(update != NULL);
 
        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, fl, update->dur_batchid);
-       if (rc != 0 || o->opo_ooa == NULL)
-               return rc;
+       rc = osp_update_rpc_pack(env, xattr_set, update, OUT_XATTR_SET,
+                                lu_object_fid(&dt->do_lu), buf, name, fl);
+       if (rc != 0)
+               RETURN(rc);
+
+       /* Do not cache linkEA that may be self-adjusted by peers
+        * under EA overflow case. */
+       if (strcmp(name, XATTR_NAME_LINK) == 0) {
+               oxe = osp_oac_xattr_find(o, name, true);
+               if (oxe != NULL)
+                       osp_oac_xattr_put(oxe);
+
+               RETURN(0);
+       }
 
        oxe = osp_oac_xattr_find_or_add(o, name, buf->lb_len);
        if (oxe == NULL) {
@@ -1247,18 +1190,18 @@ int osp_declare_xattr_del(const struct lu_env *env, struct dt_object *dt,
 int osp_xattr_del(const struct lu_env *env, struct dt_object *dt,
                  const char *name, struct thandle *th)
 {
-       struct dt_update_request *update;
+       struct osp_update_request *update;
        const struct lu_fid      *fid = lu_object_fid(&dt->do_lu);
-       struct osp_object        *o = dt2osp_obj(dt);
+       struct osp_object        *o     = dt2osp_obj(dt);
        struct osp_xattr_entry   *oxe;
        int                       rc;
 
-       update = thandle_to_dt_update_request(th);
+       update = thandle_to_osp_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)
+       rc = osp_update_rpc_pack(env, xattr_del, update, OUT_XATTR_DEL,
+                                fid, name);
+       if (rc != 0)
                return rc;
 
        oxe = osp_oac_xattr_find(o, name, true);
@@ -1269,6 +1212,48 @@ int osp_xattr_del(const struct lu_env *env, struct dt_object *dt,
        return 0;
 }
 
+void osp_obj_invalidate_cache(struct osp_object *obj)
+{
+       struct osp_xattr_entry *oxe;
+       struct osp_xattr_entry *tmp;
+
+       spin_lock(&obj->opo_lock);
+       list_for_each_entry_safe(oxe, tmp, &obj->opo_xattr_list, oxe_list) {
+               oxe->oxe_ready = 0;
+               list_del_init(&oxe->oxe_list);
+               osp_oac_xattr_put(oxe);
+       }
+       obj->opo_attr.la_valid = 0;
+       spin_unlock(&obj->opo_lock);
+}
+
+/**
+ * Implement OSP layer dt_object_operations::do_invalidate() interface.
+ *
+ * Invalidate attributes cached on the specified MDT/OST object.
+ *
+ * \param[in] env      pointer to the thread context
+ * \param[in] dt       pointer to the OSP layer dt_object
+ *
+ * \retval             0 for success
+ * \retval             negative error number on failure
+ */
+int osp_invalidate(const struct lu_env *env, struct dt_object *dt)
+{
+       struct osp_object *obj = dt2osp_obj(dt);
+       ENTRY;
+
+       CDEBUG(D_HA, "Invalidate osp_object "DFID"\n",
+              PFID(lu_object_fid(&dt->do_lu)));
+       osp_obj_invalidate_cache(obj);
+
+       spin_lock(&obj->opo_lock);
+       obj->opo_stale = 1;
+       spin_unlock(&obj->opo_lock);
+
+       RETURN(0);
+}
+
 /**
  * Implement OSP layer dt_object_operations::do_declare_create() interface.
  *
@@ -1554,6 +1539,7 @@ static int osp_object_destroy(const struct lu_env *env, struct dt_object *dt,
        int                      rc = 0;
 
        ENTRY;
+
        o->opo_non_exist = 1;
 
        LASSERT(!osp->opd_connect_mdt);
@@ -1670,7 +1656,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
@@ -1693,7 +1679,7 @@ static int osp_it_fetch(const struct lu_env *env, struct osp_it *it)
 
        /* 1MB bulk */
        npages = min_t(unsigned int, OFD_MAX_BRW_SIZE, 1 << 20);
-       npages /= PAGE_CACHE_SIZE;
+       npages /= PAGE_SIZE;
 
        OBD_ALLOC(pages, npages * sizeof(*pages));
        if (pages == NULL)
@@ -1702,7 +1688,7 @@ static int osp_it_fetch(const struct lu_env *env, struct osp_it *it)
        it->ooi_pages = pages;
        it->ooi_total_npages = npages;
        for (i = 0; i < npages; i++) {
-               pages[i] = alloc_page(GFP_IOFS);
+               pages[i] = alloc_page(GFP_NOFS);
                if (pages[i] == NULL)
                        RETURN(-ENOMEM);
        }
@@ -1718,6 +1704,7 @@ static int osp_it_fetch(const struct lu_env *env, struct osp_it *it)
                RETURN(rc);
        }
 
+       osp_set_req_replay(osp, req);
        req->rq_request_portal = OUT_PORTAL;
        ii = req_capsule_client_get(&req->rq_pill, &RMF_IDX_INFO);
        memset(ii, 0, sizeof(*ii));
@@ -1742,15 +1729,18 @@ static int osp_it_fetch(const struct lu_env *env, struct osp_it *it)
 
        ptlrpc_at_set_req_timeout(req);
 
-       desc = ptlrpc_prep_bulk_imp(req, npages, 1, BULK_PUT_SINK,
-                                   MDS_BULK_PORTAL);
+       desc = ptlrpc_prep_bulk_imp(req, npages, 1,
+                                   PTLRPC_BULK_PUT_SINK | PTLRPC_BULK_BUF_KIOV,
+                                   MDS_BULK_PORTAL,
+                                   &ptlrpc_bulk_kiov_pin_ops);
        if (desc == NULL) {
                ptlrpc_request_free(req);
                RETURN(-ENOMEM);
        }
 
        for (i = 0; i < npages; i++)
-               ptlrpc_prep_bulk_page_pin(desc, pages[i], 0, PAGE_CACHE_SIZE);
+               desc->bd_frag_ops->add_kiov_frag(desc, pages[i], 0,
+                                                PAGE_SIZE);
 
        ptlrpc_request_set_replen(req);
        rc = ptlrpc_queue_wait(req);
@@ -1768,7 +1758,7 @@ static int osp_it_fetch(const struct lu_env *env, struct osp_it *it)
                 GOTO(out, rc = -EPROTO);
 
        npages = (ii->ii_count + LU_PAGE_COUNT - 1) >>
-                (PAGE_CACHE_SHIFT - LU_PAGE_SHIFT);
+                (PAGE_SHIFT - LU_PAGE_SHIFT);
        if (npages > it->ooi_total_npages) {
                CERROR("%s: returned more pages than expected, %u > %u\n",
                       osp->opd_obd->obd_name, npages, it->ooi_total_npages);
@@ -2108,6 +2098,8 @@ static int osp_object_init(const struct lu_env *env, struct lu_object *o,
 
        spin_lock_init(&po->opo_lock);
        o->lo_header->loh_attr |= LOHA_REMOTE;
+       INIT_LIST_HEAD(&po->opo_xattr_list);
+       INIT_LIST_HEAD(&po->opo_invalidate_cb_list);
 
        if (is_ost_obj(o)) {
                po->opo_obj.do_ops = &osp_obj_ops;
@@ -2116,13 +2108,19 @@ 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);
-               if (rc == 0)
-                       o->lo_header->loh_attr |=
-                               LOHA_EXISTS | (la->la_mode & S_IFMT);
-               if (rc == -ENOENT) {
+
+               if (conf != NULL && conf->loc_flags & LOC_F_NEW) {
                        po->opo_non_exist = 1;
-                       rc = 0;
+               } else {
+                       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);
+                       if (rc == -ENOENT) {
+                               po->opo_non_exist = 1;
+                               rc = 0;
+                       }
                }
                init_rwsem(&po->opo_sem);
        }
@@ -2144,26 +2142,20 @@ static void osp_object_free(const struct lu_env *env, struct lu_object *o)
 {
        struct osp_object       *obj = lu2osp_obj(o);
        struct lu_object_header *h = o->lo_header;
+       struct osp_xattr_entry *oxe;
+       struct osp_xattr_entry *tmp;
+       int                     count;
 
        dt_object_fini(&obj->opo_obj);
        lu_object_header_fini(h);
-       if (obj->opo_ooa != NULL) {
-               struct osp_xattr_entry *oxe;
-               struct osp_xattr_entry *tmp;
-               int                     count;
-
-               list_for_each_entry_safe(oxe, tmp,
-                                        &obj->opo_ooa->ooa_xattr_list,
-                                        oxe_list) {
-                       list_del(&oxe->oxe_list);
-                       count = atomic_read(&oxe->oxe_ref);
-                       LASSERTF(count == 1,
-                                "Still has %d users on the xattr entry %.*s\n",
-                                count-1, (int)oxe->oxe_namelen, oxe->oxe_buf);
-
-                       OBD_FREE(oxe, oxe->oxe_buflen);
-               }
-               OBD_FREE_PTR(obj->opo_ooa);
+       list_for_each_entry_safe(oxe, tmp, &obj->opo_xattr_list, oxe_list) {
+               list_del(&oxe->oxe_list);
+               count = atomic_read(&oxe->oxe_ref);
+               LASSERTF(count == 1,
+                        "Still has %d users on the xattr entry %.*s\n",
+                        count-1, (int)oxe->oxe_namelen, oxe->oxe_buf);
+
+               OBD_FREE(oxe, oxe->oxe_buflen);
        }
        OBD_SLAB_FREE_PTR(obj, osp_object_kmem);
 }