]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: add session pointer to Capability
authorYan, Zheng <zyan@redhat.com>
Mon, 26 Nov 2018 01:44:56 +0000 (09:44 +0800)
committerYan, Zheng <zyan@redhat.com>
Mon, 21 Oct 2019 02:52:21 +0000 (10:52 +0800)
Signed-off-by: "Yan, Zheng" <zyan@redhat.com>
(cherry picked from commit 7c628472a86c6acebb20f0a2504744b10f250587)

 Conflicts:
src/mds/CInode.cc
src/mds/Capability.h
src/mds/Locker.cc

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

index be865c5b55c7634c623e750eb2f23a0c8ff3dcb1..b648b6d5001b53c1af364d429b5c5f755346e293 100644 (file)
@@ -3006,15 +3006,12 @@ Capability *CInode::add_client_cap(client_t client, Session *session, SnapRealm
     if (parent)
       parent->dir->adjust_num_inodes_with_caps(1);
   }
-  
-  Capability *cap = new Capability(this, ++mdcache->last_cap_id, client);
+
+  Capability *cap = new Capability(this, session, ++mdcache->last_cap_id);
   assert(client_caps.count(client) == 0);
   client_caps[client] = cap;
 
   session->add_cap(cap);
-  if (session->is_stale())
-    cap->mark_stale();
-  
   cap->client_follows = first-1;
   
   containing_realm->add_cap(client, cap);
index 3cd408937b37383e1f48b3387991bbbe49dab1f1..1624de325f89655bf95241d2990801fdaec33ca6 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "Capability.h"
 #include "CInode.h"
+#include "SessionMap.h"
 
 #include "common/Formatter.h"
 
@@ -141,6 +142,28 @@ void Capability::revoke_info::generate_test_instances(list<Capability::revoke_in
 /*
  * Capability
  */
+Capability::Capability(CInode *i, Session *s, uint64_t id) :
+  client_follows(0),
+  client_xattr_version(0), client_inline_version(0),
+  last_rbytes(0), last_rsize(0),
+  item_session_caps(this), item_snaprealm_caps(this),
+  item_revoking_caps(this), item_client_revoking_caps(this),
+  inode(i), session(s),
+  cap_id(id), _wanted(0), num_revoke_warnings(0),
+  _pending(0), _issued(0), last_sent(0), last_issue(0), mseq(0),
+  suppress(0), state(0)
+{
+}
+
+client_t Capability::get_client() const
+{
+  return session ? session->get_client() : client_t(-1);
+}
+
+bool Capability::is_stale() const
+{
+  return session ? session->is_stale() : false;
+}
 
 void Capability::set_wanted(int w) {
   CInode *in = get_inode();
index 4f5d7a9848f428b857caf10e2e62220b44bec299..3cec6b7288c61d688afaa9e9623e46b1e3e05a6f 100644 (file)
@@ -61,6 +61,7 @@
  */
 
 class CInode;
+class Session;
 
 namespace ceph {
   class Formatter;
@@ -110,27 +111,12 @@ public:
   };
 
 
-  const static unsigned STATE_STALE            = (1<<0);
   const static unsigned STATE_NEW              = (1<<1);
   const static unsigned STATE_IMPORTING                = (1<<2);
   const static unsigned STATE_NEEDSNAPFLUSH    = (1<<3);
 
 
-  Capability(CInode *i = NULL, uint64_t id = 0, client_t c = 0) :
-    client_follows(0), client_xattr_version(0),
-    client_inline_version(0),
-    last_rbytes(0), last_rsize(0),
-    item_session_caps(this), item_snaprealm_caps(this),
-    item_revoking_caps(this), item_client_revoking_caps(this),
-    inode(i), client(c),
-    cap_id(id),
-    _wanted(0), num_revoke_warnings(0),
-    _pending(0), _issued(0),
-    last_sent(0),
-    last_issue(0),
-    mseq(0),
-    suppress(0), state(0) {
-  }
+  Capability(CInode *i=nullptr, Session *s=nullptr, uint64_t id=0);
   Capability(const Capability& other) = delete;
 
   const Capability& operator=(const Capability& other) = delete;
@@ -158,14 +144,14 @@ public:
       assert(_pending == c);
     }
     //last_issue = 
-    ++last_sent;
+    inc_last_seq();
     return last_sent;
   }
   ceph_seq_t issue_norevoke(unsigned c) {
     _pending |= c;
     _issued |= c;
     //check_rdcaps_list();
-    ++last_sent;
+    inc_last_seq();
     return last_sent;
   }
   void _calc_issued() {
@@ -239,10 +225,8 @@ public:
   void inc_suppress() { suppress++; }
   void dec_suppress() { suppress--; }
 
-  bool is_stale() { return state & STATE_STALE; }
-  void mark_stale() { state |= STATE_STALE; }
-  void clear_stale() { state &= ~STATE_STALE; }
-  bool is_new() { return state & STATE_NEW; }
+  bool is_stale() const;
+  bool is_new() const { return state & STATE_NEW; }
   void mark_new() { state |= STATE_NEW; }
   void clear_new() { state &= ~STATE_NEW; }
   bool is_importing() { return state & STATE_IMPORTING; }
@@ -252,11 +236,12 @@ public:
   void mark_needsnapflush() { state |= STATE_NEEDSNAPFLUSH; }
   void clear_needsnapflush() { state &= ~STATE_NEEDSNAPFLUSH; }
 
-  CInode *get_inode() { return inode; }
-  client_t get_client() const { return client; }
+  CInode *get_inode() const { return inode; }
+  Session *get_session() const { return session; }
+  client_t get_client() const;
 
   // caps this client wants to hold
-  int wanted() { return _wanted; }
+  int wanted() const { return _wanted; }
   void set_wanted(int w);
 
   void inc_last_seq() { last_sent++; }
@@ -333,7 +318,7 @@ public:
 
 private:
   CInode *inode;
-  client_t client;
+  Session *session;
 
   uint64_t cap_id;
 
index 36c60e66ec557edc1dbf91acd447214f74a66ba0..b150b2b49302fc535a3254265d5003dd75f861dd 100644 (file)
@@ -2199,7 +2199,6 @@ void Locker::revoke_stale_caps(Session *session)
 
   for (xlist<Capability*>::iterator p = session->caps.begin(); !p.end(); ++p) {
     Capability *cap = *p;
-    cap->mark_stale();
     revoke_stale_caps(cap);
   }
 }
@@ -2211,21 +2210,18 @@ void Locker::resume_stale_caps(Session *session)
   for (xlist<Capability*>::iterator p = session->caps.begin(); !p.end(); ++p) {
     Capability *cap = *p;
     CInode *in = cap->get_inode();
-    assert(in->is_head());
-    if (cap->is_stale()) {
-      dout(10) << " clearing stale flag on " << *in << dendl;
-      cap->clear_stale();
-
-      if (in->state_test(CInode::STATE_EXPORTINGCAPS)) {
-       // if export succeeds, the cap will be removed. if export fails,
-       // we need to re-issue the cap if it's not stale.
-       in->state_set(CInode::STATE_EVALSTALECAPS);
-       continue;
-      }
+    ceph_assert(in->is_head());
+    dout(10) << " clearing stale flag on " << *in << dendl;
 
-      if (!in->is_auth() || !eval(in, CEPH_CAP_LOCKS))
-       issue_caps(in, cap);
+    if (in->state_test(CInode::STATE_EXPORTINGCAPS)) {
+      // if export succeeds, the cap will be removed. if export fails,
+      // we need to re-issue the cap if it's not stale.
+      in->state_set(CInode::STATE_EVALSTALECAPS);
+      continue;
     }
+
+    if (!in->is_auth() || !eval(in, CEPH_CAP_LOCKS))
+      issue_caps(in, cap);
   }
 }