Skip to content

Commit

Permalink
syscalls/quotactl: Don't use ltp-quota.m4
Browse files Browse the repository at this point in the history
Current quotactl01.c has logic problem. There is no relation between
Q_GETINFO and quota format. The format should depend on quotacheck -F
and kernel config such as CONFIG_QFMT_V1 or CONFIG_QFMT_V2 (most linux
distributions use the v2).

Q_GETINFO cmd was introduced since Linux 2.4.22, we don't need to
check it now. Also, specify quota format to QFMT_VFS_V0 by quotacheck
-F and check CONFIG_QFMT_V2 in kernel config to avoid issue such as linux-test-project#189 [1].
So in quotactl01.c, we don't need to use the macro of ltp-quota.m4.
In quotactl0[2-3].c, we don't need to check very basic header <sys/quota.h>
(it was introdued in glibc since 1997). Remove quota version macro.

Don't remove ltp-quota.m4 because I will rewrite it to detect
if_nextdqblk struct for Q_GETNEXTQUOTA cmd on the coming patch.

[1]linux-test-project#189

Reviewed-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
Signed-off-by: Petr Vorel <pvorel@suse.cz>
  • Loading branch information
xuyang0410 authored and pevik committed Oct 31, 2019
1 parent 58f21cc commit bad28b6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 42 deletions.
47 changes: 17 additions & 30 deletions testcases/kernel/syscalls/quotactl/quotactl01.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,12 @@

#include "tst_test.h"

#if defined(HAVE_QUOTAV2) || defined(HAVE_QUOTAV1)
# include <sys/quota.h>

# if defined(HAVE_QUOTAV2)
# define _LINUX_QUOTA_VERSION 2
# ifndef QFMT_VFS_V0
# define QFMT_VFS_V0 2
# endif
# define QFMT_VFS_V0 2
# define USRPATH MNTPOINT "/aquota.user"
# define GRPPATH MNTPOINT "/aquota.group"
# define FMTID QFMT_VFS_V0
# else
# define _LINUX_QUOTA_VERSION 1
# ifndef QFMT_VFS_OLD
# define QFMT_VFS_OLD 1
# endif
# define USRPATH MNTPOINT "/quota.user"
# define GRPPATH MNTPOINT "/quota.group"
# define FMTID QFMT_VFS_OLD
# endif

# define MNTPOINT "mntpoint"

Expand All @@ -69,14 +55,13 @@ static struct dqblk set_dq = {
.dqb_valid = QIF_BLIMITS
};
static struct dqblk res_dq;
# if defined(HAVE_QUOTAV2)

static struct dqinfo set_qf = {
.dqi_bgrace = 80,
.dqi_valid = IIF_BGRACE
};
static struct dqinfo res_qf;
static int32_t fmt_buf;
# endif

static struct tcase {
int cmd;
Expand All @@ -96,7 +81,7 @@ static struct tcase {
{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"},
# if defined(HAVE_QUOTAV2)

{QCMD(Q_SETINFO, USRQUOTA), &test_id, &set_qf,
NULL, NULL, 0, "set information about quotafile for user"},

Expand All @@ -107,7 +92,7 @@ static struct tcase {
{QCMD(Q_GETFMT, USRQUOTA), &test_id, &fmt_buf,
&fmt_id, &fmt_buf, sizeof(fmt_buf),
"get quota format for user"},
# endif

{QCMD(Q_SYNC, USRQUOTA), &test_id, &res_dq,
NULL, NULL, 0, "update quota usages for user"},

Expand All @@ -123,7 +108,7 @@ static struct tcase {
{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"},
# if defined(HAVE_QUOTAV2)

{QCMD(Q_SETINFO, GRPQUOTA), &test_id, &set_qf,
NULL, NULL, 0, "set information about quotafile for group"},

Expand All @@ -133,7 +118,7 @@ static struct tcase {

{QCMD(Q_GETFMT, GRPQUOTA), &test_id, &fmt_buf,
&fmt_id, &fmt_buf, sizeof(fmt_buf), "get quota format for group"},
# endif

{QCMD(Q_SYNC, GRPQUOTA), &test_id, &res_dq,
NULL, NULL, 0, "update quota usages for group"},

Expand All @@ -143,22 +128,21 @@ static struct tcase {

static void setup(void)
{
const char *const cmd[] = {"quotacheck", "-ug", MNTPOINT, NULL};
const char *const cmd[] = {"quotacheck", "-ugF", "vfsv0", MNTPOINT, NULL};
int ret;


ret = tst_run_cmd(cmd, NULL, NULL, 1);
switch (ret) {
case 0:
break;
case 255:
tst_brk(TCONF, "quotacheck binary not installed");
tst_brk(TBROK, "quotacheck binary not installed");
break;
default:
tst_brk(TBROK, "quotacheck exited with %i", ret);
case 0:
break;
}

test_id = geteuid();

if (access(USRPATH, F_OK) == -1)
tst_brk(TFAIL | TERRNO, "user quotafile didn't exist");

Expand Down Expand Up @@ -190,9 +174,15 @@ static void verify_quota(unsigned int n)
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,
.test = verify_quota,
.tcnt = ARRAY_SIZE(tcases),
.mount_device = 1,
Expand All @@ -202,6 +192,3 @@ static struct tst_test test = {
.setup = setup,
};

#else
TST_TEST_TCONF("This system didn't support quota");
#endif
8 changes: 2 additions & 6 deletions testcases/kernel/syscalls/quotactl/quotactl02.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,14 @@
#include <sys/quota.h>
#include "config.h"

#if defined(HAVE_QUOTAV2) || defined(HAVE_QUOTAV1)
# include <sys/quota.h>
#endif

#if defined(HAVE_XFS_QUOTA)
# include <xfs/xqm.h>
#endif

#include "tst_test.h"
#include "lapi/quotactl.h"

#if defined(HAVE_XFS_QUOTA) && (defined(HAVE_QUOTAV2) || defined(HAVE_QUOTAV1))
#if defined(HAVE_XFS_QUOTA)
static void check_qoff(int, char *);
static void check_qon(int, char *);
static void check_qlim(int, char *);
Expand Down Expand Up @@ -172,5 +168,5 @@ static struct tst_test test = {
.setup = setup,
};
#else
TST_TEST_TCONF("This system didn't support quota or xfs quota");
TST_TEST_TCONF("This system didn't support xfs quota");
#endif
9 changes: 3 additions & 6 deletions testcases/kernel/syscalls/quotactl/quotactl03.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@
#include <stdio.h>
#include <sys/quota.h>
#include "config.h"

#if defined(HAVE_QUOTAV2) || defined(HAVE_QUOTAV1)
# include <sys/quota.h>
#endif
#include <sys/quota.h>

#if defined(HAVE_XFS_QUOTA)
# include <xfs/xqm.h>
Expand All @@ -41,7 +38,7 @@
#include "tst_test.h"
#include "lapi/quotactl.h"

#if defined(HAVE_XFS_QUOTA) && (defined(HAVE_QUOTAV2) || defined(HAVE_QUOTAV1))
#if defined(HAVE_XFS_QUOTA)

static const char mntpoint[] = "mnt_point";
static uint32_t test_id = 0xfffffffc;
Expand Down Expand Up @@ -84,5 +81,5 @@ static struct tst_test test = {
};

#else
TST_TEST_TCONF("This system didn't support quota or xfs quota");
TST_TEST_TCONF("This system didn't support xfs quota");
#endif

0 comments on commit bad28b6

Please sign in to comment.