-
Notifications
You must be signed in to change notification settings - Fork 998
/
quotactl02.c
182 lines (153 loc) · 4.5 KB
/
quotactl02.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
* Copyright (c) 2013 Fujitsu Ltd.
* Author: DAN LI <li.dan@cn.fujitsu.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it would be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/*
* Test Name: quotactl02
*
* Description:
* This testcase checks basic flags of quotactl(2) for an XFS file system:
* 1) quotactl(2) succeeds to turn off xfs quota and get xfs quota off status.
* 2) quotactl(2) succeeds to turn on xfs quota and get xfs quota on status.
* 3) quotactl(2) succeeds to set and get xfs disk quota limits.
*/
#define _GNU_SOURCE
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
#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"
#if defined(HAVE_XFS_QUOTA) && (defined(HAVE_QUOTAV2) || defined(HAVE_QUOTAV1))
static void check_qoff(char *);
static void check_qon(char *);
static void check_qlim(char *);
static int test_id;
static int mount_flag;
static struct fs_disk_quota set_dquota = {
.d_rtb_softlimit = 1000,
.d_fieldmask = FS_DQ_RTBSOFT
};
static unsigned short qflag = XFS_QUOTA_UDQ_ENFD;
static const char mntpoint[] = "mnt_point";
static struct t_case {
int cmd;
void *addr;
void (*func_check)();
char *des;
} tcases[] = {
{QCMD(Q_XQUOTAOFF, USRQUOTA), &qflag, check_qoff,
"turn off xfs quota and get xfs quota off status"},
{QCMD(Q_XQUOTAON, USRQUOTA), &qflag, check_qon,
"turn on xfs quota and get xfs quota on status"},
{QCMD(Q_XSETQLIM, USRQUOTA), &set_dquota, check_qlim,
"set and get xfs disk quota limits"},
};
static void check_qoff(char *desp)
{
int res;
struct fs_quota_stat res_qstat;
res = quotactl(QCMD(Q_XGETQSTAT, USRQUOTA), tst_device->dev,
test_id, (void*) &res_qstat);
if (res == -1) {
tst_res(TFAIL | TERRNO,
"quotactl() failed to get xfs quota off status");
return;
}
if (res_qstat.qs_flags & XFS_QUOTA_UDQ_ENFD) {
tst_res(TFAIL, "xfs quota enforcement was on unexpectedly");
return;
}
tst_res(TPASS, "quoactl() succeeded to %s", desp);
}
static void check_qon(char *desp)
{
int res;
struct fs_quota_stat res_qstat;
res = quotactl(QCMD(Q_XGETQSTAT, USRQUOTA), tst_device->dev,
test_id, (void*) &res_qstat);
if (res == -1) {
tst_res(TFAIL | TERRNO,
"quotactl() failed to get xfs quota on status");
return;
}
if (!(res_qstat.qs_flags & XFS_QUOTA_UDQ_ENFD)) {
tst_res(TFAIL, "xfs quota enforcement was off unexpectedly");
return;
}
tst_res(TPASS, "quoactl() succeeded to %s", desp);
}
static void check_qlim(char *desp)
{
int res;
static struct fs_disk_quota res_dquota;
res_dquota.d_rtb_softlimit = 0;
res = quotactl(QCMD(Q_XGETQUOTA, USRQUOTA), tst_device->dev,
test_id, (void*) &res_dquota);
if (res == -1) {
tst_res(TFAIL | TERRNO,
"quotactl() failed to get xfs disk quota limits");
return;
}
if (res_dquota.d_rtb_hardlimit != set_dquota.d_rtb_hardlimit) {
tst_res(TFAIL, "quotactl() got unexpected rtb soft limit %llu,"
" expected %llu", res_dquota.d_rtb_hardlimit,
set_dquota.d_rtb_hardlimit);
return;
}
tst_res(TPASS, "quoactl() succeeded to %s", desp);
}
static void setup(void)
{
SAFE_MKDIR(mntpoint, 0755);
SAFE_MKFS(tst_device->dev, "xfs", NULL, NULL);
SAFE_MOUNT(tst_device->dev, mntpoint, "xfs", 0, "usrquota");
mount_flag = 1;
test_id = geteuid();
}
static void cleanup(void)
{
if (mount_flag && tst_umount(mntpoint) < 0)
tst_res(TWARN | TERRNO, "umount() failed");
}
static void verify_quota(unsigned int n)
{
struct t_case *tc = &tcases[n];
TEST(quotactl(tc->cmd, tst_device->dev, test_id, tc->addr));
if (TEST_RETURN == -1) {
tst_res(TFAIL | TTERRNO, "quotactl() failed to %s", tc->des);
return;
}
tc->func_check(tc->des);
}
static struct tst_test test = {
.tid = "quotactl02",
.needs_tmpdir = 1,
.needs_root = 1,
.test = verify_quota,
.tcnt = ARRAY_SIZE(tcases),
.needs_device = 1,
.setup = setup,
.cleanup = cleanup
};
#else
TST_TEST_TCONF("This system didn't support quota or xfs quota");
#endif