syscalls/quotactl: Store addr string literals in buffer
PATCH v2 1/3 syscalls/quotactl: Store addr string literals in buffer
The addr parameter of quotactl() is read-write so it's technically wrong to pass string literals directly. Store them in a buffer and pass the buffer instead.
Signed-off-by Martin Doucha <[email protected]>
---
Changes since v1: New patch
.../kernel/syscalls/quotactl/quotactl01.c | 10 +++++--- .../kernel/syscalls/quotactl/quotactl06.c | 25 +++++++++++-------- 2 files changed, 21 insertions(+), 14 deletions(-)
testcases/kernel/syscalls/quotactl/quotactl01.c +6 -4
@@ -53,6 +53,8 @@static int32_t fmt_id =FMTID ;static int test_id; +static char usrpath[] =USRPATH ; +static char grppath[] =GRPPATH ;static struct dqblk set_dq = { .dqb_bsoftlimit =100 , .dqb_valid =QIF_BLIMITS
@@ -79,7 +81,7 @@ static struct tcase {char *des;char *tname; } tcases[] = { - {QCMD (Q_QUOTAON ,USRQUOTA ), &fmt_id,USRPATH , + {QCMD (Q_QUOTAON ,USRQUOTA ), &fmt_id, usrpath,NULL ,NULL ,0 ,"turn on quota for user" , "QCMD(Q_QUOTAON, USRQUOTA)"},
@@ -115,11 +117,11 @@ static struct tcase {"get next disk quota limit for user" , "QCMD(Q_GETNEXTQUOTA, USRQUOTA)"}, - {QCMD(Q_QUOTAOFF, USRQUOTA), &test_id, USRPATH, + {QCMD(Q_QUOTAOFF, USRQUOTA), &test_id, usrpath,NULL ,NULL ,0 ,"turn off quota for user" , "QCMD(Q_QUOTAOFF, USRQUOTA)"}, - {QCMD(Q_QUOTAON, GRPQUOTA), &fmt_id, GRPPATH, + {QCMD(Q_QUOTAON, GRPQUOTA), &fmt_id, grppath,NULL ,NULL ,0 ,"turn on quota for group" , "QCMD(Q_QUOTAON, GRPQUOTA)"},
@@ -154,7 +156,7 @@ static struct tcase { "get next disk quota limit for group", "QCMD(Q_GETNEXTQUOTA, GRPQUOTA)"}, - {QCMD (Q_QUOTAOFF ,GRPQUOTA ), &test_id,GRPPATH , + {QCMD (Q_QUOTAOFF ,GRPQUOTA ), &test_id, grppath,NULL ,NULL ,0 ,"turn off quota for group" , "QCMD(Q_QUOTAOFF, GRPQUOTA)"}, };
testcases/kernel/syscalls/quotactl/quotactl06.c +15 -10
@@ -40,6 +40,9 @@#define TESTDIR1 MNTPOINT "/testdir1"#define TESTDIR2 MNTPOINT "/testdir2" +static char usrpath[] =USRPATH ; +static char testdir1[] =TESTDIR1 ; +static char testdir2[] =TESTDIR2 ;static int32_t fmt_id =FMTID ;static int32_t fmt_invalid =999 ;static int test_invalid;
@@ -76,17 +79,17 @@ static struct tcase {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_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(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_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}, + {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, usrpath, EPERM, 0}, }; static void verify_quotactl(unsigned int n)
@@ -101,7 +104,8 @@ static void verify_quotactl(unsigned int n) }if (tc->on_flag) { -TEST (quotactl (QCMD (Q_QUOTAON ,USRQUOTA ), tst_device->dev,FMTID ,USRPATH )); +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 );
@@ -130,7 +134,8 @@ static void verify_quotactl(unsigned int n) }if (quota_on) { -TEST (quotactl (QCMD (Q_QUOTAOFF ,USRQUOTA ), tst_device->dev,FMTID ,USRPATH )); +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 );
Signature · 1 line
2.30.1
PATCH v2 2/3 Add FS quota availability check functions
Signed-off-by Martin Doucha <[email protected]>
---
Changes since v1:
- Change quotafile argument from const char* to char*
include/tst_fs.h | 15 +++++++++++++++ lib/tst_supported_fs_types.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+)
include/tst_fs.h +15 -0
@@ -180,6 +180,21 @@ 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,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,char *quotafile); +/* * Creates and writes to files on given path until write fails with ENOSPC */
lib/tst_supported_fs_types.c +31 -0
@@ -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,33 @@ const char **tst_get_supported_fs_types(int flags)return fs_types; } + +int tst_check_quota_support (const char *device,int format,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,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.1
PATCH v2 3/3 syscalls/quotactl: Skip tests if FS quota is not supported
In reply to Martin DouchaSigned-off-by Martin Doucha <[email protected]>
---
Changes since v1:
- Change USRPATH string literal to the usrpath buffer introduced in patch 1
.../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
@@ -174,6 +174,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
@@ -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
@@ -158,6 +158,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.1
PATCH v2 3/3 syscalls/quotactl: Skip tests if FS quota is not supported
Hi Martin,
thanks, pushed!
Kind regards,
Petr