]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
include/CompatSet: un-inline to reduce header dependencies
authorMax Kellermann <max.kellermann@ionos.com>
Wed, 16 Oct 2024 16:15:16 +0000 (18:15 +0200)
committerMax Kellermann <max.kellermann@ionos.com>
Tue, 5 Aug 2025 08:28:01 +0000 (10:28 +0200)
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
src/common/CMakeLists.txt
src/common/CompatSet.cc [new file with mode: 0644]
src/crimson/CMakeLists.txt
src/include/CompatSet.h

index 4cc50736fc0a51d21160e7a22fe8ce2d821c19ab..97fb1fe7440143dfa832f15f6b6722e040868336 100644 (file)
@@ -19,6 +19,7 @@ add_subdirectory(options)
 set(common_srcs
   AsyncOpTracker.cc
   BackTrace.cc
+  CompatSet.cc
   ConfUtils.cc
   Cycles.cc
   CDC.cc
diff --git a/src/common/CompatSet.cc b/src/common/CompatSet.cc
new file mode 100644 (file)
index 0000000..54f45be
--- /dev/null
@@ -0,0 +1,108 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2009 Sage Weil <sage@newdream.net>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software 
+ * Foundation.  See file COPYING.
+ * 
+ */
+
+#include "include/CompatSet.h"
+
+#include <iostream>
+
+#include "common/Formatter.h"
+#include "include/types.h"
+
+void CompatSet::FeatureSet::encode(ceph::buffer::list& bl) const {
+  using ceph::encode;
+  /* See below, mask always has the lowest bit set in memory, but
+   * unset in the encoding */
+  encode(mask & (~(uint64_t)1), bl);
+  encode(names, bl);
+}
+
+void CompatSet::FeatureSet::decode(ceph::buffer::list::const_iterator& bl) {
+  using ceph::decode;
+  decode(mask, bl);
+  decode(names, bl);
+  /**
+   * Previously, there was a bug where insert did
+   * mask |= f.id rather than mask |= (1 << f.id).
+   * In FeatureSets from those version, mask always
+   * has the lowest bit set.  Since then, masks always
+   * have the lowest bit unset.
+   *
+   * When we encounter such a FeatureSet, we have to
+   * reconstruct the mask from the names map.
+   */
+  if (mask & 1) {
+    mask = 1;
+    std::map<uint64_t, std::string> temp_names;
+    temp_names.swap(names);
+    for (auto i = temp_names.begin(); i != temp_names.end(); ++i) {
+      insert(Feature(i->first, i->second));
+    }
+  } else {
+    mask |= 1;
+  }
+}
+
+void CompatSet::FeatureSet::dump(ceph::Formatter *f) const {
+  for (auto p = names.cbegin(); p != names.cend(); ++p) {
+    char s[18];
+    snprintf(s, sizeof(s), "feature_%llu", (unsigned long long)p->first);
+    f->dump_string(s, p->second);
+  }
+}
+
+std::ostream& CompatSet::printlite(std::ostream& o) const {
+  o << "{c=[" << std::hex << compat.mask << "]";
+  o << ",r=[" << std::hex << ro_compat.mask << "]";
+  o << ",i=[" << std::hex << incompat.mask << "]}";
+  o << std::dec;
+  return o;
+}
+
+void CompatSet::dump(ceph::Formatter *f) const {
+  f->open_object_section("compat");
+  compat.dump(f);
+  f->close_section();
+  f->open_object_section("ro_compat");
+  ro_compat.dump(f);
+  f->close_section();
+  f->open_object_section("incompat");
+  incompat.dump(f);
+  f->close_section();
+}
+
+void CompatSet::generate_test_instances(std::list<CompatSet*>& o) {
+  o.push_back(new CompatSet);
+  o.push_back(new CompatSet);
+  o.back()->compat.insert(Feature(1, "one"));
+  o.back()->compat.insert(Feature(2, "two"));
+  o.back()->ro_compat.insert(Feature(4, "four"));
+  o.back()->incompat.insert(Feature(3, "three"));
+}
+
+std::ostream& operator<<(std::ostream& out, const CompatSet::Feature& f)
+{
+  return out << "F(" << f.id << ", \"" << f.name << "\")";
+}
+
+std::ostream& operator<<(std::ostream& out, const CompatSet::FeatureSet& fs)
+{
+  return out << fs.names;
+}
+
+std::ostream& operator<<(std::ostream& out, const CompatSet& compat)
+{
+  return out << "compat=" << compat.compat
+            << ",rocompat=" << compat.ro_compat
+            << ",incompat=" << compat.incompat;
+}
index 95d7d34d14376ff882e4128cebffaefca55e7b9d..ce9b44cb0d935ff90a606d1abfb0dd4ba592c9e6 100644 (file)
@@ -73,6 +73,7 @@ add_library(crimson-common STATIC
   ${PROJECT_SOURCE_DIR}/src/common/utf8.c
   ${PROJECT_SOURCE_DIR}/src/common/version.cc
   ${PROJECT_SOURCE_DIR}/src/common/BackTrace.cc
+  ${PROJECT_SOURCE_DIR}/src/common/CompatSet.cc
   ${PROJECT_SOURCE_DIR}/src/common/ConfUtils.cc
   ${PROJECT_SOURCE_DIR}/src/common/DecayCounter.cc
   ${PROJECT_SOURCE_DIR}/src/common/HTMLFormatter.cc
index 35c7a77381dc2c15c98975eac7fc5b2cb2bcb1b7..9441b11d4c06211ebb45ff9a74125a4546bc51ca 100644 (file)
 #ifndef CEPH_COMPATSET_H
 #define CEPH_COMPATSET_H
 
-#include <iostream>
+#include <iosfwd>
 #include <map>
 #include <string>
 
 #include "include/buffer.h"
 #include "include/encoding.h"
-#include "include/types.h"
-#include "common/Formatter.h"
+
+namespace ceph { class Formatter; }
 
 struct CompatSet {
 
@@ -77,47 +77,10 @@ struct CompatSet {
       remove(f.id);
     }
 
-    void encode(ceph::buffer::list& bl) const {
-      using ceph::encode;
-      /* See below, mask always has the lowest bit set in memory, but
-       * unset in the encoding */
-      encode(mask & (~(uint64_t)1), bl);
-      encode(names, bl);
-    }
-
-    void decode(ceph::buffer::list::const_iterator& bl) {
-      using ceph::decode;
-      decode(mask, bl);
-      decode(names, bl);
-      /**
-       * Previously, there was a bug where insert did
-       * mask |= f.id rather than mask |= (1 << f.id).
-       * In FeatureSets from those version, mask always
-       * has the lowest bit set.  Since then, masks always
-       * have the lowest bit unset.
-       *
-       * When we encounter such a FeatureSet, we have to
-       * reconstruct the mask from the names map.
-       */
-      if (mask & 1) {
-       mask = 1;
-       std::map<uint64_t, std::string> temp_names;
-       temp_names.swap(names);
-       for (auto i = temp_names.begin(); i != temp_names.end(); ++i) {
-         insert(Feature(i->first, i->second));
-       }
-      } else {
-       mask |= 1;
-      }
-    }
+    void encode(ceph::buffer::list& bl) const;
+    void decode(ceph::buffer::list::const_iterator& bl);
 
-    void dump(ceph::Formatter *f) const {
-      for (auto p = names.cbegin(); p != names.cend(); ++p) {
-       char s[18];
-       snprintf(s, sizeof(s), "feature_%llu", (unsigned long long)p->first);
-       f->dump_string(s, p->second);
-      }
-    }
+    void dump(ceph::Formatter *f) const;
   };
 
   // These features have no impact on the read / write status
@@ -222,13 +185,7 @@ struct CompatSet {
     return true;
   }
 
-  std::ostream& printlite(std::ostream& o) const {
-    o << "{c=[" << std::hex << compat.mask << "]";
-    o << ",r=[" << std::hex << ro_compat.mask << "]";
-    o << ",i=[" << std::hex << incompat.mask << "]}";
-    o << std::dec;
-    return o;
-  }
+  std::ostream& printlite(std::ostream& o) const;
 
   void encode(ceph::buffer::list& bl) const {
     compat.encode(bl);
@@ -242,44 +199,14 @@ struct CompatSet {
     incompat.decode(bl);
   }
 
-  void dump(ceph::Formatter *f) const {
-    f->open_object_section("compat");
-    compat.dump(f);
-    f->close_section();
-    f->open_object_section("ro_compat");
-    ro_compat.dump(f);
-    f->close_section();
-    f->open_object_section("incompat");
-    incompat.dump(f);
-    f->close_section();
-  }
+  void dump(ceph::Formatter *f) const;
 
-  static void generate_test_instances(std::list<CompatSet*>& o) {
-    o.push_back(new CompatSet);
-    o.push_back(new CompatSet);
-    o.back()->compat.insert(Feature(1, "one"));
-    o.back()->compat.insert(Feature(2, "two"));
-    o.back()->ro_compat.insert(Feature(4, "four"));
-    o.back()->incompat.insert(Feature(3, "three"));
-  }
+  static void generate_test_instances(std::list<CompatSet*>& o);
 };
 WRITE_CLASS_ENCODER(CompatSet)
 
-inline std::ostream& operator<<(std::ostream& out, const CompatSet::Feature& f)
-{
-  return out << "F(" << f.id << ", \"" << f.name << "\")";
-}
-
-inline std::ostream& operator<<(std::ostream& out, const CompatSet::FeatureSet& fs)
-{
-  return out << fs.names;
-}
-
-inline std::ostream& operator<<(std::ostream& out, const CompatSet& compat)
-{
-  return out << "compat=" << compat.compat
-            << ",rocompat=" << compat.ro_compat
-            << ",incompat=" << compat.incompat;
-}
+std::ostream& operator<<(std::ostream& out, const CompatSet::Feature& f);
+std::ostream& operator<<(std::ostream& out, const CompatSet::FeatureSet& fs);
+std::ostream& operator<<(std::ostream& out, const CompatSet& compat);
 
 #endif