1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2003 Cluster File Systems, Inc.
5 * Author: Lai Siyao <lsy@clusterfs.com>
7 * This file is part of Lustre, http://www.lustre.org/
9 * No redistribution or use is permitted outside of Cluster File Systems, Inc.
11 * A kernel module which tests the fsfilt quotactl API from the OBD setup function.
15 # define EXPORT_SYMTAB
17 #define DEBUG_SUBSYSTEM S_CLASS
19 #include <linux/module.h>
20 #include <linux/init.h>
22 #include <linux/obd_class.h>
23 #include <linux/lustre_fsfilt.h>
24 #include <linux/lustre_mds.h>
25 #include <linux/obd_ost.h>
27 char *test_quotafile[] = {"aquotactl.user", "aquotactl.group"};
30 static int quotactl_test_1(struct obd_device *obd, struct super_block *sb)
32 struct obd_quotactl oqctl;
36 oqctl.qc_cmd = Q_QUOTAON;
37 oqctl.qc_id = QFMT_LDISKFS;
38 oqctl.qc_type = UGQUOTA;
39 rc = fsfilt_quotactl(obd, sb, &oqctl);
41 CERROR("1a: quotactl Q_QUOTAON failed: %d\n", rc);
48 #if 0 /* set/getinfo not supported, this is for cluster-wide quotas */
49 /* Test set/getinfo */
50 static int quotactl_test_2(struct obd_device *obd, struct super_block *sb)
52 struct obd_quotactl oqctl;
56 oqctl.qc_cmd = Q_SETINFO;
57 oqctl.qc_type = USRQUOTA;
58 oqctl.qc_dqinfo.dqi_bgrace = 1616;
59 oqctl.qc_dqinfo.dqi_igrace = 2828;
60 oqctl.qc_dqinfo.dqi_flags = 0;
61 rc = fsfilt_quotactl(obd, sb, &oqctl);
63 CERROR("2a: quotactl Q_SETINFO failed: %d\n", rc);
67 oqctl.qc_cmd = Q_GETINFO;
68 oqctl.qc_type = USRQUOTA;
69 rc = fsfilt_quotactl(obd, sb, &oqctl);
71 CERROR("2b: quotactl Q_GETINFO failed: %d\n", rc);
74 if (oqctl.qc_dqinfo.dqi_bgrace != 1616 ||
75 oqctl.qc_dqinfo.dqi_igrace != 2828 ||
76 oqctl.qc_dqinfo.dqi_flags != 0) {
77 CERROR("2c: quotactl Q_GETINFO get wrong result: %d, %d, %d\n",
78 oqctl.qc_dqinfo.dqi_bgrace,
79 oqctl.qc_dqinfo.dqi_igrace,
80 oqctl.qc_dqinfo.dqi_flags);
88 /* Test set/getquota */
89 static int quotactl_test_3(struct obd_device *obd, struct super_block *sb)
91 struct obd_quotactl oqctl;
95 oqctl.qc_cmd = Q_SETQUOTA;
96 oqctl.qc_type = USRQUOTA;
98 oqctl.qc_dqblk.dqb_bhardlimit = 919;
99 oqctl.qc_dqblk.dqb_bsoftlimit = 818;
100 oqctl.qc_dqblk.dqb_ihardlimit = 616;
101 oqctl.qc_dqblk.dqb_isoftlimit = 515;
102 oqctl.qc_dqblk.dqb_valid = QIF_LIMITS;
103 rc = fsfilt_quotactl(obd, sb, &oqctl);
105 CERROR("3a: quotactl Q_SETQUOTA failed: %d\n", rc);
109 oqctl.qc_cmd = Q_GETQUOTA;
110 oqctl.qc_type = USRQUOTA;
112 rc = fsfilt_quotactl(obd, sb, &oqctl);
114 CERROR("3b: quotactl Q_SETQUOTA failed: %d\n", rc);
117 if (oqctl.qc_dqblk.dqb_bhardlimit != 919 ||
118 oqctl.qc_dqblk.dqb_bsoftlimit != 818 ||
119 oqctl.qc_dqblk.dqb_ihardlimit != 616 ||
120 oqctl.qc_dqblk.dqb_isoftlimit != 515) {
121 CERROR("3c: quotactl Q_GETQUOTA get wrong result:"
122 LPU64", "LPU64", "LPU64", "LPU64"\n",
123 oqctl.qc_dqblk.dqb_bhardlimit,
124 oqctl.qc_dqblk.dqb_bsoftlimit,
125 oqctl.qc_dqblk.dqb_ihardlimit,
126 oqctl.qc_dqblk.dqb_isoftlimit);
130 oqctl.qc_cmd = Q_SETQUOTA;
131 oqctl.qc_type = USRQUOTA;
133 oqctl.qc_dqblk.dqb_curspace = 717;
134 oqctl.qc_dqblk.dqb_curinodes = 414;
135 oqctl.qc_dqblk.dqb_valid = QIF_USAGE;
136 rc = fsfilt_quotactl(obd, sb, &oqctl);
138 CERROR("3d: quotactl Q_SETQUOTA failed: %d\n", rc);
142 oqctl.qc_cmd = Q_GETQUOTA;
143 oqctl.qc_type = USRQUOTA;
145 rc = fsfilt_quotactl(obd, sb, &oqctl);
147 CERROR("3e: quotactl Q_SETQUOTA failed: %d\n", rc);
150 if (oqctl.qc_dqblk.dqb_curspace != 717 ||
151 oqctl.qc_dqblk.dqb_curinodes != 414) {
152 CERROR("3f: quotactl Q_GETQUOTA get wrong result: "
153 LPU64", "LPU64"\n", oqctl.qc_dqblk.dqb_curspace,
154 oqctl.qc_dqblk.dqb_curinodes);
158 oqctl.qc_cmd = Q_SETQUOTA;
159 oqctl.qc_type = USRQUOTA;
160 oqctl.qc_dqblk.dqb_btime = 313;
161 oqctl.qc_dqblk.dqb_itime = 212;
163 oqctl.qc_dqblk.dqb_valid = QIF_TIMES;
164 rc = fsfilt_quotactl(obd, sb, &oqctl);
166 CERROR("3g: quotactl Q_SETQUOTA failed: %d\n", rc);
170 oqctl.qc_cmd = Q_GETQUOTA;
171 oqctl.qc_type = USRQUOTA;
173 rc = fsfilt_quotactl(obd, sb, &oqctl);
175 CERROR("3h: quotactl Q_SETQUOTA failed: %d\n", rc);
178 if (oqctl.qc_dqblk.dqb_btime != 313 ||
179 oqctl.qc_dqblk.dqb_itime != 212) {
180 CERROR("3i: quotactl Q_GETQUOTA get wrong result: "
181 LPU64", "LPU64"\n", oqctl.qc_dqblk.dqb_btime,
182 oqctl.qc_dqblk.dqb_itime);
186 oqctl.qc_cmd = Q_SETQUOTA;
187 oqctl.qc_type = USRQUOTA;
189 oqctl.qc_dqblk.dqb_bhardlimit = 919;
190 oqctl.qc_dqblk.dqb_bsoftlimit = 818;
191 oqctl.qc_dqblk.dqb_curspace = 717;
192 oqctl.qc_dqblk.dqb_ihardlimit = 616;
193 oqctl.qc_dqblk.dqb_isoftlimit = 515;
194 oqctl.qc_dqblk.dqb_curinodes = 414;
195 oqctl.qc_dqblk.dqb_btime = 313;
196 oqctl.qc_dqblk.dqb_itime = 212;
197 oqctl.qc_dqblk.dqb_valid = QIF_ALL;
198 rc = fsfilt_quotactl(obd, sb, &oqctl);
200 CERROR("3j: quotactl Q_SETQUOTA failed: %d\n", rc);
204 oqctl.qc_cmd = Q_GETQUOTA;
205 oqctl.qc_type = USRQUOTA;
207 rc = fsfilt_quotactl(obd, sb, &oqctl);
209 CERROR("3k: quotactl Q_SETQUOTA failed: %d\n", rc);
212 if (oqctl.qc_dqblk.dqb_bhardlimit != 919 ||
213 oqctl.qc_dqblk.dqb_bsoftlimit != 818 ||
214 oqctl.qc_dqblk.dqb_ihardlimit != 616 ||
215 oqctl.qc_dqblk.dqb_isoftlimit != 515 ||
216 oqctl.qc_dqblk.dqb_curspace != 717 ||
217 oqctl.qc_dqblk.dqb_curinodes != 414 ||
218 oqctl.qc_dqblk.dqb_btime != 0 ||
219 oqctl.qc_dqblk.dqb_itime != 0) {
220 CERROR("3l: quotactl Q_GETQUOTA get wrong result:"
221 LPU64", "LPU64", "LPU64", "LPU64", "LPU64", "LPU64", "
222 LPU64", "LPU64"\n", oqctl.qc_dqblk.dqb_bhardlimit,
223 oqctl.qc_dqblk.dqb_bsoftlimit,
224 oqctl.qc_dqblk.dqb_ihardlimit,
225 oqctl.qc_dqblk.dqb_isoftlimit,
226 oqctl.qc_dqblk.dqb_curspace,
227 oqctl.qc_dqblk.dqb_curinodes,
228 oqctl.qc_dqblk.dqb_btime,
229 oqctl.qc_dqblk.dqb_itime);
237 static int quotactl_test_4(struct obd_device *obd, struct super_block *sb)
239 struct obd_quotactl oqctl;
243 oqctl.qc_cmd = Q_QUOTAOFF;
245 oqctl.qc_type = UGQUOTA;
246 rc = fsfilt_quotactl(obd, sb, &oqctl);
248 CERROR("4a: quotactl Q_QUOTAOFF failed: %d\n", rc);
255 /* -------------------------------------------------------------------------
256 * Tests above, boring obd functions below
257 * ------------------------------------------------------------------------- */
258 static int quotactl_run_tests(struct obd_device *obd, struct obd_device *tgt)
260 struct super_block *sb;
261 struct lvfs_run_ctxt saved;
265 if (!strcmp(tgt->obd_type->typ_name, LUSTRE_MDS_NAME))
266 sb = tgt->u.mds.mds_sb;
267 else if (!strcmp(tgt->obd_type->typ_name, "obdfilter"))
268 sb = tgt->u.filter.fo_sb;
270 CERROR("TARGET OBD should be mds or obdfilter\n");
274 push_ctxt(&saved, &tgt->obd_lvfs_ctxt, NULL);
276 rc = quotactl_test_1(tgt, sb);
281 rc = quotactl_test_2(tgt, sb);
286 rc = quotactl_test_3(tgt, sb);
291 quotactl_test_4(tgt, sb);
293 pop_ctxt(&saved, &tgt->obd_lvfs_ctxt, NULL);
298 static int quotactl_test_cleanup(struct obd_device *obd)
300 lprocfs_obd_cleanup(obd);
304 static int quotactl_test_setup(struct obd_device *obd, obd_count len, void *buf)
306 struct lprocfs_static_vars lvars;
307 struct lustre_cfg *lcfg = buf;
308 struct obd_device *tgt;
312 if (lcfg->lcfg_bufcount < 1) {
313 CERROR("requires a mds OBD name\n");
317 tgt = class_name2obd(lustre_cfg_string(lcfg, 1));
318 if (!tgt || !tgt->obd_attached || !tgt->obd_set_up) {
319 CERROR("target device not attached or not set up (%s)\n",
320 lustre_cfg_string(lcfg, 1));
324 lprocfs_init_vars(quotactl_test, &lvars);
325 lprocfs_obd_setup(obd, lvars.obd_vars);
327 rc = quotactl_run_tests(obd, tgt);
329 quotactl_test_cleanup(obd);
334 static struct obd_ops quotactl_obd_ops = {
335 .o_owner = THIS_MODULE,
336 .o_setup = quotactl_test_setup,
337 .o_cleanup = quotactl_test_cleanup,
341 static struct lprocfs_vars lprocfs_obd_vars[] = { {0} };
342 static struct lprocfs_vars lprocfs_module_vars[] = { {0} };
343 LPROCFS_INIT_VARS(quotactl_test, lprocfs_module_vars, lprocfs_obd_vars)
346 static int __init quotactl_test_init(void)
348 struct lprocfs_static_vars lvars;
350 lprocfs_init_vars(quotactl_test, &lvars);
351 return class_register_type("actl_obd_ops, lvars.module_vars,
355 static void __exit quotactl_test_exit(void)
357 class_unregister_type("quotactl_test");
360 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
361 MODULE_DESCRIPTION("quotactl test module");
362 MODULE_LICENSE("GPL");
364 module_init(quotactl_test_init);
365 module_exit(quotactl_test_exit);