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,
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;
120 rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
124 int mdd_quota_off(const struct lu_env *env, struct md_device *m,
127 struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
128 struct obd_device *obd = mdd->mdd_obd_dev;
129 struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
133 oqctl->qc_cmd = Q_QUOTAOFF;
134 oqctl->qc_type = type;
135 rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
139 int mdd_quota_setinfo(const struct lu_env *env, struct md_device *m,
140 __u32 type, __u32 id, struct obd_dqinfo *dqinfo)
142 struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
143 struct obd_device *obd = mdd->mdd_obd_dev;
144 struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
148 oqctl->qc_cmd = Q_SETINFO;
149 oqctl->qc_type = type;
151 oqctl->qc_dqinfo = *dqinfo;
152 rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
156 int mdd_quota_getinfo(const struct lu_env *env, const struct md_device *m,
157 __u32 type, __u32 id, struct obd_dqinfo *dqinfo)
159 struct mdd_device *mdd = lu2mdd_dev(
160 &((struct md_device *)m)->md_lu_dev);
161 struct obd_device *obd = mdd->mdd_obd_dev;
162 struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
166 oqctl->qc_cmd = Q_GETINFO;
167 oqctl->qc_type = type;
169 rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
170 *dqinfo = oqctl->qc_dqinfo;
174 int mdd_quota_setquota(const struct lu_env *env, struct md_device *m,
175 __u32 type, __u32 id, struct obd_dqblk *dqblk)
177 struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
178 struct obd_device *obd = mdd->mdd_obd_dev;
179 struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
183 oqctl->qc_cmd = Q_SETQUOTA;
184 oqctl->qc_type = type;
186 oqctl->qc_dqblk = *dqblk;
187 rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
191 int mdd_quota_getquota(const struct lu_env *env, const struct md_device *m,
192 __u32 type, __u32 id, struct obd_dqblk *dqblk)
194 struct mdd_device *mdd = lu2mdd_dev(
195 &((struct md_device *)m)->md_lu_dev);
196 struct obd_device *obd = mdd->mdd_obd_dev;
197 struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
201 oqctl->qc_cmd = Q_GETQUOTA;
202 oqctl->qc_type = type;
204 rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
205 *dqblk = oqctl->qc_dqblk;
209 int mdd_quota_getoinfo(const struct lu_env *env, const struct md_device *m,
210 __u32 type, __u32 id, struct obd_dqinfo *dqinfo)
212 struct mdd_device *mdd = lu2mdd_dev(
213 &((struct md_device *)m)->md_lu_dev);
214 struct obd_device *obd = mdd->mdd_obd_dev;
215 struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
219 oqctl->qc_cmd = Q_GETOINFO;
220 oqctl->qc_type = type;
222 rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
223 *dqinfo = oqctl->qc_dqinfo;
227 int mdd_quota_getoquota(const struct lu_env *env, const struct md_device *m,
228 __u32 type, __u32 id, struct obd_dqblk *dqblk)
230 struct mdd_device *mdd = lu2mdd_dev(
231 &((struct md_device *)m)->md_lu_dev);
232 struct obd_device *obd = mdd->mdd_obd_dev;
233 struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
237 oqctl->qc_cmd = Q_GETOQUOTA;
238 oqctl->qc_type = type;
240 rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
241 *dqblk = oqctl->qc_dqblk;
245 int mdd_quota_invalidate(const struct lu_env *env, struct md_device *m,
248 struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
249 struct obd_device *obd = mdd->mdd_obd_dev;
250 struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
254 oqctl->qc_cmd = LUSTRE_Q_INVALIDATE;
255 oqctl->qc_type = type;
256 rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
260 int mdd_quota_finvalidate(const struct lu_env *env, struct md_device *m,
263 struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
264 struct obd_device *obd = mdd->mdd_obd_dev;
265 struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
269 oqctl->qc_cmd = LUSTRE_Q_FINVALIDATE;
270 oqctl->qc_type = type;
271 rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);