Whamcloud - gitweb
d246a07efd3b1bf3128d500568257698db84f718
[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)
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         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
121         RETURN(rc);
122 }
123
124 int mdd_quota_off(const struct lu_env *env, struct md_device *m,
125                   __u32 type)
126 {
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;
130         int rc;
131         ENTRY;
132
133         oqctl->qc_cmd = Q_QUOTAOFF;
134         oqctl->qc_type = type;
135         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
136         RETURN(rc);
137 }
138
139 int mdd_quota_setinfo(const struct lu_env *env, struct md_device *m,
140                       __u32 type, __u32 id, struct obd_dqinfo *dqinfo)
141 {
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;
145         int rc;
146         ENTRY;
147
148         oqctl->qc_cmd = Q_SETINFO;
149         oqctl->qc_type = type;
150         oqctl->qc_id = id;
151         oqctl->qc_dqinfo = *dqinfo;
152         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
153         RETURN(rc);
154 }
155
156 int mdd_quota_getinfo(const struct lu_env *env, const struct md_device *m,
157                       __u32 type, __u32 id, struct obd_dqinfo *dqinfo)
158 {
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;
163         int rc;
164         ENTRY;
165
166         oqctl->qc_cmd = Q_GETINFO;
167         oqctl->qc_type = type;
168         oqctl->qc_id = id;
169         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
170         *dqinfo = oqctl->qc_dqinfo;
171         RETURN(rc);
172 }
173
174 int mdd_quota_setquota(const struct lu_env *env, struct md_device *m,
175                        __u32 type, __u32 id, struct obd_dqblk *dqblk)
176 {
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;
180         int rc;
181         ENTRY;
182
183         oqctl->qc_cmd = Q_SETQUOTA;
184         oqctl->qc_type = type;
185         oqctl->qc_id = id;
186         oqctl->qc_dqblk = *dqblk;
187         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
188         RETURN(rc);
189 }
190
191 int mdd_quota_getquota(const struct lu_env *env, const struct md_device *m,
192                        __u32 type, __u32 id, struct obd_dqblk *dqblk)
193 {
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;
198         int rc;
199         ENTRY;
200
201         oqctl->qc_cmd = Q_GETQUOTA;
202         oqctl->qc_type = type;
203         oqctl->qc_id = id;
204         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
205         *dqblk = oqctl->qc_dqblk;
206         RETURN(rc);
207 }
208
209 int mdd_quota_getoinfo(const struct lu_env *env, const struct md_device *m,
210                        __u32 type, __u32 id, struct obd_dqinfo *dqinfo)
211 {
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;
216         int rc;
217         ENTRY;
218
219         oqctl->qc_cmd = Q_GETOINFO;
220         oqctl->qc_type = type;
221         oqctl->qc_id = id;
222         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
223         *dqinfo = oqctl->qc_dqinfo;
224         RETURN(rc);
225 }
226
227 int mdd_quota_getoquota(const struct lu_env *env, const struct md_device *m,
228                         __u32 type, __u32 id, struct obd_dqblk *dqblk)
229 {
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;
234         int rc;
235         ENTRY;
236
237         oqctl->qc_cmd = Q_GETOQUOTA;
238         oqctl->qc_type = type;
239         oqctl->qc_id = id;
240         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
241         *dqblk = oqctl->qc_dqblk;
242         RETURN(rc);
243 }
244
245 int mdd_quota_invalidate(const struct lu_env *env, struct md_device *m,
246                          __u32 type)
247 {
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;
251         int rc;
252         ENTRY;
253
254         oqctl->qc_cmd = LUSTRE_Q_INVALIDATE;
255         oqctl->qc_type = type;
256         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
257         RETURN(rc);
258 }
259
260 int mdd_quota_finvalidate(const struct lu_env *env, struct md_device *m,
261                           __u32 type)
262 {
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;
266         int rc;
267         ENTRY;
268
269         oqctl->qc_cmd = LUSTRE_Q_FINVALIDATE;
270         oqctl->qc_type = type;
271         rc = lquota_ctl(mds_quota_interface_ref, obd, oqctl);
272         RETURN(rc);
273 }
274 #endif