From: Ilya Dryomov Date: Thu, 16 Feb 2023 11:51:04 +0000 (+0100) Subject: test/librbd: add LengthModifiedDiscardJournalAppendEnabled test X-Git-Tag: v16.2.13~133^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=99ee5a70d6086049ef644b9d37b4ba4d89030934;p=ceph.git test/librbd: add LengthModifiedDiscardJournalAppendEnabled test Currently nothing triggers the length_modified case in ImageDiscardRequest::prune_object_extents() in isolation. It's only triggered in DiscardGranularityJournalAppendEnabled test together with the prune_required case and a bad refactoring could easily break the length_modified logic again. Signed-off-by: Ilya Dryomov (cherry picked from commit 34e59c450298e1c05f07570f74a9489bd8479a44) Conflicts: src/test/librbd/io/test_mock_ImageRequest.cc [ commit b9a2384cdc43 ("librbd: propagate area down to file_to_extents()") not in pacific ] --- diff --git a/src/test/librbd/io/test_mock_ImageRequest.cc b/src/test/librbd/io/test_mock_ImageRequest.cc index 2173c3216cf9..2181ff33ca18 100644 --- a/src/test/librbd/io/test_mock_ImageRequest.cc +++ b/src/test/librbd/io/test_mock_ImageRequest.cc @@ -117,10 +117,6 @@ struct TestMockIoImageRequest : public TestMockFixture { .WillOnce(Return(journal_tid)); } - void expect_journal_append_io_event_times(MockTestJournal &mock_journal, int n) { - EXPECT_CALL(mock_journal, append_io_event_mock(_, _, _, _, _)).Times(n); - } - void expect_object_discard_request(MockTestImageCtx &mock_image_ctx, uint64_t object_no, uint64_t offset, uint32_t length, int r) { @@ -138,10 +134,6 @@ struct TestMockIoImageRequest : public TestMockFixture { })); } - void expect_object_request_send_times(MockTestImageCtx &mock_image_ctx, int n) { - EXPECT_CALL(*mock_image_ctx.io_object_dispatcher, send(_)).Times(n); - } - void expect_object_request_send(MockTestImageCtx &mock_image_ctx, int r) { EXPECT_CALL(*mock_image_ctx.io_object_dispatcher, send(_)) @@ -437,12 +429,11 @@ TEST_F(TestMockIoImageRequest, TailDiscardJournalAppendEnabled) { ASSERT_EQ(0, aio_comp_ctx.wait()); } -TEST_F(TestMockIoImageRequest, EmptyDiscardJournalAppendEnabled) { +TEST_F(TestMockIoImageRequest, PruneRequiredDiscardJournalAppendEnabled) { REQUIRE_FEATURE(RBD_FEATURE_JOURNALING); librbd::ImageCtx *ictx; ASSERT_EQ(0, open_image(m_image_name, &ictx)); - ASSERT_EQ(0, resize(ictx, ictx->layout.object_size)); ictx->discard_granularity_bytes = 32; MockTestImageCtx mock_image_ctx(*ictx); @@ -452,8 +443,8 @@ TEST_F(TestMockIoImageRequest, EmptyDiscardJournalAppendEnabled) { InSequence seq; expect_get_modify_timestamp(mock_image_ctx, false); expect_is_journal_appending(mock_journal, true); - expect_journal_append_io_event_times(mock_journal, 0); - expect_object_request_send_times(mock_image_ctx, 0); + EXPECT_CALL(mock_journal, append_io_event_mock(_, _, _, _, _)).Times(0); + EXPECT_CALL(*mock_image_ctx.io_object_dispatcher, send(_)).Times(0); C_SaferCond aio_comp_ctx; AioCompletion *aio_comp = AioCompletion::create_and_start( @@ -468,6 +459,36 @@ TEST_F(TestMockIoImageRequest, EmptyDiscardJournalAppendEnabled) { ASSERT_EQ(0, aio_comp_ctx.wait()); } +TEST_F(TestMockIoImageRequest, LengthModifiedDiscardJournalAppendEnabled) { + REQUIRE_FEATURE(RBD_FEATURE_JOURNALING); + + librbd::ImageCtx *ictx; + ASSERT_EQ(0, open_image(m_image_name, &ictx)); + ictx->discard_granularity_bytes = 32; + + MockTestImageCtx mock_image_ctx(*ictx); + MockTestJournal mock_journal; + mock_image_ctx.journal = &mock_journal; + + InSequence seq; + expect_get_modify_timestamp(mock_image_ctx, false); + expect_is_journal_appending(mock_journal, true); + expect_journal_append_io_event(mock_journal, 0, 32, 32); + expect_object_discard_request(mock_image_ctx, 0, 32, 32, 0); + + C_SaferCond aio_comp_ctx; + AioCompletion *aio_comp = AioCompletion::create_and_start( + &aio_comp_ctx, ictx, AIO_TYPE_DISCARD); + MockImageDiscardRequest mock_aio_image_discard( + mock_image_ctx, aio_comp, {{16, 63}}, ictx->discard_granularity_bytes, + mock_image_ctx.get_data_io_context(), {}); + { + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; + mock_aio_image_discard.send(); + } + ASSERT_EQ(0, aio_comp_ctx.wait()); +} + TEST_F(TestMockIoImageRequest, DiscardGranularityJournalAppendEnabled) { REQUIRE_FEATURE(RBD_FEATURE_JOURNALING);