From: Yan, Zheng Date: Thu, 9 Jul 2020 02:43:12 +0000 (+0800) Subject: mds: only add inodes that clients want Frw or excl caps to open file table X-Git-Tag: v15.2.9~122^2~32^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=62cca9464e5ee7eb6cf781cb0b4c29511dc2ea5e;p=ceph.git mds: only add inodes that clients want Frw or excl caps to open file table Signed-off-by: "Yan, Zheng" (cherry picked from commit e6de138f3334adc26cac4c01dfbbdf8a2472679a) --- diff --git a/src/mds/CInode.cc b/src/mds/CInode.cc index 551d2bf0b4538..7055e0e49d21b 100644 --- a/src/mds/CInode.cc +++ b/src/mds/CInode.cc @@ -3261,9 +3261,9 @@ void CInode::set_mds_caps_wanted(mempool::mds_co::compact_map& 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); } } @@ -3273,23 +3273,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, @@ -3336,8 +3336,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()) { diff --git a/src/mds/CInode.h b/src/mds/CInode.h index 22cdc6e7bef32..a416a9060a382 100644 --- a/src/mds/CInode.h +++ b/src/mds/CInode.h @@ -366,7 +366,7 @@ class CInode : public MDSCacheObject, public InodeStoreBase, public Counter caps mempool::mds_co::compact_map 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; diff --git a/src/mds/Capability.cc b/src/mds/Capability.cc index 32f780ee20267..4c2ccc75d1268 100644 --- a/src/mds/Capability.cc +++ b/src/mds/Capability.cc @@ -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(); } } diff --git a/src/mds/Capability.h b/src/mds/Capability.h index 218eeb40fce0d..b136b08c1f359 100644 --- a/src/mds/Capability.h +++ b/src/mds/Capability.h @@ -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;