Whamcloud - gitweb
LU-2007 ldlm: reconnect can be racy
[fs/lustre-release.git] / lustre / mdd / mdd_quota.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  */
30 /*
31  * This file is part of Lustre, http://www.lustre.org/
32  * Lustre is a trademark of Sun Microsystems, Inc.
33  *
34  * lustre/mdd/mdd_quota.c
35  *
36  * Lustre Metadata Server (mdd) routines
37  *
38  * Author: Fan Yong <Yong.Fan@Sun.Com>
39  */
40
41 #ifdef HAVE_QUOTA_SUPPORT
42
43 #include "mdd_internal.h"
44
45 int mdd_quota_notify(const struct lu_env *env, struct md_device *m)
46 {
47         struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
48         struct obd_device *obd = mdd->mdd_obd_dev;
49         ENTRY;
50
51         lquota_setinfo(mds_quota_interface_ref, obd, (void *)1);
52         RETURN(0);
53 }
54
55 int mdd_quota_setup(const struct lu_env *env, struct md_device *m,
56                     void *data)
57 {
58         struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
59         struct obd_device *obd = mdd->mdd_obd_dev;
60         struct dt_device *dt = mdd->mdd_child;
61         int rc;
62         ENTRY;
63
64         LASSERT(obd->obd_fsops != NULL);
65         dt->dd_ops->dt_init_quota_ctxt(env, dt, (void *)obd, data);
66         rc = lquota_setup(mds_quota_interface_ref, obd);
67         RETURN(rc);
68 }
69
70 int mdd_quota_cleanup(const struct lu_env *env, struct md_device *m)
71 {
72         struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
73         struct obd_device *obd = mdd->mdd_obd_dev;
74         int rc1, rc2;
75         ENTRY;
76
77         rc1 = lquota_cleanup(mds_quota_interface_ref, obd);
78         rc2 = lquota_fs_cleanup(mds_quota_interface_ref, obd);
79         RETURN(rc1 ? : rc2);
80 }
81
82 int mdd_quota_recovery(const struct lu_env *env, struct md_device *m)
83 {
84         struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
85         struct obd_device *obd = mdd->mdd_obd_dev;
86         int rc;
87         ENTRY;
88
89         rc = lquota_recovery(mds_quota_interface_ref, obd);
90         RETURN(rc);
91 }
92
93 int mdd_quota_check(const struct lu_env *env, struct md_device *m,
94                     __u32 type)
95 {
96         struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
97         struct obd_device *obd = mdd->mdd_obd_dev;
98         struct obd_export *exp = md_quota(env)->mq_exp;
99         struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
100         int rc;
101         ENTRY;
102
103         oqctl->qc_type = type;
104         rc = lquota_check(mds_quota_interface_ref, obd, exp, oqctl);
105         RETURN(rc);
106 }
107
108 int mdd_quota_on(const struct lu_env *env, struct md_device *m,
109                  __u32 type)
110 {
111         struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
112         struct obd_device *obd = mdd->mdd_obd_dev;
113         struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
114         int rc;
115         ENTRY;
116
117         oqctl->qc_cmd = Q_QUOTAON;
118         oqctl->qc_type = type;
119         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
120         RETURN(rc);
121 }
122
123 int mdd_quota_off(const struct lu_env *env, struct md_device *m,
124                   __u32 type)
125 {
126         struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
127         struct obd_device *obd = mdd->mdd_obd_dev;
128         struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
129         int rc;
130         ENTRY;
131
132         oqctl->qc_cmd = Q_QUOTAOFF;
133         oqctl->qc_type = type;
134         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
135         RETURN(rc);
136 }
137
138 int mdd_quota_setinfo(const struct lu_env *env, struct md_device *m,
139                       __u32 type, __u32 id, struct obd_dqinfo *dqinfo)
140 {
141         struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
142         struct obd_device *obd = mdd->mdd_obd_dev;
143         struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
144         int rc;
145         ENTRY;
146
147         oqctl->qc_cmd = Q_SETINFO;
148         oqctl->qc_type = type;
149         oqctl->qc_id = id;
150         oqctl->qc_dqinfo = *dqinfo;
151         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
152         RETURN(rc);
153 }
154
155 int mdd_quota_getinfo(const struct lu_env *env, const struct md_device *m,
156                       __u32 type, __u32 id, struct obd_dqinfo *dqinfo)
157 {
158         struct mdd_device *mdd = lu2mdd_dev(
159                                  &((struct md_device *)m)->md_lu_dev);
160         struct obd_device *obd = mdd->mdd_obd_dev;
161         struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
162         int rc;
163         ENTRY;
164
165         oqctl->qc_cmd = Q_GETINFO;
166         oqctl->qc_type = type;
167         oqctl->qc_id = id;
168         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
169         *dqinfo = oqctl->qc_dqinfo;
170         RETURN(rc);
171 }
172
173 int mdd_quota_setquota(const struct lu_env *env, struct md_device *m,
174                        __u32 type, __u32 id, struct obd_dqblk *dqblk)
175 {
176         struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
177         struct obd_device *obd = mdd->mdd_obd_dev;
178         struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
179         int rc;
180         ENTRY;
181
182         oqctl->qc_cmd = Q_SETQUOTA;
183         oqctl->qc_type = type;
184         oqctl->qc_id = id;
185         oqctl->qc_dqblk = *dqblk;
186         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
187         RETURN(rc);
188 }
189
190 int mdd_quota_getquota(const struct lu_env *env, const struct md_device *m,
191                        __u32 type, __u32 id, struct obd_dqblk *dqblk)
192 {
193         struct mdd_device *mdd = lu2mdd_dev(
194                                  &((struct md_device *)m)->md_lu_dev);
195         struct obd_device *obd = mdd->mdd_obd_dev;
196         struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
197         int rc;
198         ENTRY;
199
200         oqctl->qc_cmd = Q_GETQUOTA;
201         oqctl->qc_type = type;
202         oqctl->qc_id = id;
203         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
204         *dqblk = oqctl->qc_dqblk;
205         RETURN(rc);
206 }
207
208 int mdd_quota_getoinfo(const struct lu_env *env, const struct md_device *m,
209                        __u32 type, __u32 id, struct obd_dqinfo *dqinfo)
210 {
211         struct mdd_device *mdd = lu2mdd_dev(
212                                  &((struct md_device *)m)->md_lu_dev);
213         struct obd_device *obd = mdd->mdd_obd_dev;
214         struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
215         int rc;
216         ENTRY;
217
218         oqctl->qc_cmd = Q_GETOINFO;
219         oqctl->qc_type = type;
220         oqctl->qc_id = id;
221         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
222         *dqinfo = oqctl->qc_dqinfo;
223         RETURN(rc);
224 }
225
226 int mdd_quota_getoquota(const struct lu_env *env, const struct md_device *m,
227                         __u32 type, __u32 id, struct obd_dqblk *dqblk)
228 {
229         struct mdd_device *mdd = lu2mdd_dev(
230                                  &((struct md_device *)m)->md_lu_dev);
231         struct obd_device *obd = mdd->mdd_obd_dev;
232         struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
233         int rc;
234         ENTRY;
235
236         oqctl->qc_cmd = Q_GETOQUOTA;
237         oqctl->qc_type = type;
238         oqctl->qc_id = id;
239         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
240         *dqblk = oqctl->qc_dqblk;
241         RETURN(rc);
242 }
243
244 int mdd_quota_invalidate(const struct lu_env *env, struct md_device *m,
245                          __u32 type)
246 {
247         struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
248         struct obd_device *obd = mdd->mdd_obd_dev;
249         struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
250         int rc;
251         ENTRY;
252
253         oqctl->qc_cmd = LUSTRE_Q_INVALIDATE;
254         oqctl->qc_type = type;
255         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
256         RETURN(rc);
257 }
258
259 int mdd_quota_finvalidate(const struct lu_env *env, struct md_device *m,
260                           __u32 type)
261 {
262         struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
263         struct obd_device *obd = mdd->mdd_obd_dev;
264         struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
265         int rc;
266         ENTRY;
267
268         oqctl->qc_cmd = LUSTRE_Q_FINVALIDATE;
269         oqctl->qc_type = type;
270         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
271         RETURN(rc);
272 }
273 #endif