1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * lustre/quota/quota_ctl.c
6 * Copyright (c) 2005 Cluster File Systems, Inc.
8 * This file is part of Lustre, http://www.lustre.org.
10 * No redistribution or use is permitted outside of Cluster File Systems, Inc.
14 # define EXPORT_SYMTAB
16 #define DEBUG_SUBSYSTEM S_MDS
19 # include <linux/version.h>
20 # include <linux/module.h>
21 # include <linux/init.h>
22 # include <linux/fs.h>
23 # include <linux/jbd.h>
24 # include <linux/ext3_fs.h>
25 # include <linux/quota.h>
26 # if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
27 # include <linux/smp_lock.h>
28 # include <linux/buffer_head.h>
29 # include <linux/workqueue.h>
30 # include <linux/mount.h>
32 # include <linux/locks.h>
34 #else /* __KERNEL__ */
35 # include <liblustre.h>
38 #include <obd_class.h>
39 #include <lustre_mds.h>
40 #include <lustre_dlm.h>
41 #include <lustre_cfg.h>
43 #include <lustre_fsfilt.h>
44 #include <lustre_quota.h>
45 #include "quota_internal.h"
48 int mds_quota_ctl(struct obd_export *exp, struct obd_quotactl *oqctl)
50 struct obd_device *obd = exp->exp_obd;
54 switch (oqctl->qc_cmd) {
56 rc = mds_quota_on(obd, oqctl);
59 mds_quota_off(obd, oqctl);
62 rc = mds_set_dqinfo(obd, oqctl);
65 rc = mds_get_dqinfo(obd, oqctl);
68 rc = mds_set_dqblk(obd, oqctl);
71 rc = mds_get_dqblk(obd, oqctl);
75 rc = mds_get_obd_quota(obd, oqctl);
78 CERROR("%s: unsupported mds_quotactl command: %d\n",
79 obd->obd_name, oqctl->qc_cmd);
84 CDEBUG(D_INFO, "mds_quotactl admin quota command %d, id %u, "
85 "type %d, failed: rc = %d\n",
86 oqctl->qc_cmd, oqctl->qc_id, oqctl->qc_type, rc);
91 int filter_quota_ctl(struct obd_export *exp, struct obd_quotactl *oqctl)
93 struct obd_device *obd = exp->exp_obd;
94 struct obd_device_target *obt = &obd->u.obt;
95 struct lvfs_run_ctxt saved;
99 switch (oqctl->qc_cmd) {
102 if (!atomic_dec_and_test(&obt->obt_quotachecking)) {
103 CDEBUG(D_INFO, "other people are doing quotacheck\n");
104 atomic_inc(&obt->obt_quotachecking);
111 /* In recovery scenario, this pending dqacq/dqrel might have
112 * been processed by master successfully before it's dquot
113 * on master enter recovery mode. We must wait for this
114 * dqacq/dqrel done then return the correct limits to master */
115 if (oqctl->qc_stat == QUOTA_RECOVERING)
116 qctxt_wait_pending_dqacq(&obd->u.obt.obt_qctxt,
117 oqctl->qc_id, oqctl->qc_type,
120 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
121 rc = fsfilt_quotactl(obd, obd->u.obt.obt_sb, oqctl);
122 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
124 if (oqctl->qc_cmd == Q_QUOTAON || oqctl->qc_cmd == Q_QUOTAOFF) {
126 obt->obt_qctxt.lqc_status =
127 (oqctl->qc_cmd == Q_QUOTAON) ? 1 : 0;
128 atomic_inc(&obt->obt_quotachecking);
133 unsigned int uid = 0, gid = 0;
135 /* Initialize quota limit to MIN_QLIMIT */
136 LASSERT(oqctl->qc_dqblk.dqb_valid == QIF_BLIMITS);
137 LASSERT(oqctl->qc_dqblk.dqb_bsoftlimit == 0);
139 /* There might be a pending dqacq/dqrel (which is going to
140 * clear stale limits on slave). we should wait for it's
141 * completion then initialize limits */
142 qctxt_wait_pending_dqacq(&obd->u.obt.obt_qctxt,
143 oqctl->qc_id, oqctl->qc_type, 1);
145 if (!oqctl->qc_dqblk.dqb_bhardlimit)
148 LASSERT(oqctl->qc_dqblk.dqb_bhardlimit == MIN_QLIMIT);
149 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
150 rc = fsfilt_quotactl(obd, obd->u.obt.obt_sb, oqctl);
152 /* Update on-disk quota, in case of lose the changed limits
153 * (MIN_QLIMIT) on crash, which cannot be recovered.*/
155 oqctl->qc_cmd = Q_SYNC;
156 fsfilt_quotactl(obd, obd->u.obt.obt_sb, oqctl);
157 oqctl->qc_cmd = Q_INITQUOTA;
159 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
164 /* Trigger qunit pre-acquire */
165 if (oqctl->qc_type == USRQUOTA)
170 rc = qctxt_adjust_qunit(obd, &obd->u.obt.obt_qctxt,
175 CERROR("%s: unsupported filter_quotactl command: %d\n",
176 obd->obd_name, oqctl->qc_cmd);
182 #endif /* __KERNEL__ */
184 int client_quota_ctl(struct obd_export *exp, struct obd_quotactl *oqctl)
186 struct ptlrpc_request *req;
187 struct obd_quotactl *oqc;
188 int size[2] = { sizeof(struct ptlrpc_body), sizeof(*oqctl) };
192 if (!strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_MDC_NAME)) {
193 ver = LUSTRE_MDS_VERSION,
195 } else if (!strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_OSC_NAME)) {
196 ver = LUSTRE_OST_VERSION,
202 req = ptlrpc_prep_req(class_exp2cliimp(exp), ver, opc, 2, size, NULL);
204 GOTO(out, rc = -ENOMEM);
206 oqc = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*oqctl));
209 ptlrpc_req_set_repsize(req, 2, size);
211 rc = ptlrpc_queue_wait(req);
213 oqc = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*oqc),
214 lustre_swab_obd_quotactl);
216 CERROR ("Can't unpack obd_quotactl\n");
217 GOTO(out, rc = -EPROTO);
223 ptlrpc_req_finished(req);
227 int lov_quota_ctl(struct obd_export *exp, struct obd_quotactl *oqctl)
229 struct obd_device *obd = class_exp2obd(exp);
230 struct lov_obd *lov = &obd->u.lov;
232 __u32 bhardlimit = 0;
236 if (oqctl->qc_cmd != Q_QUOTAON && oqctl->qc_cmd != Q_QUOTAOFF &&
237 oqctl->qc_cmd != Q_GETOQUOTA && oqctl->qc_cmd != Q_INITQUOTA) {
238 CERROR("bad quota opc %x for lov obd", oqctl->qc_cmd);
242 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
245 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active) {
246 if (oqctl->qc_cmd == Q_GETOQUOTA) {
247 CERROR("ost %d is inactive\n", i);
251 CDEBUG(D_HA, "ost %d is inactive\n", i);
256 err = obd_quotactl(lov->lov_tgts[i]->ltd_exp, oqctl);
258 if (lov->lov_tgts[i]->ltd_active && !rc)
263 if (oqctl->qc_cmd == Q_GETOQUOTA) {
264 curspace += oqctl->qc_dqblk.dqb_curspace;
265 bhardlimit += oqctl->qc_dqblk.dqb_bhardlimit;
269 if (oqctl->qc_cmd == Q_GETOQUOTA) {
270 oqctl->qc_dqblk.dqb_curspace = curspace;
271 oqctl->qc_dqblk.dqb_bhardlimit = bhardlimit;