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.
39 # define EXPORT_SYMTAB
41 #define DEBUG_SUBSYSTEM S_LQUOTA
44 # include <linux/version.h>
45 # include <linux/module.h>
46 # include <linux/init.h>
47 # include <linux/fs.h>
48 # include <linux/jbd.h>
49 # include <linux/ext3_fs.h>
50 # include <linux/smp_lock.h>
51 # include <linux/buffer_head.h>
52 # include <linux/workqueue.h>
53 # include <linux/mount.h>
54 #else /* __KERNEL__ */
55 # include <liblustre.h>
58 #include <obd_class.h>
59 #include <lustre_mds.h>
60 #include <lustre_dlm.h>
61 #include <lustre_cfg.h>
63 #include <lustre_fsfilt.h>
64 #include <lustre_quota.h>
65 #include "quota_internal.h"
67 #ifdef HAVE_QUOTA_SUPPORT
69 static int target_quotacheck_callback(struct obd_export *exp,
70 struct obd_quotactl *oqctl)
72 struct ptlrpc_request *req;
73 struct obd_quotactl *body;
77 req = ptlrpc_request_alloc_pack(exp->exp_imp_reverse, &RQF_QC_CALLBACK,
78 LUSTRE_OBD_VERSION, OBD_QC_CALLBACK);
82 body = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
85 ptlrpc_request_set_replen(req);
87 rc = ptlrpc_queue_wait(req);
88 ptlrpc_req_finished(req);
93 static int target_quotacheck_thread(void *data)
95 struct quotacheck_thread_args *qta = data;
96 struct obd_export *exp;
97 struct obd_device *obd;
98 struct obd_quotactl *oqctl;
99 struct lvfs_run_ctxt saved;
102 ptlrpc_daemonize("quotacheck");
106 oqctl = &qta->qta_oqctl;
108 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
110 rc = fsfilt_quotacheck(obd, qta->qta_sb, oqctl);
112 CERROR("%s: fsfilt_quotacheck: %d\n", obd->obd_name, rc);
114 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
116 rc = target_quotacheck_callback(exp, oqctl);
117 class_export_put(exp);
123 int target_quota_check(struct obd_device *obd, struct obd_export *exp,
124 struct obd_quotactl *oqctl)
126 struct obd_device_target *obt = &obd->u.obt;
127 struct quotacheck_thread_args *qta;
135 down(&obt->obt_quotachecking);
139 qta->qta_oqctl = *oqctl;
140 qta->qta_oqctl.qc_id = obt->obt_qfmt; /* override qfmt version */
141 qta->qta_sb = obt->obt_sb;
142 qta->qta_sem = &obt->obt_quotachecking;
144 if (!strcmp(obd->obd_type->typ_name, LUSTRE_MDS_NAME)) {
146 rc = init_admin_quotafiles(obd, &qta->qta_oqctl);
148 CERROR("init_admin_quotafiles failed: %d\n", rc);
153 /* we get ref for exp because target_quotacheck_callback() will use this
154 * export later b=18126 */
155 class_export_get(exp);
156 rc = kernel_thread(target_quotacheck_thread, qta, CLONE_VM|CLONE_FILES);
158 CDEBUG(D_INFO, "%s: target_quotacheck_thread: %d\n",
162 CERROR("%s: error starting quotacheck_thread: %d\n",
164 class_export_put(exp);
169 up(&obt->obt_quotachecking);
174 #endif /* __KERNEL__ */
175 #endif /* HAVE_QUOTA_SUPPORT */
177 int client_quota_check(struct obd_device *unused, struct obd_export *exp,
178 struct obd_quotactl *oqctl)
180 struct client_obd *cli = &exp->exp_obd->u.cli;
181 struct ptlrpc_request *req;
182 struct obd_quotactl *body;
183 const struct req_format *rf;
187 if (!strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_MDC_NAME)) {
188 rf = &RQF_MDS_QUOTACHECK;
189 ver = LUSTRE_MDS_VERSION;
190 opc = MDS_QUOTACHECK;
191 } else if (!strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_OSC_NAME)) {
192 rf = &RQF_OST_QUOTACHECK;
193 ver = LUSTRE_OST_VERSION;
194 opc = OST_QUOTACHECK;
199 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), rf, ver, opc);
203 body = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
206 ptlrpc_request_set_replen(req);
208 /* the next poll will find -ENODATA, that means quotacheck is
210 cli->cl_qchk_stat = -ENODATA;
211 rc = ptlrpc_queue_wait(req);
213 cli->cl_qchk_stat = rc;
214 ptlrpc_req_finished(req);
218 int client_quota_poll_check(struct obd_export *exp, struct if_quotacheck *qchk)
220 struct client_obd *cli = &exp->exp_obd->u.cli;
224 rc = cli->cl_qchk_stat;
226 /* the client is not the previous one */
227 if (rc == CL_NOT_QUOTACHECKED)
230 qchk->obd_uuid = cli->cl_target_uuid;
231 /* FIXME change strncmp to strcmp and save the strlen op */
232 if (strncmp(exp->exp_obd->obd_type->typ_name, LUSTRE_OSC_NAME,
233 strlen(LUSTRE_OSC_NAME)) == 0)
234 memcpy(qchk->obd_type, LUSTRE_OST_NAME,
235 strlen(LUSTRE_OST_NAME));
236 else if (strncmp(exp->exp_obd->obd_type->typ_name, LUSTRE_MDC_NAME,
237 strlen(LUSTRE_MDC_NAME)) == 0)
238 memcpy(qchk->obd_type, LUSTRE_MDS_NAME,
239 strlen(LUSTRE_MDS_NAME));
244 int lmv_quota_check(struct obd_device *unused, struct obd_export *exp,
245 struct obd_quotactl *oqctl)
247 struct obd_device *obd = class_exp2obd(exp);
248 struct lmv_obd *lmv = &obd->u.lmv;
249 struct lmv_tgt_desc *tgt;
253 for (i = 0, tgt = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgt++) {
256 if (!tgt->ltd_active) {
257 CERROR("lmv idx %d inactive\n", i);
261 err = obd_quotacheck(tgt->ltd_exp, oqctl);
269 int lov_quota_check(struct obd_device *unused, struct obd_export *exp,
270 struct obd_quotactl *oqctl)
272 struct obd_device *obd = class_exp2obd(exp);
273 struct lov_obd *lov = &obd->u.lov;
277 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
278 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active) {
279 CERROR("lov idx %d inactive\n", i);
284 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
287 err = obd_quotacheck(lov->lov_tgts[i]->ltd_exp, oqctl);