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
7 #ifndef QUOTACTL02_H
8 #define QUOTACTL02_H
9
10 #define _GNU_SOURCE
11 #include "config.h"
12 #include <errno.h>
13 #include <unistd.h>
14 #include <stdio.h>
15 #include "tst_test.h"
16 #include "lapi/quotactl.h"
17
18 #ifdef HAVE_XFS_XQM_H
19 # include <xfs/xqm.h>
20
21 static struct fs_disk_quota set_dquota = {
22 .d_rtb_softlimit = 1000,
23 .d_fieldmask = FS_DQ_RTBSOFT
24 };
25 static uint32_t test_id;
26 static int x_getnextquota_nsup;
27 static int x_getstatv_nsup;
28 static const char mntpoint[] = "mnt_point";
29
check_support_cmd(int quotatype)30 void check_support_cmd(int quotatype)
31 {
32 struct fs_disk_quota resfs_dquota;
33 struct fs_quota_statv resfs_qstatv = {
34 .qs_version = FS_QSTATV_VERSION1
35 };
36
37 x_getnextquota_nsup = 0;
38 x_getstatv_nsup = 0;
39
40 TEST(quotactl(QCMD(Q_XGETNEXTQUOTA, quotatype), tst_device->dev,
41 test_id, (void *) &resfs_dquota));
42 if (TST_ERR == EINVAL || TST_ERR == ENOSYS)
43 x_getnextquota_nsup = 1;
44
45 TEST(quotactl(QCMD(Q_XGETQSTATV, quotatype), tst_device->dev, test_id,
46 (void *) &resfs_qstatv));
47 if (TST_ERR == EINVAL || TST_ERR == ENOSYS)
48 x_getstatv_nsup = 1;
49
50 }
check_qoff(int subcmd,char * desp,int flag)51 void check_qoff(int subcmd, char *desp, int flag)
52 {
53 int res;
54 struct fs_quota_stat res_qstat;
55
56 res = quotactl(subcmd, tst_device->dev, test_id, (void *) &res_qstat);
57 if (res == -1) {
58 tst_res(TFAIL | TERRNO,
59 "quotactl() failed to get xfs quota off status");
60 return;
61 }
62
63 if (res_qstat.qs_flags & flag) {
64 tst_res(TFAIL, "xfs quota enforcement was on unexpectedly");
65 return;
66 }
67
68 tst_res(TPASS, "quotactl() succeeded to %s", desp);
69 }
70
check_qon(int subcmd,char * desp,int flag)71 void check_qon(int subcmd, char *desp, int flag)
72 {
73 int res;
74 struct fs_quota_stat res_qstat;
75
76 res = quotactl(subcmd, tst_device->dev, test_id, (void *) &res_qstat);
77 if (res == -1) {
78 tst_res(TFAIL | TERRNO,
79 "quotactl() failed to get xfs quota on status");
80 return;
81 }
82
83 if (!(res_qstat.qs_flags & flag)) {
84 tst_res(TFAIL, "xfs quota enforcement was off unexpectedly");
85 return;
86 }
87
88 tst_res(TPASS, "quotactl() succeeded to %s", desp);
89 }
90
check_qoffv(int subcmd,char * desp,int flag)91 void check_qoffv(int subcmd, char *desp, int flag)
92 {
93 int res;
94 struct fs_quota_statv res_qstatv = {
95 .qs_version = FS_QSTATV_VERSION1,
96 };
97
98 res = quotactl(subcmd, tst_device->dev, test_id, (void *) &res_qstatv);
99 if (res == -1) {
100 tst_res(TFAIL | TERRNO,
101 "quotactl() failed to get xfs quota off stav");
102 return;
103 }
104
105 if (res_qstatv.qs_flags & flag) {
106 tst_res(TFAIL, "xfs quota enforcement was on unexpectedly");
107 return;
108 }
109
110 tst_res(TPASS, "quotactl() succeeded to %s", desp);
111 }
112
check_qonv(int subcmd,char * desp,int flag)113 void check_qonv(int subcmd, char *desp, int flag)
114 {
115 int res;
116 struct fs_quota_statv res_qstatv = {
117 .qs_version = FS_QSTATV_VERSION1
118 };
119
120 res = quotactl(subcmd, tst_device->dev, test_id, (void *) &res_qstatv);
121 if (res == -1) {
122 tst_res(TFAIL | TERRNO,
123 "quotactl() failed to get xfs quota on statv");
124 return;
125 }
126
127 if (!(res_qstatv.qs_flags & flag)) {
128 tst_res(TFAIL, "xfs quota enforcement was off unexpectedly");
129 return;
130 }
131
132 tst_res(TPASS, "quotactl() succeeded to %s", desp);
133 }
134
check_qlim(int subcmd,char * desp)135 void check_qlim(int subcmd, char *desp)
136 {
137 int res;
138 static struct fs_disk_quota res_dquota;
139
140 res_dquota.d_rtb_softlimit = 0;
141
142 res = quotactl(subcmd, tst_device->dev, test_id, (void *) &res_dquota);
143 if (res == -1) {
144 tst_res(TFAIL | TERRNO,
145 "quotactl() failed to get xfs disk quota limits");
146 return;
147 }
148
149 if (res_dquota.d_id != test_id) {
150 tst_res(TFAIL, "quotactl() got unexpected user id %u, expected %u",
151 res_dquota.d_id, test_id);
152 return;
153 }
154
155 if (res_dquota.d_rtb_hardlimit != set_dquota.d_rtb_hardlimit) {
156 tst_res(TFAIL, "quotactl() got unexpected rtb soft limit %llu, expected %llu",
157 res_dquota.d_rtb_hardlimit, set_dquota.d_rtb_hardlimit);
158 return;
159 }
160
161 tst_res(TPASS, "quotactl() succeeded to set and use %s to get xfs disk quota limits",
162 desp);
163 }
164 #endif /* HAVE_XFS_XQM_H */
165 #endif /* QUOTACTL02_H */
166