From: Jason Dillaman Date: Wed, 30 Sep 2020 01:24:23 +0000 (-0400) Subject: librbd: rename SnapshotExtent to SparseExtent X-Git-Tag: v16.1.0~833^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3a3dec2596d31eb9951aae03bb7a8feca37ad0c3;p=ceph.git librbd: rename SnapshotExtent to SparseExtent The processing of copyup needs to be able to denote data extents that are potentially zeroed or included in the associated bufferlist. By renaming the type, it can be re-used for this second purpose. Signed-off-by: Jason Dillaman --- diff --git a/src/librbd/api/DiffIterate.cc b/src/librbd/api/DiffIterate.cc index 30c7a6ce30ce..b2ed9a82420a 100644 --- a/src/librbd/api/DiffIterate.cc +++ b/src/librbd/api/DiffIterate.cc @@ -122,15 +122,14 @@ private: CephContext *cct = m_cct; // merge per-snapshot deltas into an aggregate - interval_map - aggregate_snapshot_extents; + io::SparseExtents aggregate_snapshot_extents; for (auto& [key, snapshot_extents] : m_snapshot_delta) { for (auto& snapshot_extent : snapshot_extents) { auto state = snapshot_extent.get_val().state; // ignore DNE object (and parent) if (key == io::WriteReadSnapIds{0, 0} && - state != io::SNAPSHOT_EXTENT_STATE_DATA) { + state != io::SPARSE_EXTENT_STATE_DATA) { continue; } @@ -147,7 +146,7 @@ private: << "state=" << snapshot_extent.get_val().state << dendl; diffs->emplace_back( snapshot_extent.get_off(), snapshot_extent.get_len(), - snapshot_extent.get_val().state == io::SNAPSHOT_EXTENT_STATE_DATA); + snapshot_extent.get_val().state == io::SPARSE_EXTENT_STATE_DATA); } } }; diff --git a/src/librbd/deep_copy/ObjectCopyRequest.cc b/src/librbd/deep_copy/ObjectCopyRequest.cc index e423ccab1bac..f7f837a1d9a9 100644 --- a/src/librbd/deep_copy/ObjectCopyRequest.cc +++ b/src/librbd/deep_copy/ObjectCopyRequest.cc @@ -444,7 +444,7 @@ void ObjectCopyRequest::compute_read_ops() { for (auto& image_interval : image_intervals) { auto state = image_interval.get_val().state; switch (state) { - case io::SNAPSHOT_EXTENT_STATE_DNE: + case io::SPARSE_EXTENT_STATE_DNE: ceph_assert(write_read_snap_ids == io::INITIAL_WRITE_READ_SNAP_IDS); if (read_from_parent) { // special-case for DNE object-extents since when flattening we need @@ -456,10 +456,10 @@ void ObjectCopyRequest::compute_read_ops() { image_interval.get_off(), image_interval.get_len()); } break; - case io::SNAPSHOT_EXTENT_STATE_ZEROED: + case io::SPARSE_EXTENT_STATE_ZEROED: only_dne_extents = false; break; - case io::SNAPSHOT_EXTENT_STATE_DATA: + case io::SPARSE_EXTENT_STATE_DATA: ldout(m_cct, 20) << "read op: " << "snap_ids=" << write_read_snap_ids << " " << image_interval.get_off() << "~" @@ -582,7 +582,7 @@ void ObjectCopyRequest::compute_zero_ops() { for (auto& image_interval : image_intervals) { auto state = image_interval.get_val().state; switch (state) { - case io::SNAPSHOT_EXTENT_STATE_ZEROED: + case io::SPARSE_EXTENT_STATE_ZEROED: if (write_read_snap_ids != io::WriteReadSnapIds{0, 0}) { ldout(m_cct, 20) << "zeroed extent: " << "src_snap_seq=" << src_snap_seq << " " @@ -600,8 +600,8 @@ void ObjectCopyRequest::compute_zero_ops() { image_interval.get_off(), image_interval.get_len()); } break; - case io::SNAPSHOT_EXTENT_STATE_DNE: - case io::SNAPSHOT_EXTENT_STATE_DATA: + case io::SPARSE_EXTENT_STATE_DNE: + case io::SPARSE_EXTENT_STATE_DATA: break; default: ceph_abort(); diff --git a/src/librbd/io/ImageRequest.cc b/src/librbd/io/ImageRequest.cc index 6953d21fad0d..5f5ea4471ecb 100644 --- a/src/librbd/io/ImageRequest.cc +++ b/src/librbd/io/ImageRequest.cc @@ -99,11 +99,11 @@ struct C_AssembleSnapshotDeltas : public C_AioRequest { auto& intervals = (*image_snapshot_delta)[key]; auto& assembled_intervals = (*assembled_image_snapshot_delta)[key]; for (auto [image_offset, image_length] : image_extents) { - SnapshotExtent snapshot_extent{object_extent.get_val().state, - image_length}; - intervals.insert(image_offset, image_length, snapshot_extent); + SparseExtent sparse_extent{object_extent.get_val().state, + image_length}; + intervals.insert(image_offset, image_length, sparse_extent); assembled_intervals.insert(image_offset, image_length, - snapshot_extent); + sparse_extent); } } } diff --git a/src/librbd/io/ObjectRequest.cc b/src/librbd/io/ObjectRequest.cc index 27223221faea..0964bec99127 100644 --- a/src/librbd/io/ObjectRequest.cc +++ b/src/librbd/io/ObjectRequest.cc @@ -883,7 +883,7 @@ void ObjectListSnapsRequest::handle_list_snaps(int r) { for (auto& interval : diff_interval) { snapshot_delta[{end_snap_id, clone_end_snap_id}].insert( interval.first, interval.second, - SnapshotExtent(SNAPSHOT_EXTENT_STATE_DATA, interval.second)); + SparseExtent(SPARSE_EXTENT_STATE_DATA, interval.second)); if (maybe_whiteout_detected) { initial_written_extents.union_insert(interval.first, interval.second); @@ -903,7 +903,7 @@ void ObjectListSnapsRequest::handle_list_snaps(int r) { for (auto& interval : zero_interval) { snapshot_delta[{end_snap_id, end_snap_id}].insert( interval.first, interval.second, - SnapshotExtent(SNAPSHOT_EXTENT_STATE_ZEROED, interval.second)); + SparseExtent(SPARSE_EXTENT_STATE_ZEROED, interval.second)); if (maybe_whiteout_detected) { initial_written_extents.union_insert(interval.first, interval.second); @@ -1057,8 +1057,8 @@ void ObjectListSnapsRequest::zero_initial_extent( << dendl; (*m_snapshot_delta)[INITIAL_WRITE_READ_SNAP_IDS].insert( offset, length, - SnapshotExtent( - (dne ? SNAPSHOT_EXTENT_STATE_DNE : SNAPSHOT_EXTENT_STATE_ZEROED), + SparseExtent( + (dne ? SPARSE_EXTENT_STATE_DNE : SPARSE_EXTENT_STATE_ZEROED), length)); } } diff --git a/src/librbd/io/Types.cc b/src/librbd/io/Types.cc index 128d725ade33..223c7728320f 100644 --- a/src/librbd/io/Types.cc +++ b/src/librbd/io/Types.cc @@ -9,12 +9,15 @@ namespace io { const WriteReadSnapIds INITIAL_WRITE_READ_SNAP_IDS{0, 0}; -std::ostream& operator<<(std::ostream& os, SnapshotExtentState state) { +std::ostream& operator<<(std::ostream& os, SparseExtentState state) { switch (state) { - case SNAPSHOT_EXTENT_STATE_ZEROED: + case SPARSE_EXTENT_STATE_DNE: + os << "dne"; + break; + case SPARSE_EXTENT_STATE_ZEROED: os << "zeroed"; break; - case SNAPSHOT_EXTENT_STATE_DATA: + case SPARSE_EXTENT_STATE_DATA: os << "data"; break; default: @@ -24,7 +27,7 @@ std::ostream& operator<<(std::ostream& os, SnapshotExtentState state) { return os; } -std::ostream& operator<<(std::ostream& os, const SnapshotExtent& se) { +std::ostream& operator<<(std::ostream& os, const SparseExtent& se) { os << "[" << "state=" << se.state << ", " << "length=" << se.length << "]"; diff --git a/src/librbd/io/Types.h b/src/librbd/io/Types.h index 9d473fd41315..b4e9f14d1e33 100644 --- a/src/librbd/io/Types.h +++ b/src/librbd/io/Types.h @@ -131,64 +131,63 @@ enum { LIST_SNAPS_FLAG_IGNORE_ZEROED_EXTENTS = 1UL << 2, }; -enum SnapshotExtentState { - SNAPSHOT_EXTENT_STATE_DNE, /* does not exist */ - SNAPSHOT_EXTENT_STATE_ZEROED, - SNAPSHOT_EXTENT_STATE_DATA +enum SparseExtentState { + SPARSE_EXTENT_STATE_DNE, /* does not exist */ + SPARSE_EXTENT_STATE_ZEROED, + SPARSE_EXTENT_STATE_DATA }; -std::ostream& operator<<(std::ostream& os, SnapshotExtentState state); +std::ostream& operator<<(std::ostream& os, SparseExtentState state); -struct SnapshotExtent { - SnapshotExtentState state; +struct SparseExtent { + SparseExtentState state; size_t length; - SnapshotExtent(SnapshotExtentState state, size_t length) + SparseExtent(SparseExtentState state, size_t length) : state(state), length(length) { } - operator SnapshotExtentState() const { + operator SparseExtentState() const { return state; } - bool operator==(const SnapshotExtent& rhs) const { + bool operator==(const SparseExtent& rhs) const { return state == rhs.state && length == rhs.length; } }; -std::ostream& operator<<(std::ostream& os, const SnapshotExtent& state); +std::ostream& operator<<(std::ostream& os, const SparseExtent& state); -struct SnapshotExtentSplitMerge { - SnapshotExtent split(uint64_t offset, uint64_t length, - SnapshotExtent &se) const { - return SnapshotExtent(se.state, se.length); +struct SparseExtentSplitMerge { + SparseExtent split(uint64_t offset, uint64_t length, SparseExtent &se) const { + return SparseExtent(se.state, se.length); } - bool can_merge(const SnapshotExtent& left, - const SnapshotExtent& right) const { + bool can_merge(const SparseExtent& left, const SparseExtent& right) const { return left.state == right.state; } - SnapshotExtent merge(SnapshotExtent&& left, SnapshotExtent&& right) const { - SnapshotExtent se(left); + SparseExtent merge(SparseExtent&& left, SparseExtent&& right) const { + SparseExtent se(left); se.length += right.length; return se; } - uint64_t length(const SnapshotExtent& se) const { + uint64_t length(const SparseExtent& se) const { return se.length; } }; +typedef interval_map SparseExtents; + typedef std::vector SnapIds; typedef std::pair WriteReadSnapIds; extern const WriteReadSnapIds INITIAL_WRITE_READ_SNAP_IDS; -typedef std::map> SnapshotDelta; +typedef std::map SnapshotDelta; using striper::LightweightBufferExtents; using striper::LightweightObjectExtent; diff --git a/src/test/librbd/io/test_mock_ImageRequest.cc b/src/test/librbd/io/test_mock_ImageRequest.cc index e39409e68a80..c17e55ca45f7 100644 --- a/src/test/librbd/io/test_mock_ImageRequest.cc +++ b/src/test/librbd/io/test_mock_ImageRequest.cc @@ -502,15 +502,15 @@ TEST_F(TestMockIoImageRequest, ListSnaps) { SnapshotDelta object_snapshot_delta; object_snapshot_delta[{5,6}].insert( - 0, 1024, {SNAPSHOT_EXTENT_STATE_DATA, 1024}); + 0, 1024, {SPARSE_EXTENT_STATE_DATA, 1024}); object_snapshot_delta[{5,5}].insert( - 4096, 4096, {SNAPSHOT_EXTENT_STATE_ZEROED, 4096}); + 4096, 4096, {SPARSE_EXTENT_STATE_ZEROED, 4096}); expect_object_list_snaps_request(mock_image_ctx, 0, object_snapshot_delta, 0); object_snapshot_delta = {}; object_snapshot_delta[{5,6}].insert( - 1024, 3072, {SNAPSHOT_EXTENT_STATE_DATA, 3072}); + 1024, 3072, {SPARSE_EXTENT_STATE_DATA, 3072}); object_snapshot_delta[{5,5}].insert( - 2048, 2048, {SNAPSHOT_EXTENT_STATE_ZEROED, 2048}); + 2048, 2048, {SPARSE_EXTENT_STATE_ZEROED, 2048}); expect_object_list_snaps_request(mock_image_ctx, 1, object_snapshot_delta, 0); SnapshotDelta snapshot_delta; @@ -528,11 +528,11 @@ TEST_F(TestMockIoImageRequest, ListSnaps) { SnapshotDelta expected_snapshot_delta; expected_snapshot_delta[{5,6}].insert( - 0, 1024, {SNAPSHOT_EXTENT_STATE_DATA, 1024}); + 0, 1024, {SPARSE_EXTENT_STATE_DATA, 1024}); expected_snapshot_delta[{5,6}].insert( - 5120, 3072, {SNAPSHOT_EXTENT_STATE_DATA, 3072}); + 5120, 3072, {SPARSE_EXTENT_STATE_DATA, 3072}); expected_snapshot_delta[{5,5}].insert( - 6144, 6144, {SNAPSHOT_EXTENT_STATE_ZEROED, 6144}); + 6144, 6144, {SPARSE_EXTENT_STATE_ZEROED, 6144}); ASSERT_EQ(expected_snapshot_delta, snapshot_delta); } diff --git a/src/test/librbd/io/test_mock_ObjectRequest.cc b/src/test/librbd/io/test_mock_ObjectRequest.cc index c19d3a62dc86..559de694e5eb 100644 --- a/src/test/librbd/io/test_mock_ObjectRequest.cc +++ b/src/test/librbd/io/test_mock_ObjectRequest.cc @@ -1745,19 +1745,19 @@ TEST_F(TestMockIoObjectRequest, ListSnaps) { SnapshotDelta expected_snapshot_delta; expected_snapshot_delta[{5,6}].insert( - 440320, 1024, {SNAPSHOT_EXTENT_STATE_DATA, 1024}); + 440320, 1024, {SPARSE_EXTENT_STATE_DATA, 1024}); expected_snapshot_delta[{5,6}].insert( - 2122728, 1024, {SNAPSHOT_EXTENT_STATE_DATA, 1024}); + 2122728, 1024, {SPARSE_EXTENT_STATE_DATA, 1024}); expected_snapshot_delta[{5,6}].insert( - 2220032, 2048, {SNAPSHOT_EXTENT_STATE_DATA, 2048}); + 2220032, 2048, {SPARSE_EXTENT_STATE_DATA, 2048}); expected_snapshot_delta[{7,CEPH_NOSNAP}].insert( - 2122728, 1024, {SNAPSHOT_EXTENT_STATE_DATA, 1024}); + 2122728, 1024, {SPARSE_EXTENT_STATE_DATA, 1024}); expected_snapshot_delta[{7,CEPH_NOSNAP}].insert( - 2221056, 1024, {SNAPSHOT_EXTENT_STATE_DATA, 1024}); + 2221056, 1024, {SPARSE_EXTENT_STATE_DATA, 1024}); expected_snapshot_delta[{7,CEPH_NOSNAP}].insert( - 3072000, 4096, {SNAPSHOT_EXTENT_STATE_DATA, 4096}); + 3072000, 4096, {SPARSE_EXTENT_STATE_DATA, 4096}); expected_snapshot_delta[{5,5}].insert( - 3072000, 4096, {SNAPSHOT_EXTENT_STATE_ZEROED, 4096}); + 3072000, 4096, {SPARSE_EXTENT_STATE_ZEROED, 4096}); ASSERT_EQ(expected_snapshot_delta, snapshot_delta); } @@ -1780,7 +1780,7 @@ TEST_F(TestMockIoObjectRequest, ListSnapsDNE) { SnapshotDelta expected_snapshot_delta; expected_snapshot_delta[{0,0}].insert( - 440320, 1024, {SNAPSHOT_EXTENT_STATE_DNE, 1024}); + 440320, 1024, {SPARSE_EXTENT_STATE_DNE, 1024}); ASSERT_EQ(expected_snapshot_delta, snapshot_delta); } @@ -1803,7 +1803,7 @@ TEST_F(TestMockIoObjectRequest, ListSnapsEmpty) { SnapshotDelta expected_snapshot_delta; expected_snapshot_delta[{0,0}].insert( - 440320, 1024, {SNAPSHOT_EXTENT_STATE_ZEROED, 1024}); + 440320, 1024, {SPARSE_EXTENT_STATE_ZEROED, 1024}); ASSERT_EQ(expected_snapshot_delta, snapshot_delta); } @@ -1842,7 +1842,7 @@ TEST_F(TestMockIoObjectRequest, ListSnapsParent) { MockImageListSnapsRequest mock_image_list_snaps_request; SnapshotDelta image_snapshot_delta; image_snapshot_delta[{1,6}].insert( - 0, 1024, {SNAPSHOT_EXTENT_STATE_DATA, 1024}); + 0, 1024, {SPARSE_EXTENT_STATE_DATA, 1024}); expect_image_list_snaps(mock_image_list_snaps_request, {{0, 4096}}, image_snapshot_delta, 0); @@ -1857,7 +1857,7 @@ TEST_F(TestMockIoObjectRequest, ListSnapsParent) { SnapshotDelta expected_snapshot_delta; expected_snapshot_delta[{0,0}].insert( - 0, 1024, {SNAPSHOT_EXTENT_STATE_DATA, 1024}); + 0, 1024, {SPARSE_EXTENT_STATE_DATA, 1024}); ASSERT_EQ(expected_snapshot_delta, snapshot_delta); } @@ -1899,7 +1899,7 @@ TEST_F(TestMockIoObjectRequest, ListSnapsWholeObject) { SnapshotDelta expected_snapshot_delta; expected_snapshot_delta[{CEPH_NOSNAP,CEPH_NOSNAP}].insert( 0, mock_image_ctx.layout.object_size - 1, - {SNAPSHOT_EXTENT_STATE_DATA, mock_image_ctx.layout.object_size - 1}); + {SPARSE_EXTENT_STATE_DATA, mock_image_ctx.layout.object_size - 1}); ASSERT_EQ(expected_snapshot_delta, snapshot_delta); }