]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test/librbd: add LengthModifiedDiscardJournalAppendEnabled test
authorIlya Dryomov <idryomov@gmail.com>
Thu, 16 Feb 2023 11:51:04 +0000 (12:51 +0100)
committerIlya Dryomov <idryomov@gmail.com>
Fri, 3 Mar 2023 18:12:11 +0000 (19:12 +0100)
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 <idryomov@gmail.com>
(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 quincy ]

src/test/librbd/io/test_mock_ImageRequest.cc

index ded809cd3fc50e46aa3c998b2a94f1fc82efb49a..190aec028ff0920173b7f73c5a5a9bc120718fbb 100644 (file)
@@ -121,10 +121,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) {
@@ -142,10 +138,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(_))
@@ -441,12 +433,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);
@@ -456,8 +447,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(
@@ -472,6 +463,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);