librados: fix narrow race with tid return value assignment

The completion should be done by the time op_submit returns.

Signed-off-by: Sage Weil <sage@redhat.com>
This commit is contained in:
Sage Weil 2016-03-11 13:19:34 -05:00
parent b7eb86fe30
commit 4a88a7f1ce
3 changed files with 69 additions and 26 deletions

View File

@ -745,7 +745,7 @@ int librados::IoCtxImpl::aio_operate_read(const object_t &oid,
Objecter::Op *objecter_op = objecter->prepare_read_op(oid, oloc,
*o, snap_seq, pbl, flags,
onack, &c->objver);
c->tid = objecter->op_submit(objecter_op);
objecter->op_submit(objecter_op, &c->tid);
return 0;
}

View File

@ -2125,12 +2125,13 @@ void Objecter::resend_mon_ops()
// read | write ---------------------------
ceph_tid_t Objecter::op_submit(Op *op, int *ctx_budget)
void Objecter::op_submit(Op *op, ceph_tid_t *ptid, int *ctx_budget)
{
shunique_lock rl(rwlock, ceph::acquire_shared);
ceph_tid_t tid = 0;
_op_submit_with_budget(op, rl, &tid, ctx_budget);
return tid;
if (!ptid)
ptid = &tid;
_op_submit_with_budget(op, rl, ptid, ctx_budget);
}
void Objecter::_op_submit_with_budget(Op *op, shunique_lock& sul,

View File

@ -2082,7 +2082,7 @@ private:
// public interface
public:
ceph_tid_t op_submit(Op *op, int *ctx_budget = NULL);
void op_submit(Op *op, ceph_tid_t *ptid = NULL, int *ctx_budget = NULL);
bool is_active() {
shared_lock l(rwlock);
return !((!inflight_ops.read()) && linger_ops.empty() &&
@ -2195,7 +2195,9 @@ public:
osd_reqid_t reqid = osd_reqid_t()) {
Op *o = prepare_mutate_op(oid, oloc, op, snapc, mtime, flags, onack,
oncommit, objver, reqid);
return op_submit(o);
ceph_tid_t tid;
op_submit(o, &tid);
return tid;
}
Op *prepare_read_op(const object_t& oid, const object_locator_t& oloc,
ObjectOperation& op,
@ -2224,7 +2226,9 @@ public:
data_offset);
if (features)
o->features = features;
return op_submit(o);
ceph_tid_t tid;
op_submit(o, &tid);
return tid;
}
ceph_tid_t pg_read(uint32_t hash, object_locator_t oloc,
ObjectOperation& op, bufferlist *pbl, int flags,
@ -2246,7 +2250,9 @@ public:
// budget is tracked by listing context
o->ctx_budgeted = true;
}
return op_submit(o, ctx_budget);
ceph_tid_t tid;
op_submit(o, &tid, ctx_budget);
return tid;
}
// caller owns a ref
@ -2310,7 +2316,9 @@ public:
CEPH_OSD_FLAG_READ, fin, 0, objver);
o->snapid = snap;
o->outbl = &fin->bl;
return op_submit(o);
ceph_tid_t tid;
op_submit(o, &tid);
return tid;
}
ceph_tid_t read(const object_t& oid, const object_locator_t& oloc,
@ -2329,7 +2337,9 @@ public:
CEPH_OSD_FLAG_READ, onfinish, 0, objver);
o->snapid = snap;
o->outbl = pbl;
return op_submit(o);
ceph_tid_t tid;
op_submit(o, &tid);
return tid;
}
ceph_tid_t read_trunc(const object_t& oid, const object_locator_t& oloc,
@ -2350,7 +2360,9 @@ public:
CEPH_OSD_FLAG_READ, onfinish, 0, objver);
o->snapid = snap;
o->outbl = pbl;
return op_submit(o);
ceph_tid_t tid;
op_submit(o, &tid);
return tid;
}
ceph_tid_t mapext(const object_t& oid, const object_locator_t& oloc,
uint64_t off, uint64_t len, snapid_t snap, bufferlist *pbl,
@ -2367,7 +2379,9 @@ public:
CEPH_OSD_FLAG_READ, onfinish, 0, objver);
o->snapid = snap;
o->outbl = pbl;
return op_submit(o);
ceph_tid_t tid;
op_submit(o, &tid);
return tid;
}
ceph_tid_t getxattr(const object_t& oid, const object_locator_t& oloc,
const char *name, snapid_t snap, bufferlist *pbl, int flags,
@ -2384,7 +2398,9 @@ public:
CEPH_OSD_FLAG_READ, onfinish, 0, objver);
o->snapid = snap;
o->outbl = pbl;
return op_submit(o);
ceph_tid_t tid;
op_submit(o, &tid);
return tid;
}
ceph_tid_t getxattrs(const object_t& oid, const object_locator_t& oloc,
@ -2399,7 +2415,9 @@ public:
CEPH_OSD_FLAG_READ, fin, 0, objver);
o->snapid = snap;
o->outbl = &fin->bl;
return op_submit(o);
ceph_tid_t tid;
op_submit(o, &tid);
return tid;
}
ceph_tid_t read_full(const object_t& oid, const object_locator_t& oloc,
@ -2421,7 +2439,9 @@ public:
CEPH_OSD_FLAG_WRITE, onack, oncommit, objver);
o->mtime = mtime;
o->snapc = snapc;
return op_submit(o);
ceph_tid_t tid;
op_submit(o, &tid);
return tid;
}
ceph_tid_t write(const object_t& oid, const object_locator_t& oloc,
uint64_t off, uint64_t len, const SnapContext& snapc,
@ -2441,7 +2461,9 @@ public:
CEPH_OSD_FLAG_WRITE, onack, oncommit, objver);
o->mtime = mtime;
o->snapc = snapc;
return op_submit(o);
ceph_tid_t tid;
op_submit(o, &tid);
return tid;
}
ceph_tid_t append(const object_t& oid, const object_locator_t& oloc,
uint64_t len, const SnapContext& snapc,
@ -2461,7 +2483,9 @@ public:
CEPH_OSD_FLAG_WRITE, onack, oncommit, objver);
o->mtime = mtime;
o->snapc = snapc;
return op_submit(o);
ceph_tid_t tid;
op_submit(o, &tid);
return tid;
}
ceph_tid_t write_trunc(const object_t& oid, const object_locator_t& oloc,
uint64_t off, uint64_t len, const SnapContext& snapc,
@ -2483,7 +2507,9 @@ public:
CEPH_OSD_FLAG_WRITE, onack, oncommit, objver);
o->mtime = mtime;
o->snapc = snapc;
return op_submit(o);
ceph_tid_t tid;
op_submit(o, &tid);
return tid;
}
ceph_tid_t write_full(const object_t& oid, const object_locator_t& oloc,
const SnapContext& snapc, const bufferlist &bl,
@ -2501,7 +2527,9 @@ public:
CEPH_OSD_FLAG_WRITE, onack, oncommit, objver);
o->mtime = mtime;
o->snapc = snapc;
return op_submit(o);
ceph_tid_t tid;
op_submit(o, &tid);
return tid;
}
ceph_tid_t trunc(const object_t& oid, const object_locator_t& oloc,
const SnapContext& snapc, ceph::real_time mtime, int flags,
@ -2518,7 +2546,9 @@ public:
CEPH_OSD_FLAG_WRITE, onack, oncommit, objver);
o->mtime = mtime;
o->snapc = snapc;
return op_submit(o);
ceph_tid_t tid;
op_submit(o, &tid);
return tid;
}
ceph_tid_t zero(const object_t& oid, const object_locator_t& oloc,
uint64_t off, uint64_t len, const SnapContext& snapc,
@ -2533,7 +2563,9 @@ public:
CEPH_OSD_FLAG_WRITE, onack, oncommit, objver);
o->mtime = mtime;
o->snapc = snapc;
return op_submit(o);
ceph_tid_t tid;
op_submit(o, &tid);
return tid;
}
ceph_tid_t rollback_object(const object_t& oid, const object_locator_t& oloc,
const SnapContext& snapc, snapid_t snapid,
@ -2548,7 +2580,9 @@ public:
objver);
o->mtime = mtime;
o->snapc = snapc;
return op_submit(o);
ceph_tid_t tid;
op_submit(o, &tid);
return tid;
}
ceph_tid_t create(const object_t& oid, const object_locator_t& oloc,
const SnapContext& snapc, ceph::real_time mtime, int global_flags,
@ -2563,7 +2597,9 @@ public:
CEPH_OSD_FLAG_WRITE, onack, oncommit, objver);
o->mtime = mtime;
o->snapc = snapc;
return op_submit(o);
ceph_tid_t tid;
op_submit(o, &tid);
return tid;
}
ceph_tid_t remove(const object_t& oid, const object_locator_t& oloc,
const SnapContext& snapc, ceph::real_time mtime, int flags,
@ -2576,7 +2612,9 @@ public:
CEPH_OSD_FLAG_WRITE, onack, oncommit, objver);
o->mtime = mtime;
o->snapc = snapc;
return op_submit(o);
ceph_tid_t tid;
op_submit(o, &tid);
return tid;
}
ceph_tid_t setxattr(const object_t& oid, const object_locator_t& oloc,
@ -2596,7 +2634,9 @@ public:
CEPH_OSD_FLAG_WRITE, onack, oncommit, objver);
o->mtime = mtime;
o->snapc = snapc;
return op_submit(o);
ceph_tid_t tid;
op_submit(o, &tid);
return tid;
}
ceph_tid_t removexattr(const object_t& oid, const object_locator_t& oloc,
const char *name, const SnapContext& snapc,
@ -2614,7 +2654,9 @@ public:
CEPH_OSD_FLAG_WRITE, onack, oncommit, objver);
o->mtime = mtime;
o->snapc = snapc;
return op_submit(o);
ceph_tid_t tid;
op_submit(o, &tid);
return tid;
}
void list_nobjects(NListContext *p, Context *onfinish);