[LTP] [PATCH v3 08/12] syscalls/quotactl02, 5: Add quotactl_fd test variant

Yang Xu xuyang2018.jy@fujitsu.com
Tue Nov 9 11:54:44 CET 2021


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



More information about the ltp mailing list