From: Adam Kupczyk Date: Fri, 5 Jan 2024 07:54:05 +0000 (+0000) Subject: os/bluestore: Functions to manipulate Blob X-Git-Tag: v20.0.0~1280^2~25 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=21454afa6884f644a3009df3d51d3b4b6cce396d;p=ceph.git os/bluestore: Functions to manipulate Blob Set of various simple functions to simplify code. No special logic here. Signed-off-by: Adam Kupczyk --- diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index bd6b85f0ff0ce..6eec97b133621 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -725,6 +725,7 @@ public: o.blob_bl = blob_bl; #endif } + void add_tail(uint32_t new_blob_size, uint32_t min_release_size); void dup(const Blob& from, bool copy_used_in_blob); void copy_from(CephContext* cct, const Blob& from, uint32_t min_release_size, uint32_t start, uint32_t len); diff --git a/src/os/bluestore/Writer.cc b/src/os/bluestore/Writer.cc index ffb0dca280c64..3ab3fb5311598 100644 --- a/src/os/bluestore/Writer.cc +++ b/src/os/bluestore/Writer.cc @@ -12,30 +12,10 @@ * */ +#include "Writer.h" +#include "include/intarith.h" #include "os/bluestore/bluestore_types.h" -#include "BlueStore.h" -#include "Allocator.h" -/// Signals that a range [offset~length] is no longer used. -/// Collects allocation units that became unused into *released_disk. -/// Returns: -/// disk space size to release -uint32_t BlueStore::Blob::put_ref_accumulate( - Collection *coll, - uint32_t offset, - uint32_t length, - PExtentVector *released_disk) -{ - ceph_assert(length > 0); - uint32_t res = 0; - auto [in_blob_offset, in_blob_length] = used_in_blob.put_simple(offset, length); - if (in_blob_length != 0) { - bluestore_blob_t& b = dirty_blob(); - res = b.release_extents(in_blob_offset, in_blob_length, released_disk); - return res; - } - return res; -} /// Empties range [offset~length] of object o that is in collection c. /// Collects unused elements: @@ -111,3 +91,61 @@ BlueStore::extent_map_t::iterator BlueStore::_punch_hole_2( } return p; } + + +/// Signals that a range [offset~length] is no longer used. +/// Collects allocation units that became unused into *released_disk. +/// Returns: +/// disk space size to release +uint32_t BlueStore::Blob::put_ref_accumulate( + Collection *coll, + uint32_t offset, + uint32_t length, + PExtentVector *released_disk) +{ + ceph_assert(length > 0); + uint32_t res = 0; + auto [in_blob_offset, in_blob_length] = used_in_blob.put_simple(offset, length); + if (in_blob_length != 0) { + bluestore_blob_t& b = dirty_blob(); + res = b.release_extents(in_blob_offset, in_blob_length, released_disk); + return res; + } + return res; +} + +inline void BlueStore::Blob::add_tail( + uint32_t new_blob_size, + uint32_t min_release_size) +{ + ceph_assert(p2phase(new_blob_size, min_release_size) == 0); + dirty_blob().add_tail(new_blob_size); + used_in_blob.add_tail(new_blob_size, min_release_size); +} + +inline void bluestore_blob_use_tracker_t::init_and_ref( + uint32_t full_length, + uint32_t tracked_chunk) +{ + ceph_assert(p2phase(full_length, tracked_chunk) == 0); + uint32_t _num_au = full_length / tracked_chunk; + au_size = tracked_chunk; + if ( _num_au > 1) { + allocate(_num_au); + for (uint32_t i = 0; i < num_au; i++) { + bytes_per_au[i] = tracked_chunk; + } + } else { + total_bytes = full_length; + } +} + +inline void bluestore_blob_t::allocated_full( + uint32_t length, + PExtentVector&& allocs) +{ + ceph_assert(extents.size() == 0); + extents.swap(allocs); + logical_length = length; +} + diff --git a/src/os/bluestore/bluestore_types.h b/src/os/bluestore/bluestore_types.h index 66a22689ae5dd..405b8b521f944 100644 --- a/src/os/bluestore/bluestore_types.h +++ b/src/os/bluestore/bluestore_types.h @@ -388,6 +388,10 @@ struct bluestore_blob_use_tracker_t { uint32_t full_length, uint32_t _au_size); + inline void init_and_ref( + uint32_t full_length, + uint32_t tracked_chunk); + void get( uint32_t offset, uint32_t len); @@ -741,7 +745,14 @@ public: } } } - + /// todo implement me! + unused_t get_unused_mask(uint32_t offset, uint32_t length, uint32_t chunk_size) { + if (has_unused()) { + return 0; + } else { + return 0; + } + } // map_f_invoke templates intended to mask parameters which are not expected // by the provided callback template::max(); + uint64_t get_allocation_at(uint32_t in_blob_offset) { + uint32_t loc = in_blob_offset; + for (auto e : extents) { + if (loc < e.length) { + //ceph_assert(e.is_valid()); + if (e.is_valid()) { + return e.offset + loc; + } else { + return NO_ALLOCATION; + } + } + loc -= e.length; + } + ceph_assert(false); + }; /// updates blob's pextents container and return unused pextents eligible /// for release.