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.
37 # define EXPORT_SYMTAB
39 #define DEBUG_SUBSYSTEM S_MDS
42 # include <linux/version.h>
43 # include <linux/module.h>
44 # include <linux/init.h>
45 # include <linux/fs.h>
46 # include <linux/jbd.h>
47 # include <linux/ext3_fs.h>
48 # include <linux/smp_lock.h>
49 # include <linux/buffer_head.h>
50 # include <linux/workqueue.h>
51 # include <linux/mount.h>
52 #else /* __KERNEL__ */
53 # include <liblustre.h>
56 #include <obd_class.h>
57 #include <lustre_mds.h>
58 #include <lustre_dlm.h>
59 #include <lustre_cfg.h>
61 #include <lustre_fsfilt.h>
62 #include <lustre_quota.h>
63 #include "quota_internal.h"
66 static int target_quotacheck_callback(struct obd_export *exp,
67 struct obd_quotactl *oqctl)
69 struct ptlrpc_request *req;
70 struct obd_quotactl *body;
74 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_QC_CALLBACK,
75 LUSTRE_OBD_VERSION, OBD_QC_CALLBACK);
79 body = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
82 ptlrpc_request_set_replen(req);
84 rc = ptlrpc_queue_wait(req);
85 ptlrpc_req_finished(req);
90 static int target_quotacheck_thread(void *data)
92 struct quotacheck_thread_args *qta = data;
93 struct obd_export *exp;
94 struct obd_device *obd;
95 struct obd_quotactl *oqctl;
96 struct lvfs_run_ctxt saved;
99 ptlrpc_daemonize("quotacheck");
103 oqctl = &qta->qta_oqctl;
105 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
107 rc = fsfilt_quotacheck(obd, qta->qta_sb, oqctl);
109 CERROR("%s: fsfilt_quotacheck: %d\n", obd->obd_name, rc);
111 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
113 rc = target_quotacheck_callback(exp, oqctl);
115 atomic_inc(qta->qta_sem);
121 int target_quota_check(struct obd_export *exp, struct obd_quotactl *oqctl)
123 struct obd_device *obd = exp->exp_obd;
124 struct obd_device_target *obt = &obd->u.obt;
125 struct quotacheck_thread_args *qta;
129 if (!atomic_dec_and_test(&obt->obt_quotachecking)) {
130 CDEBUG(D_INFO, "other people are doing quotacheck\n");
131 GOTO(out, rc = -EBUSY);
136 GOTO(out, rc = -ENOMEM);
139 qta->qta_oqctl = *oqctl;
140 qta->qta_sb = obt->obt_sb;
141 qta->qta_sem = &obt->obt_quotachecking;
143 if (!strcmp(obd->obd_type->typ_name, LUSTRE_MDS_NAME)) {
145 rc = init_admin_quotafiles(obd, &qta->qta_oqctl);
147 CERROR("init_admin_quotafiles failed: %d\n", rc);
153 rc = kernel_thread(target_quotacheck_thread, qta, CLONE_VM|CLONE_FILES);
155 CDEBUG(D_INFO, "%s: target_quotacheck_thread: %d\n",
160 CERROR("%s: error starting quotacheck_thread: %d\n",
164 atomic_inc(&obt->obt_quotachecking);
168 #endif /* __KERNEL__ */
170 int client_quota_check(struct obd_export *exp, struct obd_quotactl *oqctl)
172 struct client_obd *cli = &exp->exp_obd->u.cli;
173 struct ptlrpc_request *req;
174 struct obd_quotactl *body;
178 if (!strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_MDC_NAME)) {
179 ver = LUSTRE_MDS_VERSION;
180 opc = MDS_QUOTACHECK;
181 } else if (!strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_OSC_NAME)) {
182 ver = LUSTRE_OST_VERSION;
183 opc = OST_QUOTACHECK;
188 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
189 &RQF_MDS_QUOTACHECK, ver, opc);
193 body = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
196 ptlrpc_request_set_replen(req);
198 /* the next poll will find -ENODATA, that means quotacheck is
200 cli->cl_qchk_stat = -ENODATA;
201 rc = ptlrpc_queue_wait(req);
203 cli->cl_qchk_stat = rc;
204 ptlrpc_req_finished(req);
208 int client_quota_poll_check(struct obd_export *exp, struct if_quotacheck *qchk)
210 struct client_obd *cli = &exp->exp_obd->u.cli;
214 rc = cli->cl_qchk_stat;
216 /* the client is not the previous one */
217 if (rc == CL_NOT_QUOTACHECKED)
220 qchk->obd_uuid = cli->cl_target_uuid;
221 /* FIXME change strncmp to strcmp and save the strlen op */
222 if (strncmp(exp->exp_obd->obd_type->typ_name, LUSTRE_OSC_NAME,
223 strlen(LUSTRE_OSC_NAME)))
224 memcpy(qchk->obd_type, LUSTRE_OST_NAME,
225 strlen(LUSTRE_OST_NAME));
226 else if (strncmp(exp->exp_obd->obd_type->typ_name, LUSTRE_MDC_NAME,
227 strlen(LUSTRE_MDC_NAME)))
228 memcpy(qchk->obd_type, LUSTRE_MDS_NAME,
229 strlen(LUSTRE_MDS_NAME));
234 int lov_quota_check(struct obd_export *exp, struct obd_quotactl *oqctl)
236 struct obd_device *obd = class_exp2obd(exp);
237 struct lov_obd *lov = &obd->u.lov;
241 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
244 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active) {
245 CERROR("lov idx %d inactive\n", i);
249 err = obd_quotacheck(lov->lov_tgts[i]->ltd_exp, oqctl);
250 if (err && lov->lov_tgts[i]->ltd_active && !rc)