* [LTP] [PATCH v2 10/13] syscalls/quotactl04: Add quotactl_fd test variant
@ 2021-10-27 12:29 Yang Xu
2021-10-27 12:29 ` [LTP] [PATCH v2 11/13] syscalls/quotactl09: Test error when quota info hidden in filesystem Yang Xu
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Yang Xu @ 2021-10-27 12:29 UTC (permalink / raw)
To: ltp
Also remove useless geteuid.
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
testcases/kernel/syscalls/quotactl/quotactl04.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/testcases/kernel/syscalls/quotactl/quotactl04.c b/testcases/kernel/syscalls/quotactl/quotactl04.c
index f34050716..4dc68c2ae 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl04.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl04.c
@@ -29,12 +29,14 @@
#include <sys/mount.h>
#include "tst_safe_stdio.h"
#include "tst_test.h"
-#include "lapi/quotactl.h"
+#include "quotactl_syscall_var.h"
#define FMTID QFMT_VFS_V1
#define MNTPOINT "mntpoint"
+#define TESTFILE MNTPOINT "/testfile"
+
static int32_t fmt_id = FMTID;
-static int test_id, mount_flag;
+static int test_id, mount_flag, fd = -1;
static struct dqblk set_dq = {
.dqb_bsoftlimit = 100,
.dqb_valid = QIF_BLIMITS
@@ -125,7 +127,7 @@ static void setup(void)
const char *const fs_opts[] = {"-I 256", "-O quota,project", NULL};
int rc, major, minor, patch;
- test_id = geteuid();
+ quotactl_info();
f = SAFE_POPEN("mkfs.ext4 -V 2>&1", "r");
rc = fscanf(f, "mke2fs %d.%d.%d", &major, &minor, &patch);
if (rc != 3)
@@ -135,10 +137,13 @@ static void setup(void)
pclose(f);
SAFE_MKFS(tst_device->dev, tst_device->fs_type, fs_opts, NULL);
do_mount(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL);
+ fd = SAFE_OPEN(TESTFILE, O_RDWR | O_CREAT, 0666);
}
static void cleanup(void)
{
+ if (fd > -1)
+ SAFE_CLOSE(fd);
if (mount_flag && tst_umount(MNTPOINT))
tst_res(TWARN | TERRNO, "umount(%s)", MNTPOINT);
}
@@ -153,7 +158,7 @@ static void verify_quota(unsigned int n)
tst_res(TINFO, "Test #%d: %s", n, tc->tname);
- TEST(quotactl(tc->cmd, tst_device->dev, *tc->id, tc->addr));
+ 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);
return;
@@ -183,6 +188,7 @@ static struct tst_test test = {
.needs_device = 1,
.dev_fs_type = "ext4",
.mntpoint = MNTPOINT,
+ .test_variants = QUOTACTL_SYSCALL_VARIANTS,
.needs_cmds = (const char *[]) {
"mkfs.ext4",
NULL
--
2.23.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [LTP] [PATCH v2 11/13] syscalls/quotactl09: Test error when quota info hidden in filesystem
2021-10-27 12:29 [LTP] [PATCH v2 10/13] syscalls/quotactl04: Add quotactl_fd test variant Yang Xu
@ 2021-10-27 12:29 ` Yang Xu
2021-10-27 12:29 ` [LTP] [PATCH v2 12/13] syscalls/quotactl07: Add quotactl_fd test variant Yang Xu
2021-10-27 12:29 ` [LTP] [PATCH v2 13/13] syscalls/quotactl: Move common code into quotactl_syscal_var.h Yang Xu
2 siblings, 0 replies; 4+ messages in thread
From: Yang Xu @ 2021-10-27 12:29 UTC (permalink / raw)
To: ltp
This case is similar to quotactl06 but only two differences
1) use quotactl and quotactl_fd syscalls without visible quota file
2) remove some error for addr argument
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/quotactl/.gitignore | 1 +
.../kernel/syscalls/quotactl/quotactl09.c | 171 ++++++++++++++++++
3 files changed, 173 insertions(+)
create mode 100644 testcases/kernel/syscalls/quotactl/quotactl09.c
diff --git a/runtest/syscalls b/runtest/syscalls
index cdeb3e142..c8df80fa0 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1074,6 +1074,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..1a3a7005d
--- /dev/null
+++ b/testcases/kernel/syscalls/quotactl/quotactl09.c
@@ -0,0 +1,171 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 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
+ */
+
+#include <errno.h>
+#include <sys/quota.h>
+#include "tst_test.h"
+#include "tst_capability.h"
+#include "quotactl_syscall_var.h"
+#include "tst_safe_stdio.h"
+
+#define OPTION_INVALID 999
+#define MNTPOINT "mntpoint"
+#define TESTFILE MNTPOINT "/testfile"
+
+static int32_t fmt_id = QFMT_VFS_V1;
+static int test_id, fd = -1;
+static int getnextquota_nsup;
+
+static struct if_nextdqblk res_ndq;
+
+static struct dqblk set_dqmax = {
+ .dqb_bsoftlimit = 0x7fffffffffffffffLL, /* 2^63-1 */
+ .dqb_valid = QIF_BLIMITS
+};
+
+struct tst_cap dropadmin = {
+ .action = TST_CAP_DROP,
+ .id = CAP_SYS_ADMIN,
+ .name = "CAP_SYS_ADMIN",
+};
+
+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;
+} tcases[] = {
+ {QCMD(Q_SETQUOTA, USRQUOTA), &fmt_id, NULL, EFAULT, 1},
+ {QCMD(OPTION_INVALID, USRQUOTA), &fmt_id, NULL, EINVAL, 0},
+ {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, NULL, ENOTBLK, 0},
+ {QCMD(Q_SETQUOTA, USRQUOTA), &test_id, &set_dqmax, ERANGE, 1},
+ {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, NULL, EPERM, 0},
+};
+
+static void verify_quotactl(unsigned int n)
+{
+ struct tcase *tc = &tcases[n];
+ int quota_on = 0;
+ int drop_flag = 0;
+
+ 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(do_quotactl(fd, QCMD(Q_QUOTAON, USRQUOTA), tst_device->dev,
+ fmt_id, NULL));
+ if (TST_RET == -1)
+ tst_brk(TBROK,
+ "quotactl with Q_QUOTAON returned %ld", TST_RET);
+ 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;
+ }
+ }
+ if (tc->exp_err == ENOTBLK)
+ TEST(do_quotactl(fd, tc->cmd, "/dev/null", *tc->id, tc->addr));
+ else
+ TEST(do_quotactl(fd, 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);
+ }
+
+ if (quota_on) {
+ TEST(do_quotactl(fd, QCMD(Q_QUOTAOFF, USRQUOTA), tst_device->dev,
+ fmt_id, NULL));
+ if (TST_RET == -1)
+ tst_brk(TBROK,
+ "quotactl with Q_QUOTAOFF returned %ld", TST_RET);
+ quota_on = 0;
+ }
+
+ if (drop_flag) {
+ tst_cap_action(&needadmin);
+ drop_flag = 0;
+ }
+}
+
+static void setup(void)
+{
+ unsigned int i;
+
+ quotactl_info();
+ fd = SAFE_OPEN(TESTFILE, O_RDWR | O_CREAT, 0644);
+ 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);
+}
+
+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",
+ .dev_fs_opts = (const char *const []){"-O", "quota", NULL},
+ .mntpoint = MNTPOINT,
+ .mount_device = 1,
+ .needs_root = 1,
+ .test_variants = QUOTACTL_SYSCALL_VARIANTS,
+};
--
2.23.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [LTP] [PATCH v2 12/13] syscalls/quotactl07: Add quotactl_fd test variant
2021-10-27 12:29 [LTP] [PATCH v2 10/13] syscalls/quotactl04: Add quotactl_fd test variant Yang Xu
2021-10-27 12:29 ` [LTP] [PATCH v2 11/13] syscalls/quotactl09: Test error when quota info hidden in filesystem Yang Xu
@ 2021-10-27 12:29 ` Yang Xu
2021-10-27 12:29 ` [LTP] [PATCH v2 13/13] syscalls/quotactl: Move common code into quotactl_syscal_var.h Yang Xu
2 siblings, 0 replies; 4+ messages in thread
From: Yang Xu @ 2021-10-27 12:29 UTC (permalink / raw)
To: ltp
Also man-pages has error that Q_XQUOTARM was not introduced by kernel
3.16. So use invalid type directly.
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
.../kernel/syscalls/quotactl/quotactl07.c | 24 +++++++++++--------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/testcases/kernel/syscalls/quotactl/quotactl07.c b/testcases/kernel/syscalls/quotactl/quotactl07.c
index 2992a6112..d29a56ee4 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl07.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl07.c
@@ -16,21 +16,22 @@
#include <stdio.h>
#include <sys/quota.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"
+#define TESTFILE MNTPOINT "/testfile"
+
+static int fd = -1;
-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 void verify_quota(void)
{
- TEST(quotactl(QCMD(Q_XQUOTARM, USRQUOTA), tst_device->dev, 0, (void *)&invalid_type));
+ TEST(do_quotactl(fd, QCMD(Q_XQUOTARM, USRQUOTA), tst_device->dev, 0, (void *)&invalid_type));
if (TST_ERR == EINVAL)
tst_res(TPASS, "Q_XQUOTARM has quota type check");
else
@@ -39,17 +40,19 @@ static void verify_quota(void)
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();
+ fd = SAFE_OPEN(TESTFILE, O_RDWR | O_CREAT, 0666);
+}
- 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");
+static void cleanup(void)
+{
+ if (fd > -1)
+ SAFE_CLOSE(fd);
}
static struct tst_test test = {
.setup = setup,
+ .cleanup = cleanup,
.needs_root = 1,
.needs_kconfigs = (const char *[]) {
"CONFIG_XFS_QUOTA",
@@ -60,6 +63,7 @@ static struct tst_test test = {
.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] 4+ messages in thread
* [LTP] [PATCH v2 13/13] syscalls/quotactl: Move common code into quotactl_syscal_var.h
2021-10-27 12:29 [LTP] [PATCH v2 10/13] syscalls/quotactl04: Add quotactl_fd test variant Yang Xu
2021-10-27 12:29 ` [LTP] [PATCH v2 11/13] syscalls/quotactl09: Test error when quota info hidden in filesystem Yang Xu
2021-10-27 12:29 ` [LTP] [PATCH v2 12/13] syscalls/quotactl07: Add quotactl_fd test variant Yang Xu
@ 2021-10-27 12:29 ` Yang Xu
2 siblings, 0 replies; 4+ messages in thread
From: Yang Xu @ 2021-10-27 12:29 UTC (permalink / raw)
To: ltp
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
testcases/kernel/syscalls/quotactl/quotactl02.h | 5 +----
testcases/kernel/syscalls/quotactl/quotactl03.c | 4 ----
testcases/kernel/syscalls/quotactl/quotactl04.c | 4 +---
testcases/kernel/syscalls/quotactl/quotactl07.c | 5 -----
testcases/kernel/syscalls/quotactl/quotactl08.c | 5 +----
testcases/kernel/syscalls/quotactl/quotactl09.c | 4 +---
testcases/kernel/syscalls/quotactl/quotactl_syscall_var.h | 4 ++++
7 files changed, 8 insertions(+), 23 deletions(-)
diff --git a/testcases/kernel/syscalls/quotactl/quotactl02.h b/testcases/kernel/syscalls/quotactl/quotactl02.h
index faee5d282..145ce7039 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl02.h
+++ b/testcases/kernel/syscalls/quotactl/quotactl02.h
@@ -17,15 +17,12 @@
#ifdef HAVE_XFS_XQM_H
# include <xfs/xqm.h>
-#define MNTPOINT "mntpoint"
-#define TESTFILE MNTPOINT "/testfile"
-
static struct fs_disk_quota set_dquota = {
.d_rtb_softlimit = 1000,
.d_fieldmask = FS_DQ_RTBSOFT
};
static uint32_t test_id;
-static int x_getnextquota_nsup, fd = -1;
+static int x_getnextquota_nsup;
static int x_getstatv_nsup;
void check_support_cmd(int quotatype)
diff --git a/testcases/kernel/syscalls/quotactl/quotactl03.c b/testcases/kernel/syscalls/quotactl/quotactl03.c
index 0c4c50b42..d13bc694b 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl03.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl03.c
@@ -34,11 +34,7 @@
#ifdef HAVE_XFS_XQM_H
# include <xfs/xqm.h>
-#define MNTPOINT "mnt_point"
-#define TESTFILE MNTPOINT "/testfile"
-
static uint32_t test_id = 0xfffffffc;
-static int fd = -1;
static void verify_quota(void)
{
diff --git a/testcases/kernel/syscalls/quotactl/quotactl04.c b/testcases/kernel/syscalls/quotactl/quotactl04.c
index 4dc68c2ae..50ba445ca 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl04.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl04.c
@@ -32,11 +32,9 @@
#include "quotactl_syscall_var.h"
#define FMTID QFMT_VFS_V1
-#define MNTPOINT "mntpoint"
-#define TESTFILE MNTPOINT "/testfile"
static int32_t fmt_id = FMTID;
-static int test_id, mount_flag, fd = -1;
+static int test_id, mount_flag;
static struct dqblk set_dq = {
.dqb_bsoftlimit = 100,
.dqb_valid = QIF_BLIMITS
diff --git a/testcases/kernel/syscalls/quotactl/quotactl07.c b/testcases/kernel/syscalls/quotactl/quotactl07.c
index d29a56ee4..6e8c3ecee 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl07.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl07.c
@@ -21,11 +21,6 @@
#ifdef HAVE_XFS_XQM_H
# include <xfs/xqm.h>
-#define MNTPOINT "mntpoint"
-#define TESTFILE MNTPOINT "/testfile"
-
-static int fd = -1;
-
/* Include a valid quota type to avoid other EINVAL error */
static unsigned int invalid_type = XFS_GROUP_QUOTA << 1 | XFS_USER_QUOTA;
diff --git a/testcases/kernel/syscalls/quotactl/quotactl08.c b/testcases/kernel/syscalls/quotactl/quotactl08.c
index 6912378f1..e37a474d2 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl08.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl08.c
@@ -40,11 +40,8 @@
#include "quotactl_syscall_var.h"
#include "tst_safe_stdio.h"
-#define MNTPOINT "mntpoint"
-#define TESTFILE MNTPOINT "/testfile"
-
static int32_t fmt_id = QFMT_VFS_V1;
-static int test_id, fd = -1;
+static int test_id;
static struct dqblk set_dq = {
.dqb_bsoftlimit = 100,
.dqb_valid = QIF_BLIMITS
diff --git a/testcases/kernel/syscalls/quotactl/quotactl09.c b/testcases/kernel/syscalls/quotactl/quotactl09.c
index 1a3a7005d..e7aad7b9b 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl09.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl09.c
@@ -27,11 +27,9 @@
#include "tst_safe_stdio.h"
#define OPTION_INVALID 999
-#define MNTPOINT "mntpoint"
-#define TESTFILE MNTPOINT "/testfile"
static int32_t fmt_id = QFMT_VFS_V1;
-static int test_id, fd = -1;
+static int test_id;
static int getnextquota_nsup;
static struct if_nextdqblk res_ndq;
diff --git a/testcases/kernel/syscalls/quotactl/quotactl_syscall_var.h b/testcases/kernel/syscalls/quotactl/quotactl_syscall_var.h
index 92a7c45db..bf2b06ffe 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl_syscall_var.h
+++ b/testcases/kernel/syscalls/quotactl/quotactl_syscall_var.h
@@ -10,6 +10,10 @@
#include "lapi/quotactl.h"
#define QUOTACTL_SYSCALL_VARIANTS 2
+#define MNTPOINT "mntpoint"
+#define TESTFILE MNTPOINT "/testfile"
+
+static int fd = -1;
static int do_quotactl(int fd, int cmd, const char *special, int id, caddr_t addr)
{
--
2.23.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-10-27 12:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-27 12:29 [LTP] [PATCH v2 10/13] syscalls/quotactl04: Add quotactl_fd test variant Yang Xu
2021-10-27 12:29 ` [LTP] [PATCH v2 11/13] syscalls/quotactl09: Test error when quota info hidden in filesystem Yang Xu
2021-10-27 12:29 ` [LTP] [PATCH v2 12/13] syscalls/quotactl07: Add quotactl_fd test variant Yang Xu
2021-10-27 12:29 ` [LTP] [PATCH v2 13/13] syscalls/quotactl: Move common code into quotactl_syscal_var.h Yang Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).