]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/crimson/os/seastore/random_block_manager.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / crimson / os / seastore / random_block_manager.h
index ee707478a2bf7843bc2b9c214540e0e5b09deec5..0478f5d0e5a633efe10e2a310f4e3e45a09f73b6 100644 (file)
 
 #include "crimson/common/layout.h"
 #include "include/buffer.h"
-#include "include/uuid.h"
-
+#include "crimson/os/seastore/device.h"
 
 namespace crimson::os::seastore {
 
+struct rbm_metadata_header_t {
+  size_t size = 0;
+  size_t block_size = 0;
+  uint64_t feature = 0;
+  uint64_t journal_size = 0;
+  checksum_t crc = 0;
+  device_config_t config;
+
+  DENC(rbm_metadata_header_t, v, p) {
+    DENC_START(1, 1, p);
+    denc(v.size, p);
+    denc(v.block_size, p);
+    denc(v.feature, p);
+
+    denc(v.journal_size, p);
+    denc(v.crc, p);
+    denc(v.config, p);
+    DENC_FINISH(p);
+  }
+
+};
+
+enum class rbm_extent_state_t {
+  FREE,                // not allocated
+  RESERVED,    // extent is reserved by alloc_new_extent, but is not persistent
+  ALLOCATED,   // extent is persistent
+};
+
+class Device;
+using rbm_abs_addr = uint64_t;
+constexpr rbm_abs_addr RBM_START_ADDRESS = 0;
 class RandomBlockManager {
 public:
 
-  struct mkfs_config_t {
-    std::string path;
-    paddr_t start;
-    paddr_t end;
-    size_t block_size = 0;
-    size_t total_size = 0;
-    uint32_t blocks_per_segment = 1 << 18;
-    device_id_t device_id = 0;
-    seastore_meta_t meta;
-  };
-  using mkfs_ertr = crimson::errorator<
-       crimson::ct_error::input_output_error,
-       crimson::ct_error::invarg
-       >;
-  virtual mkfs_ertr::future<> mkfs(mkfs_config_t) = 0;
-
   using read_ertr = crimson::errorator<
     crimson::ct_error::input_output_error,
     crimson::ct_error::invarg,
     crimson::ct_error::enoent,
     crimson::ct_error::erange>;
-  virtual read_ertr::future<> read(uint64_t addr, bufferptr &buffer) = 0;
+  virtual read_ertr::future<> read(paddr_t addr, bufferptr &buffer) = 0;
 
   using write_ertr = crimson::errorator<
     crimson::ct_error::input_output_error,
@@ -56,13 +70,13 @@ public:
     crimson::ct_error::enospc,
     crimson::ct_error::erange
     >;
-  virtual write_ertr::future<> write(uint64_t addr, bufferptr &buf) = 0;
+  virtual write_ertr::future<> write(paddr_t addr, bufferptr &buf) = 0;
 
   using open_ertr = crimson::errorator<
     crimson::ct_error::input_output_error,
     crimson::ct_error::invarg,
     crimson::ct_error::enoent>;
-  virtual open_ertr::future<> open(const std::string &path, paddr_t start) = 0;
+  virtual open_ertr::future<> open() = 0;
 
   using close_ertr = crimson::errorator<
     crimson::ct_error::input_output_error,
@@ -76,29 +90,49 @@ public:
     >;
   using allocate_ret = allocate_ertr::future<paddr_t>;
   // allocator, return start addr of allocated blocks
-  virtual allocate_ret alloc_extent(Transaction &t, size_t size) = 0;
+  virtual paddr_t alloc_extent(size_t size) = 0;
 
-  using abort_allocation_ertr = crimson::errorator<
-    crimson::ct_error::input_output_error,
-    crimson::ct_error::invarg
-    >;
-  virtual abort_allocation_ertr::future<> abort_allocation(Transaction &t) = 0;
+  virtual void mark_space_used(paddr_t paddr, size_t len) = 0;
+  virtual void mark_space_free(paddr_t paddr, size_t len) = 0;
 
-  using complete_allocation_ertr = crimson::errorator<
-    crimson::ct_error::input_output_error,
-    crimson::ct_error::invarg,
-    crimson::ct_error::enoent,
-    crimson::ct_error::erange
-    >;
-  virtual write_ertr::future<> complete_allocation(Transaction &t) = 0;
+  virtual void complete_allocation(paddr_t addr, size_t size) = 0;
 
   virtual size_t get_size() const = 0;
-  virtual size_t get_block_size() const = 0;
+  virtual extent_len_t get_block_size() const = 0;
   virtual uint64_t get_free_blocks() const = 0;
-  virtual uint32_t get_blocks_per_segment() const = 0;
   virtual device_id_t get_device_id() const = 0;
+  virtual const seastore_meta_t &get_meta() const = 0;
+  virtual Device* get_device() = 0;
+  virtual paddr_t get_start() = 0;
+  virtual rbm_extent_state_t get_extent_state(paddr_t addr, size_t size) = 0;
+  virtual size_t get_journal_size() const = 0;
   virtual ~RandomBlockManager() {}
 };
 using RandomBlockManagerRef = std::unique_ptr<RandomBlockManager>;
 
+inline rbm_abs_addr convert_paddr_to_abs_addr(const paddr_t& paddr) {
+  const blk_paddr_t& blk_addr = paddr.as_blk_paddr();
+  return blk_addr.get_device_off();
+}
+
+inline paddr_t convert_abs_addr_to_paddr(rbm_abs_addr addr, device_id_t d_id) {
+  return paddr_t::make_blk_paddr(d_id, addr);
+}
+
+namespace random_block_device {
+  class RBMDevice;
 }
+
+seastar::future<std::unique_ptr<random_block_device::RBMDevice>> 
+  get_rb_device(const std::string &device);
+
+std::ostream &operator<<(std::ostream &out, const rbm_metadata_header_t &header);
+}
+
+WRITE_CLASS_DENC_BOUNDED(
+  crimson::os::seastore::rbm_metadata_header_t
+)
+
+#if FMT_VERSION >= 90000
+template<> struct fmt::formatter<crimson::os::seastore::rbm_metadata_header_t> : fmt::ostream_formatter {};
+#endif