]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
kstore: fix dest onode process logic of clone
authorxie xingguo <xie.xingguo@zte.com.cn>
Tue, 19 Jan 2016 10:27:00 +0000 (18:27 +0800)
committerxie xingguo <xie.xingguo@zte.com.cn>
Tue, 19 Jan 2016 11:31:54 +0000 (19:31 +0800)
Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
src/os/kstore/KStore.cc

index 7d7960238db698c459af560f135bac9a72b7dd78..68d6e9298432d65299ef9bab035eed591d6577da 100644 (file)
@@ -3515,20 +3515,23 @@ int KStore::_clone(TransContext *txc,
     r = -ENOENT;
     goto out;
   }
-  newo = c->get_onode(new_oid, true);
-  assert(newo);
-  newo->exists = true;
-  _assign_nid(txc, newo);
+  newo = c->get_onode(new_oid, false);
+  if (newo) {
+    // already exist, truncate any old data
+    r = _do_truncate(txc, newo, 0);
+    if (r < 0)
+      goto out;
+  } else {
+    // does not exist, create it
+    newo = c->get_onode(new_oid, true);
+    _assign_nid(txc, newo);
+  }
 
   r = _do_read(oldo, 0, oldo->onode.size, bl, 0);
   if (r < 0)
     goto out;
 
-  // truncate any old data
-  r = _do_truncate(txc, newo, 0);
-  if (r < 0)
-    goto out;
-
   r = _do_write(txc, newo, 0, oldo->onode.size, bl, 0);
 
   newo->onode.attrs = oldo->onode.attrs;