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);
+}