]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds/mdstypes: un-inline functions that use CachedStackStringStream
authorMax Kellermann <max.kellermann@ionos.com>
Fri, 4 Oct 2024 19:44:37 +0000 (21:44 +0200)
committerMax Kellermann <max.kellermann@ionos.com>
Thu, 17 Apr 2025 13:59:27 +0000 (15:59 +0200)
This avoids the heavy include in a commonly used header.

Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
src/mds/mdstypes.cc
src/mds/mdstypes.h

index 24a00679bb89641993b15e56d1edaf5426045246..5be3506bc3d5215ff9c51258960c6995b37c7e7a 100644 (file)
@@ -24,6 +24,19 @@ using std::vector;
 using ceph::bufferlist;
 using ceph::Formatter;
 
+void mds_role_t::print(std::ostream& out) const {
+  out << fscid << ":" << rank;
+}
+
+std::ostream& operator<<(std::ostream &out, const vinodeno_t &vino) {
+  out << vino.ino;
+  if (vino.snapid == CEPH_NOSNAP)
+    out << ".head";
+  else if (vino.snapid)
+    out << '.' << vino.snapid;
+  return out;
+}
+
 /*
  * frag_info_t
  */
@@ -438,6 +451,10 @@ void old_rstat_t::generate_test_instances(std::list<old_rstat_t*>& ls)
   ls.back()->accounted_rstat = *nls.front();
 }
 
+void old_rstat_t::print(std::ostream& out) const {
+  out << "old_rstat(first " << first << " " << rstat << " " << accounted_rstat << ")";
+}
+
 /*
  * feature_bitset_t
  */
@@ -717,10 +734,33 @@ void session_info_t::generate_test_instances(std::list<session_info_t*>& ls)
   // we can't add used inos; they're cleared on decode
 }
 
+/*
+ * dentry_key_t
+ */
+void dentry_key_t::print(std::ostream& out) const {
+  out << "(" << name << "," << snapid << ")";
+}
+
+void dentry_key_t::encode(std::string& key) const {
+  char b[20];
+  if (snapid != CEPH_NOSNAP) {
+    uint64_t val(snapid);
+    snprintf(b, sizeof(b), "%" PRIx64, val);
+  } else {
+    snprintf(b, sizeof(b), "%s", "head");
+  }
+  CachedStackStringStream css;
+  *css << name << "_" << b;
+  key = css->strv();
+}
 
 /*
  * string_snap_t
  */
+void string_snap_t::print(std::ostream& out) const {
+  out << "(" << name << "," << snapid << ")";
+}
+
 void string_snap_t::encode(bufferlist& bl) const
 {
   ENCODE_START(2, 2, bl);
@@ -786,6 +826,17 @@ void MDSCacheObjectInfo::dump(Formatter *f) const
   f->dump_unsigned("snapid", snapid);
 }
 
+void MDSCacheObjectInfo::print(std::ostream& out) const {
+  if (ino) {
+    out << ino << "." << snapid;
+  } else if (dname.length()) {
+    out << dirfrag << "/" << dname
+        << " snap " << snapid;
+  } else {
+    out << dirfrag;
+  }
+}
+
 void MDSCacheObjectInfo::generate_test_instances(std::list<MDSCacheObjectInfo*>& ls)
 {
   ls.push_back(new MDSCacheObjectInfo);
@@ -843,6 +894,36 @@ void metareqid_t::dump(ceph::Formatter* f) const {
   f->dump_unsigned("tid", tid);
 }
 
+void metareqid_t::print(std::ostream& out) const {
+  out << name << ":" << tid;
+}
+
+void metareqid_t::generate_test_instances(std::list<metareqid_t*>& ls) {
+  ls.push_back(new metareqid_t);
+  ls.push_back(new metareqid_t(entity_name_t::CLIENT(123), 456));
+}
+
+/*
+ * dirfrag_t
+ */
+void dirfrag_t::print(std::ostream& out) const {
+  out << ino;
+  if (!frag.is_root()) {
+    out << "." << frag;
+  }
+}
+
+void dirfrag_t::dump(ceph::Formatter *f) const {
+  f->dump_unsigned("ino", ino);
+  f->dump_unsigned("frag", frag);
+}
+
+void dirfrag_t::generate_test_instances(std::list<dirfrag_t*>& ls) {
+  ls.push_back(new dirfrag_t);
+  ls.push_back(new dirfrag_t(1, frag_t()));
+  ls.push_back(new dirfrag_t(2, frag_t(3)));
+}
+
 /*
  * inode_load_vec_t
  */
@@ -905,6 +986,19 @@ void dirfrag_load_vec_t::dump(Formatter *f, const DecayRate& rate) const
   f->dump_float("STORE", get(META_POP_STORE).get());
 }
 
+void dirfrag_load_vec_t::print(std::ostream& out) const {
+  CachedStackStringStream css;
+  *css << std::setprecision(1) << std::fixed
+       << "[pop"
+          " IRD:" << vec[0]
+       << " IWR:" << vec[1]
+       << " RDR:" << vec[2]
+       << " FET:" << vec[3]
+       << " STR:" << vec[4]
+       << " *LOAD:" << meta_load() << "]";
+  out << css->strv();
+}
+
 void dirfrag_load_vec_t::generate_test_instances(std::list<dirfrag_load_vec_t*>& ls)
 {
   ls.push_back(new dirfrag_load_vec_t(DecayRate()));
@@ -913,6 +1007,15 @@ void dirfrag_load_vec_t::generate_test_instances(std::list<dirfrag_load_vec_t*>&
 /*
  * mds_load_t
  */
+void mds_load_t::print(std::ostream& out) const {
+  out << "mdsload<" << auth << "/" << all
+      << ", req " << req_rate
+      << ", hr " << cache_hit_rate
+      << ", qlen " << queue_len
+       << ", cpu " << cpu_load_avg
+      << ">";
+}
+
 void mds_load_t::encode(bufferlist &bl) const {
   ENCODE_START(2, 2, bl);
   encode(auth, bl);
index 6174bbc1379b36cacba5b3736c303261bfa7a6eb..195fe56c24f92e522665e862815a7e57a201bcef 100644 (file)
@@ -5,14 +5,13 @@
 
 #include "include/int_types.h"
 
-#include <ostream>
+#include <iosfwd>
 #include <set>
 #include <map>
 #include <string>
 #include <string_view>
 
 #include "common/DecayCounter.h"
-#include "common/StackStringStream.h"
 #include "common/entity_name.h"
 
 #include "include/frag.h"
@@ -76,9 +75,7 @@ public:
     return (rank == MDS_RANK_NONE);
   }
 
-  void print(std::ostream& out) const {
-    out << fscid << ":" << rank;
-  }
+  void print(std::ostream& out) const;
 
   fs_cluster_id_t fscid = FS_CLUSTER_ID_NONE;
   mds_rank_t rank = MDS_RANK_NONE;
@@ -130,14 +127,7 @@ namespace std {
   };
 }
 
-inline std::ostream& operator<<(std::ostream &out, const vinodeno_t &vino) {
-  out << vino.ino;
-  if (vino.snapid == CEPH_NOSNAP)
-    out << ".head";
-  else if (vino.snapid)
-    out << '.' << vino.snapid;
-  return out;
-}
+std::ostream& operator<<(std::ostream &out, const vinodeno_t &vino);
 
 typedef uint32_t damage_flags_t;
 
@@ -269,9 +259,7 @@ struct old_rstat_t {
   void dump(ceph::Formatter *f) const;
   static void generate_test_instances(std::list<old_rstat_t*>& ls);
 
-  void print(std::ostream& out) const {
-    out << "old_rstat(first " << first << " " << rstat << " " << accounted_rstat << ")";
-  }
+  void print(std::ostream& out) const;
 
   snapid_t first;
   nest_info_t rstat, accounted_rstat;
@@ -468,9 +456,7 @@ struct dentry_key_t {
   dentry_key_t(snapid_t s, std::string_view n, __u32 h=0) :
     snapid(s), name(n), hash(h) {}
 
-  void print(std::ostream& out) const {
-    out << "(" << name << "," << snapid << ")";
-  }
+  void print(std::ostream& out) const;
 
   bool is_valid() { return name.length() || snapid; }
 
@@ -482,18 +468,7 @@ struct dentry_key_t {
     using ceph::encode;
     encode(key, bl);
   }
-  void encode(std::string& key) const {
-    char b[20];
-    if (snapid != CEPH_NOSNAP) {
-      uint64_t val(snapid);
-      snprintf(b, sizeof(b), "%" PRIx64, val);
-    } else {
-      snprintf(b, sizeof(b), "%s", "head");
-    }
-    CachedStackStringStream css;
-    *css << name << "_" << b;
-    key = css->strv();
-  }
+  void encode(std::string& key) const;
   static void decode_helper(ceph::buffer::list::const_iterator& bl, std::string& nm,
                            snapid_t& sn) {
     std::string key;
@@ -543,9 +518,7 @@ struct string_snap_t {
   string_snap_t() {}
   string_snap_t(std::string_view n, snapid_t s) : name(n), snapid(s) {}
 
-  void print(std::ostream& out) const {
-    out << "(" << name << "," << snapid << ")";
-  }
+  void print(std::ostream& out) const;
 
   int compare(const string_snap_t& r) const {
     int ret = name.compare(r.name);
@@ -624,13 +597,8 @@ struct metareqid_t {
     decode(tid, p);
   }
   void dump(ceph::Formatter *f) const;
-  void print(std::ostream& out) const {
-    out << name << ":" << tid;
-  }
-  static void generate_test_instances(std::list<metareqid_t*>& ls) {
-    ls.push_back(new metareqid_t);
-    ls.push_back(new metareqid_t(entity_name_t::CLIENT(123), 456));
-  }
+  void print(std::ostream& out) const;
+  static void generate_test_instances(std::list<metareqid_t*>& ls);
   entity_name_t name;
   uint64_t tid = 0;
 };
@@ -765,12 +733,7 @@ struct dirfrag_t {
   dirfrag_t() {}
   dirfrag_t(inodeno_t i, frag_t f) : ino(i), frag(f) { }
 
-  void print(std::ostream& out) const {
-    out << ino;
-    if (!frag.is_root()) {
-      out << "." << frag;
-    }
-  }
+  void print(std::ostream& out) const;
 
   void encode(ceph::buffer::list& bl) const {
     using ceph::encode;
@@ -782,15 +745,8 @@ struct dirfrag_t {
     decode(ino, bl);
     decode(frag, bl);
   }
-  void dump(ceph::Formatter *f) const {
-    f->dump_unsigned("ino", ino);
-    f->dump_unsigned("frag", frag);
-  }
-  static void generate_test_instances(std::list<dirfrag_t*>& ls) {
-    ls.push_back(new dirfrag_t);
-    ls.push_back(new dirfrag_t(1, frag_t()));
-    ls.push_back(new dirfrag_t(2, frag_t(3)));
-  }
+  void dump(ceph::Formatter *f) const;
+  static void generate_test_instances(std::list<dirfrag_t*>& ls);
 
   inodeno_t ino = 0;
   frag_t frag;
@@ -890,18 +846,7 @@ public:
   }
   void dump(ceph::Formatter *f) const;
   void dump(ceph::Formatter *f, const DecayRate& rate) const;
-  void print(std::ostream& out) const {
-    CachedStackStringStream css;
-    *css << std::setprecision(1) << std::fixed
-         << "[pop"
-            " IRD:" << vec[0]
-         << " IWR:" << vec[1]
-         << " RDR:" << vec[2]
-         << " FET:" << vec[3]
-         << " STR:" << vec[4]
-         << " *LOAD:" << meta_load() << "]";
-    out << css->strv();
-  }
+  void print(std::ostream& out) const;
   static void generate_test_instances(std::list<dirfrag_load_vec_t*>& ls);
 
   const DecayCounter &get(int t) const {
@@ -963,14 +908,7 @@ struct mds_load_t {
   mds_load_t() : auth(DecayRate()), all(DecayRate()) {}
   mds_load_t(const DecayRate &rate) : auth(rate), all(rate) {}
 
-  void print(std::ostream& out) const {
-    out << "mdsload<" << auth << "/" << all
-        << ", req " << req_rate
-        << ", hr " << cache_hit_rate
-        << ", qlen " << queue_len
-       << ", cpu " << cpu_load_avg
-        << ">";
-  }
+  void print(std::ostream& out) const;
 
   double req_rate = 0.0;
   double cache_hit_rate = 0.0;
@@ -1008,16 +946,7 @@ public:
   void encode(ceph::buffer::list& bl) const;
   void decode(ceph::buffer::list::const_iterator& bl);
   void dump(ceph::Formatter *f) const;
-  void print(std::ostream& out) const {
-    if (ino) {
-      out << ino << "." << snapid;
-    } else if (dname.length()) {
-      out << dirfrag << "/" << dname
-          << " snap " << snapid;
-    } else {
-      out << dirfrag;
-    }
-  }
+  void print(std::ostream& out) const;
   static void generate_test_instances(std::list<MDSCacheObjectInfo*>& ls);
 
   inodeno_t ino = 0;