Whamcloud - gitweb
not send LOV EA under replay, we can't know about they size at this
[fs/lustre-release.git] / lustre / mdd / mdd_quota.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
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.
11  *
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).
17  *
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
21  *
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
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/mdd/mdd_quota.c
37  *
38  * Lustre Metadata Server (mdd) routines
39  *
40  * Author: Fan Yong <Yong.Fan@Sun.Com>
41  */
42
43 #ifdef HAVE_QUOTA_SUPPORT
44
45 #include "mdd_internal.h"
46
47 int mdd_quota_notify(const struct lu_env *env, struct md_device *m)
48 {
49         struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
50         struct obd_device *obd = mdd->mdd_obd_dev;
51         ENTRY;
52
53         lquota_setinfo(mds_quota_interface_ref, obd, (void *)1);
54         RETURN(0);
55 }
56
57 int mdd_quota_setup(const struct lu_env *env, struct md_device *m,
58                     void *data)
59 {
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;
63         int rc;
64         ENTRY;
65
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);
69         RETURN(rc);
70 }
71
72 int mdd_quota_cleanup(const struct lu_env *env, struct md_device *m)
73 {
74         struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
75         struct obd_device *obd = mdd->mdd_obd_dev;
76         int rc1, rc2;
77         ENTRY;
78
79         rc1 = lquota_cleanup(mds_quota_interface_ref, obd);
80         rc2 = lquota_fs_cleanup(mds_quota_interface_ref, obd);
81         RETURN(rc1 ? : rc2);
82 }
83
84 int mdd_quota_recovery(const struct lu_env *env, struct md_device *m)
85 {
86         struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
87         struct obd_device *obd = mdd->mdd_obd_dev;
88         int rc;
89         ENTRY;
90
91         rc = lquota_recovery(mds_quota_interface_ref, obd);
92         RETURN(rc);
93 }
94
95 int mdd_quota_check(const struct lu_env *env, struct md_device *m,
96                     struct obd_export *exp, __u32 type)
97 {
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;
101         int rc;
102         ENTRY;
103
104         oqctl->qc_type = type;
105         rc = lquota_check(mds_quota_interface_ref, obd, exp, oqctl);
106         RETURN(rc);
107 }
108
109 int mdd_quota_on(const struct lu_env *env, struct md_device *m,
110                  __u32 type, __u32 id)
111 {
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;
115         int rc;
116         ENTRY;
117
118         oqctl->qc_cmd = Q_QUOTAON;
119         oqctl->qc_type = type;
120         oqctl->qc_id = id;
121         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
122         RETURN(rc);
123 }
124
125 int mdd_quota_off(const struct lu_env *env, struct md_device *m,
126                   __u32 type, __u32 id)
127 {
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;
131         int rc;
132         ENTRY;
133
134         oqctl->qc_cmd = Q_QUOTAOFF;
135         oqctl->qc_type = type;
136         oqctl->qc_id = id;
137         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
138         RETURN(rc);
139 }
140
141 int mdd_quota_setinfo(const struct lu_env *env, struct md_device *m,
142                       __u32 type, __u32 id, struct obd_dqinfo *dqinfo)
143 {
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;
147         int rc;
148         ENTRY;
149
150         oqctl->qc_cmd = Q_SETINFO;
151         oqctl->qc_type = type;
152         oqctl->qc_id = id;
153         oqctl->qc_dqinfo = *dqinfo;
154         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
155         RETURN(rc);
156 }
157
158 int mdd_quota_getinfo(const struct lu_env *env, const struct md_device *m,
159                       __u32 type, __u32 id, struct obd_dqinfo *dqinfo)
160 {
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;
165         int rc;
166         ENTRY;
167
168         oqctl->qc_cmd = Q_GETINFO;
169         oqctl->qc_type = type;
170         oqctl->qc_id = id;
171         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
172         *dqinfo = oqctl->qc_dqinfo;
173         RETURN(rc);
174 }
175
176 int mdd_quota_setquota(const struct lu_env *env, struct md_device *m,
177                        __u32 type, __u32 id, struct obd_dqblk *dqblk)
178 {
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;
182         int rc;
183         ENTRY;
184
185         oqctl->qc_cmd = Q_SETQUOTA;
186         oqctl->qc_type = type;
187         oqctl->qc_id = id;
188         oqctl->qc_dqblk = *dqblk;
189         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
190         RETURN(rc);
191 }
192
193 int mdd_quota_getquota(const struct lu_env *env, const struct md_device *m,
194                        __u32 type, __u32 id, struct obd_dqblk *dqblk)
195 {
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;
200         int rc;
201         ENTRY;
202
203         oqctl->qc_cmd = Q_GETQUOTA;
204         oqctl->qc_type = type;
205         oqctl->qc_id = id;
206         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
207         *dqblk = oqctl->qc_dqblk;
208         RETURN(rc);
209 }
210
211 int mdd_quota_getoinfo(const struct lu_env *env, const struct md_device *m,
212                        __u32 type, __u32 id, struct obd_dqinfo *dqinfo)
213 {
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;
218         int rc;
219         ENTRY;
220
221         oqctl->qc_cmd = Q_GETOINFO;
222         oqctl->qc_type = type;
223         oqctl->qc_id = id;
224         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
225         *dqinfo = oqctl->qc_dqinfo;
226         RETURN(rc);
227 }
228
229 int mdd_quota_getoquota(const struct lu_env *env, const struct md_device *m,
230                         __u32 type, __u32 id, struct obd_dqblk *dqblk)
231 {
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;
236         int rc;
237         ENTRY;
238
239         oqctl->qc_cmd = Q_GETOQUOTA;
240         oqctl->qc_type = type;
241         oqctl->qc_id = id;
242         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
243         *dqblk = oqctl->qc_dqblk;
244         RETURN(rc);
245 }
246
247 int mdd_quota_invalidate(const struct lu_env *env, struct md_device *m,
248                          __u32 type)
249 {
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;
253         int rc;
254         ENTRY;
255
256         oqctl->qc_cmd = LUSTRE_Q_INVALIDATE;
257         oqctl->qc_type = type;
258         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
259         RETURN(rc);
260 }
261
262 int mdd_quota_finvalidate(const struct lu_env *env, struct md_device *m,
263                           __u32 type)
264 {
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;
268         int rc;
269         ENTRY;
270
271         oqctl->qc_cmd = LUSTRE_Q_FINVALIDATE;
272         oqctl->qc_type = type;
273         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
274         RETURN(rc);
275 }
276 #endif