]> 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>
Thu, 16 Feb 2023 12:05:05 +0000 (13:05 +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>
src/test/librbd/io/test_mock_ImageRequest.cc

index 56d011560dd37a034bc8c8bf108cca324b16b47c..546f2d04d9643cc8b11561f4aef4b66d45df8ed5 100644 (file)
@@ -125,10 +125,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) {
@@ -146,10 +142,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(_))
@@ -447,12 +439,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);
@@ -462,8 +453,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(
@@ -479,6 +470,37 @@ 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}},
+    ImageArea::DATA, 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);