]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: cleanup set/drop loner code
authorYan, Zheng <zyan@redhat.com>
Tue, 7 Nov 2017 02:37:44 +0000 (10:37 +0800)
committerPatrick Donnelly <pdonnell@redhat.com>
Tue, 6 Feb 2018 17:44:35 +0000 (09:44 -0800)
integrate functionalities of try_drop_loner and try_set_loner into
CInode::choose_ideal_loner

Signed-off-by: "Yan, Zheng" <zyan@redhat.com>
(cherry picked from commit d4cbf3aeeada57a88b794d3d6d5fb1cd891e31cd)

src/mds/CInode.cc
src/mds/CInode.h
src/mds/Locker.cc

index b0a2bcf5f1de96da8ae915bb61324efbf2a14cd1..fc640f841c04ad39a6e61ca62cc859221dfbc3c1 100644 (file)
@@ -2734,10 +2734,24 @@ client_t CInode::calc_ideal_loner()
   return loner;
 }
 
-client_t CInode::choose_ideal_loner()
+bool CInode::choose_ideal_loner()
 {
   want_loner_cap = calc_ideal_loner();
-  return want_loner_cap;
+  int changed = false;
+  if (loner_cap >= 0 && loner_cap != want_loner_cap) {
+    if (!try_drop_loner())
+      return false;
+    changed = true;
+  }
+
+  if (want_loner_cap >= 0) {
+    if (loner_cap < 0) {
+      set_loner_cap(want_loner_cap);
+      changed = true;
+    } else
+      assert(loner_cap == want_loner_cap);
+  }
+  return changed;
 }
 
 bool CInode::try_set_loner()
@@ -2805,9 +2819,8 @@ void CInode::choose_lock_state(SimpleLock *lock, int allissued)
 void CInode::choose_lock_states(int dirty_caps)
 {
   int issued = get_caps_issued() | dirty_caps;
-  if (is_auth() && (issued & (CEPH_CAP_ANY_EXCL|CEPH_CAP_ANY_WR)) &&
-      choose_ideal_loner() >= 0)
-    try_set_loner();
+  if (is_auth() && (issued & (CEPH_CAP_ANY_EXCL|CEPH_CAP_ANY_WR)))
+    choose_ideal_loner();
   choose_lock_state(&filelock, issued);
   choose_lock_state(&nestlock, issued);
   choose_lock_state(&dirfragtreelock, issued);
@@ -3297,12 +3310,8 @@ int CInode::encode_inodestat(bufferlist& bl, Session *session,
     if (!no_caps && !cap) {
       // add a new cap
       cap = add_client_cap(client, session, realm);
-      if (is_auth()) {
-       if (choose_ideal_loner() >= 0)
-         try_set_loner();
-       else if (get_wanted_loner() < 0)
-         try_drop_loner();
-      }
+      if (is_auth())
+       choose_ideal_loner();
     }
 
     int issue = 0;
index 99f12de927f3f04e1449d1033f78fd835b004c21..675a6bc090a5ce3d6d84b9f79fac446efaa82c69 100644 (file)
@@ -918,9 +918,9 @@ public:
   }
 
   client_t calc_ideal_loner();
-  client_t choose_ideal_loner();
-  bool try_set_loner();
   void set_loner_cap(client_t l);
+  bool choose_ideal_loner();
+  bool try_set_loner();
   bool try_drop_loner();
 
   // choose new lock state during recovery, based on issued caps
index 9f72471ef4539578c8e5b52d8e0c477eef43b76b..dda87315df1d8ad3aeaf1dfe53e2a49e9a5cbe70 100644 (file)
@@ -1038,15 +1038,15 @@ bool Locker::eval(CInode *in, int mask, bool caps_imported)
 
   // choose loner?
   if (in->is_auth() && in->is_head()) {
-    if (in->choose_ideal_loner() >= 0) {
-      if (in->try_set_loner()) {
-       dout(10) << "eval set loner to client." << in->get_loner() << dendl;
-       need_issue = true;
-       mask = -1;
-      } else
-       dout(10) << "eval want loner client." << in->get_wanted_loner() << " but failed to set it" << dendl;
-    } else
-      dout(10) << "eval doesn't want loner" << dendl;
+    client_t orig_loner = in->get_loner();
+    if (in->choose_ideal_loner()) {
+      dout(10) << "eval set loner: client." << orig_loner << " -> client." << in->get_loner() << dendl;
+      need_issue = true;
+      mask = -1;
+    } else if (in->get_wanted_loner() != in->get_loner()) {
+      dout(10) << "eval want loner: client." << in->get_wanted_loner() << " but failed to set it" << dendl;
+      mask = -1;
+    }
   }
 
  retry:
@@ -1067,19 +1067,14 @@ bool Locker::eval(CInode *in, int mask, bool caps_imported)
 
   // drop loner?
   if (in->is_auth() && in->is_head() && in->get_wanted_loner() != in->get_loner()) {
-    dout(10) << "  trying to drop loner" << dendl;
     if (in->try_drop_loner()) {
-      dout(10) << "  dropped loner" << dendl;
       need_issue = true;
-
       if (in->get_wanted_loner() >= 0) {
-       if (in->try_set_loner()) {
-         dout(10) << "eval end set loner to client." << in->get_loner() << dendl;
-         mask = -1;
-         goto retry;
-       } else {
-         dout(10) << "eval want loner client." << in->get_wanted_loner() << " but failed to set it" << dendl;
-       }
+       dout(10) << "eval end set loner to client." << in->get_loner() << dendl;
+       bool ok = in->try_set_loner();
+       assert(ok);
+       mask = -1;
+       goto retry;
       }
     }
   }