1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2005 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 <obd_class.h>
23 #include <lustre_fsfilt.h>
24 #include <lustre_mds.h>
27 static struct obd_quotactl oqctl;
30 static int quotactl_test_1(struct obd_device *obd, struct super_block *sb)
35 oqctl.qc_cmd = Q_QUOTAON;
36 oqctl.qc_id = QFMT_LDISKFS;
37 oqctl.qc_type = UGQUOTA;
38 rc = fsfilt_quotactl(obd, sb, &oqctl);
40 CERROR("1a: quotactl Q_QUOTAON failed: %d\n", rc);
44 #if 0 /* set/getinfo not supported, this is for cluster-wide quotas */
45 /* Test set/getinfo */
46 static int quotactl_test_2(struct obd_device *obd, struct super_block *sb)
48 struct obd_quotactl oqctl;
52 oqctl.qc_cmd = Q_SETINFO;
53 oqctl.qc_type = USRQUOTA;
54 oqctl.qc_dqinfo.dqi_bgrace = 1616;
55 oqctl.qc_dqinfo.dqi_igrace = 2828;
56 oqctl.qc_dqinfo.dqi_flags = 0;
57 rc = fsfilt_quotactl(obd, sb, &oqctl);
59 CERROR("2a: quotactl Q_SETINFO failed: %d\n", rc);
63 oqctl.qc_cmd = Q_GETINFO;
64 oqctl.qc_type = USRQUOTA;
65 rc = fsfilt_quotactl(obd, sb, &oqctl);
67 CERROR("2b: quotactl Q_GETINFO failed: %d\n", rc);
70 if (oqctl.qc_dqinfo.dqi_bgrace != 1616 ||
71 oqctl.qc_dqinfo.dqi_igrace != 2828 ||
72 oqctl.qc_dqinfo.dqi_flags != 0) {
73 CERROR("2c: quotactl Q_GETINFO get wrong result: %d, %d, %d\n",
74 oqctl.qc_dqinfo.dqi_bgrace,
75 oqctl.qc_dqinfo.dqi_igrace,
76 oqctl.qc_dqinfo.dqi_flags);
84 /* Test set/getquota */
85 static int quotactl_test_3(struct obd_device *obd, struct super_block *sb)
90 oqctl.qc_cmd = Q_SETQUOTA;
91 oqctl.qc_type = USRQUOTA;
93 oqctl.qc_dqblk.dqb_bhardlimit = 919;
94 oqctl.qc_dqblk.dqb_bsoftlimit = 818;
95 oqctl.qc_dqblk.dqb_ihardlimit = 616;
96 oqctl.qc_dqblk.dqb_isoftlimit = 515;
97 oqctl.qc_dqblk.dqb_valid = QIF_LIMITS;
98 rc = fsfilt_quotactl(obd, sb, &oqctl);
100 CERROR("3a: quotactl Q_SETQUOTA failed: %d\n", rc);
104 oqctl.qc_cmd = Q_GETQUOTA;
105 oqctl.qc_type = USRQUOTA;
107 rc = fsfilt_quotactl(obd, sb, &oqctl);
109 CERROR("3b: quotactl Q_SETQUOTA failed: %d\n", rc);
112 if (oqctl.qc_dqblk.dqb_bhardlimit != 919 ||
113 oqctl.qc_dqblk.dqb_bsoftlimit != 818 ||
114 oqctl.qc_dqblk.dqb_ihardlimit != 616 ||
115 oqctl.qc_dqblk.dqb_isoftlimit != 515) {
116 CERROR("3c: quotactl Q_GETQUOTA get wrong result:"
117 LPU64", "LPU64", "LPU64", "LPU64"\n",
118 oqctl.qc_dqblk.dqb_bhardlimit,
119 oqctl.qc_dqblk.dqb_bsoftlimit,
120 oqctl.qc_dqblk.dqb_ihardlimit,
121 oqctl.qc_dqblk.dqb_isoftlimit);
125 oqctl.qc_cmd = Q_SETQUOTA;
126 oqctl.qc_type = USRQUOTA;
128 oqctl.qc_dqblk.dqb_curspace = 717;
129 oqctl.qc_dqblk.dqb_curinodes = 414;
130 oqctl.qc_dqblk.dqb_valid = QIF_USAGE;
131 rc = fsfilt_quotactl(obd, sb, &oqctl);
133 CERROR("3d: quotactl Q_SETQUOTA failed: %d\n", rc);
137 oqctl.qc_cmd = Q_GETQUOTA;
138 oqctl.qc_type = USRQUOTA;
140 rc = fsfilt_quotactl(obd, sb, &oqctl);
142 CERROR("3e: quotactl Q_SETQUOTA failed: %d\n", rc);
145 if (oqctl.qc_dqblk.dqb_curspace != 717 ||
146 oqctl.qc_dqblk.dqb_curinodes != 414) {
147 CERROR("3f: quotactl Q_GETQUOTA get wrong result: "
148 LPU64", "LPU64"\n", oqctl.qc_dqblk.dqb_curspace,
149 oqctl.qc_dqblk.dqb_curinodes);
153 oqctl.qc_cmd = Q_SETQUOTA;
154 oqctl.qc_type = USRQUOTA;
155 oqctl.qc_dqblk.dqb_btime = 313;
156 oqctl.qc_dqblk.dqb_itime = 212;
158 oqctl.qc_dqblk.dqb_valid = QIF_TIMES;
159 rc = fsfilt_quotactl(obd, sb, &oqctl);
161 CERROR("3g: quotactl Q_SETQUOTA failed: %d\n", rc);
165 oqctl.qc_cmd = Q_GETQUOTA;
166 oqctl.qc_type = USRQUOTA;
168 rc = fsfilt_quotactl(obd, sb, &oqctl);
170 CERROR("3h: quotactl Q_SETQUOTA failed: %d\n", rc);
173 if (oqctl.qc_dqblk.dqb_btime != 313 ||
174 oqctl.qc_dqblk.dqb_itime != 212) {
175 CERROR("3i: quotactl Q_GETQUOTA get wrong result: "
176 LPU64", "LPU64"\n", oqctl.qc_dqblk.dqb_btime,
177 oqctl.qc_dqblk.dqb_itime);
181 oqctl.qc_cmd = Q_SETQUOTA;
182 oqctl.qc_type = USRQUOTA;
184 oqctl.qc_dqblk.dqb_bhardlimit = 919;
185 oqctl.qc_dqblk.dqb_bsoftlimit = 818;
186 oqctl.qc_dqblk.dqb_curspace = 717;
187 oqctl.qc_dqblk.dqb_ihardlimit = 616;
188 oqctl.qc_dqblk.dqb_isoftlimit = 515;
189 oqctl.qc_dqblk.dqb_curinodes = 414;
190 oqctl.qc_dqblk.dqb_btime = 313;
191 oqctl.qc_dqblk.dqb_itime = 212;
192 oqctl.qc_dqblk.dqb_valid = QIF_ALL;
193 rc = fsfilt_quotactl(obd, sb, &oqctl);
195 CERROR("3j: quotactl Q_SETQUOTA failed: %d\n", rc);
199 oqctl.qc_cmd = Q_GETQUOTA;
200 oqctl.qc_type = USRQUOTA;
202 rc = fsfilt_quotactl(obd, sb, &oqctl);
204 CERROR("3k: quotactl Q_SETQUOTA failed: %d\n", rc);
207 if (oqctl.qc_dqblk.dqb_bhardlimit != 919 ||
208 oqctl.qc_dqblk.dqb_bsoftlimit != 818 ||
209 oqctl.qc_dqblk.dqb_ihardlimit != 616 ||
210 oqctl.qc_dqblk.dqb_isoftlimit != 515 ||
211 oqctl.qc_dqblk.dqb_curspace != 717 ||
212 oqctl.qc_dqblk.dqb_curinodes != 414 ||
213 oqctl.qc_dqblk.dqb_btime != 0 ||
214 oqctl.qc_dqblk.dqb_itime != 0) {
215 CERROR("3l: quotactl Q_GETQUOTA get wrong result:"
216 LPU64", "LPU64", "LPU64", "LPU64", "LPU64", "LPU64", "
217 LPU64", "LPU64"\n", oqctl.qc_dqblk.dqb_bhardlimit,
218 oqctl.qc_dqblk.dqb_bsoftlimit,
219 oqctl.qc_dqblk.dqb_ihardlimit,
220 oqctl.qc_dqblk.dqb_isoftlimit,
221 oqctl.qc_dqblk.dqb_curspace,
222 oqctl.qc_dqblk.dqb_curinodes,
223 oqctl.qc_dqblk.dqb_btime,
224 oqctl.qc_dqblk.dqb_itime);
232 static int quotactl_test_4(struct obd_device *obd, struct super_block *sb)
237 oqctl.qc_cmd = Q_QUOTAOFF;
239 oqctl.qc_type = UGQUOTA;
240 rc = fsfilt_quotactl(obd, sb, &oqctl);
242 CERROR("4a: quotactl Q_QUOTAOFF failed: %d\n", rc);
249 /* -------------------------------------------------------------------------
250 * Tests above, boring obd functions below
251 * ------------------------------------------------------------------------- */
252 static int quotactl_run_tests(struct obd_device *obd, struct obd_device *tgt)
254 struct super_block *sb;
255 struct lvfs_run_ctxt saved;
259 if (strcmp(tgt->obd_type->typ_name, LUSTRE_MDS_NAME) &&
260 !strcmp(tgt->obd_type->typ_name, "obdfilter")) {
261 CERROR("TARGET OBD should be mds or ost\n");
265 sb = tgt->u.obt.obt_sb;
267 push_ctxt(&saved, &tgt->obd_lvfs_ctxt, NULL);
269 rc = quotactl_test_1(tgt, sb);
274 rc = quotactl_test_2(tgt, sb);
279 rc = quotactl_test_3(tgt, sb);
284 quotactl_test_4(tgt, sb);
286 pop_ctxt(&saved, &tgt->obd_lvfs_ctxt, NULL);
292 static struct lprocfs_vars lprocfs_quotactl_test_obd_vars[] = { {0} };
293 static struct lprocfs_vars lprocfs_quotactl_test_module_vars[] = { {0} };
295 void lprocfs_quotactl_test_init_vars(struct lprocfs_static_vars *lvars)
297 lvars->module_vars = lprocfs_quotactl_test_module_vars;
298 lvars->obd_vars = lprocfs_quotactl_test_obd_vars;
302 static int quotactl_test_cleanup(struct obd_device *obd)
304 lprocfs_obd_cleanup(obd);
308 static int quotactl_test_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
310 struct lprocfs_static_vars lvars = { 0 };
311 struct obd_device *tgt;
315 if (lcfg->lcfg_bufcount < 1) {
316 CERROR("requires a mds OBD name\n");
320 tgt = class_name2obd(lustre_cfg_string(lcfg, 1));
321 if (!tgt || !tgt->obd_attached || !tgt->obd_set_up) {
322 CERROR("target device not attached or not set up (%s)\n",
323 lustre_cfg_string(lcfg, 1));
327 lprocfs_quotactl_test_init_vars(&lvars);
328 lprocfs_obd_setup(obd, lvars.obd_vars);
330 rc = quotactl_run_tests(obd, tgt);
332 quotactl_test_cleanup(obd);
337 static struct obd_ops quotactl_obd_ops = {
338 .o_owner = THIS_MODULE,
339 .o_setup = quotactl_test_setup,
340 .o_cleanup = quotactl_test_cleanup,
343 static int __init quotactl_test_init(void)
345 struct lprocfs_static_vars lvars = { 0 };
347 lprocfs_quotactl_test_init_vars(&lvars);
348 return class_register_type("actl_obd_ops, NULL, lvars.module_vars,
349 "quotactl_test", NULL);
352 static void __exit quotactl_test_exit(void)
354 class_unregister_type("quotactl_test");
357 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
358 MODULE_DESCRIPTION("quotactl test module");
359 MODULE_LICENSE("GPL");
361 module_init(quotactl_test_init);
362 module_exit(quotactl_test_exit);