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.
36 * lustre/mdd/mdd_quota.c
38 * Lustre Metadata Server (mdd) routines
40 * Author: Fan Yong <Yong.Fan@Sun.Com>
43 #ifdef HAVE_QUOTA_SUPPORT
45 #include "mdd_internal.h"
47 int mdd_quota_notify(const struct lu_env *env, struct md_device *m)
49 struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
50 struct obd_device *obd = mdd->mdd_obd_dev;
53 lquota_setinfo(mds_quota_interface_ref, obd, (void *)1);
57 int mdd_quota_setup(const struct lu_env *env, struct md_device *m,
60 struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
61 struct obd_device *obd = mdd->mdd_obd_dev;
62 struct dt_device *dt = mdd->mdd_child;
66 LASSERT(obd->obd_fsops != NULL);
67 dt->dd_ops->dt_init_quota_ctxt(env, dt, (void *)obd, data);
68 rc = lquota_setup(mds_quota_interface_ref, obd);
72 int mdd_quota_cleanup(const struct lu_env *env, struct md_device *m)
74 struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
75 struct obd_device *obd = mdd->mdd_obd_dev;
79 rc1 = lquota_cleanup(mds_quota_interface_ref, obd);
80 rc2 = lquota_fs_cleanup(mds_quota_interface_ref, obd);
84 int mdd_quota_recovery(const struct lu_env *env, struct md_device *m)
86 struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
87 struct obd_device *obd = mdd->mdd_obd_dev;
91 rc = lquota_recovery(mds_quota_interface_ref, obd);
95 int mdd_quota_check(const struct lu_env *env, struct md_device *m,
96 struct obd_export *exp, __u32 type)
98 struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
99 struct obd_device *obd = mdd->mdd_obd_dev;
100 struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
104 oqctl->qc_type = type;
105 rc = lquota_check(mds_quota_interface_ref, obd, exp, oqctl);
109 int mdd_quota_on(const struct lu_env *env, struct md_device *m,
110 __u32 type, __u32 id)
112 struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
113 struct obd_device *obd = mdd->mdd_obd_dev;
114 struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
118 oqctl->qc_cmd = Q_QUOTAON;
119 oqctl->qc_type = type;
121 rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
125 int mdd_quota_off(const struct lu_env *env, struct md_device *m,
126 __u32 type, __u32 id)
128 struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
129 struct obd_device *obd = mdd->mdd_obd_dev;
130 struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
134 oqctl->qc_cmd = Q_QUOTAOFF;
135 oqctl->qc_type = type;
137 rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
141 int mdd_quota_setinfo(const struct lu_env *env, struct md_device *m,
142 __u32 type, __u32 id, struct obd_dqinfo *dqinfo)
144 struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
145 struct obd_device *obd = mdd->mdd_obd_dev;
146 struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
150 oqctl->qc_cmd = Q_SETINFO;
151 oqctl->qc_type = type;
153 oqctl->qc_dqinfo = *dqinfo;
154 rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
158 int mdd_quota_getinfo(const struct lu_env *env, const struct md_device *m,
159 __u32 type, __u32 id, struct obd_dqinfo *dqinfo)
161 struct mdd_device *mdd = lu2mdd_dev(
162 &((struct md_device *)m)->md_lu_dev);
163 struct obd_device *obd = mdd->mdd_obd_dev;
164 struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
168 oqctl->qc_cmd = Q_GETINFO;
169 oqctl->qc_type = type;
171 rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
172 *dqinfo = oqctl->qc_dqinfo;
176 int mdd_quota_setquota(const struct lu_env *env, struct md_device *m,
177 __u32 type, __u32 id, struct obd_dqblk *dqblk)
179 struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
180 struct obd_device *obd = mdd->mdd_obd_dev;
181 struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
185 oqctl->qc_cmd = Q_SETQUOTA;
186 oqctl->qc_type = type;
188 oqctl->qc_dqblk = *dqblk;
189 rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
193 int mdd_quota_getquota(const struct lu_env *env, const struct md_device *m,
194 __u32 type, __u32 id, struct obd_dqblk *dqblk)
196 struct mdd_device *mdd = lu2mdd_dev(
197 &((struct md_device *)m)->md_lu_dev);
198 struct obd_device *obd = mdd->mdd_obd_dev;
199 struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
203 oqctl->qc_cmd = Q_GETQUOTA;
204 oqctl->qc_type = type;
206 rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
207 *dqblk = oqctl->qc_dqblk;
211 int mdd_quota_getoinfo(const struct lu_env *env, const struct md_device *m,
212 __u32 type, __u32 id, struct obd_dqinfo *dqinfo)
214 struct mdd_device *mdd = lu2mdd_dev(
215 &((struct md_device *)m)->md_lu_dev);
216 struct obd_device *obd = mdd->mdd_obd_dev;
217 struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
221 oqctl->qc_cmd = Q_GETOINFO;
222 oqctl->qc_type = type;
224 rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
225 *dqinfo = oqctl->qc_dqinfo;
229 int mdd_quota_getoquota(const struct lu_env *env, const struct md_device *m,
230 __u32 type, __u32 id, struct obd_dqblk *dqblk)
232 struct mdd_device *mdd = lu2mdd_dev(
233 &((struct md_device *)m)->md_lu_dev);
234 struct obd_device *obd = mdd->mdd_obd_dev;
235 struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
239 oqctl->qc_cmd = Q_GETOQUOTA;
240 oqctl->qc_type = type;
242 rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
243 *dqblk = oqctl->qc_dqblk;
247 int mdd_quota_invalidate(const struct lu_env *env, struct md_device *m,
250 struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
251 struct obd_device *obd = mdd->mdd_obd_dev;
252 struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
256 oqctl->qc_cmd = LUSTRE_Q_INVALIDATE;
257 oqctl->qc_type = type;
258 rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
262 int mdd_quota_finvalidate(const struct lu_env *env, struct md_device *m,
265 struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
266 struct obd_device *obd = mdd->mdd_obd_dev;
267 struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
271 oqctl->qc_cmd = LUSTRE_Q_FINVALIDATE;
272 oqctl->qc_type = type;
273 rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);