1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define DEBUG_SUBSYSTEM S_LQUOTA
39 #include <linux/version.h>
40 #include <lprocfs_status.h>
42 #include <linux/seq_file.h>
43 #include <lustre_fsfilt.h>
45 #include "quota_internal.h"
47 #ifdef HAVE_QUOTA_SUPPORT
50 int lprocfs_quota_rd_bunit(char *page, char **start, off_t off, int count,
53 struct obd_device *obd = (struct obd_device *)data;
56 return snprintf(page, count, "%lu\n",
57 obd->u.obt.obt_qctxt.lqc_bunit_sz);
59 EXPORT_SYMBOL(lprocfs_quota_rd_bunit);
61 int lprocfs_quota_wr_bunit(struct file *file, const char *buffer,
62 unsigned long count, void *data)
64 struct obd_device *obd = (struct obd_device *)data;
68 rc = lprocfs_write_helper(buffer, count, &val);
72 if (val % QUOTABLOCK_SIZE ||
73 val <= obd->u.obt.obt_qctxt.lqc_btune_sz)
76 obd->u.obt.obt_qctxt.lqc_bunit_sz = val;
79 EXPORT_SYMBOL(lprocfs_quota_wr_bunit);
81 int lprocfs_quota_rd_btune(char *page, char **start, off_t off, int count,
84 struct obd_device *obd = (struct obd_device *)data;
87 return snprintf(page, count, "%lu\n",
88 obd->u.obt.obt_qctxt.lqc_btune_sz);
90 EXPORT_SYMBOL(lprocfs_quota_rd_btune);
92 int lprocfs_quota_wr_btune(struct file *file, const char *buffer,
93 unsigned long count, void *data)
95 struct obd_device *obd = (struct obd_device *)data;
99 rc = lprocfs_write_helper(buffer, count, &val);
103 if (val <= QUOTABLOCK_SIZE * MIN_QLIMIT || val % QUOTABLOCK_SIZE ||
104 val >= obd->u.obt.obt_qctxt.lqc_bunit_sz)
107 obd->u.obt.obt_qctxt.lqc_btune_sz = val;
110 EXPORT_SYMBOL(lprocfs_quota_wr_btune);
112 int lprocfs_quota_rd_iunit(char *page, char **start, off_t off, int count,
113 int *eof, void *data)
115 struct obd_device *obd = (struct obd_device *)data;
116 LASSERT(obd != NULL);
118 return snprintf(page, count, "%lu\n",
119 obd->u.obt.obt_qctxt.lqc_iunit_sz);
121 EXPORT_SYMBOL(lprocfs_quota_rd_iunit);
123 int lprocfs_quota_wr_iunit(struct file *file, const char *buffer,
124 unsigned long count, void *data)
126 struct obd_device *obd = (struct obd_device *)data;
128 LASSERT(obd != NULL);
130 rc = lprocfs_write_helper(buffer, count, &val);
134 if (val <= obd->u.obt.obt_qctxt.lqc_itune_sz)
137 obd->u.obt.obt_qctxt.lqc_iunit_sz = val;
140 EXPORT_SYMBOL(lprocfs_quota_wr_iunit);
142 int lprocfs_quota_rd_itune(char *page, char **start, off_t off, int count,
143 int *eof, void *data)
145 struct obd_device *obd = (struct obd_device *)data;
146 LASSERT(obd != NULL);
148 return snprintf(page, count, "%lu\n",
149 obd->u.obt.obt_qctxt.lqc_itune_sz);
151 EXPORT_SYMBOL(lprocfs_quota_rd_itune);
153 int lprocfs_quota_wr_itune(struct file *file, const char *buffer,
154 unsigned long count, void *data)
156 struct obd_device *obd = (struct obd_device *)data;
158 LASSERT(obd != NULL);
160 rc = lprocfs_write_helper(buffer, count, &val);
164 if (val <= MIN_QLIMIT ||
165 val >= obd->u.obt.obt_qctxt.lqc_iunit_sz)
168 obd->u.obt.obt_qctxt.lqc_itune_sz = val;
171 EXPORT_SYMBOL(lprocfs_quota_wr_itune);
174 #define GROUP_QUOTA 2
176 #define MAX_STYPE_SIZE 5
178 int lprocfs_quota_rd_type(char *page, char **start, off_t off, int count,
179 int *eof, void *data)
181 struct obd_device *obd = (struct obd_device *)data;
182 char stype[MAX_STYPE_SIZE + 1] = "";
184 struct obd_device_target *obt;
186 LASSERT(obd != NULL);
190 /* Collect the needed information */
191 oq_type = obd->u.obt.obt_qctxt.lqc_flags;
193 /* Transform the collected data into a user-readable string */
194 if (oq_type & LQC_USRQUOTA_FLAG)
196 if (oq_type & LQC_GRPQUOTA_FLAG)
201 return snprintf(page, count, "%s\n", stype);
203 EXPORT_SYMBOL(lprocfs_quota_rd_type);
205 static int auto_quota_on(struct obd_device *obd, int type,
206 struct super_block *sb, int is_master)
208 struct obd_quotactl *oqctl;
209 struct lvfs_run_ctxt saved;
211 struct obd_device_target *obt;
214 LASSERT(type == USRQUOTA || type == GRPQUOTA || type == UGQUOTA);
218 OBD_ALLOC_PTR(oqctl);
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);
228 id = UGQUOTA2LQC(type);
229 /* quota already turned on */
230 if ((obt->obt_qctxt.lqc_flags & id) == id) {
234 if (obt->obt_qctxt.lqc_immutable) {
235 LCONSOLE_ERROR("Failed to turn Quota on, immutable mode "
236 "(is SOM enabled?)\n");
240 oqctl->qc_type = type;
241 oqctl->qc_cmd = Q_QUOTAON;
242 oqctl->qc_id = obt->obt_qfmt;
244 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
246 struct mds_obd *mds = &obd->u.mds;
248 down(&mds->mds_qonoff_sem);
249 /* turn on cluster wide quota */
250 rc = mds_admin_quota_on(obd, oqctl);
252 CDEBUG(rc == -ENOENT ? D_QUOTA : D_ERROR,
253 "auto-enable admin quota failed. rc=%d\n", rc);
254 up(&mds->mds_qonoff_sem);
258 /* turn on local quota */
259 rc = fsfilt_quotactl(obd, sb, oqctl);
261 CDEBUG(rc == -ENOENT ? D_QUOTA : D_ERROR,
262 "auto-enable local quota failed. rc=%d\n", rc);
264 obt->obt_qctxt.lqc_flags |= UGQUOTA2LQC(type);
267 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
270 atomic_inc(&obt->obt_quotachecking);
276 int lprocfs_quota_wr_type(struct file *file, const char *buffer,
277 unsigned long count, void *data)
279 struct obd_device *obd = (struct obd_device *)data;
280 struct obd_device_target *obt;
281 int type = 0, is_mds;
283 char stype[MAX_STYPE_SIZE + 1] = "";
285 LASSERT(obd != NULL);
289 is_mds = !strcmp(obd->obd_type->typ_name, LUSTRE_MDS_NAME);
291 if (count > MAX_STYPE_SIZE)
294 if (copy_from_user(stype, buffer, count))
297 for (i = 0 ; i < count ; i++) {
307 CWARN("quota_type options 1 and 2 are obsolete, "
308 "they will be ignored\n");
310 case '3' : /* the only valid version spec, do nothing */
311 default : /* just skip stray symbols like \n */
317 auto_quota_on(obd, type - 1, obt->obt_sb, is_mds);
323 EXPORT_SYMBOL(lprocfs_quota_wr_type);
325 int lprocfs_quota_rd_switch_seconds(char *page, char **start, off_t off,
326 int count, int *eof, void *data)
328 struct obd_device *obd = (struct obd_device *)data;
329 LASSERT(obd != NULL);
331 return snprintf(page, count, "%d\n",
332 obd->u.obt.obt_qctxt.lqc_switch_seconds);
334 EXPORT_SYMBOL(lprocfs_quota_rd_switch_seconds);
336 int lprocfs_quota_wr_switch_seconds(struct file *file, const char *buffer,
337 unsigned long count, void *data)
339 struct obd_device *obd = (struct obd_device *)data;
341 LASSERT(obd != NULL);
343 rc = lprocfs_write_helper(buffer, count, &val);
350 obd->u.obt.obt_qctxt.lqc_switch_seconds = val;
353 EXPORT_SYMBOL(lprocfs_quota_wr_switch_seconds);
355 int lprocfs_quota_rd_sync_blk(char *page, char **start, off_t off,
356 int count, int *eof, void *data)
358 struct obd_device *obd = (struct obd_device *)data;
359 LASSERT(obd != NULL);
361 return snprintf(page, count, "%d\n",
362 obd->u.obt.obt_qctxt.lqc_sync_blk);
364 EXPORT_SYMBOL(lprocfs_quota_rd_sync_blk);
366 int lprocfs_quota_wr_sync_blk(struct file *file, const char *buffer,
367 unsigned long count, void *data)
369 struct obd_device *obd = (struct obd_device *)data;
371 LASSERT(obd != NULL);
373 rc = lprocfs_write_helper(buffer, count, &val);
380 obd->u.obt.obt_qctxt.lqc_sync_blk = val;
383 EXPORT_SYMBOL(lprocfs_quota_wr_sync_blk);
385 int lprocfs_quota_rd_switch_qs(char *page, char **start, off_t off,
386 int count, int *eof, void *data)
388 struct obd_device *obd = (struct obd_device *)data;
389 LASSERT(obd != NULL);
391 return snprintf(page, count, "changing qunit size is %s\n",
392 obd->u.obt.obt_qctxt.lqc_switch_qs ?
393 "enabled" : "disabled");
395 EXPORT_SYMBOL(lprocfs_quota_rd_switch_qs);
397 int lprocfs_quota_wr_switch_qs(struct file *file, const char *buffer,
398 unsigned long count, void *data)
400 struct obd_device *obd = (struct obd_device *)data;
402 LASSERT(obd != NULL);
404 rc = lprocfs_write_helper(buffer, count, &val);
409 obd->u.obt.obt_qctxt.lqc_switch_qs = 1;
411 obd->u.obt.obt_qctxt.lqc_switch_qs = 0;
415 EXPORT_SYMBOL(lprocfs_quota_wr_switch_qs);
417 int lprocfs_quota_rd_boundary_factor(char *page, char **start, off_t off,
418 int count, int *eof, void *data)
420 struct obd_device *obd = (struct obd_device *)data;
421 LASSERT(obd != NULL);
424 return snprintf(page, count, "%lu\n",
425 obd->u.obt.obt_qctxt.lqc_cqs_boundary_factor);
427 EXPORT_SYMBOL(lprocfs_quota_rd_boundary_factor);
429 int lprocfs_quota_wr_boundary_factor(struct file *file, const char *buffer,
430 unsigned long count, void *data)
432 struct obd_device *obd = (struct obd_device *)data;
434 LASSERT(obd != NULL);
436 rc = lprocfs_write_helper(buffer, count, &val);
443 obd->u.obt.obt_qctxt.lqc_cqs_boundary_factor = val;
446 EXPORT_SYMBOL(lprocfs_quota_wr_boundary_factor);
448 int lprocfs_quota_rd_least_bunit(char *page, char **start, off_t off,
449 int count, int *eof, void *data)
451 struct obd_device *obd = (struct obd_device *)data;
452 LASSERT(obd != NULL);
455 return snprintf(page, count, "%lu\n",
456 obd->u.obt.obt_qctxt.lqc_cqs_least_bunit);
458 EXPORT_SYMBOL(lprocfs_quota_rd_least_bunit);
460 int lprocfs_quota_wr_least_bunit(struct file *file, const char *buffer,
461 unsigned long count, void *data)
463 struct obd_device *obd = (struct obd_device *)data;
465 LASSERT(obd != NULL);
467 rc = lprocfs_write_helper(buffer, count, &val);
471 if (val < PTLRPC_MAX_BRW_SIZE ||
472 val >= obd->u.obt.obt_qctxt.lqc_bunit_sz)
475 obd->u.obt.obt_qctxt.lqc_cqs_least_bunit = val;
478 EXPORT_SYMBOL(lprocfs_quota_wr_least_bunit);
480 int lprocfs_quota_rd_least_iunit(char *page, char **start, off_t off,
481 int count, int *eof, void *data)
483 struct obd_device *obd = (struct obd_device *)data;
484 LASSERT(obd != NULL);
487 return snprintf(page, count, "%lu\n",
488 obd->u.obt.obt_qctxt.lqc_cqs_least_iunit);
490 EXPORT_SYMBOL(lprocfs_quota_rd_least_iunit);
492 int lprocfs_quota_wr_least_iunit(struct file *file, const char *buffer,
493 unsigned long count, void *data)
495 struct obd_device *obd = (struct obd_device *)data;
497 LASSERT(obd != NULL);
499 rc = lprocfs_write_helper(buffer, count, &val);
503 if (val < 1 || val >= obd->u.obt.obt_qctxt.lqc_iunit_sz)
506 obd->u.obt.obt_qctxt.lqc_cqs_least_iunit = val;
509 EXPORT_SYMBOL(lprocfs_quota_wr_least_iunit);
511 int lprocfs_quota_rd_qs_factor(char *page, char **start, off_t off,
512 int count, int *eof, void *data)
514 struct obd_device *obd = (struct obd_device *)data;
515 LASSERT(obd != NULL);
518 return snprintf(page, count, "%lu\n",
519 obd->u.obt.obt_qctxt.lqc_cqs_qs_factor);
521 EXPORT_SYMBOL(lprocfs_quota_rd_qs_factor);
523 int lprocfs_quota_wr_qs_factor(struct file *file, const char *buffer,
524 unsigned long count, void *data)
526 struct obd_device *obd = (struct obd_device *)data;
528 LASSERT(obd != NULL);
530 rc = lprocfs_write_helper(buffer, count, &val);
537 obd->u.obt.obt_qctxt.lqc_cqs_qs_factor = val;
540 EXPORT_SYMBOL(lprocfs_quota_wr_qs_factor);
542 struct lprocfs_vars lprocfs_quota_common_vars[] = {
543 { "quota_bunit_sz", lprocfs_quota_rd_bunit,
544 lprocfs_quota_wr_bunit, 0},
545 { "quota_btune_sz", lprocfs_quota_rd_btune,
546 lprocfs_quota_wr_btune, 0},
547 { "quota_iunit_sz", lprocfs_quota_rd_iunit,
548 lprocfs_quota_wr_iunit, 0},
549 { "quota_itune_sz", lprocfs_quota_rd_itune,
550 lprocfs_quota_wr_itune, 0},
551 { "quota_type", lprocfs_quota_rd_type,
552 lprocfs_quota_wr_type, 0},
553 { "quota_switch_seconds", lprocfs_quota_rd_switch_seconds,
554 lprocfs_quota_wr_switch_seconds, 0 },
555 { "quota_sync_blk", lprocfs_quota_rd_sync_blk,
556 lprocfs_quota_wr_sync_blk, 0},
560 struct lprocfs_vars lprocfs_quota_master_vars[] = {
561 { "quota_switch_qs", lprocfs_quota_rd_switch_qs,
562 lprocfs_quota_wr_switch_qs, 0 },
563 { "quota_boundary_factor", lprocfs_quota_rd_boundary_factor,
564 lprocfs_quota_wr_boundary_factor, 0 },
565 { "quota_least_bunit", lprocfs_quota_rd_least_bunit,
566 lprocfs_quota_wr_least_bunit, 0 },
567 { "quota_least_iunit", lprocfs_quota_rd_least_iunit,
568 lprocfs_quota_wr_least_iunit, 0 },
569 { "quota_qs_factor", lprocfs_quota_rd_qs_factor,
570 lprocfs_quota_wr_qs_factor, 0 },
574 int lquota_proc_setup(struct obd_device *obd, int is_master)
576 struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt;
580 LASSERT(lquota_type_proc_dir && obd);
581 qctxt->lqc_proc_dir = lprocfs_register(obd->obd_name,
582 lquota_type_proc_dir,
583 lprocfs_quota_common_vars, obd);
584 if (IS_ERR(qctxt->lqc_proc_dir)) {
585 rc = PTR_ERR(qctxt->lqc_proc_dir);
586 CERROR("error %d setting up lprocfs for %s\n", rc,
588 qctxt->lqc_proc_dir = NULL;
593 rc = lprocfs_add_vars(qctxt->lqc_proc_dir,
594 lprocfs_quota_master_vars, obd);
596 CERROR("error %d setting up lprocfs for %s"
597 "(quota master)\n", rc, obd->obd_name);
598 GOTO(out_free_proc, rc);
602 qctxt->lqc_stats = lprocfs_alloc_stats(LQUOTA_LAST_STAT -
603 LQUOTA_FIRST_STAT, 0);
604 if (!qctxt->lqc_stats)
605 GOTO(out_free_proc, rc = -ENOMEM);
607 lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_SYNC_ACQ,
608 LPROCFS_CNTR_AVGMINMAX, "sync_acq_req", "us");
609 lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_SYNC_REL,
610 LPROCFS_CNTR_AVGMINMAX, "sync_rel_req", "us");
611 lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_ASYNC_ACQ,
612 LPROCFS_CNTR_AVGMINMAX, "async_acq_req", "us");
613 lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_ASYNC_REL,
614 LPROCFS_CNTR_AVGMINMAX, "async_rel_req", "us");
616 lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_WAIT_FOR_CHK_BLK,
617 LPROCFS_CNTR_AVGMINMAX,
618 "wait_for_blk_quota(lquota_chkquota)", "us");
619 lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_WAIT_FOR_CHK_INO,
620 LPROCFS_CNTR_AVGMINMAX,
621 "wait_for_ino_quota(lquota_chkquota)", "us");
622 lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_WAIT_FOR_COMMIT_BLK,
623 LPROCFS_CNTR_AVGMINMAX,
624 "wait_for_blk_quota(lquota_pending_commit)",
626 lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_WAIT_FOR_COMMIT_INO,
627 LPROCFS_CNTR_AVGMINMAX,
628 "wait_for_ino_quota(lquota_pending_commit)",
631 lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_WAIT_PENDING_BLK_QUOTA,
632 LPROCFS_CNTR_AVGMINMAX,
633 "wait_for_pending_blk_quota_req"
634 "(qctxt_wait_pending_dqacq)", "us");
635 lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_WAIT_PENDING_INO_QUOTA,
636 LPROCFS_CNTR_AVGMINMAX,
637 "wait_for_pending_ino_quota_req"
638 "(qctxt_wait_pending_dqacq)", "us");
639 lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_NOWAIT_PENDING_BLK_QUOTA,
640 LPROCFS_CNTR_AVGMINMAX,
641 "nowait_for_pending_blk_quota_req"
642 "(qctxt_wait_pending_dqacq)", "us");
643 lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_NOWAIT_PENDING_INO_QUOTA,
644 LPROCFS_CNTR_AVGMINMAX,
645 "nowait_for_pending_ino_quota_req"
646 "(qctxt_wait_pending_dqacq)", "us");
648 lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_QUOTA_CTL,
649 LPROCFS_CNTR_AVGMINMAX, "quota_ctl", "us");
650 lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_ADJUST_QUNIT,
651 LPROCFS_CNTR_AVGMINMAX, "adjust_qunit", "us");
653 lprocfs_register_stats(qctxt->lqc_proc_dir, "stats", qctxt->lqc_stats);
658 lprocfs_remove(&qctxt->lqc_proc_dir);
663 int lquota_proc_cleanup(struct lustre_quota_ctxt *qctxt)
665 if (!qctxt || !qctxt->lqc_proc_dir)
668 if (qctxt->lqc_stats != NULL)
669 lprocfs_free_stats(&qctxt->lqc_stats);
671 lprocfs_remove(&qctxt->lqc_proc_dir);