@@ -1019,6 +1019,58 @@ TEST(LibCephFS, FlagO_PATH) {
10191019}
10201020#endif /* __linux */
10211021
1022+ TEST (LibCephFS, StatfsQuota) {
1023+
1024+ struct ceph_mount_info *cmount;
1025+ ASSERT_EQ (ceph_create (&cmount, NULL ), 0 );
1026+ ASSERT_EQ (ceph_conf_read_file (cmount, NULL ), 0 );
1027+ ASSERT_EQ (0 , ceph_conf_parse_env (cmount, NULL ));
1028+ ASSERT_EQ (ceph_mount (cmount, NULL ), 0 );
1029+
1030+ const char * quota_dir = " quota_dir" ;
1031+
1032+ ASSERT_EQ (0 , ceph_mkdir (cmount, quota_dir, 0777 ));
1033+ EXPECT_EQ (0 , ceph_setxattr (cmount, quota_dir, " ceph.quota.max_files" , " 10000" , 05 , 0 ));
1034+
1035+ const int num_quota_files = 1 ;
1036+ char quota_file[256 ];
1037+ sprintf (quota_file, " %s/test_statfs_quota_%d" , quota_dir, getpid ());
1038+
1039+ int fd = ceph_open (cmount, quota_file, O_CREAT|O_RDWR, 0666 );
1040+ ASSERT_GT (fd, 0 );
1041+
1042+ ceph_close (cmount, fd);
1043+
1044+ const int num_reg_files = 5 ;
1045+ char regular_file[256 ];
1046+ for (int i = 0 ; i < num_reg_files; i++) {
1047+ sprintf (regular_file, " test_statfs_regular_%d" , i);
1048+ fd = ceph_open (cmount, regular_file, O_CREAT|O_RDWR, 0666 );
1049+ ceph_close (cmount, fd);
1050+ }
1051+
1052+ ASSERT_EQ (0 , ceph_unmount (cmount));
1053+ ASSERT_EQ (0 , ceph_mount (cmount, NULL ));
1054+
1055+ struct statvfs quota_stvbuf;
1056+ ASSERT_EQ (0 , ceph_statfs (cmount, quota_file, "a_stvbuf));
1057+ ASSERT_EQ (num_quota_files+1 , quota_stvbuf.f_files ); // +1 for dirent quota_dir
1058+
1059+ struct statvfs reg_stvbuf;
1060+ ASSERT_EQ (0 , ceph_statfs (cmount, " test_statfs_regular_1" , ®_stvbuf));
1061+ ASSERT_GT (reg_stvbuf.f_files , quota_stvbuf.f_files );
1062+
1063+ for (int i = 0 ; i < num_reg_files; i++) {
1064+ sprintf (regular_file, " test_statfs_regular_%d" , i);
1065+ ASSERT_EQ (0 , ceph_unlink (cmount, regular_file));
1066+ }
1067+
1068+ ASSERT_EQ (0 , ceph_unlink (cmount, quota_file));
1069+ ASSERT_EQ (0 , ceph_rmdir (cmount, quota_dir));
1070+
1071+ ceph_shutdown (cmount);
1072+ }
1073+
10221074TEST (LibCephFS, Symlinks) {
10231075 struct ceph_mount_info *cmount;
10241076 ASSERT_EQ (ceph_create (&cmount, NULL ), 0 );
0 commit comments