]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephfs: LeaseStat versioning 23280/head
authorJos Collin <jcollin@redhat.com>
Wed, 1 Aug 2018 14:58:21 +0000 (20:28 +0530)
committerJos Collin <jcollin@redhat.com>
Sun, 12 Aug 2018 01:12:18 +0000 (06:42 +0530)
* Use the new feature bit CEPHFS_FEATURE_REPLY_ENCODING for encoding.
* encode/decode in the new format.
* Dropped LeaseStat::encode().
* The old format is maintained for backward compatibility.
* Created Locker::encode_lease() for encoding and dropped the duplicates.

Fixes: http://tracker.ceph.com/issues/24444
Signed-off-by: Jos Collin <jcollin@redhat.com>
src/client/Client.cc
src/mds/Locker.cc
src/mds/Locker.h
src/mds/Server.cc
src/mds/Server.h
src/messages/MClientReply.h

index 6deeaf43759e1362cbe591870894fa6bfb97dfcb..128b3b7e840feb4f8da95263362e28d3ab62dbca 100644 (file)
@@ -1151,7 +1151,7 @@ void Client::insert_readdir_results(MetaRequest *request, MetaSession *session,
     LeaseStat dlease;
     for (unsigned i=0; i<numdn; i++) {
       decode(dname, p);
-      decode(dlease, p);
+      dlease.decode(p, features);
       InodeStat ist(p, features);
 
       ldout(cct, 15) << "" << i << ": '" << dname << "'" << dendl;
@@ -1301,7 +1301,7 @@ Inode* Client::insert_trace(MetaRequest *request, MetaSession *session)
     dirst.decode(p, features);
     dst.decode(p, features);
     decode(dname, p);
-    decode(dlease, p);
+    dlease.decode(p, features);
   }
 
   Inode *in = 0;
index de9160ec517c93416617639dc18baff22f48a9ad..dee0587b2be5024b9aedea62113d5f06a64dbf74 100644 (file)
@@ -3774,20 +3774,17 @@ void Locker::issue_client_lease(CDentry *dn, client_t client,
     now += mdcache->client_lease_durations[pool];
     mdcache->touch_client_lease(l, pool, now);
 
-    LeaseStat e;
-    e.mask = 1 | CEPH_LOCK_DN;  // old and new bit values
-    e.seq = ++l->seq;
-    e.duration_ms = (int)(1000 * mdcache->client_lease_durations[pool]);
-    encode(e, bl);
-    dout(20) << "issue_client_lease seq " << e.seq << " dur " << e.duration_ms << "ms "
+    LeaseStat lstat;
+    lstat.mask = 1 | CEPH_LOCK_DN;  // old and new bit values
+    lstat.duration_ms = (uint32_t)(1000 * mdcache->client_lease_durations[pool]);
+    lstat.seq = ++l->seq;
+    encode_lease(bl, session->info, lstat);
+    dout(20) << "issue_client_lease seq " << lstat.seq << " dur " << lstat.duration_ms << "ms "
             << " on " << *dn << dendl;
   } else {
     // null lease
-    LeaseStat e;
-    e.mask = 0;
-    e.seq = 0;
-    e.duration_ms = 0;
-    encode(e, bl);
+    LeaseStat lstat;
+    encode_lease(bl, session->info, lstat);
     dout(20) << "issue_client_lease no/null lease on " << *dn << dendl;
   }
 }
@@ -3819,7 +3816,22 @@ void Locker::revoke_client_leases(SimpleLock *lock)
   }
 }
 
-
+void Locker::encode_lease(bufferlist& bl, const session_info_t& info,
+                         const LeaseStat& ls)
+{
+  if (info.has_feature(CEPHFS_FEATURE_REPLY_ENCODING)) {
+    ENCODE_START(1, 1, bl);
+    encode(ls.mask, bl);
+    encode(ls.duration_ms, bl);
+    encode(ls.seq, bl);
+    ENCODE_FINISH(bl);
+  }
+  else {
+    encode(ls.mask, bl);
+    encode(ls.duration_ms, bl);
+    encode(ls.seq, bl);
+  }
+}
 
 // locks ----------------------------------------------------------------
 
index 4e77ef9369d9af2a0836be42a6d65083248f744a..74cdb45ac267bea4c2e59a53e1bf1f595513227a 100644 (file)
@@ -45,6 +45,7 @@ class LocalLock;
 #include "SimpleLock.h"
 #include "MDSContext.h"
 #include "Mutation.h"
+#include "messages/MClientReply.h"
 
 class Locker {
 private:
@@ -287,6 +288,7 @@ public:
 
   void issue_client_lease(CDentry *dn, client_t client, bufferlist &bl, utime_t now, Session *session);
   void revoke_client_leases(SimpleLock *lock);
+  static void encode_lease(bufferlist& bl, const session_info_t& info, const LeaseStat& ls);
 };
 
 
index 706a91c80a95da50b09866b54f784ba436dc0ff6..2d743b23174e2d5ce4bd7a8e63c3f6b9dc99e174 100644 (file)
@@ -1658,27 +1658,6 @@ void Server::reply_client_request(MDRequestRef& mdr, MClientReply *reply)
   }
 }
 
-void Server::encode_infinite_lease(bufferlist& bl)
-{
-  LeaseStat e;
-  e.seq = 0;
-  e.mask = -1;
-  e.duration_ms = -1;
-  encode(e, bl);
-  dout(20) << "encode_infinite_lease " << e << dendl;
-}
-
-void Server::encode_null_lease(bufferlist& bl)
-{
-  LeaseStat e;
-  e.seq = 0;
-  e.mask = 0;
-  e.duration_ms = 0;
-  encode(e, bl);
-  dout(20) << "encode_null_lease " << e << dendl;
-}
-
-
 /*
  * pass inode OR dentry (not both, or we may get confused)
  *
@@ -1744,8 +1723,11 @@ void Server::set_trace_dist(Session *session, MClientReply *reply,
     encode(dn->get_name(), bl);
     if (snapid == CEPH_NOSNAP)
       mds->locker->issue_client_lease(dn, client, bl, now, session);
-    else
-      encode_null_lease(bl);
+    else {
+      //null lease
+      LeaseStat e;
+      mds->locker->encode_lease(bl, session->info, e);
+    }
     dout(20) << "set_trace_dist added dn   " << snapid << " " << *dn << dendl;
   } else
     reply->head.is_dentry = 0;
@@ -9162,7 +9144,10 @@ void Server::handle_client_lssnap(MDRequestRef& mdr)
       break;
 
     encode(snap_name, dnbl);
-    encode_infinite_lease(dnbl);
+    //infinite lease
+    LeaseStat e(-1, -1, 0);
+    mds->locker->encode_lease(dnbl, mdr->session->info, e);
+    dout(20) << "encode_infinite_lease" << dendl;
 
     int r = diri->encode_inodestat(dnbl, mdr->session, realm, p->first, max_bytes - (int)dnbl.length());
     if (r < 0) {
index c1faba068aadd997e80df597a35024223ea41df9..4719d4f374efe919d493026d192f833691acb535 100644 (file)
@@ -160,8 +160,6 @@ public:
                      int num_dentries_wanted,
                      MDRequestRef& mdr);
 
-  void encode_infinite_lease(bufferlist& bl);
-  void encode_null_lease(bufferlist& bl);
 
   void handle_slave_request(MMDSSlaveRequest *m);
   void handle_slave_request_reply(MMDSSlaveRequest *m);
index 6a93d9aa6b6bb7c1b7b3e4427624a02916add399..edd3d19c2bb360ad33429097d7080c10106f74db 100644 (file)
@@ -52,21 +52,24 @@ struct LeaseStat {
   __u32 seq;
 
   LeaseStat() : mask(0), duration_ms(0), seq(0) {}
+  LeaseStat(__u16 msk, __u32 dur, __u32 sq) : mask{msk}, duration_ms{dur}, seq{sq} {}
 
-  void encode(bufferlist &bl) const {
-    using ceph::encode;
-    encode(mask, bl);
-    encode(duration_ms, bl);
-    encode(seq, bl);
-  }
-  void decode(bufferlist::const_iterator &bl) {
+  void decode(bufferlist::const_iterator &bl, const uint64_t features) {
     using ceph::decode;
-    decode(mask, bl);
-    decode(duration_ms, bl);
-    decode(seq, bl);
+    if (features == (uint64_t)-1) {
+      DECODE_START(1, bl);
+      decode(mask, bl);
+      decode(duration_ms, bl);
+      decode(seq, bl);
+      DECODE_FINISH(bl);
+    }
+    else {
+      decode(mask, bl);
+      decode(duration_ms, bl);
+      decode(seq, bl);
+    }
   }
 };
-WRITE_CLASS_ENCODER(LeaseStat)
 
 inline ostream& operator<<(ostream& out, const LeaseStat& l) {
   return out << "lease(mask " << l.mask << " dur " << l.duration_ms << ")";