From 58a58a88bb66edd35387a3ef11dea63cf28bb4bd Mon Sep 17 00:00:00 2001 From: Xuehan Xu Date: Tue, 30 Mar 2021 18:38:23 +0800 Subject: [PATCH] crimson/os/seastore: add get/set attr methods Signed-off-by: Xuehan Xu --- src/crimson/os/seastore/onode.h | 19 +++++++++++++++ src/crimson/os/seastore/seastore.cc | 37 ++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/crimson/os/seastore/onode.h b/src/crimson/os/seastore/onode.h index 21c0fba8aa559..955d3a9d80253 100644 --- a/src/crimson/os/seastore/onode.h +++ b/src/crimson/os/seastore/onode.h @@ -14,10 +14,29 @@ namespace crimson::os::seastore { struct onode_layout_t { + // around 350 bytes for fixed fields in object_info_t, + // the left are for the variable-sized fields like oid + // FIXME: object_info_t may need to shrinked, at least + // oid doesn't need to be held in it. + static constexpr int MAX_OI_LENGTH = 1024; + // We might want to move the ss field out of onode_layout_t. + // The reason is that ss_attr may grow to relative large, as + // its clone_overlap may grow to a large size, if applications + // set objects to a relative large size(for the purpose of reducing + // the number of objects per OSD, so that all objects' metadata + // can be cached in memory) and do many modifications between + // snapshots. + static constexpr int MAX_SS_LENGTH = 128; + ceph_le32 size{0}; + ceph_le32 oi_size{0}; + ceph_le32 ss_size{0}; omap_root_le_t omap_root; object_data_le_t object_data; + + char oi[MAX_OI_LENGTH]; + char ss[MAX_SS_LENGTH]; } __attribute__((packed)); class Transaction; diff --git a/src/crimson/os/seastore/seastore.cc b/src/crimson/os/seastore/seastore.cc index 899019e0bd3ca..b44a3290b91f3 100644 --- a/src/crimson/os/seastore/seastore.cc +++ b/src/crimson/os/seastore/seastore.cc @@ -212,7 +212,17 @@ SeaStore::get_attrs_ertr::future SeaStore::get_attrs( auto c = static_cast(ch.get()); logger().debug("{} {} {}", __func__, c->get_cid(), oid); - return crimson::ct_error::enoent::make(); + return repeat_with_onode( + c, oid, [=](auto &t, auto& onode) { + auto& layout = onode.get_layout(); + SeaStore::attrs_t attrs; + attrs[OI_ATTR] = ceph::bufferptr(&layout.oi[0], layout.oi_size); + attrs[SS_ATTR] = ceph::bufferptr(&layout.ss[0], layout.ss_size); + return attrs; + }).handle_error(crimson::ct_error::input_output_error::handle([this] { + logger().error("EIO when getting attrs"); + abort(); + }), crimson::ct_error::pass_further_all{}); } seastar::future SeaStore::stat( @@ -803,6 +813,31 @@ SeaStore::tm_ret SeaStore::_setattrs( { logger().debug("{} onode={}", __func__, *onode); + auto& layout = onode->get_mutable_layout(*ctx.transaction); + for (auto& [key, val] : aset) { + if (key == OI_ATTR) { + if (__builtin_expect( + val.length() > onode_layout_t::MAX_OI_LENGTH, + false)) { + logger().error("{} onode={} oi attr too long!"); + return crimson::ct_error::input_output_error::make(); + } + layout.oi_size = val.length(); + val.copy_out(0, val.length(), &layout.oi[0]); + } else if (key == SS_ATTR) { + if (__builtin_expect( + val.length() > onode_layout_t::MAX_SS_LENGTH, + false)) { + logger().error("{} onode={} oi attr too long!"); + return crimson::ct_error::input_output_error::make(); + } + layout.ss_size = val.length(); + val.copy_out(0, val.length(), &layout.ss[0]); + } else { + //FIXME: right now, only OI_ATTR and SS_ATTR are supported + assert(0 == "only OI_ATTR and SS_ATTR are supported for now"); + } + } return tm_ertr::now(); } -- 2.39.5