From: Sage Weil Date: Wed, 27 Jan 2016 22:27:41 +0000 (-0500) Subject: os/bluestore/BlueStore: load OnodeRef in _txc_add_transaction X-Git-Tag: v10.0.4~35^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9a6e6619f25f38ce100c4c7958346145ad5c8c92;p=ceph.git os/bluestore/BlueStore: 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: Sage Weil --- diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 15b769d49621..0c4dc2d3321b 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -4196,7 +4196,6 @@ void BlueStore::_txc_aio_submit(TransContext *txc) int BlueStore::_txc_add_transaction(TransContext *txc, Transaction *t) { Transaction::iterator i = t->begin(); - int pos = 0; dout(30) << __func__ << " transaction dump:\n"; JSONFormatter f(true); @@ -4218,11 +4217,16 @@ int BlueStore::_txc_add_transaction(TransContext *txc, Transaction *t) } vector ovec(i.objects.size()); - for (; i.have_op(); ++pos) { + 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_RMCOLL: { @@ -4256,6 +4260,40 @@ int BlueStore::_txc_add_transaction(TransContext *txc, Transaction *t) continue; } 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) { dout(0) << " error " << cpp_strerror(r) @@ -4271,36 +4309,50 @@ int BlueStore::_txc_add_transaction(TransContext *txc, Transaction *t) 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_NOP: - break; case Transaction::OP_TOUCH: - { - const ghobject_t &oid = i.get_oid(op->oid); - r = _touch(txc, c, oid); - } + 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; @@ -4312,60 +4364,54 @@ int BlueStore::_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; @@ -4375,33 +4421,12 @@ int BlueStore::_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_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; - } + r = _clone_range(txc, c, o, no, srcoff, len, dstoff); } break; @@ -4420,70 +4445,53 @@ int BlueStore::_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); + 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); } @@ -4494,6 +4502,7 @@ int BlueStore::_txc_add_transaction(TransContext *txc, Transaction *t) assert(0); } + endop: if (r < 0) { bool ok = false; @@ -4547,17 +4556,15 @@ int BlueStore::_txc_add_transaction(TransContext *txc, Transaction *t) // write operations int BlueStore::_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; - 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; } @@ -5566,21 +5573,20 @@ int BlueStore::_do_write( } int BlueStore::_write(TransContext *txc, - CollectionRef& c, - const ghobject_t& oid, + 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; - OnodeRef 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); - dout(10) << __func__ << " " << c->cid << " " << oid + dout(10) << __func__ << " " << c->cid << " " << o->oid << " " << offset << "~" << length << " = " << r << dendl; return r; @@ -5601,17 +5607,16 @@ int BlueStore::_do_write_zero( } int BlueStore::_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; EnodeRef enode; - OnodeRef o = c->get_onode(oid, true); _dump_onode(o); _assign_nid(txc, o); @@ -5649,7 +5654,7 @@ int BlueStore::_zero(TransContext *txc, dout(20) << __func__ << " dealloc " << bp->first << ": " << bp->second << dendl; _txc_release( - txc, c, enode, oid.hobj.get_hash(), + txc, c, enode, o->oid.hobj.get_hash(), bp->second.offset, bp->second.length, bp->second.has_flag(bluestore_extent_t::FLAG_SHARED)); o->onode.block_map.erase(bp++); @@ -5689,7 +5694,7 @@ int BlueStore::_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; @@ -5845,24 +5850,15 @@ int BlueStore::_do_truncate( } int BlueStore::_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; - - OnodeRef o = c->get_onode(oid, false); - if (!o || !o->exists) { - r = -ENOENT; - goto out; - } - r = _do_truncate(txc, c, o, offset); - - out: - dout(10) << __func__ << " " << c->cid << " " << oid + int r = _do_truncate(txc, c, o, offset); + dout(10) << __func__ << " " << c->cid << " " << o->oid << " " << offset << " = " << r << dendl; return r; @@ -5885,65 +5881,42 @@ int BlueStore::_do_remove( } int BlueStore::_remove(TransContext *txc, - CollectionRef& c, - const ghobject_t& oid) + CollectionRef& c, + OnodeRef &o) { - dout(15) << __func__ << " " << c->cid << " " << oid << dendl; - int r; - OnodeRef o = c->get_onode(oid, false); - if (!o || !o->exists) { - r = -ENOENT; - goto out; - } - r = _do_remove(txc, c, o); - - out: - dout(10) << __func__ << " " << c->cid << " " << oid << " = " << r << dendl; + dout(15) << __func__ << " " << c->cid << " " << o->oid << dendl; + int r = _do_remove(txc, c, o); + dout(10) << __func__ << " " << c->cid << " " << o->oid << " = " << r << dendl; return r; } int BlueStore::_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; - - 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 BlueStore::_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; - - 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) { if (p->second.is_partial()) @@ -5952,10 +5925,7 @@ int BlueStore::_setattrs(TransContext *txc, 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; @@ -5963,47 +5933,29 @@ int BlueStore::_setattrs(TransContext *txc, int BlueStore::_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; - - 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 BlueStore::_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; - - 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; } @@ -6026,42 +5978,27 @@ void BlueStore::_do_omap_clear(TransContext *txc, uint64_t id) } int BlueStore::_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; - - 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 BlueStore::_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; - - 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); @@ -6079,26 +6016,18 @@ int BlueStore::_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 BlueStore::_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; - - OnodeRef o = c->get_onode(oid, false); + dout(15) << __func__ << " " << c->cid << " " << o->oid << dendl; + int r; 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); @@ -6106,27 +6035,20 @@ int BlueStore::_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 BlueStore::_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; - OnodeRef o = c->get_onode(oid, false); - if (!o || !o->exists) { - r = -ENOENT; - goto out; - } if (!o->onode.omap_head) { r = 0; goto out; @@ -6144,27 +6066,20 @@ int BlueStore::_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 BlueStore::_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; - - OnodeRef o = c->get_onode(oid, false); - if (!o || !o->exists) { - r = -ENOENT; - goto out; - } + int r = 0; if (!o->onode.omap_head) { - r = 0; goto out; } it = db->get_iterator(PREFIX_OMAP); @@ -6184,33 +6099,25 @@ int BlueStore::_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 BlueStore::_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; - 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; @@ -6218,28 +6125,20 @@ int BlueStore::_setallochint(TransContext *txc, } int BlueStore::_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 (old_oid.hobj.get_hash() != new_oid.hobj.get_hash()) { - derr << __func__ << " mismatched hash on " << old_oid << " and " << new_oid - << dendl; + if (oldo->oid.hobj.get_hash() != newo->oid.hobj.get_hash()) { + derr << __func__ << " mismatched hash on " << oldo->oid + << " and " << newo->oid << dendl; return -EINVAL; } 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); @@ -6316,35 +6215,26 @@ int BlueStore::_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 BlueStore::_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; 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; r = _do_read(oldo, srcoff, length, bl, 0); @@ -6360,32 +6250,26 @@ int BlueStore::_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 BlueStore::_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; 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, c, newo); diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index edb817c7c3c2..a0c6547d5339 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -830,7 +830,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); @@ -871,14 +871,14 @@ private: uint32_t fadvise_flags); int _touch(TransContext *txc, CollectionRef& c, - const ghobject_t& oid); + OnodeRef& o); int _do_write_zero(TransContext *txc, CollectionRef &c, OnodeRef o, uint64_t offset, uint64_t length); int _zero(TransContext *txc, CollectionRef& c, - const ghobject_t& oid, + OnodeRef& o, uint64_t offset, size_t len); int _do_truncate(TransContext *txc, CollectionRef& c, @@ -886,67 +886,68 @@ private: 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, CollectionRef& c, 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);