* [LTP] [PATCH v6 1/3] syscalls/quotactl09: Test error when quota info hidden in filesystem
@ 2022-01-12 7:48 Yang Xu
2022-01-12 7:48 ` [LTP] [PATCH v6 2/3] syscalls/quotactl07: Refactor this case Yang Xu
` (3 more replies)
0 siblings, 4 replies; 13+ messages in thread
From: Yang Xu @ 2022-01-12 7:48 UTC (permalink / raw)
To: ltp
This case is similar to quotactl06 but only some differences
1) use quotactl and quotactl_fd syscalls without visible quota file
2) remove some error for addr argument
3) test external_fd for quotactl_fd for EINVAL error when using Q_QUOTAON
4) add error case description when running
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/quotactl/.gitignore | 1 +
.../kernel/syscalls/quotactl/quotactl09.c | 195 ++++++++++++++++++
3 files changed, 197 insertions(+)
create mode 100644 testcases/kernel/syscalls/quotactl/quotactl09.c
diff --git a/runtest/syscalls b/runtest/syscalls
index a0ca84b36..3b2deb64e 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1073,6 +1073,7 @@ quotactl05 quotactl05
quotactl06 quotactl06
quotactl07 quotactl07
quotactl08 quotactl08
+quotactl09 quotactl09
read01 read01
read02 read02
diff --git a/testcases/kernel/syscalls/quotactl/.gitignore b/testcases/kernel/syscalls/quotactl/.gitignore
index dab9b3420..94de2c8f2 100644
--- a/testcases/kernel/syscalls/quotactl/.gitignore
+++ b/testcases/kernel/syscalls/quotactl/.gitignore
@@ -6,3 +6,4 @@
/quotactl06
/quotactl07
/quotactl08
+/quotactl09
diff --git a/testcases/kernel/syscalls/quotactl/quotactl09.c b/testcases/kernel/syscalls/quotactl/quotactl09.c
new file mode 100644
index 000000000..79f506bdc
--- /dev/null
+++ b/testcases/kernel/syscalls/quotactl/quotactl09.c
@@ -0,0 +1,195 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Tests basic error handling of the quotactl syscall without visible quota files
+ * (use quotactl and quotactl_fd syscall):
+ *
+ * - EFAULT when addr or special is invalid
+ * - EINVAL when cmd or type is invalid
+ * - ENOTBLK when special is not a block device
+ * - ERANGE when cmd is Q_SETQUOTA, but the specified limits are out of the range
+ * allowed by the quota format
+ * - EPERM when the caller lacked the required privilege (CAP_SYS_ADMIN) for the
+ * specified operation
+ * - EINVAL when cmd is Q_QUOTAON, but the fd refers to a regular file(doesn't
+ * under this moutpoint)
+ *
+ * Minimum e2fsprogs version required is 1.43.
+ */
+
+#include <errno.h>
+#include <sys/quota.h>
+#include "tst_test.h"
+#include "tst_capability.h"
+#include "quotactl_syscall_var.h"
+
+#define OPTION_INVALID 999
+
+static int32_t fmt_id = QFMT_VFS_V1;
+static int test_id, mount_flag;
+static int getnextquota_nsup, external_fd = -1;
+
+static struct if_nextdqblk res_ndq;
+
+static struct dqblk set_dqmax = {
+ .dqb_bsoftlimit = 0x7fffffffffffffffLL, /* 2^63-1 */
+ .dqb_valid = QIF_BLIMITS
+};
+
+static struct tst_cap dropadmin = {
+ .action = TST_CAP_DROP,
+ .id = CAP_SYS_ADMIN,
+ .name = "CAP_SYS_ADMIN",
+};
+
+static struct tst_cap needadmin = {
+ .action = TST_CAP_REQ,
+ .id = CAP_SYS_ADMIN,
+ .name = "CAP_SYS_ADMIN",
+};
+
+static struct tcase {
+ int cmd;
+ int *id;
+ void *addr;
+ int exp_err;
+ int on_flag;
+ int use_external_fd;
+ char *des;
+} tcases[] = {
+ {QCMD(Q_SETQUOTA, USRQUOTA), &fmt_id, NULL, EFAULT, 1, 0,
+ "EFAULT when addr or special is invalid"},
+
+ {QCMD(OPTION_INVALID, USRQUOTA), &fmt_id, NULL, EINVAL, 0, 0,
+ "EINVAL when cmd or type is invalid"},
+
+ {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, NULL, ENOTBLK, 0, 0,
+ "ENOTBLK when special is not a block device"},
+
+ {QCMD(Q_SETQUOTA, USRQUOTA), &test_id, &set_dqmax, ERANGE, 1, 0,
+ "ERANGE when cmd is Q_SETQUOTA, but the specified limits are out of the range"},
+
+ {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, NULL, EPERM, 0, 0,
+ "EPERM when the caller lacked the required privilege for specified operations"},
+
+ {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, NULL, EINVAL, 0, 1,
+ "EINVAL when cmd is Q_QUOTAON, but the fd refers to a regular file(doesn't under "
+ "this mountpoint)"}
+};
+
+static void verify_quotactl(unsigned int n)
+{
+ struct tcase *tc = &tcases[n];
+ int quota_on = 0;
+ int drop_flag = 0;
+
+ tst_res(TINFO, "Testing %s", tc->des);
+ if (tc->cmd == QCMD(Q_GETNEXTQUOTA, USRQUOTA) && getnextquota_nsup) {
+ tst_res(TCONF, "current system doesn't support Q_GETNEXTQUOTA");
+ return;
+ }
+
+ if (tc->on_flag) {
+ TST_EXP_PASS_SILENT(do_quotactl(fd, QCMD(Q_QUOTAON, USRQUOTA), tst_device->dev,
+ fmt_id, NULL), "do_quotactl(QCMD(Q_QUOTAON, USRQUOTA))");
+ if (!TST_PASS)
+ return;
+ quota_on = 1;
+ }
+
+ if (tc->exp_err == EPERM) {
+ tst_cap_action(&dropadmin);
+ drop_flag = 1;
+ }
+
+ if (tst_variant) {
+ if (tc->exp_err == ENOTBLK) {
+ tst_res(TCONF, "quotactl_fd() doesn't have this error, skip");
+ return;
+ }
+ } else {
+ if (tc->use_external_fd) {
+ tst_res(TCONF, "quotactl() doesn't use fd, skip");
+ return;
+ }
+ }
+ if (tc->exp_err == ENOTBLK)
+ TST_EXP_FAIL(do_quotactl(fd, tc->cmd, "/dev/null", *tc->id, tc->addr),
+ ENOTBLK, "do_quotactl()");
+ else
+ TST_EXP_FAIL(do_quotactl(tc->use_external_fd ? external_fd : fd, tc->cmd,
+ tst_device->dev, *tc->id, tc->addr), tc->exp_err, "do_quotactl()");
+
+ if (quota_on) {
+ TST_EXP_PASS_SILENT(do_quotactl(fd, QCMD(Q_QUOTAOFF, USRQUOTA), tst_device->dev,
+ fmt_id, NULL), "do_quotactl(QCMD(Q_QUOTAOFF, USRQUOTA)");
+ if (!TST_PASS)
+ return;
+ quota_on = 0;
+ }
+
+ if (drop_flag) {
+ tst_cap_action(&needadmin);
+ drop_flag = 0;
+ }
+}
+
+static void setup(void)
+{
+ unsigned int i;
+ const char *const fs_opts[] = { "-O quota", NULL};
+
+ quotactl_info();
+ external_fd = SAFE_CREAT("testfile", O_RDONLY);
+
+ SAFE_MKFS(tst_device->dev, tst_device->fs_type, fs_opts, NULL);
+ SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL);
+ mount_flag = 1;
+
+ fd = SAFE_OPEN(MNTPOINT, O_RDONLY);
+ TEST(do_quotactl(fd, QCMD(Q_GETNEXTQUOTA, USRQUOTA), tst_device->dev,
+ test_id, (void *) &res_ndq));
+ if (TST_ERR == EINVAL || TST_ERR == ENOSYS)
+ getnextquota_nsup = 1;
+
+ for (i = 0; i < ARRAY_SIZE(tcases); i++) {
+ if (!tcases[i].addr)
+ tcases[i].addr = tst_get_bad_addr(NULL);
+ }
+}
+
+static void cleanup(void)
+{
+ if (fd > -1)
+ SAFE_CLOSE(fd);
+ if (external_fd > -1)
+ SAFE_CLOSE(external_fd);
+ if (mount_flag && tst_umount(MNTPOINT))
+ tst_res(TWARN | TERRNO, "umount(%s)", MNTPOINT);
+}
+
+static struct tst_test test = {
+ .setup = setup,
+ .cleanup = cleanup,
+ .needs_kconfigs = (const char *[]) {
+ "CONFIG_QFMT_V2",
+ NULL
+ },
+ .tcnt = ARRAY_SIZE(tcases),
+ .test = verify_quotactl,
+ .dev_fs_type = "ext4",
+ .mntpoint = MNTPOINT,
+ .needs_device = 1,
+ .needs_root = 1,
+ .test_variants = QUOTACTL_SYSCALL_VARIANTS,
+ .needs_cmds = (const char *[]) {
+ "mkfs.ext4 >= 1.43.0",
+ NULL
+ }
+};
--
2.23.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [LTP] [PATCH v6 2/3] syscalls/quotactl07: Refactor this case
2022-01-12 7:48 [LTP] [PATCH v6 1/3] syscalls/quotactl09: Test error when quota info hidden in filesystem Yang Xu
@ 2022-01-12 7:48 ` Yang Xu
2022-01-13 14:03 ` Cyril Hrubis
2022-01-12 7:48 ` [LTP] [PATCH v6 3/3] syscalls/quotactl: Make use of TST_EXP_PASS_SILENT and TST_EXP_FAIL Yang Xu
` (2 subsequent siblings)
3 siblings, 1 reply; 13+ messages in thread
From: Yang Xu @ 2022-01-12 7:48 UTC (permalink / raw)
To: ltp
man-pages has error that Q_XQUOTARM was not introduced by kernel
3.16[1][2]. It only doesn't have owner handler so the flag spaces overlap
a bit[3].
Add a functional test for Q_XQUOTARM and check whether available block
is greater than before instead of a regression test for buggy 3.16 kernel
because it is about 8 year old. Functional test is more meaningful.
Since kernel commit 40b52225e ("xfs: remove support for disabling quota
accounting on a mounted file system")[4] was introduced, if we want to
disable quota account feature before Q_XQUOTARM, we must need to remount
with noquota like xfs maintainer does in xfstests xfs/220 [5].
So, change this by mount with usrquota and remount with noquota to create
a test environment that superblock has quota data but quota feature not running.
We also add quotactl_fd test variant for this test.
[1]https://github.com/alejandro-colomar/man-pages/commit/38bccbcf4f51c5370a1060e6a80b90d68b0dcdc8
[2]https://github.com/alejandro-colomar/man-pages/commit/26f3978f04a1aeeb5397a5facebaef40a341afb6
[3]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=9da93f9b7c
[4]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit?id=40b52225e58
[5]https://patchwork.kernel.org/project/fstests/patch/20220105195352.GM656707@magnolia/
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
.../kernel/syscalls/quotactl/quotactl07.c | 58 +++++++++++++------
1 file changed, 40 insertions(+), 18 deletions(-)
diff --git a/testcases/kernel/syscalls/quotactl/quotactl07.c b/testcases/kernel/syscalls/quotactl/quotactl07.c
index 2992a6112..2427ef682 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl07.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl07.c
@@ -7,7 +7,9 @@
/*\
* [Description]
*
- * This is a regresstion test for kernel commit 3dd4d40b4208
+ * This is not only a functional test but also a error test for Q_XQUOTARM.
+ *
+ * It is a regresstion test for kernel commit 3dd4d40b4208
* ("xfs: Sanity check flags of Q_XQUOTARM call").
*/
@@ -15,51 +17,71 @@
#include <unistd.h>
#include <stdio.h>
#include <sys/quota.h>
+#include <sys/statvfs.h>
#include "tst_test.h"
-#include "lapi/quotactl.h"
+#include "quotactl_syscall_var.h"
#ifdef HAVE_XFS_XQM_H
# include <xfs/xqm.h>
-#define MNTPOINT "mntpoint"
-
-static uint32_t qflag_acct = XFS_QUOTA_UDQ_ACCT;
-static unsigned int valid_type = XFS_USER_QUOTA;
/* Include a valid quota type to avoid other EINVAL error */
static unsigned int invalid_type = XFS_GROUP_QUOTA << 1 | XFS_USER_QUOTA;
+static unsigned int valid_type = XFS_USER_QUOTA;
+static int mount_flag;
static void verify_quota(void)
{
- TEST(quotactl(QCMD(Q_XQUOTARM, USRQUOTA), tst_device->dev, 0, (void *)&invalid_type));
- if (TST_ERR == EINVAL)
- tst_res(TPASS, "Q_XQUOTARM has quota type check");
+ struct statfs before, after;
+
+ SAFE_STATFS(MNTPOINT, &before);
+ TST_EXP_PASS(do_quotactl(fd, QCMD(Q_XQUOTARM, USRQUOTA), tst_device->dev, 0,
+ (void *)&valid_type), "do_quotactl(Q_XQUOTARM,valid_type)");
+ SAFE_STATFS(MNTPOINT, &after);
+ if (before.f_bavail <= after.f_bavail)
+ tst_res(TPASS, "Q_XQUOTARM to free space, delta(%lu)", after.f_bavail - before.f_bavail);
else
- tst_res(TFAIL, "Q_XQUOTARM doesn't have quota type check");
+ tst_res(TFAIL, "Q_XQUOTARM to free space, delta(-%lu)", before.f_bavail - after.f_bavail);
+
+ TST_EXP_FAIL(do_quotactl(fd, QCMD(Q_XQUOTARM, USRQUOTA), tst_device->dev, 0,
+ (void *)&invalid_type), EINVAL, "do_quotactl(Q_XQUOTARM, invalid_type)");
}
static void setup(void)
{
- TEST(quotactl(QCMD(Q_XQUOTAOFF, USRQUOTA), tst_device->dev, 0, (void *)&qflag_acct));
- if (TST_RET == -1)
- tst_brk(TBROK | TTERRNO, "quotactl with Q_XQUOTAOFF failed");
+ quotactl_info();
+
+ /* ensure superblock has quota data, but not running */
+ SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, "usrquota");
+ mount_flag = 1;
+ SAFE_UMOUNT(MNTPOINT);
+ mount_flag = 0;
+ SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, "noquota");
+ mount_flag = 1;
- TEST(quotactl(QCMD(Q_XQUOTARM, USRQUOTA), tst_device->dev, 0, (void *)&valid_type));
- if (TST_ERR == EINVAL)
- tst_brk(TCONF, "current system doesn't support Q_XQUOTARM, skip it");
+ fd = SAFE_OPEN(MNTPOINT, O_RDONLY);
+}
+
+static void cleanup(void)
+{
+ if (fd > -1)
+ SAFE_CLOSE(fd);
+ if (mount_flag && tst_umount(MNTPOINT))
+ tst_res(TWARN | TERRNO, "umount(%s)", MNTPOINT);
}
static struct tst_test test = {
.setup = setup,
+ .cleanup = cleanup,
.needs_root = 1,
.needs_kconfigs = (const char *[]) {
"CONFIG_XFS_QUOTA",
NULL
},
.test_all = verify_quota,
- .mount_device = 1,
+ .format_device = 1,
.dev_fs_type = "xfs",
- .mnt_data = "usrquota",
.mntpoint = MNTPOINT,
+ .test_variants = QUOTACTL_SYSCALL_VARIANTS,
.tags = (const struct tst_tag[]) {
{"linux-git", "3dd4d40b4208"},
{}
--
2.23.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [LTP] [PATCH v6 3/3] syscalls/quotactl: Make use of TST_EXP_PASS_SILENT and TST_EXP_FAIL
2022-01-12 7:48 [LTP] [PATCH v6 1/3] syscalls/quotactl09: Test error when quota info hidden in filesystem Yang Xu
2022-01-12 7:48 ` [LTP] [PATCH v6 2/3] syscalls/quotactl07: Refactor this case Yang Xu
@ 2022-01-12 7:48 ` Yang Xu
2022-01-13 14:45 ` Cyril Hrubis
2022-01-12 9:18 ` [LTP] [PATCH v6 1/3] syscalls/quotactl09: Test error when quota info hidden in filesystem xuyang2018.jy
2022-01-13 14:22 ` Cyril Hrubis
3 siblings, 1 reply; 13+ messages in thread
From: Yang Xu @ 2022-01-12 7:48 UTC (permalink / raw)
To: ltp
Also, add some description and make check happy for quotactl06.c.
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
.../kernel/syscalls/quotactl/quotactl01.c | 7 +-
.../kernel/syscalls/quotactl/quotactl02.c | 7 +-
.../kernel/syscalls/quotactl/quotactl02.h | 45 ++++------
.../kernel/syscalls/quotactl/quotactl04.c | 7 +-
.../kernel/syscalls/quotactl/quotactl05.c | 7 +-
.../kernel/syscalls/quotactl/quotactl06.c | 90 +++++++++++--------
6 files changed, 80 insertions(+), 83 deletions(-)
diff --git a/testcases/kernel/syscalls/quotactl/quotactl01.c b/testcases/kernel/syscalls/quotactl/quotactl01.c
index 1e0f5da70..561e5030f 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl01.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl01.c
@@ -196,11 +196,10 @@ static void verify_quota(unsigned int n)
tst_res(TCONF, "current system doesn't support this cmd");
return;
}
- TEST(quotactl(tc->cmd, tst_device->dev, *tc->id, tc->addr));
- if (TST_RET == -1) {
- tst_res(TFAIL | TTERRNO, "quotactl failed to %s", tc->des);
+ TST_EXP_PASS_SILENT(quotactl(tc->cmd, tst_device->dev, *tc->id, tc->addr),
+ "quotactl to %s", tc->des);
+ if (!TST_PASS)
return;
- }
if (memcmp(tc->res_data, tc->set_data, tc->sz)) {
tst_res(TFAIL, "quotactl failed to %s", tc->des);
diff --git a/testcases/kernel/syscalls/quotactl/quotactl02.c b/testcases/kernel/syscalls/quotactl/quotactl02.c
index c16e0a3f8..d9c4f9b2e 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl02.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl02.c
@@ -130,11 +130,10 @@ static void verify_quota(unsigned int n)
return;
}
- TEST(do_quotactl(fd, tc->cmd, tst_device->dev, test_id, tc->addr));
- if (TST_RET == -1) {
- tst_res(TFAIL | TTERRNO, "quotactl() failed to %s", tc->des);
+ TST_EXP_PASS_SILENT(do_quotactl(fd, tc->cmd, tst_device->dev, test_id, tc->addr),
+ "do_quotactl()");
+ if (!TST_PASS)
return;
- }
if (tc->flag)
tc->func_check(tc->check_subcmd, tc->des, *(int *)(tc->addr));
diff --git a/testcases/kernel/syscalls/quotactl/quotactl02.h b/testcases/kernel/syscalls/quotactl/quotactl02.h
index 28b632646..a5683ae7d 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl02.h
+++ b/testcases/kernel/syscalls/quotactl/quotactl02.h
@@ -49,15 +49,12 @@ static void check_support_cmd(int quotatype)
static void check_qoff(int subcmd, char *desp, int flag)
{
- int res;
struct fs_quota_stat res_qstat;
- res = do_quotactl(fd, subcmd, tst_device->dev, test_id, (void *) &res_qstat);
- if (res == -1) {
- tst_res(TFAIL | TERRNO,
- "quotactl() failed to get xfs quota off status");
+ TST_EXP_PASS_SILENT(do_quotactl(fd, subcmd, tst_device->dev, test_id,
+ (void *) &res_qstat), "do_quotactl() to %s", desp);
+ if (!TST_PASS)
return;
- }
if (res_qstat.qs_flags & flag) {
tst_res(TFAIL, "xfs quota enforcement was on unexpectedly");
@@ -69,15 +66,12 @@ static void check_qoff(int subcmd, char *desp, int flag)
static void check_qon(int subcmd, char *desp, int flag)
{
- int res;
struct fs_quota_stat res_qstat;
- res = do_quotactl(fd, subcmd, tst_device->dev, test_id, (void *) &res_qstat);
- if (res == -1) {
- tst_res(TFAIL | TERRNO,
- "quotactl() failed to get xfs quota on status");
+ TST_EXP_PASS_SILENT(do_quotactl(fd, subcmd, tst_device->dev, test_id,
+ (void *) &res_qstat), "do_quotactl() to %s", desp);
+ if (!TST_PASS)
return;
- }
if (!(res_qstat.qs_flags & flag)) {
tst_res(TFAIL, "xfs quota enforcement was off unexpectedly");
@@ -89,17 +83,14 @@ static void check_qon(int subcmd, char *desp, int flag)
static void check_qoffv(int subcmd, char *desp, int flag)
{
- int res;
struct fs_quota_statv res_qstatv = {
.qs_version = FS_QSTATV_VERSION1,
};
- res = do_quotactl(fd, subcmd, tst_device->dev, test_id, (void *) &res_qstatv);
- if (res == -1) {
- tst_res(TFAIL | TERRNO,
- "quotactl() failed to get xfs quota off stav");
+ TST_EXP_PASS_SILENT(do_quotactl(fd, subcmd, tst_device->dev, test_id,
+ (void *) &res_qstatv), "do_quotactl() to %s", desp);
+ if (!TST_PASS)
return;
- }
if (res_qstatv.qs_flags & flag) {
tst_res(TFAIL, "xfs quota enforcement was on unexpectedly");
@@ -111,17 +102,14 @@ static void check_qoffv(int subcmd, char *desp, int flag)
static void check_qonv(int subcmd, char *desp, int flag)
{
- int res;
struct fs_quota_statv res_qstatv = {
.qs_version = FS_QSTATV_VERSION1
};
- res = do_quotactl(fd, subcmd, tst_device->dev, test_id, (void *) &res_qstatv);
- if (res == -1) {
- tst_res(TFAIL | TERRNO,
- "quotactl() failed to get xfs quota on statv");
+ TST_EXP_PASS_SILENT(do_quotactl(fd, subcmd, tst_device->dev, test_id,
+ (void *) &res_qstatv), "do_quotactl() to %s", desp);
+ if (!TST_PASS)
return;
- }
if (!(res_qstatv.qs_flags & flag)) {
tst_res(TFAIL, "xfs quota enforcement was off unexpectedly");
@@ -133,17 +121,14 @@ static void check_qonv(int subcmd, char *desp, int flag)
static void check_qlim(int subcmd, char *desp)
{
- int res;
static struct fs_disk_quota res_dquota;
res_dquota.d_rtb_softlimit = 0;
- res = do_quotactl(fd, subcmd, tst_device->dev, test_id, (void *) &res_dquota);
- if (res == -1) {
- tst_res(TFAIL | TERRNO,
- "quotactl() failed to get xfs disk quota limits");
+ TST_EXP_PASS_SILENT(do_quotactl(fd, subcmd, tst_device->dev, test_id,
+ (void *) &res_dquota), "do_quotactl() to %s", desp);
+ if (!TST_PASS)
return;
- }
if (res_dquota.d_id != test_id) {
tst_res(TFAIL, "quotactl() got unexpected user id %u, expected %u",
diff --git a/testcases/kernel/syscalls/quotactl/quotactl04.c b/testcases/kernel/syscalls/quotactl/quotactl04.c
index 44273c35d..55da28270 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl04.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl04.c
@@ -145,11 +145,10 @@ static void verify_quota(unsigned int n)
tst_res(TINFO, "Test #%d: %s", n, tc->tname);
- TEST(do_quotactl(fd, tc->cmd, tst_device->dev, *tc->id, tc->addr));
- if (TST_RET == -1) {
- tst_res(TFAIL | TTERRNO, "quotactl failed to %s", tc->des);
+ TST_EXP_PASS_SILENT(do_quotactl(fd, tc->cmd, tst_device->dev, *tc->id, tc->addr),
+ "do_quotactl to %s", tc->des);
+ if (!TST_PASS)
return;
- }
if (memcmp(tc->res_data, tc->set_data, tc->sz)) {
tst_res(TFAIL, "quotactl failed to %s", tc->des);
diff --git a/testcases/kernel/syscalls/quotactl/quotactl05.c b/testcases/kernel/syscalls/quotactl/quotactl05.c
index 541007e97..ac75cee31 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl05.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl05.c
@@ -93,11 +93,10 @@ static void verify_quota(unsigned int n)
return;
}
- TEST(do_quotactl(fd, tc->cmd, tst_device->dev, test_id, tc->addr));
- if (TST_RET == -1) {
- tst_res(TFAIL | TTERRNO, "quotactl() failed to %s", tc->des);
+ TST_EXP_PASS_SILENT(do_quotactl(fd, tc->cmd, tst_device->dev, test_id, tc->addr),
+ "do_quotactl()");
+ if (!TST_PASS)
return;
- }
if (tc->flag)
tc->func_check(tc->check_subcmd, tc->des, *(int *)(tc->addr));
diff --git a/testcases/kernel/syscalls/quotactl/quotactl06.c b/testcases/kernel/syscalls/quotactl/quotactl06.c
index 21a86ad1e..9206cc3e4 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl06.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl06.c
@@ -12,7 +12,7 @@
*
* - EACCES when cmd is Q_QUOTAON and addr existed but not a regular file
* - ENOENT when the file specified by special or addr does not exist
- * - EBUSTY when cmd is Q_QUOTAON and another Q_QUOTAON had already been performed
+ * - EBUSY when cmd is Q_QUOTAON and another Q_QUOTAON had already been performed
* - EFAULT when addr or special is invalid
* - EINVAL when cmd or type is invalid
* - ENOTBLK when special is not a block device
@@ -68,13 +68,13 @@ static struct dqblk set_dqmax = {
.dqb_valid = QIF_BLIMITS
};
-struct tst_cap dropadmin = {
+static struct tst_cap dropadmin = {
.action = TST_CAP_DROP,
.id = CAP_SYS_ADMIN,
.name = "CAP_SYS_ADMIN",
};
-struct tst_cap needadmin = {
+static struct tst_cap needadmin = {
.action = TST_CAP_REQ,
.id = CAP_SYS_ADMIN,
.name = "CAP_SYS_ADMIN",
@@ -86,18 +86,44 @@ static struct tcase {
void *addr;
int exp_err;
int on_flag;
+ char *des;
} tcases[] = {
- {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, testdir1, EACCES, 0},
- {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, testdir2, ENOENT, 0},
- {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, usrpath, EBUSY, 1},
- {QCMD(Q_SETQUOTA, USRQUOTA), &fmt_id, NULL, EFAULT, 1},
- {QCMD(OPTION_INVALID, USRQUOTA), &fmt_id, usrpath, EINVAL, 0},
- {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, usrpath, ENOTBLK, 0},
- {QCMD(Q_SETQUOTA, USRQUOTA), &test_id, &set_dq, ESRCH, 0},
- {QCMD(Q_QUOTAON, USRQUOTA), &fmt_invalid, usrpath, ESRCH, 0},
- {QCMD(Q_GETNEXTQUOTA, USRQUOTA), &test_invalid, usrpath, ESRCH, 0},
- {QCMD(Q_SETQUOTA, USRQUOTA), &test_id, &set_dqmax, ERANGE, 1},
- {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, usrpath, EPERM, 0},
+ {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, testdir1, EACCES, 0,
+ "EACCES when cmd is Q_QUOTAON and addr existed but not a regular file"},
+
+ {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, testdir2, ENOENT, 0,
+ "ENOENT when the file specified by special or addr does not exist"},
+
+ {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, usrpath, EBUSY, 1,
+ "EBUSY when cmd is Q_QUOTAON and another Q_QUOTAON had already been performed"},
+
+ {QCMD(Q_SETQUOTA, USRQUOTA), &fmt_id, NULL, EFAULT, 1,
+ "EFAULT when addr or special is invalid"},
+
+ {QCMD(OPTION_INVALID, USRQUOTA), &fmt_id, usrpath, EINVAL, 0,
+ "EINVAL when cmd or type is invalid"},
+
+ {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, usrpath, ENOTBLK, 0,
+ "ENOTBLK when special is not a block device"},
+
+ {QCMD(Q_SETQUOTA, USRQUOTA), &test_id, &set_dq, ESRCH, 0,
+ "ESRCH when no disk quota is found for the indicated user and quotas "
+ "have not been turned on for this fs"},
+
+ {QCMD(Q_QUOTAON, USRQUOTA), &fmt_invalid, usrpath, ESRCH, 0,
+ "ESRCH when cmd is Q_QUOTAON, but the quota format was not found"},
+
+ {QCMD(Q_GETNEXTQUOTA, USRQUOTA), &test_invalid, usrpath, ESRCH, 0,
+ "ESRCH when cmd is Q_GETNEXTQUOTA, but there is no ID greater than or "
+ "equal to id that has an active quota"},
+
+ {QCMD(Q_SETQUOTA, USRQUOTA), &test_id, &set_dqmax, ERANGE, 1,
+ "ERANGE when cmd is Q_SETQUOTA, but the specified limits are out of "
+ "the range allowed by the quota format"},
+
+ {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, usrpath, EPERM, 0,
+ "EPERM when the caller lacked the required privilege (CAP_SYS_ADMIN) "
+ "for the specified operation"},
};
static void verify_quotactl(unsigned int n)
@@ -106,17 +132,17 @@ static void verify_quotactl(unsigned int n)
int quota_on = 0;
int drop_flag = 0;
+ tst_res(TINFO, "Testing %s", tc->des);
if (tc->cmd == QCMD(Q_GETNEXTQUOTA, USRQUOTA) && getnextquota_nsup) {
tst_res(TCONF, "current system doesn't support Q_GETNEXTQUOTA");
return;
}
if (tc->on_flag) {
- TEST(quotactl(QCMD(Q_QUOTAON, USRQUOTA), tst_device->dev,
- fmt_id, usrpath));
- if (TST_RET == -1)
- tst_brk(TBROK,
- "quotactl with Q_QUOTAON returned %ld", TST_RET);
+ TST_EXP_PASS_SILENT(quotactl(QCMD(Q_QUOTAON, USRQUOTA), tst_device->dev,
+ fmt_id, usrpath), "quotactl with Q_QUOTAON");
+ if (!TST_PASS)
+ return;
quota_on = 1;
}
@@ -126,27 +152,17 @@ static void verify_quotactl(unsigned int n)
}
if (tc->exp_err == ENOTBLK)
- TEST(quotactl(tc->cmd, "/dev/null", *tc->id, tc->addr));
+ TST_EXP_FAIL(quotactl(tc->cmd, "/dev/null", *tc->id, tc->addr),
+ ENOTBLK, "quotactl()");
else
- TEST(quotactl(tc->cmd, tst_device->dev, *tc->id, tc->addr));
- if (TST_RET == -1) {
- if (tc->exp_err == TST_ERR) {
- tst_res(TPASS | TTERRNO, "quotactl failed as expected");
- } else {
- tst_res(TFAIL | TTERRNO,
- "quotactl failed unexpectedly; expected %s, but got",
- tst_strerrno(tc->exp_err));
- }
- } else {
- tst_res(TFAIL, "quotactl returned wrong value: %ld", TST_RET);
- }
+ TST_EXP_FAIL(quotactl(tc->cmd, tst_device->dev, *tc->id, tc->addr),
+ tc->exp_err, "quotactl()");
if (quota_on) {
- TEST(quotactl(QCMD(Q_QUOTAOFF, USRQUOTA), tst_device->dev,
- fmt_id, usrpath));
- if (TST_RET == -1)
- tst_brk(TBROK,
- "quotactl with Q_QUOTAOFF returned %ld", TST_RET);
+ TST_EXP_PASS_SILENT(quotactl(QCMD(Q_QUOTAOFF, USRQUOTA), tst_device->dev,
+ fmt_id, usrpath), "quotactl with Q_QUOTAOFF");
+ if (!TST_PASS)
+ return;
quota_on = 0;
}
--
2.23.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH v6 1/3] syscalls/quotactl09: Test error when quota info hidden in filesystem
2022-01-12 7:48 [LTP] [PATCH v6 1/3] syscalls/quotactl09: Test error when quota info hidden in filesystem Yang Xu
2022-01-12 7:48 ` [LTP] [PATCH v6 2/3] syscalls/quotactl07: Refactor this case Yang Xu
2022-01-12 7:48 ` [LTP] [PATCH v6 3/3] syscalls/quotactl: Make use of TST_EXP_PASS_SILENT and TST_EXP_FAIL Yang Xu
@ 2022-01-12 9:18 ` xuyang2018.jy
2022-01-12 9:46 ` Cyril Hrubis
2022-01-13 14:22 ` Cyril Hrubis
3 siblings, 1 reply; 13+ messages in thread
From: xuyang2018.jy @ 2022-01-12 9:18 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi Cyril
As your suggestion, I modify this patch as below
diff --git a/testcases/kernel/syscalls/quotactl/quotactl09.c
b/testcases/kernel/syscalls/quotactl/quotactl09.c
index 79f506bdc..4dbfcc7ea 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl09.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl09.c
@@ -17,14 +17,14 @@
* allowed by the quota format
* - EPERM when the caller lacked the required privilege
(CAP_SYS_ADMIN) for the
* specified operation
- * - EINVAL when cmd is Q_QUOTAON, but the fd refers to a regular
file(doesn't
- * under this moutpoint)
+ * - ENOSYS when cmd is Q_QUOTAON, but the fd refers to a socket
*
* Minimum e2fsprogs version required is 1.43.
*/
#include <errno.h>
#include <sys/quota.h>
+#include <sys/socket.h>
#include "tst_test.h"
#include "tst_capability.h"
#include "quotactl_syscall_var.h"
@@ -33,7 +33,7 @@
static int32_t fmt_id = QFMT_VFS_V1;
static int test_id, mount_flag;
-static int getnextquota_nsup, external_fd = -1;
+static int getnextquota_nsup, socket_fd = -1;
static struct if_nextdqblk res_ndq;
@@ -60,27 +60,25 @@ static struct tcase {
void *addr;
int exp_err;
int on_flag;
- int use_external_fd;
char *des;
} tcases[] = {
- {QCMD(Q_SETQUOTA, USRQUOTA), &fmt_id, NULL, EFAULT, 1, 0,
+ {QCMD(Q_SETQUOTA, USRQUOTA), &fmt_id, NULL, EFAULT, 1,
"EFAULT when addr or special is invalid"},
- {QCMD(OPTION_INVALID, USRQUOTA), &fmt_id, NULL, EINVAL, 0, 0,
+ {QCMD(OPTION_INVALID, USRQUOTA), &fmt_id, NULL, EINVAL, 0,
"EINVAL when cmd or type is invalid"},
- {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, NULL, ENOTBLK, 0, 0,
+ {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, NULL, ENOTBLK, 0,
"ENOTBLK when special is not a block device"},
- {QCMD(Q_SETQUOTA, USRQUOTA), &test_id, &set_dqmax, ERANGE, 1, 0,
+ {QCMD(Q_SETQUOTA, USRQUOTA), &test_id, &set_dqmax, ERANGE, 1,
"ERANGE when cmd is Q_SETQUOTA, but the specified limits are out
of the range"},
- {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, NULL, EPERM, 0, 0,
+ {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, NULL, EPERM, 0,
"EPERM when the caller lacked the required privilege for
specified operations"},
- {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, NULL, EINVAL, 0, 1,
- "EINVAL when cmd is Q_QUOTAON, but the fd refers to a regular
file(doesn't under"
- "this mountpoint)"}
+ {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, NULL, ENOSYS, 0,
+ "ENOSYS when cmd is Q_QUOTAON, but the fd refers to a socket"}
};
static void verify_quotactl(unsigned int n)
@@ -113,8 +111,12 @@ static void verify_quotactl(unsigned int n)
tst_res(TCONF, "quotactl_fd() doesn't have this
error, skip");
return;
}
+ if (tc->exp_err == ENOSYS) {
+ TST_EXP_FAIL(syscall(__NR_quotactl_fd,
socket_fd, tc->cmd, *tc->id, tc->addr), tc->exp_err,
"syscall(quotactl_fd)");
+ return;
+ }
} else {
- if (tc->use_external_fd) {
+ if (tc->exp_err == ENOSYS) {
tst_res(TCONF, "quotactl() doesn't use fd, skip");
return;
}
@@ -123,8 +125,8 @@ static void verify_quotactl(unsigned int n)
TST_EXP_FAIL(do_quotactl(fd, tc->cmd, "/dev/null",
*tc->id, tc->addr),
ENOTBLK, "do_quotactl()");
else
- TST_EXP_FAIL(do_quotactl(tc->use_external_fd ?
external_fd : fd, tc->cmd,
- tst_device->dev, *tc->id, tc->addr),
tc->exp_err, "do_quotactl()");
+ TST_EXP_FAIL(do_quotactl(fd, tc->cmd, tst_device->dev,
*tc->id, tc->addr),
+ tc->exp_err, "do_quotactl()");
if (quota_on) {
TST_EXP_PASS_SILENT(do_quotactl(fd, QCMD(Q_QUOTAOFF,
USRQUOTA), tst_device->dev,
@@ -146,12 +148,11 @@ static void setup(void)
const char *const fs_opts[] = { "-O quota", NULL};
quotactl_info();
- external_fd = SAFE_CREAT("testfile", O_RDONLY);
SAFE_MKFS(tst_device->dev, tst_device->fs_type, fs_opts, NULL);
SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL);
mount_flag = 1;
-
+ socket_fd = SAFE_SOCKET(PF_INET, SOCK_STREAM, 0);
fd = SAFE_OPEN(MNTPOINT, O_RDONLY);
TEST(do_quotactl(fd, QCMD(Q_GETNEXTQUOTA, USRQUOTA),
tst_device->dev,
test_id, (void *) &res_ndq));
@@ -168,8 +169,8 @@ static void cleanup(void)
{
if (fd > -1)
SAFE_CLOSE(fd);
- if (external_fd > -1)
- SAFE_CLOSE(external_fd);
+ if (socket_fd > -1)
+ SAFE_CLOSE(socket_fd);
if (mount_flag && tst_umount(MNTPOINT))
tst_res(TWARN | TERRNO, "umount(%s)", MNTPOINT);
How about this patch after this change?
Best Regards
Yang Xu
> This case is similar to quotactl06 but only some differences
> 1) use quotactl and quotactl_fd syscalls without visible quota file
> 2) remove some error for addr argument
> 3) test external_fd for quotactl_fd for EINVAL error when using Q_QUOTAON
> 4) add error case description when running
>
> Signed-off-by: Yang Xu<xuyang2018.jy@fujitsu.com>
> ---
> runtest/syscalls | 1 +
> testcases/kernel/syscalls/quotactl/.gitignore | 1 +
> .../kernel/syscalls/quotactl/quotactl09.c | 195 ++++++++++++++++++
> 3 files changed, 197 insertions(+)
> create mode 100644 testcases/kernel/syscalls/quotactl/quotactl09.c
>
> diff --git a/runtest/syscalls b/runtest/syscalls
> index a0ca84b36..3b2deb64e 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -1073,6 +1073,7 @@ quotactl05 quotactl05
> quotactl06 quotactl06
> quotactl07 quotactl07
> quotactl08 quotactl08
> +quotactl09 quotactl09
>
> read01 read01
> read02 read02
> diff --git a/testcases/kernel/syscalls/quotactl/.gitignore b/testcases/kernel/syscalls/quotactl/.gitignore
> index dab9b3420..94de2c8f2 100644
> --- a/testcases/kernel/syscalls/quotactl/.gitignore
> +++ b/testcases/kernel/syscalls/quotactl/.gitignore
> @@ -6,3 +6,4 @@
> /quotactl06
> /quotactl07
> /quotactl08
> +/quotactl09
> diff --git a/testcases/kernel/syscalls/quotactl/quotactl09.c b/testcases/kernel/syscalls/quotactl/quotactl09.c
> new file mode 100644
> index 000000000..79f506bdc
> --- /dev/null
> +++ b/testcases/kernel/syscalls/quotactl/quotactl09.c
> @@ -0,0 +1,195 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
> + * Author: Yang Xu<xuyang2018.jy@fujitsu.com>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * Tests basic error handling of the quotactl syscall without visible quota files
> + * (use quotactl and quotactl_fd syscall):
> + *
> + * - EFAULT when addr or special is invalid
> + * - EINVAL when cmd or type is invalid
> + * - ENOTBLK when special is not a block device
> + * - ERANGE when cmd is Q_SETQUOTA, but the specified limits are out of the range
> + * allowed by the quota format
> + * - EPERM when the caller lacked the required privilege (CAP_SYS_ADMIN) for the
> + * specified operation
> + * - EINVAL when cmd is Q_QUOTAON, but the fd refers to a regular file(doesn't
> + * under this moutpoint)
> + *
> + * Minimum e2fsprogs version required is 1.43.
> + */
> +
> +#include<errno.h>
> +#include<sys/quota.h>
> +#include "tst_test.h"
> +#include "tst_capability.h"
> +#include "quotactl_syscall_var.h"
> +
> +#define OPTION_INVALID 999
> +
> +static int32_t fmt_id = QFMT_VFS_V1;
> +static int test_id, mount_flag;
> +static int getnextquota_nsup, external_fd = -1;
> +
> +static struct if_nextdqblk res_ndq;
> +
> +static struct dqblk set_dqmax = {
> + .dqb_bsoftlimit = 0x7fffffffffffffffLL, /* 2^63-1 */
> + .dqb_valid = QIF_BLIMITS
> +};
> +
> +static struct tst_cap dropadmin = {
> + .action = TST_CAP_DROP,
> + .id = CAP_SYS_ADMIN,
> + .name = "CAP_SYS_ADMIN",
> +};
> +
> +static struct tst_cap needadmin = {
> + .action = TST_CAP_REQ,
> + .id = CAP_SYS_ADMIN,
> + .name = "CAP_SYS_ADMIN",
> +};
> +
> +static struct tcase {
> + int cmd;
> + int *id;
> + void *addr;
> + int exp_err;
> + int on_flag;
> + int use_external_fd;
> + char *des;
> +} tcases[] = {
> + {QCMD(Q_SETQUOTA, USRQUOTA),&fmt_id, NULL, EFAULT, 1, 0,
> + "EFAULT when addr or special is invalid"},
> +
> + {QCMD(OPTION_INVALID, USRQUOTA),&fmt_id, NULL, EINVAL, 0, 0,
> + "EINVAL when cmd or type is invalid"},
> +
> + {QCMD(Q_QUOTAON, USRQUOTA),&fmt_id, NULL, ENOTBLK, 0, 0,
> + "ENOTBLK when special is not a block device"},
> +
> + {QCMD(Q_SETQUOTA, USRQUOTA),&test_id,&set_dqmax, ERANGE, 1, 0,
> + "ERANGE when cmd is Q_SETQUOTA, but the specified limits are out of the range"},
> +
> + {QCMD(Q_QUOTAON, USRQUOTA),&fmt_id, NULL, EPERM, 0, 0,
> + "EPERM when the caller lacked the required privilege for specified operations"},
> +
> + {QCMD(Q_QUOTAON, USRQUOTA),&fmt_id, NULL, EINVAL, 0, 1,
> + "EINVAL when cmd is Q_QUOTAON, but the fd refers to a regular file(doesn't under "
> + "this mountpoint)"}
> +};
> +
> +static void verify_quotactl(unsigned int n)
> +{
> + struct tcase *tc =&tcases[n];
> + int quota_on = 0;
> + int drop_flag = 0;
> +
> + tst_res(TINFO, "Testing %s", tc->des);
> + if (tc->cmd == QCMD(Q_GETNEXTQUOTA, USRQUOTA)&& getnextquota_nsup) {
> + tst_res(TCONF, "current system doesn't support Q_GETNEXTQUOTA");
> + return;
> + }
> +
> + if (tc->on_flag) {
> + TST_EXP_PASS_SILENT(do_quotactl(fd, QCMD(Q_QUOTAON, USRQUOTA), tst_device->dev,
> + fmt_id, NULL), "do_quotactl(QCMD(Q_QUOTAON, USRQUOTA))");
> + if (!TST_PASS)
> + return;
> + quota_on = 1;
> + }
> +
> + if (tc->exp_err == EPERM) {
> + tst_cap_action(&dropadmin);
> + drop_flag = 1;
> + }
> +
> + if (tst_variant) {
> + if (tc->exp_err == ENOTBLK) {
> + tst_res(TCONF, "quotactl_fd() doesn't have this error, skip");
> + return;
> + }
> + } else {
> + if (tc->use_external_fd) {
> + tst_res(TCONF, "quotactl() doesn't use fd, skip");
> + return;
> + }
> + }
> + if (tc->exp_err == ENOTBLK)
> + TST_EXP_FAIL(do_quotactl(fd, tc->cmd, "/dev/null", *tc->id, tc->addr),
> + ENOTBLK, "do_quotactl()");
> + else
> + TST_EXP_FAIL(do_quotactl(tc->use_external_fd ? external_fd : fd, tc->cmd,
> + tst_device->dev, *tc->id, tc->addr), tc->exp_err, "do_quotactl()");
> +
> + if (quota_on) {
> + TST_EXP_PASS_SILENT(do_quotactl(fd, QCMD(Q_QUOTAOFF, USRQUOTA), tst_device->dev,
> + fmt_id, NULL), "do_quotactl(QCMD(Q_QUOTAOFF, USRQUOTA)");
> + if (!TST_PASS)
> + return;
> + quota_on = 0;
> + }
> +
> + if (drop_flag) {
> + tst_cap_action(&needadmin);
> + drop_flag = 0;
> + }
> +}
> +
> +static void setup(void)
> +{
> + unsigned int i;
> + const char *const fs_opts[] = { "-O quota", NULL};
> +
> + quotactl_info();
> + external_fd = SAFE_CREAT("testfile", O_RDONLY);
> +
> + SAFE_MKFS(tst_device->dev, tst_device->fs_type, fs_opts, NULL);
> + SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL);
> + mount_flag = 1;
> +
> + fd = SAFE_OPEN(MNTPOINT, O_RDONLY);
> + TEST(do_quotactl(fd, QCMD(Q_GETNEXTQUOTA, USRQUOTA), tst_device->dev,
> + test_id, (void *)&res_ndq));
> + if (TST_ERR == EINVAL || TST_ERR == ENOSYS)
> + getnextquota_nsup = 1;
> +
> + for (i = 0; i< ARRAY_SIZE(tcases); i++) {
> + if (!tcases[i].addr)
> + tcases[i].addr = tst_get_bad_addr(NULL);
> + }
> +}
> +
> +static void cleanup(void)
> +{
> + if (fd> -1)
> + SAFE_CLOSE(fd);
> + if (external_fd> -1)
> + SAFE_CLOSE(external_fd);
> + if (mount_flag&& tst_umount(MNTPOINT))
> + tst_res(TWARN | TERRNO, "umount(%s)", MNTPOINT);
> +}
> +
> +static struct tst_test test = {
> + .setup = setup,
> + .cleanup = cleanup,
> + .needs_kconfigs = (const char *[]) {
> + "CONFIG_QFMT_V2",
> + NULL
> + },
> + .tcnt = ARRAY_SIZE(tcases),
> + .test = verify_quotactl,
> + .dev_fs_type = "ext4",
> + .mntpoint = MNTPOINT,
> + .needs_device = 1,
> + .needs_root = 1,
> + .test_variants = QUOTACTL_SYSCALL_VARIANTS,
> + .needs_cmds = (const char *[]) {
> + "mkfs.ext4>= 1.43.0",
> + NULL
> + }
> +};
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH v6 1/3] syscalls/quotactl09: Test error when quota info hidden in filesystem
2022-01-12 9:18 ` [LTP] [PATCH v6 1/3] syscalls/quotactl09: Test error when quota info hidden in filesystem xuyang2018.jy
@ 2022-01-12 9:46 ` Cyril Hrubis
2022-01-13 6:51 ` xuyang2018.jy
0 siblings, 1 reply; 13+ messages in thread
From: Cyril Hrubis @ 2022-01-12 9:46 UTC (permalink / raw)
To: xuyang2018.jy; +Cc: ltp
Hi!
> How about this patch after this change?
Looks reasonable.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH v6 1/3] syscalls/quotactl09: Test error when quota info hidden in filesystem
2022-01-12 9:46 ` Cyril Hrubis
@ 2022-01-13 6:51 ` xuyang2018.jy
2022-01-13 9:49 ` Cyril Hrubis
0 siblings, 1 reply; 13+ messages in thread
From: xuyang2018.jy @ 2022-01-13 6:51 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi Cyril
> Hi!
>> How about this patch after this change?
>
> Looks reasonable.
So do you have some comments for other two quotactl patches? or add RVB tag?
ps: I want to make them merged in ltp before this release.
Best Regargds
Yang Xu
>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH v6 1/3] syscalls/quotactl09: Test error when quota info hidden in filesystem
2022-01-13 6:51 ` xuyang2018.jy
@ 2022-01-13 9:49 ` Cyril Hrubis
0 siblings, 0 replies; 13+ messages in thread
From: Cyril Hrubis @ 2022-01-13 9:49 UTC (permalink / raw)
To: xuyang2018.jy; +Cc: ltp
Hi!
> >> How about this patch after this change?
> >
> > Looks reasonable.
> So do you have some comments for other two quotactl patches? or add RVB tag?
>
> ps: I want to make them merged in ltp before this release.
I will have a look today, I had half day off yesterday and haven't
managed to get to them.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH v6 2/3] syscalls/quotactl07: Refactor this case
2022-01-12 7:48 ` [LTP] [PATCH v6 2/3] syscalls/quotactl07: Refactor this case Yang Xu
@ 2022-01-13 14:03 ` Cyril Hrubis
2022-01-14 3:29 ` xuyang2018.jy
0 siblings, 1 reply; 13+ messages in thread
From: Cyril Hrubis @ 2022-01-13 14:03 UTC (permalink / raw)
To: Yang Xu; +Cc: ltp
Hi!
> diff --git a/testcases/kernel/syscalls/quotactl/quotactl07.c b/testcases/kernel/syscalls/quotactl/quotactl07.c
> index 2992a6112..2427ef682 100644
> --- a/testcases/kernel/syscalls/quotactl/quotactl07.c
> +++ b/testcases/kernel/syscalls/quotactl/quotactl07.c
> @@ -7,7 +7,9 @@
> /*\
> * [Description]
> *
> - * This is a regresstion test for kernel commit 3dd4d40b4208
> + * This is not only a functional test but also a error test for Q_XQUOTARM.
> + *
> + * It is a regresstion test for kernel commit 3dd4d40b4208
> * ("xfs: Sanity check flags of Q_XQUOTARM call").
> */
>
> @@ -15,51 +17,71 @@
> #include <unistd.h>
> #include <stdio.h>
> #include <sys/quota.h>
> +#include <sys/statvfs.h>
> #include "tst_test.h"
> -#include "lapi/quotactl.h"
> +#include "quotactl_syscall_var.h"
>
> #ifdef HAVE_XFS_XQM_H
> # include <xfs/xqm.h>
>
> -#define MNTPOINT "mntpoint"
> -
> -static uint32_t qflag_acct = XFS_QUOTA_UDQ_ACCT;
> -static unsigned int valid_type = XFS_USER_QUOTA;
> /* Include a valid quota type to avoid other EINVAL error */
> static unsigned int invalid_type = XFS_GROUP_QUOTA << 1 | XFS_USER_QUOTA;
> +static unsigned int valid_type = XFS_USER_QUOTA;
> +static int mount_flag;
>
> static void verify_quota(void)
> {
> - TEST(quotactl(QCMD(Q_XQUOTARM, USRQUOTA), tst_device->dev, 0, (void *)&invalid_type));
> - if (TST_ERR == EINVAL)
> - tst_res(TPASS, "Q_XQUOTARM has quota type check");
> + struct statfs before, after;
> +
> + SAFE_STATFS(MNTPOINT, &before);
> + TST_EXP_PASS(do_quotactl(fd, QCMD(Q_XQUOTARM, USRQUOTA), tst_device->dev, 0,
> + (void *)&valid_type), "do_quotactl(Q_XQUOTARM,valid_type)");
> + SAFE_STATFS(MNTPOINT, &after);
> + if (before.f_bavail <= after.f_bavail)
> + tst_res(TPASS, "Q_XQUOTARM to free space, delta(%lu)", after.f_bavail - before.f_bavail);
> else
> - tst_res(TFAIL, "Q_XQUOTARM doesn't have quota type check");
> + tst_res(TFAIL, "Q_XQUOTARM to free space, delta(-%lu)", before.f_bavail - after.f_bavail);
> +
> + TST_EXP_FAIL(do_quotactl(fd, QCMD(Q_XQUOTARM, USRQUOTA), tst_device->dev, 0,
> + (void *)&invalid_type), EINVAL, "do_quotactl(Q_XQUOTARM, invalid_type)");
> }
>
> static void setup(void)
> {
> - TEST(quotactl(QCMD(Q_XQUOTAOFF, USRQUOTA), tst_device->dev, 0, (void *)&qflag_acct));
> - if (TST_RET == -1)
> - tst_brk(TBROK | TTERRNO, "quotactl with Q_XQUOTAOFF failed");
> + quotactl_info();
> +
> + /* ensure superblock has quota data, but not running */
> + SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, "usrquota");
> + mount_flag = 1;
> + SAFE_UMOUNT(MNTPOINT);
> + mount_flag = 0;
> + SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, "noquota");
> + mount_flag = 1;
Maybe just SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, "remount, noquota") ?
If we can remount the device without umounting it the code would be a
bit shorter.
Anyways looks good to me:
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH v6 1/3] syscalls/quotactl09: Test error when quota info hidden in filesystem
2022-01-12 7:48 [LTP] [PATCH v6 1/3] syscalls/quotactl09: Test error when quota info hidden in filesystem Yang Xu
` (2 preceding siblings ...)
2022-01-12 9:18 ` [LTP] [PATCH v6 1/3] syscalls/quotactl09: Test error when quota info hidden in filesystem xuyang2018.jy
@ 2022-01-13 14:22 ` Cyril Hrubis
2022-01-14 2:27 ` xuyang2018.jy
3 siblings, 1 reply; 13+ messages in thread
From: Cyril Hrubis @ 2022-01-13 14:22 UTC (permalink / raw)
To: Yang Xu; +Cc: ltp
Hi!
> +/*\
> + * [Description]
> + *
> + * Tests basic error handling of the quotactl syscall without visible quota files
> + * (use quotactl and quotactl_fd syscall):
> + *
> + * - EFAULT when addr or special is invalid
> + * - EINVAL when cmd or type is invalid
> + * - ENOTBLK when special is not a block device
> + * - ERANGE when cmd is Q_SETQUOTA, but the specified limits are out of the range
> + * allowed by the quota format
> + * - EPERM when the caller lacked the required privilege (CAP_SYS_ADMIN) for the
> + * specified operation
> + * - EINVAL when cmd is Q_QUOTAON, but the fd refers to a regular file(doesn't
> + * under this moutpoint)
> + *
> + * Minimum e2fsprogs version required is 1.43.
> + */
> +
> +#include <errno.h>
> +#include <sys/quota.h>
> +#include "tst_test.h"
> +#include "tst_capability.h"
> +#include "quotactl_syscall_var.h"
> +
> +#define OPTION_INVALID 999
> +
> +static int32_t fmt_id = QFMT_VFS_V1;
> +static int test_id, mount_flag;
> +static int getnextquota_nsup, external_fd = -1;
> +
> +static struct if_nextdqblk res_ndq;
> +
> +static struct dqblk set_dqmax = {
> + .dqb_bsoftlimit = 0x7fffffffffffffffLL, /* 2^63-1 */
> + .dqb_valid = QIF_BLIMITS
> +};
> +
> +static struct tst_cap dropadmin = {
> + .action = TST_CAP_DROP,
> + .id = CAP_SYS_ADMIN,
> + .name = "CAP_SYS_ADMIN",
> +};
> +
> +static struct tst_cap needadmin = {
> + .action = TST_CAP_REQ,
> + .id = CAP_SYS_ADMIN,
> + .name = "CAP_SYS_ADMIN",
> +};
> +
> +static struct tcase {
> + int cmd;
> + int *id;
> + void *addr;
> + int exp_err;
> + int on_flag;
> + int use_external_fd;
> + char *des;
> +} tcases[] = {
> + {QCMD(Q_SETQUOTA, USRQUOTA), &fmt_id, NULL, EFAULT, 1, 0,
> + "EFAULT when addr or special is invalid"},
> +
> + {QCMD(OPTION_INVALID, USRQUOTA), &fmt_id, NULL, EINVAL, 0, 0,
> + "EINVAL when cmd or type is invalid"},
> +
> + {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, NULL, ENOTBLK, 0, 0,
> + "ENOTBLK when special is not a block device"},
> +
> + {QCMD(Q_SETQUOTA, USRQUOTA), &test_id, &set_dqmax, ERANGE, 1, 0,
> + "ERANGE when cmd is Q_SETQUOTA, but the specified limits are out of the range"},
> +
> + {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, NULL, EPERM, 0, 0,
> + "EPERM when the caller lacked the required privilege for specified operations"},
> +
> + {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, NULL, EINVAL, 0, 1,
> + "EINVAL when cmd is Q_QUOTAON, but the fd refers to a regular file(doesn't under "
> + "this mountpoint)"}
> +};
> +
> +static void verify_quotactl(unsigned int n)
> +{
> + struct tcase *tc = &tcases[n];
> + int quota_on = 0;
> + int drop_flag = 0;
> +
> + tst_res(TINFO, "Testing %s", tc->des);
> + if (tc->cmd == QCMD(Q_GETNEXTQUOTA, USRQUOTA) && getnextquota_nsup) {
> + tst_res(TCONF, "current system doesn't support Q_GETNEXTQUOTA");
> + return;
> + }
> +
> + if (tc->on_flag) {
> + TST_EXP_PASS_SILENT(do_quotactl(fd, QCMD(Q_QUOTAON, USRQUOTA), tst_device->dev,
> + fmt_id, NULL), "do_quotactl(QCMD(Q_QUOTAON, USRQUOTA))");
> + if (!TST_PASS)
> + return;
> + quota_on = 1;
> + }
> +
> + if (tc->exp_err == EPERM) {
> + tst_cap_action(&dropadmin);
> + drop_flag = 1;
> + }
> +
> + if (tst_variant) {
> + if (tc->exp_err == ENOTBLK) {
> + tst_res(TCONF, "quotactl_fd() doesn't have this error, skip");
> + return;
> + }
> + } else {
> + if (tc->use_external_fd) {
> + tst_res(TCONF, "quotactl() doesn't use fd, skip");
> + return;
> + }
> + }
> + if (tc->exp_err == ENOTBLK)
> + TST_EXP_FAIL(do_quotactl(fd, tc->cmd, "/dev/null", *tc->id, tc->addr),
> + ENOTBLK, "do_quotactl()");
> + else
> + TST_EXP_FAIL(do_quotactl(tc->use_external_fd ? external_fd : fd, tc->cmd,
> + tst_device->dev, *tc->id, tc->addr), tc->exp_err, "do_quotactl()");
> +
> + if (quota_on) {
> + TST_EXP_PASS_SILENT(do_quotactl(fd, QCMD(Q_QUOTAOFF, USRQUOTA), tst_device->dev,
> + fmt_id, NULL), "do_quotactl(QCMD(Q_QUOTAOFF, USRQUOTA)");
> + if (!TST_PASS)
> + return;
> + quota_on = 0;
There is no need to clear this flag.
> + }
> +
> + if (drop_flag) {
> + tst_cap_action(&needadmin);
> + drop_flag = 0;
And this flag.
> + }
> +}
> +
> +static void setup(void)
> +{
> + unsigned int i;
> + const char *const fs_opts[] = { "-O quota", NULL};
> +
> + quotactl_info();
> + external_fd = SAFE_CREAT("testfile", O_RDONLY);
> +
> + SAFE_MKFS(tst_device->dev, tst_device->fs_type, fs_opts, NULL);
> + SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL);
Why don't we pass the fs_opts in tst_test instead and use .mount_device = 1?
Should be as easy as:
static struct tst_test test = {
...
.dev_fs_opts = (const char *const []){"-O quota", NULL},
.mount_device = 1,
...
};
Or is there a reason why this wouldn't work?
With the changes outlined in the other email and the minor issues I've
pointed out here fixed:
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH v6 3/3] syscalls/quotactl: Make use of TST_EXP_PASS_SILENT and TST_EXP_FAIL
2022-01-12 7:48 ` [LTP] [PATCH v6 3/3] syscalls/quotactl: Make use of TST_EXP_PASS_SILENT and TST_EXP_FAIL Yang Xu
@ 2022-01-13 14:45 ` Cyril Hrubis
2022-01-14 3:58 ` xuyang2018.jy
0 siblings, 1 reply; 13+ messages in thread
From: Cyril Hrubis @ 2022-01-13 14:45 UTC (permalink / raw)
To: Yang Xu; +Cc: ltp
Hi!
> } tcases[] = {
> - {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, testdir1, EACCES, 0},
> - {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, testdir2, ENOENT, 0},
> - {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, usrpath, EBUSY, 1},
> - {QCMD(Q_SETQUOTA, USRQUOTA), &fmt_id, NULL, EFAULT, 1},
> - {QCMD(OPTION_INVALID, USRQUOTA), &fmt_id, usrpath, EINVAL, 0},
> - {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, usrpath, ENOTBLK, 0},
> - {QCMD(Q_SETQUOTA, USRQUOTA), &test_id, &set_dq, ESRCH, 0},
> - {QCMD(Q_QUOTAON, USRQUOTA), &fmt_invalid, usrpath, ESRCH, 0},
> - {QCMD(Q_GETNEXTQUOTA, USRQUOTA), &test_invalid, usrpath, ESRCH, 0},
> - {QCMD(Q_SETQUOTA, USRQUOTA), &test_id, &set_dqmax, ERANGE, 1},
> - {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, usrpath, EPERM, 0},
> + {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, testdir1, EACCES, 0,
> + "EACCES when cmd is Q_QUOTAON and addr existed but not a regular file"},
> +
> + {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, testdir2, ENOENT, 0,
> + "ENOENT when the file specified by special or addr does not exist"},
> +
> + {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, usrpath, EBUSY, 1,
> + "EBUSY when cmd is Q_QUOTAON and another Q_QUOTAON had already been performed"},
> +
> + {QCMD(Q_SETQUOTA, USRQUOTA), &fmt_id, NULL, EFAULT, 1,
> + "EFAULT when addr or special is invalid"},
> +
> + {QCMD(OPTION_INVALID, USRQUOTA), &fmt_id, usrpath, EINVAL, 0,
> + "EINVAL when cmd or type is invalid"},
> +
> + {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, usrpath, ENOTBLK, 0,
> + "ENOTBLK when special is not a block device"},
> +
> + {QCMD(Q_SETQUOTA, USRQUOTA), &test_id, &set_dq, ESRCH, 0,
> + "ESRCH when no disk quota is found for the indicated user and quotas "
> + "have not been turned on for this fs"},
> +
> + {QCMD(Q_QUOTAON, USRQUOTA), &fmt_invalid, usrpath, ESRCH, 0,
> + "ESRCH when cmd is Q_QUOTAON, but the quota format was not found"},
> +
> + {QCMD(Q_GETNEXTQUOTA, USRQUOTA), &test_invalid, usrpath, ESRCH, 0,
> + "ESRCH when cmd is Q_GETNEXTQUOTA, but there is no ID greater than or "
> + "equal to id that has an active quota"},
> +
> + {QCMD(Q_SETQUOTA, USRQUOTA), &test_id, &set_dqmax, ERANGE, 1,
> + "ERANGE when cmd is Q_SETQUOTA, but the specified limits are out of "
> + "the range allowed by the quota format"},
> +
> + {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, usrpath, EPERM, 0,
> + "EPERM when the caller lacked the required privilege (CAP_SYS_ADMIN) "
> + "for the specified operation"},
These descriptions could be a bit shorter and still have the same amount
of information, for instance the last one could be shortened to just:
"EPERM when caller lacks required privilege (CAP_SYS_ADMIN)"
or
"ESRCH for Q_GETNEXTQUOTA but the id was last one"
or
"ESRCH for Q_GETNEXTQUOTA but no quota found for the user or quotas are off"
Ideally all the messages should fit into a single line less than 80
characters...
Other than that this is a nice cleanup, with the messages shortened:
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH v6 1/3] syscalls/quotactl09: Test error when quota info hidden in filesystem
2022-01-13 14:22 ` Cyril Hrubis
@ 2022-01-14 2:27 ` xuyang2018.jy
0 siblings, 0 replies; 13+ messages in thread
From: xuyang2018.jy @ 2022-01-14 2:27 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi Cyril
> Hi!
>> +/*\
>> + * [Description]
>> + *
>> + * Tests basic error handling of the quotactl syscall without visible quota files
>> + * (use quotactl and quotactl_fd syscall):
>> + *
>> + * - EFAULT when addr or special is invalid
>> + * - EINVAL when cmd or type is invalid
>> + * - ENOTBLK when special is not a block device
>> + * - ERANGE when cmd is Q_SETQUOTA, but the specified limits are out of the range
>> + * allowed by the quota format
>> + * - EPERM when the caller lacked the required privilege (CAP_SYS_ADMIN) for the
>> + * specified operation
>> + * - EINVAL when cmd is Q_QUOTAON, but the fd refers to a regular file(doesn't
>> + * under this moutpoint)
>> + *
>> + * Minimum e2fsprogs version required is 1.43.
>> + */
>> +
>> +#include<errno.h>
>> +#include<sys/quota.h>
>> +#include "tst_test.h"
>> +#include "tst_capability.h"
>> +#include "quotactl_syscall_var.h"
>> +
>> +#define OPTION_INVALID 999
>> +
>> +static int32_t fmt_id = QFMT_VFS_V1;
>> +static int test_id, mount_flag;
>> +static int getnextquota_nsup, external_fd = -1;
>> +
>> +static struct if_nextdqblk res_ndq;
>> +
>> +static struct dqblk set_dqmax = {
>> + .dqb_bsoftlimit = 0x7fffffffffffffffLL, /* 2^63-1 */
>> + .dqb_valid = QIF_BLIMITS
>> +};
>> +
>> +static struct tst_cap dropadmin = {
>> + .action = TST_CAP_DROP,
>> + .id = CAP_SYS_ADMIN,
>> + .name = "CAP_SYS_ADMIN",
>> +};
>> +
>> +static struct tst_cap needadmin = {
>> + .action = TST_CAP_REQ,
>> + .id = CAP_SYS_ADMIN,
>> + .name = "CAP_SYS_ADMIN",
>> +};
>> +
>> +static struct tcase {
>> + int cmd;
>> + int *id;
>> + void *addr;
>> + int exp_err;
>> + int on_flag;
>> + int use_external_fd;
>> + char *des;
>> +} tcases[] = {
>> + {QCMD(Q_SETQUOTA, USRQUOTA),&fmt_id, NULL, EFAULT, 1, 0,
>> + "EFAULT when addr or special is invalid"},
>> +
>> + {QCMD(OPTION_INVALID, USRQUOTA),&fmt_id, NULL, EINVAL, 0, 0,
>> + "EINVAL when cmd or type is invalid"},
>> +
>> + {QCMD(Q_QUOTAON, USRQUOTA),&fmt_id, NULL, ENOTBLK, 0, 0,
>> + "ENOTBLK when special is not a block device"},
>> +
>> + {QCMD(Q_SETQUOTA, USRQUOTA),&test_id,&set_dqmax, ERANGE, 1, 0,
>> + "ERANGE when cmd is Q_SETQUOTA, but the specified limits are out of the range"},
>> +
>> + {QCMD(Q_QUOTAON, USRQUOTA),&fmt_id, NULL, EPERM, 0, 0,
>> + "EPERM when the caller lacked the required privilege for specified operations"},
>> +
>> + {QCMD(Q_QUOTAON, USRQUOTA),&fmt_id, NULL, EINVAL, 0, 1,
>> + "EINVAL when cmd is Q_QUOTAON, but the fd refers to a regular file(doesn't under "
>> + "this mountpoint)"}
>> +};
>> +
>> +static void verify_quotactl(unsigned int n)
>> +{
>> + struct tcase *tc =&tcases[n];
>> + int quota_on = 0;
>> + int drop_flag = 0;
>> +
>> + tst_res(TINFO, "Testing %s", tc->des);
>> + if (tc->cmd == QCMD(Q_GETNEXTQUOTA, USRQUOTA)&& getnextquota_nsup) {
>> + tst_res(TCONF, "current system doesn't support Q_GETNEXTQUOTA");
>> + return;
>> + }
>> +
>> + if (tc->on_flag) {
>> + TST_EXP_PASS_SILENT(do_quotactl(fd, QCMD(Q_QUOTAON, USRQUOTA), tst_device->dev,
>> + fmt_id, NULL), "do_quotactl(QCMD(Q_QUOTAON, USRQUOTA))");
>> + if (!TST_PASS)
>> + return;
>> + quota_on = 1;
>> + }
>> +
>> + if (tc->exp_err == EPERM) {
>> + tst_cap_action(&dropadmin);
>> + drop_flag = 1;
>> + }
>> +
>> + if (tst_variant) {
>> + if (tc->exp_err == ENOTBLK) {
>> + tst_res(TCONF, "quotactl_fd() doesn't have this error, skip");
>> + return;
>> + }
>> + } else {
>> + if (tc->use_external_fd) {
>> + tst_res(TCONF, "quotactl() doesn't use fd, skip");
>> + return;
>> + }
>> + }
>> + if (tc->exp_err == ENOTBLK)
>> + TST_EXP_FAIL(do_quotactl(fd, tc->cmd, "/dev/null", *tc->id, tc->addr),
>> + ENOTBLK, "do_quotactl()");
>> + else
>> + TST_EXP_FAIL(do_quotactl(tc->use_external_fd ? external_fd : fd, tc->cmd,
>> + tst_device->dev, *tc->id, tc->addr), tc->exp_err, "do_quotactl()");
>> +
>> + if (quota_on) {
>> + TST_EXP_PASS_SILENT(do_quotactl(fd, QCMD(Q_QUOTAOFF, USRQUOTA), tst_device->dev,
>> + fmt_id, NULL), "do_quotactl(QCMD(Q_QUOTAOFF, USRQUOTA)");
>> + if (!TST_PASS)
>> + return;
>> + quota_on = 0;
>
> There is no need to clear this flag.
Yes, good catch, will also remove this in quotactl06.c.
>
>> + }
>> +
>> + if (drop_flag) {
>> + tst_cap_action(&needadmin);
>> + drop_flag = 0;
>
> And this flag.
>
>> + }
>> +}
>> +
>> +static void setup(void)
>> +{
>> + unsigned int i;
>> + const char *const fs_opts[] = { "-O quota", NULL};
>> +
>> + quotactl_info();
>> + external_fd = SAFE_CREAT("testfile", O_RDONLY);
>> +
>> + SAFE_MKFS(tst_device->dev, tst_device->fs_type, fs_opts, NULL);
>> + SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL);
>
> Why don't we pass the fs_opts in tst_test instead and use .mount_device = 1?
The code is pasted from quotactl06.c there use
tst_require_quota_support. Here we don't use it, so we can use
.mount_device directly.
Best Regards
Yang Xu
>
> Should be as easy as:
>
> static struct tst_test test = {
> ...
> .dev_fs_opts = (const char *const []){"-O quota", NULL},
> .mount_device = 1,
> ...
> };
>
> Or is there a reason why this wouldn't work?
>
>
> With the changes outlined in the other email and the minor issues I've
> pointed out here fixed:
>
> Reviewed-by: Cyril Hrubis<chrubis@suse.cz>
>
>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH v6 2/3] syscalls/quotactl07: Refactor this case
2022-01-13 14:03 ` Cyril Hrubis
@ 2022-01-14 3:29 ` xuyang2018.jy
0 siblings, 0 replies; 13+ messages in thread
From: xuyang2018.jy @ 2022-01-14 3:29 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi Cyril
> Hi!
>> diff --git a/testcases/kernel/syscalls/quotactl/quotactl07.c b/testcases/kernel/syscalls/quotactl/quotactl07.c
>> index 2992a6112..2427ef682 100644
>> --- a/testcases/kernel/syscalls/quotactl/quotactl07.c
>> +++ b/testcases/kernel/syscalls/quotactl/quotactl07.c
>> @@ -7,7 +7,9 @@
>> /*\
>> * [Description]
>> *
>> - * This is a regresstion test for kernel commit 3dd4d40b4208
>> + * This is not only a functional test but also a error test for Q_XQUOTARM.
>> + *
>> + * It is a regresstion test for kernel commit 3dd4d40b4208
>> * ("xfs: Sanity check flags of Q_XQUOTARM call").
>> */
>>
>> @@ -15,51 +17,71 @@
>> #include<unistd.h>
>> #include<stdio.h>
>> #include<sys/quota.h>
>> +#include<sys/statvfs.h>
>> #include "tst_test.h"
>> -#include "lapi/quotactl.h"
>> +#include "quotactl_syscall_var.h"
>>
>> #ifdef HAVE_XFS_XQM_H
>> # include<xfs/xqm.h>
>>
>> -#define MNTPOINT "mntpoint"
>> -
>> -static uint32_t qflag_acct = XFS_QUOTA_UDQ_ACCT;
>> -static unsigned int valid_type = XFS_USER_QUOTA;
>> /* Include a valid quota type to avoid other EINVAL error */
>> static unsigned int invalid_type = XFS_GROUP_QUOTA<< 1 | XFS_USER_QUOTA;
>> +static unsigned int valid_type = XFS_USER_QUOTA;
>> +static int mount_flag;
>>
>> static void verify_quota(void)
>> {
>> - TEST(quotactl(QCMD(Q_XQUOTARM, USRQUOTA), tst_device->dev, 0, (void *)&invalid_type));
>> - if (TST_ERR == EINVAL)
>> - tst_res(TPASS, "Q_XQUOTARM has quota type check");
>> + struct statfs before, after;
>> +
>> + SAFE_STATFS(MNTPOINT,&before);
>> + TST_EXP_PASS(do_quotactl(fd, QCMD(Q_XQUOTARM, USRQUOTA), tst_device->dev, 0,
>> + (void *)&valid_type), "do_quotactl(Q_XQUOTARM,valid_type)");
>> + SAFE_STATFS(MNTPOINT,&after);
>> + if (before.f_bavail<= after.f_bavail)
>> + tst_res(TPASS, "Q_XQUOTARM to free space, delta(%lu)", after.f_bavail - before.f_bavail);
>> else
>> - tst_res(TFAIL, "Q_XQUOTARM doesn't have quota type check");
>> + tst_res(TFAIL, "Q_XQUOTARM to free space, delta(-%lu)", before.f_bavail - after.f_bavail);
>> +
>> + TST_EXP_FAIL(do_quotactl(fd, QCMD(Q_XQUOTARM, USRQUOTA), tst_device->dev, 0,
>> + (void *)&invalid_type), EINVAL, "do_quotactl(Q_XQUOTARM, invalid_type)");
>> }
>>
>> static void setup(void)
>> {
>> - TEST(quotactl(QCMD(Q_XQUOTAOFF, USRQUOTA), tst_device->dev, 0, (void *)&qflag_acct));
>> - if (TST_RET == -1)
>> - tst_brk(TBROK | TTERRNO, "quotactl with Q_XQUOTAOFF failed");
>> + quotactl_info();
>> +
>> + /* ensure superblock has quota data, but not running */
>> + SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, "usrquota");
>> + mount_flag = 1;
>> + SAFE_UMOUNT(MNTPOINT);
>> + mount_flag = 0;
>> + SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, "noquota");
>> + mount_flag = 1;
>
> Maybe just SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, "remount, noquota") ?
>
> If we can remount the device without umounting it the code would be a
> bit shorter.
>
It seems use MS_REMOUNT flag doesn't work well, the quota feature is
still on and will report EINVAL error when using Q_XQUOTARM syscall.
Also, send a email to xfs maintainer to prove whether it is a expected
behaviour.
ps: I will merge this first, then I will add a comment to clarify this
when I know the reason for xfs maintainer.
Best Regards
Yang Xu
> Anyways looks good to me:
>
> Reviewed-by: Cyril Hrubis<chrubis@suse.cz>
>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH v6 3/3] syscalls/quotactl: Make use of TST_EXP_PASS_SILENT and TST_EXP_FAIL
2022-01-13 14:45 ` Cyril Hrubis
@ 2022-01-14 3:58 ` xuyang2018.jy
0 siblings, 0 replies; 13+ messages in thread
From: xuyang2018.jy @ 2022-01-14 3:58 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi Cyril
> Hi!
>> } tcases[] = {
>> - {QCMD(Q_QUOTAON, USRQUOTA),&fmt_id, testdir1, EACCES, 0},
>> - {QCMD(Q_QUOTAON, USRQUOTA),&fmt_id, testdir2, ENOENT, 0},
>> - {QCMD(Q_QUOTAON, USRQUOTA),&fmt_id, usrpath, EBUSY, 1},
>> - {QCMD(Q_SETQUOTA, USRQUOTA),&fmt_id, NULL, EFAULT, 1},
>> - {QCMD(OPTION_INVALID, USRQUOTA),&fmt_id, usrpath, EINVAL, 0},
>> - {QCMD(Q_QUOTAON, USRQUOTA),&fmt_id, usrpath, ENOTBLK, 0},
>> - {QCMD(Q_SETQUOTA, USRQUOTA),&test_id,&set_dq, ESRCH, 0},
>> - {QCMD(Q_QUOTAON, USRQUOTA),&fmt_invalid, usrpath, ESRCH, 0},
>> - {QCMD(Q_GETNEXTQUOTA, USRQUOTA),&test_invalid, usrpath, ESRCH, 0},
>> - {QCMD(Q_SETQUOTA, USRQUOTA),&test_id,&set_dqmax, ERANGE, 1},
>> - {QCMD(Q_QUOTAON, USRQUOTA),&fmt_id, usrpath, EPERM, 0},
>> + {QCMD(Q_QUOTAON, USRQUOTA),&fmt_id, testdir1, EACCES, 0,
>> + "EACCES when cmd is Q_QUOTAON and addr existed but not a regular file"},
>> +
>> + {QCMD(Q_QUOTAON, USRQUOTA),&fmt_id, testdir2, ENOENT, 0,
>> + "ENOENT when the file specified by special or addr does not exist"},
>> +
>> + {QCMD(Q_QUOTAON, USRQUOTA),&fmt_id, usrpath, EBUSY, 1,
>> + "EBUSY when cmd is Q_QUOTAON and another Q_QUOTAON had already been performed"},
>> +
>> + {QCMD(Q_SETQUOTA, USRQUOTA),&fmt_id, NULL, EFAULT, 1,
>> + "EFAULT when addr or special is invalid"},
>> +
>> + {QCMD(OPTION_INVALID, USRQUOTA),&fmt_id, usrpath, EINVAL, 0,
>> + "EINVAL when cmd or type is invalid"},
>> +
>> + {QCMD(Q_QUOTAON, USRQUOTA),&fmt_id, usrpath, ENOTBLK, 0,
>> + "ENOTBLK when special is not a block device"},
>> +
>> + {QCMD(Q_SETQUOTA, USRQUOTA),&test_id,&set_dq, ESRCH, 0,
>> + "ESRCH when no disk quota is found for the indicated user and quotas "
>> + "have not been turned on for this fs"},
>> +
>> + {QCMD(Q_QUOTAON, USRQUOTA),&fmt_invalid, usrpath, ESRCH, 0,
>> + "ESRCH when cmd is Q_QUOTAON, but the quota format was not found"},
>> +
>> + {QCMD(Q_GETNEXTQUOTA, USRQUOTA),&test_invalid, usrpath, ESRCH, 0,
>> + "ESRCH when cmd is Q_GETNEXTQUOTA, but there is no ID greater than or "
>> + "equal to id that has an active quota"},
>> +
>> + {QCMD(Q_SETQUOTA, USRQUOTA),&test_id,&set_dqmax, ERANGE, 1,
>> + "ERANGE when cmd is Q_SETQUOTA, but the specified limits are out of "
>> + "the range allowed by the quota format"},
>> +
>> + {QCMD(Q_QUOTAON, USRQUOTA),&fmt_id, usrpath, EPERM, 0,
>> + "EPERM when the caller lacked the required privilege (CAP_SYS_ADMIN) "
>> + "for the specified operation"},
>
> These descriptions could be a bit shorter and still have the same amount
> of information, for instance the last one could be shortened to just:
>
> "EPERM when caller lacks required privilege (CAP_SYS_ADMIN)"
>
> or
>
> "ESRCH for Q_GETNEXTQUOTA but the id was last one"
>
> or
>
> "ESRCH for Q_GETNEXTQUOTA but no quota found for the user or quotas are off"
>
> Ideally all the messages should fit into a single line less than 80
> characters...
>
>
> Other than that this is a nice cleanup, with the messages shortened:
Thanks for your review, I have modified these and then pushed this patchset.
Best Regards
Yang Xu
>
> Reviewed-by: Cyril Hrubis<chrubis@suse.cz>
>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2022-01-14 3:58 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-12 7:48 [LTP] [PATCH v6 1/3] syscalls/quotactl09: Test error when quota info hidden in filesystem Yang Xu
2022-01-12 7:48 ` [LTP] [PATCH v6 2/3] syscalls/quotactl07: Refactor this case Yang Xu
2022-01-13 14:03 ` Cyril Hrubis
2022-01-14 3:29 ` xuyang2018.jy
2022-01-12 7:48 ` [LTP] [PATCH v6 3/3] syscalls/quotactl: Make use of TST_EXP_PASS_SILENT and TST_EXP_FAIL Yang Xu
2022-01-13 14:45 ` Cyril Hrubis
2022-01-14 3:58 ` xuyang2018.jy
2022-01-12 9:18 ` [LTP] [PATCH v6 1/3] syscalls/quotactl09: Test error when quota info hidden in filesystem xuyang2018.jy
2022-01-12 9:46 ` Cyril Hrubis
2022-01-13 6:51 ` xuyang2018.jy
2022-01-13 9:49 ` Cyril Hrubis
2022-01-13 14:22 ` Cyril Hrubis
2022-01-14 2:27 ` xuyang2018.jy
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.