]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/os/seastore: add get/set attr methods
authorXuehan Xu <xxhdx1985126@gmail.com>
Tue, 30 Mar 2021 10:38:23 +0000 (18:38 +0800)
committerXuehan Xu <xxhdx1985126@gmail.com>
Thu, 22 Apr 2021 08:09:49 +0000 (16:09 +0800)
Signed-off-by: Xuehan Xu <xxhdx1985126@gmail.com>
src/crimson/os/seastore/onode.h
src/crimson/os/seastore/seastore.cc

index 21c0fba8aa559f9bd62961cd6e88d074a8da837e..955d3a9d802534fa6d36f90e1d8f06ecf56ae6cc 100644 (file)
 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;
index 899019e0bd3cafdb1739353a8589b6715f8eeaa3..b44a3290b91f386cb13419eee2c24d44f5f39c1c 100644 (file)
@@ -212,7 +212,17 @@ SeaStore::get_attrs_ertr::future<SeaStore::attrs_t> SeaStore::get_attrs(
   auto c = static_cast<SeastoreCollection*>(ch.get());
   logger().debug("{} {} {}",
                 __func__, c->get_cid(), oid);
-  return crimson::ct_error::enoent::make();
+  return repeat_with_onode<attrs_t>(
+    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<struct stat> 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();
 }