]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/kstore: add merge_delete
authorManali Kulkarni <Manali.Kulkarni@sandisk.com>
Tue, 27 Sep 2016 14:23:39 +0000 (10:23 -0400)
committerSage Weil <sage@redhat.com>
Tue, 27 Sep 2016 15:56:44 +0000 (11:56 -0400)
Signed-off-by: Manali Kulkarni <Manali.Kulkarni@sandisk.com>
src/os/kstore/KStore.cc
src/os/kstore/KStore.h

index abd322fd7edd592de645f373633816f6ab0bfe0e..31af5c2755173e3cddcbedc5fa6d6a9b0f7c00aa 100755 (executable)
@@ -2363,6 +2363,16 @@ void KStore::_txc_add_transaction(TransContext *txc, Transaction *t)
       }
       break;
 
+    case Transaction::OP_MERGE_DELETE:
+      {
+        const ghobject_t& boid = i.get_oid(op->dest_oid);
+        OnodeRef bo = c->get_onode(boid, true);
+        vector<boost::tuple<uint64_t, uint64_t, uint64_t>> move_info;
+        i.decode_move_info(move_info);
+        r = _move_ranges_destroy_src(txc, c, o, cvec[op->dest_cid], bo, move_info);
+      }
+      break;
+
     case Transaction::OP_COLL_ADD:
       assert(0 == "not implemented");
       break;
@@ -3172,6 +3182,48 @@ int KStore::_clone_range(TransContext *txc,
   return r;
 }
 
+/* Move contents of src object according to move_info to base object.
+ * Once the move_info is traversed completely, delete the src object.
+ */
+int KStore::_move_ranges_destroy_src(TransContext *txc,
+                           CollectionRef& c,
+                           OnodeRef& srco,
+                           CollectionRef& basec,
+                           OnodeRef& baseo,
+                           vector<boost::tuple<uint64_t, uint64_t, uint64_t>> move_info)
+{
+  int r = 0;
+  bufferlist bl;
+  baseo->exists = true;
+  _assign_nid(txc, baseo);
+
+// Traverse move_info completely, move contents from src to base object.
+  for (unsigned i = 0; i < move_info.size(); ++i) {
+    uint64_t srcoff;
+    uint64_t dstoff;
+    uint64_t len;
+
+    srcoff = move_info[i].get<0>();
+    dstoff = move_info[i].get<1>();
+    len = move_info[i].get<2>();
+
+    r = _do_read(srco, srcoff, len, bl, 0);
+    if (r < 0)
+    goto out;
+
+    r = _do_write(txc, baseo, dstoff, bl.length(), bl, 0);
+    txc->write_onode(baseo);
+    r = 0;
+  }
+
+// After for loop ends, remove src obj
+  r = _do_remove(txc, srco);
+
+  out:
+  return r;
+}
+
+
 int KStore::_rename(TransContext *txc,
                    CollectionRef& c,
                    OnodeRef& oldo,
index 6230764dd813def9450c306d905a5660faec29fb..103a45a7b74f16c2eaf514aac78e1b81eb404b1e 100644 (file)
@@ -625,6 +625,12 @@ private:
                   OnodeRef& oldo,
                   OnodeRef& newo,
                   uint64_t srcoff, uint64_t length, uint64_t dstoff);
+  int _move_ranges_destroy_src(TransContext *txc,
+                  CollectionRef& c,
+                  OnodeRef& oldo,
+                  CollectionRef& bc,
+                  OnodeRef& newo,
+                  vector<boost::tuple<uint64_t, uint64_t, uint64_t>> move_info);
   int _rename(TransContext *txc,
              CollectionRef& c,
              OnodeRef& oldo,