@@ -383,3 +383,75 @@ TEST(LibCephFS, GetAndSetDirRandom) {
383383
384384 ceph_shutdown (cmount);
385385}
386+
387+ TEST (LibCephFS, FsCrypt) {
388+ struct ceph_mount_info *cmount;
389+ ASSERT_EQ (ceph_create (&cmount, NULL ), 0 );
390+ ASSERT_EQ (ceph_conf_read_file (cmount, NULL ), 0 );
391+ ASSERT_EQ (0 , ceph_conf_parse_env (cmount, NULL ));
392+ ASSERT_EQ (ceph_mount (cmount, NULL ), 0 );
393+
394+ char test_xattr_file[NAME_MAX];
395+ sprintf (test_xattr_file, " test_fscrypt_%d" , getpid ());
396+ int fd = ceph_open (cmount, test_xattr_file, O_RDWR|O_CREAT, 0666 );
397+ ASSERT_GT (fd, 0 );
398+
399+ ASSERT_EQ (0 , ceph_fsetxattr (cmount, fd, " ceph.fscrypt.auth" , " foo" , 3 , XATTR_CREATE));
400+ ASSERT_EQ (0 , ceph_fsetxattr (cmount, fd, " ceph.fscrypt.file" , " foo" , 3 , XATTR_CREATE));
401+
402+ char buf[64 ];
403+ ASSERT_EQ (3 , ceph_fgetxattr (cmount, fd, " ceph.fscrypt.auth" , buf, sizeof (buf)));
404+ ASSERT_EQ (3 , ceph_fgetxattr (cmount, fd, " ceph.fscrypt.file" , buf, sizeof (buf)));
405+ ASSERT_EQ (0 , ceph_close (cmount, fd));
406+
407+ ASSERT_EQ (0 , ceph_unmount (cmount));
408+ ASSERT_EQ (0 , ceph_mount (cmount, NULL ));
409+
410+ fd = ceph_open (cmount, test_xattr_file, O_RDWR, 0666 );
411+ ASSERT_GT (fd, 0 );
412+ ASSERT_EQ (3 , ceph_fgetxattr (cmount, fd, " ceph.fscrypt.auth" , buf, sizeof (buf)));
413+ ASSERT_EQ (3 , ceph_fgetxattr (cmount, fd, " ceph.fscrypt.file" , buf, sizeof (buf)));
414+
415+ ASSERT_EQ (0 , ceph_close (cmount, fd));
416+ ASSERT_EQ (0 , ceph_unmount (cmount));
417+ ceph_shutdown (cmount);
418+ }
419+
420+ #define ACL_EA_ACCESS " system.posix_acl_access"
421+ #define ACL_EA_DEFAULT " system.posix_acl_default"
422+
423+ TEST (LibCephFS, Removexattr) {
424+ struct ceph_mount_info *cmount;
425+ ASSERT_EQ (ceph_create (&cmount, NULL ), 0 );
426+ ASSERT_EQ (ceph_conf_read_file (cmount, NULL ), 0 );
427+ ASSERT_EQ (0 , ceph_conf_parse_env (cmount, NULL ));
428+ ASSERT_EQ (ceph_mount (cmount, NULL ), 0 );
429+
430+ char test_xattr_file[NAME_MAX];
431+ sprintf (test_xattr_file, " test_removexattr_%d" , getpid ());
432+ int fd = ceph_open (cmount, test_xattr_file, O_RDWR|O_CREAT, 0666 );
433+ ASSERT_GT (fd, 0 );
434+
435+ // remove xattr
436+ ASSERT_EQ (-CEPHFS_ENODATA, ceph_fremovexattr (cmount, fd, " user.remove.xattr" ));
437+ ASSERT_EQ (0 , ceph_fsetxattr (cmount, fd, " user.remove.xattr" , " foo" , 3 , XATTR_CREATE));
438+ ASSERT_EQ (0 , ceph_fremovexattr (cmount, fd, " user.remove.xattr" ));
439+
440+ // remove xattr via setxattr & XATTR_REPLACE
441+ ASSERT_EQ (-CEPHFS_ENODATA, ceph_fsetxattr (cmount, fd, " user.remove.xattr" , nullptr , 0 , XATTR_REPLACE));
442+ ASSERT_EQ (0 , ceph_fsetxattr (cmount, fd, " user.remove.xattr" , " foo" , 3 , XATTR_CREATE));
443+ ASSERT_EQ (0 , ceph_fsetxattr (cmount, fd, " user.remove.xattr" , nullptr , 0 , XATTR_REPLACE));
444+
445+ // ACL_EA_ACCESS and ACL_EA_DEFAULT are special and will always return success.
446+ // If the corresponding attributes exist already the first one will remove it
447+ // and the second one will remove the non-existing acl attributes.
448+ ASSERT_EQ (0 , ceph_fremovexattr (cmount, fd, ACL_EA_ACCESS));
449+ ASSERT_EQ (0 , ceph_fremovexattr (cmount, fd, ACL_EA_ACCESS));
450+ ASSERT_EQ (0 , ceph_fremovexattr (cmount, fd, ACL_EA_DEFAULT));
451+ ASSERT_EQ (0 , ceph_fremovexattr (cmount, fd, ACL_EA_DEFAULT));
452+
453+ ASSERT_EQ (0 , ceph_close (cmount, fd));
454+ ASSERT_EQ (0 , ceph_unmount (cmount));
455+ ceph_shutdown (cmount);
456+ }
457+
0 commit comments