Skip to contentSkip to conversation

Add FS quota availability check functions

PATCH New Martin Doucha 2 participants 8 messages Mar 9, 2021 – Mar 12, 2021 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Add FS quota availability check functions

---
 include/tst_fs.h             | 16 ++++++++++++++++
 lib/tst_supported_fs_types.c | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)
include/tst_fs.h +16 -0
index 4f7dd68d2..acf31d0e1 100644
@@ -180,6 +180,22 @@ int tst_fs_is_supported(const char *fs_type, int flags);
  */
 const char **tst_get_supported_fs_types(int flags);
 
+/*
+ * Check whether device supports FS quotas. Negative return value means that
+ * quotas appear to be broken.
+ */
+int tst_check_quota_support(const char *device, int format,
+	const char *quotafile);
+
+/*
+ * Check for quota support and terminate the test with appropriate exit status
+ * if quotas are not supported or broken.
+ */
+#define tst_require_quota_support(dev, fmt, qfile) \
+	tst_require_quota_support_(__FILE__, __LINE__, (dev), (fmt), (qfile))
+void tst_require_quota_support_(const char *file, const int lineno,
+	const char *device, int format, const char *quotafile);
+
 /*
  * Creates and writes to files on given path until write fails with ENOSPC
  */
lib/tst_supported_fs_types.c +32 -0
index 00ede549d..d9d310fd7 100644
@@ -8,6 +8,7 @@
 #include <stdlib.h>
 #include <sys/mount.h>
 #include <sys/wait.h>
+#include <sys/quota.h>
 
 #define TST_NO_DEFAULT_MAIN
 #include "tst_test.h"
@@ -109,3 +110,34 @@ const char **tst_get_supported_fs_types(int flags)
 
 	return fs_types;
 }
+
+int tst_check_quota_support(const char *device, int format,
+	const char *quotafile)
+{
+	TEST(quotactl(QCMD(Q_QUOTAON, USRQUOTA), device, format, quotafile));
+
+	/* Not supported */
+	if (TST_RET == -1 && TST_ERR == ESRCH)
+		return 0;
+
+	/* Broken */
+	if (TST_RET)
+		return -1;
+
+	quotactl(QCMD(Q_QUOTAOFF, USRQUOTA), device, 0, 0);
+	return 1;
+}
+
+void tst_require_quota_support_(const char *file, const int lineno,
+	const char *device, int format, const char *quotafile)
+{
+	int status = tst_check_quota_support(device, format, quotafile);
+
+	if (!status) {
+		tst_brk_(file, lineno, TCONF,
+			"Kernel or device does not support FS quotas");
+	}
+
+	if (status < 0)
+		tst_brk_(file, lineno, TBROK|TTERRNO, "FS quotas are broken");
+}
Signature · 1 line
2.30.0
#1 lore raw

PATCH 2/2 syscalls/quotactl: Skip tests if FS quota is not supported

---
 .../kernel/syscalls/quotactl/quotactl01.c     |  2 ++
 .../kernel/syscalls/quotactl/quotactl04.c     | 26 +++++++++++++++++--
 .../kernel/syscalls/quotactl/quotactl06.c     |  2 ++
 3 files changed, 28 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/quotactl/quotactl01.c +2 -0
index 7b3649fa5..e5fa02acb 100644
@@ -172,6 +172,8 @@ static void setup(void)
 	if (access(GRPPATH, F_OK) == -1)
 		tst_brk(TFAIL | TERRNO, "group quotafile didn't exist");
 
+	tst_require_quota_support(tst_device->dev, fmt_id, USRPATH);
+
 	TEST(quotactl(QCMD(Q_GETNEXTQUOTA, USRQUOTA), tst_device->dev,
 		test_id, (void *) &res_ndq));
 	if (TST_ERR == EINVAL || TST_ERR == ENOSYS)
testcases/kernel/syscalls/quotactl/quotactl04.c +24 -2
index c8fa916b2..fd3afc888 100644
@@ -28,6 +28,7 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <sys/stat.h>
+#include <sys/mount.h>
 #include "config.h"
 #include "lapi/quotactl.h"
 #include "tst_safe_stdio.h"
@@ -103,6 +104,28 @@ static struct tcase {
 
 };
 
+static void do_mount(const char *source, const char *target,
+	const char *filesystemtype, unsigned long mountflags,
+	const void *data)
+{
+	TEST(mount(source, target, filesystemtype, mountflags, data));
+
+	if (TST_RET == -1 && TST_ERR == ESRCH)
+		tst_brk(TCONF, "Kernel or device does not support FS quotas");
+
+	if (TST_RET == -1) {
+		tst_brk(TBROK | TTERRNO, "mount(%s, %s, %s, %lu, %p) failed",
+			source, target, filesystemtype, mountflags, data);
+	}
+
+	if (TST_RET) {
+		tst_brk(TBROK | TTERRNO, "mount(%s, %s, %s, %lu, %p) failed",
+			source, target, filesystemtype, mountflags, data);
+	}
+
+	mount_flag = 1;
+}
+
 static void setup(void)
 {
 	FILE *f;
@@ -118,8 +141,7 @@ static void setup(void)
 		tst_brk(TCONF, "Test needs mkfs.ext4 >= 1.43 for quota,project option, test skipped");
 	pclose(f);
 	SAFE_MKFS(tst_device->dev, tst_device->fs_type, fs_opts, NULL);
-	SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, "quota");
-	mount_flag = 1;
+	do_mount(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, "quota");
 }
 
 static void cleanup(void)
testcases/kernel/syscalls/quotactl/quotactl06.c +2 -0
index 2818a4dc4..6288f5fa2 100644
@@ -153,6 +153,8 @@ static void setup(void)
 	if (access(USRPATH, F_OK) == -1)
 		tst_brk(TFAIL | TERRNO, "user quotafile didn't exist");
 
+	tst_require_quota_support(tst_device->dev, fmt_id, USRPATH);
+
 	SAFE_MKDIR(TESTDIR1, 0666);
 	test_id = geteuid();
 	test_invalid = test_id + 1;
Signature · 1 line
2.30.0
#3 lore raw

PATCH 2/2 syscalls/quotactl: Skip tests if FS quota is not supported

In reply to Martin Doucha

Hi Martin,

Quoted 1 line

--- a/testcases/kernel/syscalls/quotactl/quotactl04.c

...

testcases/kernel/syscalls/quotactl/quotactl04.c static struct tcase { · line 114

Quoted 8 lines
testcases/kernel/syscalls/quotactl/quotactl04.c +8 -0
+static void do_mount(const char *source, const char *target,
+	const char *filesystemtype, unsigned long mountflags,
+	const void *data)
+{
+	TEST(mount(source, target, filesystemtype, mountflags, data));
+
+	if (TST_RET == -1 && TST_ERR == ESRCH)
+		tst_brk(TCONF, "Kernel or device does not support FS quotas");

BTW I was also thinking about moving this also into safe_mount(), but quotactl04.c is the only test which is using "-O quota" option, thus probably useless.

Kind regards,
Petr

Quoted 13 lines
testcases/kernel/syscalls/quotactl/quotactl04.c +13 -0
+
+	if (TST_RET == -1) {
+		tst_brk(TBROK | TTERRNO, "mount(%s, %s, %s, %lu, %p) failed",
+			source, target, filesystemtype, mountflags, data);
+	}
+
+	if (TST_RET) {
+		tst_brk(TBROK | TTERRNO, "mount(%s, %s, %s, %lu, %p) failed",
+			source, target, filesystemtype, mountflags, data);
+	}
+
+	mount_flag = 1;
+}
#5 lore raw

PATCH 1/2 Add FS quota availability check functions

In reply to Martin Doucha

Hi Martin,

lib/tst_supported_fs_types.c const char **tst_get_supported_fs_types(int flags) · line 117

Quoted 4 lines
lib/tst_supported_fs_types.c +4 -0
+int tst_check_quota_support(const char *device, int format,
+	const char *quotafile)
+{
+	TEST(quotactl(QCMD(Q_QUOTAON, USRQUOTA), device, format, quotafile));

Actually, there is a warning:
tst_supported_fs_types.c: In function ?tst_check_quota_support?:
tst_supported_fs_types.c:117:59: warning: passing argument 4 of ?quotactl? discards ?const? qualifier from pointer target type [-Wdiscarded-qualifiers]
117 | TEST(quotactl(QCMD(Q_QUOTAON, USRQUOTA), device, format, quotafile));

Would you prefer to cast to char *, or just change function parameter to char *?

Kind regards,
Petr

Quoted 12 lines
lib/tst_supported_fs_types.c +12 -0
+
+	/* Not supported */
+	if (TST_RET == -1 && TST_ERR == ESRCH)
+		return 0;
+
+	/* Broken */
+	if (TST_RET)
+		return -1;
+
+	quotactl(QCMD(Q_QUOTAOFF, USRQUOTA), device, 0, 0);
+	return 1;
+}
#6 lore raw

PATCH 1/2 Add FS quota availability check functions

Quoted 11 lines · Petr Vorel

Hi Martin,

lib/tst_supported_fs_types.c const char **tst_get_supported_fs_types(int flags) · line 117

Quoted 4 lines
lib/tst_supported_fs_types.c +4 -0
+int tst_check_quota_support(const char *device, int format,
+	const char *quotafile)
+{
+	TEST(quotactl(QCMD(Q_QUOTAON, USRQUOTA), device, format, quotafile));

Actually, there is a warning:
tst_supported_fs_types.c: In function ?tst_check_quota_support?:
tst_supported_fs_types.c:117:59: warning: passing argument 4 of ?quotactl? discards ?const? qualifier from pointer target type [-Wdiscarded-qualifiers]
117 | TEST(quotactl(QCMD(Q_QUOTAON, USRQUOTA), device, format, quotafile));

Quoted 1 line

Would you prefer to cast to char *, or just change function parameter to char *?

Thanks for catching this. Passing string literals to the function directly is technically wrong so I'll drop the const and fix the tests to allocate a buffer for quotafile paths. I'll resubmit on Monday.

Signature · 7 lines
Martin Doucha   [email protected]
QA Engineer for Software Maintenance
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic
#7 lore raw

PATCH 1/2 Add FS quota availability check functions

Hi Martin,

Quoted 11 lines
Quoted 7 lines

lib/tst_supported_fs_types.c const char **tst_get_supported_fs_types(int flags) · line 117

Quoted 1 line
lib/tst_supported_fs_types.c +1 -0
+	TEST(quotactl(QCMD(Q_QUOTAON, USRQUOTA), device, format, quotafile));

Actually, there is a warning:
tst_supported_fs_types.c: In function ?tst_check_quota_support?:
tst_supported_fs_types.c:117:59: warning: passing argument 4 of ?quotactl? discards ?const? qualifier from pointer target type [-Wdiscarded-qualifiers]
117 | TEST(quotactl(QCMD(Q_QUOTAON, USRQUOTA), device, format, quotafile));

Would you prefer to cast to char *, or just change function parameter to char *?

Thanks for catching this. Passing string literals to the function directly is technically wrong so I'll drop the const and fix the tests to allocate a buffer for quotafile paths. I'll resubmit on Monday.

Thanks a lot!

Kind regards,
Petr