[LTP] [PATCH v1 02/11] syscalls/quotactl06???Also test with vfsv1 format
Cyril Hrubis
chrubis@suse.cz
Tue Oct 26 15:45:44 CEST 2021
Hi!
> --- a/testcases/kernel/syscalls/quotactl/quotactl06.c
> +++ b/testcases/kernel/syscalls/quotactl/quotactl06.c
> @@ -1,26 +1,42 @@
> // SPDX-License-Identifier: GPL-2.0-or-later
> /*
> - * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
> + * Copyright (c) 2019-2021 FUJITSU LIMITED. All rights reserved.
> * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * Tests basic error handling of the quotactl syscall with visible quota files
> + * (cover two formats, vfsv0 and vfsv1):
> *
> - * Tests basic error handling of the quotactl syscall.
> * 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.
> */
Same comments apply here as well.
> @@ -32,10 +48,7 @@
> #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"
> @@ -43,10 +56,10 @@
> static char usrpath[] = USRPATH;
> static char testdir1[] = TESTDIR1;
> static char testdir2[] = TESTDIR2;
> -static int32_t fmt_id = FMTID;
> +static int32_t fmt_id;
> static int32_t fmt_invalid = 999;
> static int test_invalid;
> -static int test_id;
> +static int test_id, mount_flag;
> static int getnextquota_nsup;
>
> static struct if_nextdqblk res_ndq;
> @@ -105,7 +118,7 @@ static void verify_quotactl(unsigned int n)
>
> if (tc->on_flag) {
> TEST(quotactl(QCMD(Q_QUOTAON, USRQUOTA), tst_device->dev,
> - FMTID, usrpath));
> + fmt_id, usrpath));
> if (TST_RET == -1)
> tst_brk(TBROK,
> "quotactl with Q_QUOTAON returned %ld", TST_RET);
> @@ -135,7 +148,7 @@ static void verify_quotactl(unsigned int n)
>
> if (quota_on) {
> TEST(quotactl(QCMD(Q_QUOTAOFF, USRQUOTA), tst_device->dev,
> - FMTID, usrpath));
> + fmt_id, usrpath));
> if (TST_RET == -1)
> tst_brk(TBROK,
> "quotactl with Q_QUOTAOFF returned %ld", TST_RET);
> @@ -150,10 +163,23 @@ static void verify_quotactl(unsigned int n)
>
> static void setup(void)
> {
> - const char *const cmd[] = {"quotacheck", "-uF", "vfsv0", MNTPOINT, NULL};
> + const char *const vfsv0_cmd[] = {"quotacheck", "-uF", "vfsv0", MNTPOINT, NULL};
> + const char *const vfsv1_cmd[] = {"quotacheck", "-uF", "vfsv1", MNTPOINT, NULL};
If we are going to repeat this snippet in each test it may make sense to
put it into a header as we do with variants:
static struct quotactl_variant {
int32_t fmt_id;
const char *fmt_name;
} variants[] = {
{.fmt_id = QFMT_VFS_V0, .fmt_name = "vfsv0"}
{.fmt_id = QFMT_VFS_V1, .fmt_name = "vfsv1"}
};
Then we can construct the rest easily from these as:
const char *const cmd[] = {"quotacheck", "-uF", variants[variant].fmt_name, MNTPOINT, NULL};
tst_res(TINFO, "quotactl() with %s format", variants[variant].fmt_name);
SAFE_CMD(cmd, NULL, NULL);
fmt_id = variants[variant].fmt_id;
> unsigned int i;
>
> - SAFE_CMD(cmd, NULL, NULL);
> + SAFE_MKFS(tst_device->dev, tst_device->fs_type, NULL, NULL);
> + SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, "usrquota");
> + mount_flag = 1;
> +
> + if (tst_variant) {
> + tst_res(TINFO, "quotactl() with vfsv1 format");
> + SAFE_CMD(vfsv1_cmd, NULL, NULL);
> + fmt_id = QFMT_VFS_V1;
> + } else {
> + tst_res(TINFO, "quotactl() with vfsv0 format");
> + SAFE_CMD(vfsv0_cmd, NULL, NULL);
> + fmt_id = QFMT_VFS_V0;
> + }
>
> if (access(USRPATH, F_OK) == -1)
> tst_brk(TFAIL | TERRNO, "user quotafile didn't exist");
> @@ -175,8 +201,15 @@ static void setup(void)
> }
> }
>
> +static void cleanup(void)
> +{
> + if (mount_flag && tst_umount(MNTPOINT))
> + tst_res(TWARN | TERRNO, "umount(%s)", MNTPOINT);
> +}
> +
> static struct tst_test test = {
> .setup = setup,
> + .cleanup = cleanup,
> .needs_kconfigs = (const char *[]) {
> "CONFIG_QFMT_V2",
> NULL
> @@ -185,11 +218,11 @@ static struct tst_test test = {
> .test = verify_quotactl,
> .dev_fs_type = "ext4",
> .mntpoint = MNTPOINT,
> - .mount_device = 1,
> - .mnt_data = "usrquota",
> + .needs_device = 1,
> .needs_cmds = (const char *const []) {
> "quotacheck",
> NULL
> },
> .needs_root = 1,
> + .test_variants = 2,
> };
> --
> 2.23.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list