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 (c) 2008, 2010, Oracle and/or its affiliates. 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);
206 * generic_quota_on is very lazy and tolerant about current quota settings
207 * @global means to turn on quotas on each OST additionally to local quotas;
208 * should not be called from filter_quota_ctl on MDS nodes (as it starts
209 * admin quotas on MDS nodes).
211 int generic_quota_on(struct obd_device *obd, struct obd_quotactl *oqctl, int global)
213 struct obd_device_target *obt = &obd->u.obt;
214 struct lvfs_run_ctxt saved;
215 int id, is_master, rc = 0, local; /* means we need a local quotaon */
217 cfs_down(&obt->obt_quotachecking);
218 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
219 id = UGQUOTA2LQC(oqctl->qc_type);
220 local = (obt->obt_qctxt.lqc_flags & id) != id;
222 oqctl->qc_cmd = Q_QUOTAON;
223 oqctl->qc_id = obt->obt_qfmt;
225 is_master = !strcmp(obd->obd_type->typ_name, LUSTRE_MDS_NAME);
227 cfs_down_write(&obd->u.mds.mds_qonoff_sem);
229 /* turn on cluster wide quota */
230 rc = mds_admin_quota_on(obd, oqctl);
231 if (rc && rc != -ENOENT)
232 CERROR("%s: %s admin quotaon failed. rc=%d\n",
233 obd->obd_name, global ? "global":"local",
240 rc = fsfilt_quotactl(obd, obt->obt_sb, oqctl);
243 CERROR("%s: %s quotaon failed with"
244 " rc=%d\n", obd->obd_name,
245 global ? "global" : "local", rc);
247 obt->obt_qctxt.lqc_flags |= UGQUOTA2LQC(oqctl->qc_type);
252 if (rc == 0 && global && is_master)
253 rc = obd_quotactl(obd->u.mds.mds_lov_exp, oqctl);
257 cfs_up_write(&obd->u.mds.mds_qonoff_sem);
259 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
260 cfs_up(&obt->obt_quotachecking);
265 static int auto_quota_on(struct obd_device *obd, int type)
267 struct obd_quotactl *oqctl;
271 LASSERT(type == USRQUOTA || type == GRPQUOTA || type == UGQUOTA);
273 OBD_ALLOC_PTR(oqctl);
277 oqctl->qc_type = type;
279 rc = generic_quota_on(obd, oqctl, 0);
285 int lprocfs_quota_wr_type(struct file *file, const char *buffer,
286 unsigned long count, void *data)
288 struct obd_device *obd = (struct obd_device *)data;
289 struct obd_device_target *obt;
290 int type = 0, is_mds;
292 char stype[MAX_STYPE_SIZE + 1] = "";
294 LASSERT(obd != NULL);
298 is_mds = !strcmp(obd->obd_type->typ_name, LUSTRE_MDS_NAME);
300 if (count > MAX_STYPE_SIZE)
303 if (cfs_copy_from_user(stype, buffer, count))
306 for (i = 0 ; i < count ; i++) {
316 CWARN("quota_type options 1 and 2 are obsolete, "
317 "they will be ignored\n");
319 case '3' : /* the only valid version spec, do nothing */
320 default : /* just skip stray symbols like \n */
326 int rc = auto_quota_on(obd, type - 1);
328 if (rc && rc != -EALREADY && rc != -ENOENT)
334 EXPORT_SYMBOL(lprocfs_quota_wr_type);
336 int lprocfs_quota_rd_switch_seconds(char *page, char **start, off_t off,
337 int count, int *eof, void *data)
339 struct obd_device *obd = (struct obd_device *)data;
340 LASSERT(obd != NULL);
342 return snprintf(page, count, "%d\n",
343 obd->u.obt.obt_qctxt.lqc_switch_seconds);
345 EXPORT_SYMBOL(lprocfs_quota_rd_switch_seconds);
347 int lprocfs_quota_wr_switch_seconds(struct file *file, const char *buffer,
348 unsigned long count, void *data)
350 struct obd_device *obd = (struct obd_device *)data;
352 LASSERT(obd != NULL);
354 rc = lprocfs_write_helper(buffer, count, &val);
361 obd->u.obt.obt_qctxt.lqc_switch_seconds = val;
364 EXPORT_SYMBOL(lprocfs_quota_wr_switch_seconds);
366 int lprocfs_quota_rd_sync_blk(char *page, char **start, off_t off,
367 int count, int *eof, void *data)
369 struct obd_device *obd = (struct obd_device *)data;
370 LASSERT(obd != NULL);
372 return snprintf(page, count, "%d\n",
373 obd->u.obt.obt_qctxt.lqc_sync_blk);
375 EXPORT_SYMBOL(lprocfs_quota_rd_sync_blk);
377 int lprocfs_quota_wr_sync_blk(struct file *file, const char *buffer,
378 unsigned long count, void *data)
380 struct obd_device *obd = (struct obd_device *)data;
382 LASSERT(obd != NULL);
384 rc = lprocfs_write_helper(buffer, count, &val);
391 obd->u.obt.obt_qctxt.lqc_sync_blk = val;
394 EXPORT_SYMBOL(lprocfs_quota_wr_sync_blk);
396 int lprocfs_quota_rd_switch_qs(char *page, char **start, off_t off,
397 int count, int *eof, void *data)
399 struct obd_device *obd = (struct obd_device *)data;
400 LASSERT(obd != NULL);
402 return snprintf(page, count, "changing qunit size is %s\n",
403 obd->u.obt.obt_qctxt.lqc_switch_qs ?
404 "enabled" : "disabled");
406 EXPORT_SYMBOL(lprocfs_quota_rd_switch_qs);
408 int lprocfs_quota_wr_switch_qs(struct file *file, const char *buffer,
409 unsigned long count, void *data)
411 struct obd_device *obd = (struct obd_device *)data;
413 LASSERT(obd != NULL);
415 rc = lprocfs_write_helper(buffer, count, &val);
420 obd->u.obt.obt_qctxt.lqc_switch_qs = 1;
422 obd->u.obt.obt_qctxt.lqc_switch_qs = 0;
426 EXPORT_SYMBOL(lprocfs_quota_wr_switch_qs);
428 int lprocfs_quota_rd_boundary_factor(char *page, char **start, off_t off,
429 int count, int *eof, void *data)
431 struct obd_device *obd = (struct obd_device *)data;
432 LASSERT(obd != NULL);
435 return snprintf(page, count, "%lu\n",
436 obd->u.obt.obt_qctxt.lqc_cqs_boundary_factor);
438 EXPORT_SYMBOL(lprocfs_quota_rd_boundary_factor);
440 int lprocfs_quota_wr_boundary_factor(struct file *file, const char *buffer,
441 unsigned long count, void *data)
443 struct obd_device *obd = (struct obd_device *)data;
445 LASSERT(obd != NULL);
447 rc = lprocfs_write_helper(buffer, count, &val);
454 obd->u.obt.obt_qctxt.lqc_cqs_boundary_factor = val;
457 EXPORT_SYMBOL(lprocfs_quota_wr_boundary_factor);
459 int lprocfs_quota_rd_least_bunit(char *page, char **start, off_t off,
460 int count, int *eof, void *data)
462 struct obd_device *obd = (struct obd_device *)data;
463 LASSERT(obd != NULL);
466 return snprintf(page, count, "%lu\n",
467 obd->u.obt.obt_qctxt.lqc_cqs_least_bunit);
469 EXPORT_SYMBOL(lprocfs_quota_rd_least_bunit);
471 int lprocfs_quota_wr_least_bunit(struct file *file, const char *buffer,
472 unsigned long count, void *data)
474 struct obd_device *obd = (struct obd_device *)data;
476 LASSERT(obd != NULL);
478 rc = lprocfs_write_helper(buffer, count, &val);
482 if (val < PTLRPC_MAX_BRW_SIZE ||
483 val >= obd->u.obt.obt_qctxt.lqc_bunit_sz)
486 obd->u.obt.obt_qctxt.lqc_cqs_least_bunit = val;
489 EXPORT_SYMBOL(lprocfs_quota_wr_least_bunit);
491 int lprocfs_quota_rd_least_iunit(char *page, char **start, off_t off,
492 int count, int *eof, void *data)
494 struct obd_device *obd = (struct obd_device *)data;
495 LASSERT(obd != NULL);
498 return snprintf(page, count, "%lu\n",
499 obd->u.obt.obt_qctxt.lqc_cqs_least_iunit);
501 EXPORT_SYMBOL(lprocfs_quota_rd_least_iunit);
503 int lprocfs_quota_wr_least_iunit(struct file *file, const char *buffer,
504 unsigned long count, void *data)
506 struct obd_device *obd = (struct obd_device *)data;
508 LASSERT(obd != NULL);
510 rc = lprocfs_write_helper(buffer, count, &val);
514 if (val < 1 || val >= obd->u.obt.obt_qctxt.lqc_iunit_sz)
517 obd->u.obt.obt_qctxt.lqc_cqs_least_iunit = val;
520 EXPORT_SYMBOL(lprocfs_quota_wr_least_iunit);
522 int lprocfs_quota_rd_qs_factor(char *page, char **start, off_t off,
523 int count, int *eof, void *data)
525 struct obd_device *obd = (struct obd_device *)data;
526 LASSERT(obd != NULL);
529 return snprintf(page, count, "%lu\n",
530 obd->u.obt.obt_qctxt.lqc_cqs_qs_factor);
532 EXPORT_SYMBOL(lprocfs_quota_rd_qs_factor);
534 int lprocfs_quota_wr_qs_factor(struct file *file, const char *buffer,
535 unsigned long count, void *data)
537 struct obd_device *obd = (struct obd_device *)data;
539 LASSERT(obd != NULL);
541 rc = lprocfs_write_helper(buffer, count, &val);
548 obd->u.obt.obt_qctxt.lqc_cqs_qs_factor = val;
551 EXPORT_SYMBOL(lprocfs_quota_wr_qs_factor);
553 struct lprocfs_vars lprocfs_quota_common_vars[] = {
554 { "quota_bunit_sz", lprocfs_quota_rd_bunit,
555 lprocfs_quota_wr_bunit, 0},
556 { "quota_btune_sz", lprocfs_quota_rd_btune,
557 lprocfs_quota_wr_btune, 0},
558 { "quota_iunit_sz", lprocfs_quota_rd_iunit,
559 lprocfs_quota_wr_iunit, 0},
560 { "quota_itune_sz", lprocfs_quota_rd_itune,
561 lprocfs_quota_wr_itune, 0},
562 { "quota_type", lprocfs_quota_rd_type,
563 lprocfs_quota_wr_type, 0},
564 { "quota_switch_seconds", lprocfs_quota_rd_switch_seconds,
565 lprocfs_quota_wr_switch_seconds, 0 },
566 { "quota_sync_blk", lprocfs_quota_rd_sync_blk,
567 lprocfs_quota_wr_sync_blk, 0},
571 struct lprocfs_vars lprocfs_quota_master_vars[] = {
572 { "quota_switch_qs", lprocfs_quota_rd_switch_qs,
573 lprocfs_quota_wr_switch_qs, 0 },
574 { "quota_boundary_factor", lprocfs_quota_rd_boundary_factor,
575 lprocfs_quota_wr_boundary_factor, 0 },
576 { "quota_least_bunit", lprocfs_quota_rd_least_bunit,
577 lprocfs_quota_wr_least_bunit, 0 },
578 { "quota_least_iunit", lprocfs_quota_rd_least_iunit,
579 lprocfs_quota_wr_least_iunit, 0 },
580 { "quota_qs_factor", lprocfs_quota_rd_qs_factor,
581 lprocfs_quota_wr_qs_factor, 0 },
585 int lquota_proc_setup(struct obd_device *obd, int is_master)
587 struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt;
591 LASSERT(lquota_type_proc_dir && obd);
592 qctxt->lqc_proc_dir = lprocfs_register(obd->obd_name,
593 lquota_type_proc_dir,
594 lprocfs_quota_common_vars, obd);
595 if (IS_ERR(qctxt->lqc_proc_dir)) {
596 rc = PTR_ERR(qctxt->lqc_proc_dir);
597 CERROR("%s: error %d setting up lprocfs\n",
599 qctxt->lqc_proc_dir = NULL;
604 rc = lprocfs_add_vars(qctxt->lqc_proc_dir,
605 lprocfs_quota_master_vars, obd);
607 CERROR("%s: error %d setting up lprocfs for "
608 "quota master\n", obd->obd_name, rc);
609 GOTO(out_free_proc, rc);
613 qctxt->lqc_stats = lprocfs_alloc_stats(LQUOTA_LAST_STAT -
614 LQUOTA_FIRST_STAT, 0);
615 if (!qctxt->lqc_stats)
616 GOTO(out_free_proc, rc = -ENOMEM);
618 lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_SYNC_ACQ,
619 LPROCFS_CNTR_AVGMINMAX, "sync_acq_req", "us");
620 lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_SYNC_REL,
621 LPROCFS_CNTR_AVGMINMAX, "sync_rel_req", "us");
622 lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_ASYNC_ACQ,
623 LPROCFS_CNTR_AVGMINMAX, "async_acq_req", "us");
624 lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_ASYNC_REL,
625 LPROCFS_CNTR_AVGMINMAX, "async_rel_req", "us");
627 lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_WAIT_FOR_CHK_BLK,
628 LPROCFS_CNTR_AVGMINMAX,
629 "wait_for_blk_quota(lquota_chkquota)", "us");
630 lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_WAIT_FOR_CHK_INO,
631 LPROCFS_CNTR_AVGMINMAX,
632 "wait_for_ino_quota(lquota_chkquota)", "us");
633 lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_WAIT_FOR_COMMIT_BLK,
634 LPROCFS_CNTR_AVGMINMAX,
635 "wait_for_blk_quota(lquota_pending_commit)",
637 lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_WAIT_FOR_COMMIT_INO,
638 LPROCFS_CNTR_AVGMINMAX,
639 "wait_for_ino_quota(lquota_pending_commit)",
642 lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_WAIT_PENDING_BLK_QUOTA,
643 LPROCFS_CNTR_AVGMINMAX,
644 "wait_for_pending_blk_quota_req"
645 "(qctxt_wait_pending_dqacq)", "us");
646 lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_WAIT_PENDING_INO_QUOTA,
647 LPROCFS_CNTR_AVGMINMAX,
648 "wait_for_pending_ino_quota_req"
649 "(qctxt_wait_pending_dqacq)", "us");
650 lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_NOWAIT_PENDING_BLK_QUOTA,
651 LPROCFS_CNTR_AVGMINMAX,
652 "nowait_for_pending_blk_quota_req"
653 "(qctxt_wait_pending_dqacq)", "us");
654 lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_NOWAIT_PENDING_INO_QUOTA,
655 LPROCFS_CNTR_AVGMINMAX,
656 "nowait_for_pending_ino_quota_req"
657 "(qctxt_wait_pending_dqacq)", "us");
659 lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_QUOTA_CTL,
660 LPROCFS_CNTR_AVGMINMAX, "quota_ctl", "us");
661 lprocfs_counter_init(qctxt->lqc_stats, LQUOTA_ADJUST_QUNIT,
662 LPROCFS_CNTR_AVGMINMAX, "adjust_qunit", "us");
664 lprocfs_register_stats(qctxt->lqc_proc_dir, "stats", qctxt->lqc_stats);
669 lprocfs_remove(&qctxt->lqc_proc_dir);
674 int lquota_proc_cleanup(struct lustre_quota_ctxt *qctxt)
676 if (!qctxt || !qctxt->lqc_proc_dir)
679 if (qctxt->lqc_stats != NULL)
680 lprocfs_free_stats(&qctxt->lqc_stats);
682 lprocfs_remove(&qctxt->lqc_proc_dir);