From: Jianjian Huo Date: Wed, 17 Feb 2016 05:20:44 +0000 (-0500) Subject: os/kstore: load OnodeRef in _txc_add_transaction X-Git-Tag: v10.1.0~313^2~7 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d457ff001f0c1940c1f54637ce2edf2991ce3561;p=ceph.git os/kstore: load OnodeRef in _txc_add_transaction Get OnodeRef ready in the caller, and keep it in a vector so that it can be reused for any subsequent operations in the transaction. Signed-off-by: Jianjian Huo --- diff --git a/src/os/kstore/KStore.cc b/src/os/kstore/KStore.cc index aba227d10497..8ada042c8dfb 100644 --- a/src/os/kstore/KStore.cc +++ b/src/os/kstore/KStore.cc @@ -2448,7 +2448,6 @@ int KStore::queue_transactions( int KStore::_txc_add_transaction(TransContext *txc, Transaction *t) { Transaction::iterator i = t->begin(); - int pos = 0; vector cvec(i.colls.size()); unsigned j = 0; @@ -2460,40 +2459,128 @@ int KStore::_txc_add_transaction(TransContext *txc, Transaction *t) if (!j && !txc->first_collection) txc->first_collection = cvec[j]; } + vector ovec(i.objects.size()); - while (i.have_op()) { + for (int pos = 0; i.have_op(); ++pos) { Transaction::Op *op = i.decode_op(); int r = 0; - CollectionRef &c = cvec[op->cid]; + // no coll or obj + if (op->op == Transaction::OP_NOP) + continue; + + // collection operations + CollectionRef &c = cvec[op->cid]; switch (op->op) { - case Transaction::OP_NOP: + case Transaction::OP_RMCOLL: + { + coll_t cid = i.get_cid(op->cid); + r = _remove_collection(txc, cid, &c); + } break; - case Transaction::OP_TOUCH: + + case Transaction::OP_MKCOLL: + { + assert(!c); + coll_t cid = i.get_cid(op->cid); + r = _create_collection(txc, cid, op->split_bits, &c); + } + break; + + case Transaction::OP_SPLIT_COLLECTION: + assert(0 == "deprecated"); + break; + + case Transaction::OP_SPLIT_COLLECTION2: { - const ghobject_t &oid = i.get_oid(op->oid); - r = _touch(txc, c, oid); + uint32_t bits = op->split_bits; + uint32_t rem = op->split_rem; + r = _split_collection(txc, c, cvec[op->dest_cid], bits, rem); } break; + case Transaction::OP_COLL_HINT: + { + uint32_t type = op->hint_type; + bufferlist hint; + i.decode_bl(hint); + bufferlist::iterator hiter = hint.begin(); + if (type == Transaction::COLL_HINT_EXPECTED_NUM_OBJECTS) { + uint32_t pg_num; + uint64_t num_objs; + ::decode(pg_num, hiter); + ::decode(num_objs, hiter); + dout(10) << __func__ << " collection hint objects is a no-op, " + << " pg_num " << pg_num << " num_objects " << num_objs + << dendl; + } else { + // Ignore the hint + dout(10) << __func__ << " unknown collection hint " << type << dendl; + } + continue; + } + break; + + case Transaction::OP_COLL_SETATTR: + r = -EOPNOTSUPP; + break; + + case Transaction::OP_COLL_RMATTR: + r = -EOPNOTSUPP; + break; + + case Transaction::OP_COLL_RENAME: + assert(0 == "not implemented"); + break; + } + if (r < 0) { + assert(0 == "unexpected error"); + } + + // object operations + RWLock::WLocker l(c->lock); + OnodeRef &o = ovec[op->oid]; + if (!o) { + // these operations implicity create the object + bool create = false; + if (op->op == Transaction::OP_TOUCH || + op->op == Transaction::OP_WRITE || + op->op == Transaction::OP_ZERO) { + create = true; + } + ghobject_t oid = i.get_oid(op->oid); + o = c->get_onode(oid, create); + if (!create) { + if (!o || !o->exists) { + dout(10) << __func__ << " op " << op->op << " got ENOENT on " + << oid << dendl; + r = -ENOENT; + goto endop; + } + } + } + + switch (op->op) { + case Transaction::OP_TOUCH: + r = _touch(txc, c, o); + break; + case Transaction::OP_WRITE: { - const ghobject_t &oid = i.get_oid(op->oid); uint64_t off = op->off; uint64_t len = op->len; uint32_t fadvise_flags = i.get_fadvise_flags(); bufferlist bl; i.decode_bl(bl); - r = _write(txc, c, oid, off, len, bl, fadvise_flags); + r = _write(txc, c, o, off, len, bl, fadvise_flags); } break; case Transaction::OP_ZERO: { - const ghobject_t &oid = i.get_oid(op->oid); uint64_t off = op->off; uint64_t len = op->len; - r = _zero(txc, c, oid, off, len); + r = _zero(txc, c, o, off, len); } break; @@ -2505,60 +2592,52 @@ int KStore::_txc_add_transaction(TransContext *txc, Transaction *t) case Transaction::OP_TRUNCATE: { - const ghobject_t& oid = i.get_oid(op->oid); uint64_t off = op->off; - r = _truncate(txc, c, oid, off); + r = _truncate(txc, c, o, off); } break; case Transaction::OP_REMOVE: - { - const ghobject_t& oid = i.get_oid(op->oid); - r = _remove(txc, c, oid); - } + r = _remove(txc, c, o); break; case Transaction::OP_SETATTR: { - const ghobject_t &oid = i.get_oid(op->oid); string name = i.decode_string(); bufferlist bl; i.decode_bl(bl); map to_set; to_set[name] = bufferptr(bl.c_str(), bl.length()); - r = _setattrs(txc, c, oid, to_set); + r = _setattrs(txc, c, o, to_set); } break; case Transaction::OP_SETATTRS: { - const ghobject_t& oid = i.get_oid(op->oid); map aset; i.decode_attrset(aset); - r = _setattrs(txc, c, oid, aset); + r = _setattrs(txc, c, o, aset); } break; case Transaction::OP_RMATTR: { - const ghobject_t &oid = i.get_oid(op->oid); string name = i.decode_string(); - r = _rmattr(txc, c, oid, name); + r = _rmattr(txc, c, o, name); } break; case Transaction::OP_RMATTRS: { - const ghobject_t &oid = i.get_oid(op->oid); - r = _rmattrs(txc, c, oid); + r = _rmattrs(txc, c, o); } break; case Transaction::OP_CLONE: { - const ghobject_t& oid = i.get_oid(op->oid); const ghobject_t& noid = i.get_oid(op->dest_oid); - r = _clone(txc, c, oid, noid); + OnodeRef no = c->get_onode(noid, true); + r = _clone(txc, c, o, no); } break; @@ -2568,48 +2647,12 @@ int KStore::_txc_add_transaction(TransContext *txc, Transaction *t) case Transaction::OP_CLONERANGE2: { - const ghobject_t &oid = i.get_oid(op->oid); - const ghobject_t &noid = i.get_oid(op->dest_oid); + const ghobject_t& noid = i.get_oid(op->dest_oid); + OnodeRef no = c->get_onode(noid, true); uint64_t srcoff = op->off; uint64_t len = op->len; uint64_t dstoff = op->dest_off; - r = _clone_range(txc, c, oid, noid, srcoff, len, dstoff); - } - break; - - case Transaction::OP_MKCOLL: - { - assert(!c); - coll_t cid = i.get_cid(op->cid); - r = _create_collection(txc, cid, op->split_bits, &c); - } - break; - - case Transaction::OP_COLL_HINT: - { - uint32_t type = op->hint_type; - bufferlist hint; - i.decode_bl(hint); - bufferlist::iterator hiter = hint.begin(); - if (type == Transaction::COLL_HINT_EXPECTED_NUM_OBJECTS) { - uint32_t pg_num; - uint64_t num_objs; - ::decode(pg_num, hiter); - ::decode(num_objs, hiter); - dout(10) << __func__ << " collection hint objects is a no-op, " - << " pg_num " << pg_num << " num_objects " << num_objs - << dendl; - } else { - // Ignore the hint - dout(10) << __func__ << " unknown collection hint " << type << dendl; - } - } - break; - - case Transaction::OP_RMCOLL: - { - coll_t cid = i.get_cid(op->cid); - r = _remove_collection(txc, cid, &c); + r = _clone_range(txc, c, o, no, srcoff, len, dstoff); } break; @@ -2628,80 +2671,53 @@ int KStore::_txc_add_transaction(TransContext *txc, Transaction *t) case Transaction::OP_COLL_MOVE_RENAME: { assert(op->cid == op->dest_cid); - ghobject_t oldoid = i.get_oid(op->oid); - ghobject_t newoid = i.get_oid(op->dest_oid); - r = _rename(txc, c, oldoid, newoid); + const ghobject_t& noid = i.get_oid(op->dest_oid); + OnodeRef no = c->get_onode(noid, true); + r = _rename(txc, c, o, no, noid); + o.reset(); } break; - case Transaction::OP_COLL_SETATTR: - r = -EOPNOTSUPP; - break; - - case Transaction::OP_COLL_RMATTR: - r = -EOPNOTSUPP; - break; - - case Transaction::OP_COLL_RENAME: - assert(0 == "not implemented"); - break; - case Transaction::OP_OMAP_CLEAR: { - ghobject_t oid = i.get_oid(op->oid); - r = _omap_clear(txc, c, oid); + r = _omap_clear(txc, c, o); } break; case Transaction::OP_OMAP_SETKEYS: { - ghobject_t oid = i.get_oid(op->oid); bufferlist aset_bl; i.decode_attrset_bl(&aset_bl); - r = _omap_setkeys(txc, c, oid, aset_bl); + r = _omap_setkeys(txc, c, o, aset_bl); } break; case Transaction::OP_OMAP_RMKEYS: { - ghobject_t oid = i.get_oid(op->oid); bufferlist keys_bl; i.decode_keyset_bl(&keys_bl); - r = _omap_rmkeys(txc, c, oid, keys_bl); + r = _omap_rmkeys(txc, c, o, keys_bl); } break; case Transaction::OP_OMAP_RMKEYRANGE: { - ghobject_t oid = i.get_oid(op->oid); string first, last; first = i.decode_string(); last = i.decode_string(); - r = _omap_rmkey_range(txc, c, oid, first, last); + r = _omap_rmkey_range(txc, c, o, first, last); } break; case Transaction::OP_OMAP_SETHEADER: { - ghobject_t oid = i.get_oid(op->oid); bufferlist bl; i.decode_bl(bl); - r = _omap_setheader(txc, c, oid, bl); - } - break; - case Transaction::OP_SPLIT_COLLECTION: - assert(0 == "deprecated"); - break; - case Transaction::OP_SPLIT_COLLECTION2: - { - uint32_t bits = op->split_bits; - uint32_t rem = op->split_rem; - r = _split_collection(txc, c, cvec[op->dest_cid], bits, rem); + r = _omap_setheader(txc, c, o, bl); } break; case Transaction::OP_SETALLOCHINT: { - ghobject_t oid = i.get_oid(op->oid); uint64_t expected_object_size = op->expected_object_size; uint64_t expected_write_size = op->expected_write_size; - r = _setallochint(txc, c, oid, + r = _setallochint(txc, c, o, expected_object_size, expected_write_size); } @@ -2712,6 +2728,7 @@ int KStore::_txc_add_transaction(TransContext *txc, Transaction *t) assert(0); } + endop: if (r < 0) { bool ok = false; @@ -2754,8 +2771,6 @@ int KStore::_txc_add_transaction(TransContext *txc, Transaction *t) assert(0 == "unexpected error"); } } - - ++pos; } return 0; @@ -2767,18 +2782,16 @@ int KStore::_txc_add_transaction(TransContext *txc, Transaction *t) // write operations int KStore::_touch(TransContext *txc, - CollectionRef& c, - const ghobject_t& oid) + CollectionRef& c, + OnodeRef &o) { - dout(15) << __func__ << " " << c->cid << " " << oid << dendl; + dout(15) << __func__ << " " << c->cid << " " << o->oid << dendl; int r = 0; RWLock::WLocker l(c->lock); - OnodeRef o = c->get_onode(oid, true); - assert(o); o->exists = true; _assign_nid(txc, o); txc->write_onode(o); - dout(10) << __func__ << " " << c->cid << " " << oid << " = " << r << dendl; + dout(10) << __func__ << " " << c->cid << " " << o->oid << " = " << r << dendl; return r; } @@ -2829,10 +2842,10 @@ void KStore::_do_remove_stripe(TransContext *txc, OnodeRef o, uint64_t offset) } int KStore::_do_write(TransContext *txc, - OnodeRef o, - uint64_t offset, uint64_t length, - bufferlist& orig_bl, - uint32_t fadvise_flags) + OnodeRef o, + uint64_t offset, uint64_t length, + bufferlist& orig_bl, + uint32_t fadvise_flags) { int r = 0; @@ -2919,39 +2932,38 @@ int KStore::_do_write(TransContext *txc, } int KStore::_write(TransContext *txc, - CollectionRef& c, - const ghobject_t& oid, - uint64_t offset, size_t length, - bufferlist& bl, - uint32_t fadvise_flags) + CollectionRef& c, + OnodeRef& o, + uint64_t offset, size_t length, + bufferlist& bl, + uint32_t fadvise_flags) { - dout(15) << __func__ << " " << c->cid << " " << oid + dout(15) << __func__ << " " << c->cid << " " << o->oid << " " << offset << "~" << length << dendl; RWLock::WLocker l(c->lock); - OnodeRef 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); - dout(10) << __func__ << " " << c->cid << " " << oid + dout(10) << __func__ << " " << c->cid << " " << o->oid << " " << offset << "~" << length << " = " << r << dendl; return r; } int KStore::_zero(TransContext *txc, - CollectionRef& c, - const ghobject_t& oid, - uint64_t offset, size_t length) + CollectionRef& c, + OnodeRef& o, + uint64_t offset, size_t length) { - dout(15) << __func__ << " " << c->cid << " " << oid + dout(15) << __func__ << " " << c->cid << " " << o->oid << " " << offset << "~" << length << dendl; int r = 0; RWLock::WLocker l(c->lock); - OnodeRef o = c->get_onode(oid, true); + _dump_onode(o); _assign_nid(txc, o); uint64_t stripe_size = o->onode.stripe_size; @@ -3000,7 +3012,7 @@ int KStore::_zero(TransContext *txc, } txc->write_onode(o); - dout(10) << __func__ << " " << c->cid << " " << oid + dout(10) << __func__ << " " << c->cid << " " << o->oid << " " << offset << "~" << length << " = " << r << dendl; return r; @@ -3053,25 +3065,16 @@ int KStore::_do_truncate(TransContext *txc, OnodeRef o, uint64_t offset) } int KStore::_truncate(TransContext *txc, - CollectionRef& c, - const ghobject_t& oid, - uint64_t offset) + CollectionRef& c, + OnodeRef& o, + uint64_t offset) { - dout(15) << __func__ << " " << c->cid << " " << oid + dout(15) << __func__ << " " << c->cid << " " << o->oid << " " << offset << dendl; - int r = 0; - RWLock::WLocker l(c->lock); - OnodeRef o = c->get_onode(oid, false); - if (!o || !o->exists) { - r = -ENOENT; - goto out; - } - r = _do_truncate(txc, o, offset); - - out: - dout(10) << __func__ << " " << c->cid << " " << oid + int r = _do_truncate(txc, o, offset); + dout(10) << __func__ << " " << c->cid << " " << o->oid << " " << offset << " = " << r << dendl; return r; @@ -3097,76 +3100,50 @@ int KStore::_do_remove(TransContext *txc, } int KStore::_remove(TransContext *txc, - CollectionRef& c, - const ghobject_t& oid) + CollectionRef& c, + OnodeRef &o) { - dout(15) << __func__ << " " << c->cid << " " << oid << dendl; - int r; + dout(15) << __func__ << " " << c->cid << " " << o->oid << dendl; RWLock::WLocker l(c->lock); - OnodeRef o = c->get_onode(oid, false); - if (!o || !o->exists) { - r = -ENOENT; - goto out; - } - r = _do_remove(txc, o); - - out: - dout(10) << __func__ << " " << c->cid << " " << oid << " = " << r << dendl; + int r = _do_remove(txc, o); + dout(10) << __func__ << " " << c->cid << " " << o->oid << " = " << r << dendl; return r; } int KStore::_setattr(TransContext *txc, - CollectionRef& c, - const ghobject_t& oid, - const string& name, - bufferptr& val) + CollectionRef& c, + OnodeRef& o, + const string& name, + bufferptr& val) { - dout(15) << __func__ << " " << c->cid << " " << oid + dout(15) << __func__ << " " << c->cid << " " << o->oid << " " << name << " (" << val.length() << " bytes)" << dendl; int r = 0; - RWLock::WLocker l(c->lock); - OnodeRef o = c->get_onode(oid, false); - if (!o || !o->exists) { - r = -ENOENT; - goto out; - } o->onode.attrs[name] = val; txc->write_onode(o); - r = 0; - - out: - dout(10) << __func__ << " " << c->cid << " " << oid + dout(10) << __func__ << " " << c->cid << " " << o->oid << " " << name << " (" << val.length() << " bytes)" << " = " << r << dendl; return r; } int KStore::_setattrs(TransContext *txc, - CollectionRef& c, - const ghobject_t& oid, - const map& aset) + CollectionRef& c, + OnodeRef& o, + const map& aset) { - dout(15) << __func__ << " " << c->cid << " " << oid + dout(15) << __func__ << " " << c->cid << " " << o->oid << " " << aset.size() << " keys" << dendl; int r = 0; - RWLock::WLocker l(c->lock); - OnodeRef o = c->get_onode(oid, false); - if (!o || !o->exists) { - r = -ENOENT; - goto out; - } for (map::const_iterator p = aset.begin(); p != aset.end(); ++p) o->onode.attrs[p->first] = p->second; txc->write_onode(o); - r = 0; - - out: - dout(10) << __func__ << " " << c->cid << " " << oid + dout(10) << __func__ << " " << c->cid << " " << o->oid << " " << aset.size() << " keys" << " = " << r << dendl; return r; @@ -3174,49 +3151,31 @@ int KStore::_setattrs(TransContext *txc, int KStore::_rmattr(TransContext *txc, - CollectionRef& c, - const ghobject_t& oid, - const string& name) + CollectionRef& c, + OnodeRef& o, + const string& name) { - dout(15) << __func__ << " " << c->cid << " " << oid + dout(15) << __func__ << " " << c->cid << " " << o->oid << " " << name << dendl; int r = 0; - RWLock::WLocker l(c->lock); - OnodeRef o = c->get_onode(oid, false); - if (!o || !o->exists) { - r = -ENOENT; - goto out; - } o->onode.attrs.erase(name); txc->write_onode(o); - r = 0; - - out: - dout(10) << __func__ << " " << c->cid << " " << oid + dout(10) << __func__ << " " << c->cid << " " << o->oid << " " << name << " = " << r << dendl; return r; } int KStore::_rmattrs(TransContext *txc, - CollectionRef& c, - const ghobject_t& oid) + CollectionRef& c, + OnodeRef& o) { - dout(15) << __func__ << " " << c->cid << " " << oid << dendl; + dout(15) << __func__ << " " << c->cid << " " << o->oid << dendl; int r = 0; - RWLock::WLocker l(c->lock); - OnodeRef o = c->get_onode(oid, false); - if (!o || !o->exists) { - r = -ENOENT; - goto out; - } o->onode.attrs.clear(); txc->write_onode(o); - r = 0; - - out: - dout(10) << __func__ << " " << c->cid << " " << oid << " = " << r << dendl; + dout(10) << __func__ << " " << c->cid << " " << o->oid << " = " << r << dendl; return r; } @@ -3239,44 +3198,29 @@ void KStore::_do_omap_clear(TransContext *txc, uint64_t id) } int KStore::_omap_clear(TransContext *txc, - CollectionRef& c, - const ghobject_t& oid) + CollectionRef& c, + OnodeRef& o) { - dout(15) << __func__ << " " << c->cid << " " << oid << dendl; + dout(15) << __func__ << " " << c->cid << " " << o->oid << dendl; int r = 0; - RWLock::WLocker l(c->lock); - OnodeRef o = c->get_onode(oid, false); - if (!o || !o->exists) { - r = -ENOENT; - goto out; - } if (o->onode.omap_head != 0) { _do_omap_clear(txc, o->onode.omap_head); } - r = 0; - - out: - dout(10) << __func__ << " " << c->cid << " " << oid << " = " << r << dendl; + dout(10) << __func__ << " " << c->cid << " " << o->oid << " = " << r << dendl; return r; } int KStore::_omap_setkeys(TransContext *txc, - CollectionRef& c, - const ghobject_t& oid, - bufferlist &bl) + CollectionRef& c, + OnodeRef& o, + bufferlist &bl) { - dout(15) << __func__ << " " << c->cid << " " << oid << dendl; - int r = 0; + dout(15) << __func__ << " " << c->cid << " " << o->oid << dendl; + int r; bufferlist::iterator p = bl.begin(); __u32 num; - RWLock::WLocker l(c->lock); - OnodeRef o = c->get_onode(oid, false); - if (!o || !o->exists) { - r = -ENOENT; - goto out; - } if (!o->onode.omap_head) { o->onode.omap_head = o->onode.nid; txc->write_onode(o); @@ -3294,27 +3238,19 @@ int KStore::_omap_setkeys(TransContext *txc, txc->t->set(PREFIX_OMAP, final_key, value); } r = 0; - - out: - dout(10) << __func__ << " " << c->cid << " " << oid << " = " << r << dendl; + dout(10) << __func__ << " " << c->cid << " " << o->oid << " = " << r << dendl; return r; } int KStore::_omap_setheader(TransContext *txc, - CollectionRef& c, - const ghobject_t& oid, - bufferlist& bl) + CollectionRef& c, + OnodeRef &o, + bufferlist& bl) { - dout(15) << __func__ << " " << c->cid << " " << oid << dendl; - int r = 0; - + dout(15) << __func__ << " " << c->cid << " " << o->oid << dendl; + int r; RWLock::WLocker l(c->lock); - OnodeRef o = c->get_onode(oid, false); string key; - if (!o || !o->exists) { - r = -ENOENT; - goto out; - } if (!o->onode.omap_head) { o->onode.omap_head = o->onode.nid; txc->write_onode(o); @@ -3322,28 +3258,21 @@ int KStore::_omap_setheader(TransContext *txc, get_omap_header(o->onode.omap_head, &key); txc->t->set(PREFIX_OMAP, key, bl); r = 0; - - out: - dout(10) << __func__ << " " << c->cid << " " << oid << " = " << r << dendl; + dout(10) << __func__ << " " << c->cid << " " << o->oid << " = " << r << dendl; return r; } int KStore::_omap_rmkeys(TransContext *txc, - CollectionRef& c, - const ghobject_t& oid, - bufferlist& bl) + CollectionRef& c, + OnodeRef& o, + bufferlist& bl) { - dout(15) << __func__ << " " << c->cid << " " << oid << dendl; + dout(15) << __func__ << " " << c->cid << " " << o->oid << dendl; int r = 0; bufferlist::iterator p = bl.begin(); __u32 num; RWLock::WLocker l(c->lock); - OnodeRef o = c->get_onode(oid, false); - if (!o || !o->exists) { - r = -ENOENT; - goto out; - } if (!o->onode.omap_head) { r = 0; goto out; @@ -3361,28 +3290,22 @@ int KStore::_omap_rmkeys(TransContext *txc, r = 0; out: - dout(10) << __func__ << " " << c->cid << " " << oid << " = " << r << dendl; + dout(10) << __func__ << " " << c->cid << " " << o->oid << " = " << r << dendl; return r; } int KStore::_omap_rmkey_range(TransContext *txc, - CollectionRef& c, - const ghobject_t& oid, - const string& first, const string& last) + CollectionRef& c, + OnodeRef& o, + const string& first, const string& last) { - dout(15) << __func__ << " " << c->cid << " " << oid << dendl; - int r = 0; + dout(15) << __func__ << " " << c->cid << " " << o->oid << dendl; KeyValueDB::Iterator it; string key_first, key_last; + int r = 0; RWLock::WLocker l(c->lock); - OnodeRef o = c->get_onode(oid, false); - if (!o || !o->exists) { - r = -ENOENT; - goto out; - } if (!o->onode.omap_head) { - r = 0; goto out; } it = db->get_iterator(PREFIX_OMAP); @@ -3402,34 +3325,26 @@ int KStore::_omap_rmkey_range(TransContext *txc, r = 0; out: - dout(10) << __func__ << " " << c->cid << " " << oid << " = " << r << dendl; + dout(10) << __func__ << " " << c->cid << " " << o->oid << " = " << r << dendl; return r; } int KStore::_setallochint(TransContext *txc, - CollectionRef& c, - const ghobject_t& oid, - uint64_t expected_object_size, - uint64_t expected_write_size) + CollectionRef& c, + OnodeRef& o, + uint64_t expected_object_size, + uint64_t expected_write_size) { - dout(15) << __func__ << " " << c->cid << " " << oid + dout(15) << __func__ << " " << c->cid << " " << o->oid << " object_size " << expected_object_size << " write_size " << expected_write_size << dendl; int r = 0; RWLock::WLocker l(c->lock); - OnodeRef o = c->get_onode(oid, false); - if (!o || !o->exists) { - r = -ENOENT; - goto out; - } - o->onode.expected_object_size = expected_object_size; o->onode.expected_write_size = expected_write_size; txc->write_onode(o); - - out: - dout(10) << __func__ << " " << c->cid << " " << oid + dout(10) << __func__ << " " << c->cid << " " << o->oid << " object_size " << expected_object_size << " write_size " << expected_write_size << " = " << r << dendl; @@ -3437,27 +3352,25 @@ int KStore::_setallochint(TransContext *txc, } int KStore::_clone(TransContext *txc, - CollectionRef& c, - const ghobject_t& old_oid, - const ghobject_t& new_oid) + CollectionRef& c, + OnodeRef& oldo, + OnodeRef& newo) { - dout(15) << __func__ << " " << c->cid << " " << old_oid << " -> " - << new_oid << dendl; + dout(15) << __func__ << " " << c->cid << " " << oldo->oid << " -> " + << newo->oid << dendl; int r = 0; + if (oldo->oid.hobj.get_hash() != newo->oid.hobj.get_hash()) { + derr << __func__ << " mismatched hash on " << oldo->oid + << " and " << newo->oid << dendl; + return -EINVAL; + } RWLock::WLocker l(c->lock); bufferlist bl; - OnodeRef newo; - OnodeRef oldo = c->get_onode(old_oid, false); - if (!oldo || !oldo->exists) { - r = -ENOENT; - goto out; - } - newo = c->get_onode(new_oid, true); - assert(newo); newo->exists = true; _assign_nid(txc, newo); + // data oldo->flush(); r = _do_read(oldo, 0, oldo->onode.size, bl, 0); @@ -3470,6 +3383,8 @@ int KStore::_clone(TransContext *txc, goto out; r = _do_write(txc, newo, 0, oldo->onode.size, bl, 0); + if (r < 0) + goto out; newo->onode.attrs = oldo->onode.attrs; @@ -3505,36 +3420,27 @@ int KStore::_clone(TransContext *txc, } txc->write_onode(newo); - r = 0; out: - dout(10) << __func__ << " " << c->cid << " " << old_oid << " -> " - << new_oid << " = " << r << dendl; + dout(10) << __func__ << " " << c->cid << " " << oldo->oid << " -> " + << newo->oid << " = " << r << dendl; return r; } int KStore::_clone_range(TransContext *txc, - CollectionRef& c, - const ghobject_t& old_oid, - const ghobject_t& new_oid, - uint64_t srcoff, uint64_t length, uint64_t dstoff) + CollectionRef& c, + OnodeRef& oldo, + OnodeRef& newo, + uint64_t srcoff, uint64_t length, uint64_t dstoff) { - dout(15) << __func__ << " " << c->cid << " " << old_oid << " -> " - << new_oid << " from " << srcoff << "~" << length + dout(15) << __func__ << " " << c->cid << " " << oldo->oid << " -> " + << newo->oid << " from " << srcoff << "~" << length << " to offset " << dstoff << dendl; int r = 0; RWLock::WLocker l(c->lock); bufferlist bl; - OnodeRef newo; - OnodeRef oldo = c->get_onode(old_oid, false); - if (!oldo || !oldo->exists) { - r = -ENOENT; - goto out; - } - newo = c->get_onode(new_oid, true); - assert(newo); newo->exists = true; _assign_nid(txc, newo); @@ -3549,33 +3455,27 @@ int KStore::_clone_range(TransContext *txc, r = 0; out: - dout(10) << __func__ << " " << c->cid << " " << old_oid << " -> " - << new_oid << " from " << srcoff << "~" << length + dout(10) << __func__ << " " << c->cid << " " << oldo->oid << " -> " + << newo->oid << " from " << srcoff << "~" << length << " to offset " << dstoff << " = " << r << dendl; return r; } int KStore::_rename(TransContext *txc, - CollectionRef& c, - const ghobject_t& old_oid, - const ghobject_t& new_oid) + CollectionRef& c, + OnodeRef& oldo, + OnodeRef& newo, + const ghobject_t& new_oid) { - dout(15) << __func__ << " " << c->cid << " " << old_oid << " -> " + dout(15) << __func__ << " " << c->cid << " " << oldo->oid << " -> " << new_oid << dendl; int r; - + ghobject_t old_oid = oldo->oid; RWLock::WLocker l(c->lock); bufferlist bl; string old_key, new_key; - OnodeRef newo; - OnodeRef oldo = c->get_onode(old_oid, false); - if (!oldo || !oldo->exists) { - r = -ENOENT; - goto out; - } - newo = c->get_onode(new_oid, false); if (newo && newo->exists) { // destination object already exists, remove it first r = _do_remove(txc, newo); diff --git a/src/os/kstore/KStore.h b/src/os/kstore/KStore.h index f380f4e6589a..ecddae5cfa7a 100644 --- a/src/os/kstore/KStore.h +++ b/src/os/kstore/KStore.h @@ -514,7 +514,7 @@ private: int _write(TransContext *txc, CollectionRef& c, - const ghobject_t& oid, + OnodeRef& o, uint64_t offset, size_t len, bufferlist& bl, uint32_t fadvise_flags); @@ -525,76 +525,77 @@ private: uint32_t fadvise_flags); int _touch(TransContext *txc, CollectionRef& c, - const ghobject_t& oid); + OnodeRef& o); int _zero(TransContext *txc, CollectionRef& c, - const ghobject_t& oid, + OnodeRef& o, uint64_t offset, size_t len); int _do_truncate(TransContext *txc, OnodeRef o, uint64_t offset); int _truncate(TransContext *txc, CollectionRef& c, - const ghobject_t& oid, + OnodeRef& o, uint64_t offset); int _remove(TransContext *txc, CollectionRef& c, - const ghobject_t& oid); + OnodeRef& o); int _do_remove(TransContext *txc, OnodeRef o); int _setattr(TransContext *txc, CollectionRef& c, - const ghobject_t& oid, + OnodeRef& o, const string& name, bufferptr& val); int _setattrs(TransContext *txc, CollectionRef& c, - const ghobject_t& oid, + OnodeRef& o, const map& aset); int _rmattr(TransContext *txc, CollectionRef& c, - const ghobject_t& oid, + OnodeRef& o, const string& name); int _rmattrs(TransContext *txc, CollectionRef& c, - const ghobject_t& oid); + OnodeRef& o); void _do_omap_clear(TransContext *txc, uint64_t id); int _omap_clear(TransContext *txc, CollectionRef& c, - const ghobject_t& oid); + OnodeRef& o); int _omap_setkeys(TransContext *txc, CollectionRef& c, - const ghobject_t& oid, + OnodeRef& o, bufferlist& bl); int _omap_setheader(TransContext *txc, CollectionRef& c, - const ghobject_t& oid, + OnodeRef& o, bufferlist& header); int _omap_rmkeys(TransContext *txc, CollectionRef& c, - const ghobject_t& oid, + OnodeRef& o, bufferlist& bl); int _omap_rmkey_range(TransContext *txc, CollectionRef& c, - const ghobject_t& oid, + OnodeRef& o, const string& first, const string& last); int _setallochint(TransContext *txc, CollectionRef& c, - const ghobject_t& oid, + OnodeRef& o, uint64_t expected_object_size, uint64_t expected_write_size); int _clone(TransContext *txc, CollectionRef& c, - const ghobject_t& old_oid, - const ghobject_t& new_oid); + OnodeRef& oldo, + OnodeRef& newo); int _clone_range(TransContext *txc, CollectionRef& c, - const ghobject_t& old_oid, - const ghobject_t& new_oid, + OnodeRef& oldo, + OnodeRef& newo, uint64_t srcoff, uint64_t length, uint64_t dstoff); int _rename(TransContext *txc, CollectionRef& c, - const ghobject_t& old_oid, + OnodeRef& oldo, + OnodeRef& newo, const ghobject_t& new_oid); int _create_collection(TransContext *txc, coll_t cid, unsigned bits, CollectionRef *c);