From: Ilya Dryomov Date: Sat, 31 Aug 2024 10:00:48 +0000 (+0200) Subject: librbd: factor out prune_extents() from prune_parent_extents() X-Git-Tag: v17.2.8~80^2~2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=17d8bd55c9e542f5858fbd64ce8de99d445c0bb8;p=ceph.git librbd: factor out prune_extents() from prune_parent_extents() Signed-off-by: Ilya Dryomov (cherry picked from commit 5d64c9c5cda5c1ca44c349cfb9e4f1e9eac21bd5) Conflicts: src/librbd/ImageCtx.cc [ ImageArea support not in quincy ] --- diff --git a/src/librbd/ImageCtx.cc b/src/librbd/ImageCtx.cc index 7d41376325e6d..7a1d2a0fd14e5 100644 --- a/src/librbd/ImageCtx.cc +++ b/src/librbd/ImageCtx.cc @@ -35,6 +35,7 @@ #include "librbd/io/ObjectDispatcher.h" #include "librbd/io/QosImageDispatch.h" #include "librbd/io/IoOperations.h" +#include "librbd/io/Utils.h" #include "librbd/journal/StandardPolicy.h" #include "librbd/operation/ResizeRequest.h" @@ -692,13 +693,7 @@ librados::IoCtx duplicate_io_ctx(librados::IoCtx& io_ctx) { uint64_t ImageCtx::prune_parent_extents(vector >& objectx, uint64_t overlap) { - // drop extents completely beyond the overlap - while (!objectx.empty() && objectx.back().first >= overlap) - objectx.pop_back(); - - // trim final overlapping extent - if (!objectx.empty() && objectx.back().first + objectx.back().second > overlap) - objectx.back().second = overlap - objectx.back().first; + io::util::prune_extents(objectx, overlap); uint64_t len = 0; for (vector >::iterator p = objectx.begin(); diff --git a/src/librbd/io/Utils.cc b/src/librbd/io/Utils.cc index 2ce9dd11fc67f..0156309cd8db9 100644 --- a/src/librbd/io/Utils.cc +++ b/src/librbd/io/Utils.cc @@ -153,6 +153,21 @@ int clip_request(I *image_ctx, Extents *image_extents) { return 0; } +void prune_extents(Extents& extents, uint64_t size) { + // drop extents completely beyond size + while (!extents.empty() && extents.back().first >= size) { + extents.pop_back(); + } + + if (!extents.empty()) { + // trim final overlapping extent + auto& last_extent = extents.back(); + if (last_extent.first + last_extent.second > size) { + last_extent.second = size - last_extent.first; + } + } +} + void unsparsify(CephContext* cct, ceph::bufferlist* bl, const Extents& extent_map, uint64_t bl_off, uint64_t out_bl_len) { diff --git a/src/librbd/io/Utils.h b/src/librbd/io/Utils.h index 9f7e0b94668ba..fbe19e8e42997 100644 --- a/src/librbd/io/Utils.h +++ b/src/librbd/io/Utils.h @@ -46,6 +46,7 @@ inline uint64_t get_extents_length(const Extents &extents) { return total_bytes; } +void prune_extents(Extents& extents, uint64_t size); void unsparsify(CephContext* cct, ceph::bufferlist* bl, const Extents& extent_map, uint64_t bl_off, uint64_t out_bl_len);