]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephfs: DirStat versioning
authorJos Collin <jcollin@redhat.com>
Wed, 1 Aug 2018 04:18:48 +0000 (09:48 +0530)
committerJos Collin <jcollin@redhat.com>
Sun, 12 Aug 2018 01:08:41 +0000 (06:38 +0530)
* Use the new feature bit CEPHFS_FEATURE_REPLY_ENCODING for encoding.
* encode/decode in the new format.
* Dropped DirStat::encode().
* The old format is maintained for backward compatibility.
* Created CDir::encode_dirstat() 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/CDir.cc
src/mds/CDir.h
src/mds/Server.cc
src/mds/Server.h
src/messages/MClientReply.h

index 14880f8cc21303dea74424dc28c34d6c72fe7b34..6deeaf43759e1362cbe591870894fa6bfb97dfcb 100644 (file)
@@ -1093,7 +1093,7 @@ void Client::insert_readdir_results(MetaRequest *request, MetaSession *session,
     assert(dir);
 
     // dirstat
-    DirStat dst(p);
+    DirStat dst(p, features);
     __u32 numdn;
     __u16 flags;
     decode(numdn, p);
@@ -1299,7 +1299,7 @@ Inode* Client::insert_trace(MetaRequest *request, MetaSession *session)
 
   if (reply->head.is_dentry) {
     dirst.decode(p, features);
-    dst.decode(p);
+    dst.decode(p, features);
     decode(dname, p);
     decode(dlease, p);
   }
index d0b231e1fc9c5bfc516e0cf8c76a6f87ed21e275..b1ad9380619815a1cf628151952b6f83d2ccf32c 100644 (file)
@@ -2590,6 +2590,20 @@ void CDir::abort_import()
   pop_auth_subtree.zero();
 }
 
+void CDir::encode_dirstat(bufferlist& bl, const session_info_t& info, const DirStat& ds) {
+  if (info.has_feature(CEPHFS_FEATURE_REPLY_ENCODING)) {
+    ENCODE_START(1, 1, bl);
+    encode(ds.frag, bl);
+    encode(ds.auth, bl);
+    encode(ds.dist, bl);
+    ENCODE_FINISH(bl);
+  }
+  else {
+    encode(ds.frag, bl);
+    encode(ds.auth, bl);
+    encode(ds.dist, bl);
+  }
+}
 
 /********************************
  * AUTHORITY
@@ -2704,7 +2718,6 @@ void CDir::set_dir_auth(const mds_authority_t &a)
   }
 }
 
-
 /*****************************************
  * AUTH PINS and FREEZING
  *
index 0bbd3f1caff7405d422757275d7c8643dfbc1ddb..6234327d0501510bca06e532f2b1e61fcb43ef71 100644 (file)
@@ -33,6 +33,9 @@
 #include "CInode.h"
 #include "MDSCacheObject.h"
 #include "MDSContext.h"
+#include "cephfs_features.h"
+#include "SessionMap.h"
+#include "messages/MClientReply.h"
 
 class CDentry;
 class MDCache;
@@ -562,22 +565,8 @@ private:
        ls.insert(auth);
     }
   }
-  void encode_dirstat(bufferlist& bl, mds_rank_t whoami) {
-    /*
-     * note: encoding matches struct ceph_client_reply_dirfrag
-     */
-    frag_t frag = get_frag();
-    mds_rank_t auth;
-    std::set<mds_rank_t> dist;
-    
-    auth = dir_auth.first;
-    if (is_auth()) 
-      get_dist_spec(dist, whoami);
-
-    encode(frag, bl);
-    encode(auth, bl);
-    encode(dist, bl);
-  }
+
+  static void encode_dirstat(bufferlist& bl, const session_info_t& info, const DirStat& ds);
 
   void _encode_base(bufferlist& bl) {
     encode(first, bl);
index 722ce887011d4b256f73e80ace71d8af3beea94f..706a91c80a95da50b09866b54f784ba436dc0ff6 100644 (file)
@@ -1658,13 +1658,6 @@ void Server::reply_client_request(MDRequestRef& mdr, MClientReply *reply)
   }
 }
 
-
-void Server::encode_empty_dirstat(bufferlist& bl)
-{
-  static DirStat empty;
-  empty.encode(bl);
-}
-
 void Server::encode_infinite_lease(bufferlist& bl)
 {
   LeaseStat e;
@@ -1739,7 +1732,13 @@ void Server::set_trace_dist(Session *session, MClientReply *reply,
     if (dir->is_complete())
       dir->verify_fragstat();
 #endif
-    dir->encode_dirstat(bl, whoami);
+    DirStat ds;
+    ds.frag = dir->get_frag();
+    ds.auth = dir->get_dir_auth().first;
+    if (dir->is_auth())
+      dir->get_dist_spec(ds.dist, whoami);
+
+    dir->encode_dirstat(bl, session->info, ds);
     dout(20) << "set_trace_dist added dir  " << *dir << dendl;
 
     encode(dn->get_name(), bl);
@@ -3971,7 +3970,13 @@ void Server::handle_client_readdir(MDRequestRef& mdr)
 
   // start final blob
   bufferlist dirbl;
-  dir->encode_dirstat(dirbl, mds->get_nodeid());
+  DirStat ds;
+  ds.frag = dir->get_frag();
+  ds.auth = dir->get_dir_auth().first;
+  if (dir->is_auth())
+    dir->get_dist_spec(ds.dist, mds->get_nodeid());
+
+  dir->encode_dirstat(dirbl, mdr->session->info, ds);
 
   // count bytes available.
   //  this isn't perfect, but we should capture the main variable/unbounded size items!
@@ -9132,8 +9137,10 @@ void Server::handle_client_lssnap(MDRequestRef& mdr)
   if (!offset_str.empty())
     last_snapid = realm->resolve_snapname(offset_str, diri->ino());
 
+  //Empty DirStat
   bufferlist dirbl;
-  encode_empty_dirstat(dirbl);
+  static DirStat empty;
+  CDir::encode_dirstat(dirbl, mdr->session->info, empty);
 
   max_bytes -= dirbl.length() - sizeof(__u32) + sizeof(__u8) * 2;
 
index 0b78858721b64f2be8d0c41f3224b56e8b853c82..c1faba068aadd997e80df597a35024223ea41df9 100644 (file)
@@ -160,7 +160,6 @@ public:
                      int num_dentries_wanted,
                      MDRequestRef& mdr);
 
-  void encode_empty_dirstat(bufferlist& bl);
   void encode_infinite_lease(bufferlist& bl);
   void encode_null_lease(bufferlist& bl);
 
index 8706aec17203918d2a7f7b0cdaa34a5ee1b04702..6a93d9aa6b6bb7c1b7b3e4427624a02916add399 100644 (file)
@@ -79,21 +79,24 @@ struct DirStat {
   set<__s32> dist;
   
   DirStat() : auth(CDIR_AUTH_PARENT) {}
-  DirStat(bufferlist::const_iterator& p) {
-    decode(p);
+  DirStat(bufferlist::const_iterator& p, const uint64_t features) {
+    decode(p, features);
   }
 
-  void encode(bufferlist& bl) {
-    using ceph::encode;
-    encode(frag, bl);
-    encode(auth, bl);
-    encode(dist, bl);
-  }
-  void decode(bufferlist::const_iterator& p) {
+  void decode(bufferlist::const_iterator& p, const uint64_t features) {
     using ceph::decode;
-    decode(frag, p);
-    decode(auth, p);
-    decode(dist, p);
+    if (features == (uint64_t)-1) {
+      DECODE_START(1, p);
+      decode(frag, p);
+      decode(auth, p);
+      decode(dist, p);
+      DECODE_FINISH(p);
+    }
+    else {
+      decode(frag, p);
+      decode(auth, p);
+      decode(dist, p);
+    }
   }
 
   // see CDir::encode_dirstat for encoder.