• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
4  * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
5  *
6  * This is a regresstion test for kernel commit 3dd4d40b4208
7  * ("xfs: Sanity check flags of Q_XQUOTARM call").
8  */
9 
10 #include "config.h"
11 #include <errno.h>
12 #include <unistd.h>
13 #include <stdio.h>
14 #include <sys/quota.h>
15 #include "lapi/quotactl.h"
16 #include "tst_test.h"
17 
18 #ifdef HAVE_XFS_XQM_H
19 # include <xfs/xqm.h>
20 
21 #define MNTPOINT    "mntpoint"
22 
23 static uint32_t qflag_acct = XFS_QUOTA_UDQ_ACCT;
24 static unsigned int valid_type = XFS_USER_QUOTA;
25 /* Include a valid quota type to avoid other EINVAL error */
26 static unsigned int invalid_type = XFS_GROUP_QUOTA << 1 | XFS_USER_QUOTA;
27 
verify_quota(void)28 static void verify_quota(void)
29 {
30 	TEST(quotactl(QCMD(Q_XQUOTARM, USRQUOTA), tst_device->dev, 0, (void *)&invalid_type));
31 	if (TST_ERR == EINVAL)
32 		tst_res(TPASS, "Q_XQUOTARM has quota type check");
33 	else
34 		tst_res(TFAIL, "Q_XQUOTARM doesn't have quota type check");
35 }
36 
setup(void)37 static void setup(void)
38 {
39 	TEST(quotactl(QCMD(Q_XQUOTAOFF, USRQUOTA), tst_device->dev, 0, (void *)&qflag_acct));
40 	if (TST_RET == -1)
41 		tst_brk(TBROK | TTERRNO, "quotactl with Q_XQUOTAOFF failed");
42 
43 	TEST(quotactl(QCMD(Q_XQUOTARM, USRQUOTA), tst_device->dev, 0, (void *)&valid_type));
44 	if (TST_ERR == EINVAL)
45 		tst_brk(TCONF, "current system doesn't support Q_XQUOTARM, skip it");
46 }
47 
48 static struct tst_test test = {
49 	.setup = setup,
50 	.needs_root = 1,
51 	.needs_kconfigs = (const char *[]) {
52 		"CONFIG_XFS_QUOTA",
53 		NULL
54 	},
55 	.test_all = verify_quota,
56 	.mount_device = 1,
57 	.dev_fs_type = "xfs",
58 	.mnt_data = "usrquota",
59 	.mntpoint = MNTPOINT,
60 	.tags = (const struct tst_tag[]) {
61 		{"linux-git", "3dd4d40b4208"},
62 		{}
63 	}
64 };
65 #else
66 	TST_TEST_TCONF("System doesn't have <xfs/xqm.h>");
67 #endif
68