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