From: Xiubo Li Date: Wed, 29 Jun 2022 01:58:51 +0000 (+0800) Subject: test/libcephfs: move the quota test to a dedicated file X-Git-Tag: v18.0.0~164^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1fba85c2c7d1e52646005b05934213cec94d19ad;p=ceph.git test/libcephfs: move the quota test to a dedicated file Signed-off-by: Xiubo Li --- diff --git a/src/test/libcephfs/quota.cc b/src/test/libcephfs/quota.cc new file mode 100644 index 00000000000..c8ade9e1eea --- /dev/null +++ b/src/test/libcephfs/quota.cc @@ -0,0 +1,111 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2011 New Dream Network + * Copyright (C) 2022 Red Hat, Inc. + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#include "include/compat.h" +#include "gtest/gtest.h" +#include "include/cephfs/libcephfs.h" +#include "mds/mdstypes.h" +#include "include/stat.h" +#include +#include +#include +#include +#include +#include +#include + +#ifdef __linux__ +#include +#include +#endif + +TEST(LibCephFS, SnapQuota) { + 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_snap_dir_quota_xattr[256]; + char test_snap_subdir_quota_xattr[256]; + char test_snap_subdir_noquota_xattr[256]; + char xattrk[128]; + char xattrv[128]; + char c_temp[PATH_MAX]; + char gxattrv[128]; + int xbuflen = sizeof(gxattrv); + pid_t mypid = getpid(); + + // create dir and set quota + sprintf(test_snap_dir_quota_xattr, "test_snap_dir_quota_xattr_%d", mypid); + ASSERT_EQ(0, ceph_mkdir(cmount, test_snap_dir_quota_xattr, 0777)); + + sprintf(xattrk, "ceph.quota.max_bytes"); + sprintf(xattrv, "65536"); + ASSERT_EQ(0, ceph_setxattr(cmount, test_snap_dir_quota_xattr, xattrk, (void *)xattrv, 5, XATTR_CREATE)); + + // create subdir and set quota + sprintf(test_snap_subdir_quota_xattr, "test_snap_dir_quota_xattr_%d/subdir_quota", mypid); + ASSERT_EQ(0, ceph_mkdirs(cmount, test_snap_subdir_quota_xattr, 0777)); + + sprintf(xattrk, "ceph.quota.max_bytes"); + sprintf(xattrv, "32768"); + ASSERT_EQ(0, ceph_setxattr(cmount, test_snap_subdir_quota_xattr, xattrk, (void *)xattrv, 5, XATTR_CREATE)); + + // create subdir with no quota + sprintf(test_snap_subdir_noquota_xattr, "test_snap_dir_quota_xattr_%d/subdir_noquota", mypid); + ASSERT_EQ(0, ceph_mkdirs(cmount, test_snap_subdir_noquota_xattr, 0777)); + + // snapshot dir + sprintf(c_temp, "/.snap/test_snap_dir_quota_xattr_snap_%d", mypid); + ASSERT_EQ(0, ceph_mkdirs(cmount, c_temp, 0777)); + + // check dir quota under snap + sprintf(c_temp, "/.snap/test_snap_dir_quota_xattr_snap_%d/test_snap_dir_quota_xattr_%d", mypid, mypid); + int alen = ceph_getxattr(cmount, c_temp, "ceph.quota.max_bytes", (void *)gxattrv, xbuflen); + ASSERT_LT(0, alen); + ASSERT_LT(alen, xbuflen); + gxattrv[alen] = '\0'; + ASSERT_STREQ(gxattrv, "65536"); + + // check subdir quota under snap + sprintf(c_temp, "/.snap/test_snap_dir_quota_xattr_snap_%d/test_snap_dir_quota_xattr_%d/subdir_quota", mypid, mypid); + alen = ceph_getxattr(cmount, c_temp, "ceph.quota.max_bytes", (void *)gxattrv, xbuflen); + ASSERT_LT(0, alen); + ASSERT_LT(alen, xbuflen); + gxattrv[alen] = '\0'; + ASSERT_STREQ(gxattrv, "32768"); + + // ensure subdir noquota xattr under snap + sprintf(c_temp, "/.snap/test_snap_dir_quota_xattr_snap_%d/test_snap_dir_quota_xattr_%d/subdir_noquota", mypid, mypid); + EXPECT_EQ(-ENODATA, ceph_getxattr(cmount, c_temp, "ceph.quota.max_bytes", (void *)gxattrv, xbuflen)); + + // listxattr() shouldn't return ceph.quota.max_bytes vxattr + sprintf(c_temp, "/.snap/test_snap_dir_quota_xattr_snap_%d/test_snap_dir_quota_xattr_%d", mypid, mypid); + char xattrlist[512]; + int len = ceph_listxattr(cmount, c_temp, xattrlist, sizeof(xattrlist)); + ASSERT_GE(sizeof(xattrlist), (size_t)len); + char *p = xattrlist; + int found = 0; + while (len > 0) { + if (strcmp(p, "ceph.quota.max_bytes") == 0) + found++; + len -= strlen(p) + 1; + p += strlen(p) + 1; + } + ASSERT_EQ(found, 0); + + ceph_shutdown(cmount); +} diff --git a/src/test/libcephfs/test.cc b/src/test/libcephfs/test.cc index aeda4c1df1b..0a246cb1331 100644 --- a/src/test/libcephfs/test.cc +++ b/src/test/libcephfs/test.cc @@ -2394,85 +2394,6 @@ TEST(LibCephFS, SnapXattrs) { ceph_shutdown(cmount); } -TEST(LibCephFS, SnapQuota) { - 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_snap_dir_quota_xattr[256]; - char test_snap_subdir_quota_xattr[256]; - char test_snap_subdir_noquota_xattr[256]; - char xattrk[128]; - char xattrv[128]; - char c_temp[PATH_MAX]; - char gxattrv[128]; - int xbuflen = sizeof(gxattrv); - pid_t mypid = getpid(); - - // create dir and set quota - sprintf(test_snap_dir_quota_xattr, "test_snap_dir_quota_xattr_%d", mypid); - ASSERT_EQ(0, ceph_mkdir(cmount, test_snap_dir_quota_xattr, 0777)); - - sprintf(xattrk, "ceph.quota.max_bytes"); - sprintf(xattrv, "65536"); - ASSERT_EQ(0, ceph_setxattr(cmount, test_snap_dir_quota_xattr, xattrk, (void *)xattrv, 5, XATTR_CREATE)); - - // create subdir and set quota - sprintf(test_snap_subdir_quota_xattr, "test_snap_dir_quota_xattr_%d/subdir_quota", mypid); - ASSERT_EQ(0, ceph_mkdirs(cmount, test_snap_subdir_quota_xattr, 0777)); - - sprintf(xattrk, "ceph.quota.max_bytes"); - sprintf(xattrv, "32768"); - ASSERT_EQ(0, ceph_setxattr(cmount, test_snap_subdir_quota_xattr, xattrk, (void *)xattrv, 5, XATTR_CREATE)); - - // create subdir with no quota - sprintf(test_snap_subdir_noquota_xattr, "test_snap_dir_quota_xattr_%d/subdir_noquota", mypid); - ASSERT_EQ(0, ceph_mkdirs(cmount, test_snap_subdir_noquota_xattr, 0777)); - - // snapshot dir - sprintf(c_temp, "/.snap/test_snap_dir_quota_xattr_snap_%d", mypid); - ASSERT_EQ(0, ceph_mkdirs(cmount, c_temp, 0777)); - - // check dir quota under snap - sprintf(c_temp, "/.snap/test_snap_dir_quota_xattr_snap_%d/test_snap_dir_quota_xattr_%d", mypid, mypid); - int alen = ceph_getxattr(cmount, c_temp, "ceph.quota.max_bytes", (void *)gxattrv, xbuflen); - ASSERT_LT(0, alen); - ASSERT_LT(alen, xbuflen); - gxattrv[alen] = '\0'; - ASSERT_STREQ(gxattrv, "65536"); - - // check subdir quota under snap - sprintf(c_temp, "/.snap/test_snap_dir_quota_xattr_snap_%d/test_snap_dir_quota_xattr_%d/subdir_quota", mypid, mypid); - alen = ceph_getxattr(cmount, c_temp, "ceph.quota.max_bytes", (void *)gxattrv, xbuflen); - ASSERT_LT(0, alen); - ASSERT_LT(alen, xbuflen); - gxattrv[alen] = '\0'; - ASSERT_STREQ(gxattrv, "32768"); - - // ensure subdir noquota xattr under snap - sprintf(c_temp, "/.snap/test_snap_dir_quota_xattr_snap_%d/test_snap_dir_quota_xattr_%d/subdir_noquota", mypid, mypid); - EXPECT_EQ(-ENODATA, ceph_getxattr(cmount, c_temp, "ceph.quota.max_bytes", (void *)gxattrv, xbuflen)); - - // listxattr() shouldn't return ceph.quota.max_bytes vxattr - sprintf(c_temp, "/.snap/test_snap_dir_quota_xattr_snap_%d/test_snap_dir_quota_xattr_%d", mypid, mypid); - char xattrlist[512]; - int len = ceph_listxattr(cmount, c_temp, xattrlist, sizeof(xattrlist)); - ASSERT_GE(sizeof(xattrlist), (size_t)len); - char *p = xattrlist; - int found = 0; - while (len > 0) { - if (strcmp(p, "ceph.quota.max_bytes") == 0) - found++; - len -= strlen(p) + 1; - p += strlen(p) + 1; - } - ASSERT_EQ(found, 0); - - ceph_shutdown(cmount); -} - TEST(LibCephFS, Lseek) { struct ceph_mount_info *cmount; ASSERT_EQ(0, ceph_create(&cmount, NULL));