All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v3 06/12] lapi/quotactl.h: Add fallback for quotactl_fd
@ 2021-11-09 10:54 Yang Xu
  2021-11-09 10:54 ` [LTP] [PATCH v3 07/12] syscalls/quotactl08: Test quoatctl01 but quota info hidden in filesystem Yang Xu
                   ` (2 more replies)
  0 siblings, 3 replies; 32+ messages in thread
From: Yang Xu @ 2021-11-09 10:54 UTC (permalink / raw)
  To: ltp

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 configure.ac            |  1 +
 include/lapi/quotactl.h | 12 ++++++++++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 5bf3c52ec..859aa9857 100644
--- a/configure.ac
+++ b/configure.ac
@@ -122,6 +122,7 @@ AC_CHECK_FUNCS_ONCE([ \
     profil \
     pwritev \
     pwritev2 \
+    quotactl_fd \
     rand_r \
     readlinkat \
     recvmmsg \
diff --git a/include/lapi/quotactl.h b/include/lapi/quotactl.h
index 8e0315d03..739a85616 100644
--- a/include/lapi/quotactl.h
+++ b/include/lapi/quotactl.h
@@ -1,8 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Copyright (c) 2017-2019 Fujitsu Ltd.
+ * Copyright (c) 2017-2021 FUJITSU LIMITED. All rights reserved
  * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
- * Author: Yang Xu <xuyang2018.jy@cn.jujitsu.com>
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
  */
 
 #ifndef LAPI_QUOTACTL_H__
@@ -10,6 +10,14 @@
 
 #include "config.h"
 #include <sys/quota.h>
+#include "lapi/syscalls.h"
+
+#ifndef HAVE_QUOTACTL_FD
+static inline int quotactl_fd(int fd, int cmd, int id, caddr_t addr)
+{
+	return tst_syscall(__NR_quotactl_fd, fd, cmd, id, addr);
+}
+#endif
 
 #ifdef HAVE_STRUCT_IF_NEXTDQBLK
 # include <linux/quota.h>
-- 
2.23.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [LTP] [PATCH v3 07/12] syscalls/quotactl08: Test quoatctl01 but quota info hidden in filesystem
  2021-11-09 10:54 [LTP] [PATCH v3 06/12] lapi/quotactl.h: Add fallback for quotactl_fd Yang Xu
@ 2021-11-09 10:54 ` Yang Xu
  2021-11-10 16:32   ` Cyril Hrubis
  2021-11-09 10:54 ` [LTP] [PATCH v3 08/12] syscalls/quotactl02, 5: Add quotactl_fd test variant Yang Xu
  2021-11-09 10:54 ` [LTP] [PATCH v3 09/12] syscalls/quotactl03: " Yang Xu
  2 siblings, 1 reply; 32+ messages in thread
From: Yang Xu @ 2021-11-09 10:54 UTC (permalink / raw)
  To: ltp

It uses two variants(quotactl and quotactl_fd). The difference for quotactl01
is that we don't use quotacheck command and quota info hidden in filesystem.

It also needs mkfs.ext4 supports quota feature.  This feature is disabled[1]
before e2fsprog 1.42 when not specifying a --enable-quota option in compile-time
and e2fsprog 1.43 remove this disable[2]. So we should limit the e2fsprog to 1.43.
The e2fsprog version check will move to ltp lib when this patchset is merged.

[1]https://ext4.wiki.kernel.org/index.php/Quota
[2]https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git/commit/?h=v1.43&id=9e8fcd6e

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 runtest/syscalls                              |   1 +
 testcases/kernel/syscalls/quotactl/.gitignore |   1 +
 .../kernel/syscalls/quotactl/quotactl08.c     | 233 ++++++++++++++++++
 .../syscalls/quotactl/quotactl_syscall_var.h  |  32 +++
 4 files changed, 267 insertions(+)
 create mode 100644 testcases/kernel/syscalls/quotactl/quotactl08.c
 create mode 100644 testcases/kernel/syscalls/quotactl/quotactl_syscall_var.h

diff --git a/runtest/syscalls b/runtest/syscalls
index 1e6d46744..583455629 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1071,6 +1071,7 @@ quotactl04 quotactl04
 quotactl05 quotactl05
 quotactl06 quotactl06
 quotactl07 quotactl07
+quotactl08 quotactl08
 
 read01 read01
 read02 read02
diff --git a/testcases/kernel/syscalls/quotactl/.gitignore b/testcases/kernel/syscalls/quotactl/.gitignore
index 8d2ef94d9..dab9b3420 100644
--- a/testcases/kernel/syscalls/quotactl/.gitignore
+++ b/testcases/kernel/syscalls/quotactl/.gitignore
@@ -5,3 +5,4 @@
 /quotactl05
 /quotactl06
 /quotactl07
+/quotactl08
diff --git a/testcases/kernel/syscalls/quotactl/quotactl08.c b/testcases/kernel/syscalls/quotactl/quotactl08.c
new file mode 100644
index 000000000..c4a226c51
--- /dev/null
+++ b/testcases/kernel/syscalls/quotactl/quotactl08.c
@@ -0,0 +1,233 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
+ * This testcases checks that quotactl(2) on ext4 filesystem succeeds to:
+ *
+ * - turn on quota with Q_QUOTAON flag for user
+ * - set disk quota limits with Q_SETQUOTA flag for user
+ * - get disk quota limits with Q_GETQUOTA flag for user
+ * - set information about quotafile with Q_SETINFO flag for user
+ * - get information about quotafile with Q_GETINFO flag for user
+ * - get quota format with Q_GETFMT flag for user
+ * - update quota usages with Q_SYNC flag for user
+ * - get disk quota limit greater than or equal to ID with Q_GETNEXTQUOTA flag for user
+ * - turn off quota with Q_QUOTAOFF flag for user
+ * - turn on quota with Q_QUOTAON flag for group
+ * - set disk quota limits with Q_SETQUOTA flag for group
+ * - get disk quota limits with Q_GETQUOTA flag for group
+ * - set information about quotafile with Q_SETINFO flag for group
+ * - get information about quotafile with Q_GETINFO flag for group
+ * - get quota format with Q_GETFMT flag for group
+ * - update quota usages with Q_SYNC flag for group
+ * - get disk quota limit greater than or equal to ID with Q_GETNEXTQUOTA flag for group
+ * - turn off quota with Q_QUOTAOFF flag for group
+ *
+ * It is similar to quotactl01.c, only two difference
+ * - use new quotactl_fd syscalls if supports
+ * - quota file hidden in filesystem
+ *
+ * Minimum e2fsprogs version required is 1.43.
+ */
+
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdio.h>
+#include "tst_test.h"
+#include "quotactl_syscall_var.h"
+#include "tst_safe_stdio.h"
+
+static int32_t fmt_id = QFMT_VFS_V1;
+static int test_id, mount_flag;
+static struct dqblk set_dq = {
+	.dqb_bsoftlimit = 100,
+	.dqb_valid = QIF_BLIMITS
+};
+static struct dqblk res_dq;
+
+static struct dqinfo set_qf = {
+	.dqi_bgrace = 80,
+	.dqi_valid = IIF_BGRACE
+};
+static struct dqinfo res_qf;
+static int32_t fmt_buf;
+static int getnextquota_nsup;
+
+static struct if_nextdqblk res_ndq;
+
+static struct tcase {
+	int cmd;
+	int *id;
+	void *addr;
+	void *set_data;
+	void *res_data;
+	int sz;
+	char *des;
+	char *tname;
+} tcases[] = {
+	{QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, NULL,
+	NULL, NULL, 0, "turn on quota for user",
+	"QCMD(Q_QUOTAON, USRQUOTA)"},
+
+	{QCMD(Q_SETQUOTA, USRQUOTA), &test_id, &set_dq,
+	NULL, NULL, 0, "set disk quota limit for user",
+	"QCMD(Q_SETQUOTA, USRQUOTA)"},
+
+	{QCMD(Q_GETQUOTA, USRQUOTA), &test_id, &res_dq,
+	&set_dq.dqb_bsoftlimit, &res_dq.dqb_bsoftlimit,
+	sizeof(res_dq.dqb_bsoftlimit), "get disk quota limit for user",
+	"QCMD(Q_GETQUOTA, USRQUOTA)"},
+
+	{QCMD(Q_SETINFO, USRQUOTA), &test_id, &set_qf,
+	NULL, NULL, 0, "set information about quotafile for user",
+	"QCMD(Q_SETINFO, USRQUOTA)"},
+
+	{QCMD(Q_GETINFO, USRQUOTA), &test_id, &res_qf,
+	&set_qf.dqi_bgrace, &res_qf.dqi_bgrace, sizeof(res_qf.dqi_bgrace),
+	"get information about quotafile for user",
+	"QCMD(Q_GETINFO, USRQUOTA)"},
+
+	{QCMD(Q_GETFMT, USRQUOTA), &test_id, &fmt_buf,
+	&fmt_id, &fmt_buf, sizeof(fmt_buf),
+	"get quota format for user",
+	"QCMD(Q_GETFMT, USRQUOTA)"},
+
+	{QCMD(Q_SYNC, USRQUOTA), &test_id, &res_dq,
+	NULL, NULL, 0, "update quota usages for user",
+	"QCMD(Q_SYNC, USRQUOTA)"},
+
+	{QCMD(Q_GETNEXTQUOTA, USRQUOTA), &test_id, &res_ndq,
+	&test_id, &res_ndq.dqb_id, sizeof(res_ndq.dqb_id),
+	"get next disk quota limit for user",
+	"QCMD(Q_GETNEXTQUOTA, USRQUOTA)"},
+
+	{QCMD(Q_QUOTAOFF, USRQUOTA), &test_id, NULL,
+	NULL, NULL, 0, "turn off quota for user",
+	"QCMD(Q_QUOTAOFF, USRQUOTA)"},
+
+	{QCMD(Q_QUOTAON, GRPQUOTA), &fmt_id, NULL,
+	NULL, NULL, 0, "turn on quota for group",
+	"QCMD(Q_QUOTAON, GRPQUOTA)"},
+
+	{QCMD(Q_SETQUOTA, GRPQUOTA), &test_id, &set_dq,
+	NULL, NULL, 0, "set disk quota limit for group",
+	"QCMD(Q_SETQUOTA, GRPQUOTA)"},
+
+	{QCMD(Q_GETQUOTA, GRPQUOTA), &test_id, &res_dq, &set_dq.dqb_bsoftlimit,
+	&res_dq.dqb_bsoftlimit, sizeof(res_dq.dqb_bsoftlimit),
+	"set disk quota limit for group",
+	"QCMD(Q_GETQUOTA, GRPQUOTA)"},
+
+	{QCMD(Q_SETINFO, GRPQUOTA), &test_id, &set_qf,
+	NULL, NULL, 0, "set information about quotafile for group",
+	"QCMD(Q_SETINFO, GRPQUOTA)"},
+
+	{QCMD(Q_GETINFO, GRPQUOTA), &test_id, &res_qf, &set_qf.dqi_bgrace,
+	&res_qf.dqi_bgrace, sizeof(res_qf.dqi_bgrace),
+	"get information about quotafile for group",
+	"QCMD(Q_GETINFO, GRPQUOTA)"},
+
+	{QCMD(Q_GETFMT, GRPQUOTA), &test_id, &fmt_buf,
+	&fmt_id, &fmt_buf, sizeof(fmt_buf), "get quota format for group",
+	"QCMD(Q_GETFMT, GRPQUOTA)"},
+
+	{QCMD(Q_SYNC, GRPQUOTA), &test_id, &res_dq,
+	NULL, NULL, 0, "update quota usages for group",
+	"QCMD(Q_SYNC, GRPQUOTA)"},
+
+	{QCMD(Q_GETNEXTQUOTA, GRPQUOTA), &test_id, &res_ndq,
+	&test_id, &res_ndq.dqb_id, sizeof(res_ndq.dqb_id),
+	"get next disk quota limit for group",
+	"QCMD(Q_GETNEXTQUOTA, GRPQUOTA)"},
+
+	{QCMD(Q_QUOTAOFF, GRPQUOTA), &test_id, NULL,
+	NULL, NULL, 0, "turn off quota for group",
+	"QCMD(Q_QUOTAOFF, GRPQUOTA)"},
+};
+
+static void setup(void)
+{
+	FILE *f;
+	const char *const fs_opts[] = { "-O quota", NULL};
+	int rc, major, minor, patch;
+
+	quotactl_info();
+	f = SAFE_POPEN("mkfs.ext4 -V 2>&1", "r");
+	rc = fscanf(f, "mke2fs %d.%d.%d", &major, &minor, &patch);
+	if (rc != 3)
+		tst_res(TWARN, "Unable parse version number");
+	else if (major * 10000 + minor * 100 + patch < 14300)
+		tst_brk(TCONF, "Test needs mkfs.ext4 >= 1.43 for quota option, test skipped");
+	pclose(f);
+
+	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,
+		0, (void *) &res_ndq));
+	if (TST_ERR == EINVAL || TST_ERR == ENOSYS)
+		getnextquota_nsup = 1;
+}
+
+static void cleanup(void)
+{
+	if (fd > -1)
+		SAFE_CLOSE(fd);
+	if (mount_flag && tst_umount(MNTPOINT))
+		tst_res(TWARN | TERRNO, "umount(%s)", MNTPOINT);
+}
+
+static void verify_quota(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+
+	res_dq.dqb_bsoftlimit = 0;
+	res_qf.dqi_igrace = 0;
+	fmt_buf = 0;
+	res_ndq.dqb_id = -1;
+
+	tst_res(TINFO, "Test #%d: %s", n, tc->tname);
+	if ((tc->cmd == QCMD(Q_GETNEXTQUOTA, USRQUOTA) ||
+		tc->cmd == QCMD(Q_GETNEXTQUOTA, GRPQUOTA)) &&
+		getnextquota_nsup) {
+		tst_res(TCONF, "current system doesn't support this cmd");
+		return;
+	}
+	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;
+	}
+
+	if (memcmp(tc->res_data, tc->set_data, tc->sz)) {
+		tst_res(TFAIL, "quotactl failed to %s", tc->des);
+		tst_res_hexd(TINFO, tc->res_data, tc->sz, "retval:   ");
+		tst_res_hexd(TINFO, tc->set_data, tc->sz, "expected: ");
+		return;
+	}
+
+	tst_res(TPASS, "quotactl succeeded to %s", tc->des);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_QFMT_V2",
+		NULL
+	},
+	.test = verify_quota,
+	.tcnt = ARRAY_SIZE(tcases),
+	.mntpoint = MNTPOINT,
+	.dev_fs_type = "ext4",
+	.needs_device = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_variants = QUOTACTL_SYSCALL_VARIANTS,
+};
diff --git a/testcases/kernel/syscalls/quotactl/quotactl_syscall_var.h b/testcases/kernel/syscalls/quotactl/quotactl_syscall_var.h
new file mode 100644
index 000000000..3d1a2c8f5
--- /dev/null
+++ b/testcases/kernel/syscalls/quotactl/quotactl_syscall_var.h
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+#ifndef LTP_QUOTACTL_SYSCALL_VAR_H
+#define LTP_QUOTACTL_SYSCALL_VAR_H
+
+#include "lapi/quotactl.h"
+
+#define QUOTACTL_SYSCALL_VARIANTS 2
+#define MNTPOINT "mntpoint"
+
+static int fd = -1;
+
+static int do_quotactl(int fd, int cmd, const char *special, int id, caddr_t addr)
+{
+	if (tst_variant == 0)
+		return quotactl(cmd, special, id, addr);
+	return quotactl_fd(fd, cmd, id, addr);
+}
+
+static void quotactl_info(void)
+{
+	if (tst_variant == 0)
+		tst_res(TINFO, "Test quotactl()");
+	else
+		tst_res(TINFO, "Test quotactl_fd()");
+}
+
+#endif /* LTP_QUOTACTL_SYSCALL_VAR_H */
-- 
2.23.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [LTP] [PATCH v3 08/12] syscalls/quotactl02, 5: Add quotactl_fd test variant
  2021-11-09 10:54 [LTP] [PATCH v3 06/12] lapi/quotactl.h: Add fallback for quotactl_fd Yang Xu
  2021-11-09 10:54 ` [LTP] [PATCH v3 07/12] syscalls/quotactl08: Test quoatctl01 but quota info hidden in filesystem Yang Xu
@ 2021-11-09 10:54 ` Yang Xu
  2021-11-09 10:54 ` [LTP] [PATCH v3 09/12] syscalls/quotactl03: " Yang Xu
  2 siblings, 0 replies; 32+ messages in thread
From: Yang Xu @ 2021-11-09 10:54 UTC (permalink / raw)
  To: ltp

Also remove useless geteuid.

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 testcases/kernel/syscalls/quotactl/quotactl02.c | 15 ++++++++++++---
 testcases/kernel/syscalls/quotactl/quotactl02.h | 17 ++++++++---------
 testcases/kernel/syscalls/quotactl/quotactl05.c | 15 ++++++++++++---
 3 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/testcases/kernel/syscalls/quotactl/quotactl02.c b/testcases/kernel/syscalls/quotactl/quotactl02.c
index 55a6a8906..56fa23b9d 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl02.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl02.c
@@ -99,11 +99,18 @@ static struct t_case {
 
 static void setup(void)
 {
-	test_id = geteuid();
+	quotactl_info();
+	fd = SAFE_OPEN(MNTPOINT, O_RDONLY);
 	check_support_cmd(USRQUOTA);
 	check_support_cmd(GRPQUOTA);
 }
 
+static void cleanup(void)
+{
+	if (fd > -1)
+		SAFE_CLOSE(fd);
+}
+
 static void verify_quota(unsigned int n)
 {
 	struct t_case *tc = &tcases[n];
@@ -122,7 +129,7 @@ static void verify_quota(unsigned int n)
 		return;
 	}
 
-	TEST(quotactl(tc->cmd, tst_device->dev, test_id, tc->addr));
+	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);
 		return;
@@ -144,9 +151,11 @@ static struct tst_test test = {
 	.tcnt = ARRAY_SIZE(tcases),
 	.mount_device = 1,
 	.dev_fs_type = "xfs",
-	.mntpoint = mntpoint,
+	.mntpoint = MNTPOINT,
 	.mnt_data = "usrquota,grpquota",
 	.setup = setup,
+	.cleanup = cleanup,
+	.test_variants = QUOTACTL_SYSCALL_VARIANTS,
 };
 #else
 	TST_TEST_TCONF("System doesn't have <xfs/xqm.h>");
diff --git a/testcases/kernel/syscalls/quotactl/quotactl02.h b/testcases/kernel/syscalls/quotactl/quotactl02.h
index 3351fb578..145ce7039 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl02.h
+++ b/testcases/kernel/syscalls/quotactl/quotactl02.h
@@ -12,7 +12,7 @@
 #include <unistd.h>
 #include <stdio.h>
 #include "tst_test.h"
-#include "lapi/quotactl.h"
+#include "quotactl_syscall_var.h"
 
 #ifdef HAVE_XFS_XQM_H
 # include <xfs/xqm.h>
@@ -24,7 +24,6 @@ static struct fs_disk_quota set_dquota = {
 static uint32_t test_id;
 static int x_getnextquota_nsup;
 static int x_getstatv_nsup;
-static const char mntpoint[] = "mnt_point";
 
 void check_support_cmd(int quotatype)
 {
@@ -36,12 +35,12 @@ void check_support_cmd(int quotatype)
 	x_getnextquota_nsup = 0;
 	x_getstatv_nsup = 0;
 
-	TEST(quotactl(QCMD(Q_XGETNEXTQUOTA, quotatype), tst_device->dev,
+	TEST(do_quotactl(fd, QCMD(Q_XGETNEXTQUOTA, quotatype), tst_device->dev,
 		      test_id, (void *) &resfs_dquota));
 	if (TST_ERR == EINVAL || TST_ERR == ENOSYS)
 		x_getnextquota_nsup = 1;
 
-	TEST(quotactl(QCMD(Q_XGETQSTATV, quotatype), tst_device->dev, test_id,
+	TEST(do_quotactl(fd, QCMD(Q_XGETQSTATV, quotatype), tst_device->dev, test_id,
 		      (void *) &resfs_qstatv));
 	if (TST_ERR == EINVAL || TST_ERR == ENOSYS)
 		x_getstatv_nsup = 1;
@@ -52,7 +51,7 @@ void check_qoff(int subcmd, char *desp, int flag)
 	int res;
 	struct fs_quota_stat res_qstat;
 
-	res = quotactl(subcmd, tst_device->dev, test_id, (void *) &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");
@@ -72,7 +71,7 @@ void check_qon(int subcmd, char *desp, int flag)
 	int res;
 	struct fs_quota_stat res_qstat;
 
-	res = quotactl(subcmd, tst_device->dev, test_id, (void *) &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");
@@ -94,7 +93,7 @@ void check_qoffv(int subcmd, char *desp, int flag)
 		.qs_version = FS_QSTATV_VERSION1,
 	};
 
-	res = quotactl(subcmd, tst_device->dev, test_id, (void *) &res_qstatv);
+	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");
@@ -116,7 +115,7 @@ void check_qonv(int subcmd, char *desp, int flag)
 		.qs_version = FS_QSTATV_VERSION1
 	};
 
-	res = quotactl(subcmd, tst_device->dev, test_id, (void *) &res_qstatv);
+	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");
@@ -138,7 +137,7 @@ void check_qlim(int subcmd, char *desp)
 
 	res_dquota.d_rtb_softlimit = 0;
 
-	res = quotactl(subcmd, tst_device->dev, test_id, (void *) &res_dquota);
+	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");
diff --git a/testcases/kernel/syscalls/quotactl/quotactl05.c b/testcases/kernel/syscalls/quotactl/quotactl05.c
index 15a6c1e67..e56e191df 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl05.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl05.c
@@ -62,10 +62,17 @@ static struct t_case {
 
 static void setup(void)
 {
-	test_id = geteuid();
+	quotactl_info();
+	fd = SAFE_OPEN(MNTPOINT, O_RDONLY);
 	check_support_cmd(PRJQUOTA);
 }
 
+static void cleanup(void)
+{
+	if (fd > -1)
+		SAFE_CLOSE(fd);
+}
+
 static void verify_quota(unsigned int n)
 {
 	struct t_case *tc = &tcases[n];
@@ -85,7 +92,7 @@ static void verify_quota(unsigned int n)
 		return;
 	}
 
-	TEST(quotactl(tc->cmd, tst_device->dev, test_id, tc->addr));
+	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);
 		return;
@@ -107,9 +114,11 @@ static struct tst_test test = {
 	.tcnt = ARRAY_SIZE(tcases),
 	.mount_device = 1,
 	.dev_fs_type = "xfs",
-	.mntpoint = mntpoint,
+	.mntpoint = MNTPOINT,
 	.mnt_data = "prjquota",
 	.setup = setup,
+	.cleanup = cleanup,
+	.test_variants = QUOTACTL_SYSCALL_VARIANTS,
 };
 
 #else
-- 
2.23.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [LTP] [PATCH v3 09/12] syscalls/quotactl03: Add quotactl_fd test variant
  2021-11-09 10:54 [LTP] [PATCH v3 06/12] lapi/quotactl.h: Add fallback for quotactl_fd Yang Xu
  2021-11-09 10:54 ` [LTP] [PATCH v3 07/12] syscalls/quotactl08: Test quoatctl01 but quota info hidden in filesystem Yang Xu
  2021-11-09 10:54 ` [LTP] [PATCH v3 08/12] syscalls/quotactl02, 5: Add quotactl_fd test variant Yang Xu
@ 2021-11-09 10:54 ` Yang Xu
  2 siblings, 0 replies; 32+ messages in thread
From: Yang Xu @ 2021-11-09 10:54 UTC (permalink / raw)
  To: ltp

Also remove dupcliated header file.

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 .../kernel/syscalls/quotactl/quotactl03.c     | 23 +++++++++++++++----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/testcases/kernel/syscalls/quotactl/quotactl03.c b/testcases/kernel/syscalls/quotactl/quotactl03.c
index e0e4bf5b2..22f5496b6 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl03.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl03.c
@@ -23,19 +23,17 @@
  */
 
 #define _GNU_SOURCE
-#include "config.h"
 #include <errno.h>
 #include <unistd.h>
 #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>
 
-static const char mntpoint[] = "mnt_point";
 static uint32_t test_id = 0xfffffffc;
 
 static void verify_quota(void)
@@ -44,7 +42,7 @@ static void verify_quota(void)
 
 	res_dquota.d_id = 1;
 
-	TEST(quotactl(QCMD(Q_XGETNEXTQUOTA, USRQUOTA), tst_device->dev,
+	TEST(do_quotactl(fd, QCMD(Q_XGETNEXTQUOTA, USRQUOTA), tst_device->dev,
 		test_id, (void *)&res_dquota));
 	if (TST_RET != -1) {
 		tst_res(TFAIL, "quotactl() found the next active ID: %u unexpectedly",
@@ -63,7 +61,21 @@ static void verify_quota(void)
 		tst_res(TPASS, "quotactl() failed with ENOENT as expected");
 }
 
+static void setup(void)
+{
+	quotactl_info();
+	fd = SAFE_OPEN(MNTPOINT, O_RDONLY);
+}
+
+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",
@@ -72,8 +84,9 @@ static struct tst_test test = {
 	.test_all = verify_quota,
 	.mount_device = 1,
 	.dev_fs_type = "xfs",
-	.mntpoint = mntpoint,
+	.mntpoint = MNTPOINT,
 	.mnt_data = "usrquota",
+	.test_variants = QUOTACTL_SYSCALL_VARIANTS,
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "657bdfb7f5e6"},
 		{}
-- 
2.23.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* Re: [LTP] [PATCH v3 07/12] syscalls/quotactl08: Test quoatctl01 but quota info hidden in filesystem
  2021-11-09 10:54 ` [LTP] [PATCH v3 07/12] syscalls/quotactl08: Test quoatctl01 but quota info hidden in filesystem Yang Xu
@ 2021-11-10 16:32   ` Cyril Hrubis
  2021-11-11  8:48     ` xuyang2018.jy
  0 siblings, 1 reply; 32+ messages in thread
From: Cyril Hrubis @ 2021-11-10 16:32 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi!
> +	f = SAFE_POPEN("mkfs.ext4 -V 2>&1", "r");
> +	rc = fscanf(f, "mke2fs %d.%d.%d", &major, &minor, &patch);
> +	if (rc != 3)
> +		tst_res(TWARN, "Unable parse version number");
> +	else if (major * 10000 + minor * 100 + patch < 14300)
> +		tst_brk(TCONF, "Test needs mkfs.ext4 >= 1.43 for quota option, test skipped");
> +	pclose(f);

Ideally this should be added to the .needs_cmds instead so that we get
the minimal version in the test metadata too.

I wonder how this should be done.

One possibility would be adding support for version in the needs_cmds
strings as:

"mkfs.ext4 >= 1.43"

Then we would have to add a table of version checks to the library as
well so that we could lookup a function based on the command name.

Something as:

static long mkfs_ext4_version_parser(void)
{
	f = SAFE_POPEN("mkfs.ext4 -V 2>&1", "r");
	rc = fscanf(f, "mke2fs %d.%d.%d", &major, &minor, &patch);
	pclose(f);
	if (rc != 3) {
		tst_res(TWARN, "Unable to parse mkfs.ext4 version");
		return -1;
	}

	return major * 10000 * minor * 100 + patch;
}

static struct version_parser {
	const char *name,
	long (*parser)(void);
} version_parsers[] = {
	{.cmd = "mkfs.ext4", .parser = mkfs_ext4_version_parser},
	{},
};

Then the library would do:

	struct version_parser *p;
	size_t cmd_len;
	long version;
	char *str, *version;

	str = strchr(cmd, ' ');
	if (!str)
		return;

	version = strchr(str, ' ');
	if (!version)
		tst_brk(TBROK, "Missing version in %s", cmd);

	//TODO: check that the string between str and version is a
	//correct operator

	cmd_len = str - cmd;

	for (p = *version_parsers; *p; p++) {
		if (strlen(p->name) != cmd_len)
			continue;

		if (!strncmp(p->name, cmd, cmd_len))
			break;
	}

	if (!p->name)
		tst_brk(TBROK, "No version parser for %s implemented!");

	long ver = p->parser();
	if (ver < 0)
		tst_brk(TBROK, "Failed to parse %s version", p->name);

	/* now we have to parse the version from the version variable
	 * and compare it with the ver variable */

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [LTP] [PATCH v3 07/12] syscalls/quotactl08: Test quoatctl01 but quota info hidden in filesystem
  2021-11-10 16:32   ` Cyril Hrubis
@ 2021-11-11  8:48     ` xuyang2018.jy
  2021-11-11 14:30       ` Cyril Hrubis
  0 siblings, 1 reply; 32+ messages in thread
From: xuyang2018.jy @ 2021-11-11  8:48 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi Cyril
> Hi!
>> +	f = SAFE_POPEN("mkfs.ext4 -V 2>&1", "r");
>> +	rc = fscanf(f, "mke2fs %d.%d.%d",&major,&minor,&patch);
>> +	if (rc != 3)
>> +		tst_res(TWARN, "Unable parse version number");
>> +	else if (major * 10000 + minor * 100 + patch<  14300)
>> +		tst_brk(TCONF, "Test needs mkfs.ext4>= 1.43 for quota option, test skipped");
>> +	pclose(f);
>
> Ideally this should be added to the .needs_cmds instead so that we get
> the minimal version in the test metadata too.
Good suggestion, I am looking your code. But As my commit log said,  add 
a lib mkfs.ext4 version check after this quotactl patchset are merged.

Then we can add this version check and make use it for not only 
quotactl04,08,09 case but also for statx05.c.

Best Regards
Yang Xu
>
> I wonder how this should be done.
>
> One possibility would be adding support for version in the needs_cmds
> strings as:
>
> "mkfs.ext4>= 1.43"
>
> Then we would have to add a table of version checks to the library as
> well so that we could lookup a function based on the command name.
>
> Something as:
>
> static long mkfs_ext4_version_parser(void)
> {
> 	f = SAFE_POPEN("mkfs.ext4 -V 2>&1", "r");
> 	rc = fscanf(f, "mke2fs %d.%d.%d",&major,&minor,&patch);
> 	pclose(f);
> 	if (rc != 3) {
> 		tst_res(TWARN, "Unable to parse mkfs.ext4 version");
> 		return -1;
> 	}
>
> 	return major * 10000 * minor * 100 + patch;
> }
>
> static struct version_parser {
> 	const char *name,
> 	long (*parser)(void);
> } version_parsers[] = {
> 	{.cmd = "mkfs.ext4", .parser = mkfs_ext4_version_parser},
> 	{},
> };
>
> Then the library would do:
>
> 	struct version_parser *p;
> 	size_t cmd_len;
> 	long version;
> 	char *str, *version;
>
> 	str = strchr(cmd, ' ');
> 	if (!str)
> 		return;
>
> 	version = strchr(str, ' ');
> 	if (!version)
> 		tst_brk(TBROK, "Missing version in %s", cmd);
>
> 	//TODO: check that the string between str and version is a
> 	//correct operator
>
> 	cmd_len = str - cmd;
>
> 	for (p = *version_parsers; *p; p++) {
> 		if (strlen(p->name) != cmd_len)
> 			continue;
>
> 		if (!strncmp(p->name, cmd, cmd_len))
> 			break;
> 	}
>
> 	if (!p->name)
> 		tst_brk(TBROK, "No version parser for %s implemented!");
>
> 	long ver = p->parser();
> 	if (ver<  0)
> 		tst_brk(TBROK, "Failed to parse %s version", p->name);
>
> 	/* now we have to parse the version from the version variable
> 	 * and compare it with the ver variable */
>

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [LTP] [PATCH v3 07/12] syscalls/quotactl08: Test quoatctl01 but quota info hidden in filesystem
  2021-11-11  8:48     ` xuyang2018.jy
@ 2021-11-11 14:30       ` Cyril Hrubis
  2021-11-26  9:32         ` xuyang2018.jy
  2021-12-13  7:26         ` [LTP] [PATCH v4 1/6] " Yang Xu
  0 siblings, 2 replies; 32+ messages in thread
From: Cyril Hrubis @ 2021-11-11 14:30 UTC (permalink / raw)
  To: xuyang2018.jy; +Cc: ltp

Hi!
> >> +	f = SAFE_POPEN("mkfs.ext4 -V 2>&1", "r");
> >> +	rc = fscanf(f, "mke2fs %d.%d.%d",&major,&minor,&patch);
> >> +	if (rc != 3)
> >> +		tst_res(TWARN, "Unable parse version number");
> >> +	else if (major * 10000 + minor * 100 + patch<  14300)
> >> +		tst_brk(TCONF, "Test needs mkfs.ext4>= 1.43 for quota option, test skipped");
> >> +	pclose(f);
> >
> > Ideally this should be added to the .needs_cmds instead so that we get
> > the minimal version in the test metadata too.
> Good suggestion, I am looking your code. But As my commit log said,  add 
> a lib mkfs.ext4 version check after this quotactl patchset are merged.

Sure I will continue with the review of the patches next week.

> Then we can add this version check and make use it for not only 
> quotactl04,08,09 case but also for statx05.c.

Indeed, the plan is to use this for all tests that needs to check any
versions of the tools.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [LTP] [PATCH v3 07/12] syscalls/quotactl08: Test quoatctl01 but quota info hidden in filesystem
  2021-11-11 14:30       ` Cyril Hrubis
@ 2021-11-26  9:32         ` xuyang2018.jy
  2021-12-13  7:26         ` [LTP] [PATCH v4 1/6] " Yang Xu
  1 sibling, 0 replies; 32+ messages in thread
From: xuyang2018.jy @ 2021-11-26  9:32 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi Cyril
> Hi!
>>>> +	f = SAFE_POPEN("mkfs.ext4 -V 2>&1", "r");
>>>> +	rc = fscanf(f, "mke2fs %d.%d.%d",&major,&minor,&patch);
>>>> +	if (rc != 3)
>>>> +		tst_res(TWARN, "Unable parse version number");
>>>> +	else if (major * 10000 + minor * 100 + patch<   14300)
>>>> +		tst_brk(TCONF, "Test needs mkfs.ext4>= 1.43 for quota option, test skipped");
>>>> +	pclose(f);
>>>
>>> Ideally this should be added to the .needs_cmds instead so that we get
>>> the minimal version in the test metadata too.
>> Good suggestion, I am looking your code. But As my commit log said,  add
>> a lib mkfs.ext4 version check after this quotactl patchset are merged.
>
> Sure I will continue with the review of the patches next week.
>
>> Then we can add this version check and make use it for not only
>> quotactl04,08,09 case but also for statx05.c.
>
> Indeed, the plan is to use this for all tests that needs to check any
> versions of the tools.
Got it.
I have write a draft for this and works well.
I will send the parser patch in the next week.

Best Regards
Yang Xu
>

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [LTP] [PATCH v4 1/6] syscalls/quotactl08: Test quoatctl01 but quota info hidden in filesystem
  2021-11-11 14:30       ` Cyril Hrubis
  2021-11-26  9:32         ` xuyang2018.jy
@ 2021-12-13  7:26         ` Yang Xu
  2021-12-13  7:26           ` [LTP] [PATCH v4 2/6] syscalls/quotactl02, 5: Add quotactl_fd test variant Yang Xu
                             ` (6 more replies)
  1 sibling, 7 replies; 32+ messages in thread
From: Yang Xu @ 2021-12-13  7:26 UTC (permalink / raw)
  To: ltp

It uses two variants(quotactl and quotactl_fd). The difference for quotactl01
is that we don't use quotacheck command and quota info hidden in filesystem.

It also needs mkfs.ext4 supports quota feature.  This feature is disabled[1]
before e2fsprog 1.42 when not specifying a --enable-quota option in compile-time
and e2fsprog 1.43 remove this disable[2]. So we should limit the e2fsprog to 1.43.

[1]https://ext4.wiki.kernel.org/index.php/Quota
[2]https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git/commit/?h=v1.43&id=9e8fcd6e

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 runtest/syscalls                              |   1 +
 testcases/kernel/syscalls/quotactl/.gitignore |   1 +
 .../kernel/syscalls/quotactl/quotactl08.c     | 228 ++++++++++++++++++
 .../syscalls/quotactl/quotactl_syscall_var.h  |  32 +++
 4 files changed, 262 insertions(+)
 create mode 100644 testcases/kernel/syscalls/quotactl/quotactl08.c
 create mode 100644 testcases/kernel/syscalls/quotactl/quotactl_syscall_var.h

diff --git a/runtest/syscalls b/runtest/syscalls
index bcf3d56c9..c795b9101 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1071,6 +1071,7 @@ quotactl04 quotactl04
 quotactl05 quotactl05
 quotactl06 quotactl06
 quotactl07 quotactl07
+quotactl08 quotactl08
 
 read01 read01
 read02 read02
diff --git a/testcases/kernel/syscalls/quotactl/.gitignore b/testcases/kernel/syscalls/quotactl/.gitignore
index 8d2ef94d9..dab9b3420 100644
--- a/testcases/kernel/syscalls/quotactl/.gitignore
+++ b/testcases/kernel/syscalls/quotactl/.gitignore
@@ -5,3 +5,4 @@
 /quotactl05
 /quotactl06
 /quotactl07
+/quotactl08
diff --git a/testcases/kernel/syscalls/quotactl/quotactl08.c b/testcases/kernel/syscalls/quotactl/quotactl08.c
new file mode 100644
index 000000000..1b8f1cd2b
--- /dev/null
+++ b/testcases/kernel/syscalls/quotactl/quotactl08.c
@@ -0,0 +1,228 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
+ * This testcases checks that quotactl(2) on ext4 filesystem succeeds to:
+ *
+ * - turn on quota with Q_QUOTAON flag for user
+ * - set disk quota limits with Q_SETQUOTA flag for user
+ * - get disk quota limits with Q_GETQUOTA flag for user
+ * - set information about quotafile with Q_SETINFO flag for user
+ * - get information about quotafile with Q_GETINFO flag for user
+ * - get quota format with Q_GETFMT flag for user
+ * - update quota usages with Q_SYNC flag for user
+ * - get disk quota limit greater than or equal to ID with Q_GETNEXTQUOTA flag for user
+ * - turn off quota with Q_QUOTAOFF flag for user
+ * - turn on quota with Q_QUOTAON flag for group
+ * - set disk quota limits with Q_SETQUOTA flag for group
+ * - get disk quota limits with Q_GETQUOTA flag for group
+ * - set information about quotafile with Q_SETINFO flag for group
+ * - get information about quotafile with Q_GETINFO flag for group
+ * - get quota format with Q_GETFMT flag for group
+ * - update quota usages with Q_SYNC flag for group
+ * - get disk quota limit greater than or equal to ID with Q_GETNEXTQUOTA flag for group
+ * - turn off quota with Q_QUOTAOFF flag for group
+ *
+ * It is similar to quotactl01.c, only two difference
+ * - use new quotactl_fd syscalls if supports
+ * - quota file hidden in filesystem
+ *
+ * Minimum e2fsprogs version required is 1.43.
+ */
+
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+#include "tst_test.h"
+#include "quotactl_syscall_var.h"
+
+#define MNTPOINT	"mntpoint"
+
+static int32_t fmt_id = QFMT_VFS_V1;
+static int test_id, mount_flag;
+static struct dqblk set_dq = {
+	.dqb_bsoftlimit = 100,
+	.dqb_valid = QIF_BLIMITS
+};
+static struct dqblk res_dq;
+
+static struct dqinfo set_qf = {
+	.dqi_bgrace = 80,
+	.dqi_valid = IIF_BGRACE
+};
+static struct dqinfo res_qf;
+static int32_t fmt_buf;
+static int getnextquota_nsup;
+
+static struct if_nextdqblk res_ndq;
+
+static struct tcase {
+	int cmd;
+	int *id;
+	void *addr;
+	void *set_data;
+	void *res_data;
+	int sz;
+	char *des;
+	char *tname;
+} tcases[] = {
+	{QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, NULL,
+	NULL, NULL, 0, "turn on quota for user",
+	"QCMD(Q_QUOTAON, USRQUOTA)"},
+
+	{QCMD(Q_SETQUOTA, USRQUOTA), &test_id, &set_dq,
+	NULL, NULL, 0, "set disk quota limit for user",
+	"QCMD(Q_SETQUOTA, USRQUOTA)"},
+
+	{QCMD(Q_GETQUOTA, USRQUOTA), &test_id, &res_dq,
+	&set_dq.dqb_bsoftlimit, &res_dq.dqb_bsoftlimit,
+	sizeof(res_dq.dqb_bsoftlimit), "get disk quota limit for user",
+	"QCMD(Q_GETQUOTA, USRQUOTA)"},
+
+	{QCMD(Q_SETINFO, USRQUOTA), &test_id, &set_qf,
+	NULL, NULL, 0, "set information about quotafile for user",
+	"QCMD(Q_SETINFO, USRQUOTA)"},
+
+	{QCMD(Q_GETINFO, USRQUOTA), &test_id, &res_qf,
+	&set_qf.dqi_bgrace, &res_qf.dqi_bgrace, sizeof(res_qf.dqi_bgrace),
+	"get information about quotafile for user",
+	"QCMD(Q_GETINFO, USRQUOTA)"},
+
+	{QCMD(Q_GETFMT, USRQUOTA), &test_id, &fmt_buf,
+	&fmt_id, &fmt_buf, sizeof(fmt_buf),
+	"get quota format for user",
+	"QCMD(Q_GETFMT, USRQUOTA)"},
+
+	{QCMD(Q_SYNC, USRQUOTA), &test_id, &res_dq,
+	NULL, NULL, 0, "update quota usages for user",
+	"QCMD(Q_SYNC, USRQUOTA)"},
+
+	{QCMD(Q_GETNEXTQUOTA, USRQUOTA), &test_id, &res_ndq,
+	&test_id, &res_ndq.dqb_id, sizeof(res_ndq.dqb_id),
+	"get next disk quota limit for user",
+	"QCMD(Q_GETNEXTQUOTA, USRQUOTA)"},
+
+	{QCMD(Q_QUOTAOFF, USRQUOTA), &test_id, NULL,
+	NULL, NULL, 0, "turn off quota for user",
+	"QCMD(Q_QUOTAOFF, USRQUOTA)"},
+
+	{QCMD(Q_QUOTAON, GRPQUOTA), &fmt_id, NULL,
+	NULL, NULL, 0, "turn on quota for group",
+	"QCMD(Q_QUOTAON, GRPQUOTA)"},
+
+	{QCMD(Q_SETQUOTA, GRPQUOTA), &test_id, &set_dq,
+	NULL, NULL, 0, "set disk quota limit for group",
+	"QCMD(Q_SETQUOTA, GRPQUOTA)"},
+
+	{QCMD(Q_GETQUOTA, GRPQUOTA), &test_id, &res_dq, &set_dq.dqb_bsoftlimit,
+	&res_dq.dqb_bsoftlimit, sizeof(res_dq.dqb_bsoftlimit),
+	"set disk quota limit for group",
+	"QCMD(Q_GETQUOTA, GRPQUOTA)"},
+
+	{QCMD(Q_SETINFO, GRPQUOTA), &test_id, &set_qf,
+	NULL, NULL, 0, "set information about quotafile for group",
+	"QCMD(Q_SETINFO, GRPQUOTA)"},
+
+	{QCMD(Q_GETINFO, GRPQUOTA), &test_id, &res_qf, &set_qf.dqi_bgrace,
+	&res_qf.dqi_bgrace, sizeof(res_qf.dqi_bgrace),
+	"get information about quotafile for group",
+	"QCMD(Q_GETINFO, GRPQUOTA)"},
+
+	{QCMD(Q_GETFMT, GRPQUOTA), &test_id, &fmt_buf,
+	&fmt_id, &fmt_buf, sizeof(fmt_buf), "get quota format for group",
+	"QCMD(Q_GETFMT, GRPQUOTA)"},
+
+	{QCMD(Q_SYNC, GRPQUOTA), &test_id, &res_dq,
+	NULL, NULL, 0, "update quota usages for group",
+	"QCMD(Q_SYNC, GRPQUOTA)"},
+
+	{QCMD(Q_GETNEXTQUOTA, GRPQUOTA), &test_id, &res_ndq,
+	&test_id, &res_ndq.dqb_id, sizeof(res_ndq.dqb_id),
+	"get next disk quota limit for group",
+	"QCMD(Q_GETNEXTQUOTA, GRPQUOTA)"},
+
+	{QCMD(Q_QUOTAOFF, GRPQUOTA), &test_id, NULL,
+	NULL, NULL, 0, "turn off quota for group",
+	"QCMD(Q_QUOTAOFF, GRPQUOTA)"},
+};
+
+static void setup(void)
+{
+	const char *const fs_opts[] = { "-O quota", NULL};
+
+	quotactl_info();
+
+	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,
+		0, (void *) &res_ndq));
+	if (TST_ERR == EINVAL || TST_ERR == ENOSYS)
+		getnextquota_nsup = 1;
+}
+
+static void cleanup(void)
+{
+	if (fd > -1)
+		SAFE_CLOSE(fd);
+	if (mount_flag && tst_umount(MNTPOINT))
+		tst_res(TWARN | TERRNO, "umount(%s)", MNTPOINT);
+}
+
+static void verify_quota(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+
+	res_dq.dqb_bsoftlimit = 0;
+	res_qf.dqi_igrace = 0;
+	fmt_buf = 0;
+	res_ndq.dqb_id = -1;
+
+	tst_res(TINFO, "Test #%d: %s", n, tc->tname);
+	if ((tc->cmd == QCMD(Q_GETNEXTQUOTA, USRQUOTA) ||
+		tc->cmd == QCMD(Q_GETNEXTQUOTA, GRPQUOTA)) &&
+		getnextquota_nsup) {
+		tst_res(TCONF, "current system doesn't support this cmd");
+		return;
+	}
+	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;
+	}
+
+	if (memcmp(tc->res_data, tc->set_data, tc->sz)) {
+		tst_res(TFAIL, "quotactl failed to %s", tc->des);
+		tst_res_hexd(TINFO, tc->res_data, tc->sz, "retval:   ");
+		tst_res_hexd(TINFO, tc->set_data, tc->sz, "expected: ");
+		return;
+	}
+
+	tst_res(TPASS, "quotactl succeeded to %s", tc->des);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_QFMT_V2",
+		NULL
+	},
+	.test = verify_quota,
+	.tcnt = ARRAY_SIZE(tcases),
+	.mntpoint = MNTPOINT,
+	.dev_fs_type = "ext4",
+	.needs_device = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_variants = QUOTACTL_SYSCALL_VARIANTS,
+	.needs_cmds = (const char *[]) {
+		"mkfs.ext4 >= 1.43.0",
+		NULL
+	}
+};
diff --git a/testcases/kernel/syscalls/quotactl/quotactl_syscall_var.h b/testcases/kernel/syscalls/quotactl/quotactl_syscall_var.h
new file mode 100644
index 000000000..3d1a2c8f5
--- /dev/null
+++ b/testcases/kernel/syscalls/quotactl/quotactl_syscall_var.h
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+#ifndef LTP_QUOTACTL_SYSCALL_VAR_H
+#define LTP_QUOTACTL_SYSCALL_VAR_H
+
+#include "lapi/quotactl.h"
+
+#define QUOTACTL_SYSCALL_VARIANTS 2
+#define MNTPOINT "mntpoint"
+
+static int fd = -1;
+
+static int do_quotactl(int fd, int cmd, const char *special, int id, caddr_t addr)
+{
+	if (tst_variant == 0)
+		return quotactl(cmd, special, id, addr);
+	return quotactl_fd(fd, cmd, id, addr);
+}
+
+static void quotactl_info(void)
+{
+	if (tst_variant == 0)
+		tst_res(TINFO, "Test quotactl()");
+	else
+		tst_res(TINFO, "Test quotactl_fd()");
+}
+
+#endif /* LTP_QUOTACTL_SYSCALL_VAR_H */
-- 
2.23.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [LTP] [PATCH v4 2/6] syscalls/quotactl02, 5: Add quotactl_fd test variant
  2021-12-13  7:26         ` [LTP] [PATCH v4 1/6] " Yang Xu
@ 2021-12-13  7:26           ` Yang Xu
  2022-01-07 14:30             ` Cyril Hrubis
  2021-12-13  7:26           ` [LTP] [PATCH v4 3/6] syscalls/quotactl03: " Yang Xu
                             ` (5 subsequent siblings)
  6 siblings, 1 reply; 32+ messages in thread
From: Yang Xu @ 2021-12-13  7:26 UTC (permalink / raw)
  To: ltp

Also remove useless geteuid and add static prefix.

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 .../kernel/syscalls/quotactl/quotactl02.c     | 15 ++++++++--
 .../kernel/syscalls/quotactl/quotactl02.h     | 30 +++++++++----------
 .../kernel/syscalls/quotactl/quotactl05.c     | 15 ++++++++--
 3 files changed, 39 insertions(+), 21 deletions(-)

diff --git a/testcases/kernel/syscalls/quotactl/quotactl02.c b/testcases/kernel/syscalls/quotactl/quotactl02.c
index 55a6a8906..56fa23b9d 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl02.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl02.c
@@ -99,11 +99,18 @@ static struct t_case {
 
 static void setup(void)
 {
-	test_id = geteuid();
+	quotactl_info();
+	fd = SAFE_OPEN(MNTPOINT, O_RDONLY);
 	check_support_cmd(USRQUOTA);
 	check_support_cmd(GRPQUOTA);
 }
 
+static void cleanup(void)
+{
+	if (fd > -1)
+		SAFE_CLOSE(fd);
+}
+
 static void verify_quota(unsigned int n)
 {
 	struct t_case *tc = &tcases[n];
@@ -122,7 +129,7 @@ static void verify_quota(unsigned int n)
 		return;
 	}
 
-	TEST(quotactl(tc->cmd, tst_device->dev, test_id, tc->addr));
+	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);
 		return;
@@ -144,9 +151,11 @@ static struct tst_test test = {
 	.tcnt = ARRAY_SIZE(tcases),
 	.mount_device = 1,
 	.dev_fs_type = "xfs",
-	.mntpoint = mntpoint,
+	.mntpoint = MNTPOINT,
 	.mnt_data = "usrquota,grpquota",
 	.setup = setup,
+	.cleanup = cleanup,
+	.test_variants = QUOTACTL_SYSCALL_VARIANTS,
 };
 #else
 	TST_TEST_TCONF("System doesn't have <xfs/xqm.h>");
diff --git a/testcases/kernel/syscalls/quotactl/quotactl02.h b/testcases/kernel/syscalls/quotactl/quotactl02.h
index 3351fb578..28b632646 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl02.h
+++ b/testcases/kernel/syscalls/quotactl/quotactl02.h
@@ -12,7 +12,7 @@
 #include <unistd.h>
 #include <stdio.h>
 #include "tst_test.h"
-#include "lapi/quotactl.h"
+#include "quotactl_syscall_var.h"
 
 #ifdef HAVE_XFS_XQM_H
 # include <xfs/xqm.h>
@@ -24,9 +24,8 @@ static struct fs_disk_quota set_dquota = {
 static uint32_t test_id;
 static int x_getnextquota_nsup;
 static int x_getstatv_nsup;
-static const char mntpoint[] = "mnt_point";
 
-void check_support_cmd(int quotatype)
+static void check_support_cmd(int quotatype)
 {
 	struct fs_disk_quota resfs_dquota;
 	struct fs_quota_statv resfs_qstatv = {
@@ -36,23 +35,24 @@ void check_support_cmd(int quotatype)
 	x_getnextquota_nsup = 0;
 	x_getstatv_nsup = 0;
 
-	TEST(quotactl(QCMD(Q_XGETNEXTQUOTA, quotatype), tst_device->dev,
+	TEST(do_quotactl(fd, QCMD(Q_XGETNEXTQUOTA, quotatype), tst_device->dev,
 		      test_id, (void *) &resfs_dquota));
 	if (TST_ERR == EINVAL || TST_ERR == ENOSYS)
 		x_getnextquota_nsup = 1;
 
-	TEST(quotactl(QCMD(Q_XGETQSTATV, quotatype), tst_device->dev, test_id,
+	TEST(do_quotactl(fd, QCMD(Q_XGETQSTATV, quotatype), tst_device->dev, test_id,
 		      (void *) &resfs_qstatv));
 	if (TST_ERR == EINVAL || TST_ERR == ENOSYS)
 		x_getstatv_nsup = 1;
 
 }
-void check_qoff(int subcmd, char *desp, int flag)
+
+static void check_qoff(int subcmd, char *desp, int flag)
 {
 	int res;
 	struct fs_quota_stat res_qstat;
 
-	res = quotactl(subcmd, tst_device->dev, test_id, (void *) &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");
@@ -67,12 +67,12 @@ void check_qoff(int subcmd, char *desp, int flag)
 	tst_res(TPASS, "quotactl() succeeded to %s", desp);
 }
 
-void check_qon(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 = quotactl(subcmd, tst_device->dev, test_id, (void *) &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");
@@ -87,14 +87,14 @@ void check_qon(int subcmd, char *desp, int flag)
 	tst_res(TPASS, "quotactl() succeeded to %s", desp);
 }
 
-void check_qoffv(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 = quotactl(subcmd, tst_device->dev, test_id, (void *) &res_qstatv);
+	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");
@@ -109,14 +109,14 @@ void check_qoffv(int subcmd, char *desp, int flag)
 	tst_res(TPASS, "quotactl() succeeded to %s", desp);
 }
 
-void check_qonv(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 = quotactl(subcmd, tst_device->dev, test_id, (void *) &res_qstatv);
+	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");
@@ -131,14 +131,14 @@ void check_qonv(int subcmd, char *desp, int flag)
 	tst_res(TPASS, "quotactl() succeeded to %s", desp);
 }
 
-void check_qlim(int subcmd, char *desp)
+static void check_qlim(int subcmd, char *desp)
 {
 	int res;
 	static struct fs_disk_quota res_dquota;
 
 	res_dquota.d_rtb_softlimit = 0;
 
-	res = quotactl(subcmd, tst_device->dev, test_id, (void *) &res_dquota);
+	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");
diff --git a/testcases/kernel/syscalls/quotactl/quotactl05.c b/testcases/kernel/syscalls/quotactl/quotactl05.c
index 15a6c1e67..e56e191df 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl05.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl05.c
@@ -62,10 +62,17 @@ static struct t_case {
 
 static void setup(void)
 {
-	test_id = geteuid();
+	quotactl_info();
+	fd = SAFE_OPEN(MNTPOINT, O_RDONLY);
 	check_support_cmd(PRJQUOTA);
 }
 
+static void cleanup(void)
+{
+	if (fd > -1)
+		SAFE_CLOSE(fd);
+}
+
 static void verify_quota(unsigned int n)
 {
 	struct t_case *tc = &tcases[n];
@@ -85,7 +92,7 @@ static void verify_quota(unsigned int n)
 		return;
 	}
 
-	TEST(quotactl(tc->cmd, tst_device->dev, test_id, tc->addr));
+	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);
 		return;
@@ -107,9 +114,11 @@ static struct tst_test test = {
 	.tcnt = ARRAY_SIZE(tcases),
 	.mount_device = 1,
 	.dev_fs_type = "xfs",
-	.mntpoint = mntpoint,
+	.mntpoint = MNTPOINT,
 	.mnt_data = "prjquota",
 	.setup = setup,
+	.cleanup = cleanup,
+	.test_variants = QUOTACTL_SYSCALL_VARIANTS,
 };
 
 #else
-- 
2.23.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [LTP] [PATCH v4 3/6] syscalls/quotactl03: Add quotactl_fd test variant
  2021-12-13  7:26         ` [LTP] [PATCH v4 1/6] " Yang Xu
  2021-12-13  7:26           ` [LTP] [PATCH v4 2/6] syscalls/quotactl02, 5: Add quotactl_fd test variant Yang Xu
@ 2021-12-13  7:26           ` Yang Xu
  2022-01-07 14:59             ` Cyril Hrubis
  2021-12-13  7:26           ` [LTP] [PATCH v4 4/6] syscalls/quotactl04: " Yang Xu
                             ` (4 subsequent siblings)
  6 siblings, 1 reply; 32+ messages in thread
From: Yang Xu @ 2021-12-13  7:26 UTC (permalink / raw)
  To: ltp

Also remove dupcliated header file.

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 .../kernel/syscalls/quotactl/quotactl03.c     | 23 +++++++++++++++----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/testcases/kernel/syscalls/quotactl/quotactl03.c b/testcases/kernel/syscalls/quotactl/quotactl03.c
index e0e4bf5b2..22f5496b6 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl03.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl03.c
@@ -23,19 +23,17 @@
  */
 
 #define _GNU_SOURCE
-#include "config.h"
 #include <errno.h>
 #include <unistd.h>
 #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>
 
-static const char mntpoint[] = "mnt_point";
 static uint32_t test_id = 0xfffffffc;
 
 static void verify_quota(void)
@@ -44,7 +42,7 @@ static void verify_quota(void)
 
 	res_dquota.d_id = 1;
 
-	TEST(quotactl(QCMD(Q_XGETNEXTQUOTA, USRQUOTA), tst_device->dev,
+	TEST(do_quotactl(fd, QCMD(Q_XGETNEXTQUOTA, USRQUOTA), tst_device->dev,
 		test_id, (void *)&res_dquota));
 	if (TST_RET != -1) {
 		tst_res(TFAIL, "quotactl() found the next active ID: %u unexpectedly",
@@ -63,7 +61,21 @@ static void verify_quota(void)
 		tst_res(TPASS, "quotactl() failed with ENOENT as expected");
 }
 
+static void setup(void)
+{
+	quotactl_info();
+	fd = SAFE_OPEN(MNTPOINT, O_RDONLY);
+}
+
+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",
@@ -72,8 +84,9 @@ static struct tst_test test = {
 	.test_all = verify_quota,
 	.mount_device = 1,
 	.dev_fs_type = "xfs",
-	.mntpoint = mntpoint,
+	.mntpoint = MNTPOINT,
 	.mnt_data = "usrquota",
+	.test_variants = QUOTACTL_SYSCALL_VARIANTS,
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "657bdfb7f5e6"},
 		{}
-- 
2.23.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [LTP] [PATCH v4 4/6] syscalls/quotactl04: Add quotactl_fd test variant
  2021-12-13  7:26         ` [LTP] [PATCH v4 1/6] " Yang Xu
  2021-12-13  7:26           ` [LTP] [PATCH v4 2/6] syscalls/quotactl02, 5: Add quotactl_fd test variant Yang Xu
  2021-12-13  7:26           ` [LTP] [PATCH v4 3/6] syscalls/quotactl03: " Yang Xu
@ 2021-12-13  7:26           ` Yang Xu
  2022-01-07 15:35             ` Cyril Hrubis
  2021-12-13  7:26           ` [LTP] [PATCH v4 5/6] syscalls/quotactl09: Test error when quota info hidden in filesystem Yang Xu
                             ` (3 subsequent siblings)
  6 siblings, 1 reply; 32+ messages in thread
From: Yang Xu @ 2021-12-13  7:26 UTC (permalink / raw)
  To: ltp

Also remove useless geteuid.

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 testcases/kernel/syscalls/quotactl/quotactl04.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/testcases/kernel/syscalls/quotactl/quotactl04.c b/testcases/kernel/syscalls/quotactl/quotactl04.c
index cc107a7e4..44273c35d 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl04.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl04.c
@@ -27,10 +27,10 @@
 #include <sys/stat.h>
 #include <sys/mount.h>
 #include "tst_test.h"
-#include "lapi/quotactl.h"
+#include "quotactl_syscall_var.h"
 
 #define FMTID QFMT_VFS_V1
-#define MNTPOINT	"mntpoint"
+
 static int32_t fmt_id = FMTID;
 static int test_id, mount_flag;
 static struct dqblk set_dq = {
@@ -121,13 +121,16 @@ static void setup(void)
 {
 	const char *const fs_opts[] = {"-I 256", "-O quota,project", NULL};
 
-	test_id = geteuid();
+	quotactl_info();
 	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(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);
 }
@@ -142,7 +145,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;
@@ -172,6 +175,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 >= 1.43.0",
 		NULL
-- 
2.23.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [LTP] [PATCH v4 5/6] syscalls/quotactl09: Test error when quota info hidden in filesystem
  2021-12-13  7:26         ` [LTP] [PATCH v4 1/6] " Yang Xu
                             ` (2 preceding siblings ...)
  2021-12-13  7:26           ` [LTP] [PATCH v4 4/6] syscalls/quotactl04: " Yang Xu
@ 2021-12-13  7:26           ` Yang Xu
  2022-01-07 15:50             ` Cyril Hrubis
  2021-12-13  7:26           ` [LTP] [PATCH v4 6/6] syscalls/quotactl07: Add quotactl_fd test variant Yang Xu
                             ` (2 subsequent siblings)
  6 siblings, 1 reply; 32+ messages in thread
From: Yang Xu @ 2021-12-13  7:26 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     | 180 ++++++++++++++++++
 3 files changed, 182 insertions(+)
 create mode 100644 testcases/kernel/syscalls/quotactl/quotactl09.c

diff --git a/runtest/syscalls b/runtest/syscalls
index c795b9101..13a62e4a1 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1072,6 +1072,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..c7c485077
--- /dev/null
+++ b/testcases/kernel/syscalls/quotactl/quotactl09.c
@@ -0,0 +1,180 @@
+// 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
+ *
+ * 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;
+
+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;
+} 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;
+	const char *const fs_opts[] = { "-O quota", NULL};
+
+	quotactl_info();
+	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 (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] 32+ messages in thread

* [LTP] [PATCH v4 6/6] syscalls/quotactl07: Add quotactl_fd test variant
  2021-12-13  7:26         ` [LTP] [PATCH v4 1/6] " Yang Xu
                             ` (3 preceding siblings ...)
  2021-12-13  7:26           ` [LTP] [PATCH v4 5/6] syscalls/quotactl09: Test error when quota info hidden in filesystem Yang Xu
@ 2021-12-13  7:26           ` Yang Xu
  2022-01-07 16:03             ` Cyril Hrubis
  2021-12-23  8:03           ` [LTP] [PATCH v4 1/6] syscalls/quotactl08: Test quoatctl01 but quota info hidden in filesystem xuyang2018.jy
  2022-01-07 14:09           ` Cyril Hrubis
  6 siblings, 1 reply; 32+ messages in thread
From: Yang Xu @ 2021-12-13  7:26 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     | 22 +++++++++----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/testcases/kernel/syscalls/quotactl/quotactl07.c b/testcases/kernel/syscalls/quotactl/quotactl07.c
index 2992a6112..6e2079e0f 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl07.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl07.c
@@ -16,21 +16,18 @@
 #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"
 
-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 +36,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(MNTPOINT, O_RDONLY);
+}
 
-	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 +59,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] 32+ messages in thread

* Re: [LTP] [PATCH v4 1/6] syscalls/quotactl08: Test quoatctl01 but quota info hidden in filesystem
  2021-12-13  7:26         ` [LTP] [PATCH v4 1/6] " Yang Xu
                             ` (4 preceding siblings ...)
  2021-12-13  7:26           ` [LTP] [PATCH v4 6/6] syscalls/quotactl07: Add quotactl_fd test variant Yang Xu
@ 2021-12-23  8:03           ` xuyang2018.jy
  2022-01-07 14:09           ` Cyril Hrubis
  6 siblings, 0 replies; 32+ messages in thread
From: xuyang2018.jy @ 2021-12-23  8:03 UTC (permalink / raw)
  To: ltp

Hi

Ping.

Best Regards
Yang Xu

> It uses two variants(quotactl and quotactl_fd). The difference for quotactl01
> is that we don't use quotacheck command and quota info hidden in filesystem.
> 
> It also needs mkfs.ext4 supports quota feature.  This feature is disabled[1]
> before e2fsprog 1.42 when not specifying a --enable-quota option in compile-time
> and e2fsprog 1.43 remove this disable[2]. So we should limit the e2fsprog to 1.43.
> 
> [1]https://ext4.wiki.kernel.org/index.php/Quota
> [2]https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git/commit/?h=v1.43&id=9e8fcd6e
> 
> Signed-off-by: Yang Xu<xuyang2018.jy@fujitsu.com>
> ---
>   runtest/syscalls                              |   1 +
>   testcases/kernel/syscalls/quotactl/.gitignore |   1 +
>   .../kernel/syscalls/quotactl/quotactl08.c     | 228 ++++++++++++++++++
>   .../syscalls/quotactl/quotactl_syscall_var.h  |  32 +++
>   4 files changed, 262 insertions(+)
>   create mode 100644 testcases/kernel/syscalls/quotactl/quotactl08.c
>   create mode 100644 testcases/kernel/syscalls/quotactl/quotactl_syscall_var.h
> 
> diff --git a/runtest/syscalls b/runtest/syscalls
> index bcf3d56c9..c795b9101 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -1071,6 +1071,7 @@ quotactl04 quotactl04
>   quotactl05 quotactl05
>   quotactl06 quotactl06
>   quotactl07 quotactl07
> +quotactl08 quotactl08
> 
>   read01 read01
>   read02 read02
> diff --git a/testcases/kernel/syscalls/quotactl/.gitignore b/testcases/kernel/syscalls/quotactl/.gitignore
> index 8d2ef94d9..dab9b3420 100644
> --- a/testcases/kernel/syscalls/quotactl/.gitignore
> +++ b/testcases/kernel/syscalls/quotactl/.gitignore
> @@ -5,3 +5,4 @@
>   /quotactl05
>   /quotactl06
>   /quotactl07
> +/quotactl08
> diff --git a/testcases/kernel/syscalls/quotactl/quotactl08.c b/testcases/kernel/syscalls/quotactl/quotactl08.c
> new file mode 100644
> index 000000000..1b8f1cd2b
> --- /dev/null
> +++ b/testcases/kernel/syscalls/quotactl/quotactl08.c
> @@ -0,0 +1,228 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved
> + * Author: Yang Xu<xuyang2018.jy@fujitsu.com>
> + */
> +
> +/*\
> + * [Description]
> + * This testcases checks that quotactl(2) on ext4 filesystem succeeds to:
> + *
> + * - turn on quota with Q_QUOTAON flag for user
> + * - set disk quota limits with Q_SETQUOTA flag for user
> + * - get disk quota limits with Q_GETQUOTA flag for user
> + * - set information about quotafile with Q_SETINFO flag for user
> + * - get information about quotafile with Q_GETINFO flag for user
> + * - get quota format with Q_GETFMT flag for user
> + * - update quota usages with Q_SYNC flag for user
> + * - get disk quota limit greater than or equal to ID with Q_GETNEXTQUOTA flag for user
> + * - turn off quota with Q_QUOTAOFF flag for user
> + * - turn on quota with Q_QUOTAON flag for group
> + * - set disk quota limits with Q_SETQUOTA flag for group
> + * - get disk quota limits with Q_GETQUOTA flag for group
> + * - set information about quotafile with Q_SETINFO flag for group
> + * - get information about quotafile with Q_GETINFO flag for group
> + * - get quota format with Q_GETFMT flag for group
> + * - update quota usages with Q_SYNC flag for group
> + * - get disk quota limit greater than or equal to ID with Q_GETNEXTQUOTA flag for group
> + * - turn off quota with Q_QUOTAOFF flag for group
> + *
> + * It is similar to quotactl01.c, only two difference
> + * - use new quotactl_fd syscalls if supports
> + * - quota file hidden in filesystem
> + *
> + * Minimum e2fsprogs version required is 1.43.
> + */
> +
> +#include<errno.h>
> +#include<string.h>
> +#include<unistd.h>
> +#include "tst_test.h"
> +#include "quotactl_syscall_var.h"
> +
> +#define MNTPOINT	"mntpoint"
> +
> +static int32_t fmt_id = QFMT_VFS_V1;
> +static int test_id, mount_flag;
> +static struct dqblk set_dq = {
> +	.dqb_bsoftlimit = 100,
> +	.dqb_valid = QIF_BLIMITS
> +};
> +static struct dqblk res_dq;
> +
> +static struct dqinfo set_qf = {
> +	.dqi_bgrace = 80,
> +	.dqi_valid = IIF_BGRACE
> +};
> +static struct dqinfo res_qf;
> +static int32_t fmt_buf;
> +static int getnextquota_nsup;
> +
> +static struct if_nextdqblk res_ndq;
> +
> +static struct tcase {
> +	int cmd;
> +	int *id;
> +	void *addr;
> +	void *set_data;
> +	void *res_data;
> +	int sz;
> +	char *des;
> +	char *tname;
> +} tcases[] = {
> +	{QCMD(Q_QUOTAON, USRQUOTA),&fmt_id, NULL,
> +	NULL, NULL, 0, "turn on quota for user",
> +	"QCMD(Q_QUOTAON, USRQUOTA)"},
> +
> +	{QCMD(Q_SETQUOTA, USRQUOTA),&test_id,&set_dq,
> +	NULL, NULL, 0, "set disk quota limit for user",
> +	"QCMD(Q_SETQUOTA, USRQUOTA)"},
> +
> +	{QCMD(Q_GETQUOTA, USRQUOTA),&test_id,&res_dq,
> +	&set_dq.dqb_bsoftlimit,&res_dq.dqb_bsoftlimit,
> +	sizeof(res_dq.dqb_bsoftlimit), "get disk quota limit for user",
> +	"QCMD(Q_GETQUOTA, USRQUOTA)"},
> +
> +	{QCMD(Q_SETINFO, USRQUOTA),&test_id,&set_qf,
> +	NULL, NULL, 0, "set information about quotafile for user",
> +	"QCMD(Q_SETINFO, USRQUOTA)"},
> +
> +	{QCMD(Q_GETINFO, USRQUOTA),&test_id,&res_qf,
> +	&set_qf.dqi_bgrace,&res_qf.dqi_bgrace, sizeof(res_qf.dqi_bgrace),
> +	"get information about quotafile for user",
> +	"QCMD(Q_GETINFO, USRQUOTA)"},
> +
> +	{QCMD(Q_GETFMT, USRQUOTA),&test_id,&fmt_buf,
> +	&fmt_id,&fmt_buf, sizeof(fmt_buf),
> +	"get quota format for user",
> +	"QCMD(Q_GETFMT, USRQUOTA)"},
> +
> +	{QCMD(Q_SYNC, USRQUOTA),&test_id,&res_dq,
> +	NULL, NULL, 0, "update quota usages for user",
> +	"QCMD(Q_SYNC, USRQUOTA)"},
> +
> +	{QCMD(Q_GETNEXTQUOTA, USRQUOTA),&test_id,&res_ndq,
> +	&test_id,&res_ndq.dqb_id, sizeof(res_ndq.dqb_id),
> +	"get next disk quota limit for user",
> +	"QCMD(Q_GETNEXTQUOTA, USRQUOTA)"},
> +
> +	{QCMD(Q_QUOTAOFF, USRQUOTA),&test_id, NULL,
> +	NULL, NULL, 0, "turn off quota for user",
> +	"QCMD(Q_QUOTAOFF, USRQUOTA)"},
> +
> +	{QCMD(Q_QUOTAON, GRPQUOTA),&fmt_id, NULL,
> +	NULL, NULL, 0, "turn on quota for group",
> +	"QCMD(Q_QUOTAON, GRPQUOTA)"},
> +
> +	{QCMD(Q_SETQUOTA, GRPQUOTA),&test_id,&set_dq,
> +	NULL, NULL, 0, "set disk quota limit for group",
> +	"QCMD(Q_SETQUOTA, GRPQUOTA)"},
> +
> +	{QCMD(Q_GETQUOTA, GRPQUOTA),&test_id,&res_dq,&set_dq.dqb_bsoftlimit,
> +	&res_dq.dqb_bsoftlimit, sizeof(res_dq.dqb_bsoftlimit),
> +	"set disk quota limit for group",
> +	"QCMD(Q_GETQUOTA, GRPQUOTA)"},
> +
> +	{QCMD(Q_SETINFO, GRPQUOTA),&test_id,&set_qf,
> +	NULL, NULL, 0, "set information about quotafile for group",
> +	"QCMD(Q_SETINFO, GRPQUOTA)"},
> +
> +	{QCMD(Q_GETINFO, GRPQUOTA),&test_id,&res_qf,&set_qf.dqi_bgrace,
> +	&res_qf.dqi_bgrace, sizeof(res_qf.dqi_bgrace),
> +	"get information about quotafile for group",
> +	"QCMD(Q_GETINFO, GRPQUOTA)"},
> +
> +	{QCMD(Q_GETFMT, GRPQUOTA),&test_id,&fmt_buf,
> +	&fmt_id,&fmt_buf, sizeof(fmt_buf), "get quota format for group",
> +	"QCMD(Q_GETFMT, GRPQUOTA)"},
> +
> +	{QCMD(Q_SYNC, GRPQUOTA),&test_id,&res_dq,
> +	NULL, NULL, 0, "update quota usages for group",
> +	"QCMD(Q_SYNC, GRPQUOTA)"},
> +
> +	{QCMD(Q_GETNEXTQUOTA, GRPQUOTA),&test_id,&res_ndq,
> +	&test_id,&res_ndq.dqb_id, sizeof(res_ndq.dqb_id),
> +	"get next disk quota limit for group",
> +	"QCMD(Q_GETNEXTQUOTA, GRPQUOTA)"},
> +
> +	{QCMD(Q_QUOTAOFF, GRPQUOTA),&test_id, NULL,
> +	NULL, NULL, 0, "turn off quota for group",
> +	"QCMD(Q_QUOTAOFF, GRPQUOTA)"},
> +};
> +
> +static void setup(void)
> +{
> +	const char *const fs_opts[] = { "-O quota", NULL};
> +
> +	quotactl_info();
> +
> +	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,
> +		0, (void *)&res_ndq));
> +	if (TST_ERR == EINVAL || TST_ERR == ENOSYS)
> +		getnextquota_nsup = 1;
> +}
> +
> +static void cleanup(void)
> +{
> +	if (fd>  -1)
> +		SAFE_CLOSE(fd);
> +	if (mount_flag&&  tst_umount(MNTPOINT))
> +		tst_res(TWARN | TERRNO, "umount(%s)", MNTPOINT);
> +}
> +
> +static void verify_quota(unsigned int n)
> +{
> +	struct tcase *tc =&tcases[n];
> +
> +	res_dq.dqb_bsoftlimit = 0;
> +	res_qf.dqi_igrace = 0;
> +	fmt_buf = 0;
> +	res_ndq.dqb_id = -1;
> +
> +	tst_res(TINFO, "Test #%d: %s", n, tc->tname);
> +	if ((tc->cmd == QCMD(Q_GETNEXTQUOTA, USRQUOTA) ||
> +		tc->cmd == QCMD(Q_GETNEXTQUOTA, GRPQUOTA))&&
> +		getnextquota_nsup) {
> +		tst_res(TCONF, "current system doesn't support this cmd");
> +		return;
> +	}
> +	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;
> +	}
> +
> +	if (memcmp(tc->res_data, tc->set_data, tc->sz)) {
> +		tst_res(TFAIL, "quotactl failed to %s", tc->des);
> +		tst_res_hexd(TINFO, tc->res_data, tc->sz, "retval:   ");
> +		tst_res_hexd(TINFO, tc->set_data, tc->sz, "expected: ");
> +		return;
> +	}
> +
> +	tst_res(TPASS, "quotactl succeeded to %s", tc->des);
> +}
> +
> +static struct tst_test test = {
> +	.needs_root = 1,
> +	.needs_kconfigs = (const char *[]) {
> +		"CONFIG_QFMT_V2",
> +		NULL
> +	},
> +	.test = verify_quota,
> +	.tcnt = ARRAY_SIZE(tcases),
> +	.mntpoint = MNTPOINT,
> +	.dev_fs_type = "ext4",
> +	.needs_device = 1,
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.test_variants = QUOTACTL_SYSCALL_VARIANTS,
> +	.needs_cmds = (const char *[]) {
> +		"mkfs.ext4>= 1.43.0",
> +		NULL
> +	}
> +};
> diff --git a/testcases/kernel/syscalls/quotactl/quotactl_syscall_var.h b/testcases/kernel/syscalls/quotactl/quotactl_syscall_var.h
> new file mode 100644
> index 000000000..3d1a2c8f5
> --- /dev/null
> +++ b/testcases/kernel/syscalls/quotactl/quotactl_syscall_var.h
> @@ -0,0 +1,32 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
> + * Author: Yang Xu<xuyang2018.jy@fujitsu.com>
> + */
> +
> +#ifndef LTP_QUOTACTL_SYSCALL_VAR_H
> +#define LTP_QUOTACTL_SYSCALL_VAR_H
> +
> +#include "lapi/quotactl.h"
> +
> +#define QUOTACTL_SYSCALL_VARIANTS 2
> +#define MNTPOINT "mntpoint"
> +
> +static int fd = -1;
> +
> +static int do_quotactl(int fd, int cmd, const char *special, int id, caddr_t addr)
> +{
> +	if (tst_variant == 0)
> +		return quotactl(cmd, special, id, addr);
> +	return quotactl_fd(fd, cmd, id, addr);
> +}
> +
> +static void quotactl_info(void)
> +{
> +	if (tst_variant == 0)
> +		tst_res(TINFO, "Test quotactl()");
> +	else
> +		tst_res(TINFO, "Test quotactl_fd()");
> +}
> +
> +#endif /* LTP_QUOTACTL_SYSCALL_VAR_H */

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [LTP] [PATCH v4 1/6] syscalls/quotactl08: Test quoatctl01 but quota info hidden in filesystem
  2021-12-13  7:26         ` [LTP] [PATCH v4 1/6] " Yang Xu
                             ` (5 preceding siblings ...)
  2021-12-23  8:03           ` [LTP] [PATCH v4 1/6] syscalls/quotactl08: Test quoatctl01 but quota info hidden in filesystem xuyang2018.jy
@ 2022-01-07 14:09           ` Cyril Hrubis
  2022-01-10  6:37             ` xuyang2018.jy
  6 siblings, 1 reply; 32+ messages in thread
From: Cyril Hrubis @ 2022-01-07 14:09 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi!
> +static void verify_quota(unsigned int n)
> +{
> +	struct tcase *tc = &tcases[n];
> +
> +	res_dq.dqb_bsoftlimit = 0;
> +	res_qf.dqi_igrace = 0;
> +	fmt_buf = 0;
> +	res_ndq.dqb_id = -1;
> +
> +	tst_res(TINFO, "Test #%d: %s", n, tc->tname);
> +	if ((tc->cmd == QCMD(Q_GETNEXTQUOTA, USRQUOTA) ||
> +		tc->cmd == QCMD(Q_GETNEXTQUOTA, GRPQUOTA)) &&
> +		getnextquota_nsup) {
> +		tst_res(TCONF, "current system doesn't support this cmd");
                                                                ^
								Can we
								print
								tc->des
								here?
> +		return;
> +	}
> +	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;
> +	}

And this can be TST_EXP_PASS_SILENT() followed by if (!TST_PASS) return;

The difference is that the TST_EXP* macros are more comprehensive if
there is a bug in kernel that makes quotaclt() return a possitive number
on success this test would still succeed while the macro will fail it.


Other than these two minor issues:

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] 32+ messages in thread

* Re: [LTP] [PATCH v4 2/6] syscalls/quotactl02, 5: Add quotactl_fd test variant
  2021-12-13  7:26           ` [LTP] [PATCH v4 2/6] syscalls/quotactl02, 5: Add quotactl_fd test variant Yang Xu
@ 2022-01-07 14:30             ` Cyril Hrubis
  0 siblings, 0 replies; 32+ messages in thread
From: Cyril Hrubis @ 2022-01-07 14:30 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi!
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] 32+ messages in thread

* Re: [LTP] [PATCH v4 3/6] syscalls/quotactl03: Add quotactl_fd test variant
  2021-12-13  7:26           ` [LTP] [PATCH v4 3/6] syscalls/quotactl03: " Yang Xu
@ 2022-01-07 14:59             ` Cyril Hrubis
  0 siblings, 0 replies; 32+ messages in thread
From: Cyril Hrubis @ 2022-01-07 14:59 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi!
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] 32+ messages in thread

* Re: [LTP] [PATCH v4 4/6] syscalls/quotactl04: Add quotactl_fd test variant
  2021-12-13  7:26           ` [LTP] [PATCH v4 4/6] syscalls/quotactl04: " Yang Xu
@ 2022-01-07 15:35             ` Cyril Hrubis
  2022-01-10 10:09               ` xuyang2018.jy
  0 siblings, 1 reply; 32+ messages in thread
From: Cyril Hrubis @ 2022-01-07 15:35 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi!
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] 32+ messages in thread

* Re: [LTP] [PATCH v4 5/6] syscalls/quotactl09: Test error when quota info hidden in filesystem
  2021-12-13  7:26           ` [LTP] [PATCH v4 5/6] syscalls/quotactl09: Test error when quota info hidden in filesystem Yang Xu
@ 2022-01-07 15:50             ` Cyril Hrubis
  2022-01-10  6:48               ` xuyang2018.jy
  0 siblings, 1 reply; 32+ messages in thread
From: Cyril Hrubis @ 2022-01-07 15:50 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi!
> diff --git a/testcases/kernel/syscalls/quotactl/quotactl09.c b/testcases/kernel/syscalls/quotactl/quotactl09.c
> new file mode 100644
> index 000000000..c7c485077
> --- /dev/null
> +++ b/testcases/kernel/syscalls/quotactl/quotactl09.c
> @@ -0,0 +1,180 @@
> +// 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
> + *
> + * 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;
> +
> +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;
> +} 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));

How does this work for the tst_variant == 1? We still do pass the fd
pointing to device right?

Actually one way to simplify the whole patchset would be to open() and
close() the device in each do_quotactl() call in the case that
tst_variant == 1. We wouldn't have to pass the file descriptor to the
function and everything will just work fine.

> +	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);
> +	}

Use TST_EXP_FAIL() in new testcases please.

> +	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;
> +	const char *const fs_opts[] = { "-O quota", NULL};
> +
> +	quotactl_info();
> +	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 (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

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [LTP] [PATCH v4 6/6] syscalls/quotactl07: Add quotactl_fd test variant
  2021-12-13  7:26           ` [LTP] [PATCH v4 6/6] syscalls/quotactl07: Add quotactl_fd test variant Yang Xu
@ 2022-01-07 16:03             ` Cyril Hrubis
  2022-01-10  9:03               ` xuyang2018.jy
  0 siblings, 1 reply; 32+ messages in thread
From: Cyril Hrubis @ 2022-01-07 16:03 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi!
> Also man-pages has error that Q_XQUOTARM was not introduced by kernel
> 3.16. So use invalid type directly

Have you send a patch to man-pages to get this 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] 32+ messages in thread

* Re: [LTP] [PATCH v4 1/6] syscalls/quotactl08: Test quoatctl01 but quota info hidden in filesystem
  2022-01-07 14:09           ` Cyril Hrubis
@ 2022-01-10  6:37             ` xuyang2018.jy
  2022-01-10 14:46               ` Cyril Hrubis
  0 siblings, 1 reply; 32+ messages in thread
From: xuyang2018.jy @ 2022-01-10  6:37 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi Cyril
> Hi!
>> +static void verify_quota(unsigned int n)
>> +{
>> +	struct tcase *tc =&tcases[n];
>> +
>> +	res_dq.dqb_bsoftlimit = 0;
>> +	res_qf.dqi_igrace = 0;
>> +	fmt_buf = 0;
>> +	res_ndq.dqb_id = -1;
>> +
>> +	tst_res(TINFO, "Test #%d: %s", n, tc->tname);
>> +	if ((tc->cmd == QCMD(Q_GETNEXTQUOTA, USRQUOTA) ||
>> +		tc->cmd == QCMD(Q_GETNEXTQUOTA, GRPQUOTA))&&
>> +		getnextquota_nsup) {
>> +		tst_res(TCONF, "current system doesn't support this cmd");
>                                                                  ^
> 								Can we
> 								print
> 								tc->des
> 								here?
Yes.
>> +		return;
>> +	}
>> +	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;
>> +	}
>
> And this can be TST_EXP_PASS_SILENT() followed by if (!TST_PASS) return;
>
> The difference is that the TST_EXP* macros are more comprehensive if
> there is a bug in kernel that makes quotaclt() return a possitive number
> on success this test would still succeed while the macro will fail it.
Yes. But it seems all quotactl cases have this problem(ie quotactl01.c), 
so I plan to merge this first. Then make use of TST_EXP* macro for all 
quotactl cases in a separate patch.

What do you think about this?

Best Regards
Yang Xu
>
>
> Other than these two minor issues:
>
> Reviewed-by: Cyril Hrubis<chrubis@suse.cz>
>

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [LTP] [PATCH v4 5/6] syscalls/quotactl09: Test error when quota info hidden in filesystem
  2022-01-07 15:50             ` Cyril Hrubis
@ 2022-01-10  6:48               ` xuyang2018.jy
  2022-01-10 14:46                 ` Cyril Hrubis
  0 siblings, 1 reply; 32+ messages in thread
From: xuyang2018.jy @ 2022-01-10  6:48 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi Cyril
> Hi!
>> diff --git a/testcases/kernel/syscalls/quotactl/quotactl09.c b/testcases/kernel/syscalls/quotactl/quotactl09.c
>> new file mode 100644
>> index 000000000..c7c485077
>> --- /dev/null
>> +++ b/testcases/kernel/syscalls/quotactl/quotactl09.c
>> @@ -0,0 +1,180 @@
>> +// 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
>> + *
>> + * 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;
>> +
>> +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;
>> +} 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));
>
> How does this work for the tst_variant == 1? We still do pass the fd
> pointing to device right?
Yes, but for tst_variant ==1 ,we don't use dev.
>
> Actually one way to simplify the whole patchset would be to open() and
> close() the device in each do_quotactl() call in the case that
> tst_variant == 1. We wouldn't have to pass the file descriptor to the
> function and everything will just work fine.
I don't think so, it needs to open/close fd each time. IMO, the argument 
cost is less than open/close files.

Best Regards
Yang Xu
>
>> +	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);
>> +	}
>
> Use TST_EXP_FAIL() in new testcases please.
>
>> +	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;
>> +	const char *const fs_opts[] = { "-O quota", NULL};
>> +
>> +	quotactl_info();
>> +	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 (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
>

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [LTP] [PATCH v4 6/6] syscalls/quotactl07: Add quotactl_fd test variant
  2022-01-07 16:03             ` Cyril Hrubis
@ 2022-01-10  9:03               ` xuyang2018.jy
  0 siblings, 0 replies; 32+ messages in thread
From: xuyang2018.jy @ 2022-01-10  9:03 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi Cyril
> Hi!
>> Also man-pages has error that Q_XQUOTARM was not introduced by kernel
>> 3.16. So use invalid type directly
>
> Have you send a patch to man-pages to get this fixed?
Yes, but offical  man-pages[1] hasn't updated for serval months.
The updates is on alejandro-colomar(man-pages new co-maintainer) main 
branch[2][3].

This patch will get unexpect EINVAL error when kernel commit 40b52225e 
("xfs: remove support for disabling quota accounting on a mounted file 
system")[4] was introduced.

the unexpected EINVAL error position: 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/xfs/xfs_qm_syscalls.c#n108

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 , I will modify this case as below:

/* Include a valid quota type to avoid other EINVAL error */
static unsigned int invalid_type = XFS_GROUP_QUOTA << 1 | XFS_USER_QUOTA;
static int mount_flag;

static void verify_quota(void)
{
         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
                 tst_res(TFAIL, "Q_XQUOTARM doesn't have quota type check");
}

static void setup(void)
{
         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;

         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,
         .format_device = 1,
         .dev_fs_type = "xfs",
         .mntpoint = MNTPOINT,


[1]https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/
[2]https://github.com/alejandro-colomar/man-pages/commit/38bccbcf4f51c5370a1060e6a80b90d68b0dcdc8
[3]https://github.com/alejandro-colomar/man-pages/commit/26f3978f04a1aeeb5397a5facebaef40a341afb6
[4]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit?id=40b52225e58cd3adf9358146b4b39dccfbfe5892
[5]https://patchwork.kernel.org/project/fstests/patch/20220105195352.GM656707@magnolia/

I will send a v5 for this patchset and add TST_EXP* usage.

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] 32+ messages in thread

* Re: [LTP] [PATCH v4 4/6] syscalls/quotactl04: Add quotactl_fd test variant
  2022-01-07 15:35             ` Cyril Hrubis
@ 2022-01-10 10:09               ` xuyang2018.jy
  0 siblings, 0 replies; 32+ messages in thread
From: xuyang2018.jy @ 2022-01-10 10:09 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi Cyril
> Hi!
> Reviewed-by: Cyril Hrubis<chrubis@suse.cz>
Thanks for your review, I have merged the first four patches.

Best Regards
Yang Xu
>

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [LTP] [PATCH v4 5/6] syscalls/quotactl09: Test error when quota info hidden in filesystem
  2022-01-10  6:48               ` xuyang2018.jy
@ 2022-01-10 14:46                 ` Cyril Hrubis
  2022-01-11  6:51                   ` xuyang2018.jy
  0 siblings, 1 reply; 32+ messages in thread
From: Cyril Hrubis @ 2022-01-10 14:46 UTC (permalink / raw)
  To: xuyang2018.jy; +Cc: ltp

Hi!
> >> +	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));
> >
> > How does this work for the tst_variant == 1? We still do pass the fd
> > pointing to device right?
> Yes, but for tst_variant ==1 ,we don't use dev.

Well yes, but the fd points to the device, right? So we pass a fd that
points to a device and we expect ENOTBLK if tst_variant == 1 and
exp_err == ENOTBLK? That does not sound fine, what do I miss?

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [LTP] [PATCH v4 1/6] syscalls/quotactl08: Test quoatctl01 but quota info hidden in filesystem
  2022-01-10  6:37             ` xuyang2018.jy
@ 2022-01-10 14:46               ` Cyril Hrubis
  0 siblings, 0 replies; 32+ messages in thread
From: Cyril Hrubis @ 2022-01-10 14:46 UTC (permalink / raw)
  To: xuyang2018.jy; +Cc: ltp

Hi!
> Yes. But it seems all quotactl cases have this problem(ie quotactl01.c), 
> so I plan to merge this first. Then make use of TST_EXP* macro for all 
> quotactl cases in a separate patch.

Well it would be a bit cleaner to add new tests using these macros from
the start, but as long as it gets fixed it's not a big deal.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [LTP] [PATCH v4 5/6] syscalls/quotactl09: Test error when quota info hidden in filesystem
  2022-01-10 14:46                 ` Cyril Hrubis
@ 2022-01-11  6:51                   ` xuyang2018.jy
  2022-01-11 10:55                     ` Cyril Hrubis
  0 siblings, 1 reply; 32+ messages in thread
From: xuyang2018.jy @ 2022-01-11  6:51 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi Cyril
> Hi!
>>>> +	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));
>>>
>>> How does this work for the tst_variant == 1? We still do pass the fd
>>> pointing to device right?
>> Yes, but for tst_variant ==1 ,we don't use dev.
>
> Well yes, but the fd points to the device, right?
Yes, we get super block quota info stored in dev by using the fd.
>So we pass a fd that
> points to a device and we expect ENOTBLK if tst_variant == 1 and
> exp_err == ENOTBLK? That does not sound fine, what do I miss?
We skip ENOTBLK error test when tst_variant ==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));

Best Regards
Yang Xu
>

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [LTP] [PATCH v4 5/6] syscalls/quotactl09: Test error when quota info hidden in filesystem
  2022-01-11  6:51                   ` xuyang2018.jy
@ 2022-01-11 10:55                     ` Cyril Hrubis
  2022-01-12  1:52                       ` xuyang2018.jy
  0 siblings, 1 reply; 32+ messages in thread
From: Cyril Hrubis @ 2022-01-11 10:55 UTC (permalink / raw)
  To: xuyang2018.jy; +Cc: ltp

Hi!
> >So we pass a fd that
> > points to a device and we expect ENOTBLK if tst_variant == 1 and
> > exp_err == ENOTBLK? That does not sound fine, what do I miss?
> We skip ENOTBLK error test when tst_variant ==1
> 
>    	if (tst_variant) {
>    		if (tc->exp_err == ENOTBLK) {
>    			tst_res(TCONF, "quotactl_fd() doesn't have this error, skip");
>    			return;
>    		}
>    	}

Ah, that's what I have missed. But still, what happen if we pass fd to a
regular file to the quotactl_fd()? Shouldn't we test that case too?

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [LTP] [PATCH v4 5/6] syscalls/quotactl09: Test error when quota info hidden in filesystem
  2022-01-11 10:55                     ` Cyril Hrubis
@ 2022-01-12  1:52                       ` xuyang2018.jy
  2022-01-12  8:31                         ` Cyril Hrubis
  0 siblings, 1 reply; 32+ messages in thread
From: xuyang2018.jy @ 2022-01-12  1:52 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi Cyril
> Hi!
>>> So we pass a fd that
>>> points to a device and we expect ENOTBLK if tst_variant == 1 and
>>> exp_err == ENOTBLK? That does not sound fine, what do I miss?
>> We skip ENOTBLK error test when tst_variant ==1
>>
>>     	if (tst_variant) {
>>     		if (tc->exp_err == ENOTBLK) {
>>     			tst_res(TCONF, "quotactl_fd() doesn't have this error, skip");
>>     			return;
>>     		}
>>     	}
>
> Ah, that's what I have missed. But still, what happen if we pass fd to a
> regular file to the quotactl_fd()? Shouldn't we test that case too?
Good suggestion.
Yes, AFAIK, the fd point to superblock, every subcmd will check quota 
feature bit or whether enable but return different errno.

I will test Q_QUOTAON with regular file fd because it is the most 
meaningful.

Best Regards
Yang Xu
>

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [LTP] [PATCH v4 5/6] syscalls/quotactl09: Test error when quota info hidden in filesystem
  2022-01-12  1:52                       ` xuyang2018.jy
@ 2022-01-12  8:31                         ` Cyril Hrubis
  2022-01-12  9:24                           ` xuyang2018.jy
  0 siblings, 1 reply; 32+ messages in thread
From: Cyril Hrubis @ 2022-01-12  8:31 UTC (permalink / raw)
  To: xuyang2018.jy; +Cc: ltp

Hi!
> > Ah, that's what I have missed. But still, what happen if we pass fd to a
> > regular file to the quotactl_fd()? Shouldn't we test that case too?
> Good suggestion.
> Yes, AFAIK, the fd point to superblock, every subcmd will check quota 
> feature bit or whether enable but return different errno.
> 
> I will test Q_QUOTAON with regular file fd because it is the most 
> meaningful.

And we can always try to pass a fd pointing to a socket, that shouldn't
be associated with any block device at all.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [LTP] [PATCH v4 5/6] syscalls/quotactl09: Test error when quota info hidden in filesystem
  2022-01-12  8:31                         ` Cyril Hrubis
@ 2022-01-12  9:24                           ` xuyang2018.jy
  0 siblings, 0 replies; 32+ messages in thread
From: xuyang2018.jy @ 2022-01-12  9:24 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi Cyril
> Hi!
>>> Ah, that's what I have missed. But still, what happen if we pass fd to a
>>> regular file to the quotactl_fd()? Shouldn't we test that case too?
>> Good suggestion.
>> Yes, AFAIK, the fd point to superblock, every subcmd will check quota
>> feature bit or whether enable but return different errno.
>>
>> I will test Q_QUOTAON with regular file fd because it is the most
>> meaningful.
>
> And we can always try to pass a fd pointing to a socket, that shouldn't
> be associated with any block device at all.
Yes, my old way use external fd deponds on tmp environmet(ie use 
xfs,ext4 with quota or with quota feature) and it make test unstable.

If using socket fd, it should report ENOSYS.

Best Regards
Yang Xu
>

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2022-01-12  9:24 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-09 10:54 [LTP] [PATCH v3 06/12] lapi/quotactl.h: Add fallback for quotactl_fd Yang Xu
2021-11-09 10:54 ` [LTP] [PATCH v3 07/12] syscalls/quotactl08: Test quoatctl01 but quota info hidden in filesystem Yang Xu
2021-11-10 16:32   ` Cyril Hrubis
2021-11-11  8:48     ` xuyang2018.jy
2021-11-11 14:30       ` Cyril Hrubis
2021-11-26  9:32         ` xuyang2018.jy
2021-12-13  7:26         ` [LTP] [PATCH v4 1/6] " Yang Xu
2021-12-13  7:26           ` [LTP] [PATCH v4 2/6] syscalls/quotactl02, 5: Add quotactl_fd test variant Yang Xu
2022-01-07 14:30             ` Cyril Hrubis
2021-12-13  7:26           ` [LTP] [PATCH v4 3/6] syscalls/quotactl03: " Yang Xu
2022-01-07 14:59             ` Cyril Hrubis
2021-12-13  7:26           ` [LTP] [PATCH v4 4/6] syscalls/quotactl04: " Yang Xu
2022-01-07 15:35             ` Cyril Hrubis
2022-01-10 10:09               ` xuyang2018.jy
2021-12-13  7:26           ` [LTP] [PATCH v4 5/6] syscalls/quotactl09: Test error when quota info hidden in filesystem Yang Xu
2022-01-07 15:50             ` Cyril Hrubis
2022-01-10  6:48               ` xuyang2018.jy
2022-01-10 14:46                 ` Cyril Hrubis
2022-01-11  6:51                   ` xuyang2018.jy
2022-01-11 10:55                     ` Cyril Hrubis
2022-01-12  1:52                       ` xuyang2018.jy
2022-01-12  8:31                         ` Cyril Hrubis
2022-01-12  9:24                           ` xuyang2018.jy
2021-12-13  7:26           ` [LTP] [PATCH v4 6/6] syscalls/quotactl07: Add quotactl_fd test variant Yang Xu
2022-01-07 16:03             ` Cyril Hrubis
2022-01-10  9:03               ` xuyang2018.jy
2021-12-23  8:03           ` [LTP] [PATCH v4 1/6] syscalls/quotactl08: Test quoatctl01 but quota info hidden in filesystem xuyang2018.jy
2022-01-07 14:09           ` Cyril Hrubis
2022-01-10  6:37             ` xuyang2018.jy
2022-01-10 14:46               ` Cyril Hrubis
2021-11-09 10:54 ` [LTP] [PATCH v3 08/12] syscalls/quotactl02, 5: Add quotactl_fd test variant Yang Xu
2021-11-09 10:54 ` [LTP] [PATCH v3 09/12] syscalls/quotactl03: " Yang Xu

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.