]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/seastore: add OMAP_GET/SET_HEADER 46011/head
authorchunmei-liu <chunmei.liu@intel.com>
Tue, 26 Apr 2022 08:53:46 +0000 (01:53 -0700)
committerchunmei-liu <chunmei.liu@intel.com>
Fri, 29 Apr 2022 22:05:47 +0000 (15:05 -0700)
Signed-off-by: chunmei-liu <chunmei.liu@intel.com>
src/crimson/os/alienstore/alien_store.cc
src/crimson/os/alienstore/alien_store.h
src/crimson/os/cyanstore/cyan_store.cc
src/crimson/os/cyanstore/cyan_store.h
src/crimson/os/futurized_store.h
src/crimson/os/seastore/seastore.cc
src/crimson/os/seastore/seastore.h
src/crimson/os/seastore/seastore_types.h
src/crimson/osd/pg_backend.cc

index 54d61f76bce090ab8fa30059b402525dd730ee49..da6fba75d14f996fbf260cf6b69fcf16546672fe 100644 (file)
@@ -336,7 +336,7 @@ AlienStore::get_attr(CollectionRef ch,
       // after-free issue.
       auto c = static_cast<AlienCollection*>(ch.get());
       return store->getattr(c->collection, oid, name.c_str(), value);
-    }).then([oid, &value] (int r) -> get_attr_errorator::future<ceph::bufferlist> {
+    }).then([oid, &value](int r) -> get_attr_errorator::future<ceph::bufferlist> {
       if (r == -ENOENT) {
         return crimson::ct_error::enoent::make();
       } else if (r == -ENODATA) {
@@ -554,21 +554,21 @@ seastar::future<struct stat> AlienStore::stat(
 
 auto AlienStore::omap_get_header(CollectionRef ch,
                                  const ghobject_t& oid)
-  -> read_errorator::future<ceph::bufferlist>
+  -> get_attr_errorator::future<ceph::bufferlist>
 {
   assert(tp);
   return do_with_op_gate(ceph::bufferlist(), [=](auto& bl) {
     return tp->submit(ch->get_cid().hash_to_shard(tp->size()), [=, &bl] {
       auto c = static_cast<AlienCollection*>(ch.get());
       return store->omap_get_header(c->collection, oid, &bl);
-    }).then([&bl] (int r) -> read_errorator::future<ceph::bufferlist> {
+    }).then([&bl](int r) -> get_attr_errorator::future<ceph::bufferlist> {
       if (r == -ENOENT) {
         return crimson::ct_error::enoent::make();
       } else if (r < 0) {
         logger().error("omap_get_header: {}", r);
-        return crimson::ct_error::input_output_error::make();
+        ceph_assert(0 == "impossible");
       } else {
-        return read_errorator::make_ready_future<ceph::bufferlist>(
+        return get_attr_errorator::make_ready_future<ceph::bufferlist>(
          std::move(bl));
       }
     });
index b7927f50c91a538856d8e2e4bc0d1ecce6c3c0c1..f6ba12d2c94c58f52ccf9a8467bfb5f46d76db2f 100644 (file)
@@ -106,7 +106,7 @@ public:
   seastar::future<struct stat> stat(
     CollectionRef,
     const ghobject_t&) final;
-  read_errorator::future<ceph::bufferlist> omap_get_header(
+  get_attr_errorator::future<ceph::bufferlist> omap_get_header(
     CollectionRef,
     const ghobject_t&) final;
   read_errorator::future<std::map<uint64_t, uint64_t>> fiemap(
index f10be4ad1b7baa588b9080990bf08ebe0c71510c..772ecae1447bcfba516bab635ad673e7beb240be 100644 (file)
@@ -322,7 +322,7 @@ CyanStore::omap_get_values(CollectionRef ch,
 auto
 CyanStore::omap_get_header(CollectionRef ch,
                           const ghobject_t& oid)
-  -> read_errorator::future<ceph::bufferlist>
+  -> get_attr_errorator::future<ceph::bufferlist>
 {
   auto c = static_cast<Collection*>(ch.get());
   auto o = c->get_object(oid);
@@ -330,7 +330,7 @@ CyanStore::omap_get_header(CollectionRef ch,
     return crimson::ct_error::enoent::make();
   }
 
-  return read_errorator::make_ready_future<ceph::bufferlist>(
+  return get_attr_errorator::make_ready_future<ceph::bufferlist>(
     o->omap_header);
 }
 
index 66ef00b25a2ad46f05987faef878383fd25cc92b..edba296ac193d1c9076049b6379c6d31833f3b5d 100644 (file)
@@ -115,7 +115,7 @@ public:
     const ghobject_t& end,
     uint64_t limit) const final;
 
-  read_errorator::future<ceph::bufferlist> omap_get_header(
+  get_attr_errorator::future<ceph::bufferlist> omap_get_header(
     CollectionRef c,
     const ghobject_t& oid) final;
 
index eff6cb5e5d977e29afae0c161e3f08def899f1fc..20f3a81f7dbdf39f761146d8253b408014072f38 100644 (file)
@@ -125,7 +125,7 @@ public:
     const std::optional<std::string> &start ///< [in] start, empty for begin
     ) = 0; ///< @return <done, values> values.empty() only if done
 
-  virtual read_errorator::future<bufferlist> omap_get_header(
+  virtual get_attr_errorator::future<bufferlist> omap_get_header(
     CollectionRef c,
     const ghobject_t& oid) = 0;
 
index 56e31ac19e01ce082ee64353563405328997a350..daf997b014d60e0f9b5fe4a70da5de59169e7e9e 100644 (file)
@@ -649,13 +649,12 @@ seastar::future<struct stat> SeaStore::stat(
   );
 }
 
-auto
+SeaStore::get_attr_errorator::future<ceph::bufferlist>
 SeaStore::omap_get_header(
-  CollectionRef c,
+  CollectionRef ch,
   const ghobject_t& oid)
-  -> read_errorator::future<bufferlist>
 {
-  return seastar::make_ready_future<bufferlist>();
+  return get_attr(ch, oid, OMAP_HEADER_XATTR_KEY);
 }
 
 SeaStore::read_errorator::future<SeaStore::omap_values_t>
@@ -1307,8 +1306,9 @@ SeaStore::tm_ret SeaStore::_omap_set_header(
 {
   LOG_PREFIX(SeaStore::_omap_set_header);
   DEBUGT("{} {} bytes", *ctx.transaction, *onode, header.length());
-  assert(0 == "not supported yet");
-  return tm_iertr::now();
+  std::map<std::string, bufferlist> to_set;
+  to_set[OMAP_HEADER_XATTR_KEY] = header;
+  return _setattrs(ctx, onode,std::move(to_set));
 }
 
 SeaStore::tm_ret SeaStore::_omap_clear(
@@ -1317,29 +1317,32 @@ SeaStore::tm_ret SeaStore::_omap_clear(
 {
   LOG_PREFIX(SeaStore::_omap_clear);
   DEBUGT("{} {} keys", *ctx.transaction, *onode);
-  if (auto omap_root = onode->get_layout().omap_root.get(
-    onode->get_metadata_hint(device->get_block_size()));
-    omap_root.is_null()) {
-    return seastar::now();
-  } else {
-    return seastar::do_with(
-      BtreeOMapManager(*transaction_manager),
-      onode->get_layout().omap_root.get(
-        onode->get_metadata_hint(device->get_block_size())),
-      [&ctx, &onode](
-      auto &omap_manager,
-      auto &omap_root) {
-      return omap_manager.omap_clear(
-        omap_root,
-        *ctx.transaction)
-      .si_then([&] {
-        if (omap_root.must_update()) {
-          onode->get_mutable_layout(*ctx.transaction
-          ).omap_root.update(omap_root);
-        }
+  return _xattr_rmattr(ctx, onode, std::string(OMAP_HEADER_XATTR_KEY))
+    .si_then([this, &ctx, &onode]() -> tm_ret {
+    if (auto omap_root = onode->get_layout().omap_root.get(
+      onode->get_metadata_hint(device->get_block_size()));
+      omap_root.is_null()) {
+      return seastar::now();
+    } else {
+      return seastar::do_with(
+        BtreeOMapManager(*transaction_manager),
+        onode->get_layout().omap_root.get(
+          onode->get_metadata_hint(device->get_block_size())),
+        [&ctx, &onode](
+        auto &omap_manager,
+        auto &omap_root) {
+        return omap_manager.omap_clear(
+          omap_root,
+          *ctx.transaction)
+        .si_then([&] {
+          if (omap_root.must_update()) {
+            onode->get_mutable_layout(*ctx.transaction
+            ).omap_root.update(omap_root);
+          }
+        });
       });
-    });
-  }
+    }
+  });
 }
 
 SeaStore::tm_ret SeaStore::_omap_rmkeys(
index 99cf024e7bb1cc26172eafa0b87875c9fc8ab4ae..3a4822dd6bff98fd2152481d83dd95b884729665 100644 (file)
@@ -124,7 +124,7 @@ public:
     const std::optional<std::string> &start ///< [in] start, empty for begin
     ) final; ///< @return <done, values> values.empty() iff done
 
-  read_errorator::future<bufferlist> omap_get_header(
+  get_attr_errorator::future<bufferlist> omap_get_header(
     CollectionRef c,
     const ghobject_t& oid) final;
 
index a45760ad4750502d26171f426330bfccff2e7ad8..4980115829119656dde00ec258ecda51b2b170de 100644 (file)
@@ -21,6 +21,9 @@
 
 namespace crimson::os::seastore {
 
+/* using a special xattr key "omap_header" to store omap header */
+  const std::string OMAP_HEADER_XATTR_KEY = "omap_header";
+
 /*
  * Note: NULL value is usually the default and max value.
  */
index c6a74d2ec01248b28db6db38c7042a3690741ae1..5c7984fe7e4f0d1908e8714893fc7f9ce0b41b8d 100644 (file)
@@ -1099,7 +1099,13 @@ PGBackend::omap_get_header(
   const crimson::os::CollectionRef& c,
   const ghobject_t& oid) const
 {
-  return store->omap_get_header(c, oid);
+  return store->omap_get_header(c, oid)
+    .handle_error(
+      crimson::ct_error::enodata::handle([] {
+       return seastar::make_ready_future<bufferlist>();
+      }),
+      ll_read_errorator::pass_further{}
+    );
 }
 
 PGBackend::ll_read_ierrorator::future<>