Skip to content

Commit

Permalink
Merge pull request #7283 from xiexingguo/xxg-wip-14407
Browse files Browse the repository at this point in the history
os/bluestore/kstore: fix nid overwritten logic

http://pulpito.ceph.com/sage-2016-01-25_07:39:08-rados-wip-sage-testing2---basic-smithi/

Reviewed-by: Sage Weil <sage@redhat.com>
  • Loading branch information
liewegas committed Jan 26, 2016
2 parents b08116b + 0cbc76b commit e9b2674
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 42 deletions.
56 changes: 36 additions & 20 deletions src/os/bluestore/BlueStore.cc
Expand Up @@ -4113,11 +4113,11 @@ int BlueStore::_txc_add_transaction(TransContext *txc, Transaction *t)
break;

case Transaction::OP_COLL_ADD:
assert(0 == "not implmeented");
assert(0 == "not implemented");
break;

case Transaction::OP_COLL_REMOVE:
assert(0 == "not implmeented");
assert(0 == "not implemented");
break;

case Transaction::OP_COLL_MOVE:
Expand All @@ -4142,7 +4142,7 @@ int BlueStore::_txc_add_transaction(TransContext *txc, Transaction *t)
break;

case Transaction::OP_COLL_RENAME:
assert(0 == "not implmeneted");
assert(0 == "not implemented");
break;

case Transaction::OP_OMAP_CLEAR:
Expand Down Expand Up @@ -5287,8 +5287,11 @@ int BlueStore::_write(TransContext *txc,
<< " " << offset << "~" << length
<< dendl;
RWLock::WLocker l(c->lock);
OnodeRef o = c->get_onode(oid, true);
_assign_nid(txc, o);
OnodeRef o = c->get_onode(oid, false);
if (!o) {
o = c->get_onode(oid, true);
_assign_nid(txc, o);
}
int r = _do_write(txc, c, o, offset, length, bl, fadvise_flags);
txc->write_onode(o);

Expand Down Expand Up @@ -5324,9 +5327,13 @@ int BlueStore::_zero(TransContext *txc,

RWLock::WLocker l(c->lock);
EnodeRef enode;
OnodeRef o = c->get_onode(oid, true);
_dump_onode(o);
_assign_nid(txc, o);
OnodeRef o = c->get_onode(oid, false);
if (o) {
_dump_onode(o);
} else {
o = c->get_onode(oid, true);
_assign_nid(txc, o);
}

// overlay
_do_overlay_trim(txc, o, offset, length);
Expand Down Expand Up @@ -5964,18 +5971,22 @@ int BlueStore::_clone(TransContext *txc,
r = -ENOENT;
goto out;
}
newo = c->get_onode(new_oid, true);

newo = c->get_onode(new_oid, false);
if (newo) {
r = _do_truncate(txc, c, newo, 0);
if (r < 0)
goto out;
} else {
newo = c->get_onode(new_oid, true);
_assign_nid(txc, newo);
}
assert(newo);
newo->exists = true;
_assign_nid(txc, newo);

// data
oldo->flush();

r = _do_truncate(txc, c, newo, 0);
if (r < 0)
goto out;

if (g_conf->bluestore_clone_cow) {
EnodeRef e = c->get_enode(newo->oid.hobj.get_hash());
bool marked = false;
Expand Down Expand Up @@ -6068,10 +6079,15 @@ int BlueStore::_clone_range(TransContext *txc,
r = -ENOENT;
goto out;
}
newo = c->get_onode(new_oid, true);

newo = c->get_onode(new_oid, false);
if (!newo) {
newo = c->get_onode(new_oid, true);
_assign_nid(txc, newo);
}
assert(newo);
newo->exists = true;

r = _do_read(oldo, srcoff, length, bl, 0);
if (r < 0)
goto out;
Expand Down Expand Up @@ -6108,13 +6124,13 @@ int BlueStore::_rename(TransContext *txc,
r = -ENOENT;
goto out;
}
newo = c->get_onode(new_oid, true);
assert(newo);

if (newo->exists) {
newo = c->get_onode(new_oid, false);
if (newo && newo->exists) {
// destination object already exists, remove it first
r = _do_remove(txc, c, newo);
if (r < 0)
return r;
goto out;
}

txc->t->rmkey(PREFIX_OBJ, oldo->key);
Expand Down
57 changes: 35 additions & 22 deletions src/os/kstore/KStore.cc
Expand Up @@ -924,7 +924,7 @@ int KStore::mkfs()
goto out_close_fsid;

r = _read_fsid(&old_fsid);
if (r < 0 && old_fsid.is_zero()) {
if (r < 0 || old_fsid.is_zero()) {
if (fsid.is_zero()) {
fsid.generate_random();
dout(1) << __func__ << " generated fsid " << fsid << dendl;
Expand Down Expand Up @@ -2609,11 +2609,11 @@ int KStore::_txc_add_transaction(TransContext *txc, Transaction *t)
break;

case Transaction::OP_COLL_ADD:
assert(0 == "not implmeented");
assert(0 == "not implemented");
break;

case Transaction::OP_COLL_REMOVE:
assert(0 == "not implmeented");
assert(0 == "not implemented");
break;

case Transaction::OP_COLL_MOVE:
Expand All @@ -2638,7 +2638,7 @@ int KStore::_txc_add_transaction(TransContext *txc, Transaction *t)
break;

case Transaction::OP_COLL_RENAME:
assert(0 == "not implmeneted");
assert(0 == "not implemented");
break;

case Transaction::OP_OMAP_CLEAR:
Expand Down Expand Up @@ -2986,8 +2986,11 @@ int KStore::_write(TransContext *txc,
<< " " << offset << "~" << length
<< dendl;
RWLock::WLocker l(c->lock);
OnodeRef o = c->get_onode(oid, true);
_assign_nid(txc, o);
OnodeRef o = c->get_onode(oid, false);
if (!o) {
o = c->get_onode(oid, true);
_assign_nid(txc, o);
}
int r = _do_write(txc, o, offset, length, bl, fadvise_flags);
txc->write_onode(o);

Expand All @@ -3008,8 +3011,11 @@ int KStore::_zero(TransContext *txc,
int r = 0;

RWLock::WLocker l(c->lock);
OnodeRef o = c->get_onode(oid, true);
_assign_nid(txc, o);
OnodeRef o = c->get_onode(oid, false);
if (!o) {
o = c->get_onode(oid, true);
_assign_nid(txc, o);
}

uint64_t stripe_size = o->onode.stripe_size;
if (stripe_size) {
Expand Down Expand Up @@ -3509,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;
Expand Down Expand Up @@ -3587,7 +3596,11 @@ int KStore::_clone_range(TransContext *txc,
r = -ENOENT;
goto out;
}
newo = c->get_onode(new_oid, true);
newo = c->get_onode(new_oid, false);
if (!newo) {
newo = c->get_onode(new_oid, true);
_assign_nid(txc, newo);
}
assert(newo);
newo->exists = true;

Expand Down Expand Up @@ -3627,13 +3640,13 @@ int KStore::_rename(TransContext *txc,
r = -ENOENT;
goto out;
}
newo = c->get_onode(new_oid, true);
assert(newo);

if (newo->exists) {
newo = c->get_onode(new_oid, false);
if (newo && newo->exists) {
// destination object already exists, remove it first
r = _do_remove(txc, newo);
if (r < 0)
return r;
goto out;
}

txc->t->rmkey(PREFIX_OBJ, oldo->key);
Expand Down

0 comments on commit e9b2674

Please sign in to comment.