]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: add static encode/decode helpers for remote in CDentry
authorXiubo Li <xiubli@redhat.com>
Fri, 20 Nov 2020 02:02:42 +0000 (10:02 +0800)
committerPatrick Donnelly <pdonnell@redhat.com>
Sat, 16 Jan 2021 01:30:39 +0000 (17:30 -0800)
This will unify all the same work in different places.

Fixes: https://tracker.ceph.com/issues/47162
Signed-off-by: Xiubo Li <xiubli@redhat.com>
src/mds/CDentry.cc
src/mds/CDentry.h
src/mds/CDir.cc
src/mds/Migrator.cc
src/tools/cephfs/DataScan.cc
src/tools/cephfs/MetaTool.cc

index 335ee402fec824bd8c2762e38bcf89c23bc788e9..b674f8ba0d42852b59bc85193ebd514c044038c2 100644 (file)
@@ -530,6 +530,31 @@ void CDentry::_put()
   }
 }
 
+void CDentry::encode_remote(inodeno_t& ino, unsigned char d_type, bufferlist &bl)
+{
+  bl.append("l", 1);  // remote link
+
+  // marker, name, ino
+  ENCODE_START(1, 1, bl);
+  encode(ino, bl);
+  encode(d_type, bl);
+  ENCODE_FINISH(bl);
+}
+
+void CDentry::decode_remote(char icode, inodeno_t& ino, unsigned char& d_type,
+                            ceph::buffer::list::const_iterator& bl)
+{
+  if (icode == 'l') {
+    DECODE_START(1, bl);
+    decode(ino, bl);
+    decode(d_type, bl);
+    DECODE_FINISH(bl);
+  } else if (icode == 'L') {
+    decode(ino, bl);
+    decode(d_type, bl);
+  } else ceph_assert(0);
+}
+
 void CDentry::dump(Formatter *f) const
 {
   ceph_assert(f != NULL);
index ed2a66f678e7646d934a863496fc47aab93a8448..a192527dd348fe20d937c0d3cb7aa13aca4662c8 100644 (file)
@@ -332,6 +332,9 @@ public:
   void print(std::ostream& out) override;
   void dump(ceph::Formatter *f) const;
 
+  static void encode_remote(inodeno_t& ino, unsigned char d_type, bufferlist &bl);
+  static void decode_remote(char icode, inodeno_t& ino, unsigned char& d_type,
+                            ceph::buffer::list::const_iterator& bl);
 
   __u32 hash;
   snapid_t first, last;
index 610796f76747f279f6d6184493aafc515e17f64d..47834b116282ea8b185f42fa53d362ce763bb085 100644 (file)
@@ -1767,15 +1767,7 @@ CDentry *CDir::_load_dentry(
     inodeno_t ino;
     unsigned char d_type;
 
-    if (type == 'l') {
-      DECODE_START(1, q);
-      decode(ino, q);
-      decode(d_type, q);
-      DECODE_FINISH(q);
-    } else {
-      decode(ino, q);
-      decode(d_type, q);
-    }
+    CDentry::decode_remote(type, ino, d_type, q);
 
     if (stale) {
       if (!dn) {
@@ -2325,12 +2317,7 @@ void CDir::_omap_commit_ops(int r, int op_prio, int64_t metapool, version_t vers
   for (auto &item : to_set) {
     encode(item.first, bl);
     if (item.is_remote) {
-      // marker, name, ino
-      bl.append('l');         // remote link
-      ENCODE_START(1, 1, bl);
-      encode(item.ino, bl);
-      encode(item.d_type, bl);
-      ENCODE_FINISH(bl);
+      CDentry::encode_remote(item.ino, item.d_type, bl); // remote link
     } else {
       // marker, name, inode, [symlink string]
       bl.append('i');         // inode
index f2c2d33fecc16d885a32e61a7482936a971c2ce9..36a8dc0712fee32d2b93e6f03d0d89d90f72941f 100644 (file)
@@ -1791,15 +1791,9 @@ void Migrator::encode_export_dir(bufferlist& exportbl,
     }
     
     if (dn->get_linkage()->is_remote()) {
-      // remote link
-      exportbl.append("l", 1);  // remote link
-      
       inodeno_t ino = dn->get_linkage()->get_remote_ino();
       unsigned char d_type = dn->get_linkage()->get_remote_d_type();
-      ENCODE_START(1, 1, exportbl);
-      encode(ino, exportbl);
-      encode(d_type, exportbl);
-      ENCODE_FINISH(exportbl);
+      CDentry::encode_remote(ino, d_type, exportbl); // remote link
       continue;
     }
 
@@ -3451,15 +3445,7 @@ void Migrator::decode_import_dir(bufferlist::const_iterator& blp,
       // remote link
       inodeno_t ino;
       unsigned char d_type;
-      if (icode == 'l') {
-        DECODE_START(1, blp);
-        decode(ino, blp);
-        decode(d_type, blp);
-        DECODE_FINISH(blp);
-      } else {
-        decode(ino, blp);
-        decode(d_type, blp);
-      }
+      CDentry::decode_remote(icode, ino, d_type, blp);
       if (dn->get_linkage()->is_remote()) {
        ceph_assert(dn->get_linkage()->get_remote_ino() == ino);
       } else {
index d19a6ece02af7e40b703e697adfd304f135a81fa..52ff67a4601950eb3fab87fabec9e97a7ef6ab16 100644 (file)
@@ -18,6 +18,7 @@
 #include <fstream>
 #include "include/util.h"
 
+#include "mds/CDentry.h"
 #include "mds/CInode.h"
 #include "mds/InoTable.h"
 #include "mds/SnapServer.h"
@@ -1058,15 +1059,7 @@ int DataScan::scan_links()
          } else if (dentry_type == 'L' || dentry_type == 'l') {
            inodeno_t ino;
            unsigned char d_type;
-            if (dentry_type == 'l') {
-             DECODE_START(1, q);
-             decode(ino, q);
-             decode(d_type, q);
-             DECODE_FINISH(q);
-           } else {
-             decode(ino, q);
-             decode(d_type, q);
-           }
+            CDentry::decode_remote(dentry_type, ino, d_type, q);
 
            if (step == SCAN_INOS) {
              remote_links[ino]++;
index 1d7d855da4bb8c8ff2ab36d5b5fe53ae943847ae..fc45dc85ae8cd3e0803864d224b5170c914cb8fd 100644 (file)
@@ -13,6 +13,7 @@
 #include "mds/mdstypes.h"
 #include "mds/LogEvent.h"
 #include "mds/InoTable.h"
+#include "mds/CDentry.h"
 
 #include "mds/events/ENoOp.h"
 #include "mds/events/EUpdate.h"
@@ -925,15 +926,8 @@ int MetaTool::show_child(std::string_view key,
     // hard link
     inodeno_t ino;
     unsigned char d_type;
-    if (type == 'l') {
-      DECODE_START(1, q);
-      ::decode(ino, q);
-      ::decode(d_type, q);
-      DECODE_FINISH(q);
-    } else {
-      ::decode(ino, q);
-      ::decode(d_type, q);
-    }
+
+    CDentry::decode_remote(type, ino, d_type, q);
 
     if (sp_ino > 0) {
       if (sp_ino == ino) {