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