Whamcloud - gitweb
7e607f9f851f5b2cc21a37f00feadb6d98178742
[fs/lustre-release.git] / lustre / quota / lproc_quota.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #define DEBUG_SUBSYSTEM S_LQUOTA
38
39 #include <linux/version.h>
40 #include <lprocfs_status.h>
41 #include <obd.h>
42 #include <linux/seq_file.h>
43 #include <lustre_fsfilt.h>
44
45 #include "quota_internal.h"
46
47 #ifdef HAVE_QUOTA_SUPPORT
48
49 #ifdef LPROCFS
50 int lprocfs_quota_rd_bunit(char *page, char **start, off_t off, int count,
51                            int *eof, void *data)
52 {
53         struct obd_device *obd = (struct obd_device *)data;
54         LASSERT(obd != NULL);
55
56         return snprintf(page, count, "%lu\n",
57                         obd->u.obt.obt_qctxt.lqc_bunit_sz);
58 }
59 EXPORT_SYMBOL(lprocfs_quota_rd_bunit);
60
61 int lprocfs_quota_wr_bunit(struct file *file, const char *buffer,
62                            unsigned long count, void *data)
63 {
64         struct obd_device *obd = (struct obd_device *)data;
65         int val, rc;
66         LASSERT(obd != NULL);
67
68         rc = lprocfs_write_helper(buffer, count, &val);
69         if (rc)
70                 return rc;
71
72         if (val % QUOTABLOCK_SIZE ||
73             val <= obd->u.obt.obt_qctxt.lqc_btune_sz)
74                 return -EINVAL;
75
76         obd->u.obt.obt_qctxt.lqc_bunit_sz = val;
77         return count;
78 }
79 EXPORT_SYMBOL(lprocfs_quota_wr_bunit);
80
81 int lprocfs_quota_rd_btune(char *page, char **start, off_t off, int count,
82                            int *eof, void *data)
83 {
84         struct obd_device *obd = (struct obd_device *)data;
85         LASSERT(obd != NULL);
86
87         return snprintf(page, count, "%lu\n",
88                         obd->u.obt.obt_qctxt.lqc_btune_sz);
89 }
90 EXPORT_SYMBOL(lprocfs_quota_rd_btune);
91
92 int lprocfs_quota_wr_btune(struct file *file, const char *buffer,
93                            unsigned long count, void *data)
94 {
95         struct obd_device *obd = (struct obd_device *)data;
96         int val, rc;
97         LASSERT(obd != NULL);
98
99         rc = lprocfs_write_helper(buffer, count, &val);
100         if (rc)
101                 return rc;
102
103         if (val <= QUOTABLOCK_SIZE * MIN_QLIMIT || val % QUOTABLOCK_SIZE ||
104             val >= obd->u.obt.obt_qctxt.lqc_bunit_sz)
105                 return -EINVAL;
106
107         obd->u.obt.obt_qctxt.lqc_btune_sz = val;
108         return count;
109 }
110 EXPORT_SYMBOL(lprocfs_quota_wr_btune);
111
112 int lprocfs_quota_rd_iunit(char *page, char **start, off_t off, int count,
113                            int *eof, void *data)
114 {
115         struct obd_device *obd = (struct obd_device *)data;
116         LASSERT(obd != NULL);
117
118         return snprintf(page, count, "%lu\n",
119                         obd->u.obt.obt_qctxt.lqc_iunit_sz);
120 }
121 EXPORT_SYMBOL(lprocfs_quota_rd_iunit);
122
123 int lprocfs_quota_wr_iunit(struct file *file, const char *buffer,
124                            unsigned long count, void *data)
125 {
126         struct obd_device *obd = (struct obd_device *)data;
127         int val, rc;
128         LASSERT(obd != NULL);
129
130         rc = lprocfs_write_helper(buffer, count, &val);
131         if (rc)
132                 return rc;
133
134         if (val <= obd->u.obt.obt_qctxt.lqc_itune_sz)
135                 return -EINVAL;
136
137         obd->u.obt.obt_qctxt.lqc_iunit_sz = val;
138         return count;
139 }
140 EXPORT_SYMBOL(lprocfs_quota_wr_iunit);
141
142 int lprocfs_quota_rd_itune(char *page, char **start, off_t off, int count,
143                            int *eof, void *data)
144 {
145         struct obd_device *obd = (struct obd_device *)data;
146         LASSERT(obd != NULL);
147
148         return snprintf(page, count, "%lu\n",
149                         obd->u.obt.obt_qctxt.lqc_itune_sz);
150 }
151 EXPORT_SYMBOL(lprocfs_quota_rd_itune);
152
153 int lprocfs_quota_wr_itune(struct file *file, const char *buffer,
154                            unsigned long count, void *data)
155 {
156         struct obd_device *obd = (struct obd_device *)data;
157         int val, rc;
158         LASSERT(obd != NULL);
159
160         rc = lprocfs_write_helper(buffer, count, &val);
161         if (rc)
162                 return rc;
163
164         if (val <= MIN_QLIMIT ||
165             val >= obd->u.obt.obt_qctxt.lqc_iunit_sz)
166                 return -EINVAL;
167
168         obd->u.obt.obt_qctxt.lqc_itune_sz = val;
169         return count;
170 }
171 EXPORT_SYMBOL(lprocfs_quota_wr_itune);
172
173 #define USER_QUOTA      1
174 #define GROUP_QUOTA     2
175
176 #define MAX_STYPE_SIZE  5
177
178 int lprocfs_quota_rd_type(char *page, char **start, off_t off, int count,
179                           int *eof, void *data)
180 {
181         struct obd_device *obd = (struct obd_device *)data;
182         char stype[MAX_STYPE_SIZE + 1] = "";
183         int oq_type;
184         struct obd_device_target *obt;
185
186         LASSERT(obd != NULL);
187
188         obt = &obd->u.obt;
189
190         /* Collect the needed information */
191         oq_type = obd->u.obt.obt_qctxt.lqc_flags;
192
193         /* Transform the collected data into a user-readable string */
194         if (oq_type & LQC_USRQUOTA_FLAG)
195                 strcat(stype, "u");
196         if (oq_type & LQC_GRPQUOTA_FLAG)
197                 strcat(stype, "g");
198
199         strcat(stype, "3");
200
201         return snprintf(page, count, "%s\n", stype);
202 }
203 EXPORT_SYMBOL(lprocfs_quota_rd_type);
204
205 static int auto_quota_on(struct obd_device *obd, int type,
206                          struct super_block *sb, int is_master)
207 {
208         struct obd_quotactl *oqctl;
209         struct lvfs_run_ctxt saved;
210         int rc = 0, id;
211         struct obd_device_target *obt = &obd->u.obt;
212         ENTRY;
213
214         LASSERT(type == USRQUOTA || type == GRPQUOTA || type == UGQUOTA);
215
216         OBD_ALLOC_PTR(oqctl);
217         if (!oqctl)
218                 RETURN(-ENOMEM);
219
220         down(&obt->obt_quotachecking);
221         id = UGQUOTA2LQC(type);
222         /* quota already turned on */
223         if ((obt->obt_qctxt.lqc_flags & id) == id)
224                 GOTO(out, rc);
225
226         if (obt->obt_qctxt.lqc_immutable) {
227                 LCONSOLE_ERROR("Failed to turn Quota on, immutable mode "
228                                "(is SOM enabled?)\n");
229                 GOTO(out, rc = -ECANCELED);
230         }
231
232         oqctl->qc_type = type;
233         oqctl->qc_cmd = Q_QUOTAON;
234         oqctl->qc_id = obt->obt_qfmt;
235
236         push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
237         if (is_master) {
238                 struct mds_obd *mds = &obd->u.mds;
239
240                 down(&mds->mds_qonoff_sem);
241                 /* turn on cluster wide quota */
242                 rc = mds_admin_quota_on(obd, oqctl);
243                 if (rc)
244                         CDEBUG(rc == -ENOENT ? D_QUOTA : D_ERROR,
245                                "auto-enable admin quota failed. rc=%d\n", rc);
246                 up(&mds->mds_qonoff_sem);
247
248         }
249         if (!rc) {
250                 /* turn on local quota */
251                 rc = fsfilt_quotactl(obd, sb, oqctl);
252                 if (rc)
253                         CDEBUG(rc == -ENOENT ? D_QUOTA : D_ERROR,
254                                "auto-enable local quota failed. rc=%d\n", rc);
255                 else
256                         obt->obt_qctxt.lqc_flags |= UGQUOTA2LQC(type);
257         }
258
259         pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
260         EXIT;
261
262 out:
263         up(&obt->obt_quotachecking);
264         OBD_FREE_PTR(oqctl);
265         return rc;
266 }
267
268 int lprocfs_quota_wr_type(struct file *file, const char *buffer,
269                           unsigned long count, void *data)
270 {
271         struct obd_device *obd = (struct obd_device *)data;
272         struct obd_device_target *obt;
273         int type = 0, is_mds;
274         unsigned long i;
275         char stype[MAX_STYPE_SIZE + 1] = "";
276
277         LASSERT(obd != NULL);
278
279         obt = &obd->u.obt;
280
281         is_mds = !strcmp(obd->obd_type->typ_name, LUSTRE_MDS_NAME);
282
283         if (count > MAX_STYPE_SIZE)
284                 return -EINVAL;
285
286         if (copy_from_user(stype, buffer, count))
287                 return -EFAULT;
288
289         for (i = 0 ; i < count ; i++) {
290                 switch (stype[i]) {
291                 case 'u' :
292                         type |= USER_QUOTA;
293                         break;
294                 case 'g' :
295                         type |= GROUP_QUOTA;
296                         break;
297                 case '1' :
298                 case '2' :
299                         CWARN("quota_type options 1 and 2 are obsolete, "
300                               "they will be ignored\n");
301                         break;
302                 case '3' : /* the only valid version spec, do nothing */
303                 default  : /* just skip stray symbols like \n */
304                         break;
305                 }
306         }
307
308         if (type != 0) {
309                 int rc = auto_quota_on(obd, type - 1, obt->obt_sb, is_mds);
310
311                 if (rc == 0)
312                         build_lqs(obd);
313                 else if (rc != -EALREADY)
314                         return rc;
315         }
316
317         return count;
318 }
319 EXPORT_SYMBOL(lprocfs_quota_wr_type);
320
321 int lprocfs_quota_rd_switch_seconds(char *page, char **start, off_t off,
322                                     int count, int *eof, void *data)
323 {
324         struct obd_device *obd = (struct obd_device *)data;
325         LASSERT(obd != NULL);
326
327         return snprintf(page, count, "%d\n",
328                         obd->u.obt.obt_qctxt.lqc_switch_seconds);
329 }
330 EXPORT_SYMBOL(lprocfs_quota_rd_switch_seconds);
331
332 int lprocfs_quota_wr_switch_seconds(struct file *file, const char *buffer,
333                                     unsigned long count, void *data)
334 {
335         struct obd_device *obd = (struct obd_device *)data;
336         int val, rc;
337         LASSERT(obd != NULL);
338
339         rc = lprocfs_write_helper(buffer, count, &val);
340         if (rc)
341                 return rc;
342
343         if (val <= 10)
344                 return -EINVAL;
345
346         obd->u.obt.obt_qctxt.lqc_switch_seconds = val;
347         return count;
348 }
349 EXPORT_SYMBOL(lprocfs_quota_wr_switch_seconds);
350
351 int lprocfs_quota_rd_sync_blk(char *page, char **start, off_t off,
352                               int count, int *eof, void *data)
353 {
354         struct obd_device *obd = (struct obd_device *)data;
355         LASSERT(obd != NULL);
356
357         return snprintf(page, count, "%d\n",
358                         obd->u.obt.obt_qctxt.lqc_sync_blk);
359 }
360 EXPORT_SYMBOL(lprocfs_quota_rd_sync_blk);
361
362 int lprocfs_quota_wr_sync_blk(struct file *file, const char *buffer,
363                               unsigned long count, void *data)
364 {
365         struct obd_device *obd = (struct obd_device *)data;
366         int val, rc;
367         LASSERT(obd != NULL);
368
369         rc = lprocfs_write_helper(buffer, count, &val);
370         if (rc)
371                 return rc;
372
373         if (val < 0)
374                 return -EINVAL;
375
376         obd->u.obt.obt_qctxt.lqc_sync_blk = val;
377         return count;
378 }
379 EXPORT_SYMBOL(lprocfs_quota_wr_sync_blk);
380
381 int lprocfs_quota_rd_switch_qs(char *page, char **start, off_t off,
382                                int count, int *eof, void *data)
383 {
384         struct obd_device *obd = (struct obd_device *)data;
385         LASSERT(obd != NULL);
386
387         return snprintf(page, count, "changing qunit size is %s\n",
388                         obd->u.obt.obt_qctxt.lqc_switch_qs ?
389                         "enabled" : "disabled");
390 }
391 EXPORT_SYMBOL(lprocfs_quota_rd_switch_qs);
392
393 int lprocfs_quota_wr_switch_qs(struct file *file, const char *buffer,
394                                unsigned long count, void *data)
395 {
396         struct obd_device *obd = (struct obd_device *)data;
397         int val, rc;
398         LASSERT(obd != NULL);
399
400         rc = lprocfs_write_helper(buffer, count, &val);
401         if (rc)
402                 return rc;
403
404         if (val)
405             obd->u.obt.obt_qctxt.lqc_switch_qs = 1;
406         else
407             obd->u.obt.obt_qctxt.lqc_switch_qs = 0;
408
409         return count;
410 }
411 EXPORT_SYMBOL(lprocfs_quota_wr_switch_qs);
412
413 int lprocfs_quota_rd_boundary_factor(char *page, char **start, off_t off,
414                                      int count, int *eof, void *data)
415 {
416         struct obd_device *obd = (struct obd_device *)data;
417         LASSERT(obd != NULL);
418
419
420         return snprintf(page, count, "%lu\n",
421                         obd->u.obt.obt_qctxt.lqc_cqs_boundary_factor);
422 }
423 EXPORT_SYMBOL(lprocfs_quota_rd_boundary_factor);
424
425 int lprocfs_quota_wr_boundary_factor(struct file *file, const char *buffer,
426                                      unsigned long count, void *data)
427 {
428         struct obd_device *obd = (struct obd_device *)data;
429         int val, rc;
430         LASSERT(obd != NULL);
431
432         rc = lprocfs_write_helper(buffer, count, &val);
433         if (rc)
434                 return rc;
435
436         if (val < 2)
437                 return -EINVAL;
438
439         obd->u.obt.obt_qctxt.lqc_cqs_boundary_factor = val;
440         return count;
441 }
442 EXPORT_SYMBOL(lprocfs_quota_wr_boundary_factor);
443
444 int lprocfs_quota_rd_least_bunit(char *page, char **start, off_t off,
445                                  int count, int *eof, void *data)
446 {
447         struct obd_device *obd = (struct obd_device *)data;
448         LASSERT(obd != NULL);
449
450
451         return snprintf(page, count, "%lu\n",
452                         obd->u.obt.obt_qctxt.lqc_cqs_least_bunit);
453 }
454 EXPORT_SYMBOL(lprocfs_quota_rd_least_bunit);
455
456 int lprocfs_quota_wr_least_bunit(struct file *file, const char *buffer,
457                                  unsigned long count, void *data)
458 {
459         struct obd_device *obd = (struct obd_device *)data;
460         int val, rc;
461         LASSERT(obd != NULL);
462
463         rc = lprocfs_write_helper(buffer, count, &val);
464         if (rc)
465                 return rc;
466
467         if (val < PTLRPC_MAX_BRW_SIZE ||
468             val >= obd->u.obt.obt_qctxt.lqc_bunit_sz)
469                 return -EINVAL;
470
471         obd->u.obt.obt_qctxt.lqc_cqs_least_bunit = val;
472         return count;
473 }
474 EXPORT_SYMBOL(lprocfs_quota_wr_least_bunit);
475
476 int lprocfs_quota_rd_least_iunit(char *page, char **start, off_t off,
477                                  int count, int *eof, void *data)
478 {
479         struct obd_device *obd = (struct obd_device *)data;
480         LASSERT(obd != NULL);
481
482
483         return snprintf(page, count, "%lu\n",
484                         obd->u.obt.obt_qctxt.lqc_cqs_least_iunit);
485 }
486 EXPORT_SYMBOL(lprocfs_quota_rd_least_iunit);
487
488 int lprocfs_quota_wr_least_iunit(struct file *file, const char *buffer,
489                                  unsigned long count, void *data)
490 {
491         struct obd_device *obd = (struct obd_device *)data;
492         int val, rc;
493         LASSERT(obd != NULL);
494
495         rc = lprocfs_write_helper(buffer, count, &val);
496         if (rc)
497                 return rc;
498
499         if (val < 1 || val >= obd->u.obt.obt_qctxt.lqc_iunit_sz)
500                 return -EINVAL;
501
502         obd->u.obt.obt_qctxt.lqc_cqs_least_iunit = val;
503         return count;
504 }
505 EXPORT_SYMBOL(lprocfs_quota_wr_least_iunit);
506
507 int lprocfs_quota_rd_qs_factor(char *page, char **start, off_t off,
508                                int count, int *eof, void *data)
509 {
510         struct obd_device *obd = (struct obd_device *)data;
511         LASSERT(obd != NULL);
512
513
514         return snprintf(page, count, "%lu\n",
515                         obd->u.obt.obt_qctxt.lqc_cqs_qs_factor);
516 }
517 EXPORT_SYMBOL(lprocfs_quota_rd_qs_factor);
518
519 int lprocfs_quota_wr_qs_factor(struct file *file, const char *buffer,
520                                unsigned long count, void *data)
521 {
522         struct obd_device *obd = (struct obd_device *)data;
523         int val, rc;
524         LASSERT(obd != NULL);
525
526         rc = lprocfs_write_helper(buffer, count, &val);
527         if (rc)
528                 return rc;
529
530         if (val < 2)
531                 return -EINVAL;
532
533         obd->u.obt.obt_qctxt.lqc_cqs_qs_factor = val;
534         return count;
535 }
536 EXPORT_SYMBOL(lprocfs_quota_wr_qs_factor);
537
538 struct lprocfs_vars lprocfs_quota_common_vars[] = {
539         { "quota_bunit_sz", lprocfs_quota_rd_bunit,
540                             lprocfs_quota_wr_bunit, 0},
541         { "quota_btune_sz", lprocfs_quota_rd_btune,
542                             lprocfs_quota_wr_btune, 0},
543         { "quota_iunit_sz", lprocfs_quota_rd_iunit,
544                             lprocfs_quota_wr_iunit, 0},
545         { "quota_itune_sz", lprocfs_quota_rd_itune,
546                             lprocfs_quota_wr_itune, 0},
547         { "quota_type",     lprocfs_quota_rd_type,
548                             lprocfs_quota_wr_type, 0},
549         { "quota_switch_seconds",  lprocfs_quota_rd_switch_seconds,
550                                    lprocfs_quota_wr_switch_seconds, 0 },
551         { "quota_sync_blk", lprocfs_quota_rd_sync_blk,
552                             lprocfs_quota_wr_sync_blk, 0},
553         { NULL }
554 };
555
556 struct lprocfs_vars lprocfs_quota_master_vars[] = {
557         { "quota_switch_qs", lprocfs_quota_rd_switch_qs,
558                              lprocfs_quota_wr_switch_qs, 0 },
559         { "quota_boundary_factor", lprocfs_quota_rd_boundary_factor,
560                                    lprocfs_quota_wr_boundary_factor, 0 },
561         { "quota_least_bunit", lprocfs_quota_rd_least_bunit,
562                                lprocfs_quota_wr_least_bunit, 0 },
563         { "quota_least_iunit", lprocfs_quota_rd_least_iunit,
564                                lprocfs_quota_wr_least_iunit, 0 },
565         { "quota_qs_factor",   lprocfs_quota_rd_qs_factor,
566                                lprocfs_quota_wr_qs_factor, 0 },
567         { NULL }
568 };
569
570 int lquota_proc_setup(struct obd_device *obd, int is_master)
571 {
572         struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt;
573         int rc = 0;
574         ENTRY;
575
576         LASSERT(lquota_type_proc_dir && obd);
577         qctxt->lqc_proc_dir = lprocfs_register(obd->obd_name,
578                                                lquota_type_proc_dir,
579                                                lprocfs_quota_common_vars, obd);
580         if (IS_ERR(qctxt->lqc_proc_dir)) {
581                 rc = PTR_ERR(qctxt->lqc_proc_dir);
582                 CERROR("error %d setting up lprocfs for %s\n", rc,
583                        obd->obd_name);
584                 qctxt->lqc_proc_dir = NULL;
585                 GOTO(out, rc);
586         }
587
588         if (is_master) {
589                 rc = lprocfs_add_vars(qctxt->lqc_proc_dir,
590                                       lprocfs_quota_master_vars, obd);
591                 if (rc) {
592                         CERROR("error %d setting up lprocfs for %s"
593                                "(quota master)\n", rc, obd->obd_name);
594                         GOTO(out_free_proc, rc);
595                 }
596         }
597
598         qctxt->lqc_stats = lprocfs_alloc_stats(LQUOTA_LAST_STAT -
599                                                LQUOTA_FIRST_STAT, 0);
600         if (!qctxt->lqc_stats)
601                 GOTO(out_free_proc, rc = -ENOMEM);
602
603         lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_SYNC_ACQ,
604                              LPROCFS_CNTR_AVGMINMAX, "sync_acq_req", "us");
605         lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_SYNC_REL,
606                              LPROCFS_CNTR_AVGMINMAX, "sync_rel_req", "us");
607         lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_ASYNC_ACQ,
608                              LPROCFS_CNTR_AVGMINMAX, "async_acq_req", "us");
609         lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_ASYNC_REL,
610                              LPROCFS_CNTR_AVGMINMAX, "async_rel_req", "us");
611
612         lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_WAIT_FOR_CHK_BLK,
613                              LPROCFS_CNTR_AVGMINMAX,
614                              "wait_for_blk_quota(lquota_chkquota)", "us");
615         lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_WAIT_FOR_CHK_INO,
616                              LPROCFS_CNTR_AVGMINMAX,
617                              "wait_for_ino_quota(lquota_chkquota)", "us");
618         lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_WAIT_FOR_COMMIT_BLK,
619                              LPROCFS_CNTR_AVGMINMAX,
620                              "wait_for_blk_quota(lquota_pending_commit)",
621                              "us");
622         lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_WAIT_FOR_COMMIT_INO,
623                              LPROCFS_CNTR_AVGMINMAX,
624                              "wait_for_ino_quota(lquota_pending_commit)",
625                              "us");
626
627         lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_WAIT_PENDING_BLK_QUOTA,
628                              LPROCFS_CNTR_AVGMINMAX,
629                              "wait_for_pending_blk_quota_req"
630                              "(qctxt_wait_pending_dqacq)", "us");
631         lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_WAIT_PENDING_INO_QUOTA,
632                              LPROCFS_CNTR_AVGMINMAX,
633                              "wait_for_pending_ino_quota_req"
634                              "(qctxt_wait_pending_dqacq)", "us");
635         lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_NOWAIT_PENDING_BLK_QUOTA,
636                              LPROCFS_CNTR_AVGMINMAX,
637                              "nowait_for_pending_blk_quota_req"
638                              "(qctxt_wait_pending_dqacq)", "us");
639         lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_NOWAIT_PENDING_INO_QUOTA,
640                              LPROCFS_CNTR_AVGMINMAX,
641                              "nowait_for_pending_ino_quota_req"
642                              "(qctxt_wait_pending_dqacq)", "us");
643
644         lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_QUOTA_CTL,
645                              LPROCFS_CNTR_AVGMINMAX, "quota_ctl", "us");
646         lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_ADJUST_QUNIT,
647                              LPROCFS_CNTR_AVGMINMAX, "adjust_qunit", "us");
648
649         lprocfs_register_stats(qctxt->lqc_proc_dir, "stats", qctxt->lqc_stats);
650
651         RETURN(rc);
652
653 out_free_proc:
654         lprocfs_remove(&qctxt->lqc_proc_dir);
655 out:
656         RETURN(rc);
657 }
658
659 int lquota_proc_cleanup(struct lustre_quota_ctxt *qctxt)
660 {
661         if (!qctxt || !qctxt->lqc_proc_dir)
662                 return -EINVAL;
663
664         if (qctxt->lqc_stats != NULL)
665                  lprocfs_free_stats(&qctxt->lqc_stats);
666
667         lprocfs_remove(&qctxt->lqc_proc_dir);
668         return 0;
669 }
670
671 #endif  /* LPROCFS */
672 #endif