summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/mds/CDentry.cc25
-rw-r--r--src/mds/CDentry.h3
-rw-r--r--src/mds/CDir.cc17
-rw-r--r--src/mds/Migrator.cc18
-rw-r--r--src/tools/cephfs/DataScan.cc11
-rw-r--r--src/tools/cephfs/MetaTool.cc12
6 files changed, 37 insertions, 49 deletions
diff --git a/src/mds/CDentry.cc b/src/mds/CDentry.cc
index 335ee402fec..b674f8ba0d4 100644
--- a/src/mds/CDentry.cc
+++ b/src/mds/CDentry.cc
@@ -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);
diff --git a/src/mds/CDentry.h b/src/mds/CDentry.h
index ed2a66f678e..a192527dd34 100644
--- a/src/mds/CDentry.h
+++ b/src/mds/CDentry.h
@@ -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;
diff --git a/src/mds/CDir.cc b/src/mds/CDir.cc
index 610796f7674..47834b11628 100644
--- a/src/mds/CDir.cc
+++ b/src/mds/CDir.cc
@@ -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
diff --git a/src/mds/Migrator.cc b/src/mds/Migrator.cc
index f2c2d33fecc..36a8dc0712f 100644
--- a/src/mds/Migrator.cc
+++ b/src/mds/Migrator.cc
@@ -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 {
diff --git a/src/tools/cephfs/DataScan.cc b/src/tools/cephfs/DataScan.cc
index d19a6ece02a..52ff67a4601 100644
--- a/src/tools/cephfs/DataScan.cc
+++ b/src/tools/cephfs/DataScan.cc
@@ -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]++;
diff --git a/src/tools/cephfs/MetaTool.cc b/src/tools/cephfs/MetaTool.cc
index 1d7d855da4b..fc45dc85ae8 100644
--- a/src/tools/cephfs/MetaTool.cc
+++ b/src/tools/cephfs/MetaTool.cc
@@ -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) {