From: Sage Weil Date: Mon, 28 Mar 2016 17:23:56 +0000 (-0400) Subject: os/bluestore: _do_zero_tail_extent helper X-Git-Tag: v10.1.1~28^2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=5abd9ffd6c1be3b082cff16bcf9505f98df8b262;p=ceph.git os/bluestore: _do_zero_tail_extent helper We do this from both _do_truncate and _do_write. No functional change here. Signed-off-by: Sage Weil --- diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 45a1b2f45acbb..4add5a1bcd7c8 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -5447,22 +5447,14 @@ int BlueStore::_do_write( bp = o->onode.seek_extent(orig_offset); - // zero tail of previous existing extent? - // (this happens if the old eof was partway through a previous extent, - // and we implicitly zero the rest of it by writing to a larger offset.) if (orig_offset > o->onode.size) { - uint64_t end = ROUND_UP_TO(o->onode.size, block_size); - map::iterator pp = o->onode.find_extent(end); - if (orig_offset > end && - pp != o->onode.block_map.end() && + // zero tail of previous existing extent? + map::iterator pp = + o->onode.find_extent(o->onode.size); + if (pp != o->onode.block_map.end() && pp != bp) { assert(pp->first < bp->first); - uint64_t x_off = end - pp->first; - uint64_t x_len = pp->second.length - x_off; - dout(10) << __func__ << " zero tail " << x_off << "~" << x_len - << " of prior extent " << pp->first << ": " << pp->second - << dendl; - bdev->aio_zero(pp->second.offset + x_off, x_len, &txc->ioc); + _do_zero_tail_extent(txc, o, orig_offset, pp); } } @@ -5757,6 +5749,36 @@ int BlueStore::_zero(TransContext *txc, return r; } +void BlueStore::_do_zero_tail_extent( + TransContext *txc, + OnodeRef& o, + uint64_t offset, + map::iterator pp) +{ + const uint64_t block_size = bdev->get_block_size(); + const uint64_t block_mask = ~(block_size - 1); + + assert(offset > o->onode.size); + assert(pp != o->onode.block_map.end()); + + // we currently assume that any partial tail block is always zeroed + uint64_t end = ROUND_UP_TO(o->onode.size, block_size); + + // we assume the caller will handle any partial block they start with + offset &= block_mask; + + // zero tail of previous existing extent? + // (this happens if the old eof was partway through a previous extent, + // and we implicitly zero the rest of it by writing to a larger offset.) + if (offset > end) { + uint64_t x_off = end - pp->first; + uint64_t x_len = pp->second.length - x_off; + dout(10) << __func__ << " zero tail " << x_off << "~" << x_len + << " of prior extent " << pp->first << ": " << pp->second + << dendl; + bdev->aio_zero(pp->second.offset + x_off, x_len, &txc->ioc); + } +} int BlueStore::_do_zero(TransContext *txc, CollectionRef& c, @@ -5778,20 +5800,11 @@ int BlueStore::_do_zero(TransContext *txc, uint64_t block_size = bdev->get_block_size(); map::iterator bp = o->onode.seek_extent(offset); - // zero tail of previous existing extent? - // (this happens if the old eof was partway through a previous extent, - // and we implicitly zero the rest of it by writing to a larger offset.) if (offset > o->onode.size) { - uint64_t end = ROUND_UP_TO(o->onode.size, block_size); - map::iterator pp = o->onode.find_extent(end); - if (offset > end && - pp != o->onode.block_map.end()) { - uint64_t x_off = end - pp->first; - uint64_t x_len = pp->second.length - x_off; - dout(10) << __func__ << " zero tail " << x_off << "~" << x_len - << " of prior extent " << pp->first << ": " << pp->second - << dendl; - bdev->aio_zero(pp->second.offset + x_off, x_len, &txc->ioc); + map::iterator pp = + o->onode.find_extent(o->onode.size); + if (pp != o->onode.block_map.end()) { + _do_zero_tail_extent(txc, o, offset, pp); } } diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 124c06c938072..c311951cedd80 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -898,6 +898,11 @@ private: CollectionRef &c, OnodeRef o, uint64_t offset, uint64_t length); + void _do_zero_tail_extent( + TransContext *txc, + OnodeRef& o, + uint64_t offset, + map::iterator pp); int _do_zero(TransContext *txc, CollectionRef& c, OnodeRef& o,