]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
client: track cap hits and misses globally
authorVenky Shankar <vshankar@redhat.com>
Thu, 23 Jul 2020 05:20:38 +0000 (01:20 -0400)
committerVenky Shankar <vshankar@redhat.com>
Wed, 29 Jul 2020 10:11:07 +0000 (06:11 -0400)
Signed-off-by: Venky Shankar <vshankar@redhat.com>
src/client/Client.cc
src/client/Client.h
src/client/Inode.cc

index 1e884075220f4028bd8e894fc713fa733a12801b..d9c0bb0d270830b5792fee04be37536d4b1a797f 100755 (executable)
@@ -3230,6 +3230,10 @@ void Client::put_cap_ref(Inode *in, int cap)
   }
 }
 
+// get caps for a given file handle -- the inode should have @need caps
+// issued by the mds and @want caps not revoked (or not under revocation).
+// this routine blocks till the cap requirement is satisfied. also account
+// (track) for capability hit when required (when cap requirement succeedes).
 int Client::get_caps(Fh *fh, int need, int want, int *phave, loff_t endoff)
 {
   Inode *in = fh->inode.get();
@@ -3304,6 +3308,7 @@ int Client::get_caps(Fh *fh, int need, int want, int *phave, loff_t endoff)
        if ((revoking & want) == 0) {
          *phave = need | (have & want);
          in->get_cap_ref(need);
+         cap_hit();
          return 0;
        }
       }
index 15bf6a9cd8dbc43b8a6177f5e256d2299e30ccdb..002357a3ee596de5ac615d6ae23fcc3e358ca061 100644 (file)
@@ -732,6 +732,16 @@ public:
   void flush_cap_releases();
   void tick();
 
+  void cap_hit() {
+    ++cap_hits;
+  }
+  void cap_miss() {
+    ++cap_misses;
+  }
+  std::pair<uint64_t, uint64_t> get_cap_hit_rates() {
+    return std::make_pair(cap_hits, cap_misses);
+  }
+
   xlist<Inode*> &get_dirty_list() { return dirty_list; }
 
   SafeTimer timer;
@@ -1281,6 +1291,9 @@ private:
   int reclaim_errno = 0;
   epoch_t reclaim_osd_epoch = 0;
   entity_addrvec_t reclaim_target_addrs;
+
+  uint64_t cap_hits = 0;
+  uint64_t cap_misses = 0;
 };
 
 /**
index 2b7738adf4a5b70192761b781d539af25d2439da..ab27d1eb4f115fb0b0507e325b5e2e6a9bd80639 100644 (file)
@@ -232,6 +232,7 @@ void Inode::try_touch_cap(mds_rank_t mds)
  * This is the bog standard "check whether we have the required caps" operation.
  * Typically, we only check against the capset that is currently "issued".
  * In other words, we ignore caps that have been revoked but not yet released.
+ * Also account capability hit/miss stats.
  *
  * Some callers (particularly those doing attribute retrieval) can also make
  * use of the full set of "implemented" caps to satisfy requests from the
@@ -252,6 +253,7 @@ bool Inode::caps_issued_mask(unsigned mask, bool allow_impl)
       cap_is_valid(*auth_cap) &&
       (auth_cap->issued & mask) == mask) {
     auth_cap->touch();
+    client->cap_hit();
     return true;
   }
   // try any cap
@@ -260,6 +262,7 @@ bool Inode::caps_issued_mask(unsigned mask, bool allow_impl)
     if (cap_is_valid(cap)) {
       if ((cap.issued & mask) == mask) {
         cap.touch();
+       client->cap_hit();
        return true;
       }
       c |= cap.issued;
@@ -275,8 +278,11 @@ bool Inode::caps_issued_mask(unsigned mask, bool allow_impl)
     for (auto &pair : caps) {
       pair.second.touch();
     }
+    client->cap_hit();
     return true;
   }
+
+  client->cap_miss();
   return false;
 }