From: xie xingguo Date: Tue, 8 Nov 2016 07:45:21 +0000 (+0800) Subject: os/bluestore: refactor _do_write() X-Git-Tag: v11.1.0~367^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=aa7b9a8251361303cccb46ebb8042495398567d0;p=ceph-ci.git os/bluestore: refactor _do_write() By moving garbage collection logic into a separate method. Signed-off-by: xie xingguo --- diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index aa837b69488..f7142ab252f 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -8050,6 +8050,61 @@ void BlueStore::_do_write_data( } } } + +void BlueStore::_do_garbage_collection( + TransContext *txc, + CollectionRef& c, + OnodeRef o, + uint64_t& offset, + uint64_t& length, + bufferlist& bl, + WriteContext *wctx) +{ + uint64_t gc_start_offset, gc_end_offset; + uint64_t end = offset + length; + bool do_collect = + o->extent_map.do_write_check_depth(o->onode.size, + offset, end, &wctx->blob_depth, + &gc_start_offset, + &gc_end_offset); + if (do_collect) { + // we need garbage collection of blobs. + if (offset > gc_start_offset) { + bufferlist head_bl; + size_t read_len = offset - gc_start_offset; + int r = _do_read(c.get(), o, gc_start_offset, read_len, head_bl, 0); + assert(r == (int)read_len); + if (g_conf->bluestore_gc_merge_data) { + head_bl.claim_append(bl); + bl.swap(head_bl); + offset = gc_start_offset; + length = end - offset; + } else { + o->extent_map.fault_range(db, gc_start_offset, read_len); + _do_write_data(txc, c, o, gc_start_offset, read_len, head_bl, wctx); + } + logger->inc(l_bluestore_gc); + logger->inc(l_bluestore_gc_bytes, read_len); + } + + if (end < gc_end_offset) { + bufferlist tail_bl; + size_t read_len = gc_end_offset - end; + int r = _do_read(c.get(), o, end, read_len, tail_bl, 0); + assert(r == (int)read_len); + if (g_conf->bluestore_gc_merge_data) { + bl.claim_append(tail_bl); + length += read_len; + } else { + o->extent_map.fault_range(db, end, read_len); + _do_write_data(txc, c, o, end, read_len, tail_bl, wctx); + } + logger->inc(l_bluestore_gc); + logger->inc(l_bluestore_gc_bytes, read_len); + } + } +} + int BlueStore::_do_write( TransContext *txc, CollectionRef& c, @@ -8163,49 +8218,7 @@ int BlueStore::_do_write( << " target_blob_size 0x" << std::hex << wctx.target_blob_size << std::dec << dendl; - uint64_t gc_start_offset = offset, gc_end_offset = end; - bool do_collect = - o->extent_map.do_write_check_depth(o->onode.size, - offset, end, &wctx.blob_depth, - &gc_start_offset, - &gc_end_offset); - if (do_collect) { - // we need garbage collection of blobs. - if (offset > gc_start_offset) { - bufferlist head_bl; - size_t read_len = offset - gc_start_offset; - int r = _do_read(c.get(), o, gc_start_offset, read_len, head_bl, 0); - assert(r == (int)read_len); - if (g_conf->bluestore_gc_merge_data) { - head_bl.claim_append(bl); - bl.swap(head_bl); - offset = gc_start_offset; - length = end - offset; - } else { - o->extent_map.fault_range(db, gc_start_offset, read_len); - _do_write_data(txc, c, o, gc_start_offset, read_len, head_bl, &wctx); - } - logger->inc(l_bluestore_gc); - logger->inc(l_bluestore_gc_bytes, read_len); - } - - if (end < gc_end_offset) { - bufferlist tail_bl; - size_t read_len = gc_end_offset - end; - int r = _do_read(c.get(), o, end, read_len, tail_bl, 0); - assert(r == (int)read_len); - if (g_conf->bluestore_gc_merge_data) { - bl.claim_append(tail_bl); - length += read_len; - end += read_len; - } else { - o->extent_map.fault_range(db, end, read_len); - _do_write_data(txc, c, o, end, read_len, tail_bl, &wctx); - } - logger->inc(l_bluestore_gc); - logger->inc(l_bluestore_gc_bytes, read_len); - } - } + _do_garbage_collection(txc, c, o, offset, length, bl, &wctx); o->extent_map.fault_range(db, offset, length); _do_write_data(txc, c, o, offset, length, bl, &wctx); diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 52f1027cfa7..c513b48ca54 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -2000,6 +2000,14 @@ private: void _pad_zeros(bufferlist *bl, uint64_t *offset, uint64_t chunk_size); + void _do_garbage_collection(TransContext *txc, + CollectionRef& c, + OnodeRef o, + uint64_t& offset, + uint64_t& length, + bufferlist& bl, + WriteContext *wctx); + int _do_write(TransContext *txc, CollectionRef &c, OnodeRef o,