Skip to content

Commit ed231f7

Browse files
committed
test/libcephfs: add test cases for Client::mksnap and Client::rmsnap
they exist as libceohfs APIs but aren't being called by FUSE/pybind clients, make sure they work as intended. Fixes: https://tracker.ceph.com/issues/71740 Signed-off-by: Dhairya Parmar <[email protected]>
1 parent 350c377 commit ed231f7

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed

src/test/libcephfs/vxattr.cc

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,3 +455,117 @@ TEST(LibCephFS, Removexattr) {
455455
ceph_shutdown(cmount);
456456
}
457457

458+
TEST(LibCephFS, MksnapSubvolumeSnapshotVisibility) {
459+
struct ceph_mount_info *cmount;
460+
ASSERT_EQ(0, ceph_create(&cmount, NULL));
461+
ASSERT_EQ(0, ceph_conf_read_file(cmount, NULL));
462+
ASSERT_EQ(0, ceph_conf_parse_env(cmount, NULL));
463+
ASSERT_EQ(0, ceph_mount(cmount, "/"));
464+
465+
const char* SNAPSHOT_VISIBILITY_CONFIG =
466+
"client_respect_subvolume_snapshot_visibility";
467+
const char* SNAPSHOT_VISIBILITY_VXATTR =
468+
"ceph.dir.subvolume.snaps.visible";
469+
470+
// client should respect subvolume snapshot visibility
471+
ASSERT_EQ(0, ceph_conf_set(cmount, SNAPSHOT_VISIBILITY_CONFIG, "true"));
472+
473+
const char *subvol_path = "subvol_test_mksnap";
474+
ASSERT_EQ(0, ceph_mkdir(cmount, subvol_path, 0777));
475+
476+
// set the subvolume vxattr on the subvol_path
477+
ASSERT_EQ(0, ceph_setxattr(cmount, subvol_path, "ceph.dir.subvolume",
478+
(void*)"1", 1, XATTR_CREATE));
479+
480+
// try mksnap
481+
ASSERT_EQ(0, ceph_mksnap(cmount, subvol_path, "snap1", 0777, nullptr, 0));
482+
483+
// disable snapshot visibility
484+
ASSERT_EQ(0, ceph_setxattr(cmount, subvol_path, SNAPSHOT_VISIBILITY_VXATTR,
485+
(void*)"0", 1, XATTR_CREATE));
486+
487+
// should not be able to create snap2
488+
ASSERT_EQ(-1, ceph_mksnap(cmount, subvol_path, "snap2", 0777, nullptr, 0));
489+
490+
// enable snapshot visibility
491+
ASSERT_EQ(0, ceph_setxattr(cmount, subvol_path, SNAPSHOT_VISIBILITY_VXATTR,
492+
(void*)"1", 1, XATTR_CREATE));
493+
494+
// now snap2 should get created
495+
ASSERT_EQ(0, ceph_mksnap(cmount, subvol_path, "snap2", 0777, nullptr, 0));
496+
497+
// setting to false (FYI, default config value is false)
498+
ASSERT_EQ(0, ceph_conf_set(cmount, SNAPSHOT_VISIBILITY_CONFIG, "false"));
499+
// since client doesn't respect subvolume's snapshot visibility, mksnap
500+
// should go through irrespective of ceph.dir.subvolume.snaps.visible
501+
// set to 0.
502+
ASSERT_EQ(0, ceph_setxattr(cmount, subvol_path, SNAPSHOT_VISIBILITY_VXATTR,
503+
(void*)"0", 1, XATTR_CREATE));
504+
505+
// snap3 should get created
506+
ASSERT_EQ(0, ceph_mksnap(cmount, subvol_path, "snap3", 0777, nullptr, 0));
507+
508+
// cleanup
509+
ASSERT_EQ(0, ceph_rmsnap(cmount, subvol_path, "snap1"));
510+
ASSERT_EQ(0, ceph_rmsnap(cmount, subvol_path, "snap2"));
511+
ASSERT_EQ(0, ceph_rmsnap(cmount, subvol_path, "snap3"));
512+
ASSERT_EQ(0, ceph_rmdir(cmount, subvol_path));
513+
ceph_shutdown(cmount);
514+
}
515+
516+
TEST(LibCephFS, RmsnapSubvolumeSnapshotVisibility) {
517+
struct ceph_mount_info *cmount;
518+
ASSERT_EQ(0, ceph_create(&cmount, NULL));
519+
ASSERT_EQ(0, ceph_conf_read_file(cmount, NULL));
520+
ASSERT_EQ(0, ceph_conf_parse_env(cmount, NULL));
521+
ASSERT_EQ(0, ceph_mount(cmount, "/"));
522+
523+
const char* SNAPSHOT_VISIBILITY_CONFIG =
524+
"client_respect_subvolume_snapshot_visibility";
525+
const char* SNAPSHOT_VISIBILITY_VXATTR =
526+
"ceph.dir.subvolume.snaps.visible";
527+
528+
// client should respect subvolume snapshot visibility
529+
ASSERT_EQ(0, ceph_conf_set(cmount, SNAPSHOT_VISIBILITY_CONFIG, "true"));
530+
531+
const char *subvol_path = "subvol_test_rmsnap";
532+
ASSERT_EQ(0, ceph_mkdir(cmount, subvol_path, 0777));
533+
534+
// set the subvolume vxattr on the subvol_path
535+
ASSERT_EQ(0, ceph_setxattr(cmount, subvol_path, "ceph.dir.subvolume",
536+
(void*)"1", 1, XATTR_CREATE));
537+
538+
ASSERT_EQ(0, ceph_mksnap(cmount, subvol_path, "snap1", 0777, nullptr, 0));
539+
ASSERT_EQ(0, ceph_mksnap(cmount, subvol_path, "snap2", 0777, nullptr, 0));
540+
ASSERT_EQ(0, ceph_mksnap(cmount, subvol_path, "snap3", 0777, nullptr, 0));
541+
542+
// disable snapshot visibility
543+
ASSERT_EQ(0, ceph_setxattr(cmount, subvol_path, SNAPSHOT_VISIBILITY_VXATTR,
544+
(void*)"0", 1, XATTR_CREATE));
545+
546+
// should not be able to remove snaps
547+
ASSERT_EQ(-1, ceph_rmsnap(cmount, subvol_path, "snap1"));
548+
ASSERT_EQ(-1, ceph_rmsnap(cmount, subvol_path, "snap2"));
549+
550+
// enable snapshot visibility
551+
ASSERT_EQ(0, ceph_setxattr(cmount, subvol_path, SNAPSHOT_VISIBILITY_VXATTR,
552+
(void*)"1", 1, XATTR_CREATE));
553+
554+
// should be able to remove snaps
555+
ASSERT_EQ(0, ceph_rmsnap(cmount, subvol_path, "snap1"));
556+
ASSERT_EQ(0, ceph_rmsnap(cmount, subvol_path, "snap2"));
557+
558+
// setting to false (FYI, default config value is false)
559+
ASSERT_EQ(0, ceph_conf_set(cmount, SNAPSHOT_VISIBILITY_CONFIG, "false"));
560+
// since client doesn't respect subvolume's snapshot visibility, rmsnap
561+
// should go through irrespective of ceph.dir.subvolume.snaps.visible
562+
// set to 0.
563+
ASSERT_EQ(0, ceph_setxattr(cmount, subvol_path, SNAPSHOT_VISIBILITY_VXATTR,
564+
(void*)"0", 1, XATTR_CREATE));
565+
// rmsnap should go through
566+
ASSERT_EQ(0, ceph_rmsnap(cmount, subvol_path, "snap3"));
567+
568+
// cleanup
569+
ASSERT_EQ(0, ceph_rmdir(cmount, subvol_path));
570+
ceph_shutdown(cmount);
571+
}

0 commit comments

Comments
 (0)