Whamcloud - gitweb
58d88f7d0ee5270b2c157ec6e32d5190dfd9a5ef
[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;
212         ENTRY;
213
214         LASSERT(type == USRQUOTA || type == GRPQUOTA || type == UGQUOTA);
215
216         obt = &obd->u.obt;
217
218         OBD_ALLOC_PTR(oqctl);
219         if (!oqctl)
220                 RETURN(-ENOMEM);
221
222         if (!atomic_dec_and_test(&obt->obt_quotachecking)) {
223                 CDEBUG(D_INFO, "other people are doing quotacheck\n");
224                 atomic_inc(&obt->obt_quotachecking);
225                 RETURN(-EBUSY);
226         }
227
228         id = UGQUOTA2LQC(type);
229         /* quota already turned on */
230         if ((obt->obt_qctxt.lqc_flags & id) == id) {
231                 rc = 0;
232                 goto out;
233         }
234         if (obt->obt_qctxt.lqc_immutable) {
235                 LCONSOLE_ERROR("Failed to turn Quota on, immutable mode "
236                                "(is SOM enabled?)\n");
237                 goto out;
238         }
239
240         oqctl->qc_type = type;
241         oqctl->qc_cmd = Q_QUOTAON;
242         oqctl->qc_id = obt->obt_qfmt;
243
244         push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
245         if (is_master) {
246                 struct mds_obd *mds = &obd->u.mds;
247
248                 down(&mds->mds_qonoff_sem);
249                 /* turn on cluster wide quota */
250                 rc = mds_admin_quota_on(obd, oqctl);
251                 if (rc)
252                         CDEBUG(rc == -ENOENT ? D_QUOTA : D_ERROR,
253                                "auto-enable admin quota failed. rc=%d\n", rc);
254                 up(&mds->mds_qonoff_sem);
255
256         }
257         if (!rc) {
258                 /* turn on local quota */
259                 rc = fsfilt_quotactl(obd, sb, oqctl);
260                 if (rc)
261                         CDEBUG(rc == -ENOENT ? D_QUOTA : D_ERROR,
262                                "auto-enable local quota failed. rc=%d\n", rc);
263                 else
264                         obt->obt_qctxt.lqc_flags |= UGQUOTA2LQC(type);
265         }
266
267         pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
268
269 out:
270         atomic_inc(&obt->obt_quotachecking);
271
272         OBD_FREE_PTR(oqctl);
273         RETURN(rc);
274 }
275
276 int lprocfs_quota_wr_type(struct file *file, const char *buffer,
277                           unsigned long count, void *data)
278 {
279         struct obd_device *obd = (struct obd_device *)data;
280         struct obd_device_target *obt;
281         int type = 0, is_mds;
282         unsigned long i;
283         char stype[MAX_STYPE_SIZE + 1] = "";
284
285         LASSERT(obd != NULL);
286
287         obt = &obd->u.obt;
288
289         is_mds = !strcmp(obd->obd_type->typ_name, LUSTRE_MDS_NAME);
290
291         if (count > MAX_STYPE_SIZE)
292                 return -EINVAL;
293
294         if (copy_from_user(stype, buffer, count))
295                 return -EFAULT;
296
297         for (i = 0 ; i < count ; i++) {
298                 switch (stype[i]) {
299                 case 'u' :
300                         type |= USER_QUOTA;
301                         break;
302                 case 'g' :
303                         type |= GROUP_QUOTA;
304                         break;
305                 case '1' :
306                 case '2' :
307                         CWARN("quota_type options 1 and 2 are obsolete, "
308                               "they will be ignored\n");
309                         break;
310                 case '3' : /* the only valid version spec, do nothing */
311                 default  : /* just skip stray symbols like \n */
312                         break;
313                 }
314         }
315
316         if (type != 0)
317                 auto_quota_on(obd, type - 1, obt->obt_sb, is_mds);
318
319         return count;
320 }
321 EXPORT_SYMBOL(lprocfs_quota_wr_type);
322
323 int lprocfs_quota_rd_switch_seconds(char *page, char **start, off_t off,
324                                     int count, int *eof, void *data)
325 {
326         struct obd_device *obd = (struct obd_device *)data;
327         LASSERT(obd != NULL);
328
329         return snprintf(page, count, "%d\n",
330                         obd->u.obt.obt_qctxt.lqc_switch_seconds);
331 }
332 EXPORT_SYMBOL(lprocfs_quota_rd_switch_seconds);
333
334 int lprocfs_quota_wr_switch_seconds(struct file *file, const char *buffer,
335                                     unsigned long count, void *data)
336 {
337         struct obd_device *obd = (struct obd_device *)data;
338         int val, rc;
339         LASSERT(obd != NULL);
340
341         rc = lprocfs_write_helper(buffer, count, &val);
342         if (rc)
343                 return rc;
344
345         if (val <= 10)
346                 return -EINVAL;
347
348         obd->u.obt.obt_qctxt.lqc_switch_seconds = val;
349         return count;
350 }
351 EXPORT_SYMBOL(lprocfs_quota_wr_switch_seconds);
352
353 int lprocfs_quota_rd_sync_blk(char *page, char **start, off_t off,
354                               int count, int *eof, void *data)
355 {
356         struct obd_device *obd = (struct obd_device *)data;
357         LASSERT(obd != NULL);
358
359         return snprintf(page, count, "%d\n",
360                         obd->u.obt.obt_qctxt.lqc_sync_blk);
361 }
362 EXPORT_SYMBOL(lprocfs_quota_rd_sync_blk);
363
364 int lprocfs_quota_wr_sync_blk(struct file *file, const char *buffer,
365                               unsigned long count, void *data)
366 {
367         struct obd_device *obd = (struct obd_device *)data;
368         int val, rc;
369         LASSERT(obd != NULL);
370
371         rc = lprocfs_write_helper(buffer, count, &val);
372         if (rc)
373                 return rc;
374
375         if (val < 0)
376                 return -EINVAL;
377
378         obd->u.obt.obt_qctxt.lqc_sync_blk = val;
379         return count;
380 }
381 EXPORT_SYMBOL(lprocfs_quota_wr_sync_blk);
382
383 int lprocfs_quota_rd_switch_qs(char *page, char **start, off_t off,
384                                int count, int *eof, void *data)
385 {
386         struct obd_device *obd = (struct obd_device *)data;
387         LASSERT(obd != NULL);
388
389         return snprintf(page, count, "changing qunit size is %s\n",
390                         obd->u.obt.obt_qctxt.lqc_switch_qs ?
391                         "enabled" : "disabled");
392 }
393 EXPORT_SYMBOL(lprocfs_quota_rd_switch_qs);
394
395 int lprocfs_quota_wr_switch_qs(struct file *file, const char *buffer,
396                                unsigned long count, void *data)
397 {
398         struct obd_device *obd = (struct obd_device *)data;
399         int val, rc;
400         LASSERT(obd != NULL);
401
402         rc = lprocfs_write_helper(buffer, count, &val);
403         if (rc)
404                 return rc;
405
406         if (val)
407             obd->u.obt.obt_qctxt.lqc_switch_qs = 1;
408         else
409             obd->u.obt.obt_qctxt.lqc_switch_qs = 0;
410
411         return count;
412 }
413 EXPORT_SYMBOL(lprocfs_quota_wr_switch_qs);
414
415 int lprocfs_quota_rd_boundary_factor(char *page, char **start, off_t off,
416                                      int count, int *eof, void *data)
417 {
418         struct obd_device *obd = (struct obd_device *)data;
419         LASSERT(obd != NULL);
420
421
422         return snprintf(page, count, "%lu\n",
423                         obd->u.obt.obt_qctxt.lqc_cqs_boundary_factor);
424 }
425 EXPORT_SYMBOL(lprocfs_quota_rd_boundary_factor);
426
427 int lprocfs_quota_wr_boundary_factor(struct file *file, const char *buffer,
428                                      unsigned long count, void *data)
429 {
430         struct obd_device *obd = (struct obd_device *)data;
431         int val, rc;
432         LASSERT(obd != NULL);
433
434         rc = lprocfs_write_helper(buffer, count, &val);
435         if (rc)
436                 return rc;
437
438         if (val < 2)
439                 return -EINVAL;
440
441         obd->u.obt.obt_qctxt.lqc_cqs_boundary_factor = val;
442         return count;
443 }
444 EXPORT_SYMBOL(lprocfs_quota_wr_boundary_factor);
445
446 int lprocfs_quota_rd_least_bunit(char *page, char **start, off_t off,
447                                  int count, int *eof, void *data)
448 {
449         struct obd_device *obd = (struct obd_device *)data;
450         LASSERT(obd != NULL);
451
452
453         return snprintf(page, count, "%lu\n",
454                         obd->u.obt.obt_qctxt.lqc_cqs_least_bunit);
455 }
456 EXPORT_SYMBOL(lprocfs_quota_rd_least_bunit);
457
458 int lprocfs_quota_wr_least_bunit(struct file *file, const char *buffer,
459                                  unsigned long count, void *data)
460 {
461         struct obd_device *obd = (struct obd_device *)data;
462         int val, rc;
463         LASSERT(obd != NULL);
464
465         rc = lprocfs_write_helper(buffer, count, &val);
466         if (rc)
467                 return rc;
468
469         if (val < PTLRPC_MAX_BRW_SIZE ||
470             val >= obd->u.obt.obt_qctxt.lqc_bunit_sz)
471                 return -EINVAL;
472
473         obd->u.obt.obt_qctxt.lqc_cqs_least_bunit = val;
474         return count;
475 }
476 EXPORT_SYMBOL(lprocfs_quota_wr_least_bunit);
477
478 int lprocfs_quota_rd_least_iunit(char *page, char **start, off_t off,
479                                  int count, int *eof, void *data)
480 {
481         struct obd_device *obd = (struct obd_device *)data;
482         LASSERT(obd != NULL);
483
484
485         return snprintf(page, count, "%lu\n",
486                         obd->u.obt.obt_qctxt.lqc_cqs_least_iunit);
487 }
488 EXPORT_SYMBOL(lprocfs_quota_rd_least_iunit);
489
490 int lprocfs_quota_wr_least_iunit(struct file *file, const char *buffer,
491                                  unsigned long count, void *data)
492 {
493         struct obd_device *obd = (struct obd_device *)data;
494         int val, rc;
495         LASSERT(obd != NULL);
496
497         rc = lprocfs_write_helper(buffer, count, &val);
498         if (rc)
499                 return rc;
500
501         if (val < 1 || val >= obd->u.obt.obt_qctxt.lqc_iunit_sz)
502                 return -EINVAL;
503
504         obd->u.obt.obt_qctxt.lqc_cqs_least_iunit = val;
505         return count;
506 }
507 EXPORT_SYMBOL(lprocfs_quota_wr_least_iunit);
508
509 int lprocfs_quota_rd_qs_factor(char *page, char **start, off_t off,
510                                int count, int *eof, void *data)
511 {
512         struct obd_device *obd = (struct obd_device *)data;
513         LASSERT(obd != NULL);
514
515
516         return snprintf(page, count, "%lu\n",
517                         obd->u.obt.obt_qctxt.lqc_cqs_qs_factor);
518 }
519 EXPORT_SYMBOL(lprocfs_quota_rd_qs_factor);
520
521 int lprocfs_quota_wr_qs_factor(struct file *file, const char *buffer,
522                                unsigned long count, void *data)
523 {
524         struct obd_device *obd = (struct obd_device *)data;
525         int val, rc;
526         LASSERT(obd != NULL);
527
528         rc = lprocfs_write_helper(buffer, count, &val);
529         if (rc)
530                 return rc;
531
532         if (val < 2)
533                 return -EINVAL;
534
535         obd->u.obt.obt_qctxt.lqc_cqs_qs_factor = val;
536         return count;
537 }
538 EXPORT_SYMBOL(lprocfs_quota_wr_qs_factor);
539
540 struct lprocfs_vars lprocfs_quota_common_vars[] = {
541         { "quota_bunit_sz", lprocfs_quota_rd_bunit,
542                             lprocfs_quota_wr_bunit, 0},
543         { "quota_btune_sz", lprocfs_quota_rd_btune,
544                             lprocfs_quota_wr_btune, 0},
545         { "quota_iunit_sz", lprocfs_quota_rd_iunit,
546                             lprocfs_quota_wr_iunit, 0},
547         { "quota_itune_sz", lprocfs_quota_rd_itune,
548                             lprocfs_quota_wr_itune, 0},
549         { "quota_type",     lprocfs_quota_rd_type,
550                             lprocfs_quota_wr_type, 0},
551         { "quota_switch_seconds",  lprocfs_quota_rd_switch_seconds,
552                                    lprocfs_quota_wr_switch_seconds, 0 },
553         { "quota_sync_blk", lprocfs_quota_rd_sync_blk,
554                             lprocfs_quota_wr_sync_blk, 0},
555         { NULL }
556 };
557
558 struct lprocfs_vars lprocfs_quota_master_vars[] = {
559         { "quota_switch_qs", lprocfs_quota_rd_switch_qs,
560                              lprocfs_quota_wr_switch_qs, 0 },
561         { "quota_boundary_factor", lprocfs_quota_rd_boundary_factor,
562                                    lprocfs_quota_wr_boundary_factor, 0 },
563         { "quota_least_bunit", lprocfs_quota_rd_least_bunit,
564                                lprocfs_quota_wr_least_bunit, 0 },
565         { "quota_least_iunit", lprocfs_quota_rd_least_iunit,
566                                lprocfs_quota_wr_least_iunit, 0 },
567         { "quota_qs_factor",   lprocfs_quota_rd_qs_factor,
568                                lprocfs_quota_wr_qs_factor, 0 },
569         { NULL }
570 };
571
572 int lquota_proc_setup(struct obd_device *obd, int is_master)
573 {
574         struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt;
575         int rc = 0;
576         ENTRY;
577
578         LASSERT(lquota_type_proc_dir && obd);
579         qctxt->lqc_proc_dir = lprocfs_register(obd->obd_name,
580                                                lquota_type_proc_dir,
581                                                lprocfs_quota_common_vars, obd);
582         if (IS_ERR(qctxt->lqc_proc_dir)) {
583                 rc = PTR_ERR(qctxt->lqc_proc_dir);
584                 CERROR("error %d setting up lprocfs for %s\n", rc,
585                        obd->obd_name);
586                 qctxt->lqc_proc_dir = NULL;
587                 GOTO(out, rc);
588         }
589
590         if (is_master) {
591                 rc = lprocfs_add_vars(qctxt->lqc_proc_dir,
592                                       lprocfs_quota_master_vars, obd);
593                 if (rc) {
594                         CERROR("error %d setting up lprocfs for %s"
595                                "(quota master)\n", rc, obd->obd_name);
596                         GOTO(out_free_proc, rc);
597                 }
598         }
599
600         qctxt->lqc_stats = lprocfs_alloc_stats(LQUOTA_LAST_STAT -
601                                                LQUOTA_FIRST_STAT, 0);
602         if (!qctxt->lqc_stats)
603                 GOTO(out_free_proc, rc = -ENOMEM);
604
605         lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_SYNC_ACQ,
606                              LPROCFS_CNTR_AVGMINMAX, "sync_acq_req", "us");
607         lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_SYNC_REL,
608                              LPROCFS_CNTR_AVGMINMAX, "sync_rel_req", "us");
609         lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_ASYNC_ACQ,
610                              LPROCFS_CNTR_AVGMINMAX, "async_acq_req", "us");
611         lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_ASYNC_REL,
612                              LPROCFS_CNTR_AVGMINMAX, "async_rel_req", "us");
613
614         lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_WAIT_FOR_CHK_BLK,
615                              LPROCFS_CNTR_AVGMINMAX,
616                              "wait_for_blk_quota(lquota_chkquota)", "us");
617         lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_WAIT_FOR_CHK_INO,
618                              LPROCFS_CNTR_AVGMINMAX,
619                              "wait_for_ino_quota(lquota_chkquota)", "us");
620         lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_WAIT_FOR_COMMIT_BLK,
621                              LPROCFS_CNTR_AVGMINMAX,
622                              "wait_for_blk_quota(lquota_pending_commit)",
623                              "us");
624         lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_WAIT_FOR_COMMIT_INO,
625                              LPROCFS_CNTR_AVGMINMAX,
626                              "wait_for_ino_quota(lquota_pending_commit)",
627                              "us");
628
629         lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_WAIT_PENDING_BLK_QUOTA,
630                              LPROCFS_CNTR_AVGMINMAX,
631                              "wait_for_pending_blk_quota_req"
632                              "(qctxt_wait_pending_dqacq)", "us");
633         lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_WAIT_PENDING_INO_QUOTA,
634                              LPROCFS_CNTR_AVGMINMAX,
635                              "wait_for_pending_ino_quota_req"
636                              "(qctxt_wait_pending_dqacq)", "us");
637         lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_NOWAIT_PENDING_BLK_QUOTA,
638                              LPROCFS_CNTR_AVGMINMAX,
639                              "nowait_for_pending_blk_quota_req"
640                              "(qctxt_wait_pending_dqacq)", "us");
641         lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_NOWAIT_PENDING_INO_QUOTA,
642                              LPROCFS_CNTR_AVGMINMAX,
643                              "nowait_for_pending_ino_quota_req"
644                              "(qctxt_wait_pending_dqacq)", "us");
645
646         lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_QUOTA_CTL,
647                              LPROCFS_CNTR_AVGMINMAX, "quota_ctl", "us");
648         lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_ADJUST_QUNIT,
649                              LPROCFS_CNTR_AVGMINMAX, "adjust_qunit", "us");
650
651         lprocfs_register_stats(qctxt->lqc_proc_dir, "stats", qctxt->lqc_stats);
652
653         RETURN(rc);
654
655 out_free_proc:
656         lprocfs_remove(&qctxt->lqc_proc_dir);
657 out:
658         RETURN(rc);
659 }
660
661 int lquota_proc_cleanup(struct lustre_quota_ctxt *qctxt)
662 {
663         if (!qctxt || !qctxt->lqc_proc_dir)
664                 return -EINVAL;
665
666         if (qctxt->lqc_stats != NULL)
667                  lprocfs_free_stats(&qctxt->lqc_stats);
668
669         lprocfs_remove(&qctxt->lqc_proc_dir);
670         return 0;
671 }
672
673 #endif  /* LPROCFS */
674 #endif