Whamcloud - gitweb
LU-573: conf-sanity test_22 failed with 41
[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 (c) 2008, 2010, Oracle and/or its affiliates. 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                     __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_export *exp = md_quota(env)->mq_exp;
101         struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
102         int rc;
103         ENTRY;
104
105         oqctl->qc_type = type;
106         rc = lquota_check(mds_quota_interface_ref, obd, exp, oqctl);
107         RETURN(rc);
108 }
109
110 int mdd_quota_on(const struct lu_env *env, struct md_device *m,
111                  __u32 type)
112 {
113         struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
114         struct obd_device *obd = mdd->mdd_obd_dev;
115         struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
116         int rc;
117         ENTRY;
118
119         oqctl->qc_cmd = Q_QUOTAON;
120         oqctl->qc_type = type;
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)
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         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
137         RETURN(rc);
138 }
139
140 int mdd_quota_setinfo(const struct lu_env *env, struct md_device *m,
141                       __u32 type, __u32 id, struct obd_dqinfo *dqinfo)
142 {
143         struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
144         struct obd_device *obd = mdd->mdd_obd_dev;
145         struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
146         int rc;
147         ENTRY;
148
149         oqctl->qc_cmd = Q_SETINFO;
150         oqctl->qc_type = type;
151         oqctl->qc_id = id;
152         oqctl->qc_dqinfo = *dqinfo;
153         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
154         RETURN(rc);
155 }
156
157 int mdd_quota_getinfo(const struct lu_env *env, const struct md_device *m,
158                       __u32 type, __u32 id, struct obd_dqinfo *dqinfo)
159 {
160         struct mdd_device *mdd = lu2mdd_dev(
161                                  &((struct md_device *)m)->md_lu_dev);
162         struct obd_device *obd = mdd->mdd_obd_dev;
163         struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
164         int rc;
165         ENTRY;
166
167         oqctl->qc_cmd = Q_GETINFO;
168         oqctl->qc_type = type;
169         oqctl->qc_id = id;
170         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
171         *dqinfo = oqctl->qc_dqinfo;
172         RETURN(rc);
173 }
174
175 int mdd_quota_setquota(const struct lu_env *env, struct md_device *m,
176                        __u32 type, __u32 id, struct obd_dqblk *dqblk)
177 {
178         struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
179         struct obd_device *obd = mdd->mdd_obd_dev;
180         struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
181         int rc;
182         ENTRY;
183
184         oqctl->qc_cmd = Q_SETQUOTA;
185         oqctl->qc_type = type;
186         oqctl->qc_id = id;
187         oqctl->qc_dqblk = *dqblk;
188         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
189         RETURN(rc);
190 }
191
192 int mdd_quota_getquota(const struct lu_env *env, const struct md_device *m,
193                        __u32 type, __u32 id, struct obd_dqblk *dqblk)
194 {
195         struct mdd_device *mdd = lu2mdd_dev(
196                                  &((struct md_device *)m)->md_lu_dev);
197         struct obd_device *obd = mdd->mdd_obd_dev;
198         struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
199         int rc;
200         ENTRY;
201
202         oqctl->qc_cmd = Q_GETQUOTA;
203         oqctl->qc_type = type;
204         oqctl->qc_id = id;
205         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
206         *dqblk = oqctl->qc_dqblk;
207         RETURN(rc);
208 }
209
210 int mdd_quota_getoinfo(const struct lu_env *env, const struct md_device *m,
211                        __u32 type, __u32 id, struct obd_dqinfo *dqinfo)
212 {
213         struct mdd_device *mdd = lu2mdd_dev(
214                                  &((struct md_device *)m)->md_lu_dev);
215         struct obd_device *obd = mdd->mdd_obd_dev;
216         struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
217         int rc;
218         ENTRY;
219
220         oqctl->qc_cmd = Q_GETOINFO;
221         oqctl->qc_type = type;
222         oqctl->qc_id = id;
223         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
224         *dqinfo = oqctl->qc_dqinfo;
225         RETURN(rc);
226 }
227
228 int mdd_quota_getoquota(const struct lu_env *env, const struct md_device *m,
229                         __u32 type, __u32 id, struct obd_dqblk *dqblk)
230 {
231         struct mdd_device *mdd = lu2mdd_dev(
232                                  &((struct md_device *)m)->md_lu_dev);
233         struct obd_device *obd = mdd->mdd_obd_dev;
234         struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
235         int rc;
236         ENTRY;
237
238         oqctl->qc_cmd = Q_GETOQUOTA;
239         oqctl->qc_type = type;
240         oqctl->qc_id = id;
241         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
242         *dqblk = oqctl->qc_dqblk;
243         RETURN(rc);
244 }
245
246 int mdd_quota_invalidate(const struct lu_env *env, struct md_device *m,
247                          __u32 type)
248 {
249         struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
250         struct obd_device *obd = mdd->mdd_obd_dev;
251         struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
252         int rc;
253         ENTRY;
254
255         oqctl->qc_cmd = LUSTRE_Q_INVALIDATE;
256         oqctl->qc_type = type;
257         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
258         RETURN(rc);
259 }
260
261 int mdd_quota_finvalidate(const struct lu_env *env, struct md_device *m,
262                           __u32 type)
263 {
264         struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
265         struct obd_device *obd = mdd->mdd_obd_dev;
266         struct obd_quotactl *oqctl = &mdd_env_info(env)->mti_oqctl;
267         int rc;
268         ENTRY;
269
270         oqctl->qc_cmd = LUSTRE_Q_FINVALIDATE;
271         oqctl->qc_type = type;
272         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
273         RETURN(rc);
274 }
275 #endif