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 (c) 2006, 2010, Oracle and/or its affiliates. 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/smp_lock.h>
48 # include <linux/buffer_head.h>
49 # include <linux/workqueue.h>
50 # include <linux/mount.h>
51 #else /* __KERNEL__ */
52 # include <liblustre.h>
55 #include <obd_class.h>
56 #include <lustre_mds.h>
57 #include <lustre_dlm.h>
58 #include <lustre_cfg.h>
60 #include <lustre_fsfilt.h>
61 #include <lustre_quota.h>
62 #include "quota_internal.h"
64 #ifdef HAVE_QUOTA_SUPPORT
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;
71 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*oqctl) };
74 req = ptlrpc_prep_req(exp->exp_imp_reverse, LUSTRE_OBD_VERSION,
75 OBD_QC_CALLBACK, 2, size, NULL);
79 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
82 ptlrpc_req_set_repsize(req, 1, NULL);
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 cfs_daemonize_ctxt("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);
114 class_export_put(exp);
116 atomic_inc(qta->qta_sem);
122 int target_quota_check(struct obd_export *exp, struct obd_quotactl *oqctl)
124 struct obd_device *obd = exp->exp_obd;
125 struct obd_device_target *obt = &obd->u.obt;
126 struct quotacheck_thread_args *qta;
130 if (!atomic_dec_and_test(&obt->obt_quotachecking)) {
131 CDEBUG(D_INFO, "other people are doing quotacheck\n");
132 GOTO(out, rc = -EBUSY);
137 GOTO(out, rc = -ENOMEM);
140 qta->qta_oqctl = *oqctl;
141 qta->qta_oqctl.qc_id = obt->obt_qfmt; /* override qfmt version */
142 qta->qta_sb = obt->obt_sb;
143 qta->qta_sem = &obt->obt_quotachecking;
145 if (!strcmp(obd->obd_type->typ_name, LUSTRE_MDS_NAME)) {
147 rc = init_admin_quotafiles(obd, &qta->qta_oqctl);
149 CERROR("init_admin_quotafiles failed: %d\n", rc);
155 /* we get ref for exp because target_quotacheck_callback() will use this
156 * export later b=18126 */
157 class_export_get(exp);
158 rc = kernel_thread(target_quotacheck_thread, qta, CLONE_VM|CLONE_FILES);
160 CDEBUG(D_INFO, "%s: target_quotacheck_thread: %d\n",
165 class_export_put(exp);
166 CERROR("%s: error starting quotacheck_thread: %d\n",
170 atomic_inc(&obt->obt_quotachecking);
174 #endif /* __KERNEL__ */
175 #endif /* HAVE_QUOTA_SUPPORT */
177 int client_quota_check(struct obd_export *exp, struct obd_quotactl *oqctl)
179 struct client_obd *cli = &exp->exp_obd->u.cli;
180 struct ptlrpc_request *req;
181 struct obd_quotactl *body;
182 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
186 if (!strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_MDC_NAME)) {
187 ver = LUSTRE_MDS_VERSION;
188 opc = MDS_QUOTACHECK;
189 } else if (!strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_OSC_NAME)) {
190 ver = LUSTRE_OST_VERSION;
191 opc = OST_QUOTACHECK;
196 req = ptlrpc_prep_req(class_exp2cliimp(exp), ver, opc, 2, size, NULL);
198 GOTO(out, rc = -ENOMEM);
200 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
203 ptlrpc_req_set_repsize(req, 1, NULL);
205 /* the next poll will find -ENODATA, that means quotacheck is
207 cli->cl_qchk_stat = -ENODATA;
208 rc = ptlrpc_queue_wait(req);
210 cli->cl_qchk_stat = rc;
212 ptlrpc_req_finished(req);
216 int client_quota_poll_check(struct obd_export *exp, struct if_quotacheck *qchk)
218 struct client_obd *cli = &exp->exp_obd->u.cli;
222 rc = cli->cl_qchk_stat;
224 /* the client is not the previous one */
225 if (rc == CL_NOT_QUOTACHECKED)
228 qchk->obd_uuid = cli->cl_target_uuid;
229 /* FIXME change strncmp to strcmp and save the strlen op */
230 if (strncmp(exp->exp_obd->obd_type->typ_name, LUSTRE_OSC_NAME,
231 strlen(LUSTRE_OSC_NAME)) == 0)
232 memcpy(qchk->obd_type, LUSTRE_OST_NAME,
233 strlen(LUSTRE_OST_NAME));
234 else if (strncmp(exp->exp_obd->obd_type->typ_name, LUSTRE_MDC_NAME,
235 strlen(LUSTRE_MDC_NAME)) == 0)
236 memcpy(qchk->obd_type, LUSTRE_MDS_NAME,
237 strlen(LUSTRE_MDS_NAME));
242 int lov_quota_check(struct obd_export *exp, struct obd_quotactl *oqctl)
244 struct obd_device *obd = class_exp2obd(exp);
245 struct lov_obd *lov = &obd->u.lov;
251 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
252 if (!lov->lov_tgts[i])
255 if (!lov->lov_tgts[i]->ltd_active) {
256 CERROR("lov idx %d inactive\n", i);
262 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
265 if (!lov->lov_tgts[i])
268 err = obd_quotacheck(lov->lov_tgts[i]->ltd_exp, oqctl);