Skip to content

Commit f716860

Browse files
authored
Merge pull request ceph#59551 from idryomov/wip-67845
librbd/migration: prune snapshot extents in RawFormat::list_snaps() Reviewed-by: Ramana Raja <[email protected]>
2 parents 5ddf773 + 8e58a52 commit f716860

File tree

8 files changed

+26
-18
lines changed

8 files changed

+26
-18
lines changed

qa/workunits/rbd/cli_migration.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ expect_false() {
2727
create_base_image() {
2828
local image=$1
2929

30-
rbd create --size 1G ${image}
30+
# size is not a multiple of object size to trigger an edge case in
31+
# list-snaps
32+
rbd create --size 1025M ${image}
33+
3134
rbd bench --io-type write --io-pattern rand --io-size=4K --io-total 256M ${image}
3235
rbd snap create ${image}@1
3336
rbd bench --io-type write --io-pattern rand --io-size=4K --io-total 64M ${image}

src/librbd/ImageCtx.cc

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -736,18 +736,7 @@ librados::IoCtx duplicate_io_ctx(librados::IoCtx& io_ctx) {
736736

737737
auto overlap = reduce_parent_overlap(raw_overlap, migration_write);
738738
if (area == overlap.second) {
739-
// drop extents completely beyond the overlap
740-
while (!image_extents.empty() &&
741-
image_extents.back().first >= overlap.first) {
742-
image_extents.pop_back();
743-
}
744-
if (!image_extents.empty()) {
745-
// trim final overlapping extent
746-
auto& last_extent = image_extents.back();
747-
if (last_extent.first + last_extent.second > overlap.first) {
748-
last_extent.second = overlap.first - last_extent.first;
749-
}
750-
}
739+
io::util::prune_extents(image_extents, overlap.first);
751740
} else if (area == io::ImageArea::DATA &&
752741
overlap.second == io::ImageArea::CRYPTO_HEADER) {
753742
// all extents completely beyond the overlap

src/librbd/io/Utils.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,21 @@ int clip_request(I* image_ctx, Extents* image_extents, ImageArea area) {
155155
return 0;
156156
}
157157

158+
void prune_extents(Extents& extents, uint64_t size) {
159+
// drop extents completely beyond size
160+
while (!extents.empty() && extents.back().first >= size) {
161+
extents.pop_back();
162+
}
163+
164+
if (!extents.empty()) {
165+
// trim final overlapping extent
166+
auto& last_extent = extents.back();
167+
if (last_extent.first + last_extent.second > size) {
168+
last_extent.second = size - last_extent.first;
169+
}
170+
}
171+
}
172+
158173
void unsparsify(CephContext* cct, ceph::bufferlist* bl,
159174
const Extents& extent_map, uint64_t bl_off,
160175
uint64_t out_bl_len) {

src/librbd/io/Utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ inline uint64_t get_extents_length(const Extents &extents) {
4646
return total_bytes;
4747
}
4848

49+
void prune_extents(Extents& extents, uint64_t size);
4950
void unsparsify(CephContext* cct, ceph::bufferlist* bl,
5051
const Extents& extent_map, uint64_t bl_off,
5152
uint64_t out_bl_len);

src/librbd/migration/NativeFormat.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "common/errno.h"
99
#include "include/scope_guard.h"
1010
#include "librbd/ImageCtx.h"
11-
#include "librbd/ImageState.h"
1211
#include "json_spirit/json_spirit.h"
1312
#include "boost/lexical_cast.hpp"
1413

src/librbd/migration/QCOWFormat.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "include/intarith.h"
99
#include "librbd/AsioEngine.h"
1010
#include "librbd/ImageCtx.h"
11-
#include "librbd/ImageState.h"
1211
#include "librbd/Utils.h"
1312
#include "librbd/io/AioCompletion.h"
1413
#include "librbd/io/ReadResult.h"

src/librbd/migration/RawFormat.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
#include "common/dout.h"
66
#include "common/errno.h"
77
#include "librbd/ImageCtx.h"
8-
#include "librbd/ImageState.h"
98
#include "librbd/Utils.h"
109
#include "librbd/io/AioCompletion.h"
1110
#include "librbd/io/ReadResult.h"
11+
#include "librbd/io/Utils.h"
1212
#include "librbd/migration/SnapshotInterface.h"
1313
#include "librbd/migration/SourceSpecBuilder.h"
1414
#include "librbd/migration/Utils.h"
@@ -209,7 +209,9 @@ void RawFormat<I>::list_snaps(io::Extents&& image_extents,
209209
&previous_size, &sparse_extents);
210210

211211
// build set of data/zeroed extents for the current snapshot
212-
snapshot->list_snap(io::Extents{image_extents}, list_snaps_flags,
212+
auto snapshot_extents = image_extents;
213+
io::util::prune_extents(snapshot_extents, snap_info.size);
214+
snapshot->list_snap(std::move(snapshot_extents), list_snaps_flags,
213215
&sparse_extents, parent_trace, gather_ctx->new_sub());
214216
}
215217

src/test/librbd/migration/test_mock_RawFormat.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ TEST_F(TestMockMigrationRawFormat, ListSnapsMerge) {
466466
expect_snapshot_get_info(*mock_snapshot_interface_2, snap_info_2);
467467
io::SparseExtents sparse_extents_2;
468468
sparse_extents_2.insert(0, 32, {io::SPARSE_EXTENT_STATE_DATA, 32});
469-
expect_snapshot_list_snap(*mock_snapshot_interface_2, {{0, 123}},
469+
expect_snapshot_list_snap(*mock_snapshot_interface_2, {{0, 64}},
470470
sparse_extents_2, 0);
471471

472472
expect_snapshot_get_info(*mock_snapshot_interface_head, snap_info_head);

0 commit comments

Comments
 (0)