From: Dhairya Parmar Date: Wed, 3 Sep 2025 11:40:34 +0000 (+0530) Subject: test/libcephfs: add test cases for Client::mksnap and Client::rmsnap X-Git-Tag: testing/wip-vshankar-testing-20250926.115258-debug^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=91319f4e7964403600e9656b00cb5007d110acda;p=ceph-ci.git 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 --- diff --git a/src/test/libcephfs/vxattr.cc b/src/test/libcephfs/vxattr.cc index b9cc2e2e247..7322446a7a7 100644 --- a/src/test/libcephfs/vxattr.cc +++ b/src/test/libcephfs/vxattr.cc @@ -455,3 +455,117 @@ TEST(LibCephFS, Removexattr) { ceph_shutdown(cmount); } +TEST(LibCephFS, MksnapSubvolumeSnapshotVisibility) { + struct ceph_mount_info *cmount; + ASSERT_EQ(0, ceph_create(&cmount, NULL)); + ASSERT_EQ(0, ceph_conf_read_file(cmount, NULL)); + ASSERT_EQ(0, ceph_conf_parse_env(cmount, NULL)); + ASSERT_EQ(0, ceph_mount(cmount, "/")); + + const char* SNAPSHOT_VISIBILITY_CONFIG = + "client_respect_subvolume_snapshot_visibility"; + const char* SNAPSHOT_VISIBILITY_VXATTR = + "ceph.dir.subvolume.snaps.visible"; + + // client should respect subvolume snapshot visibility + ASSERT_EQ(0, ceph_conf_set(cmount, SNAPSHOT_VISIBILITY_CONFIG, "true")); + + const char *subvol_path = "subvol_test_mksnap"; + ASSERT_EQ(0, ceph_mkdir(cmount, subvol_path, 0777)); + + // set the subvolume vxattr on the subvol_path + ASSERT_EQ(0, ceph_setxattr(cmount, subvol_path, "ceph.dir.subvolume", + (void*)"1", 1, XATTR_CREATE)); + + // try mksnap + ASSERT_EQ(0, ceph_mksnap(cmount, subvol_path, "snap1", 0777, nullptr, 0)); + + // disable snapshot visibility + ASSERT_EQ(0, ceph_setxattr(cmount, subvol_path, SNAPSHOT_VISIBILITY_VXATTR, + (void*)"0", 1, XATTR_CREATE)); + + // should not be able to create snap2 + ASSERT_EQ(-1, ceph_mksnap(cmount, subvol_path, "snap2", 0777, nullptr, 0)); + + // enable snapshot visibility + ASSERT_EQ(0, ceph_setxattr(cmount, subvol_path, SNAPSHOT_VISIBILITY_VXATTR, + (void*)"1", 1, XATTR_CREATE)); + + // now snap2 should get created + ASSERT_EQ(0, ceph_mksnap(cmount, subvol_path, "snap2", 0777, nullptr, 0)); + + // setting to false (FYI, default config value is false) + ASSERT_EQ(0, ceph_conf_set(cmount, SNAPSHOT_VISIBILITY_CONFIG, "false")); + // since client doesn't respect subvolume's snapshot visibility, mksnap + // should go through irrespective of ceph.dir.subvolume.snaps.visible + // set to 0. + ASSERT_EQ(0, ceph_setxattr(cmount, subvol_path, SNAPSHOT_VISIBILITY_VXATTR, + (void*)"0", 1, XATTR_CREATE)); + + // snap3 should get created + ASSERT_EQ(0, ceph_mksnap(cmount, subvol_path, "snap3", 0777, nullptr, 0)); + + // cleanup + ASSERT_EQ(0, ceph_rmsnap(cmount, subvol_path, "snap1")); + ASSERT_EQ(0, ceph_rmsnap(cmount, subvol_path, "snap2")); + ASSERT_EQ(0, ceph_rmsnap(cmount, subvol_path, "snap3")); + ASSERT_EQ(0, ceph_rmdir(cmount, subvol_path)); + ceph_shutdown(cmount); +} + +TEST(LibCephFS, RmsnapSubvolumeSnapshotVisibility) { + struct ceph_mount_info *cmount; + ASSERT_EQ(0, ceph_create(&cmount, NULL)); + ASSERT_EQ(0, ceph_conf_read_file(cmount, NULL)); + ASSERT_EQ(0, ceph_conf_parse_env(cmount, NULL)); + ASSERT_EQ(0, ceph_mount(cmount, "/")); + + const char* SNAPSHOT_VISIBILITY_CONFIG = + "client_respect_subvolume_snapshot_visibility"; + const char* SNAPSHOT_VISIBILITY_VXATTR = + "ceph.dir.subvolume.snaps.visible"; + + // client should respect subvolume snapshot visibility + ASSERT_EQ(0, ceph_conf_set(cmount, SNAPSHOT_VISIBILITY_CONFIG, "true")); + + const char *subvol_path = "subvol_test_rmsnap"; + ASSERT_EQ(0, ceph_mkdir(cmount, subvol_path, 0777)); + + // set the subvolume vxattr on the subvol_path + ASSERT_EQ(0, ceph_setxattr(cmount, subvol_path, "ceph.dir.subvolume", + (void*)"1", 1, XATTR_CREATE)); + + ASSERT_EQ(0, ceph_mksnap(cmount, subvol_path, "snap1", 0777, nullptr, 0)); + ASSERT_EQ(0, ceph_mksnap(cmount, subvol_path, "snap2", 0777, nullptr, 0)); + ASSERT_EQ(0, ceph_mksnap(cmount, subvol_path, "snap3", 0777, nullptr, 0)); + + // disable snapshot visibility + ASSERT_EQ(0, ceph_setxattr(cmount, subvol_path, SNAPSHOT_VISIBILITY_VXATTR, + (void*)"0", 1, XATTR_CREATE)); + + // should not be able to remove snaps + ASSERT_EQ(-1, ceph_rmsnap(cmount, subvol_path, "snap1")); + ASSERT_EQ(-1, ceph_rmsnap(cmount, subvol_path, "snap2")); + + // enable snapshot visibility + ASSERT_EQ(0, ceph_setxattr(cmount, subvol_path, SNAPSHOT_VISIBILITY_VXATTR, + (void*)"1", 1, XATTR_CREATE)); + + // should be able to remove snaps + ASSERT_EQ(0, ceph_rmsnap(cmount, subvol_path, "snap1")); + ASSERT_EQ(0, ceph_rmsnap(cmount, subvol_path, "snap2")); + + // setting to false (FYI, default config value is false) + ASSERT_EQ(0, ceph_conf_set(cmount, SNAPSHOT_VISIBILITY_CONFIG, "false")); + // since client doesn't respect subvolume's snapshot visibility, rmsnap + // should go through irrespective of ceph.dir.subvolume.snaps.visible + // set to 0. + ASSERT_EQ(0, ceph_setxattr(cmount, subvol_path, SNAPSHOT_VISIBILITY_VXATTR, + (void*)"0", 1, XATTR_CREATE)); + // rmsnap should go through + ASSERT_EQ(0, ceph_rmsnap(cmount, subvol_path, "snap3")); + + // cleanup + ASSERT_EQ(0, ceph_rmdir(cmount, subvol_path)); + ceph_shutdown(cmount); +}