From 1c5fd0fc47a0fb65eeddd29f3fc21530e855a379 Mon Sep 17 00:00:00 2001 From: Adam Kupczyk Date: Tue, 9 Jul 2024 18:48:19 +0000 Subject: [PATCH] os/bluestore: Fix after rebase BufferSpace is not with Onode, not Blob. Modify code to adapt to this change. Signed-off-by: Adam Kupczyk --- src/os/bluestore/Writer.cc | 31 +++++++------------- src/test/objectstore/test_bluestore_types.cc | 14 ++++----- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/src/os/bluestore/Writer.cc b/src/os/bluestore/Writer.cc index bc22b1a58ab8b..f31b147dff039 100644 --- a/src/os/bluestore/Writer.cc +++ b/src/os/bluestore/Writer.cc @@ -393,8 +393,6 @@ inline void BlueStore::Writer::_blob_put_data_allocate( _get_disk_space(in_blob_end - in_blob_offset, blob_allocs); bblob.allocated(in_blob_offset, in_blob_end - in_blob_offset, blob_allocs); _schedule_io(blob_allocs, 0, disk_data); - bstore->_buffer_cache_write(txc, blob, in_blob_offset, disk_data, - wctx->buffered ? 0 : Buffer::FLAG_NOCACHE); dout(25) << __func__ << " 0x" << std::hex << disk_data.length() << "@" << in_blob_offset << std::dec << " -> " @@ -434,8 +432,6 @@ inline void BlueStore::Writer::_blob_put_data_subau_allocate( _get_disk_space(in_blob_alloc_end - in_blob_alloc_offset, blob_allocs); bblob.allocated(in_blob_alloc_offset, in_blob_alloc_end - in_blob_alloc_offset, blob_allocs); _schedule_io(blob_allocs, in_blob_offset - in_blob_alloc_offset, disk_data); - bstore->_buffer_cache_write(txc, blob, in_blob_offset, disk_data, - wctx->buffered ? 0 : Buffer::FLAG_NOCACHE); dout(25) << __func__ << " 0x" << std::hex << disk_data.length() << "@" << in_blob_offset << std::dec << " -> " << blob->print(pp_mode) << " no ref yet" << dendl; @@ -481,8 +477,6 @@ BlueStore::BlobRef BlueStore::Writer::_blob_create_with_data( << " alloc_offset=" << alloc_offset << " -> " << blob->print(pp_mode) << dendl; _schedule_io(blob_allocs, in_blob_offset - alloc_offset, disk_data); - bstore->_buffer_cache_write(txc, blob, in_blob_offset, disk_data, - wctx->buffered ? 0 : Buffer::FLAG_NOCACHE); return blob; } @@ -517,8 +511,6 @@ BlueStore::BlobRef BlueStore::Writer::_blob_create_full( _schedule_io(blob_allocs, 0, disk_data); //have to do before move() bblob.allocated_full(blob_length, std::move(blob_allocs)); bblob.mark_used(0, blob_length); //todo - optimize; this obviously clears it - bstore->_buffer_cache_write(txc, blob, 0, disk_data, - wctx->buffered ? 0 : Buffer::FLAG_NOCACHE); return blob; } @@ -770,8 +762,6 @@ void BlueStore::Writer::_try_reuse_allocated_l( emap.extent_map.insert(*le); logical_offset += data_size; - bstore->_buffer_cache_write(txc, b, in_blob_offset, data_at_left, - wctx->buffered ? 0 : Buffer::FLAG_NOCACHE); break; } } @@ -845,8 +835,6 @@ void BlueStore::Writer::_try_reuse_allocated_r( emap.extent_map.insert(*le); end_offset -= data_size; - bstore->_buffer_cache_write(txc, b, in_blob_offset, data_at_right, - wctx->buffered ? 0 : Buffer::FLAG_NOCACHE); break; } } @@ -1329,6 +1317,15 @@ void BlueStore::Writer::do_write( released, pruned_blobs, shared_changed, statfs_delta); dout(25) << "after punch_hole_2: " << std::endl << onode->print(pp_mode) << dendl; + // todo: if we align to disk block before splitting, we could do it in one go + uint32_t pos = location; + for (auto& b : bd) { + bstore->_buffer_cache_write(this->txc, onode, pos, b.disk_data, + wctx->buffered ? 0 : Buffer::FLAG_NOCACHE); + pos += b.disk_data.length(); + } + ceph_assert(pos == data_end); + uint32_t au_size = bstore->min_alloc_size; if (au_size != bstore->block_size) { _try_put_data_on_allocated(location, data_end, ref_end, bd, after_punch_it); @@ -1388,13 +1385,7 @@ void BlueStore::Writer::_collect_released_allocated() void BlueStore::Writer::debug_iterate_buffers( std::function data_callback) { - for (auto& e : onode->extent_map.extent_map) { - auto b = e.blob->dirty_bc()._data_lower_bound(e.blob_offset); - uint32_t in_blob_offset = e.blob_offset; - ceph_assert(b->second.offset <= in_blob_offset); - ceph_assert(in_blob_offset + e.length <= b->second.offset + b->second.data.length()); - bufferlist data; - data.substr_of(b->second.data, in_blob_offset - b->second.offset, e.length); - data_callback(e.logical_offset, data); + for (const auto& b : onode->bc.buffer_map) { + data_callback(b.offset, b.data); } } diff --git a/src/test/objectstore/test_bluestore_types.cc b/src/test/objectstore/test_bluestore_types.cc index 4f1a37f926830..b9e68f852b6d0 100644 --- a/src/test/objectstore/test_bluestore_types.cc +++ b/src/test/objectstore/test_bluestore_types.cc @@ -1253,7 +1253,7 @@ public: au_size = _au_size; store = new BlueStore(g_ceph_context, "", au_size); oc = BlueStore::OnodeCacheShard::create(g_ceph_context, "lru", NULL); - bc = BlueStore::BufferCacheShard::create(g_ceph_context, "lru", NULL); + bc = BlueStore::BufferCacheShard::create(store, "lru", NULL); coll = ceph::make_ref(store, oc, bc, coll_t()); } void SetUp() override { @@ -1446,7 +1446,7 @@ class PunchHoleFixture : public BlueStoreFixture PExtentVector d_c = allocate_continue(al_end - al_hole_end); bool blob_remains = al_start != al_hole_begin || al_hole_end != al_end; - BlueStore::BlobRef b(new BlueStore::Blob); + BlueStore::BlobRef b(coll->new_blob()); coll->open_shared_blob(0, b); blobs_created.insert(b); if (!blob_remains) { @@ -1488,7 +1488,7 @@ class PunchHoleFixture : public BlueStoreFixture y = hole_range; } coll->make_blob_shared(rand(), b); - BlueStore::BlobRef cb = new BlueStore::Blob(); + BlueStore::BlobRef cb = coll->new_blob(); b->dup(*cb); ceph_assert(d_b.size() == 1); ceph_assert(d_b[0].length == hole_range); @@ -1501,7 +1501,7 @@ class PunchHoleFixture : public BlueStoreFixture } append(disk_to_free, d_b_non_shared); if (x < y) { - cb->shared_blob->get_ref(d_b[0].offset + x, y - x); + cb->get_dirty_shared_blob()->get_ref(d_b[0].offset + x, y - x); statfs_to_free.allocated() += y - x; } } else { @@ -1521,7 +1521,7 @@ class PunchHoleFixture : public BlueStoreFixture will_punch.offset + will_punch.length < blob_like.offset + blob_like.length; PExtentVector disk = allocate(al_size); - BlueStore::BlobRef b(new BlueStore::Blob); + BlueStore::BlobRef b(coll->new_blob()); coll->open_shared_blob(0, b); blobs_created.insert(b); if (!blob_remains) { @@ -1550,12 +1550,12 @@ class PunchHoleFixture : public BlueStoreFixture if (do_shared) { create_additional_ref = rand() % 2 == 0; coll->make_blob_shared(rand(), b); - BlueStore::BlobRef cb = new BlueStore::Blob(); + BlueStore::BlobRef cb = coll->new_blob(); b->dup(*cb); ceph_assert(disk.size() == 1); ceph_assert(disk[0].length == al_size); if (create_additional_ref) { - cb->shared_blob->get_ref(disk[0].offset, al_size); + cb->get_dirty_shared_blob()->get_ref(disk[0].offset, al_size); } } statfs_to_free.stored() -= will_punch.length; -- 2.39.5