Whamcloud - gitweb
LU-14185 osp: alloc fails for OSP obj xattr cache
[fs/lustre-release.git] / lustre / osp / osp_object.c
index 896ce2e..fabf7d6 100644 (file)
@@ -186,7 +186,7 @@ static inline void osp_oac_xattr_put(struct osp_xattr_entry *oxe)
        if (atomic_dec_and_test(&oxe->oxe_ref)) {
                LASSERT(list_empty(&oxe->oxe_list));
 
-               OBD_FREE(oxe, oxe->oxe_buflen);
+               OBD_FREE_LARGE(oxe, oxe->oxe_buflen);
        }
 }
 
@@ -279,7 +279,7 @@ osp_oac_xattr_find_or_add(struct osp_object *obj, const char *name, size_t len)
        if (oxe)
                return oxe;
 
-       OBD_ALLOC(oxe, size);
+       OBD_ALLOC_LARGE(oxe, size);
        if (unlikely(!oxe))
                return NULL;
 
@@ -300,7 +300,7 @@ osp_oac_xattr_find_or_add(struct osp_object *obj, const char *name, size_t len)
        spin_unlock(&obj->opo_lock);
 
        if (tmp) {
-               OBD_FREE(oxe, size);
+               OBD_FREE_LARGE(oxe, size);
                oxe = tmp;
        }
 
@@ -332,7 +332,7 @@ osp_oac_xattr_assignment(struct osp_object *obj, struct osp_xattr_entry *oxe,
        bool unlink_only = false;
 
        if (oxe->oxe_buflen < size) {
-               OBD_ALLOC(new, size);
+               OBD_ALLOC_LARGE(new, size);
                if (likely(new)) {
                        INIT_LIST_HEAD(&new->oxe_list);
                        new->oxe_buflen = size;
@@ -431,11 +431,13 @@ static int osp_get_attr_from_reply(const struct lu_env *env,
                lustre_swab_obdo(wobdo);
 
        lustre_get_wire_obdo(NULL, lobdo, wobdo);
-       spin_lock(&obj->opo_lock);
-       la_from_obdo(&obj->opo_attr, lobdo, lobdo->o_valid);
-       if (attr != NULL)
-               *attr = obj->opo_attr;
-       spin_unlock(&obj->opo_lock);
+       if (obj) {
+               spin_lock(&obj->opo_lock);
+               la_from_obdo(&obj->opo_attr, lobdo, lobdo->o_valid);
+               spin_unlock(&obj->opo_lock);
+       }
+       if (attr)
+               la_from_obdo(attr, lobdo, lobdo->o_valid);
 
        return 0;
 }
@@ -542,7 +544,7 @@ int osp_attr_get(const struct lu_env *env, struct dt_object *dt,
        struct osp_update_request       *update;
        struct object_update_reply      *reply;
        struct ptlrpc_request           *req = NULL;
-       int                             rc = 0;
+       int                             invalidated, cache = 0, rc = 0;
        ENTRY;
 
        if (is_ost_obj(&dt->do_lu) && obj->opo_non_exist)
@@ -568,14 +570,24 @@ int osp_attr_get(const struct lu_env *env, struct dt_object *dt,
                       dev->dd_lu_dev.ld_obd->obd_name,
                       PFID(lu_object_fid(&dt->do_lu)), rc);
 
-               GOTO(out, rc);
+               GOTO(out_req, rc);
        }
 
+       invalidated = atomic_read(&obj->opo_invalidate_seq);
+
        rc = osp_remote_sync(env, osp, update, &req);
+
+       down_read(&obj->opo_invalidate_sem);
+       if (invalidated == atomic_read(&obj->opo_invalidate_seq)) {
+               /* no invalited has came so far, we can cache the attrs */
+               cache = 1;
+       }
+
        if (rc != 0) {
                if (rc == -ENOENT) {
                        osp2lu_obj(obj)->lo_header->loh_attr &= ~LOHA_EXISTS;
-                       obj->opo_non_exist = 1;
+                       if (cache)
+                               obj->opo_non_exist = 1;
                } else {
                        CERROR("%s:osp_attr_get update error "DFID": rc = %d\n",
                               dev->dd_lu_dev.ld_obd->obd_name,
@@ -593,17 +605,22 @@ 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, req, attr, obj, 0);
+       rc = osp_get_attr_from_reply(env, reply, req, attr,
+                                    cache ? obj : NULL, 0);
        if (rc != 0)
                GOTO(out, rc);
 
        spin_lock(&obj->opo_lock);
-       obj->opo_stale = 0;
+       if (cache)
+               obj->opo_stale = 0;
        spin_unlock(&obj->opo_lock);
 
        GOTO(out, rc);
 
 out:
+       up_read(&obj->opo_invalidate_sem);
+
+out_req:
        if (req != NULL)
                ptlrpc_req_finished(req);
 
@@ -938,7 +955,7 @@ int osp_xattr_get(const struct lu_env *env, struct dt_object *dt,
        struct object_update_reply *reply;
        struct osp_xattr_entry  *oxe    = NULL;
        const char *dname = osp_dto2name(obj);
-       int rc = 0;
+       int invalidated, rc = 0;
        ENTRY;
 
        LASSERT(buf != NULL);
@@ -958,6 +975,8 @@ int osp_xattr_get(const struct lu_env *env, struct dt_object *dt,
        if (unlikely(obj->opo_non_exist))
                RETURN(-ENOENT);
 
+       invalidated = atomic_read(&obj->opo_invalidate_seq);
+
        oxe = osp_oac_xattr_find(obj, name, false);
        if (oxe != NULL) {
                spin_lock(&obj->opo_lock);
@@ -986,17 +1005,40 @@ unlock:
        }
        update = osp_update_request_create(dev);
        if (IS_ERR(update))
-               GOTO(out, rc = PTR_ERR(update));
+               GOTO(out_req, rc = PTR_ERR(update));
 
        rc = OSP_UPDATE_RPC_PACK(env, out_xattr_get_pack, update,
                                 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);
-               GOTO(out, rc);
+               GOTO(out_req, rc);
        }
 
        rc = osp_remote_sync(env, osp, update, &req);
+
+       down_read(&obj->opo_invalidate_sem);
+       if (invalidated != atomic_read(&obj->opo_invalidate_seq)) {
+               /* invalidated has been requested, we can't cache the result */
+               if (rc < 0) {
+                       if (rc == -ENOENT)
+                               dt->do_lu.lo_header->loh_attr &= ~LOHA_EXISTS;
+                       GOTO(out, rc);
+               }
+               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->ourp_magic,
+                              UPDATE_REPLY_MAGIC,
+                              PFID(lu_object_fid(&dt->do_lu)), -EPROTO);
+                       GOTO(out, rc = -EPROTO);
+               }
+               rc = object_update_result_data_get(reply, rbuf, 0);
+               GOTO(out, rc);
+       }
+
        if (rc < 0) {
                if (rc == -ENOENT) {
                        dt->do_lu.lo_header->loh_attr &= ~LOHA_EXISTS;
@@ -1084,6 +1126,9 @@ unlock:
        GOTO(out, rc);
 
 out:
+       up_read(&obj->opo_invalidate_sem);
+
+out_req:
        if (rc > 0 && buf->lb_buf) {
                if (unlikely(buf->lb_len < rbuf->lb_len))
                        rc = -ERANGE;
@@ -1300,12 +1345,24 @@ int osp_invalidate(const struct lu_env *env, struct dt_object *dt)
 
        CDEBUG(D_HA, "Invalidate osp_object "DFID"\n",
               PFID(lu_object_fid(&dt->do_lu)));
-       osp_obj_invalidate_cache(obj);
+
+       /* serialize attr/EA set vs. invalidation */
+       down_write(&obj->opo_invalidate_sem);
+
+       /* this should invalidate all in-flights */
+       atomic_inc(&obj->opo_invalidate_seq);
 
        spin_lock(&obj->opo_lock);
-       obj->opo_stale = 1;
+       /* do not mark new objects stale */
+       if (obj->opo_attr.la_valid)
+               obj->opo_stale = 1;
+       obj->opo_non_exist = 0;
        spin_unlock(&obj->opo_lock);
 
+       osp_obj_invalidate_cache(obj);
+
+       up_write(&obj->opo_invalidate_sem);
+
        RETURN(0);
 }
 
@@ -1377,10 +1434,8 @@ static int osp_declare_create(const struct lu_env *env, struct dt_object *dt,
 
        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;
-
+               osp_objid_buf_prep(&osi->osi_lb, &osi->osi_off, NULL,
+                                  d->opd_index);
                rc = dt_declare_record_write(env, d->opd_last_used_oid_file,
                                             &osi->osi_lb, osi->osi_off,
                                             local_th);
@@ -1404,9 +1459,8 @@ static int osp_declare_create(const struct lu_env *env, struct dt_object *dt,
                o->opo_reserved = 1;
 
                /* 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;
+               osp_objid_buf_prep(&osi->osi_lb, &osi->osi_off, NULL,
+                                  d->opd_index);
                rc = dt_declare_record_write(env, d->opd_last_used_oid_file,
                                             &osi->osi_lb, osi->osi_off,
                                             local_th);
@@ -1449,7 +1503,6 @@ static int osp_create(const struct lu_env *env, struct dt_object *dt,
        int                     rc = 0;
        struct lu_fid           *fid = &osi->osi_fid;
        struct thandle          *local_th;
-       struct lu_fid           *last_fid = &d->opd_last_used_fid;
        ENTRY;
 
        if (is_only_remote_trans(th) &&
@@ -1529,13 +1582,8 @@ static int osp_create(const struct lu_env *env, struct dt_object *dt,
 
        /* Only need update last_used oid file, seq file will only be update
         * during seq rollover */
-       if (fid_is_idif((last_fid)))
-               osi->osi_id = fid_idif_id(fid_seq(last_fid),
-                                         fid_oid(last_fid), fid_ver(last_fid));
-       else
-               osi->osi_id = fid_oid(last_fid);
        osp_objid_buf_prep(&osi->osi_lb, &osi->osi_off,
-                          &osi->osi_id, d->opd_index);
+                          &d->opd_last_id, d->opd_index);
 
        rc = dt_record_write(env, d->opd_last_used_oid_file, &osi->osi_lb,
                             &osi->osi_off, local_th);
@@ -1713,7 +1761,7 @@ void osp_it_fini(const struct lu_env *env, struct dt_it *di)
                                __free_page(pages[i]);
                        }
                }
-               OBD_FREE(pages, npages * sizeof(*pages));
+               OBD_FREE_PTR_ARRAY(pages, npages);
        }
        OBD_FREE_PTR(it);
 }
@@ -1747,7 +1795,7 @@ static int osp_it_fetch(const struct lu_env *env, struct osp_it *it)
        npages = min_t(unsigned int, OFD_MAX_BRW_SIZE, 1 << 20);
        npages /= PAGE_SIZE;
 
-       OBD_ALLOC(pages, npages * sizeof(*pages));
+       OBD_ALLOC_PTR_ARRAY(pages, npages);
        if (pages == NULL)
                RETURN(-ENOMEM);
 
@@ -1796,7 +1844,7 @@ 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,
-                                   PTLRPC_BULK_PUT_SINK | PTLRPC_BULK_BUF_KIOV,
+                                   PTLRPC_BULK_PUT_SINK,
                                    MDS_BULK_PORTAL,
                                    &ptlrpc_bulk_kiov_pin_ops);
        if (desc == NULL)
@@ -1923,7 +1971,7 @@ again0:
                        if (pages[i] != NULL)
                                __free_page(pages[i]);
                }
-               OBD_FREE(pages, it->ooi_total_npages * sizeof(*pages));
+               OBD_FREE_PTR_ARRAY(pages, it->ooi_total_npages);
 
                it->ooi_pos_page = 0;
                it->ooi_total_npages = 0;
@@ -2196,6 +2244,7 @@ static int osp_object_init(const struct lu_env *env, struct lu_object *o,
        o->lo_header->loh_attr |= LOHA_REMOTE;
        INIT_LIST_HEAD(&po->opo_xattr_list);
        INIT_LIST_HEAD(&po->opo_invalidate_cb_list);
+       init_rwsem(&po->opo_invalidate_sem);
 
        if (is_ost_obj(o)) {
                po->opo_obj.do_ops = &osp_obj_ops;
@@ -2223,6 +2272,14 @@ static int osp_object_init(const struct lu_env *env, struct lu_object *o,
        RETURN(rc);
 }
 
+static void osp_object_free_rcu(struct rcu_head *head)
+{
+       struct osp_object *obj = container_of(head, struct osp_object,
+                                             opo_header.loh_rcu);
+
+       kmem_cache_free(osp_object_kmem, obj);
+}
+
 /**
  * Implement OSP layer lu_object_operations::loo_object_free() interface.
  *
@@ -2251,9 +2308,10 @@ static void osp_object_free(const struct lu_env *env, struct lu_object *o)
                         "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_LARGE(oxe, oxe->oxe_buflen);
        }
-       OBD_SLAB_FREE_PTR(obj, osp_object_kmem);
+       OBD_FREE_PRE(obj, sizeof(*obj), "slab-freed");
+       call_rcu(&obj->opo_header.loh_rcu, osp_object_free_rcu);
 }
 
 /**