xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/quotactl/quotactl02.h (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
4*49cdfc7eSAndroid Build Coastguard Worker  * Author: Yang Xu <[email protected]>
5*49cdfc7eSAndroid Build Coastguard Worker  */
6*49cdfc7eSAndroid Build Coastguard Worker 
7*49cdfc7eSAndroid Build Coastguard Worker #ifndef QUOTACTL02_H
8*49cdfc7eSAndroid Build Coastguard Worker #define QUOTACTL02_H
9*49cdfc7eSAndroid Build Coastguard Worker 
10*49cdfc7eSAndroid Build Coastguard Worker #define _GNU_SOURCE
11*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
12*49cdfc7eSAndroid Build Coastguard Worker #include <unistd.h>
13*49cdfc7eSAndroid Build Coastguard Worker #include <stdio.h>
14*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
15*49cdfc7eSAndroid Build Coastguard Worker #include "quotactl_syscall_var.h"
16*49cdfc7eSAndroid Build Coastguard Worker 
17*49cdfc7eSAndroid Build Coastguard Worker #ifdef HAVE_XFS_XQM_H
18*49cdfc7eSAndroid Build Coastguard Worker # include <xfs/xqm.h>
19*49cdfc7eSAndroid Build Coastguard Worker 
20*49cdfc7eSAndroid Build Coastguard Worker static struct fs_disk_quota set_dquota = {
21*49cdfc7eSAndroid Build Coastguard Worker 	.d_rtb_softlimit = 1000,
22*49cdfc7eSAndroid Build Coastguard Worker 	.d_fieldmask = FS_DQ_RTBSOFT
23*49cdfc7eSAndroid Build Coastguard Worker };
24*49cdfc7eSAndroid Build Coastguard Worker static uint32_t test_id;
25*49cdfc7eSAndroid Build Coastguard Worker static int x_getnextquota_nsup;
26*49cdfc7eSAndroid Build Coastguard Worker static int x_getstatv_nsup;
27*49cdfc7eSAndroid Build Coastguard Worker 
check_support_cmd(int quotatype)28*49cdfc7eSAndroid Build Coastguard Worker static void check_support_cmd(int quotatype)
29*49cdfc7eSAndroid Build Coastguard Worker {
30*49cdfc7eSAndroid Build Coastguard Worker 	struct fs_disk_quota resfs_dquota;
31*49cdfc7eSAndroid Build Coastguard Worker 	struct fs_quota_statv resfs_qstatv = {
32*49cdfc7eSAndroid Build Coastguard Worker 		.qs_version = FS_QSTATV_VERSION1
33*49cdfc7eSAndroid Build Coastguard Worker 	};
34*49cdfc7eSAndroid Build Coastguard Worker 
35*49cdfc7eSAndroid Build Coastguard Worker 	x_getnextquota_nsup = 0;
36*49cdfc7eSAndroid Build Coastguard Worker 	x_getstatv_nsup = 0;
37*49cdfc7eSAndroid Build Coastguard Worker 
38*49cdfc7eSAndroid Build Coastguard Worker 	TEST(do_quotactl(fd, QCMD(Q_XGETNEXTQUOTA, quotatype), tst_device->dev,
39*49cdfc7eSAndroid Build Coastguard Worker 		      test_id, (void *) &resfs_dquota));
40*49cdfc7eSAndroid Build Coastguard Worker 	if (TST_ERR == EINVAL || TST_ERR == ENOSYS)
41*49cdfc7eSAndroid Build Coastguard Worker 		x_getnextquota_nsup = 1;
42*49cdfc7eSAndroid Build Coastguard Worker 
43*49cdfc7eSAndroid Build Coastguard Worker 	TEST(do_quotactl(fd, QCMD(Q_XGETQSTATV, quotatype), tst_device->dev, test_id,
44*49cdfc7eSAndroid Build Coastguard Worker 		      (void *) &resfs_qstatv));
45*49cdfc7eSAndroid Build Coastguard Worker 	if (TST_ERR == EINVAL || TST_ERR == ENOSYS)
46*49cdfc7eSAndroid Build Coastguard Worker 		x_getstatv_nsup = 1;
47*49cdfc7eSAndroid Build Coastguard Worker 
48*49cdfc7eSAndroid Build Coastguard Worker }
49*49cdfc7eSAndroid Build Coastguard Worker 
check_qoff(int subcmd,char * desp,int flag)50*49cdfc7eSAndroid Build Coastguard Worker static void check_qoff(int subcmd, char *desp, int flag)
51*49cdfc7eSAndroid Build Coastguard Worker {
52*49cdfc7eSAndroid Build Coastguard Worker 	struct fs_quota_stat res_qstat;
53*49cdfc7eSAndroid Build Coastguard Worker 
54*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_PASS_SILENT(do_quotactl(fd, subcmd, tst_device->dev, test_id,
55*49cdfc7eSAndroid Build Coastguard Worker 			(void *) &res_qstat), "do_quotactl() to %s", desp);
56*49cdfc7eSAndroid Build Coastguard Worker 	if (!TST_PASS)
57*49cdfc7eSAndroid Build Coastguard Worker 		return;
58*49cdfc7eSAndroid Build Coastguard Worker 
59*49cdfc7eSAndroid Build Coastguard Worker 	if (res_qstat.qs_flags & flag) {
60*49cdfc7eSAndroid Build Coastguard Worker 		tst_res(TFAIL, "xfs quota enforcement was on unexpectedly");
61*49cdfc7eSAndroid Build Coastguard Worker 		return;
62*49cdfc7eSAndroid Build Coastguard Worker 	}
63*49cdfc7eSAndroid Build Coastguard Worker 
64*49cdfc7eSAndroid Build Coastguard Worker 	tst_res(TPASS, "quotactl() succeeded to %s", desp);
65*49cdfc7eSAndroid Build Coastguard Worker }
66*49cdfc7eSAndroid Build Coastguard Worker 
check_qon(int subcmd,char * desp,int flag)67*49cdfc7eSAndroid Build Coastguard Worker static void check_qon(int subcmd, char *desp, int flag)
68*49cdfc7eSAndroid Build Coastguard Worker {
69*49cdfc7eSAndroid Build Coastguard Worker 	struct fs_quota_stat res_qstat;
70*49cdfc7eSAndroid Build Coastguard Worker 
71*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_PASS_SILENT(do_quotactl(fd, subcmd, tst_device->dev, test_id,
72*49cdfc7eSAndroid Build Coastguard Worker 			(void *) &res_qstat), "do_quotactl() to %s", desp);
73*49cdfc7eSAndroid Build Coastguard Worker 	if (!TST_PASS)
74*49cdfc7eSAndroid Build Coastguard Worker 		return;
75*49cdfc7eSAndroid Build Coastguard Worker 
76*49cdfc7eSAndroid Build Coastguard Worker 	if (!(res_qstat.qs_flags & flag)) {
77*49cdfc7eSAndroid Build Coastguard Worker 		tst_res(TFAIL, "xfs quota enforcement was off unexpectedly");
78*49cdfc7eSAndroid Build Coastguard Worker 		return;
79*49cdfc7eSAndroid Build Coastguard Worker 	}
80*49cdfc7eSAndroid Build Coastguard Worker 
81*49cdfc7eSAndroid Build Coastguard Worker 	tst_res(TPASS, "quotactl() succeeded to %s", desp);
82*49cdfc7eSAndroid Build Coastguard Worker }
83*49cdfc7eSAndroid Build Coastguard Worker 
check_qoffv(int subcmd,char * desp,int flag)84*49cdfc7eSAndroid Build Coastguard Worker static void check_qoffv(int subcmd, char *desp, int flag)
85*49cdfc7eSAndroid Build Coastguard Worker {
86*49cdfc7eSAndroid Build Coastguard Worker 	struct fs_quota_statv res_qstatv = {
87*49cdfc7eSAndroid Build Coastguard Worker 		.qs_version = FS_QSTATV_VERSION1,
88*49cdfc7eSAndroid Build Coastguard Worker 	};
89*49cdfc7eSAndroid Build Coastguard Worker 
90*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_PASS_SILENT(do_quotactl(fd, subcmd, tst_device->dev, test_id,
91*49cdfc7eSAndroid Build Coastguard Worker 			(void *) &res_qstatv), "do_quotactl() to %s", desp);
92*49cdfc7eSAndroid Build Coastguard Worker 	if (!TST_PASS)
93*49cdfc7eSAndroid Build Coastguard Worker 		return;
94*49cdfc7eSAndroid Build Coastguard Worker 
95*49cdfc7eSAndroid Build Coastguard Worker 	if (res_qstatv.qs_flags & flag) {
96*49cdfc7eSAndroid Build Coastguard Worker 		tst_res(TFAIL, "xfs quota enforcement was on unexpectedly");
97*49cdfc7eSAndroid Build Coastguard Worker 		return;
98*49cdfc7eSAndroid Build Coastguard Worker 	}
99*49cdfc7eSAndroid Build Coastguard Worker 
100*49cdfc7eSAndroid Build Coastguard Worker 	tst_res(TPASS, "quotactl() succeeded to %s", desp);
101*49cdfc7eSAndroid Build Coastguard Worker }
102*49cdfc7eSAndroid Build Coastguard Worker 
check_qonv(int subcmd,char * desp,int flag)103*49cdfc7eSAndroid Build Coastguard Worker static void check_qonv(int subcmd, char *desp, int flag)
104*49cdfc7eSAndroid Build Coastguard Worker {
105*49cdfc7eSAndroid Build Coastguard Worker 	struct fs_quota_statv res_qstatv = {
106*49cdfc7eSAndroid Build Coastguard Worker 		.qs_version = FS_QSTATV_VERSION1
107*49cdfc7eSAndroid Build Coastguard Worker 	};
108*49cdfc7eSAndroid Build Coastguard Worker 
109*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_PASS_SILENT(do_quotactl(fd, subcmd, tst_device->dev, test_id,
110*49cdfc7eSAndroid Build Coastguard Worker 			(void *) &res_qstatv), "do_quotactl() to %s", desp);
111*49cdfc7eSAndroid Build Coastguard Worker 	if (!TST_PASS)
112*49cdfc7eSAndroid Build Coastguard Worker 		return;
113*49cdfc7eSAndroid Build Coastguard Worker 
114*49cdfc7eSAndroid Build Coastguard Worker 	if (!(res_qstatv.qs_flags & flag)) {
115*49cdfc7eSAndroid Build Coastguard Worker 		tst_res(TFAIL, "xfs quota enforcement was off unexpectedly");
116*49cdfc7eSAndroid Build Coastguard Worker 		return;
117*49cdfc7eSAndroid Build Coastguard Worker 	}
118*49cdfc7eSAndroid Build Coastguard Worker 
119*49cdfc7eSAndroid Build Coastguard Worker 	tst_res(TPASS, "quotactl() succeeded to %s", desp);
120*49cdfc7eSAndroid Build Coastguard Worker }
121*49cdfc7eSAndroid Build Coastguard Worker 
check_qlim(int subcmd,char * desp)122*49cdfc7eSAndroid Build Coastguard Worker static void check_qlim(int subcmd, char *desp)
123*49cdfc7eSAndroid Build Coastguard Worker {
124*49cdfc7eSAndroid Build Coastguard Worker 	static struct fs_disk_quota res_dquota;
125*49cdfc7eSAndroid Build Coastguard Worker 
126*49cdfc7eSAndroid Build Coastguard Worker 	res_dquota.d_rtb_softlimit = 0;
127*49cdfc7eSAndroid Build Coastguard Worker 
128*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_PASS_SILENT(do_quotactl(fd, subcmd, tst_device->dev, test_id,
129*49cdfc7eSAndroid Build Coastguard Worker 			(void *) &res_dquota), "do_quotactl() to %s", desp);
130*49cdfc7eSAndroid Build Coastguard Worker 	if (!TST_PASS)
131*49cdfc7eSAndroid Build Coastguard Worker 		return;
132*49cdfc7eSAndroid Build Coastguard Worker 
133*49cdfc7eSAndroid Build Coastguard Worker 	if (res_dquota.d_id != test_id) {
134*49cdfc7eSAndroid Build Coastguard Worker 		tst_res(TFAIL, "quotactl() got unexpected user id %u, expected %u",
135*49cdfc7eSAndroid Build Coastguard Worker 			res_dquota.d_id, test_id);
136*49cdfc7eSAndroid Build Coastguard Worker 		return;
137*49cdfc7eSAndroid Build Coastguard Worker 	}
138*49cdfc7eSAndroid Build Coastguard Worker 
139*49cdfc7eSAndroid Build Coastguard Worker 	if (res_dquota.d_rtb_hardlimit != set_dquota.d_rtb_hardlimit) {
140*49cdfc7eSAndroid Build Coastguard Worker 		tst_res(TFAIL, "quotactl() got unexpected rtb soft limit %llu, expected %llu",
141*49cdfc7eSAndroid Build Coastguard Worker 				res_dquota.d_rtb_hardlimit, set_dquota.d_rtb_hardlimit);
142*49cdfc7eSAndroid Build Coastguard Worker 		return;
143*49cdfc7eSAndroid Build Coastguard Worker 	}
144*49cdfc7eSAndroid Build Coastguard Worker 
145*49cdfc7eSAndroid Build Coastguard Worker 	tst_res(TPASS, "quotactl() succeeded to set and use %s to get xfs disk quota limits",
146*49cdfc7eSAndroid Build Coastguard Worker 			desp);
147*49cdfc7eSAndroid Build Coastguard Worker }
148*49cdfc7eSAndroid Build Coastguard Worker #endif /* HAVE_XFS_XQM_H */
149*49cdfc7eSAndroid Build Coastguard Worker #endif /* QUOTACTL02_H */
150