All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v4 0/5]  optimize quotactl test code
@ 2019-11-20  9:13 Yang Xu
  2019-11-20  9:13 ` [LTP] [PATCH v4 1/5] syscalls/quotactl01: Add Q_GETNEXTQUOTA test Yang Xu
                   ` (5 more replies)
  0 siblings, 6 replies; 23+ messages in thread
From: Yang Xu @ 2019-11-20  9:13 UTC (permalink / raw)
  To: ltp

I cleanup the quotactl code and add project quota test for quotactl.
Thanks to Jan Kara with support about quota.


------------
v3->v4
check some new features(such as Q_GETNETXSTAT,Q_XGETNEXTSTAT,Q_XGETQSTATV)
whether supported in setup by using ltp customized struct
------------
Yang Xu (5):
  syscalls/quotactl01: Add Q_GETNEXTQUOTA test
  syscalls/quotactl02: Add Q_XGETQSTATV test and group quota tests
  syscalls/quotactl04: add project quota test for non-xfs filesystem
  syscalls/quotactl05: add project quota test on xfs filesystem
  syscalls/quotactl06: Add new error testcase

 configure.ac                                  |   1 +
 include/lapi/quotactl.h                       |  80 +++++--
 m4/ltp-quota.m4                               |   8 +
 runtest/syscalls                              |   3 +
 testcases/kernel/syscalls/quotactl/.gitignore |   3 +
 .../kernel/syscalls/quotactl/quotactl01.c     | 107 ++++++---
 .../kernel/syscalls/quotactl/quotactl02.c     | 222 ++++++++----------
 .../kernel/syscalls/quotactl/quotactl02.h     | 167 +++++++++++++
 .../kernel/syscalls/quotactl/quotactl04.c     | 162 +++++++++++++
 .../kernel/syscalls/quotactl/quotactl05.c     | 118 ++++++++++
 .../kernel/syscalls/quotactl/quotactl06.c     | 196 ++++++++++++++++
 11 files changed, 906 insertions(+), 161 deletions(-)
 create mode 100644 m4/ltp-quota.m4
 create mode 100644 testcases/kernel/syscalls/quotactl/quotactl02.h
 create mode 100644 testcases/kernel/syscalls/quotactl/quotactl04.c
 create mode 100644 testcases/kernel/syscalls/quotactl/quotactl05.c
 create mode 100644 testcases/kernel/syscalls/quotactl/quotactl06.c

-- 
2.18.0




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

* [LTP] [PATCH v4 1/5] syscalls/quotactl01: Add Q_GETNEXTQUOTA test
  2019-11-20  9:13 [LTP] [PATCH v4 0/5] optimize quotactl test code Yang Xu
@ 2019-11-20  9:13 ` Yang Xu
  2019-11-20 15:12   ` Petr Vorel
  2019-11-20  9:13 ` [LTP] [PATCH v4 2/5] syscalls/quotactl02: Add Q_XGETQSTATV test and group quota tests Yang Xu
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 23+ messages in thread
From: Yang Xu @ 2019-11-20  9:13 UTC (permalink / raw)
  To: ltp

Q_GETNEXTQUOTA was introduced since linux 4.6, this operation is the
same as Q_GETQUOTA, but it returns quota information for the next ID
greater than or equal to id that has a quota set.

Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
---
 configure.ac                                  |   1 +
 include/lapi/quotactl.h                       |  43 ++++---
 m4/ltp-quota.m4                               |   7 ++
 .../kernel/syscalls/quotactl/quotactl01.c     | 107 +++++++++++++-----
 4 files changed, 115 insertions(+), 43 deletions(-)
 create mode 100644 m4/ltp-quota.m4

diff --git a/configure.ac b/configure.ac
index c8c0db2dc..50d14967d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -251,6 +251,7 @@ AC_DEFINE_UNQUOTED(NUMA_ERROR_MSG, ["$numa_error_msg"], [Error message when no N
 
 
 LTP_CHECK_SYSCALL_PERF_EVENT_OPEN
+LTP_CHECK_SYSCALL_QUOTACTL
 LTP_CHECK_SYSCALL_SIGNALFD
 LTP_CHECK_SYSCALL_UTIMENSAT
 LTP_CHECK_TASKSTATS
diff --git a/include/lapi/quotactl.h b/include/lapi/quotactl.h
index 729472f69..5c49cedce 100644
--- a/include/lapi/quotactl.h
+++ b/include/lapi/quotactl.h
@@ -1,26 +1,41 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Copyright (c) 2017 Fujitsu Ltd.
+ * Copyright (c) 2017-2019 Fujitsu Ltd.
  * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
- *
- * 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/>.
+ * Author: Yang Xu <xuyang2018.jy@cn.jujitsu.com>
  */
 
 #ifndef LAPI_QUOTACTL_H__
 # define LAPI_QUOTACTL_H__
 
+#include <sys/quota.h>
+
+#ifdef HAVE_STRUCT_IF_NEXTDQBLK
+# include <linux/quota.h>
+#else
+# ifdef HAVE_LINUX_TYPES_H
+# include <linux/types.h>
+struct if_nextdqblk {
+	__u64 dqb_bhardlimit;
+	__u64 dqb_bsoftlimit;
+	__u64 dqb_curspace;
+	__u64 dqb_ihardlimit;
+	__u64 dqb_isoftlimit;
+	__u64 dqb_curinodes;
+	__u64 dqb_btime;
+	__u64 dqb_itime;
+	__u32 dqb_valid;
+	__u32 dqb_id;
+};
+#endif
+#endif
+
 # ifndef Q_XGETNEXTQUOTA
 #  define Q_XGETNEXTQUOTA XQM_CMD(9)
 # endif
 
+# ifndef Q_GETNEXTQUOTA
+#  define Q_GETNEXTQUOTA 0x800009 /* get disk limits and usage >= ID */
+# endif
+
 #endif /* LAPI_QUOTACTL_H__ */
diff --git a/m4/ltp-quota.m4 b/m4/ltp-quota.m4
new file mode 100644
index 000000000..e8d08c6b7
--- /dev/null
+++ b/m4/ltp-quota.m4
@@ -0,0 +1,7 @@
+dnl SPDX-License-Identifier: GPL-2.0-or-later
+dnl Copyright (c) 2019 Fujitsu Ltd.
+dnl Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
+
+AC_DEFUN([LTP_CHECK_SYSCALL_QUOTACTL],[
+AC_CHECK_TYPES([struct if_nextdqblk],,,[#include <linux/quota.h>])
+])
diff --git a/testcases/kernel/syscalls/quotactl/quotactl01.c b/testcases/kernel/syscalls/quotactl/quotactl01.c
index 2f563515d..41662a818 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl01.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl01.c
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
 * Copyright (c) Crackerjack Project., 2007
-* Copyright (c) 2016 Fujitsu Ltd.
+* Copyright (c) 2016-2019 FUJITSU LIMITED. All rights reserved
 * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
 *
 * This testcase checks the basic flag of quotactl(2) for non-XFS filesystems:
@@ -16,19 +16,23 @@
 *    flag for user.
 * 6) quotactl(2) succeeds to get quota format with Q_GETFMT flag for user.
 * 7) quotactl(2) succeeds to update quota usages with Q_SYNC flag for user.
-* 8) quotactl(2) succeeds to turn off quota with Q_QUOTAOFF flag for user.
-* 9) quotactl(2) succeeds to turn on quota with Q_QUOTAON flag for group.
-* 10) quotactl(2) succeeds to set disk quota limits with Q_SETQUOTA flag
+* 8) quotactl(2) succeeds to get disk quota limit greater than or equal to
+*    ID with Q_GETNEXTQUOTA flag for user.
+* 9) quotactl(2) succeeds to turn off quota with Q_QUOTAOFF flag for user.
+* 10) quotactl(2) succeeds to turn on quota with Q_QUOTAON flag for group.
+* 11) quotactl(2) succeeds to set disk quota limits with Q_SETQUOTA flag
 *     for group.
-* 11) quotactl(2) succeeds to get disk quota limits with Q_GETQUOTA flag
+* 12) quotactl(2) succeeds to get disk quota limits with Q_GETQUOTA flag
 *     for group.
-* 12) quotactl(2) succeeds to set information about quotafile with Q_SETINFO
+* 13) quotactl(2) succeeds to set information about quotafile with Q_SETINFO
 *     flag for group.
-* 13) quotactl(2) succeeds to get information about quotafile with Q_GETINFO
+* 14) quotactl(2) succeeds to get information about quotafile with Q_GETINFO
 *     flag for group.
-* 14) quotactl(2) succeeds to get quota format with Q_GETFMT flag for group.
-* 15) quotactl(2) succeeds to update quota usages with Q_SYNC flag for group.
-* 16) quotactl(2) succeeds to turn off quota with Q_QUOTAOFF flag for group.
+* 15) quotactl(2) succeeds to get quota format with Q_GETFMT flag for group.
+* 16) quotactl(2) succeeds to update quota usages with Q_SYNC flag for group.
+* 17) quotactl(2) succeeds to get disk quota limit greater than or equal to
+*     ID with Q_GETNEXTQUOTA flag for group.
+* 18) quotactl(2) succeeds to turn off quota with Q_QUOTAOFF flag for group.
 */
 
 #include "config.h"
@@ -36,11 +40,13 @@
 #include <string.h>
 #include <unistd.h>
 #include <stdio.h>
-#include <sys/quota.h>
+#include "lapi/quotactl.h"
 
 #include "tst_test.h"
 
-#define QFMT_VFS_V0	2
+#ifndef QFMT_VFS_V0
+# define QFMT_VFS_V0	2
+#endif
 #define USRPATH MNTPOINT "/aquota.user"
 #define GRPPATH MNTPOINT "/aquota.group"
 #define FMTID	QFMT_VFS_V0
@@ -60,6 +66,9 @@ static struct dqinfo set_qf = {
 };
 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;
@@ -69,65 +78,93 @@ static struct tcase {
 	void *res_data;
 	int sz;
 	char *des;
+	char *tname;
 } tcases[] = {
 	{QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, USRPATH,
-	NULL, NULL, 0, "turn on quota for user"},
+	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"},
+	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"},
+	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"},
+	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"},
+	"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"},
+	"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"},
+	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, USRPATH,
-	NULL, NULL, 0, "turn off quota for user"},
+	NULL, NULL, 0, "turn off quota for user",
+	"QCMD(Q_QUOTAOFF, USRQUOTA)"},
 
 	{QCMD(Q_QUOTAON, GRPQUOTA), &fmt_id, GRPPATH,
-	NULL, NULL, 0, "turn on quota for group"},
+	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"},
+	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"},
+	"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"},
+	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"},
+	"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"},
+	&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"},
+	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, GRPPATH,
-	NULL, NULL, 0, "turn off quota for group"}
+	NULL, NULL, 0, "turn off quota for group",
+	"QCMD(Q_QUOTAOFF, GRPQUOTA)"},
 };
 
 static void setup(void)
 {
 	const char *const cmd[] = {"quotacheck", "-ugF", "vfsv0", MNTPOINT, NULL};
 	int ret;
+	getnextquota_nsup = 0;
 
 	ret = tst_run_cmd(cmd, NULL, NULL, 1);
 	switch (ret) {
@@ -146,6 +183,11 @@ static void setup(void)
 
 	if (access(GRPPATH, F_OK) == -1)
 		tst_brk(TFAIL | TERRNO, "group quotafile didn't exist");
+
+	TEST(quotactl(QCMD(Q_GETNEXTQUOTA, USRQUOTA), tst_device->dev,
+		test_id, (void *) &res_ndq));
+	if (TST_ERR == EINVAL || TST_ERR == ENOSYS)
+		getnextquota_nsup = 1;
 }
 
 static void verify_quota(unsigned int n)
@@ -155,7 +197,15 @@ static void verify_quota(unsigned int 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, skip it");
+		return;
+	}
 	TEST(quotactl(tc->cmd, tst_device->dev, *tc->id, tc->addr));
 	if (TST_RET == -1) {
 		tst_res(TFAIL | TTERRNO, "quotactl failed to %s", tc->des);
@@ -189,4 +239,3 @@ static struct tst_test test = {
 	.mnt_data = "usrquota,grpquota",
 	.setup = setup,
 };
-
-- 
2.18.0




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

* [LTP] [PATCH v4 2/5] syscalls/quotactl02: Add Q_XGETQSTATV test and group quota tests
  2019-11-20  9:13 [LTP] [PATCH v4 0/5] optimize quotactl test code Yang Xu
  2019-11-20  9:13 ` [LTP] [PATCH v4 1/5] syscalls/quotactl01: Add Q_GETNEXTQUOTA test Yang Xu
@ 2019-11-20  9:13 ` Yang Xu
  2019-11-20  9:13 ` [LTP] [PATCH v4 3/5] syscalls/quotactl04: add project quota test for non-xfs filesystem Yang Xu
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 23+ messages in thread
From: Yang Xu @ 2019-11-20  9:13 UTC (permalink / raw)
  To: ltp

Q_XGETQSTATV returns XFS filesystem-specific quota information in the fs_quota_statv
pointed to by addr. The qs_version field of the structure should be filled with the
version of the structure supported by the caller (for now, only FS_QSTAT_VERSION1
is supported).

Also, cover group quota like quotactl01.c.

Move common code to quota02.h, so we can use it for comming quotactl05.c to test project
quota on xfs filesystem.

Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
---
 include/lapi/quotactl.h                       |  33 +++
 m4/ltp-quota.m4                               |   1 +
 .../kernel/syscalls/quotactl/quotactl02.c     | 222 ++++++++----------
 .../kernel/syscalls/quotactl/quotactl02.h     | 167 +++++++++++++
 4 files changed, 305 insertions(+), 118 deletions(-)
 create mode 100644 testcases/kernel/syscalls/quotactl/quotactl02.h

diff --git a/include/lapi/quotactl.h b/include/lapi/quotactl.h
index 5c49cedce..808d044ff 100644
--- a/include/lapi/quotactl.h
+++ b/include/lapi/quotactl.h
@@ -30,6 +30,39 @@ struct if_nextdqblk {
 #endif
 #endif
 
+#ifndef HAVE_STRUCT_FS_QUOTA_STATV
+# ifdef HAVE_LINUX_TYPES_H
+# include <linux/types.h>
+struct fs_qfilestatv {
+	__u64           qfs_ino;
+	__u64           qfs_nblks;
+	__u32           qfs_nextents;
+	__u32           qfs_pad;
+};
+
+struct fs_quota_statv {
+	__s8                    qs_version;
+	__u8                    qs_pad1;
+	__u16                   qs_flags;
+	__u32                   qs_incoredqs;
+	struct fs_qfilestatv    qs_uquota;
+	struct fs_qfilestatv    qs_gquota;
+	struct fs_qfilestatv    qs_pquota;
+	__s32                   qs_btimelimit;
+	__s32                   qs_itimelimit;
+	__s32                   qs_rtbtimelimit;
+	__u16                   qs_bwarnlimit;
+	__u16                   qs_iwarnlimit;
+	__u64                   qs_pad2[8];
+};
+#define FS_QSTATV_VERSION1 1
+#endif
+#endif
+
+# ifndef Q_XGETQSTATV
+#  define Q_XGETQSTATV XQM_CMD(8)
+# endif
+
 # ifndef Q_XGETNEXTQUOTA
 #  define Q_XGETNEXTQUOTA XQM_CMD(9)
 # endif
diff --git a/m4/ltp-quota.m4 b/m4/ltp-quota.m4
index e8d08c6b7..bcdff7041 100644
--- a/m4/ltp-quota.m4
+++ b/m4/ltp-quota.m4
@@ -4,4 +4,5 @@ dnl Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
 
 AC_DEFUN([LTP_CHECK_SYSCALL_QUOTACTL],[
 AC_CHECK_TYPES([struct if_nextdqblk],,,[#include <linux/quota.h>])
+AC_CHECK_TYPES([struct fs_quota_statv],,,[#include <xfs/xqm.h>])
 ])
diff --git a/testcases/kernel/syscalls/quotactl/quotactl02.c b/testcases/kernel/syscalls/quotactl/quotactl02.c
index edba84391..9eae11f5e 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl02.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl02.c
@@ -1,7 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Copyright (c) 2013 Fujitsu Ltd.
+ * Copyright (c) 2013-2019 FUJITSU LIMITED. All rights reserved
  * Author: DAN LI <li.dan@cn.fujitsu.com>
+ * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
  */
 
 /*
@@ -9,156 +10,141 @@
  *
  * Description:
  * 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.
+ * 1) quotactl(2) succeeds to turn off xfs quota and get xfs quota off status
+ *    for user.
+ * 2) quotactl(2) succeeds to turn on xfs quota and get xfs quota on status
+ *    for usr.
  * 3) quotactl(2) succeeds to set and use Q_XGETQUOTA to get xfs disk quota
- *    limits.
+ *    limits for user.
  * 4) quotactl(2) succeeds to set and use Q_XGETNEXTQUOTA to get xfs disk
- *    quota limits.
+ *    quota limits greater than or equal to ID for user.
+ * 5) quotactl(2) succeeds to turn off xfs quota and get xfs quota off statv
+ *    for user.
+ * 6) quotactl(2) succeeds to turn on xfs quota and get xfs quota on statv
+ *    for user.
+ * 7) quotactl(2) succeeds to turn off xfs quota and get xfs quota off status
+ *    for group.
+ * 8) quotactl(2) succeeds to turn on xfs quota and get xfs quota on status
+ *    for group.
+ * 9) quotactl(2) succeeds to set and use Q_XGETQUOTA to get xfs disk quota
+ *    limits for group.
+ * 10)quotactl(2) succeeds to set and use Q_XGETNEXTQUOTA to get xfs disk
+ *    quota limits for group.
+ * 11)quotactl(2) succeeds to turn off xfs quota and get xfs quota off statv
+ *    for group.
+ * 12)quotactl(2) succeeds to turn on xfs quota and get xfs quota on statv
+ *    for group.
  */
-#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 "quotactl02.h"
 
 #ifdef HAVE_XFS_XQM_H
-# include <xfs/xqm.h>
-
-static void check_qoff(int, char *);
-static void check_qon(int, char *);
-static void check_qlim(int, char *);
-
-static uint32_t test_id;
-static struct fs_disk_quota set_dquota = {
-	.d_rtb_softlimit = 1000,
-	.d_fieldmask = FS_DQ_RTBSOFT
-};
-static uint32_t qflag = XFS_QUOTA_UDQ_ENFD;
-static const char mntpoint[] = "mnt_point";
+static uint32_t qflagu = XFS_QUOTA_UDQ_ENFD;
+static uint32_t qflagg = XFS_QUOTA_GDQ_ENFD;
 
 static struct t_case {
 	int cmd;
 	void *addr;
 	void (*func_check)();
 	int check_subcmd;
+	int flag;
 	char *des;
+	char *tname;
 } tcases[] = {
-	{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, Q_XGETQSTAT,
-	"turn on xfs quota and get xfs quota on status"},
-	{QCMD(Q_XSETQLIM, USRQUOTA), &set_dquota, check_qlim, Q_XGETQUOTA,
-	"Q_XGETQUOTA"},
-	{QCMD(Q_XSETQLIM, USRQUOTA), &set_dquota, check_qlim, Q_XGETNEXTQUOTA,
-	"Q_XGETNEXTQUOTA"},
+	{QCMD(Q_XQUOTAOFF, USRQUOTA), &qflagu, check_qoff,
+	QCMD(Q_XGETQSTAT, USRQUOTA), 1,
+	"turn off xfs quota and get xfs quota off status for user",
+	"QCMD(Q_XGETQSTAT, USRQUOTA) off"},
+
+	{QCMD(Q_XQUOTAON, USRQUOTA), &qflagu, check_qon,
+	QCMD(Q_XGETQSTAT, USRQUOTA), 1,
+	"turn on xfs quota and get xfs quota on status for user",
+	"QCMD(Q_XGETQSTAT, USRQUOTA) on"},
+
+	{QCMD(Q_XSETQLIM, USRQUOTA), &set_dquota, check_qlim,
+	QCMD(Q_XGETQUOTA, USRQUOTA), 0, "Q_XGETQUOTA for user",
+	"QCMD(Q_XGETQUOTA, USRQUOTA) qlim"},
+
+	{QCMD(Q_XSETQLIM, USRQUOTA), &set_dquota, check_qlim,
+	QCMD(Q_XGETNEXTQUOTA, USRQUOTA), 0, "Q_XGETNEXTQUOTA for user",
+	"QCMD(Q_XGETNEXTQUOTA, USRQUOTA)"},
+
+	{QCMD(Q_XQUOTAOFF, USRQUOTA), &qflagu, check_qoffv,
+	QCMD(Q_XGETQSTATV, USRQUOTA), 1,
+	"turn off xfs quota and get xfs quota off statv for user",
+	"QCMD(Q_XGETQSTATV, USRQUOTA) off"},
+
+	{QCMD(Q_XQUOTAON, USRQUOTA), &qflagu, check_qonv,
+	QCMD(Q_XGETQSTATV, USRQUOTA), 1,
+	"turn on xfs quota and get xfs quota on statv for user",
+	"QCMD(Q_XGETQSTATV, USRQUOTA) on"},
+
+	{QCMD(Q_XQUOTAOFF, GRPQUOTA), &qflagg, check_qoff,
+	QCMD(Q_XGETQSTAT, GRPQUOTA), 1,
+	"turn off xfs quota and get xfs quota off status for group",
+	"QCMD(Q_XGETQSTAT, GRPQUOTA) off"},
+
+	{QCMD(Q_XQUOTAON, GRPQUOTA), &qflagg, check_qon,
+	QCMD(Q_XGETQSTAT, GRPQUOTA), 1,
+	"turn on xfs quota and get xfs quota on status for group",
+	"QCMD(Q_XGETQSTAT, GRPQUOTA) on"},
+
+	{QCMD(Q_XSETQLIM, GRPQUOTA), &set_dquota, check_qlim,
+	QCMD(Q_XGETQUOTA, GRPQUOTA), 0, "Q_XGETQUOTA for group",
+	"QCMD(Q_XGETQUOTA, GRPQUOTA) qlim"},
+
+	{QCMD(Q_XSETQLIM, GRPQUOTA), &set_dquota, check_qlim,
+	QCMD(Q_XGETNEXTQUOTA, GRPQUOTA), 0, "Q_XGETNEXTQUOTA for group",
+	"QCMD(Q_XGETNEXTQUOTA, GRPQUOTA)"},
+
+	{QCMD(Q_XQUOTAOFF, GRPQUOTA), &qflagg, check_qoffv,
+	QCMD(Q_XGETQSTATV, GRPQUOTA), 1,
+	"turn off xfs quota and get xfs quota off statv for group",
+	"QCMD(Q_XGETQSTATV, GRPQUOTA) off"},
+
+	{QCMD(Q_XQUOTAON, GRPQUOTA), &qflagg, check_qonv,
+	QCMD(Q_XGETQSTATV, GRPQUOTA), 1,
+	"turn on xfs quota and get xfs quota on statv for group",
+	"QCMD(Q_XGETQSTATV, GRPQUOTA) on"},
 };
 
-static void check_qoff(int subcmd, char *desp)
-{
-	int res;
-	struct fs_quota_stat res_qstat;
-
-	res = quotactl(QCMD(subcmd, USRQUOTA), tst_device->dev, test_id,
-		       (void *) &res_qstat);
-	if (res == -1) {
-		tst_res(TFAIL | TERRNO,
-			"quotactl() failed to get xfs quota off status");
-		return;
-	}
-
-	if (res_qstat.qs_flags & XFS_QUOTA_UDQ_ENFD) {
-		tst_res(TFAIL, "xfs quota enforcement was on unexpectedly");
-		return;
-	}
-
-	tst_res(TPASS, "quoactl() succeeded to %s", desp);
-}
-
-static void check_qon(int subcmd, char *desp)
+static void setup(void)
 {
-	int res;
-	struct fs_quota_stat res_qstat;
-
-	res = quotactl(QCMD(subcmd, USRQUOTA), tst_device->dev,
-		       test_id, (void *) &res_qstat);
-	if (res == -1) {
-		tst_res(TFAIL | TERRNO,
-			"quotactl() failed to get xfs quota on status");
-		return;
-	}
-
-	if (!(res_qstat.qs_flags & XFS_QUOTA_UDQ_ENFD)) {
-		tst_res(TFAIL, "xfs quota enforcement was off unexpectedly");
-		return;
-	}
-
-	tst_res(TPASS, "quoactl() succeeded to %s", desp);
+	test_id = geteuid();
+	check_support_cmd(USRQUOTA);
+	check_support_cmd(GRPQUOTA);
 }
 
-static void check_qlim(int subcmd, char *desp)
+static void verify_quota(unsigned int n)
 {
-	int res;
-	static struct fs_disk_quota res_dquota;
-
-	res_dquota.d_rtb_softlimit = 0;
-
-	res = quotactl(QCMD(subcmd, USRQUOTA), tst_device->dev,
-		       test_id, (void *) &res_dquota);
-	if (res == -1) {
-		if (errno == EINVAL) {
-			tst_brk(TCONF | TERRNO,
-				"%s wasn't supported in quotactl()", desp);
-		}
-		tst_res(TFAIL | TERRNO,
-			"quotactl() failed to get xfs disk quota limits");
-		return;
-	}
+	struct t_case *tc = &tcases[n];
 
-	if (res_dquota.d_id != test_id) {
-		tst_res(TFAIL, "quotactl() got unexpected user id %u, expected %u",
-				res_dquota.d_id, test_id);
+	tst_res(TINFO, "Test #%d: %s", n, tc->tname);
+	if ((tc->check_subcmd == QCMD(Q_XGETNEXTQUOTA, USRQUOTA)
+			|| tc->check_subcmd == QCMD(Q_XGETNEXTQUOTA, GRPQUOTA))
+			&& x_getnextquota_nsup) {
+		tst_res(TCONF, "current system doesn't support this cmd, skip it");
 		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,
-			set_dquota.d_rtb_hardlimit);
+	if ((tc->check_subcmd == QCMD(Q_XGETQSTATV, USRQUOTA)
+			|| tc->check_subcmd == QCMD(Q_XGETQSTATV, GRPQUOTA))
+			&& x_getstatv_nsup) {
+		tst_res(TCONF, "current system doesn't support this cmd, skip it");
 		return;
 	}
 
-	tst_res(TPASS, "quoactl() succeeded to set and use %s to get xfs disk quota limits",
-			desp);
-}
-
-static void setup(void)
-{
-	test_id = geteuid();
-}
-
-static void verify_quota(unsigned int n)
-{
-	struct t_case *tc = &tcases[n];
-
 	TEST(quotactl(tc->cmd, tst_device->dev, test_id, tc->addr));
 	if (TST_RET == -1) {
 		tst_res(TFAIL | TTERRNO, "quotactl() failed to %s", tc->des);
 		return;
 	}
 
-	tc->func_check(tc->check_subcmd, tc->des);
+	if (tc->flag)
+		tc->func_check(tc->check_subcmd, tc->des, *(int *)(tc->addr));
+	else
+		tc->func_check(tc->check_subcmd, tc->des);
 }
 
-static const char *kconfigs[] = {
-	"CONFIG_XFS_QUOTA",
-	NULL
-};
-
 static struct tst_test test = {
 	.needs_tmpdir = 1,
 	.needs_root = 1,
@@ -168,7 +154,7 @@ static struct tst_test test = {
 	.mount_device = 1,
 	.dev_fs_type = "xfs",
 	.mntpoint = mntpoint,
-	.mnt_data = "usrquota",
+	.mnt_data = "usrquota,grpquota",
 	.setup = setup,
 };
 #else
diff --git a/testcases/kernel/syscalls/quotactl/quotactl02.h b/testcases/kernel/syscalls/quotactl/quotactl02.h
new file mode 100644
index 000000000..60237e16e
--- /dev/null
+++ b/testcases/kernel/syscalls/quotactl/quotactl02.h
@@ -0,0 +1,167 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
+ */
+
+#ifndef QUOTACTL02_H
+#define QUOTACTL02_H
+
+#define _GNU_SOURCE
+#include "config.h"
+#include <errno.h>
+#include <unistd.h>
+#include <stdio.h>
+#include "tst_test.h"
+#include "lapi/quotactl.h"
+
+#ifdef HAVE_XFS_XQM_H
+# include <xfs/xqm.h>
+
+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_getstatv_nsup;
+static const char mntpoint[] = "mnt_point";
+static const char *kconfigs[] = {
+	"CONFIG_XFS_QUOTA",
+	NULL
+};
+
+void check_support_cmd(int quotatype)
+{
+	struct fs_disk_quota resfs_dquota;
+	struct fs_quota_statv resfs_qstatv = {
+		.qs_version = FS_QSTATV_VERSION1
+	};
+
+	x_getnextquota_nsup = 0;
+	x_getstatv_nsup = 0;
+
+	TEST(quotactl(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, (void *) &resfs_qstatv));
+	if (TST_ERR == EINVAL || TST_ERR == ENOSYS)
+		x_getstatv_nsup = 1;
+
+}
+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);
+	if (res == -1) {
+		tst_res(TFAIL | TERRNO,
+			"quotactl() failed to get xfs quota off status");
+		return;
+	}
+
+	if (res_qstat.qs_flags & flag) {
+		tst_res(TFAIL, "xfs quota enforcement was on unexpectedly");
+		return;
+	}
+
+	tst_res(TPASS, "quotactl() succeeded to %s", desp);
+}
+
+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);
+	if (res == -1) {
+		tst_res(TFAIL | TERRNO,
+			"quotactl() failed to get xfs quota on status");
+		return;
+	}
+
+	if (!(res_qstat.qs_flags & flag)) {
+		tst_res(TFAIL, "xfs quota enforcement was off unexpectedly");
+		return;
+	}
+
+	tst_res(TPASS, "quotactl() succeeded to %s", desp);
+}
+
+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);
+	if (res == -1) {
+		tst_res(TFAIL | TERRNO,
+			"quotactl() failed to get xfs quota off stav");
+		return;
+	}
+
+	if (res_qstatv.qs_flags & flag) {
+		tst_res(TFAIL, "xfs quota enforcement was on unexpectedly");
+		return;
+	}
+
+	tst_res(TPASS, "quotactl() succeeded to %s", desp);
+}
+
+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);
+	if (res == -1) {
+		tst_res(TFAIL | TERRNO,
+			"quotactl() failed to get xfs quota on statv");
+		return;
+	}
+
+	if (!(res_qstatv.qs_flags & flag)) {
+		tst_res(TFAIL, "xfs quota enforcement was off unexpectedly");
+		return;
+	}
+
+	tst_res(TPASS, "quotactl() succeeded to %s", desp);
+}
+
+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);
+	if (res == -1) {
+		tst_res(TFAIL | TERRNO,
+			"quotactl() failed to get xfs disk quota limits");
+		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, set_dquota.d_rtb_hardlimit);
+		return;
+	}
+
+	tst_res(TPASS, "quotactl() succeeded to set and use %s to get xfs disk quota limits",
+			desp);
+}
+#endif//HAVE_XFS_XQM_H
+#endif
-- 
2.18.0




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

* [LTP] [PATCH v4 3/5] syscalls/quotactl04: add project quota test for non-xfs filesystem
  2019-11-20  9:13 [LTP] [PATCH v4 0/5] optimize quotactl test code Yang Xu
  2019-11-20  9:13 ` [LTP] [PATCH v4 1/5] syscalls/quotactl01: Add Q_GETNEXTQUOTA test Yang Xu
  2019-11-20  9:13 ` [LTP] [PATCH v4 2/5] syscalls/quotactl02: Add Q_XGETQSTATV test and group quota tests Yang Xu
@ 2019-11-20  9:13 ` Yang Xu
  2019-11-20  9:13 ` [LTP] [PATCH v4 4/5] syscalls/quotactl05: add project quota test on xfs filesystem Yang Xu
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 23+ messages in thread
From: Yang Xu @ 2019-11-20  9:13 UTC (permalink / raw)
  To: ltp

This is a variant about quotactl01.c and used to test project quota.
I split it into a new case instead of adding it in quotaclt01.c because
two points:
1)Before linux 4.10, ext4 doesn't support project quota.
2)On old kernel, kernel doesn't permit mount both prjquota and grpquota together.

Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
---
 include/lapi/quotactl.h                       |   4 +
 runtest/syscalls                              |   1 +
 testcases/kernel/syscalls/quotactl/.gitignore |   1 +
 .../kernel/syscalls/quotactl/quotactl04.c     | 162 ++++++++++++++++++
 4 files changed, 168 insertions(+)
 create mode 100644 testcases/kernel/syscalls/quotactl/quotactl04.c

diff --git a/include/lapi/quotactl.h b/include/lapi/quotactl.h
index 808d044ff..8d559af51 100644
--- a/include/lapi/quotactl.h
+++ b/include/lapi/quotactl.h
@@ -59,6 +59,10 @@ struct fs_quota_statv {
 #endif
 #endif
 
+#ifndef PRJQUOTA
+# define PRJQUOTA 2
+#endif
+
 # ifndef Q_XGETQSTATV
 #  define Q_XGETQSTATV XQM_CMD(8)
 # endif
diff --git a/runtest/syscalls b/runtest/syscalls
index fee91f909..078143b13 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -954,6 +954,7 @@ pwritev202_64 pwritev202_64
 quotactl01 quotactl01
 quotactl02 quotactl02
 quotactl03 quotactl03
+quotactl04 quotactl04
 
 read01 read01
 read02 read02
diff --git a/testcases/kernel/syscalls/quotactl/.gitignore b/testcases/kernel/syscalls/quotactl/.gitignore
index b0ef075e7..1db7c5d98 100644
--- a/testcases/kernel/syscalls/quotactl/.gitignore
+++ b/testcases/kernel/syscalls/quotactl/.gitignore
@@ -1,3 +1,4 @@
 /quotactl01
 /quotactl02
 /quotactl03
+/quotactl04
diff --git a/testcases/kernel/syscalls/quotactl/quotactl04.c b/testcases/kernel/syscalls/quotactl/quotactl04.c
new file mode 100644
index 000000000..86260499d
--- /dev/null
+++ b/testcases/kernel/syscalls/quotactl/quotactl04.c
@@ -0,0 +1,162 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
+ *
+ * This testcase checks the basic flag of quotactl(2) for project quota on
+ * non-XFS filesystems.
+ *
+ * 1) quotactl(2) succeeds to turn on quota with Q_QUOTAON flag for project.
+ * 2) quotactl(2) succeeds to set disk quota limits with Q_SETQUOTA flag
+ *    for project.
+ * 3) quotactl(2) succeeds to get disk quota limits with Q_GETQUOTA flag
+ *    for project.
+ * 4) quotactl(2) succeeds to set information about quotafile with Q_SETINFO
+ *    flag for project.
+ * 5) quotactl(2) succeeds to get information about quotafile with Q_GETINFO
+ *    flag for project.
+ * 6) quotactl(2) succeeds to get quota format with Q_GETFMT flag for project.
+ * 7) quotactl(2) succeeds to get disk quota limit greater than or equal to
+ *    ID with Q_GETNEXTQUOTA flag for project.
+ * 8) quotactl(2) succeeds to turn off quota with Q_QUOTAOFF flag for project.
+ */
+
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include "config.h"
+#include "lapi/quotactl.h"
+#include "tst_test.h"
+
+#ifndef QFMT_VFS_V1
+# define QFMT_VFS_V1 4
+#endif
+
+#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 = {
+	.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 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, PRJQUOTA), &fmt_id, NULL,
+	NULL, NULL, 0, "turn on quota for project",
+	"QCMD(Q_QUOTAON, PRJQUOTA)"},
+
+	{QCMD(Q_SETQUOTA, PRJQUOTA), &test_id, &set_dq,
+	NULL, NULL, 0, "set disk quota limit for project",
+	"QCMD(Q_SETQUOTA, PRJQUOTA)"},
+
+	{QCMD(Q_GETQUOTA, PRJQUOTA), &test_id, &res_dq,
+	&set_dq.dqb_bsoftlimit, &res_dq.dqb_bsoftlimit,
+	sizeof(res_dq.dqb_bsoftlimit), "get disk quota limit for project",
+	"QCMD(Q_GETQUOTA, PRJQUOTA)"},
+
+	{QCMD(Q_SETINFO, PRJQUOTA), &test_id, &set_qf,
+	NULL, NULL, 0, "set information about quotafile for project",
+	"QCMD(Q_SETINFO, PRJQUOTA"},
+
+	{QCMD(Q_GETINFO, PRJQUOTA), &test_id, &res_qf,
+	&set_qf.dqi_bgrace, &res_qf.dqi_bgrace, sizeof(res_qf.dqi_bgrace),
+	"get information about quotafile for project",
+	"QCMD(Q_GETINFO, PRJQUOTA"},
+
+	{QCMD(Q_GETFMT, PRJQUOTA), &test_id, &fmt_buf,
+	&fmt_id, &fmt_buf, sizeof(fmt_buf),
+	"get quota format for project", "QCMD(Q_GETFMT, PRJQUOTA)"},
+
+	{QCMD(Q_GETNEXTQUOTA, PRJQUOTA), &test_id, &res_ndq,
+	&test_id, &res_ndq.dqb_id, sizeof(res_ndq.dqb_id),
+	"get next disk quota limit for project",
+	"QCMD(Q_GETNEXTQUOTA, PRJQUOTA)"},
+
+	{QCMD(Q_QUOTAOFF, PRJQUOTA), &test_id, NULL,
+	NULL, NULL, 0, "turn off quota for project",
+	"QCMD(Q_QUOTAOFF, PRJQUOTA)"},
+
+};
+
+static void setup(void)
+{
+	const char *const extra_opts[] = {"-O quota,project", NULL};
+
+	test_id = geteuid();
+	SAFE_MKFS(tst_device->dev, tst_device->fs_type, NULL, extra_opts);
+	SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, "quota");
+	mount_flag = 1;
+}
+
+static void cleanup(void)
+{
+	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;
+
+	tst_res(TINFO, "Test #%d: %s", n, tc->tname);
+
+	TEST(quotactl(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 const char *kconfigs[] = {
+	"CONFIG_QFMT_V2",
+	NULL
+};
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.needs_root = 1,
+	.needs_kconfigs = kconfigs,
+	.min_kver = "4.10", /* commit 689c958cbe6b (ext4: add project quota support) */
+	.test = verify_quota,
+	.tcnt = ARRAY_SIZE(tcases),
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_device = 1,
+	.dev_fs_type = "ext4",
+	.mntpoint = MNTPOINT,
+};
-- 
2.18.0




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

* [LTP] [PATCH v4 4/5] syscalls/quotactl05: add project quota test on xfs filesystem
  2019-11-20  9:13 [LTP] [PATCH v4 0/5] optimize quotactl test code Yang Xu
                   ` (2 preceding siblings ...)
  2019-11-20  9:13 ` [LTP] [PATCH v4 3/5] syscalls/quotactl04: add project quota test for non-xfs filesystem Yang Xu
@ 2019-11-20  9:13 ` Yang Xu
  2019-11-20  9:13 ` [LTP] [PATCH v4 5/5] syscalls/quotactl06: Add new error testcase Yang Xu
  2019-11-21 17:01 ` [LTP] [PATCH v4 0/5] optimize quotactl test code Petr Vorel
  5 siblings, 0 replies; 23+ messages in thread
From: Yang Xu @ 2019-11-20  9:13 UTC (permalink / raw)
  To: ltp

This is a variant about quotactl02.c and used to test project quota.
I split it into a new case instead of adding it in quotaclt02.c because
kernel doesn't permit mount both group and project quota before
commit d892d5864f02 ("xfs: Start using pquotaino from the superblock.").

Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
---
 runtest/syscalls                              |   1 +
 testcases/kernel/syscalls/quotactl/.gitignore |   1 +
 .../kernel/syscalls/quotactl/quotactl05.c     | 118 ++++++++++++++++++
 3 files changed, 120 insertions(+)
 create mode 100644 testcases/kernel/syscalls/quotactl/quotactl05.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 078143b13..b6bf67c38 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -955,6 +955,7 @@ quotactl01 quotactl01
 quotactl02 quotactl02
 quotactl03 quotactl03
 quotactl04 quotactl04
+quotactl05 quotactl05
 
 read01 read01
 read02 read02
diff --git a/testcases/kernel/syscalls/quotactl/.gitignore b/testcases/kernel/syscalls/quotactl/.gitignore
index 1db7c5d98..6fe62fbf7 100644
--- a/testcases/kernel/syscalls/quotactl/.gitignore
+++ b/testcases/kernel/syscalls/quotactl/.gitignore
@@ -2,3 +2,4 @@
 /quotactl02
 /quotactl03
 /quotactl04
+/quotactl05
diff --git a/testcases/kernel/syscalls/quotactl/quotactl05.c b/testcases/kernel/syscalls/quotactl/quotactl05.c
new file mode 100644
index 000000000..20ef30421
--- /dev/null
+++ b/testcases/kernel/syscalls/quotactl/quotactl05.c
@@ -0,0 +1,118 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
+ *
+ * Test Name: quotactl05
+ *
+ * Description:
+ * This testcase checks basic flags of quotactl(2) for project on an XFS file
+ * system:
+ * 1) quotactl(2) succeeds to turn off xfs quota and get xfs quota off status
+ *    for project.
+ * 2) quotactl(2) succeeds to turn on xfs quota and get xfs quota on status
+ *    for project.
+ * 3) quotactl(2) succeeds to set and use Q_XGETQUOTA to get xfs disk quota
+ *    limits for project.
+ * 4) quotactl(2) succeeds to set and use Q_XGETNEXTQUOTA to get xfs disk
+ *    quota limits Cgreater than or equal to ID for project.
+ * 5) quotactl(2) succeeds to turn off xfs quota and get xfs quota off statv
+ *    for project.
+ * 6) quotactl(2) succeeds to turn on xfs quota and get xfs quota on statv
+ *    for project.
+ */
+#include "quotactl02.h"
+#if defined(HAVE_XFS_XQM_H)
+
+static uint32_t qflagp = XFS_QUOTA_PDQ_ENFD;
+static struct t_case {
+	int cmd;
+	void *addr;
+	void (*func_check)();
+	int check_subcmd;
+	int flag;
+	char *des;
+	char *tname;
+} tcases[] = {
+	{QCMD(Q_XQUOTAOFF, PRJQUOTA), &qflagp, check_qoff,
+	QCMD(Q_XGETQSTAT, PRJQUOTA), 1,
+	"turn off xfs quota and get xfs quota off status for project",
+	"QCMD(Q_XGETQSTAT, PRJQUOTA) off"},
+
+	{QCMD(Q_XQUOTAON, PRJQUOTA), &qflagp, check_qon,
+	QCMD(Q_XGETQSTAT, PRJQUOTA), 1,
+	"turn on xfs quota and get xfs quota on status for project",
+	"QCMD(Q_XGETQSTAT, PRJQUOTA) on"},
+
+	{QCMD(Q_XSETQLIM, PRJQUOTA), &set_dquota, check_qlim,
+	QCMD(Q_XGETQUOTA, PRJQUOTA), 0,
+	"Q_XGETQUOTA for project", "QCMD(Q_XGETQUOTA, PRJQUOTA) qlim"},
+
+	{QCMD(Q_XSETQLIM, PRJQUOTA), &set_dquota, check_qlim,
+	QCMD(Q_XGETNEXTQUOTA, PRJQUOTA), 0,
+	"Q_XGETNEXTQUOTA for project", "QCMD(Q_XGETNEXTQUOTA, PRJQUOTA)"},
+
+	{QCMD(Q_XQUOTAOFF, PRJQUOTA), &qflagp, check_qoffv,
+	QCMD(Q_XGETQSTATV, PRJQUOTA), 1,
+	"turn off xfs quota and get xfs quota off statv for project",
+	"QCMD(Q_XGETQSTATV, PRJQUOTA) off"},
+
+	{QCMD(Q_XQUOTAON, PRJQUOTA), &qflagp, check_qonv,
+	QCMD(Q_XGETQSTATV, PRJQUOTA), 1,
+	"turn on xfs quota and get xfs quota on statv for project",
+	"QCMD(Q_XGETQSTATV, PRJQUOTA) on"},
+};
+
+static void setup(void)
+{
+	test_id = geteuid();
+	check_support_cmd(PRJQUOTA);
+}
+
+static void verify_quota(unsigned int n)
+{
+	struct t_case *tc = &tcases[n];
+
+	tst_res(TINFO, "Test #%d: %s", n, tc->tname);
+
+	if ((tc->check_subcmd == QCMD(Q_XGETNEXTQUOTA, PRJQUOTA))
+		&& x_getnextquota_nsup) {
+		tst_res(TCONF,
+			"current system doesn't support this cmd, skip it");
+		return;
+	}
+	if ((tc->check_subcmd == QCMD(Q_XGETQSTATV, PRJQUOTA))
+		&& x_getstatv_nsup) {
+		tst_res(TCONF,
+			"current system doesn't support this cmd, skip it");
+		return;
+	}
+
+	TEST(quotactl(tc->cmd, tst_device->dev, test_id, tc->addr));
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TTERRNO, "quotactl() failed to %s", tc->des);
+		return;
+	}
+
+	if (tc->flag)
+		tc->func_check(tc->check_subcmd, tc->des, *(int *)(tc->addr));
+	else
+		tc->func_check(tc->check_subcmd, tc->des);
+}
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.needs_root = 1,
+	.needs_kconfigs = kconfigs,
+	.test = verify_quota,
+	.tcnt = ARRAY_SIZE(tcases),
+	.mount_device = 1,
+	.dev_fs_type = "xfs",
+	.mntpoint = mntpoint,
+	.mnt_data = "prjquota",
+	.setup = setup,
+};
+
+#else
+	TST_TEST_TCONF("This system didn't have <xfs/xqm.h>");
+#endif
-- 
2.18.0




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

* [LTP] [PATCH v4 5/5] syscalls/quotactl06: Add new error testcase
  2019-11-20  9:13 [LTP] [PATCH v4 0/5] optimize quotactl test code Yang Xu
                   ` (3 preceding siblings ...)
  2019-11-20  9:13 ` [LTP] [PATCH v4 4/5] syscalls/quotactl05: add project quota test on xfs filesystem Yang Xu
@ 2019-11-20  9:13 ` Yang Xu
  2019-11-21 17:01 ` [LTP] [PATCH v4 0/5] optimize quotactl test code Petr Vorel
  5 siblings, 0 replies; 23+ messages in thread
From: Yang Xu @ 2019-11-20  9:13 UTC (permalink / raw)
  To: ltp

Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
---
 runtest/syscalls                              |   1 +
 testcases/kernel/syscalls/quotactl/.gitignore |   1 +
 .../kernel/syscalls/quotactl/quotactl06.c     | 196 ++++++++++++++++++
 3 files changed, 198 insertions(+)
 create mode 100644 testcases/kernel/syscalls/quotactl/quotactl06.c

diff --git a/runtest/syscalls b/runtest/syscalls
index b6bf67c38..9bbde8c41 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -956,6 +956,7 @@ quotactl02 quotactl02
 quotactl03 quotactl03
 quotactl04 quotactl04
 quotactl05 quotactl05
+quotactl06 quotactl06
 
 read01 read01
 read02 read02
diff --git a/testcases/kernel/syscalls/quotactl/.gitignore b/testcases/kernel/syscalls/quotactl/.gitignore
index 6fe62fbf7..12896d6ad 100644
--- a/testcases/kernel/syscalls/quotactl/.gitignore
+++ b/testcases/kernel/syscalls/quotactl/.gitignore
@@ -3,3 +3,4 @@
 /quotactl03
 /quotactl04
 /quotactl05
+/quotactl06
diff --git a/testcases/kernel/syscalls/quotactl/quotactl06.c b/testcases/kernel/syscalls/quotactl/quotactl06.c
new file mode 100644
index 000000000..0d7efe38b
--- /dev/null
+++ b/testcases/kernel/syscalls/quotactl/quotactl06.c
@@ -0,0 +1,196 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
+ *
+ * Tests basic error handling of the quotactl syscall.
+ * Description:
+ * 1) quotactl fails with EACCES when cmd is Q_QUOTAON and addr
+ * existed but not a regular file.
+ * 2) quotaclt fails with ENOENT when the file specified by special
+ * or addr does not exist.
+ * 3) quotactl fails with EBUSTY when  cmd is Q_QUOTAON and another
+ * Q_QUOTAON had already been performed.
+ * 4) quotactl fails with EFAULT when addr or special is invalid.
+ * 5) quotactl fails with EINVAL when cmd or type is invalid.
+ * 6) quotactl fails with ENOTBLK when special is not a block device.
+ * 7) quotactl fails with ESRCH when no disk quota is found for the
+ * indicated user and quotas have not been turned on for this fs.
+ * 8) quotactl fails with ESRCH when cmd is Q_QUOTAON, but the quota
+ * format was not found.
+ * 9) quotactl fails with ESRCH when cmd is Q_GETNEXTQUOTA, but there
+ * is no ID greater than or equal to id that has an active quota.
+ * 10) quotactl fails with ERANGE when cmd is Q_SETQUOTA, but the
+ * specified limits are out of the range allowed by the quota format.
+ * 11) quotactl fails with EPERM when the caller lacked the required
+ * privilege (CAP_SYS_ADMIN) for the specified operation.
+ */
+#include <errno.h>
+#include <sys/quota.h>
+#include "tst_test.h"
+#include "lapi/quotactl.h"
+#include "tst_capability.h"
+
+#define OPTION_INVALID 999
+#define QFMT_VFS_V0     2
+#define USRPATH MNTPOINT "/aquota.user"
+#define FMTID QFMT_VFS_V0
+
+#define MNTPOINT "mntpoint"
+#define TESTDIR1 MNTPOINT "/testdir1"
+#define TESTDIR2 MNTPOINT "/testdir2"
+
+static int32_t fmt_id = FMTID;
+static int32_t fmt_invalid = 999;
+static int test_invalid;
+static int test_id;
+static int getnextquota_nsup;
+
+static struct if_nextdqblk res_ndq;
+static struct dqblk set_dq = {
+	.dqb_bsoftlimit = 100,
+	.dqb_valid = QIF_BLIMITS
+};
+
+static struct dqblk set_dqmax = {
+	.dqb_bsoftlimit = 0x7fffffffffffffffLL,  /* 2^63-1 */
+	.dqb_valid = QIF_BLIMITS
+};
+
+struct tst_cap dropadmin = {
+	.action = TST_CAP_DROP,
+	.id = CAP_SYS_ADMIN,
+	.name = "CAP_SYS_ADMIN",
+};
+
+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_QUOTAON, USRQUOTA), &fmt_id, TESTDIR1, EACCES, 0},
+	{QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, TESTDIR2, ENOENT, 0},
+	{QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, USRPATH, EBUSY, 1},
+	{QCMD(Q_SETQUOTA, USRQUOTA), &fmt_id, NULL, EFAULT, 1},
+	{QCMD(OPTION_INVALID, USRQUOTA), &fmt_id, USRPATH, EINVAL, 0},
+	{QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, USRPATH, ENOTBLK, 0},
+	{QCMD(Q_SETQUOTA, USRQUOTA), &test_id, &set_dq, ESRCH, 0},
+	{QCMD(Q_QUOTAON, USRQUOTA), &fmt_invalid, USRPATH, ESRCH, 0},
+	{QCMD(Q_GETNEXTQUOTA, USRQUOTA), &test_invalid, USRPATH, ESRCH, 0},
+	{QCMD(Q_SETQUOTA, USRQUOTA), &test_id, &set_dqmax, ERANGE, 1},
+	{QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, USRPATH, 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, skip it");
+		return;
+	}
+
+	if (tc->on_flag) {
+		TEST(quotactl(QCMD(Q_QUOTAON, USRQUOTA), tst_device->dev, FMTID, USRPATH));
+		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 (tc->exp_err == ENOTBLK)
+		TEST(quotactl(tc->cmd, "/dev/null", *tc->id, tc->addr));
+	else
+		TEST(quotactl(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(quotactl(QCMD(Q_QUOTAOFF, USRQUOTA), tst_device->dev, FMTID, USRPATH));
+		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)
+{
+	const char *const cmd[] = {"quotacheck", "-uF", "vfsv0", MNTPOINT, NULL};
+	int ret;
+	unsigned int i;
+
+	ret = tst_run_cmd(cmd, NULL, NULL, 1);
+	switch (ret) {
+	case 0:
+		break;
+	case 255:
+		tst_brk(TBROK, "quotacheck binary not installed");
+		break;
+	default:
+		tst_brk(TBROK, "quotacheck exited with %i", ret);
+	}
+
+	if (access(USRPATH, F_OK) == -1)
+		tst_brk(TFAIL | TERRNO, "user quotafile didn't exist");
+
+	SAFE_MKDIR(TESTDIR1, 0666);
+	test_id = geteuid();
+	test_invalid = test_id + 1;
+
+	TEST(quotactl(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 const char *kconfigs[] = {
+	"CONFIG_QFMT_V2",
+	NULL
+};
+
+static struct tst_test test = {
+	.setup = setup,
+	.needs_kconfigs = kconfigs,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_quotactl,
+	.dev_fs_type = "ext4",
+	.mntpoint = MNTPOINT,
+	.mount_device = 1,
+	.mnt_data = "usrquota",
+	.needs_root = 1,
+};
-- 
2.18.0




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

* [LTP] [PATCH v4 1/5] syscalls/quotactl01: Add Q_GETNEXTQUOTA test
  2019-11-20  9:13 ` [LTP] [PATCH v4 1/5] syscalls/quotactl01: Add Q_GETNEXTQUOTA test Yang Xu
@ 2019-11-20 15:12   ` Petr Vorel
  2019-11-20 15:16     ` Petr Vorel
                       ` (2 more replies)
  0 siblings, 3 replies; 23+ messages in thread
From: Petr Vorel @ 2019-11-20 15:12 UTC (permalink / raw)
  To: ltp

Hi Jan, Cyril, Xu,

> Q_GETNEXTQUOTA was introduced since linux 4.6, this operation is the
> same as Q_GETQUOTA, but it returns quota information for the next ID
> greater than or equal to id that has a quota set.

> Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
Reviewed-by: Petr Vorel <pvorel@suse.cz>

LGTM, with 2 questions.

>  #ifndef LAPI_QUOTACTL_H__
>  # define LAPI_QUOTACTL_H__

> +#include <sys/quota.h>
> +
> +#ifdef HAVE_STRUCT_IF_NEXTDQBLK
> +# include <linux/quota.h>
> +#else
> +# ifdef HAVE_LINUX_TYPES_H
> +# include <linux/types.h>
@Jan, @Cyril: Do we want to generally avoid loading <linux/types.h> if not really needed?
__u64 can be uint64_t etc (as it's also visible in struct dqblk in <sys/quota.h>
in various libc headers).
We used this approach for /usr/include/linux/bpf.h and for fanotify fixes for
musl (testcases/kernel/syscalls/fanotify/fanotify.h).

So unless you're against this approach here I'll change it before merge
(and add this info to next version of library API writing guidelines patch
https://patchwork.ozlabs.org/patch/1166786/).

> +struct if_nextdqblk {
> +	__u64 dqb_bhardlimit;
> +	__u64 dqb_bsoftlimit;
> +	__u64 dqb_curspace;
> +	__u64 dqb_ihardlimit;
> +	__u64 dqb_isoftlimit;
> +	__u64 dqb_curinodes;
> +	__u64 dqb_btime;
> +	__u64 dqb_itime;
> +	__u32 dqb_valid;
> +	__u32 dqb_id;
> +};

...
> +++ b/testcases/kernel/syscalls/quotactl/quotactl01.c
> @@ -1,7 +1,7 @@
>  // SPDX-License-Identifier: GPL-2.0-or-later
>  /*
>  * Copyright (c) Crackerjack Project., 2007
> -* Copyright (c) 2016 Fujitsu Ltd.
> +* Copyright (c) 2016-2019 FUJITSU LIMITED. All rights reserved
BTW correct formatting is
/*
 *
 */
Not
/*
*
*/
I'll change it during merge (nit, the code is what matters, not formatting, of course).

...
> +static int getnextquota_nsup;
...
>  static void setup(void)
>  {
>  	const char *const cmd[] = {"quotacheck", "-ugF", "vfsv0", MNTPOINT, NULL};
>  	int ret;
> +	getnextquota_nsup = 0;
This is not needed (getnextquota_nsup is static and it's called just once, I'll
remove it before merge).

>  	ret = tst_run_cmd(cmd, NULL, NULL, 1);
>  	switch (ret) {
> @@ -146,6 +183,11 @@ static void setup(void)

>  	if (access(GRPPATH, F_OK) == -1)
>  		tst_brk(TFAIL | TERRNO, "group quotafile didn't exist");
> +
> +	TEST(quotactl(QCMD(Q_GETNEXTQUOTA, USRQUOTA), tst_device->dev,
> +		test_id, (void *) &res_ndq));
> +	if (TST_ERR == EINVAL || TST_ERR == ENOSYS)
Does EINVAL really mans not supported? Shouldn't be just for ENOSYS
> +		getnextquota_nsup = 1;
>  }

Looking at kernel sources - this does not look as not supported, but rather a
failure (we might want to add some test for EINVAL):
	if (!qid_has_mapping(sb->s_user_ns, qid))
		return -EINVAL;

kernel fs/quota/quota.c
/*
 * Return quota for next active quota >= this id, if any exists,
 * otherwise return -ENOENT via ->get_nextdqblk
 */
static int quota_getnextquota(struct super_block *sb, int type, qid_t id,
			  void __user *addr)
{
	struct kqid qid;
	struct qc_dqblk fdq;
	struct if_nextdqblk idq;
	int ret;

	if (!sb->s_qcop->get_nextdqblk)
		return -ENOSYS;
	qid = make_kqid(current_user_ns(), type, id);
	if (!qid_has_mapping(sb->s_user_ns, qid))
		return -EINVAL;
	ret = sb->s_qcop->get_nextdqblk(sb, &qid, &fdq);
	if (ret)
		return ret;
	/* struct if_nextdqblk is a superset of struct if_dqblk */
	copy_to_if_dqblk((struct if_dqblk *)&idq, &fdq);
	idq.dqb_id = from_kqid(current_user_ns(), qid);
	if (copy_to_user(addr, &idq, sizeof(idq)))
		return -EFAULT;
	return 0;
}

Kind regards,
Petr

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

* [LTP] [PATCH v4 1/5] syscalls/quotactl01: Add Q_GETNEXTQUOTA test
  2019-11-20 15:12   ` Petr Vorel
@ 2019-11-20 15:16     ` Petr Vorel
  2019-11-21  3:37       ` Yang Xu
  2019-11-21  2:29     ` Yang Xu
  2019-11-21  9:01     ` Jan Stancek
  2 siblings, 1 reply; 23+ messages in thread
From: Petr Vorel @ 2019-11-20 15:16 UTC (permalink / raw)
  To: ltp

Hi Jan, Cyril, Xu,

> > +#ifdef HAVE_STRUCT_IF_NEXTDQBLK
> > +# include <linux/quota.h>
> > +#else
> > +# ifdef HAVE_LINUX_TYPES_H
> > +# include <linux/types.h>
> @Jan, @Cyril: Do we want to generally avoid loading <linux/types.h> if not really needed?
> __u64 can be uint64_t etc (as it's also visible in struct dqblk in <sys/quota.h>
> in various libc headers).
> We used this approach for /usr/include/linux/bpf.h and for fanotify fixes for
> musl (testcases/kernel/syscalls/fanotify/fanotify.h).

> So unless you're against this approach here I'll change it before merge
> (and add this info to next version of library API writing guidelines patch
> https://patchwork.ozlabs.org/patch/1166786/).
+ general question: do we want always test against kernel headers or libc
headers? Libc is often outdated, so mostly it'd be our fallback to be tested.
Ideally both kernel and libc header should be tested, but that's not easily
achievable.

Kind regards,
Petr

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

* [LTP] [PATCH v4 1/5] syscalls/quotactl01: Add Q_GETNEXTQUOTA test
  2019-11-20 15:12   ` Petr Vorel
  2019-11-20 15:16     ` Petr Vorel
@ 2019-11-21  2:29     ` Yang Xu
  2019-11-21  5:45       ` Petr Vorel
  2019-11-21  9:01     ` Jan Stancek
  2 siblings, 1 reply; 23+ messages in thread
From: Yang Xu @ 2019-11-21  2:29 UTC (permalink / raw)
  To: ltp


on 2019/11/20 23:12, Petr Vorel wrote:

> Hi Jan, Cyril, Xu,
>
>> Q_GETNEXTQUOTA was introduced since linux 4.6, this operation is the
>> same as Q_GETQUOTA, but it returns quota information for the next ID
>> greater than or equal to id that has a quota set.
>> Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
> Reviewed-by: Petr Vorel <pvorel@suse.cz>
>
> LGTM, with 2 questions.
>
>>   #ifndef LAPI_QUOTACTL_H__
>>   # define LAPI_QUOTACTL_H__
>> +#include <sys/quota.h>
>> +
>> +#ifdef HAVE_STRUCT_IF_NEXTDQBLK
>> +# include <linux/quota.h>
>> +#else
>> +# ifdef HAVE_LINUX_TYPES_H
>> +# include <linux/types.h>
> @Jan, @Cyril: Do we want to generally avoid loading <linux/types.h> if not really needed?
> __u64 can be uint64_t etc (as it's also visible in struct dqblk in <sys/quota.h>
> in various libc headers).
> We used this approach for /usr/include/linux/bpf.h and for fanotify fixes for
> musl (testcases/kernel/syscalls/fanotify/fanotify.h).
>
> So unless you're against this approach here I'll change it before merge
> (and add this info to next version of library API writing guidelines patch
> https://patchwork.ozlabs.org/patch/1166786/).

I have no objection about using uint64_t becuase Q_GETNEXTQUOTA man-pages also uses it.
I used  struct if_nextdqblk as same as <linux/quota.h> defined. But I don't know why we can't use
<linux/type.h> in lapi/quotactl.h and I also use it in lapi/seccomp.h. IMHO, they affected nothing.
Or, they have some redefined errors or not having this headers files in special linux distribution.

>> +struct if_nextdqblk {
>> +	__u64 dqb_bhardlimit;
>> +	__u64 dqb_bsoftlimit;
>> +	__u64 dqb_curspace;
>> +	__u64 dqb_ihardlimit;
>> +	__u64 dqb_isoftlimit;
>> +	__u64 dqb_curinodes;
>> +	__u64 dqb_btime;
>> +	__u64 dqb_itime;
>> +	__u32 dqb_valid;
>> +	__u32 dqb_id;
>> +};
> ...
>> +++ b/testcases/kernel/syscalls/quotactl/quotactl01.c
>> @@ -1,7 +1,7 @@
>>   // SPDX-License-Identifier: GPL-2.0-or-later
>>   /*
>>   * Copyright (c) Crackerjack Project., 2007
>> -* Copyright (c) 2016 Fujitsu Ltd.
>> +* Copyright (c) 2016-2019 FUJITSU LIMITED. All rights reserved
> BTW correct formatting is
> /*
>   *
>   */
> Not
> /*
> *
> */
> I'll change it during merge (nit, the code is what matters, not formatting, of course).
>
> ...
>> +static int getnextquota_nsup;
> ...
>>   static void setup(void)
>>   {
>>   	const char *const cmd[] = {"quotacheck", "-ugF", "vfsv0", MNTPOINT, NULL};
>>   	int ret;
>> +	getnextquota_nsup = 0;
> This is not needed (getnextquota_nsup is static and it's called just once, I'll
> remove it before merge).

Yes.

>
>>   	ret = tst_run_cmd(cmd, NULL, NULL, 1);
>>   	switch (ret) {
>> @@ -146,6 +183,11 @@ static void setup(void)
>>   	if (access(GRPPATH, F_OK) == -1)
>>   		tst_brk(TFAIL | TERRNO, "group quotafile didn't exist");
>> +
>> +	TEST(quotactl(QCMD(Q_GETNEXTQUOTA, USRQUOTA), tst_device->dev,
>> +		test_id, (void *) &res_ndq));
>> +	if (TST_ERR == EINVAL || TST_ERR == ENOSYS)
> Does EINVAL really mans not supported? Shouldn't be just for ENOSYS.

EINVAL can mean non-supported? by using correct argument.

>> +		getnextquota_nsup = 1;
>>   }
> Looking at kernel sources - this does not look as not supported, but rather a
> failure (we might want to add some test for EINVAL):
> 	if (!qid_has_mapping(sb->s_user_ns, qid))
> 		return -EINVAL;
>
> kernel fs/quota/quota.c
> /*
>   * Return quota for next active quota >= this id, if any exists,
>   * otherwise return -ENOENT via ->get_nextdqblk
>   */
> static int quota_getnextquota(struct super_block *sb, int type, qid_t id,
> 			  void __user *addr)
> {
> 	struct kqid qid;
> 	struct qc_dqblk fdq;
> 	struct if_nextdqblk idq;
> 	int ret;
>
> 	if (!sb->s_qcop->get_nextdqblk)
> 		return -ENOSYS;
> 	qid = make_kqid(current_user_ns(), type, id);
> 	if (!qid_has_mapping(sb->s_user_ns, qid))
> 		return -EINVAL;
> 	ret = sb->s_qcop->get_nextdqblk(sb, &qid, &fdq);
> 	if (ret)
> 		return ret;
> 	/* struct if_nextdqblk is a superset of struct if_dqblk */
> 	copy_to_if_dqblk((struct if_dqblk *)&idq, &fdq);
> 	idq.dqb_id = from_kqid(current_user_ns(), qid);
> 	if (copy_to_user(addr, &idq, sizeof(idq)))
> 		return -EFAULT;
> 	return 0;
> }

Hi Petr

look do_quotactl function in fs/quota/quota.c.

static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id,
 ?????????????????????? void __user *addr, const struct path *path)
{

 ??? switch (cmd) {
 ??????? case Q_QUOTAON:
 ??????????????? return quota_quotaon(sb, type, id, path);
 ??????? case Q_QUOTAOFF:
 ??????????????? return quota_quotaoff(sb, type);
 ??????? case Q_GETFMT:
 ??????????????? return quota_getfmt(sb, type, addr);
 ??????? case Q_GETINFO:
 ??? ??? ......

 ??? ???? default:
 ??????????????? return -EINVAL;
 ??????? }
}

So if it doesn't have Q_GETNEXTQUOTA cmd, it should report EINVAL(we use correct argument and correct environment, so there is no failure).

> Kind regards,
> Petr
>
>


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191121/a085db33/attachment-0001.htm>

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

* [LTP] [PATCH v4 1/5] syscalls/quotactl01: Add Q_GETNEXTQUOTA test
  2019-11-20 15:16     ` Petr Vorel
@ 2019-11-21  3:37       ` Yang Xu
  2019-11-21  5:10         ` Petr Vorel
  0 siblings, 1 reply; 23+ messages in thread
From: Yang Xu @ 2019-11-21  3:37 UTC (permalink / raw)
  To: ltp


on 2019/11/20 23:16, Petr Vorel wrote:

> Hi Jan, Cyril, Xu,
>
>>> +#ifdef HAVE_STRUCT_IF_NEXTDQBLK
>>> +# include <linux/quota.h>
>>> +#else
>>> +# ifdef HAVE_LINUX_TYPES_H
>>> +# include <linux/types.h>
>> @Jan, @Cyril: Do we want to generally avoid loading <linux/types.h> if not really needed?
>> __u64 can be uint64_t etc (as it's also visible in struct dqblk in <sys/quota.h>
>> in various libc headers).
>> We used this approach for /usr/include/linux/bpf.h and for fanotify fixes for
>> musl (testcases/kernel/syscalls/fanotify/fanotify.h).
>> So unless you're against this approach here I'll change it before merge
>> (and add this info to next version of library API writing guidelines patch
>> https://patchwork.ozlabs.org/patch/1166786/).
> + general question: do we want always test against kernel headers or libc
> headers? Libc is often outdated, so mostly it'd be our fallback to be tested.
> Ideally both kernel and libc header should be tested, but that's not easily
> achievable.

IMHO, We often test libc and it usually includes kernel headers ie. 
<sys/quota.h> <sys/prctl.h>. I perfet to check one except that glibc and 
kernel they have themselves implementation . If the struct or variable 
is not defined, we can define it in ltp lapi headers. Then we can avoid 
build error and increase coverage(because kernel may implement it).   

>
> Kind regards,
> Petr
>


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191121/6c82d301/attachment.htm>

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

* [LTP] [PATCH v4 1/5] syscalls/quotactl01: Add Q_GETNEXTQUOTA test
  2019-11-21  3:37       ` Yang Xu
@ 2019-11-21  5:10         ` Petr Vorel
  2019-11-21  7:07           ` Yang Xu
  0 siblings, 1 reply; 23+ messages in thread
From: Petr Vorel @ 2019-11-21  5:10 UTC (permalink / raw)
  To: ltp

Hi Xu,

> > + general question: do we want always test against kernel headers or libc
> > headers? Libc is often outdated, so mostly it'd be our fallback to be tested.
> > Ideally both kernel and libc header should be tested, but that's not easily
> > achievable.

> IMHO, We often test libc and it usually includes kernel headers ie.
> <sys/quota.h> <sys/prctl.h>. I perfet to check one except that glibc and
> kernel they have themselves implementation . If the struct or variable is
> not defined, we can define it in ltp lapi headers. Then we can avoid build
> error and increase coverage(because kernel may implement it).

Yep. I'm ok with using libc headers (increased coverage), but we need good
checks anyway for other libc (at least for musl; bionic also like glibc uses
internally kernel headers, uclibc-ng usually embeds kernel header parts and
strives to be glibc compatible anyway).

Kind regards,
Petr

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

* [LTP] [PATCH v4 1/5] syscalls/quotactl01: Add Q_GETNEXTQUOTA test
  2019-11-21  2:29     ` Yang Xu
@ 2019-11-21  5:45       ` Petr Vorel
  2019-11-21  7:45         ` Yang Xu
  0 siblings, 1 reply; 23+ messages in thread
From: Petr Vorel @ 2019-11-21  5:45 UTC (permalink / raw)
  To: ltp

Hi Xu,

> > @Jan, @Cyril: Do we want to generally avoid loading <linux/types.h> if not really needed?
> > __u64 can be uint64_t etc (as it's also visible in struct dqblk in <sys/quota.h>
> > in various libc headers).
> > We used this approach for /usr/include/linux/bpf.h and for fanotify fixes for
> > musl (testcases/kernel/syscalls/fanotify/fanotify.h).

> > So unless you're against this approach here I'll change it before merge
> > (and add this info to next version of library API writing guidelines patch
> > https://patchwork.ozlabs.org/patch/1166786/).

> I have no objection about using uint64_t becuase Q_GETNEXTQUOTA man-pages also uses it.
> I used  struct if_nextdqblk as same as <linux/quota.h> defined. But I don't know why we can't use
> <linux/type.h> in lapi/quotactl.h and I also use it in lapi/seccomp.h. IMHO, they affected nothing.
> Or, they have some redefined errors or not having this headers files in special linux distribution.

Based on Jan's comment [1], maybe he meant it specifically for __kernel_fsid_t in
fanotify.h, not as a general approach. __kernel_fsid_t is more complicated than
uint64_t. That's why I'm asking whether there is a general approach we want to
take.

> > > +	TEST(quotactl(QCMD(Q_GETNEXTQUOTA, USRQUOTA), tst_device->dev,
> > > +		test_id, (void *) &res_ndq));
> > > +	if (TST_ERR == EINVAL || TST_ERR == ENOSYS)
> > Does EINVAL really mans not supported? Shouldn't be just for ENOSYS.

> EINVAL can mean non-supported? by using correct argument.

> look do_quotactl function in fs/quota/quota.c.

> static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id,
> ?????????????????????? void __user *addr, const struct path *path)
> {

> ??? switch (cmd) {
> ??????? case Q_QUOTAON:
> ??????????????? return quota_quotaon(sb, type, id, path);
> ??????? case Q_QUOTAOFF:
> ??????????????? return quota_quotaoff(sb, type);
> ??????? case Q_GETFMT:
> ??????????????? return quota_getfmt(sb, type, addr);
> ??????? case Q_GETINFO:
> ??? ??? ......

> ??? ???? default:
> ??????????????? return -EINVAL;
> ??????? }
> }

> So if it doesn't have Q_GETNEXTQUOTA cmd, it should report EINVAL(we use correct argument and correct environment, so there is no failure).
OK, you're right, thanks for info :).

Kind regards,
Petr

[1] https://patchwork.ozlabs.org/patch/1178182/#2281586

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

* [LTP] [PATCH v4 1/5] syscalls/quotactl01: Add Q_GETNEXTQUOTA test
  2019-11-21  5:10         ` Petr Vorel
@ 2019-11-21  7:07           ` Yang Xu
  2019-11-21  8:21             ` Petr Vorel
  0 siblings, 1 reply; 23+ messages in thread
From: Yang Xu @ 2019-11-21  7:07 UTC (permalink / raw)
  To: ltp


on 2019/11/21 13:10, Petr Vorel wrote:

> Hi Xu,
>
>>> + general question: do we want always test against kernel headers or libc
>>> headers? Libc is often outdated, so mostly it'd be our fallback to be tested.
>>> Ideally both kernel and libc header should be tested, but that's not easily
>>> achievable.
>> IMHO, We often test libc and it usually includes kernel headers ie.
>> <sys/quota.h> <sys/prctl.h>. I perfet to check one except that glibc and
>> kernel they have themselves implementation . If the struct or variable is
>> not defined, we can define it in ltp lapi headers. Then we can avoid build
>> error and increase coverage(because kernel may implement it).
> Yep. I'm ok with using libc headers (increased coverage), but we need good
> checks anyway for other libc (at least for musl; bionic also like glibc uses
> internally kernel headers, uclibc-ng usually embeds kernel header parts and
> strives to be glibc compatible anyway).

Hi Petr

Yes. I check <sys/quota.h> and <sys/prctl.h> on musl libc[1] and they don't include linux header files.
So I think checking both kernel and libc headers on other libc(musl,bionic) is meaningful.

ps: If our travis-ci has a target with musl, I think it will be better. I don't know whether possible.

[1]http://git.musl-libc.org/cgit/musl/tree/include/sys/quota.h

Thanks
Yang Xu

>
> Kind regards,
> Petr
>
>


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191121/5943fa14/attachment.htm>

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

* [LTP] [PATCH v4 1/5] syscalls/quotactl01: Add Q_GETNEXTQUOTA test
  2019-11-21  5:45       ` Petr Vorel
@ 2019-11-21  7:45         ` Yang Xu
  2019-11-21  8:32           ` Petr Vorel
  0 siblings, 1 reply; 23+ messages in thread
From: Yang Xu @ 2019-11-21  7:45 UTC (permalink / raw)
  To: ltp


on 2019/11/21 13:45, Petr Vorel wrote:

> Based on Jan's comment [1], maybe he meant it specifically for __kernel_fsid_t in
> fanotify.h, not as a general approach. __kernel_fsid_t is more complicated than
> uint64_t. That's why I'm asking whether there is a general approach we want to
> take.

Hi Petr

I see. Now, I think we should avoid to use <linux/types.h>?? because on musl? libc doesn't have it.

Also ,If we use uint64_t, they still failed on 2.6.32-754.el6.x86_64 with undefined  . Or, we should use TST_ABI to define uint64_t them

on myself.

Thanks
Yang Xu



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191121/90916f80/attachment-0001.htm>

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

* [LTP] [PATCH v4 1/5] syscalls/quotactl01: Add Q_GETNEXTQUOTA test
  2019-11-21  7:07           ` Yang Xu
@ 2019-11-21  8:21             ` Petr Vorel
  2019-11-21  9:01               ` Yang Xu
  0 siblings, 1 reply; 23+ messages in thread
From: Petr Vorel @ 2019-11-21  8:21 UTC (permalink / raw)
  To: ltp

Hi Xu,

> Yes. I check <sys/quota.h> and <sys/prctl.h> on musl libc[1] and they don't include linux header files.
> So I think checking both kernel and libc headers on other libc(musl,bionic) is meaningful.
But in single C file we decide only on one of these two.
It's a similar problem as testing raw syscall or libc wrapper (which we already
solved with .test_variants).
NOTE: Bionic has generate it's headers from linux headers.

> ps: If our travis-ci has a target with musl, I think it will be better. I don't know whether possible.
It's here. But it requires some more fixes (in a meantime files are deleted),
so I'll post it once it's everything fixed
https://github.com/pevik/ltp/commits/travis/musl
https://travis-ci.org/pevik/ltp/builds/614575796

There is also CI on LTP on all glibc/uclibc-ng/musl in Buildroot
http://autobuild.buildroot.net/index.php?reason=ltp-testsuite-20190930

+ There are other CI based on yocto/openembedded on glibc/uclibc-ng/musl

> [1]http://git.musl-libc.org/cgit/musl/tree/include/sys/quota.h

Kind regards,
Petr

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

* [LTP] [PATCH v4 1/5] syscalls/quotactl01: Add Q_GETNEXTQUOTA test
  2019-11-21  7:45         ` Yang Xu
@ 2019-11-21  8:32           ` Petr Vorel
  2019-11-21  8:38             ` Yang Xu
  0 siblings, 1 reply; 23+ messages in thread
From: Petr Vorel @ 2019-11-21  8:32 UTC (permalink / raw)
  To: ltp

Hi Xu,

> I see. Now, I think we should avoid to use <linux/types.h>?? because on musl? libc doesn't have it.
IMHO <linux/types.h> are always installed from kernel, not from libc
(packaged result of make headers_install run from kernel sources).

> Also ,If we use uint64_t, they still failed on 2.6.32-754.el6.x86_64 with undefined  . Or, we should use TST_ABI to define uint64_t them
Hm, that what I said: using kernel headers is imho easier that using libc
headers (fewer problems with compatibility).
Anyway, I don't want to block this patchset.
We can always merge it as it is and sort/fix this problem later.

Kind regards,
Petr

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

* [LTP] [PATCH v4 1/5] syscalls/quotactl01: Add Q_GETNEXTQUOTA test
  2019-11-21  8:32           ` Petr Vorel
@ 2019-11-21  8:38             ` Yang Xu
  0 siblings, 0 replies; 23+ messages in thread
From: Yang Xu @ 2019-11-21  8:38 UTC (permalink / raw)
  To: ltp

on 2019/11/21 16:32, Petr Vorel wrote:

> Hi Xu,
>
>> I see. Now, I think we should avoid to use <linux/types.h>?? because on musl? libc doesn't have it.
> IMHO <linux/types.h> are always installed from kernel, not from libc
> (packaged result of make headers_install run from kernel sources).

Oh, you are right. For this case, using <linux/types.h> is right that we don't have situation such as fanotify .

>
>> Also ,If we use uint64_t, they still failed on 2.6.32-754.el6.x86_64 with undefined  . Or, we should use TST_ABI to define uint64_t them
> Hm, that what I said: using kernel headers is imho easier that using libc
> headers (fewer problems with compatibility).
> Anyway, I don't want to block this patchset.
> We can always merge it as it is and sort/fix this problem later.

Yes. kernel header is more eaiser that libc. Thanks.

>
> Kind regards,
> Petr
>
>


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191121/9198e6fb/attachment.htm>

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

* [LTP] [PATCH v4 1/5] syscalls/quotactl01: Add Q_GETNEXTQUOTA test
  2019-11-20 15:12   ` Petr Vorel
  2019-11-20 15:16     ` Petr Vorel
  2019-11-21  2:29     ` Yang Xu
@ 2019-11-21  9:01     ` Jan Stancek
  2019-11-21 10:30       ` Petr Vorel
  2 siblings, 1 reply; 23+ messages in thread
From: Jan Stancek @ 2019-11-21  9:01 UTC (permalink / raw)
  To: ltp



----- Original Message -----
> @Jan, @Cyril: Do we want to generally avoid loading <linux/types.h> if not
> really needed?

Yes, we generally try to avoid including kernel headers. Our style-guide says
"Don't use +linux/+ headers if at all possible". uapi on older distros
was more prone to cause LTP build errors.


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

* [LTP] [PATCH v4 1/5] syscalls/quotactl01: Add Q_GETNEXTQUOTA test
  2019-11-21  8:21             ` Petr Vorel
@ 2019-11-21  9:01               ` Yang Xu
  0 siblings, 0 replies; 23+ messages in thread
From: Yang Xu @ 2019-11-21  9:01 UTC (permalink / raw)
  To: ltp


on 2019/11/21 16:21, Petr Vorel wrote:

> Hi Xu,
>
>> Yes. I check <sys/quota.h> and <sys/prctl.h> on musl libc[1] and they don't include linux header files.
>> So I think checking both kernel and libc headers on other libc(musl,bionic) is meaningful.
> But in single C file we decide only on one of these two.
> It's a similar problem as testing raw syscall or libc wrapper (which we already
> solved with .test_variants).
> NOTE: Bionic has generate it's headers from linux headers.

I see.

Thanks again for reminding Bionic like glibc uses linux headers.

>
>> ps: If our travis-ci has a target with musl, I think it will be better. I don't know whether possible.
> It's here. But it requires some more fixes (in a meantime files are deleted),
> so I'll post it once it's everything fixed
> https://github.com/pevik/ltp/commits/travis/musl
> https://travis-ci.org/pevik/ltp/builds/614575796
>
> There is also CI on LTP on all glibc/uclibc-ng/musl in Buildroot
> http://autobuild.buildroot.net/index.php?reason=ltp-testsuite-20190930
>
> + There are other CI based on yocto/openembedded on glibc/uclibc-ng/musl

It is so cool.? And I think I? can move your musl patches to my ltp fork, so that I can also test them on musl
when I contribute my patches to ltp.

ps: I also think we should not block this patchset.

>
>> [1]http://git.musl-libc.org/cgit/musl/tree/include/sys/quota.h
> Kind regards,
> Petr
>
>


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191121/c86c4866/attachment.htm>

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

* [LTP] [PATCH v4 1/5] syscalls/quotactl01: Add Q_GETNEXTQUOTA test
  2019-11-21  9:01     ` Jan Stancek
@ 2019-11-21 10:30       ` Petr Vorel
  2019-11-21 11:08         ` Jan Stancek
  0 siblings, 1 reply; 23+ messages in thread
From: Petr Vorel @ 2019-11-21 10:30 UTC (permalink / raw)
  To: ltp

Hi Jan, Li,

> ----- Original Message -----
> > @Jan, @Cyril: Do we want to generally avoid loading <linux/types.h> if not
> > really needed?

> Yes, we generally try to avoid including kernel headers. Our style-guide says
> "Don't use +linux/+ headers if at all possible". uapi on older distros
> was more prone to cause LTP build errors.
Thank you for pointing out docs, I completely forgot on this page.
BTW it needs some update (examples use old API, linux_syscall_numbers.h).
Also not sure if everything else still applies (4. Call APIs that don't require
freeing up resources on failure first, 2. Sort headers).

> > Also ,If we use uint64_t, they still failed on 2.6.32-754.el6.x86_64 with undefined  . Or, we should use TST_ABI to define uint64_t them
Jan, are you aware of this problem?
Xu, I'm not sure if you're talking about uint64_t problematic in <linux/types.h>
(as you mention kernel) or problem in glibc <sys/types.h> / <stdint.h> / <inttypes.h>?
We have lots of code which is using some of these 3 libc headers, does it fail
on 2.6.32?

Does anybody compile for 2.6.32?
I know we want to keep support for 2.6.x (we had some discussion in the past).
Than it'd be good to have travis build for kernel 2.6.x.

Back to patchset. I suggest to merge it as it is and I'll prepare patches, which
use <sys/types.h> in our tests.

Kind regards,
Petr

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

* [LTP] [PATCH v4 1/5] syscalls/quotactl01: Add Q_GETNEXTQUOTA test
  2019-11-21 10:30       ` Petr Vorel
@ 2019-11-21 11:08         ` Jan Stancek
  2019-11-21 15:19           ` Petr Vorel
  0 siblings, 1 reply; 23+ messages in thread
From: Jan Stancek @ 2019-11-21 11:08 UTC (permalink / raw)
  To: ltp



----- Original Message -----
> > > Also ,If we use uint64_t, they still failed on 2.6.32-754.el6.x86_64 with
> > > undefined  . Or, we should use TST_ABI to define uint64_t them
> Jan, are you aware of this problem?

I'm not, it should be defined in stdint.h.

# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 6.10 (Santiago)

# grep uint64_t -r /usr/include/ | grep stdint
/usr/include/stdint.h:typedef unsigned long int	uint64_t;

> Xu, I'm not sure if you're talking about uint64_t problematic in
> <linux/types.h>
> (as you mention kernel) or problem in glibc <sys/types.h> / <stdint.h> /
> <inttypes.h>?
> We have lots of code which is using some of these 3 libc headers, does it
> fail
> on 2.6.32?
> 
> Does anybody compile for 2.6.32?

[CC Li]
I think RH still does compile latest for regression tests. RHEL6 will be in
sustaining for couple more years. 


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

* [LTP] [PATCH v4 1/5] syscalls/quotactl01: Add Q_GETNEXTQUOTA test
  2019-11-21 11:08         ` Jan Stancek
@ 2019-11-21 15:19           ` Petr Vorel
  0 siblings, 0 replies; 23+ messages in thread
From: Petr Vorel @ 2019-11-21 15:19 UTC (permalink / raw)
  To: ltp

Hi Jan,

> ----- Original Message -----
> > > > Also ,If we use uint64_t, they still failed on 2.6.32-754.el6.x86_64 with
> > > > undefined  . Or, we should use TST_ABI to define uint64_t them
> > Jan, are you aware of this problem?

> I'm not, it should be defined in stdint.h.

> # cat /etc/redhat-release 
> Red Hat Enterprise Linux Server release 6.10 (Santiago)

> # grep uint64_t -r /usr/include/ | grep stdint
> /usr/include/stdint.h:typedef unsigned long int	uint64_t;

> > Xu, I'm not sure if you're talking about uint64_t problematic in
> > <linux/types.h>
> > (as you mention kernel) or problem in glibc <sys/types.h> / <stdint.h> /
> > <inttypes.h>?
> > We have lots of code which is using some of these 3 libc headers, does it
> > fail
> > on 2.6.32?

> > Does anybody compile for 2.6.32?

> [CC Li]
> I think RH still does compile latest for regression tests. RHEL6 will be in
> sustaining for couple more years. 
Thanks for info. Sorry I forgot, we have CentOS 6.10 in travis, that should be
enough for testing build in old toolchain.

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

* [LTP] [PATCH v4 0/5]  optimize quotactl test code
  2019-11-20  9:13 [LTP] [PATCH v4 0/5] optimize quotactl test code Yang Xu
                   ` (4 preceding siblings ...)
  2019-11-20  9:13 ` [LTP] [PATCH v4 5/5] syscalls/quotactl06: Add new error testcase Yang Xu
@ 2019-11-21 17:01 ` Petr Vorel
  5 siblings, 0 replies; 23+ messages in thread
From: Petr Vorel @ 2019-11-21 17:01 UTC (permalink / raw)
  To: ltp

Hi Xu,

> I cleanup the quotactl code and add project quota test for quotactl.
> Thanks to Jan Kara with support about quota.

Whole patchset merged, following with changes for and quotactl.h seccomp.h to
use libc headers.
Thanks for your work!

Kind regards,
Petr

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

end of thread, other threads:[~2019-11-21 17:01 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-20  9:13 [LTP] [PATCH v4 0/5] optimize quotactl test code Yang Xu
2019-11-20  9:13 ` [LTP] [PATCH v4 1/5] syscalls/quotactl01: Add Q_GETNEXTQUOTA test Yang Xu
2019-11-20 15:12   ` Petr Vorel
2019-11-20 15:16     ` Petr Vorel
2019-11-21  3:37       ` Yang Xu
2019-11-21  5:10         ` Petr Vorel
2019-11-21  7:07           ` Yang Xu
2019-11-21  8:21             ` Petr Vorel
2019-11-21  9:01               ` Yang Xu
2019-11-21  2:29     ` Yang Xu
2019-11-21  5:45       ` Petr Vorel
2019-11-21  7:45         ` Yang Xu
2019-11-21  8:32           ` Petr Vorel
2019-11-21  8:38             ` Yang Xu
2019-11-21  9:01     ` Jan Stancek
2019-11-21 10:30       ` Petr Vorel
2019-11-21 11:08         ` Jan Stancek
2019-11-21 15:19           ` Petr Vorel
2019-11-20  9:13 ` [LTP] [PATCH v4 2/5] syscalls/quotactl02: Add Q_XGETQSTATV test and group quota tests Yang Xu
2019-11-20  9:13 ` [LTP] [PATCH v4 3/5] syscalls/quotactl04: add project quota test for non-xfs filesystem Yang Xu
2019-11-20  9:13 ` [LTP] [PATCH v4 4/5] syscalls/quotactl05: add project quota test on xfs filesystem Yang Xu
2019-11-20  9:13 ` [LTP] [PATCH v4 5/5] syscalls/quotactl06: Add new error testcase Yang Xu
2019-11-21 17:01 ` [LTP] [PATCH v4 0/5] optimize quotactl test code Petr Vorel

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.