From: Max Kellermann Date: Wed, 16 Oct 2024 16:15:16 +0000 (+0200) Subject: include/CompatSet: un-inline to reduce header dependencies X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=a703c99b4b28927a680b73d0ff9a2da781401a5e;p=ceph.git include/CompatSet: un-inline to reduce header dependencies Signed-off-by: Max Kellermann --- diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 4cc50736fc0a5..97fb1fe744014 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -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 index 0000000000000..54f45be5cfa2c --- /dev/null +++ b/src/common/CompatSet.cc @@ -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 + * + * 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 + +#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 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& 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; +} diff --git a/src/crimson/CMakeLists.txt b/src/crimson/CMakeLists.txt index 95d7d34d14376..ce9b44cb0d935 100644 --- a/src/crimson/CMakeLists.txt +++ b/src/crimson/CMakeLists.txt @@ -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 diff --git a/src/include/CompatSet.h b/src/include/CompatSet.h index 35c7a77381dc2..9441b11d4c062 100644 --- a/src/include/CompatSet.h +++ b/src/include/CompatSet.h @@ -15,14 +15,14 @@ #ifndef CEPH_COMPATSET_H #define CEPH_COMPATSET_H -#include +#include #include #include #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 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& 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& 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