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 EXPORT_SYMTAB
39 #define DEBUG_SUBSYSTEM S_MDS
42 # include <linux/version.h>
43 # include <linux/module.h>
44 # include <linux/init.h>
45 # include <linux/fs.h>
46 # include <linux/jbd.h>
47 # include <linux/ext3_fs.h>
48 # include <linux/quota.h>
49 # include <linux/smp_lock.h>
50 # include <linux/buffer_head.h>
51 # include <linux/workqueue.h>
52 # include <linux/mount.h>
53 #else /* __KERNEL__ */
54 # include <liblustre.h>
57 #include <obd_class.h>
58 #include <lustre_mds.h>
59 #include <lustre_dlm.h>
60 #include <lustre_cfg.h>
62 #include <lustre_fsfilt.h>
63 #include <lustre_quota.h>
64 #include "quota_internal.h"
67 int mds_quota_ctl(struct obd_export *exp, struct obd_quotactl *oqctl)
69 struct obd_device *obd = exp->exp_obd;
73 switch (oqctl->qc_cmd) {
75 rc = mds_quota_on(obd, oqctl);
78 mds_quota_off(obd, oqctl);
81 rc = mds_set_dqinfo(obd, oqctl);
84 rc = mds_get_dqinfo(obd, oqctl);
87 rc = mds_set_dqblk(obd, oqctl);
90 rc = mds_get_dqblk(obd, oqctl);
94 rc = mds_get_obd_quota(obd, oqctl);
97 CERROR("%s: unsupported mds_quotactl command: %d\n",
98 obd->obd_name, oqctl->qc_cmd);
103 CDEBUG(D_INFO, "mds_quotactl admin quota command %d, id %u, "
104 "type %d, failed: rc = %d\n",
105 oqctl->qc_cmd, oqctl->qc_id, oqctl->qc_type, rc);
110 int filter_quota_ctl(struct obd_export *exp, struct obd_quotactl *oqctl)
112 struct obd_device *obd = exp->exp_obd;
113 struct obd_device_target *obt = &obd->u.obt;
114 struct lvfs_run_ctxt saved;
118 switch (oqctl->qc_cmd) {
121 if (!atomic_dec_and_test(&obt->obt_quotachecking)) {
122 CDEBUG(D_INFO, "other people are doing quotacheck\n");
123 atomic_inc(&obt->obt_quotachecking);
130 /* In recovery scenario, this pending dqacq/dqrel might have
131 * been processed by master successfully before it's dquot
132 * on master enter recovery mode. We must wait for this
133 * dqacq/dqrel done then return the correct limits to master */
134 if (oqctl->qc_stat == QUOTA_RECOVERING)
135 qctxt_wait_pending_dqacq(&obd->u.obt.obt_qctxt,
136 oqctl->qc_id, oqctl->qc_type,
139 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
140 rc = fsfilt_quotactl(obd, obd->u.obt.obt_sb, oqctl);
141 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
143 if (oqctl->qc_cmd == Q_QUOTAON || oqctl->qc_cmd == Q_QUOTAOFF) {
145 obt->obt_qctxt.lqc_status =
146 (oqctl->qc_cmd == Q_QUOTAON) ? 1 : 0;
147 atomic_inc(&obt->obt_quotachecking);
151 qctxt_wait_pending_dqacq(&obd->u.obt.obt_qctxt,
152 oqctl->qc_id, oqctl->qc_type, 1);
154 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
155 rc = fsfilt_quotactl(obd, obd->u.obt.obt_sb, oqctl);
158 oqctl->qc_cmd = Q_SYNC;
159 fsfilt_quotactl(obd, obd->u.obt.obt_sb, oqctl);
160 oqctl->qc_cmd = Q_SETQUOTA;
162 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
166 unsigned int uid = 0, gid = 0;
168 /* Initialize quota limit to MIN_QLIMIT */
169 LASSERT(oqctl->qc_dqblk.dqb_valid == QIF_BLIMITS);
170 LASSERT(oqctl->qc_dqblk.dqb_bsoftlimit == 0);
172 /* There might be a pending dqacq/dqrel (which is going to
173 * clear stale limits on slave). we should wait for it's
174 * completion then initialize limits */
175 qctxt_wait_pending_dqacq(&obd->u.obt.obt_qctxt,
176 oqctl->qc_id, oqctl->qc_type, 1);
178 if (!oqctl->qc_dqblk.dqb_bhardlimit)
181 LASSERT(oqctl->qc_dqblk.dqb_bhardlimit == MIN_QLIMIT);
182 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
183 rc = fsfilt_quotactl(obd, obd->u.obt.obt_sb, oqctl);
185 /* Update on-disk quota, in case of lose the changed limits
186 * (MIN_QLIMIT) on crash, which cannot be recovered.*/
188 oqctl->qc_cmd = Q_SYNC;
189 fsfilt_quotactl(obd, obd->u.obt.obt_sb, oqctl);
190 oqctl->qc_cmd = Q_INITQUOTA;
192 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
197 /* Trigger qunit pre-acquire */
198 if (oqctl->qc_type == USRQUOTA)
203 rc = qctxt_adjust_qunit(obd, &obd->u.obt.obt_qctxt,
208 CERROR("%s: unsupported filter_quotactl command: %d\n",
209 obd->obd_name, oqctl->qc_cmd);
215 #endif /* __KERNEL__ */
217 int client_quota_ctl(struct obd_export *exp, struct obd_quotactl *oqctl)
219 struct ptlrpc_request *req;
220 struct obd_quotactl *oqc;
224 if (!strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_MDC_NAME)) {
225 ver = LUSTRE_MDS_VERSION,
227 } else if (!strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_OSC_NAME)) {
228 ver = LUSTRE_OST_VERSION,
234 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
235 &RQF_MDS_QUOTACTL, ver, opc);
239 oqc = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
242 ptlrpc_request_set_replen(req);
244 rc = ptlrpc_queue_wait(req);
246 oqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
248 GOTO(out, rc = -EPROTO);
253 ptlrpc_req_finished(req);
257 int lov_quota_ctl(struct obd_export *exp, struct obd_quotactl *oqctl)
259 struct obd_device *obd = class_exp2obd(exp);
260 struct lov_obd *lov = &obd->u.lov;
262 __u32 bhardlimit = 0;
266 if (oqctl->qc_cmd != Q_QUOTAON && oqctl->qc_cmd != Q_QUOTAOFF &&
267 oqctl->qc_cmd != Q_GETOQUOTA && oqctl->qc_cmd != Q_INITQUOTA &&
268 oqctl->qc_cmd != Q_SETQUOTA) {
269 CERROR("bad quota opc %x for lov obd", oqctl->qc_cmd);
273 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
276 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active) {
277 if (oqctl->qc_cmd == Q_GETOQUOTA) {
278 CERROR("ost %d is inactive\n", i);
282 CDEBUG(D_HA, "ost %d is inactive\n", i);
287 err = obd_quotactl(lov->lov_tgts[i]->ltd_exp, oqctl);
289 if (lov->lov_tgts[i]->ltd_active && !rc)
294 if (oqctl->qc_cmd == Q_GETOQUOTA) {
295 curspace += oqctl->qc_dqblk.dqb_curspace;
296 bhardlimit += oqctl->qc_dqblk.dqb_bhardlimit;
300 if (oqctl->qc_cmd == Q_GETOQUOTA) {
301 oqctl->qc_dqblk.dqb_curspace = curspace;
302 oqctl->qc_dqblk.dqb_bhardlimit = bhardlimit;