]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson: move helper classes down
authorKefu Chai <tchaikov@gmail.com>
Thu, 18 Aug 2022 15:40:42 +0000 (23:40 +0800)
committerKefu Chai <tchaikov@gmail.com>
Thu, 18 Aug 2022 15:45:23 +0000 (23:45 +0800)
so we can use the concept of `IsFullKey` for defining accessors in the
incoming commit.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
src/crimson/os/seastore/onode_manager/staged-fltree/stages/key_layout.h

index b2224455c8be4b0f01fe6d23d8993f3959b33545..13c52c9c1ab19f77bf97158644e43bc2078adc92 100644 (file)
@@ -55,61 +55,6 @@ struct node_offset_packed_t {
   node_offset_t value;
 } __attribute__((packed));
 
-// TODO: consider alignments
-struct shard_pool_t {
-  auto operator<=>(const shard_pool_t&) const = default;
-
-  pool_t pool() const { return _pool; }
-
-  template <KeyT KT>
-  static shard_pool_t from_key(const full_key_t<KT>& key);
-
-  shard_t shard;
-  pool_t _pool;
-} __attribute__((packed));
-inline std::ostream& operator<<(std::ostream& os, const shard_pool_t& sp) {
-  return os << (int)sp.shard << "," << sp.pool();
-}
-
-// Note: this is the reversed version of the object hash
-struct crush_t {
-  auto operator<=>(const crush_t&) const = default;
-
-  template <KeyT KT>
-  static crush_t from_key(const full_key_t<KT>& key);
-
-  crush_hash_t crush;
-} __attribute__((packed));
-inline std::ostream& operator<<(std::ostream& os, const crush_t& c) {
-  return os << "0x" << std::hex << c.crush << std::dec;
-}
-
-struct shard_pool_crush_t {
-  auto operator<=>(const shard_pool_crush_t&) const = default;
-
-  template <KeyT KT>
-  static shard_pool_crush_t from_key(const full_key_t<KT>& key);
-
-  shard_pool_t shard_pool;
-  crush_t crush;
-} __attribute__((packed));
-inline std::ostream& operator<<(std::ostream& os, const shard_pool_crush_t& spc) {
-  return os << spc.shard_pool << ",0x" << std::hex << spc.crush << std::dec;
-}
-
-struct snap_gen_t {
-  auto operator<=>(const snap_gen_t&) const = default;
-
-  template <KeyT KT>
-  static snap_gen_t from_key(const full_key_t<KT>& key);
-
-  snap_t snap;
-  gen_t gen;
-} __attribute__((packed));
-inline std::ostream& operator<<(std::ostream& os, const snap_gen_t& sg) {
-  return os << sg.snap << "," << sg.gen;
-}
-
 /**
  * string_key_view_t
  *
@@ -568,6 +513,11 @@ inline std::ostream& operator<<(std::ostream& os, const key_hobj_t& key) {
   return key.dump(os);
 }
 
+struct shard_pool_t;
+struct crush_t;
+struct shard_pool_crush_t;
+struct snap_gen_t;
+
 /**
  * key_view_t
  *
@@ -579,15 +529,9 @@ class key_view_t {
   /**
    * common interfaces as a full_key_t
    */
-  shard_t shard() const {
-    return shard_pool_packed().shard;
-  }
-  pool_t pool() const {
-    return shard_pool_packed().pool();
-  }
-  crush_hash_t crush() const {
-    return crush_packed().crush;
-  }
+  inline shard_t shard() const;
+  inline pool_t pool() const;
+  inline crush_hash_t crush() const;
   laddr_t get_hint() const {
     return get_lba_hint(shard(), pool(), crush());
   }
@@ -610,12 +554,8 @@ class key_view_t {
   ns_oid_view_t::Type dedup_type() const {
     return ns_oid_view().type();
   }
-  snap_t snap() const {
-    return snap_gen_packed().snap;
-  }
-  gen_t gen() const {
-    return snap_gen_packed().gen;
-  }
+  inline snap_t snap() const;
+  inline gen_t gen() const;
 
   /**
    * key_view_t specific interfaces
@@ -667,12 +607,8 @@ class key_view_t {
     assert(!has_crush());
     replace(key);
   }
-  void replace(const shard_pool_crush_t& key) { p_shard_pool = &key.shard_pool; }
-  void set(const shard_pool_crush_t& key) {
-    set(key.crush);
-    assert(!has_shard_pool());
-    replace(key);
-  }
+  inline void replace(const shard_pool_crush_t& key);
+  inline void set(const shard_pool_crush_t& key);
   void replace(const ns_oid_view_t& key) { p_ns_oid = key; }
   void set(const ns_oid_view_t& key) {
     assert(!has_ns_oid());
@@ -736,6 +672,91 @@ class key_view_t {
 template<typename T>
 concept IsFullKey = std::same_as<T, key_hobj_t> || std::same_as<T, key_view_t>;
 
+// TODO: consider alignments
+struct shard_pool_t {
+  auto operator<=>(const shard_pool_t&) const = default;
+
+  pool_t pool() const { return _pool; }
+
+  template <KeyT KT>
+  static shard_pool_t from_key(const full_key_t<KT>& key);
+
+  shard_t shard;
+  pool_t _pool;
+} __attribute__((packed));
+inline std::ostream& operator<<(std::ostream& os, const shard_pool_t& sp) {
+  return os << (int)sp.shard << "," << sp.pool();
+}
+
+// Note: this is the reversed version of the object hash
+struct crush_t {
+  auto operator<=>(const crush_t&) const = default;
+
+  template <KeyT KT>
+  static crush_t from_key(const full_key_t<KT>& key);
+
+  crush_hash_t crush;
+} __attribute__((packed));
+inline std::ostream& operator<<(std::ostream& os, const crush_t& c) {
+  return os << "0x" << std::hex << c.crush << std::dec;
+}
+
+struct shard_pool_crush_t {
+  auto operator<=>(const shard_pool_crush_t&) const = default;
+
+  template <KeyT KT>
+  static shard_pool_crush_t from_key(const full_key_t<KT>& key);
+
+  shard_pool_t shard_pool;
+  crush_t crush;
+} __attribute__((packed));
+inline std::ostream& operator<<(std::ostream& os, const shard_pool_crush_t& spc) {
+  return os << spc.shard_pool << ",0x" << std::hex << spc.crush << std::dec;
+}
+
+struct snap_gen_t {
+  auto operator<=>(const snap_gen_t&) const = default;
+
+  template <KeyT KT>
+  static snap_gen_t from_key(const full_key_t<KT>& key);
+
+  snap_t snap;
+  gen_t gen;
+} __attribute__((packed));
+inline std::ostream& operator<<(std::ostream& os, const snap_gen_t& sg) {
+  return os << sg.snap << "," << sg.gen;
+}
+
+shard_t key_view_t::shard() const {
+  return shard_pool_packed().shard;
+}
+
+pool_t key_view_t::pool() const {
+  return shard_pool_packed().pool();
+}
+
+crush_hash_t key_view_t::crush() const {
+  return crush_packed().crush;
+}
+
+snap_t key_view_t::snap() const {
+  return snap_gen_packed().snap;
+}
+
+gen_t key_view_t::gen() const {
+  return snap_gen_packed().gen;
+}
+
+void key_view_t::replace(const shard_pool_crush_t& key) {
+  p_shard_pool = &key.shard_pool;
+}
+
+void key_view_t::set(const shard_pool_crush_t& key) {
+  set(key.crush);
+  assert(!has_shard_pool());
+  replace(key);
+}
+
 template <IsFullKey Key>
 void encode_key(const Key& key, ceph::bufferlist& bl) {
   ceph::encode(key.shard(), bl);