Skip to contentSkip to conversation

syscalls/quotactl02.c: add Q_XGETNEXTQUOTA flag test

PATCH Superseded Xiao Yang 2 participants 7 messages Mar 31, 2017 – Apr 12, 2017

lore
Share & tools
lore

Xiao Yang

author
#0 lore raw

PATCH 1/2 syscalls/quotactl02.c: add Q_XGETNEXTQUOTA flag test

---
 testcases/kernel/syscalls/quotactl/quotactl02.c | 44 ++++++++++++++++---------
 1 file changed, 28 insertions(+), 16 deletions(-)
testcases/kernel/syscalls/quotactl/quotactl02.c +28 -16
index f7ae78b..a601006 100644
@@ -22,7 +22,8 @@
  * This testcase checks basic flags of quotactl(2) for an XFS file system:
  * 1) quotactl(2) succeeds to turn off xfs quota and get xfs quota off status.
  * 2) quotactl(2) succeeds to turn on xfs quota and get xfs quota on status.
- * 3) quotactl(2) succeeds to set and get xfs disk quota limits.
+ * 3) quotactl(2) succeeds to set and use Q_XGETQUOTA to get xfs disk quota limits.
+ * 4) quotactl(2) succeeds to set and use Q_XGETNEXTQUOTA to get xfs disk quota limits.
  */
 #define _GNU_SOURCE
 #include <errno.h>
@@ -42,11 +43,11 @@
 #include "tst_test.h"
 
 #if defined(HAVE_XFS_QUOTA) && (defined(HAVE_QUOTAV2) || defined(HAVE_QUOTAV1))
-static void check_qoff(char *);
-static void check_qon(char *);
-static void check_qlim(char *);
+static void check_qoff(int, char *);
+static void check_qon(int, char *);
+static void check_qlim(int, char *);
 
-static int test_id;
+static uint32_t test_id;
 static struct fs_disk_quota set_dquota = {
 	.d_rtb_softlimit = 1000,
 	.d_fieldmask = FS_DQ_RTBSOFT
@@ -58,22 +59,27 @@ static struct t_case {
 	int cmd;
 	void *addr;
 	void (*func_check)();
+	int check_subcmd;
 	char *des;
 } tcases[] = {
-	{QCMD(Q_XQUOTAOFF, USRQUOTA), &qflag, check_qoff,
+	{QCMD(Q_XQUOTAOFF, USRQUOTA), &qflag, check_qoff, Q_XGETQSTAT,
 	"turn off xfs quota and get xfs quota off status"},
-	{QCMD(Q_XQUOTAON, USRQUOTA), &qflag, check_qon,
+	{QCMD(Q_XQUOTAON, USRQUOTA), &qflag, check_qon, Q_XGETQSTAT,
 	"turn on xfs quota and get xfs quota on status"},
-	{QCMD(Q_XSETQLIM, USRQUOTA), &set_dquota, check_qlim,
-	"set and get xfs disk quota limits"},
+	{QCMD(Q_XSETQLIM, USRQUOTA), &set_dquota, check_qlim, Q_XGETQUOTA,
+	"set and use Q_XGETQUOTA to get xfs disk quota limits"},
+# ifdef Q_XGETNEXTQUOTA
+	{QCMD(Q_XSETQLIM, USRQUOTA), &set_dquota, check_qlim, Q_XGETNEXTQUOTA,
+	"set and use Q_XGETNEXTQUOTA to get xfs disk quota limits"},
+# endif
 };
 
-static void check_qoff(char *desp)
+static void check_qoff(int subcmd, char *desp)
 {
 	int res;
 	struct fs_quota_stat res_qstat;
 
-	res = quotactl(QCMD(Q_XGETQSTAT, USRQUOTA), tst_device->dev,
+	res = quotactl(QCMD(subcmd, USRQUOTA), tst_device->dev,
 	               test_id, (void*) &res_qstat);
 	if (res == -1) {
 		tst_res(TFAIL | TERRNO,
@@ -89,12 +95,12 @@ static void check_qoff(char *desp)
 	tst_res(TPASS, "quoactl() succeeded to %s", desp);
 }
 
-static void check_qon(char *desp)
+static void check_qon(int subcmd, char *desp)
 {
 	int res;
 	struct fs_quota_stat res_qstat;
 
-	res = quotactl(QCMD(Q_XGETQSTAT, USRQUOTA), tst_device->dev,
+	res = quotactl(QCMD(subcmd, USRQUOTA), tst_device->dev,
 	               test_id, (void*) &res_qstat);
 	if (res == -1) {
 		tst_res(TFAIL | TERRNO,
@@ -110,14 +116,14 @@ static void check_qon(char *desp)
 	tst_res(TPASS, "quoactl() succeeded to %s", desp);
 }
 
-static void check_qlim(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(QCMD(Q_XGETQUOTA, USRQUOTA), tst_device->dev,
+	res = quotactl(QCMD(subcmd, USRQUOTA), tst_device->dev,
 	               test_id, (void*) &res_dquota);
 	if (res == -1) {
 		tst_res(TFAIL | TERRNO,
@@ -125,6 +131,12 @@ static void check_qlim(char *desp)
 		return;
 	}
 
+	if (res_dquota.d_id != test_id) {
+		tst_res(TFAIL, "quotactl() got unexpected user id %u,"
+			" expected %u", res_dquota.d_id, test_id);
+		return;
+	}
+
 	if (res_dquota.d_rtb_hardlimit != set_dquota.d_rtb_hardlimit) {
 		tst_res(TFAIL, "quotactl() got unexpected rtb soft limit %llu,"
 			" expected %llu", res_dquota.d_rtb_hardlimit,
@@ -150,7 +162,7 @@ static void verify_quota(unsigned int n)
 		return;
 	}
 
-	tc->func_check(tc->des);
+	tc->func_check(tc->check_subcmd, tc->des);
 }
 
 static struct tst_test test = {
Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH 2/2 syscalls/quotactl03.c: add new regression test

This kernel bug of xfs has been fixed in:

commit 657bdfb7f5e68ca5e2ed009ab473c429b0d6af85

Author: Eric Sandeen <[email protected]>
Date:   Tue Jan 17 11:43:38 2017 -0800

xfs: don't wrap ID in xfs_dq_get_next_id

---
 runtest/syscalls                                |   1 +
 testcases/kernel/syscalls/.gitignore            |   1 +
 testcases/kernel/syscalls/quotactl/quotactl03.c | 105 ++++++++++++++++++++++++
 3 files changed, 107 insertions(+)
 create mode 100644 testcases/kernel/syscalls/quotactl/quotactl03.c
runtest/syscalls +1 -0
index 15ae66e..1ae1d39 100644
@@ -849,6 +849,7 @@ pwritev02_64 pwritev02_64
 
 quotactl01 quotactl01
 quotactl02 quotactl02
+quotactl03 quotactl03
 
 read01 read01
 read02 read02
testcases/kernel/syscalls/.gitignore +1 -0
index fad662c..e01d906 100644
@@ -713,6 +713,7 @@
 /pwritev/pwritev02_64
 /quotactl/quotactl01
 /quotactl/quotactl02
+/quotactl/quotactl03
 /read/read01
 /read/read02
 /read/read03
testcases/kernel/syscalls/quotactl/quotactl03.c new file +105 -0

105 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/2 syscalls/quotactl03.c: add new regression test

Hi!

testcases/kernel/syscalls/quotactl/quotactl03.c line 57

Quoted 5 lines
testcases/kernel/syscalls/quotactl/quotactl03.c new file +5 -0
+#include "tst_test.h"
+
+#if defined(HAVE_XFS_QUOTA) && (defined(HAVE_QUOTAV2) || defined(HAVE_QUOTAV1))
+
+# ifdef Q_XGETNEXTQUOTA

Here as well, can we add fallback definition and handle EINVAL (and possibly ENOSYS) from the quotaclt as TCONF?

testcases/kernel/syscalls/quotactl/quotactl03.c line 60

Quoted 2 lines
testcases/kernel/syscalls/quotactl/quotactl03.c new file +2 -0
+static const char mntpoint[] = "mnt_point";
+static uint32_t test_id = 4294967292;
                             ^
			     This would be a bit clealer when written in
			     hexadecimal which should be 0xfffffffc

testcases/kernel/syscalls/quotactl/quotactl03.c line 72

Quoted 11 lines
testcases/kernel/syscalls/quotactl/quotactl03.c new file +11 -0
+static void verify_quota(void)
+{
+	struct fs_disk_quota res_dquota;
+
+	res_dquota.d_id = 1;
+
+	TEST(quotactl(QCMD(Q_XGETNEXTQUOTA, USRQUOTA), tst_device->dev,
+		test_id, (void *)&res_dquota));
+	if (TEST_RETURN != -1) {
+		tst_res(TFAIL, "quotactl() found the next active ID: %u "
+			"unexpectedly when asking for it past UINT_MAX.",

^
Maybe this is too verbose, we could have ended the message after "unexpectedly"

testcases/kernel/syscalls/quotactl/quotactl03.c line 80

Quoted 8 lines
testcases/kernel/syscalls/quotactl/quotactl03.c new file +8 -0
+			res_dquota.d_id);
+		return;
+	}
+
+	if (TEST_ERRNO != ENOENT) {
+		tst_res(TFAIL | TTERRNO, "quotactl() couldn't find the next "
+			"active ID expectedly when asking for it past UINT_MAX"
+			", but returns %s instead of ENOENT.",

"quotaclt() failed unexpectedly with %s expected ENOENT"

or something similar would suffice here, let's keep the message short and to the point

testcases/kernel/syscalls/quotactl/quotactl03.c line 85

Quoted 5 lines
testcases/kernel/syscalls/quotactl/quotactl03.c new file +5 -0
+			tst_strerrno(TEST_ERRNO));
+	} else {
+		tst_res(TPASS, "quotactl() couldn't find the next active ID "
+			"expectedly when asking for it past UINT_MAX, and "
+			"return ENOENT.");

Here as well something as:

"quotaclt() failed with ENOENT as expected"

Quoted 28 lines
testcases/kernel/syscalls/quotactl/quotactl03.c new file +20 -0
+	}
+}
+
+static struct tst_test test = {
+	.tid = "quotactl03",
+	.needs_tmpdir = 1,
+	.needs_root = 1,
+	.test_all = verify_quota,
+	.mount_device = 1,
+	.dev_fs_type = "xfs",
+	.mntpoint = mntpoint,
+	.mnt_data = "usrquota",
+};
+# else
+	TST_TEST_TCONF("This system didn't support Q_XGETNEXTQUOTA");
+# endif
+
+#else
+	TST_TEST_TCONF("This system didn't support quota or xfs quota");
+#endif
Signature · 7 lines
1.8.3.1




-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis
[email protected]
#3 lore raw

PATCH 1/2 syscalls/quotactl02.c: add Q_XGETNEXTQUOTA flag test

In reply to Xiao Yang

Hi!

testcases/kernel/syscalls/quotactl/quotactl02.c static struct t_case { · line 74

Quoted 4 lines
testcases/kernel/syscalls/quotactl/quotactl02.c +4 -0
+# ifdef Q_XGETNEXTQUOTA
+	{QCMD(Q_XSETQLIM, USRQUOTA), &set_dquota, check_qlim, Q_XGETNEXTQUOTA,
+	"set and use Q_XGETNEXTQUOTA to get xfs disk quota limits"},
+# endif

Can we, rather than this ifdef, define a fallback definition for the flag (ideally in an header in lapi) and handle possible EINVAL as TCONF in case that we run on an older kernel?

Otherwise it looks good.

Signature · 2 lines
Cyril Hrubis
[email protected]
author
#4 lore raw

PATCH v2 1/2 syscalls/quotactl02.c: add Q_XGETNEXTQUOTA flag test

---
 include/lapi/quotactl.h                         | 26 +++++++++++++
 testcases/kernel/syscalls/quotactl/quotactl02.c | 52 +++++++++++++++++--------
 2 files changed, 61 insertions(+), 17 deletions(-)
 create mode 100644 include/lapi/quotactl.h
include/lapi/quotactl.h new file +26 -0
new file mode 100644
index 0000000..729472f
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2017 Fujitsu Ltd.
+ * Author: Xiao Yang <[email protected]>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef LAPI_QUOTACTL_H__
+# define LAPI_QUOTACTL_H__
+
+# ifndef Q_XGETNEXTQUOTA
+#  define Q_XGETNEXTQUOTA XQM_CMD(9)
+# endif
+
+#endif /* LAPI_QUOTACTL_H__ */
testcases/kernel/syscalls/quotactl/quotactl02.c +35 -17

124 lines not on this page · raw message

Signature · 1 line
1.8.3.1
author
#5 lore raw

PATCH v2 2/2 syscalls/quotactl03.c: add new regression test

This kernel bug of xfs has been fixed in:

commit 657bdfb7f5e68ca5e2ed009ab473c429b0d6af85

Author: Eric Sandeen <[email protected]>
Date:   Tue Jan 17 11:43:38 2017 -0800

xfs: don't wrap ID in xfs_dq_get_next_id

---
 runtest/syscalls                                |   1 +
 testcases/kernel/syscalls/.gitignore            |   1 +
 testcases/kernel/syscalls/quotactl/quotactl03.c | 101 ++++++++++++++++++++++++
 3 files changed, 103 insertions(+)
 create mode 100644 testcases/kernel/syscalls/quotactl/quotactl03.c
runtest/syscalls +1 -0
index b5d12ca..5909456 100644
@@ -850,6 +850,7 @@ pwritev02_64 pwritev02_64
 
 quotactl01 quotactl01
 quotactl02 quotactl02
+quotactl03 quotactl03
 
 read01 read01
 read02 read02
testcases/kernel/syscalls/.gitignore +1 -0
index 6804e18..d5985cd 100644
@@ -714,6 +714,7 @@
 /pwritev/pwritev02_64
 /quotactl/quotactl01
 /quotactl/quotactl02
+/quotactl/quotactl03
 /read/read01
 /read/read02
 /read/read03
testcases/kernel/syscalls/quotactl/quotactl03.c new file +101 -0

101 lines not on this page · raw message

Signature · 1 line
1.8.3.1