Skip to content

Commit 61c13a9

Browse files
committed
test: Add test for libcephfs statfs
Signed-off-by: Christopher Hoffman <[email protected]>
1 parent 85f9fc2 commit 61c13a9

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/test/libcephfs/test.cc

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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, &quota_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", &reg_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+
10221074
TEST(LibCephFS, Symlinks) {
10231075
struct ceph_mount_info *cmount;
10241076
ASSERT_EQ(ceph_create(&cmount, NULL), 0);

0 commit comments

Comments
 (0)