]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: only add inodes that clients want Frw or excl caps to open file table
authorYan, Zheng <zyan@redhat.com>
Thu, 9 Jul 2020 02:43:12 +0000 (10:43 +0800)
committerYan, Zheng <zyan@redhat.com>
Thu, 30 Jul 2020 12:10:29 +0000 (20:10 +0800)
Signed-off-by: "Yan, Zheng" <zyan@redhat.com>
src/mds/CInode.cc
src/mds/CInode.h
src/mds/Capability.cc
src/mds/Capability.h

index 69cd3bdab0198524077d2e5d331a7addd7c8a458..5fa858b6af7926deca3e9b2c1d3a42130b1126df 100644 (file)
@@ -3344,9 +3344,9 @@ void CInode::set_mds_caps_wanted(mempool::mds_co::compact_map<int32_t,int32_t>&
   mds_caps_wanted.swap(m);
   if (old_empty != (bool)mds_caps_wanted.empty()) {
     if (old_empty)
-      adjust_num_caps_wanted(1);
+      adjust_num_caps_notable(1);
     else
-      adjust_num_caps_wanted(-1);
+      adjust_num_caps_notable(-1);
   }
 }
 
@@ -3356,23 +3356,23 @@ void CInode::set_mds_caps_wanted(mds_rank_t mds, int32_t wanted)
   if (wanted) {
     mds_caps_wanted[mds] = wanted;
     if (old_empty)
-      adjust_num_caps_wanted(1);
+      adjust_num_caps_notable(1);
   } else if (!old_empty) {
     mds_caps_wanted.erase(mds);
     if (mds_caps_wanted.empty())
-      adjust_num_caps_wanted(-1);
+      adjust_num_caps_notable(-1);
   }
 }
 
-void CInode::adjust_num_caps_wanted(int d)
+void CInode::adjust_num_caps_notable(int d)
 {
-  if (!num_caps_wanted && d > 0)
+  if (!num_caps_notable && d > 0)
     mdcache->open_file_table.add_inode(this);
-  else if (num_caps_wanted > 0 && num_caps_wanted == -d)
+  else if (num_caps_notable > 0 && num_caps_notable == -d)
     mdcache->open_file_table.remove_inode(this);
 
-  num_caps_wanted +=d;
-  ceph_assert(num_caps_wanted >= 0);
+  num_caps_notable +=d;
+  ceph_assert(num_caps_notable >= 0);
 }
 
 Capability *CInode::add_client_cap(client_t client, Session *session,
@@ -3419,8 +3419,8 @@ void CInode::remove_client_cap(client_t client)
   if (client == loner_cap)
     loner_cap = -1;
 
-  if (cap->wanted())
-    adjust_num_caps_wanted(-1);
+  if (cap->is_wanted_notable())
+    adjust_num_caps_notable(-1);
 
   client_caps.erase(it);
   if (client_caps.empty()) {
index 6cbfaaad4e6064f6faa287a672e74b9c7b478d59..781bcf7f72606fe42c617f36b29a3220de75ff56 100644 (file)
@@ -400,7 +400,7 @@ class CInode : public MDSCacheObject, public InodeStoreBase, public Counter<CIno
     close_snaprealm();
     clear_file_locks();
     ceph_assert(num_projected_srnodes == 0);
-    ceph_assert(num_caps_wanted == 0);
+    ceph_assert(num_caps_notable == 0);
     ceph_assert(num_subtree_roots == 0);
     ceph_assert(num_exporting_dirs == 0);
     ceph_assert(batch_ops.empty());
@@ -904,8 +904,8 @@ class CInode : public MDSCacheObject, public InodeStoreBase, public Counter<CIno
     }
   }
 
-  int get_num_caps_wanted() const { return num_caps_wanted; }
-  void adjust_num_caps_wanted(int d);
+  int get_num_caps_notable() const { return num_caps_notable; }
+  void adjust_num_caps_notable(int d);
 
   Capability *add_client_cap(client_t client, Session *session,
                             SnapRealm *conrealm=nullptr, bool new_inode=false);
@@ -1207,7 +1207,7 @@ protected:
   mempool_cap_map client_caps; // client -> caps
   mempool::mds_co::compact_map<int32_t, int32_t> mds_caps_wanted;     // [auth] mds -> caps wanted
   int replica_caps_wanted = 0; // [replica] what i've requested from auth
-  int num_caps_wanted = 0;
+  int num_caps_notable = 0;
 
   ceph_lock_state_t *fcntl_locks = nullptr;
   ceph_lock_state_t *flock_locks = nullptr;
index 76ae3291d7cf35e91c5993345a4a94d303237bbc..8a6afe3cbddb83bd7c45569b5321c0299239675c 100644 (file)
@@ -212,15 +212,12 @@ void Capability::maybe_clear_notable()
 void Capability::set_wanted(int w) {
   CInode *in = get_inode();
   if (in) {
-    if (!_wanted && w) {
-      in->adjust_num_caps_wanted(1);
-    } else if (_wanted && !w) {
-      in->adjust_num_caps_wanted(-1);
-    }
     if (!is_wanted_notable(_wanted) && is_wanted_notable(w)) {
+      in->adjust_num_caps_notable(1);
       if (!is_notable())
        mark_notable();
     } else if (is_wanted_notable(_wanted) && !is_wanted_notable(w)) {
+      in->adjust_num_caps_notable(-1);
       maybe_clear_notable();
     }
   }
index 83a1ba5176af8953ea210f068fcd227fcfee397e..f7119f002e1381698343a029c2a8ede2b6b4cf7d 100644 (file)
@@ -253,6 +253,9 @@ public:
   static bool is_wanted_notable(int wanted) {
     return wanted & (CEPH_CAP_ANY_WR|CEPH_CAP_FILE_WR|CEPH_CAP_FILE_RD);
   }
+  bool is_wanted_notable() const {
+    return is_wanted_notable(wanted());
+  }
   bool is_notable() const { return state & STATE_NOTABLE; }
 
   bool is_stale() const;