From: Xiubo Li Date: Tue, 5 Mar 2024 00:32:34 +0000 (+0800) Subject: test/libcephfs: move FsCrypt xattr test to dedicated test file X-Git-Tag: v18.2.5~294^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=da8e3a46c2bfecb87345e2e348c7729a7efc6275;p=ceph.git test/libcephfs: move FsCrypt xattr test to dedicated test file Switch to use XATTR_CREATE. Fixes: https://tracker.ceph.com/issues/64679 Signed-off-by: Xiubo Li (cherry picked from commit ec30c46d1773679ae3787cf68a14b0f7d869101b) --- diff --git a/src/test/libcephfs/test.cc b/src/test/libcephfs/test.cc index 57c5eefa6d32..f2c87168633b 100644 --- a/src/test/libcephfs/test.cc +++ b/src/test/libcephfs/test.cc @@ -3520,39 +3520,6 @@ TEST(LibCephFS, SetMountTimeout) { ceph_shutdown(cmount); } -TEST(LibCephFS, FsCrypt) { - struct ceph_mount_info *cmount; - ASSERT_EQ(ceph_create(&cmount, NULL), 0); - ASSERT_EQ(ceph_conf_read_file(cmount, NULL), 0); - ASSERT_EQ(0, ceph_conf_parse_env(cmount, NULL)); - ASSERT_EQ(ceph_mount(cmount, NULL), 0); - - char test_xattr_file[NAME_MAX]; - sprintf(test_xattr_file, "test_fscrypt_%d", getpid()); - int fd = ceph_open(cmount, test_xattr_file, O_RDWR|O_CREAT, 0666); - ASSERT_GT(fd, 0); - - ASSERT_EQ(0, ceph_fsetxattr(cmount, fd, "ceph.fscrypt.auth", "foo", 3, CEPH_XATTR_CREATE)); - ASSERT_EQ(0, ceph_fsetxattr(cmount, fd, "ceph.fscrypt.file", "foo", 3, CEPH_XATTR_CREATE)); - - char buf[64]; - ASSERT_EQ(3, ceph_fgetxattr(cmount, fd, "ceph.fscrypt.auth", buf, sizeof(buf))); - ASSERT_EQ(3, ceph_fgetxattr(cmount, fd, "ceph.fscrypt.file", buf, sizeof(buf))); - ASSERT_EQ(0, ceph_close(cmount, fd)); - - ASSERT_EQ(0, ceph_unmount(cmount)); - ASSERT_EQ(0, ceph_mount(cmount, NULL)); - - fd = ceph_open(cmount, test_xattr_file, O_RDWR, 0666); - ASSERT_GT(fd, 0); - ASSERT_EQ(3, ceph_fgetxattr(cmount, fd, "ceph.fscrypt.auth", buf, sizeof(buf))); - ASSERT_EQ(3, ceph_fgetxattr(cmount, fd, "ceph.fscrypt.file", buf, sizeof(buf))); - - ASSERT_EQ(0, ceph_close(cmount, fd)); - ASSERT_EQ(0, ceph_unmount(cmount)); - ceph_shutdown(cmount); -} - TEST(LibCephFS, SnapdirAttrs) { struct ceph_mount_info *cmount; ASSERT_EQ(ceph_create(&cmount, NULL), 0); diff --git a/src/test/libcephfs/vxattr.cc b/src/test/libcephfs/vxattr.cc index 4d9eaf5e4d0c..b48ffb56e4e7 100644 --- a/src/test/libcephfs/vxattr.cc +++ b/src/test/libcephfs/vxattr.cc @@ -383,3 +383,37 @@ TEST(LibCephFS, GetAndSetDirRandom) { ceph_shutdown(cmount); } + +TEST(LibCephFS, FsCrypt) { + struct ceph_mount_info *cmount; + ASSERT_EQ(ceph_create(&cmount, NULL), 0); + ASSERT_EQ(ceph_conf_read_file(cmount, NULL), 0); + ASSERT_EQ(0, ceph_conf_parse_env(cmount, NULL)); + ASSERT_EQ(ceph_mount(cmount, NULL), 0); + + char test_xattr_file[NAME_MAX]; + sprintf(test_xattr_file, "test_fscrypt_%d", getpid()); + int fd = ceph_open(cmount, test_xattr_file, O_RDWR|O_CREAT, 0666); + ASSERT_GT(fd, 0); + + ASSERT_EQ(0, ceph_fsetxattr(cmount, fd, "ceph.fscrypt.auth", "foo", 3, XATTR_CREATE)); + ASSERT_EQ(0, ceph_fsetxattr(cmount, fd, "ceph.fscrypt.file", "foo", 3, XATTR_CREATE)); + + char buf[64]; + ASSERT_EQ(3, ceph_fgetxattr(cmount, fd, "ceph.fscrypt.auth", buf, sizeof(buf))); + ASSERT_EQ(3, ceph_fgetxattr(cmount, fd, "ceph.fscrypt.file", buf, sizeof(buf))); + ASSERT_EQ(0, ceph_close(cmount, fd)); + + ASSERT_EQ(0, ceph_unmount(cmount)); + ASSERT_EQ(0, ceph_mount(cmount, NULL)); + + fd = ceph_open(cmount, test_xattr_file, O_RDWR, 0666); + ASSERT_GT(fd, 0); + ASSERT_EQ(3, ceph_fgetxattr(cmount, fd, "ceph.fscrypt.auth", buf, sizeof(buf))); + ASSERT_EQ(3, ceph_fgetxattr(cmount, fd, "ceph.fscrypt.file", buf, sizeof(buf))); + + ASSERT_EQ(0, ceph_close(cmount, fd)); + ASSERT_EQ(0, ceph_unmount(cmount)); + ceph_shutdown(cmount); +} +