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 <linux/obd_class.h>
39 #include <linux/lustre_mds.h>
40 #include <linux/lustre_dlm.h>
41 #include <linux/lustre_cfg.h>
42 #include <linux/obd_ost.h>
43 #include <linux/lustre_fsfilt.h>
44 #include <linux/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 lvfs_run_ctxt saved;
98 switch (oqctl->qc_cmd) {
104 /* In recovery scenario, this pending dqacq/dqrel might have
105 * been processed by master successfully before it's dquot
106 * on master enter recovery mode. We must wait for this
107 * dqacq/dqrel done then return the correct limits to master */
108 if (oqctl->qc_stat == QUOTA_RECOVERING)
109 qctxt_wait_pending_dqacq(&obd->u.obt.obt_qctxt,
110 oqctl->qc_id, oqctl->qc_type,
113 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
114 rc = fsfilt_quotactl(obd, obd->u.obt.obt_sb, oqctl);
115 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
119 unsigned int uid = 0, gid = 0;
121 /* Initialize quota limit to MIN_QLIMIT */
122 LASSERT(oqctl->qc_dqblk.dqb_valid == QIF_BLIMITS);
123 LASSERT(oqctl->qc_dqblk.dqb_bsoftlimit == 0);
125 /* There might be a pending dqacq/dqrel (which is going to
126 * clear stale limits on slave). we should wait for it's
127 * completion then initialize limits */
128 qctxt_wait_pending_dqacq(&obd->u.obt.obt_qctxt,
129 oqctl->qc_id, oqctl->qc_type, 1);
131 if (!oqctl->qc_dqblk.dqb_bhardlimit)
134 LASSERT(oqctl->qc_dqblk.dqb_bhardlimit == MIN_QLIMIT);
135 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
136 rc = fsfilt_quotactl(obd, obd->u.obt.obt_sb, oqctl);
138 /* Update on-disk quota, in case of lose the changed limits
139 * (MIN_QLIMIT) on crash, which cannot be recovered.*/
141 oqctl->qc_cmd = Q_SYNC;
142 fsfilt_quotactl(obd, obd->u.obt.obt_sb, oqctl);
143 oqctl->qc_cmd = Q_INITQUOTA;
145 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
150 /* Trigger qunit pre-acquire */
151 if (oqctl->qc_type == USRQUOTA)
156 rc = qctxt_adjust_qunit(obd, &obd->u.obt.obt_qctxt,
161 CERROR("%s: unsupported filter_quotactl command: %d\n",
162 obd->obd_name, oqctl->qc_cmd);
168 #endif /* __KERNEL__ */
170 int client_quota_ctl(struct obd_export *exp, struct obd_quotactl *oqctl)
172 struct ptlrpc_request *req;
173 struct obd_quotactl *oqc;
174 int size = sizeof(*oqctl), opc, version;
178 if (!strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_MDC_NAME)) {
180 version = LUSTRE_MDS_VERSION;
181 } else if (!strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_OSC_NAME)) {
183 version = LUSTRE_OST_VERSION;
188 req = ptlrpc_prep_req(class_exp2cliimp(exp), version, opc, 1, &size,
191 GOTO(out, rc = -ENOMEM);
193 oqc = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*oqctl));
196 req->rq_replen = lustre_msg_size(1, &size);
198 rc = ptlrpc_queue_wait(req);
200 oqc = lustre_swab_repbuf(req, 0, sizeof (*oqc),
201 lustre_swab_obd_quotactl);
203 CERROR ("Can't unpack obd_quotactl\n");
204 GOTO(out, rc = -EPROTO);
210 ptlrpc_req_finished(req);
214 int lov_quota_ctl(struct obd_export *exp, struct obd_quotactl *oqctl)
216 struct obd_device *obd = class_exp2obd(exp);
217 struct lov_obd *lov = &obd->u.lov;
219 __u32 bhardlimit = 0;
223 if (oqctl->qc_cmd != Q_QUOTAON && oqctl->qc_cmd != Q_QUOTAOFF &&
224 oqctl->qc_cmd != Q_GETOQUOTA && oqctl->qc_cmd != Q_INITQUOTA) {
225 CERROR("bad quota opc %x for lov obd", oqctl->qc_cmd);
229 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
232 if (!lov->tgts[i].active) {
233 if (oqctl->qc_cmd == Q_GETOQUOTA) {
234 CERROR("ost %d is inactive\n", i);
238 CDEBUG(D_HA, "ost %d is inactive\n", i);
243 err = obd_quotactl(lov->tgts[i].ltd_exp, oqctl);
245 if (lov->tgts[i].active && !rc)
250 if (oqctl->qc_cmd == Q_GETOQUOTA) {
251 curspace += oqctl->qc_dqblk.dqb_curspace;
252 bhardlimit += oqctl->qc_dqblk.dqb_bhardlimit;
256 if (oqctl->qc_cmd == Q_GETOQUOTA) {
257 oqctl->qc_dqblk.dqb_curspace = curspace;
258 oqctl->qc_dqblk.dqb_bhardlimit = bhardlimit;