]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: expand profile caps upon construction to avoid potential race
authorJason Dillaman <dillaman@redhat.com>
Tue, 11 Jul 2017 12:09:26 +0000 (08:09 -0400)
committerJason Dillaman <dillaman@redhat.com>
Fri, 21 Jul 2017 18:30:18 +0000 (14:30 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/osd/OSDCap.cc
src/osd/OSDCap.h
src/osd/PG.cc

index 43988dc7635d81e9ca57e4223b5fbd378ca93a96..c3aa6b6caa3a52b0d8081615e950b924fd6a7ff2 100644 (file)
@@ -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),
index 2c9ffa27c80a9e578edec9463ba5465b8e741418..4030d4572c4bcd3d5d8590230da56fe00d946c98 100644 (file)
@@ -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<OSDCapGrant> profile_grants;
+  std::list<OSDCapGrant> 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<OpRequest::ClassInfo>& classes,
                   std::vector<bool>* class_allowed) const;
 
-  void expand_profile() const;
+  void expand_profile();
 };
 
 ostream& operator<<(ostream& out, const OSDCapGrant& g);
index 3bc6db4d9e451866f382083460007b1a53ff9598..a42601f264001bd15b8785539d3786ee605ff03c 100644 (file)
@@ -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()