[LTP] [PATCH v2 08/13] syscalls/quotactl02, 5: Add quotactl_fd test variant
Yang Xu
xuyang2018.jy@fujitsu.com
Wed Oct 27 14:28:25 CEST 2021
Also remove useless geteuid
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
.../kernel/syscalls/quotactl/quotactl02.c | 15 ++++++++++---
.../kernel/syscalls/quotactl/quotactl02.h | 22 ++++++++++---------
.../kernel/syscalls/quotactl/quotactl05.c | 15 ++++++++++---
3 files changed, 36 insertions(+), 16 deletions(-)
diff --git a/testcases/kernel/syscalls/quotactl/quotactl02.c b/testcases/kernel/syscalls/quotactl/quotactl02.c
index 55a6a8906..a8d6dea83 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(TESTFILE, O_RDWR | O_CREAT, 0666);
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..faee5d282 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl02.h
+++ b/testcases/kernel/syscalls/quotactl/quotactl02.h
@@ -12,19 +12,21 @@
#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>
+#define MNTPOINT "mntpoint"
+#define TESTFILE MNTPOINT "/testfile"
+
static struct fs_disk_quota set_dquota = {
.d_rtb_softlimit = 1000,
.d_fieldmask = FS_DQ_RTBSOFT
};
static uint32_t test_id;
-static int x_getnextquota_nsup;
+static int x_getnextquota_nsup, fd = -1;
static int x_getstatv_nsup;
-static const char mntpoint[] = "mnt_point";
void check_support_cmd(int quotatype)
{
@@ -36,12 +38,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 +54,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 +74,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 +96,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 +118,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 +140,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..00a9242bc 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(TESTFILE, O_RDWR | O_CREAT, 0666);
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