From 1f6fc570abb6e20f08aeb724e1003ea7bb36b292 Mon Sep 17 00:00:00 2001 From: Adam Kupczyk Date: Tue, 14 Nov 2023 14:10:31 +0000 Subject: [PATCH] os/bluestore: Add ExtentMap::split_at and ExtentMap::maybe_split_at Created dedicated mutator of ExtentMap that is useful when a logical extent must be split. Signed-off-by: Adam Kupczyk --- src/os/bluestore/BlueStore.cc | 36 +++++++++++++++++++++++++++++++++++ src/os/bluestore/BlueStore.h | 4 ++++ 2 files changed, 40 insertions(+) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 3bcdfa72b4c..d646cb56294 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -4299,6 +4299,42 @@ BlueStore::extent_map_t::const_iterator BlueStore::ExtentMap::seek_lextent( return fp; } +// Split extent at desired offset. +// Returns iterator to the right part. +BlueStore::extent_map_t::iterator BlueStore::ExtentMap::split_at( + BlueStore::extent_map_t::iterator p, uint32_t offset) +{ + ceph_assert(p != extent_map.end()); + ceph_assert(p->logical_offset < offset); + ceph_assert(offset < p->logical_end()); + add(offset, p->blob_offset + (offset - p->logical_offset), + p->logical_end() - offset, p->blob); + p->length = offset - p->logical_offset; + ++p; + return p; +} + +// If inside extent split it, and return right part. +// If not inside extent return extent on right. +BlueStore::extent_map_t::iterator BlueStore::ExtentMap::maybe_split_at(uint32_t offset) +{ + auto p = seek_lextent(offset); + if (p != extent_map.end()) { + if (p->logical_offset < offset && offset < p->logical_end()) { + // need to split + add(offset, p->blob_offset + (offset - p->logical_offset), + p->logical_end() - offset, p->blob); + p->length = offset - p->logical_offset; + ++p; + // check that we moved to proper extent + ceph_assert(p->logical_offset == offset); + } else { + // the extent is either outside offset or exactly at + } + } + return p; +} + bool BlueStore::ExtentMap::has_any_lextents(uint64_t offset, uint64_t length) { auto fp = seek_lextent(offset); diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 87fe96ccc98..2cb7229942d 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -1149,6 +1149,10 @@ public: extent_map_t::iterator seek_lextent(uint64_t offset); extent_map_t::const_iterator seek_lextent(uint64_t offset) const; + /// split extent + extent_map_t::iterator split_at(extent_map_t::iterator p, uint32_t offset); + /// if inside extent split it, if not return extent on right + extent_map_t::iterator maybe_split_at(uint32_t offset); /// add a new Extent void add(uint32_t lo, uint32_t o, uint32_t l, BlobRef& b) { extent_map.insert(*new Extent(lo, o, l, b)); -- 2.39.5