* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
- * Copyright (c) 2012, 2016, Intel Corporation.
+ * Copyright (c) 2012, 2017, Intel Corporation.
*/
/*
* lustre/osp/osp_object.c
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;
}
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)
if (IS_ERR(update))
RETURN(PTR_ERR(update));
- rc = osp_update_rpc_pack(env, attr_get, update, OUT_ATTR_GET,
+ rc = OSP_UPDATE_RPC_PACK(env, out_attr_get_pack, update,
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,
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,
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);
RETURN(0);
if (!is_only_remote_trans(th)) {
- rc = osp_sync_add(env, o, MDS_SETATTR64_REC, th, attr);
- /* XXX: send new uid/gid to OST ASAP? */
+ if (attr->la_flags & LUSTRE_SET_SYNC_FL) {
+ struct ptlrpc_request *req = NULL;
+ struct osp_update_request *update = NULL;
+ struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
+
+ update = osp_update_request_create(&osp->opd_dt_dev);
+ if (IS_ERR(update))
+ RETURN(PTR_ERR(update));
+
+ rc = OSP_UPDATE_RPC_PACK(env, out_attr_set_pack, update,
+ lu_object_fid(&dt->do_lu),
+ attr);
+ if (rc != 0) {
+ CERROR("%s: update error "DFID": rc = %d\n",
+ osp->opd_obd->obd_name,
+ PFID(lu_object_fid(&dt->do_lu)), rc);
+
+ osp_update_request_destroy(env, update);
+ RETURN(rc);
+ }
+
+ rc = osp_remote_sync(env, osp, update, &req);
+ if (req != NULL)
+ ptlrpc_req_finished(req);
+
+ osp_update_request_destroy(env, update);
+ } else {
+ rc = osp_sync_add(env, o, MDS_SETATTR64_REC, th, attr);
+ /* XXX: send new uid/gid to OST ASAP? */
+ }
} else {
struct lu_attr *la;
void *data, int index, int rc)
{
struct osp_xattr_entry *oxe = data;
- struct lu_buf *rbuf = &osp_env_info(env)->osi_lb2;
- if (!rc) {
+ spin_lock(&obj->opo_lock);
+ if (rc >= 0) {
+ struct lu_buf *rbuf = &osp_env_info(env)->osi_lb2;
size_t len = sizeof(*oxe) + oxe->oxe_namelen + 1;
rc = object_update_result_data_get(reply, rbuf, index);
- spin_lock(&obj->opo_lock);
- if (rc < 0 || rbuf->lb_len == 0 ||
- rbuf->lb_len > (oxe->oxe_buflen - len)) {
- if (unlikely(rc == -ENODATA)) {
- oxe->oxe_exist = 0;
- oxe->oxe_ready = 1;
- } else {
- oxe->oxe_ready = 0;
- }
- spin_unlock(&obj->opo_lock);
- /* Put the reference obtained in the
- * osp_declare_xattr_get(). */
- osp_oac_xattr_put(oxe);
+ if (rc == -ENOENT || rc == -ENODATA || rc == 0) {
+ oxe->oxe_exist = 0;
+ oxe->oxe_ready = 1;
+ goto unlock;
+ }
- return rc < 0 ? rc : -ERANGE;
+ if (unlikely(rc < 0) ||
+ rbuf->lb_len > (oxe->oxe_buflen - len)) {
+ oxe->oxe_ready = 0;
+ goto unlock;
}
__osp_oac_xattr_assignment(obj, oxe, rbuf);
- spin_unlock(&obj->opo_lock);
} else if (rc == -ENOENT || rc == -ENODATA) {
- spin_lock(&obj->opo_lock);
oxe->oxe_exist = 0;
oxe->oxe_ready = 1;
- spin_unlock(&obj->opo_lock);
} else {
- spin_lock(&obj->opo_lock);
oxe->oxe_ready = 0;
- spin_unlock(&obj->opo_lock);
}
+unlock:
+ spin_unlock(&obj->opo_lock);
+
/* Put the reference obtained in the osp_declare_xattr_get(). */
osp_oac_xattr_put(oxe);
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;
int rc = 0;
+ __u16 len;
LASSERT(buf != NULL);
LASSERT(name != NULL);
if (oxe == NULL)
return -ENOMEM;
- namelen = strlen(name);
+ len = strlen(name) + 1;
mutex_lock(&osp->opd_async_requests_mutex);
rc = osp_insert_async_request(env, OUT_XATTR_GET, obj, 1,
- &namelen, (const void **)&name,
+ &len, (const void **)&name,
oxe, buf->lb_len,
osp_xattr_get_interpterer);
if (rc != 0) {
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);
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);
}
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, xattr_get, update, OUT_XATTR_GET,
+ 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;
rc = object_update_result_data_get(reply, rbuf, 0);
if (rc < 0 || rbuf->lb_len == 0) {
+ if (oxe == NULL && rc == -ENODATA) {
+ oxe = osp_oac_xattr_find_or_add(obj, name, buf->lb_len);
+ if (oxe == NULL) {
+ rc = -ENOMEM;
+ CWARN("%s: Fail to add xattr (%s) to cache for "
+ DFID" (1): rc = %d\n", dname, name,
+ PFID(lu_object_fid(&dt->do_lu)), rc);
+ GOTO(out, rc);
+ }
+ }
+
if (oxe) {
spin_lock(&obj->opo_lock);
if (unlikely(rc == -ENODATA)) {
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;
const struct lu_buf *buf, const char *name, int fl,
struct thandle *th)
{
- struct osp_object *o = dt2osp_obj(dt);
+ struct osp_object *o = dt2osp_obj(dt);
struct osp_update_request *update;
- struct osp_xattr_entry *oxe;
- int rc;
+ struct osp_xattr_entry *oxe;
+ int rc;
ENTRY;
update = thandle_to_osp_update_request(th);
CDEBUG(D_INODE, DFID" set xattr '%s' with size %zd\n",
PFID(lu_object_fid(&dt->do_lu)), name, buf->lb_len);
- rc = osp_update_rpc_pack(env, xattr_set, update, OUT_XATTR_SET,
+ rc = OSP_UPDATE_RPC_PACK(env, out_xattr_set_pack, update,
lu_object_fid(&dt->do_lu), buf, name, fl);
if (rc != 0)
RETURN(rc);
const char *name, struct thandle *th)
{
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_xattr_entry *oxe;
- int rc;
+ const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
+ struct osp_object *o = dt2osp_obj(dt);
+ struct osp_xattr_entry *oxe;
+ int rc;
update = thandle_to_osp_update_request(th);
LASSERT(update != NULL);
- rc = osp_update_rpc_pack(env, xattr_del, update, OUT_XATTR_DEL,
- fid, name);
+ rc = OSP_UPDATE_RPC_PACK(env, out_xattr_del_pack, update, fid, name);
if (rc != 0)
return rc;
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);
}
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);
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);
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) &&
/* 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);
ENTRY;
LASSERT(!osp->opd_connect_mdt);
- rc = osp_sync_declare_add(env, o, MDS_UNLINK64_REC, th);
+
+ if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LOST_MDTOBJ))
+ rc = osp_sync_declare_add(env, o, MDS_UNLINK64_REC, th);
RETURN(rc);
}
o->opo_non_exist = 1;
LASSERT(!osp->opd_connect_mdt);
- /* once transaction is committed put proper command on
- * the queue going to our OST. */
- rc = osp_sync_add(env, o, MDS_UNLINK64_REC, th, NULL);
- if (rc < 0)
- RETURN(rc);
+
+ if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LOST_MDTOBJ)) {
+ /* once transaction is committed put proper command on
+ * the queue going to our OST. */
+ rc = osp_sync_add(env, o, MDS_UNLINK64_REC, th, NULL);
+ if (rc < 0)
+ RETURN(rc);
+ }
/* not needed in cache any more */
set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags);
struct dt_object *dt,
const struct dt_rec *rec,
const struct dt_key *key,
- struct thandle *handle,
- int ignore_quota)
+ struct thandle *handle)
{
return -EOPNOTSUPP;
}
it->ooi_pos_ent++;
if (it->ooi_pos_ent < idxpage->lip_nr) {
if (it->ooi_rec_size ==
+ sizeof(struct lu_orphan_rec_v3)) {
+ it->ooi_ent =
+ (struct lu_orphan_ent_v3 *)idxpage->lip_entries+
+ it->ooi_pos_ent;
+ if (it->ooi_swab)
+ lustre_swab_orphan_ent_v3(it->ooi_ent);
+ } else if (it->ooi_rec_size ==
sizeof(struct lu_orphan_rec_v2)) {
it->ooi_ent =
(struct lu_orphan_ent_v2 *)idxpage->lip_entries+
struct osp_it *it = (struct osp_it *)di;
if (likely(it->ooi_ent)) {
- if (it->ooi_rec_size == sizeof(struct lu_orphan_rec_v2)) {
+ if (it->ooi_rec_size == sizeof(struct lu_orphan_rec_v3)) {
+ struct lu_orphan_ent_v3 *ent =
+ (struct lu_orphan_ent_v3 *)it->ooi_ent;
+
+ *(struct lu_orphan_rec_v3 *)rec = ent->loe_rec;
+ } else if (it->ooi_rec_size ==
+ sizeof(struct lu_orphan_rec_v2)) {
struct lu_orphan_ent_v2 *ent =
(struct lu_orphan_ent_v2 *)it->ooi_ent;
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;
d->opd_pre_reserved--;
spin_unlock(&d->opd_pre_lock);
+ /*
+ * Check that osp_precreate_cleanup_orphans is not blocked
+ * due to opd_pre_reserved > 0.
+ */
+ if (unlikely(d->opd_pre_reserved == 0 &&
+ (d->opd_pre_recovering || d->opd_pre_status)))
+ wake_up(&d->opd_pre_waitq);
+
/* not needed in cache any more */
set_bit(LU_OBJECT_HEARD_BANSHEE, &o->lo_header->loh_flags);
}