]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/os: Add OP_CLONE to cyanstore 46127/head
authorMatan Breizman <mbreizma@redhat.com>
Tue, 3 May 2022 14:15:57 +0000 (14:15 +0000)
committerMatan Breizman <mbreizma@redhat.com>
Sun, 8 May 2022 08:27:25 +0000 (08:27 +0000)
Signed-off-by: Matan Breizman <mbreizma@redhat.com>
src/crimson/os/cyanstore/cyan_store.cc
src/crimson/os/cyanstore/cyan_store.h

index d58d55a22552c7aa2eee2a6626d3d4a6dfd3e7f1..d0674766276c27e9d3aed1f82d386ee8ec0b5958 100644 (file)
@@ -392,6 +392,14 @@ seastar::future<> CyanStore::do_transaction(CollectionRef ch,
         r = _truncate(cid, oid, off);
       }
       break;
+      case Transaction::OP_CLONE:
+      {
+        coll_t cid = i.get_cid(op->cid);
+        ghobject_t oid = i.get_oid(op->oid);
+        ghobject_t noid = i.get_oid(op->dest_oid);
+        r = _clone(cid, oid, noid);
+      }
+      break;
       case Transaction::OP_SETATTR:
       {
         coll_t cid = i.get_cid(op->cid);
@@ -703,6 +711,30 @@ int CyanStore::_truncate(const coll_t& cid, const ghobject_t& oid, uint64_t size
   return r;
 }
 
+int CyanStore::_clone(const coll_t& cid, const ghobject_t& oid,
+                      const ghobject_t& noid)
+{
+  logger().debug("{} cid={} oid={} noid={}",
+                __func__, cid, oid, noid);
+  auto c = _get_collection(cid);
+  if (!c)
+    return -ENOENT;
+
+  ObjectRef oo = c->get_object(oid);
+  if (!oo)
+    return -ENOENT;
+  if (local_conf()->memstore_debug_omit_block_device_write)
+    return 0;
+  ObjectRef no = c->get_or_create_object(noid);
+  used_bytes += ((ssize_t)oo->get_size() - (ssize_t)no->get_size());
+  no->clone(oo.get(), 0, oo->get_size(), 0);
+
+  no->omap_header = oo->omap_header;
+  no->omap = oo->omap;
+  no->xattr = oo->xattr;
+  return 0;
+}
+
 int CyanStore::_setattrs(const coll_t& cid, const ghobject_t& oid,
                          std::map<std::string,bufferlist>&& aset)
 {
index edba296ac193d1c9076049b6379c6d31833f3b5d..d3ae138d47bf70fe0e9018af2fd7069b411e176e 100644 (file)
@@ -171,6 +171,8 @@ private:
     const std::string &first,
     const std::string &last);
   int _truncate(const coll_t& cid, const ghobject_t& oid, uint64_t size);
+  int _clone(const coll_t& cid, const ghobject_t& oid,
+             const ghobject_t& noid);
   int _setattrs(const coll_t& cid, const ghobject_t& oid,
                 std::map<std::string,bufferlist>&& aset);
   int _rm_attr(const coll_t& cid, const ghobject_t& oid,