From: Jason Dillaman Date: Tue, 11 Jul 2017 12:09:26 +0000 (-0400) Subject: osd: expand profile caps upon construction to avoid potential race X-Git-Tag: v12.1.2~162^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e1d439f2fb47425e8cd978747ae255cfb9ac9b41;p=ceph.git osd: expand profile caps upon construction to avoid potential race Signed-off-by: Jason Dillaman --- diff --git a/src/osd/OSDCap.cc b/src/osd/OSDCap.cc index 43988dc7635d..c3aa6b6caa3a 100644 --- a/src/osd/OSDCap.cc +++ b/src/osd/OSDCap.cc @@ -86,7 +86,7 @@ ostream& operator<<(ostream& out, const OSDCapMatch& m) ostream& operator<<(ostream& out, const OSDCapProfile& m) { - out << "profile " << m.name << " "; + out << "profile " << m.name; out << m.pool_namespace; return out; } @@ -151,7 +151,15 @@ ostream& operator<<(ostream& out, const OSDCapGrant& g) { out << "grant("; if (g.profile.is_valid()) { - out << g.profile; + out << g.profile << " ["; + for (auto it = g.profile_grants.cbegin(); + it != g.profile_grants.cend(); ++it) { + if (it != g.profile_grants.cbegin()) { + out << ","; + } + out << *it; + } + out << "]"; } else { out << g.match << g.spec; } @@ -162,7 +170,6 @@ ostream& operator<<(ostream& out, const OSDCapGrant& g) bool OSDCapGrant::allow_all() const { if (profile.is_valid()) { - expand_profile(); return std::any_of(profile_grants.cbegin(), profile_grants.cend(), [](const OSDCapGrant& grant) { return grant.allow_all(); @@ -180,7 +187,6 @@ bool OSDCapGrant::is_capable(const string& pool_name, const string& ns, { osd_rwxa_t allow = 0; if (profile.is_valid()) { - expand_profile(); return std::any_of(profile_grants.cbegin(), profile_grants.cend(), [&](const OSDCapGrant& grant) { return grant.is_capable(pool_name, ns, pool_auid, object, op_may_read, @@ -227,13 +233,8 @@ bool OSDCapGrant::is_capable(const string& pool_name, const string& ns, return false; } -void OSDCapGrant::expand_profile() const +void OSDCapGrant::expand_profile() { - // only generate this list once - if (!profile_grants.empty()) { - return; - } - if (profile.name == "read-only") { // grants READ-ONLY caps to the OSD profile_grants.emplace_back(OSDCapMatch(profile.pool_namespace), diff --git a/src/osd/OSDCap.h b/src/osd/OSDCap.h index 2c9ffa27c80a..4030d4572c4b 100644 --- a/src/osd/OSDCap.h +++ b/src/osd/OSDCap.h @@ -155,11 +155,12 @@ struct OSDCapGrant { // explicit grants that a profile grant expands to; populated as // needed by expand_profile() and cached here. - mutable std::list profile_grants; + std::list profile_grants; OSDCapGrant() {} OSDCapGrant(const OSDCapMatch& m, const OSDCapSpec& s) : match(m), spec(s) {} OSDCapGrant(const OSDCapProfile& profile) : profile(profile) { + expand_profile(); } bool allow_all() const; @@ -168,7 +169,7 @@ struct OSDCapGrant { const std::vector& classes, std::vector* class_allowed) const; - void expand_profile() const; + void expand_profile(); }; ostream& operator<<(ostream& out, const OSDCapGrant& g); diff --git a/src/osd/PG.cc b/src/osd/PG.cc index 3bc6db4d9e45..a42601f26400 100644 --- a/src/osd/PG.cc +++ b/src/osd/PG.cc @@ -1877,8 +1877,10 @@ bool PG::op_has_sufficient_caps(OpRequestRef& op) op->need_write_cap(), op->classes()); - dout(20) << "op_has_sufficient_caps pool=" << pool.id << " (" << pool.name - << " " << req->get_hobj().nspace + dout(20) << "op_has_sufficient_caps " + << "session=" << session + << " pool=" << pool.id << " (" << pool.name + << " " << req->get_hobj().nspace << ") owner=" << pool.auid << " need_read_cap=" << op->need_read_cap() << " need_write_cap=" << op->need_write_cap()