]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
test/libcephfs: add test cases for Client::mksnap and Client::rmsnap
authorDhairya Parmar <dparmar@redhat.com>
Wed, 3 Sep 2025 11:40:34 +0000 (17:10 +0530)
committerDhairya Parmar <dparmar@redhat.com>
Thu, 25 Sep 2025 16:41:08 +0000 (22:11 +0530)
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 <dparmar@redhat.com>
src/test/libcephfs/vxattr.cc

index b9cc2e2e247f3f8f04718701351e77b755afadf2..7322446a7a77c38d0e0e128fb973f7d268e40ab6 100644 (file)
@@ -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);
+}