Actually ensure alignment and byte order independence.
Signed-off-by: Samuel Just <sjust@redhat.com>
namespace crimson::os::seastore::extentmap_manager {
struct extmap_node_meta_le_t {
- depth_le_t depth = init_les32(0);
+ depth_le_t depth = init_depth_le(0);
extmap_node_meta_le_t() = default;
extmap_node_meta_le_t(const extmap_node_meta_le_t &) = default;
explicit extmap_node_meta_le_t(const extmap_node_meta_t &val)
- : depth(init_les32(val.depth)) {}
+ : depth(init_depth_le(val.depth)) {}
operator extmap_node_meta_t() const {
return extmap_node_meta_t{ depth };
struct lext_map_val_le_t {
laddr_le_t laddr;
- extent_len_le_t length = init_extent_len_le_t(0);
+ extent_len_le_t length = init_extent_len_le(0);
lext_map_val_le_t() = default;
lext_map_val_le_t(const lext_map_val_le_t &) = default;
explicit lext_map_val_le_t(const lext_map_val_t &val)
: laddr(laddr_le_t(val.laddr)),
- length(init_extent_len_le_t(val.length)) {}
+ length(init_extent_len_le(val.length)) {}
operator lext_map_val_t() const {
return lext_map_val_t{laddr, length};
lba_node_meta_t meta{0, L_ADDR_MAX, 1};
root_leaf->set_meta(meta);
root_leaf->pin.set_range(meta);
- croot->get_root() =
- root_t{
- 1,
- 0,
- root_leaf->get_paddr(),
- make_record_relative_paddr(0),
- L_ADDR_NULL};
+ croot->get_root().lba_root =
+ lba_root_t{root_leaf->get_paddr(), 1u};
return mkfs_ertr::now();
}).handle_error(
mkfs_ertr::pass_further{},
return cache.get_root(t).safe_then([this, &t](auto croot) {
logger().debug(
"BtreeLBAManager::get_root: reading root at {} depth {}",
- paddr_t{croot->get_root().lba_root_addr},
- unsigned(croot->get_root().lba_depth));
+ paddr_t{croot->get_root().lba_root.get_location()},
+ croot->get_root().lba_root.get_depth());
return get_lba_btree_extent(
get_context(t),
croot,
- croot->get_root().lba_depth,
- croot->get_root().lba_root_addr,
+ croot->get_root().lba_root.get_depth(),
+ croot->get_root().lba_root.get_location(),
paddr_t());
});
}
L_ADDR_MIN,
root->get_paddr(),
nullptr);
- croot->get_root().lba_root_addr = nroot->get_paddr();
- croot->get_root().lba_depth = root->get_node_meta().depth + 1;
+ croot->get_root().lba_root = lba_root_t{
+ nroot->get_paddr(),
+ root->get_node_meta().depth + 1
+ };
return nroot->split_entry(
get_context(t),
laddr, nroot->begin(), root);
paddr_t paddr)
{
return cache.get_root(t).safe_then([=, &t](RootBlockRef croot) {
- if (depth == croot->get_root().lba_depth) {
+ if (depth == croot->get_root().lba_root.get_depth()) {
logger().debug(
"update_internal_mapping: updating lba root to: {}->{}",
laddr,
croot = mut_croot->cast<RootBlock>();
}
ceph_assert(laddr == 0);
- auto old_paddr = croot->get_root().lba_root_addr;
- croot->get_root().lba_root_addr = paddr;
+ auto old_paddr = croot->get_root().lba_root.get_location();
+ croot->get_root().lba_root.set_location(paddr);
return update_internal_mapping_ret(
update_internal_mapping_ertr::ready_future_marker{},
old_paddr);
return get_lba_btree_extent(
get_context(t),
croot,
- croot->get_root().lba_depth,
- croot->get_root().lba_root_addr,
+ croot->get_root().lba_root.get_depth(),
+ croot->get_root().lba_root.get_location(),
paddr_t()).safe_then([=, &t](LBANodeRef broot) {
return broot->mutate_internal_address(
get_context(t),
auto mut_croot = c.cache.duplicate_for_write(c.trans, croot);
croot = mut_croot->cast<RootBlock>();
}
- croot->root.lba_root_addr = begin()->get_val();
+ croot->get_root().lba_root = lba_root_t{
+ begin()->get_val(),
+ get_meta().depth - 1};
logger().debug(
"LBAInternalNode::merge_entry: collapsing root {} to addr {}",
*this,
begin()->get_val());
- croot->root.lba_depth = get_meta().depth - 1;
c.cache.retire_extent(c.trans, this);
return merge_ertr::make_ready_future<LBANodeRef>(replacement);
});
struct lba_node_meta_le_t {
laddr_le_t begin = laddr_le_t(0);
laddr_le_t end = laddr_le_t(0);
- depth_le_t depth = init_les32(0);
+ depth_le_t depth = init_depth_le(0);
lba_node_meta_le_t() = default;
lba_node_meta_le_t(const lba_node_meta_le_t &) = default;
explicit lba_node_meta_le_t(const lba_node_meta_t &val)
: begin(init_le64(val.begin)),
end(init_le64(val.end)),
- depth(init_les32(val.depth)) {}
+ depth(init_depth_le(val.depth)) {}
operator lba_node_meta_t() const {
return lba_node_meta_t{ begin, end, depth };
* On disk layout for lba_map_val_t.
*/
struct lba_map_val_le_t {
- extent_len_le_t len = init_extent_len_le_t(0);
+ extent_len_le_t len = init_extent_len_le(0);
paddr_le_t paddr;
ceph_le32 refcount = init_le32(0);
ceph_le32 checksum = init_le32(0);
lba_map_val_le_t() = default;
lba_map_val_le_t(const lba_map_val_le_t &) = default;
explicit lba_map_val_le_t(const lba_map_val_t &val)
- : len(init_extent_len_le_t(val.len)),
+ : len(init_extent_len_le(val.len)),
paddr(paddr_le_t(val.paddr)),
refcount(init_le32(val.refcount)),
checksum(init_le32(val.checksum)) {}
};
struct omap_node_meta_le_t {
- depth_le_t depth = init_les32(0);
+ depth_le_t depth = init_depth_le(0);
omap_node_meta_le_t() = default;
omap_node_meta_le_t(const omap_node_meta_le_t &) = default;
explicit omap_node_meta_le_t(const omap_node_meta_t &val)
- : depth(init_les32(val.depth)) {}
+ : depth(init_depth_le(val.depth)) {}
operator omap_node_meta_t() const {
return omap_node_meta_t{ depth };
namespace crimson::os::seastore {
-/**
- * root_t
- *
- * Contains information required to find metadata roots.
- * TODO: generalize this to permit more than one lba_manager implementation
- */
-struct __attribute__((aligned(8), packed)) root_t {
- depth_t lba_depth = 0;
- depth_t segment_depth = 0;
- paddr_t lba_root_addr;
- paddr_t segment_root;
- laddr_t onode_root = L_ADDR_NULL;
- laddr_t collection_root = L_ADDR_NULL;
- segment_off_t collection_root_size = 0;
-
- void adjust_addrs_from_base(paddr_t base) {
- if (lba_root_addr.is_relative()) {
- lba_root_addr = base.add_record_relative(lba_root_addr);
- }
- }
-};
-
/**
* RootBlock
*
namespace crimson::os::seastore {
-using depth_t = int32_t;
-using depth_le_t = ceph_les32;
+using depth_t = uint32_t;
+using depth_le_t = ceph_le32;
+
+inline depth_le_t init_depth_le(uint32_t i) {
+ return init_le32(i);
+}
using checksum_t = uint32_t;
return paddr_t{FAKE_SEG_ID, off};
}
-struct paddr_le_t {
+struct __attribute((packed)) paddr_le_t {
ceph_le32 segment = init_le32(NULL_SEG_ID);
ceph_les32 offset = init_les32(NULL_SEG_OFF);
constexpr laddr_t L_ADDR_ROOT = std::numeric_limits<laddr_t>::max() - 1;
constexpr laddr_t L_ADDR_LBAT = std::numeric_limits<laddr_t>::max() - 2;
-struct laddr_le_t {
+struct __attribute((packed)) laddr_le_t {
ceph_le64 laddr = init_le64(L_ADDR_NULL);
laddr_le_t() = default;
std::numeric_limits<extent_len_t>::max();
using extent_len_le_t = ceph_le32;
-inline extent_len_le_t init_extent_len_le_t(extent_len_t len) {
+inline extent_len_le_t init_extent_len_le(extent_len_t len) {
return init_le32(len);
}
};
/**
- * coll_root_t
- *
- * Information for locating CollectionManager information, addr should be
- * embedded into the TransactionManager root.
+ * lba_root_t
*/
-class coll_root_t {
- laddr_t coll_root_laddr;
- segment_off_t size = 0;
-
- enum state_t : uint8_t {
- CLEAN = 0, /// No pending mutations
- MUTATED = 1, /// coll_root_laddr state must be written back to persistence
- NONE = 0xFF /// Not yet mounted, should not be exposed to user
- } state = NONE;
+class __attribute__((packed)) lba_root_t {
+ paddr_le_t root_addr;
+ depth_le_t depth = init_extent_len_le(0);
public:
- coll_root_t() : state(state_t::NONE) {}
+ lba_root_t() = default;
- coll_root_t(laddr_t laddr, segment_off_t size)
- : coll_root_laddr(laddr), size(size), state(state_t::CLEAN) {}
+ lba_root_t(paddr_t addr, depth_t depth)
+ : root_addr(addr), depth(init_depth_le(depth)) {}
+
+ lba_root_t(const lba_root_t &o) = default;
+ lba_root_t(lba_root_t &&o) = default;
+ lba_root_t &operator=(const lba_root_t &o) = default;
+ lba_root_t &operator=(lba_root_t &&o) = default;
+
+ paddr_t get_location() const {
+ return root_addr;
+ }
+
+ void set_location(paddr_t location) {
+ root_addr = location;
+ }
+
+ depth_t get_depth() const {
+ return depth;
+ }
+
+ void adjust_addrs_from_base(paddr_t base) {
+ paddr_t _root_addr = root_addr;
+ if (_root_addr.is_relative()) {
+ root_addr = base.add_record_relative(_root_addr);
+ }
+ }
+};
+
+class coll_root_t {
+ laddr_t addr = L_ADDR_NULL;
+ extent_len_t size = 0;
+
+ bool mutated = false;
+
+public:
+ coll_root_t() = default;
+ coll_root_t(laddr_t addr, extent_len_t size) : addr(addr), size(size) {}
+
+ coll_root_t(const coll_root_t &o) = default;
+ coll_root_t(coll_root_t &&o) = default;
+ coll_root_t &operator=(const coll_root_t &o) = default;
+ coll_root_t &operator=(coll_root_t &&o) = default;
bool must_update() const {
- return state == MUTATED;
+ return mutated;
}
- void update(laddr_t addr, segment_off_t s) {
- state = state_t::MUTATED;
- coll_root_laddr = addr;
- size = s;
+ void update(laddr_t _addr, extent_len_t _s) {
+ mutated = true;
+ addr = _addr;
+ size = _s;
}
laddr_t get_location() const {
- return coll_root_laddr;
+ return addr;
}
- auto get_size() const {
+
+ extent_len_t get_size() const {
return size;
}
};
+/**
+ * coll_root_le_t
+ *
+ * Information for locating CollectionManager information, to be embedded
+ * in root block.
+ */
+class __attribute__((packed)) coll_root_le_t {
+ laddr_le_t addr;
+ extent_len_le_t size = init_extent_len_le(0);
+
+public:
+ coll_root_le_t() = default;
+
+ coll_root_le_t(laddr_t laddr, segment_off_t size)
+ : addr(laddr), size(init_extent_len_le(size)) {}
+
+
+ coll_root_le_t(const coll_root_le_t &o) = default;
+ coll_root_le_t(coll_root_le_t &&o) = default;
+ coll_root_le_t &operator=(const coll_root_le_t &o) = default;
+ coll_root_le_t &operator=(coll_root_le_t &&o) = default;
+
+ void update(const coll_root_t &nroot) {
+ addr = nroot.get_location();
+ size = init_extent_len_le(nroot.get_size());
+ }
+
+ coll_root_t get() const {
+ return coll_root_t(addr, size);
+ }
+};
+
+
+/**
+ * root_t
+ *
+ * Contains information required to find metadata roots.
+ * TODO: generalize this to permit more than one lba_manager implementation
+ */
+struct __attribute__((packed)) root_t {
+ lba_root_t lba_root;
+ laddr_le_t onode_root;
+ coll_root_le_t collection_root;
+
+ void adjust_addrs_from_base(paddr_t base) {
+ lba_root.adjust_addrs_from_base(base);
+ }
+};
+
}
WRITE_CLASS_DENC_BOUNDED(crimson::os::seastore::seastore_meta_t)
using read_onode_root_ret = read_onode_root_ertr::future<laddr_t>;
read_onode_root_ret read_onode_root(Transaction &t) {
return cache->get_root(t).safe_then([](auto croot) {
- return croot->get_root().onode_root;
+ laddr_t ret = croot->get_root().onode_root;
+ return ret;
});
}
coll_root_t>;
read_collection_root_ret read_collection_root(Transaction &t) {
return cache->get_root(t).safe_then([](auto croot) {
- return coll_root_t{
- croot->get_root().collection_root,
- croot->get_root().collection_root_size
- };
+ return croot->get_root().collection_root.get();
});
}
void write_collection_root(Transaction &t, coll_root_t cmroot) {
auto croot = cache->get_root_fast(t);
croot = cache->duplicate_for_write(t, croot)->cast<RootBlock>();
- croot->get_root().collection_root = cmroot.get_location();
- croot->get_root().collection_root_size = cmroot.get_size();
+ croot->get_root().collection_root.update(cmroot);
}
~TransactionManager();