Skip to content

Commit a7e314c

Browse files
committed
test/librbd: avoid caching effects TestGroup.add_snapshot{,PP}
After rollback started being tested in commit b3977c5 ("test/librbd: make rollback in TestGroup.add_snapshot{,PP} meaningful"), these tests can fail on comparing post-rollback data to expected data if run with exclusive lock disabled. This doesn't occur with exclusive lock enabled because the RBD cache gets invalidated implicitly before releasing the lock. While at it, pass LIBRADOS_OP_FLAG_FADVISE_FUA to avoid relying on any cache settings that happen to be in effect. Signed-off-by: Ilya Dryomov <[email protected]>
1 parent 4c69370 commit a7e314c

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/test/librbd/test_Groups.cc

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ TEST_F(TestGroup, add_snapshot)
275275
EXPECT_EQ(0, rbd_close(image));
276276
} BOOST_SCOPE_EXIT_END;
277277

278-
ASSERT_EQ(10, rbd_write(image, 0, 10, orig_data));
278+
ASSERT_EQ(10, rbd_write2(image, 0, 10, orig_data,
279+
LIBRADOS_OP_FLAG_FADVISE_FUA));
279280
ASSERT_EQ(10, rbd_read(image, 0, 10, read_data));
280281
ASSERT_EQ(0, memcmp(orig_data, read_data, 10));
281282

@@ -344,13 +345,17 @@ TEST_F(TestGroup, add_snapshot)
344345

345346
ASSERT_STREQ(snap_name, snaps[0].name);
346347

347-
ASSERT_EQ(10, rbd_write(image, 9, 10, test_data));
348+
ASSERT_EQ(10, rbd_write2(image, 9, 10, test_data,
349+
LIBRADOS_OP_FLAG_FADVISE_FUA));
348350
ASSERT_EQ(10, rbd_read(image, 9, 10, read_data));
349351
ASSERT_EQ(0, memcmp(test_data, read_data, 10));
350352

351353
ASSERT_EQ(10, rbd_read(image, 0, 10, read_data));
352354
ASSERT_NE(0, memcmp(orig_data, read_data, 10));
353355
ASSERT_EQ(0, rbd_group_snap_rollback(ioctx, group_name, snap_name));
356+
if (!is_feature_enabled(RBD_FEATURE_EXCLUSIVE_LOCK)) {
357+
ASSERT_EQ(0, rbd_invalidate_cache(image));
358+
}
354359
ASSERT_EQ(10, rbd_read(image, 0, 10, read_data));
355360
ASSERT_EQ(0, memcmp(orig_data, read_data, 10));
356361

@@ -421,7 +426,8 @@ TEST_F(TestGroup, add_snapshotPP)
421426
bufferlist expect_bl;
422427
bufferlist read_bl;
423428
expect_bl.append(std::string(512, '1'));
424-
ASSERT_EQ((ssize_t)expect_bl.length(), image.write(0, expect_bl.length(), expect_bl));
429+
ASSERT_EQ(512, image.write2(0, expect_bl.length(), expect_bl,
430+
LIBRADOS_OP_FLAG_FADVISE_FUA));
425431
ASSERT_EQ(512, image.read(0, 512, read_bl));
426432
ASSERT_TRUE(expect_bl.contents_equal(read_bl));
427433

@@ -436,13 +442,17 @@ TEST_F(TestGroup, add_snapshotPP)
436442

437443
bufferlist write_bl;
438444
write_bl.append(std::string(1024, '2'));
439-
ASSERT_EQ(1024, image.write(256, write_bl.length(), write_bl));
445+
ASSERT_EQ(1024, image.write2(256, write_bl.length(), write_bl,
446+
LIBRADOS_OP_FLAG_FADVISE_FUA));
440447
ASSERT_EQ(1024, image.read(256, 1024, read_bl));
441448
ASSERT_TRUE(write_bl.contents_equal(read_bl));
442449

443450
ASSERT_EQ(512, image.read(0, 512, read_bl));
444451
ASSERT_FALSE(expect_bl.contents_equal(read_bl));
445452
ASSERT_EQ(0, rbd.group_snap_rollback(ioctx, group_name, snap_name));
453+
if (!is_feature_enabled(RBD_FEATURE_EXCLUSIVE_LOCK)) {
454+
ASSERT_EQ(0, image.invalidate_cache());
455+
}
446456
ASSERT_EQ(512, image.read(0, 512, read_bl));
447457
ASSERT_TRUE(expect_bl.contents_equal(read_bl));
448458

0 commit comments

Comments
 (0)