diff mbox series

[v4,1/6] syscalls/quotactl08: Test quoatctl01 but quota info hidden in filesystem

Message ID 1639380414-24390-1-git-send-email-xuyang2018.jy@fujitsu.com
State Accepted
Headers show
Series [v4,1/6] syscalls/quotactl08: Test quoatctl01 but quota info hidden in filesystem | expand

Commit Message

Yang Xu \(Fujitsu\) Dec. 13, 2021, 7:26 a.m. UTC
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

Comments

Yang Xu \(Fujitsu\) Dec. 23, 2021, 8:03 a.m. UTC | #1
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 */
Cyril Hrubis Jan. 7, 2022, 2:09 p.m. UTC | #2
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>
Yang Xu \(Fujitsu\) Jan. 10, 2022, 6:37 a.m. UTC | #3
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>
>
Cyril Hrubis Jan. 10, 2022, 2:46 p.m. UTC | #4
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.
diff mbox series

Patch

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 */