]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/os/seastore/seastore_types: pretty print fundamental types 45010/head
authorYingxin Cheng <yingxin.cheng@intel.com>
Mon, 14 Feb 2022 03:37:20 +0000 (11:37 +0800)
committerYingxin Cheng <yingxin.cheng@intel.com>
Mon, 21 Feb 2022 06:55:03 +0000 (14:55 +0800)
Signed-off-by: Yingxin Cheng <yingxin.cheng@intel.com>
src/crimson/os/seastore/seastore_types.cc
src/crimson/os/seastore/seastore_types.h

index 966075f6d931bbf0bd68c573ec88991fc3695742..f4b8e4cbb820bcaee8111892c1a0ba459bd94e11 100644 (file)
@@ -24,22 +24,46 @@ std::ostream& operator<<(std::ostream& out, const seastore_meta_t& meta)
   return out << meta.seastore_id;
 }
 
-std::ostream &segment_to_stream(std::ostream &out, const segment_id_t &t)
+std::ostream &operator<<(std::ostream &out, const device_id_printer_t &id)
+{
+  auto _id = id.id;
+  if (_id == DEVICE_ID_NULL) {
+    return out << "DEVICE_ID_NULL";
+  } else if (_id == DEVICE_ID_RECORD_RELATIVE) {
+    return out << "DEVICE_ID_RR";
+  } else if (_id == DEVICE_ID_BLOCK_RELATIVE) {
+    return out << "DEVICE_ID_BR";
+  } else if (_id == DEVICE_ID_DELAYED) {
+    return out << "DEVICE_ID_DELAYED";
+  } else if (_id == DEVICE_ID_FAKE) {
+    return out << "DEVICE_ID_FAKE";
+  } else if (_id == DEVICE_ID_ZERO) {
+    return out << "DEVICE_ID_ZERO";
+  } else {
+    return out << (unsigned)_id;
+  }
+}
+
+std::ostream &operator<<(std::ostream &out, const segment_id_t &segment)
 {
-  if (t == NULL_SEG_ID)
+  if (segment == NULL_SEG_ID) {
     return out << "NULL_SEG";
-  else if (t == FAKE_SEG_ID)
+  } else if (segment == FAKE_SEG_ID) {
     return out << "FAKE_SEG";
-  else
-    return out << t;
+  } else {
+    return out << "[" << device_id_printer_t{segment.device_id()}
+               << "," << segment.device_segment_id()
+               << "]";
+  }
 }
 
-std::ostream &offset_to_stream(std::ostream &out, const seastore_off_t &t)
+std::ostream &operator<<(std::ostream &out, const seastore_off_printer_t &off)
 {
-  if (t == NULL_SEG_OFF)
+  if (off.off == NULL_SEG_OFF) {
     return out << "NULL_OFF";
-  else
-    return out << t;
+  } else {
+    return out << off.off;
+  }
 }
 
 std::ostream& operator<<(std::ostream& out, segment_type_t t)
@@ -79,50 +103,51 @@ std::ostream& operator<<(std::ostream& out, segment_seq_printer_t seq)
   }
 }
 
-std::ostream &operator<<(std::ostream &out, const segment_id_t& segment)
-{
-  return out << "[" << (uint64_t)segment.device_id() << ","
-    << segment.device_segment_id() << "]";
-}
-
-std::ostream &block_offset_to_stream(std::ostream &out, const block_off_t &t)
-{
-  return out << t;
-}
-
 std::ostream &operator<<(std::ostream &out, const paddr_t &rhs)
 {
   out << "paddr_t<";
   if (rhs == P_ADDR_NULL) {
-    out << "NULL_PADDR";
+    out << "NULL";
   } else if (rhs == P_ADDR_MIN) {
-    out << "MIN_PADDR";
-  } else if (rhs.is_block_relative()) {
-    out << "BLOCK_REG";
-  } else if (rhs.is_record_relative()) {
-    out << "RECORD_REG";
+    out << "MIN";
+  } else if (rhs == P_ADDR_ZERO) {
+    out << "ZERO";
   } else if (rhs.is_delayed()) {
     out << "DELAYED_TEMP";
+  } else if (rhs.is_block_relative()) {
+    const seg_paddr_t& s = rhs.as_seg_paddr();
+    out << "BLOCK_REG, " << s.get_segment_off();
+  } else if (rhs.is_record_relative()) {
+    const seg_paddr_t& s = rhs.as_seg_paddr();
+    out << "RECORD_REG, " << s.get_segment_off();
   } else if (rhs.get_addr_type() == addr_types_t::SEGMENT) {
     const seg_paddr_t& s = rhs.as_seg_paddr();
-    segment_to_stream(out, s.get_segment_id());
-    out << ", ";
-    offset_to_stream(out, s.get_segment_off());
+    out << s.get_segment_id()
+        << ", "
+        << seastore_off_printer_t{s.get_segment_off()};
   } else if (rhs.get_addr_type() == addr_types_t::RANDOM_BLOCK) {
     const blk_paddr_t& s = rhs.as_blk_paddr();
-    block_offset_to_stream(out, s.get_block_off());
+    out << s.get_block_off();
   } else {
-    out << "INVALID";
+    out << "INVALID!";
   }
   return out << ">";
 }
 
 std::ostream &operator<<(std::ostream &out, const journal_seq_t &seq)
 {
-  return out << "journal_seq_t("
-             << "segment_seq=" << segment_seq_printer_t{seq.segment_seq}
-             << ", offset=" << seq.offset
-             << ")";
+  if (seq == JOURNAL_SEQ_NULL) {
+    return out << "JOURNAL_SEQ_NULL";
+  } else if (seq == JOURNAL_SEQ_MIN) {
+    return out << "JOURNAL_SEQ_MIN";
+  } else if (seq == NO_DELTAS) {
+    return out << "JOURNAL_SEQ_NO_DELTAS";
+  } else {
+    return out << "journal_seq_t("
+               << "segment_seq=" << segment_seq_printer_t{seq.segment_seq}
+               << ", offset=" << seq.offset
+               << ")";
+  }
 }
 
 std::ostream &operator<<(std::ostream &out, extent_types_t t)
@@ -176,16 +201,16 @@ std::ostream &operator<<(std::ostream &out, const paddr_list_t &rhs)
   return out << ']';
 }
 
-std::ostream &operator<<(std::ostream &lhs, const delta_info_t &rhs)
+std::ostream &operator<<(std::ostream &out, const delta_info_t &delta)
 {
-  return lhs << "delta_info_t("
-            << "type: " << rhs.type
-            << ", paddr: " << rhs.paddr
-            << ", laddr: " << rhs.laddr
-            << ", prev_crc: " << rhs.prev_crc
-            << ", final_crc: " << rhs.final_crc
-            << ", length: " << rhs.length
-            << ", pversion: " << rhs.pversion
+  return out << "delta_info_t("
+            << "type: " << delta.type
+            << ", paddr: " << delta.paddr
+            << ", laddr: " << delta.laddr
+            << ", prev_crc: " << delta.prev_crc
+            << ", final_crc: " << delta.final_crc
+            << ", length: " << delta.length
+            << ", pversion: " << delta.pversion
             << ")";
 }
 
index b126820ca5517c6b80bb89380e0874f5d8548b8c..113b5a280834d944e723e1c4eeae76fe1ebc9861 100644 (file)
@@ -43,10 +43,10 @@ struct seastore_meta_t {
   }
 };
 
-bool is_aligned(uint64_t offset, uint64_t alignment);
-
 std::ostream& operator<<(std::ostream& out, const seastore_meta_t& meta);
 
+bool is_aligned(uint64_t offset, uint64_t alignment);
+
 // identifies a specific physical device within seastore
 using device_id_t = uint8_t;
 
@@ -71,6 +71,12 @@ constexpr device_id_t DEVICE_ID_FAKE = DEVICE_ID_MAX - 4;
 constexpr device_id_t DEVICE_ID_ZERO = DEVICE_ID_MAX - 5;
 constexpr device_id_t DEVICE_ID_MAX_VALID = DEVICE_ID_MAX - 6;
 
+struct device_id_printer_t {
+  device_id_t id;
+};
+
+std::ostream &operator<<(std::ostream &out, const device_id_printer_t &id);
+
 constexpr device_segment_id_t DEVICE_SEGMENT_ID_MAX =
   (1 << SEGMENT_ID_LEN_BITS) - 1;
 
@@ -158,6 +164,8 @@ private:
   friend struct paddr_le_t;
 };
 
+std::ostream &operator<<(std::ostream &out, const segment_id_t&);
+
 // ondisk type of segment_id_t
 struct __attribute((packed)) segment_id_le_t {
   ceph_le32 segment = ceph_le32(segment_id_t::DEFAULT_INTERNAL_SEG_ID);
@@ -179,11 +187,6 @@ constexpr segment_id_t MAX_SEG_ID = segment_id_t(
 constexpr segment_id_t NULL_SEG_ID = MAX_SEG_ID;
 constexpr segment_id_t FAKE_SEG_ID = segment_id_t(DEVICE_ID_FAKE, 0);
 
-std::ostream &operator<<(std::ostream &out, const segment_id_t&);
-
-
-std::ostream &segment_to_stream(std::ostream &, const segment_id_t &t);
-
 // Offset within a segment on disk, see SegmentManager
 // may be negative for relative offsets
 using seastore_off_t = int32_t;
@@ -191,7 +194,11 @@ constexpr seastore_off_t MAX_SEG_OFF =
   std::numeric_limits<seastore_off_t>::max();
 constexpr seastore_off_t NULL_SEG_OFF = MAX_SEG_OFF;
 
-std::ostream &offset_to_stream(std::ostream &, const seastore_off_t &t);
+struct seastore_off_printer_t {
+  seastore_off_t off;
+};
+
+std::ostream &operator<<(std::ostream&, const seastore_off_printer_t&);
 
 /* Monotonically increasing segment seq, uniquely identifies
  * the incarnation of a segment */
@@ -555,6 +562,8 @@ public:
 WRITE_EQ_OPERATORS_1(paddr_t, dev_addr);
 WRITE_CMP_OPERATORS_1(paddr_t, dev_addr);
 
+std::ostream &operator<<(std::ostream &out, const paddr_t &rhs);
+
 struct seg_paddr_t : public paddr_t {
   static constexpr uint64_t SEG_OFF_MASK = std::numeric_limits<uint32_t>::max();
   // mask for segment manager id
@@ -709,8 +718,6 @@ struct __attribute((packed)) paddr_le_t {
   }
 };
 
-std::ostream &operator<<(std::ostream &out, const paddr_t &rhs);
-
 using objaddr_t = uint32_t;
 constexpr objaddr_t OBJ_ADDR_MAX = std::numeric_limits<objaddr_t>::max();
 constexpr objaddr_t OBJ_ADDR_NULL = OBJ_ADDR_MAX;
@@ -762,6 +769,9 @@ struct journal_seq_t {
 };
 WRITE_CMP_OPERATORS_2(journal_seq_t, segment_seq, offset)
 WRITE_EQ_OPERATORS_2(journal_seq_t, segment_seq, offset)
+
+std::ostream &operator<<(std::ostream &out, const journal_seq_t &seq);
+
 constexpr journal_seq_t JOURNAL_SEQ_MIN{
   0,
   P_ADDR_MIN
@@ -777,8 +787,6 @@ constexpr journal_seq_t NO_DELTAS = journal_seq_t{
   P_ADDR_ZERO
 };
 
-std::ostream &operator<<(std::ostream &out, const journal_seq_t &seq);
-
 // logical addr, see LBAManager, TransactionManager
 using laddr_t = uint64_t;
 constexpr laddr_t L_ADDR_MIN = std::numeric_limits<laddr_t>::min();
@@ -855,6 +863,8 @@ enum class extent_types_t : uint8_t {
 };
 constexpr auto EXTENT_TYPES_MAX = static_cast<uint8_t>(extent_types_t::NONE);
 
+std::ostream &operator<<(std::ostream &out, extent_types_t t);
+
 constexpr bool is_logical_type(extent_types_t type) {
   switch (type) {
   case extent_types_t::ROOT:
@@ -872,8 +882,6 @@ constexpr bool is_lba_node(extent_types_t type)
     type == extent_types_t::LADDR_LEAF;
 }
 
-std::ostream &operator<<(std::ostream &out, extent_types_t t);
-
 /* description of a new physical extent */
 struct extent_t {
   extent_types_t type;  ///< type of extent
@@ -919,11 +927,9 @@ struct delta_info_t {
       bl == rhs.bl
     );
   }
-
-  friend std::ostream &operator<<(std::ostream &lhs, const delta_info_t &rhs);
 };
 
-std::ostream &operator<<(std::ostream &lhs, const delta_info_t &rhs);
+std::ostream &operator<<(std::ostream &out, const delta_info_t &delta);
 
 class object_data_t {
   laddr_t reserved_data_base = L_ADDR_NULL;