Whamcloud - gitweb
LU-5417 osp: fix comparison between signed and unsigned
[fs/lustre-release.git] / lustre / osp / osp_object.c
index 78e2250..966d751 100644 (file)
@@ -87,7 +87,7 @@ static int osp_oac_init(struct osp_object *obj)
 
 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, bool unlink)
 {
        struct osp_xattr_entry *oxe;
 
@@ -121,13 +121,13 @@ 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, 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);
 
@@ -163,14 +163,14 @@ osp_oac_xattr_find_or_add(struct osp_object *obj, const char *name, int len)
 
 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 = old->oxe_namelen;
+       size_t                  size    = sizeof(*oxe) + namelen + 1 + len;
 
        LASSERT(ooa != NULL);
 
@@ -208,6 +208,7 @@ static inline void osp_oac_xattr_put(struct osp_xattr_entry *oxe)
 
 static int osp_get_attr_from_reply(const struct lu_env *env,
                                   struct object_update_reply *reply,
+                                  struct ptlrpc_request *req,
                                   struct lu_attr *attr,
                                   struct osp_object *obj, int index)
 {
@@ -225,7 +226,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) {
@@ -244,6 +248,7 @@ static int osp_get_attr_from_reply(const struct lu_env *env,
 
 static int osp_attr_get_interpterer(const struct lu_env *env,
                                    struct object_update_reply *reply,
+                                   struct ptlrpc_request *req,
                                    struct osp_object *obj,
                                    void *data, int index, int rc)
 {
@@ -255,7 +260,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;
@@ -275,7 +281,6 @@ static int osp_declare_attr_get(const struct lu_env *env, struct dt_object *dt,
 {
        struct osp_object       *obj    = dt2osp_obj(dt);
        struct osp_device       *osp    = lu2osp_dev(dt->do_lu.lo_dev);
-       struct dt_update_request *update;
        int                      rc     = 0;
 
        if (obj->opo_ooa == NULL) {
@@ -285,14 +290,9 @@ 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, OUT_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;
@@ -360,17 +360,10 @@ int osp_attr_get(const struct lu_env *env, struct dt_object *dt,
        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:
@@ -500,6 +493,7 @@ static int osp_attr_set(const struct lu_env *env, struct dt_object *dt,
 
 static int osp_xattr_get_interpterer(const struct lu_env *env,
                                     struct object_update_reply *reply,
+                                    struct ptlrpc_request *req,
                                     struct osp_object *obj,
                                     void *data, int index, int rc)
 {
@@ -510,7 +504,7 @@ 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 = object_update_result_data_get(reply, rbuf, index);
                if (rc < 0 || rbuf->lb_len > (oxe->oxe_buflen - len)) {
@@ -550,7 +544,6 @@ 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 dt_update_request *update;
        struct osp_xattr_entry  *oxe;
        int                      namelen = strlen(name);
        int                      rc      = 0;
@@ -573,33 +566,28 @@ 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, &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, OUT_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_req != NULL &&
+                   update->dur_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->dur_req != NULL &&
-                           update->dur_req->ourq_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);
                }
        }
 
@@ -746,7 +734,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);
@@ -833,7 +821,7 @@ int osp_declare_xattr_set(const struct lu_env *env, struct dt_object *dt,
                              ": rc = %d\n", dt->do_lu.lo_dev->ld_obd->obd_name,
                              name, PFID(lu_object_fid(&dt->do_lu)), rc);
                        spin_lock(&o->opo_lock);
-                       oxe->oxe_ready = 0;
+                       old->oxe_ready = 0;
                        spin_unlock(&o->opo_lock);
 
                        return 0;
@@ -864,6 +852,36 @@ int osp_xattr_set(const struct lu_env *env, struct dt_object *dt,
        return 0;
 }
 
+int osp_declare_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;
+       int                      size = strlen(name);
+       int                      rc;
+
+       update = out_find_create_update_loc(th, dt);
+       if (IS_ERR(update))
+               return PTR_ERR(update);
+
+       fid = lu_object_fid(&dt->do_lu);
+
+       rc = out_insert_update(env, update, OUT_XATTR_DEL, fid, 1, &size,
+                              (const char **)&name);
+
+       return rc;
+}
+
+int osp_xattr_del(const struct lu_env *env, struct dt_object *dt,
+                 const char *name, struct thandle *th,
+                 struct lustre_capa *capa)
+{
+       CDEBUG(D_INFO, "xattr %s del object "DFID"\n", name,
+              PFID(&dt->do_lu.lo_header->loh_fid));
+
+       return 0;
+}
+
 static int osp_declare_object_create(const struct lu_env *env,
                                     struct dt_object *dt,
                                     struct lu_attr *attr,
@@ -1077,21 +1095,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,
@@ -1138,30 +1141,27 @@ 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)
+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)
+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++) {
@@ -1178,8 +1178,7 @@ 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)
+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);
@@ -1219,7 +1218,28 @@ 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->opd_storage->dd_lu_dev.ld_site->ld_seq_site->ss_node_id;
+
        ptlrpc_at_set_req_timeout(req);
 
        desc = ptlrpc_prep_bulk_imp(req, npages, 1, BULK_PUT_SINK,
@@ -1232,18 +1252,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)
@@ -1253,6 +1261,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)
@@ -1272,22 +1281,19 @@ 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)
+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:
@@ -1296,23 +1302,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) {
@@ -1323,24 +1323,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;
                }
 
@@ -1350,7 +1351,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;
@@ -1363,30 +1364,59 @@ 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)
+int osp_orphan_it_next(const struct lu_env *env, struct dt_it *di)
+{
+       struct osp_it           *it = (struct osp_it *)di;
+       struct lu_idxpage       *idxpage;
+       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 -ENOSYS;
+       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);
@@ -1394,19 +1424,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;
@@ -1416,10 +1443,9 @@ 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;
 }
@@ -1430,11 +1456,10 @@ static __u64 osp_orphan_it_store(const struct lu_env *env,
  *                  call next() to move to a valid position.
  * \retval     -ve: on error
  */
-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;
+       struct osp_it   *it     = (struct osp_it *)di;
        int                      rc;
 
        it->ooi_next = hash;
@@ -1448,9 +1473,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;
 }
@@ -1462,17 +1486,17 @@ 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,
        }
 };
 
@@ -1482,13 +1506,11 @@ static int osp_index_try(const struct lu_env *env,
 {
        const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
 
-       if (fid_is_last_id(fid) && fid_is_idif(fid)) {
+       if (fid_is_last_id(fid) && fid_is_idif(fid))
                dt->do_index_ops = &osp_orphan_index_ops;
-
-               return 0;
-       }
-
-       return -EINVAL;
+       else
+               dt->do_index_ops = &osp_md_index_ops;
+       return 0;
 }
 
 struct dt_object_operations osp_obj_ops = {
@@ -1557,7 +1579,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);
                }