From: Gabriel BenHanokh Date: Mon, 18 Oct 2021 11:38:16 +0000 (+0300) Subject: Bug-Fix: When restoring allocation from file use a temp allocator and only copy the... X-Git-Tag: v17.1.0~575^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=585d3f66367639df8287728524ddca5d369a7663;p=ceph.git Bug-Fix: When restoring allocation from file use a temp allocator and only copy the allocation to the shared-allocator after the file was verified and all extents were cleared Signed-off-by: Gabriel Benhanokh --- diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 4f59ebde508a..edd563ced55b 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -17365,7 +17365,7 @@ int calc_allocator_image_trailer_size() } //----------------------------------------------------------------------------------- -int BlueStore::restore_allocator(Allocator* allocator, uint64_t *num, uint64_t *bytes) +int BlueStore::__restore_allocator(Allocator* allocator, uint64_t *num, uint64_t *bytes) { utime_t start_time = ceph_clock_now(); BlueFS::FileReader *p_temp_handle = nullptr; @@ -17518,6 +17518,31 @@ int BlueStore::restore_allocator(Allocator* allocator, uint64_t *num, uint64_t * return 0; } +//----------------------------------------------------------------------------------- +int BlueStore::restore_allocator(Allocator* dest_allocator, uint64_t *num, uint64_t *bytes) +{ + utime_t start = ceph_clock_now(); + Allocator *temp_allocator = create_bitmap_allocator(bdev->get_size()); + if (temp_allocator == nullptr) { + derr << "****failed create_bitmap_allocator()" << dendl; + return -1; + } + + int ret = __restore_allocator(temp_allocator, num, bytes); + if (ret != 0) { + delete temp_allocator; + return ret; + } + + uint64_t num_entries = 0; + dout(5) << " calling copy_allocator(bitmap_allocator -> shared_alloc.a)" << dendl; + copy_allocator(temp_allocator, dest_allocator, &num_entries); + delete temp_allocator; + utime_t duration = ceph_clock_now() - start; + dout(5) << " <<>> in " << duration << " seconds, num_entries=" << num_entries << dendl; + return ret; +} + //------------------------------------------------------------------------- void BlueStore::ExtentMap::provide_shard_info_to_onode(bufferlist v, uint32_t shard_id) { diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 29ff87d5ff13..31e1acfa2aa0 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -3547,6 +3547,7 @@ private: int copy_allocator(Allocator* src_alloc, Allocator *dest_alloc, uint64_t* p_num_entries); int store_allocator(Allocator* allocator); int invalidate_allocation_file_on_bluefs(); + int __restore_allocator(Allocator* allocator, uint64_t *num, uint64_t *bytes); int restore_allocator(Allocator* allocator, uint64_t *num, uint64_t *bytes); int read_allocation_from_drive_on_startup(); int reconstruct_allocations(Allocator* allocator, read_alloc_stats_t &stats);