From 72f7b8cb6e8bd648eed77dee64bf77c058109995 Mon Sep 17 00:00:00 2001 From: Xiubo Li Date: Wed, 29 Jun 2022 17:44:45 +0800 Subject: [PATCH] test/libcephfs: add quota size check support Fixes: https://tracker.ceph.com/issues/56414 Signed-off-by: Xiubo Li --- src/test/libcephfs/quota.cc | 56 +++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/test/libcephfs/quota.cc b/src/test/libcephfs/quota.cc index c8ade9e1eea..c4d0c4c3f3b 100644 --- a/src/test/libcephfs/quota.cc +++ b/src/test/libcephfs/quota.cc @@ -109,3 +109,59 @@ TEST(LibCephFS, SnapQuota) { ceph_shutdown(cmount); } + +void statfs_quota_size_check(struct ceph_mount_info *cmount, const char *path, + int blocks, int bsize) +{ + struct statvfs stvfs; + + ASSERT_EQ(0, ceph_statfs(cmount, path, &stvfs)); + ASSERT_EQ(blocks, stvfs.f_blocks); + ASSERT_EQ(bsize, stvfs.f_bsize); + ASSERT_EQ(bsize, stvfs.f_frsize); +} + +TEST(LibCephFS, QuotaRealm) { + struct ceph_mount_info *cmount, *pmount1, *pmount2; + char test_quota_realm_pdir[128]; + char test_quota_realm_cdir[256]; + char xattrk[32]; + char xattrv[16]; + + 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); + + pid_t mypid = getpid(); + + // create parent directory and set quota size + sprintf(test_quota_realm_pdir, "/test_quota_realm_pdir_%d", mypid); + ASSERT_EQ(0, ceph_mkdir(cmount, test_quota_realm_pdir, 0777)); + sprintf(xattrk, "ceph.quota.max_bytes"); + sprintf(xattrv, "8388608"); // 8MB + ASSERT_EQ(0, ceph_setxattr(cmount, test_quota_realm_pdir, xattrk, (void *)xattrv, 7, XATTR_CREATE)); + + // create child directory and set quota file + sprintf(test_quota_realm_cdir, "%s/test_quota_realm_cdir", test_quota_realm_pdir); + ASSERT_EQ(0, ceph_mkdir(cmount, test_quota_realm_cdir, 0777)); + sprintf(xattrk, "ceph.quota.max_files"); + sprintf(xattrv, "1024"); // 1K files + ASSERT_EQ(0, ceph_setxattr(cmount, test_quota_realm_cdir, xattrk, (void *)xattrv, 4, XATTR_CREATE)); + + ASSERT_EQ(ceph_create(&pmount1, NULL), 0); + ASSERT_EQ(ceph_conf_read_file(pmount1, NULL), 0); + ASSERT_EQ(0, ceph_conf_parse_env(pmount1, NULL)); + ASSERT_EQ(ceph_mount(pmount1, test_quota_realm_pdir), 0); + statfs_quota_size_check(pmount1, "/", 2, 4194304); // 8MB + + ASSERT_EQ(ceph_create(&pmount2, NULL), 0); + ASSERT_EQ(ceph_conf_read_file(pmount2, NULL), 0); + ASSERT_EQ(0, ceph_conf_parse_env(pmount2, NULL)); + ASSERT_EQ(ceph_mount(pmount2, test_quota_realm_cdir), 0); + statfs_quota_size_check(pmount2, "/", 2, 4194304); // 8MB + + ceph_shutdown(pmount1); + ceph_shutdown(pmount2); + ceph_shutdown(cmount); +} -- 2.39.5