Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

osd: constify OpRequest::get_req(); fix a few cases of operator<< vs mutated message races #13545

Merged
merged 28 commits into from Feb 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b0faed7
messages/MOSDPGPull: make pulls vector private
liewegas Feb 16, 2017
769ed7b
osd/ECBackend: remove no-op set_priority calls
liewegas Feb 16, 2017
72d72da
osd: avoid require_mon_peer stray put()
liewegas Feb 16, 2017
7c991aa
osd/OpRequest: add get_nonconst_req()
liewegas Feb 18, 2017
71dc3cf
common/RefCountedObject: allow refs to const objects
liewegas Feb 18, 2017
45426f7
osd: constify a bit
liewegas Feb 16, 2017
504edae
msg/Message: add const variant for get_data()
liewegas Feb 20, 2017
b01dbd3
os/ObjectStore: make setattrs take const attrset
liewegas Feb 20, 2017
6fd447b
osd: add some const to MOSDPGLog handling; document non-constness of log
liewegas Feb 20, 2017
1b2b063
osd: make message check helpers const
liewegas Feb 20, 2017
cfdf7eb
osd/Session: const Message* for check_backoff
liewegas Feb 20, 2017
a61fcc4
osd/ReplicatedBackend: constify
liewegas Feb 20, 2017
cb76f60
osd/ECBackend: constify
liewegas Feb 20, 2017
97c9b3a
osd/ECBackend: cast const Message*'s where possible; annotate where not
liewegas Feb 20, 2017
19c5240
osd/PG: take const refs to pg info where possible
liewegas Feb 20, 2017
854eee2
osd/PrimaryLogPG: non-const helpers where possible
liewegas Feb 20, 2017
c8c6267
osd: constify handle_pg_notify
liewegas Feb 20, 2017
6d9857c
osd: constify handle_pg_remove
liewegas Feb 20, 2017
db805f6
osd: constify handle_pg_query
liewegas Feb 20, 2017
8435311
osd: constify handle_pg_create
liewegas Feb 20, 2017
1f7f4de
osd: constify handle_pg_info
liewegas Feb 20, 2017
16e99f6
osd: constify misc messages
liewegas Feb 20, 2017
6a0fe7e
osd: cast const Message*'s where we can
liewegas Feb 20, 2017
855cc87
osd/PG: cast const messages where we can
liewegas Feb 20, 2017
b8e7b10
osd/PGBackend: take const where we can
liewegas Feb 20, 2017
d66aca0
osd/PrimaryLogPG: annotate non-const MOSDOp casts
liewegas Feb 20, 2017
a3f601c
osd/PrimaryLogPG: cast const Message*'s where possible
liewegas Feb 20, 2017
a4feab5
osd/OpRequest: make get_req() return const
liewegas Feb 20, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/common/RefCountedObj.cc
Expand Up @@ -14,10 +14,10 @@

#include "common/RefCountedObj.h"

void intrusive_ptr_add_ref(RefCountedObject *p) {
void intrusive_ptr_add_ref(const RefCountedObject *p) {
p->get();
}
void intrusive_ptr_release(RefCountedObject *p) {
void intrusive_ptr_release(const RefCountedObject *p) {
p->put();
}

16 changes: 12 additions & 4 deletions src/common/RefCountedObj.h
Expand Up @@ -23,14 +23,22 @@

struct RefCountedObject {
private:
atomic_t nref;
mutable atomic_t nref;
CephContext *cct;
public:
RefCountedObject(CephContext *c = NULL, int n=1) : nref(n), cct(c) {}
virtual ~RefCountedObject() {
assert(nref.read() == 0);
}

const RefCountedObject *get() const {
int v = nref.inc();
if (cct)
lsubdout(cct, refs, 1) << "RefCountedObject::get " << this << " "
<< (v - 1) << " -> " << v
<< dendl;
return this;
}
RefCountedObject *get() {
int v = nref.inc();
if (cct)
Expand All @@ -39,7 +47,7 @@ struct RefCountedObject {
<< dendl;
return this;
}
void put() {
void put() const {
CephContext *local_cct = cct;
int v = nref.dec();
if (v == 0) {
Expand Down Expand Up @@ -151,7 +159,7 @@ struct RefCountedWaitObject {
}
};

void intrusive_ptr_add_ref(RefCountedObject *p);
void intrusive_ptr_release(RefCountedObject *p);
void intrusive_ptr_add_ref(const RefCountedObject *p);
void intrusive_ptr_release(const RefCountedObject *p);

#endif
2 changes: 1 addition & 1 deletion src/messages/MOSDFailure.h
Expand Up @@ -59,7 +59,7 @@ class MOSDFailure : public PaxosServiceMessage {
bool is_immediate() const {
return flags & FLAG_IMMEDIATE;
}
epoch_t get_epoch() { return epoch; }
epoch_t get_epoch() const { return epoch; }

void decode_payload() {
bufferlist::iterator p = payload.begin();
Expand Down
4 changes: 2 additions & 2 deletions src/messages/MOSDMarkMeDown.h
Expand Up @@ -40,8 +40,8 @@ class MOSDMarkMeDown : public PaxosServiceMessage {
~MOSDMarkMeDown() {}

public:
entity_inst_t get_target() { return target_osd; }
epoch_t get_epoch() { return epoch; }
entity_inst_t get_target() const { return target_osd; }
epoch_t get_epoch() const { return epoch; }

void decode_payload() {
bufferlist::iterator p = payload.begin();
Expand Down
6 changes: 3 additions & 3 deletions src/messages/MOSDOp.h
Expand Up @@ -130,14 +130,14 @@ class MOSDOp : public MOSDFastDispatchOp {
else
return object_locator_t(hobj);
}
object_t& get_oid() {
const object_t& get_oid() const {
assert(!final_decode_needed);
return hobj.oid;
}
const hobject_t &get_hobj() const {
return hobj;
}
snapid_t get_snapid() {
snapid_t get_snapid() const {
assert(!final_decode_needed);
return hobj.snap;
}
Expand Down Expand Up @@ -231,7 +231,7 @@ class MOSDOp : public MOSDFastDispatchOp {
add_simple_op(CEPH_OSD_OP_STAT, 0, 0);
}

bool has_flag(__u32 flag) { return flags & flag; };
bool has_flag(__u32 flag) const { return flags & flag; };
bool wants_ack() const { return flags & CEPH_OSD_FLAG_ACK; }
bool wants_ondisk() const { return flags & CEPH_OSD_FLAG_ONDISK; }
bool wants_onnvram() const { return flags & CEPH_OSD_FLAG_ONNVRAM; }
Expand Down
3 changes: 2 additions & 1 deletion src/messages/MOSDOpReply.h
Expand Up @@ -128,7 +128,8 @@ class MOSDOpReply : public Message {
: Message(CEPH_MSG_OSD_OPREPLY, HEAD_VERSION, COMPAT_VERSION) {
do_redirect = false;
}
MOSDOpReply(MOSDOp *req, int r, epoch_t e, int acktype, bool ignore_out_data)
MOSDOpReply(const MOSDOp *req, int r, epoch_t e, int acktype,
bool ignore_out_data)
: Message(CEPH_MSG_OSD_OPREPLY, HEAD_VERSION, COMPAT_VERSION),
oid(req->hobj.oid), pgid(req->pgid.pgid), ops(req->ops) {

Expand Down
2 changes: 1 addition & 1 deletion src/messages/MOSDPGInfo.h
Expand Up @@ -28,7 +28,7 @@ class MOSDPGInfo : public Message {
public:
vector<pair<pg_notify_t,pg_interval_map_t> > pg_list;

epoch_t get_epoch() { return epoch; }
epoch_t get_epoch() const { return epoch; }

MOSDPGInfo()
: Message(MSG_OSD_PG_INFO, HEAD_VERSION, COMPAT_VERSION) {
Expand Down
8 changes: 5 additions & 3 deletions src/messages/MOSDPGLog.h
Expand Up @@ -38,9 +38,9 @@ class MOSDPGLog : public Message {
pg_missing_t missing;
pg_interval_map_t past_intervals;

epoch_t get_epoch() { return epoch; }
spg_t get_pgid() { return spg_t(info.pgid.pgid, to); }
epoch_t get_query_epoch() { return query_epoch; }
epoch_t get_epoch() const { return epoch; }
spg_t get_pgid() const { return spg_t(info.pgid.pgid, to); }
epoch_t get_query_epoch() const { return query_epoch; }

MOSDPGLog() : Message(MSG_OSD_PG_LOG, HEAD_VERSION, COMPAT_VERSION) {
set_priority(CEPH_MSG_PRIO_HIGH);
Expand All @@ -67,6 +67,8 @@ class MOSDPGLog : public Message {
public:
const char *get_type_name() const { return "PGlog"; }
void print(ostream& out) const {
// NOTE: log is not const, but operator<< doesn't touch fields
// swapped out by OSD code.
out << "pg_log(" << info.pgid << " epoch " << epoch
<< " log " << log
<< " query_epoch " << query_epoch << ")";
Expand Down
8 changes: 5 additions & 3 deletions src/messages/MOSDPGNotify.h
Expand Up @@ -36,12 +36,14 @@ class MOSDPGNotify : public Message {
vector<pair<pg_notify_t,pg_interval_map_t> > pg_list; // pgid -> version

public:
version_t get_epoch() { return epoch; }
vector<pair<pg_notify_t,pg_interval_map_t> >& get_pg_list() { return pg_list; }
version_t get_epoch() const { return epoch; }
const vector<pair<pg_notify_t,pg_interval_map_t> >& get_pg_list() const {
return pg_list;
}

MOSDPGNotify()
: Message(MSG_OSD_PG_NOTIFY, HEAD_VERSION, COMPAT_VERSION) {
set_priority(CEPH_MSG_PRIO_HIGH);
set_priority(CEPH_MSG_PRIO_HIGH);
}
MOSDPGNotify(epoch_t e, vector<pair<pg_notify_t,pg_interval_map_t> >& l)
: Message(MSG_OSD_PG_NOTIFY, HEAD_VERSION, COMPAT_VERSION),
Expand Down
15 changes: 11 additions & 4 deletions src/messages/MOSDPGPull.h
Expand Up @@ -21,12 +21,12 @@ class MOSDPGPull : public MOSDFastDispatchOp {
static const int HEAD_VERSION = 2;
static const int COMPAT_VERSION = 1;

vector<PullOp> pulls;

public:
pg_shard_t from;
spg_t pgid;
epoch_t map_epoch;
vector<PullOp> pulls;
uint64_t cost;

epoch_t get_map_epoch() const override {
Expand All @@ -36,6 +36,13 @@ class MOSDPGPull : public MOSDFastDispatchOp {
return pgid;
}

void take_pulls(vector<PullOp> *outpulls) {
outpulls->swap(pulls);
}
void set_pulls(vector<PullOp> *inpulls) {
inpulls->swap(pulls);
}

MOSDPGPull()
: MOSDFastDispatchOp(MSG_OSD_PG_PULL, HEAD_VERSION, COMPAT_VERSION),
cost(0)
Expand Down Expand Up @@ -82,9 +89,9 @@ class MOSDPGPull : public MOSDFastDispatchOp {

void print(ostream& out) const {
out << "MOSDPGPull(" << pgid
<< " " << map_epoch
<< " " << pulls;
out << ")";
<< " e" << map_epoch
<< " cost " << cost
<< ")";
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/messages/MOSDPGQuery.h
Expand Up @@ -29,7 +29,7 @@ class MOSDPGQuery : public Message {
version_t epoch;

public:
version_t get_epoch() { return epoch; }
version_t get_epoch() const { return epoch; }
map<spg_t, pg_query_t> pg_list;

MOSDPGQuery() : Message(MSG_OSD_PG_QUERY,
Expand Down
2 changes: 1 addition & 1 deletion src/messages/MOSDPGRemove.h
Expand Up @@ -30,7 +30,7 @@ class MOSDPGRemove : public Message {
public:
vector<spg_t> pg_list;

epoch_t get_epoch() { return epoch; }
epoch_t get_epoch() const { return epoch; }

MOSDPGRemove() :
Message(MSG_OSD_PG_REMOVE, HEAD_VERSION, COMPAT_VERSION) {}
Expand Down
2 changes: 1 addition & 1 deletion src/messages/MOSDPGTrim.h
Expand Up @@ -27,7 +27,7 @@ class MOSDPGTrim : public Message {
spg_t pgid;
eversion_t trim_to;

epoch_t get_epoch() { return epoch; }
epoch_t get_epoch() const { return epoch; }

MOSDPGTrim() : Message(MSG_OSD_PG_TRIM, HEAD_VERSION, COMPAT_VERSION) {}
MOSDPGTrim(version_t mv, spg_t p, eversion_t tt) :
Expand Down
4 changes: 2 additions & 2 deletions src/messages/MOSDRepOpReply.h
Expand Up @@ -95,11 +95,11 @@ class MOSDRepOpReply : public MOSDFastDispatchOp {
int get_result() { return result; }

void set_last_complete_ondisk(eversion_t v) { last_complete_ondisk = v; }
eversion_t get_last_complete_ondisk() { return last_complete_ondisk; }
eversion_t get_last_complete_ondisk() const { return last_complete_ondisk; }

public:
MOSDRepOpReply(
MOSDRepOp *req, pg_shard_t from, int result_, epoch_t e, int at) :
const MOSDRepOp *req, pg_shard_t from, int result_, epoch_t e, int at) :
MOSDFastDispatchOp(MSG_OSD_REPOPREPLY, HEAD_VERSION, COMPAT_VERSION),
map_epoch(e),
reqid(req->reqid),
Expand Down
6 changes: 3 additions & 3 deletions src/messages/MOSDSubOpReply.h
Expand Up @@ -116,8 +116,8 @@ class MOSDSubOpReply : public MOSDFastDispatchOp {

epoch_t get_map_epoch() { return map_epoch; }

spg_t get_pg() { return pgid; }
hobject_t get_poid() { return poid; }
spg_t get_pg() const { return pgid; }
const hobject_t& get_poid() const { return poid; }

int get_ack_type() { return ack_type; }
bool is_ondisk() { return ack_type & CEPH_OSD_FLAG_ONDISK; }
Expand All @@ -136,7 +136,7 @@ class MOSDSubOpReply : public MOSDFastDispatchOp {

public:
MOSDSubOpReply(
MOSDSubOp *req, pg_shard_t from, int result_, epoch_t e, int at)
const MOSDSubOp *req, pg_shard_t from, int result_, epoch_t e, int at)
: MOSDFastDispatchOp(MSG_OSD_SUBOPREPLY, HEAD_VERSION, COMPAT_VERSION),
map_epoch(e),
reqid(req->reqid),
Expand Down
1 change: 1 addition & 0 deletions src/msg/Message.h
Expand Up @@ -376,6 +376,7 @@ class Message : public RefCountedObject {
byte_throttler->take(data.length());
}

const bufferlist& get_data() const { return data; }
bufferlist& get_data() { return data; }
void claim_data(bufferlist& bl,
unsigned int flags = buffer::list::CLAIM_DEFAULT) {
Expand Down
4 changes: 2 additions & 2 deletions src/os/ObjectStore.h
Expand Up @@ -1114,7 +1114,7 @@ class ObjectStore {
data.ops++;
}
/// Set multiple xattrs of an object
void setattrs(const coll_t& cid, const ghobject_t& oid, map<string,bufferptr>& attrset) {
void setattrs(const coll_t& cid, const ghobject_t& oid, const map<string,bufferptr>& attrset) {
Op* _op = _get_next_op();
_op->op = OP_SETATTRS;
_op->cid = _get_coll_id(cid);
Expand All @@ -1123,7 +1123,7 @@ class ObjectStore {
data.ops++;
}
/// Set multiple xattrs of an object
void setattrs(const coll_t& cid, const ghobject_t& oid, map<string,bufferlist>& attrset) {
void setattrs(const coll_t& cid, const ghobject_t& oid, const map<string,bufferlist>& attrset) {
Op* _op = _get_next_op();
_op->op = OP_SETATTRS;
_op->cid = _get_coll_id(cid);
Expand Down