4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Whamcloud, Inc.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define DEBUG_SUBSYSTEM S_LQUOTA
40 # include <linux/version.h>
41 # include <linux/module.h>
42 # include <linux/init.h>
43 # include <linux/fs.h>
44 # include <linux/jbd.h>
45 # include <linux/ext3_fs.h>
46 # include <linux/smp_lock.h>
47 # include <linux/buffer_head.h>
48 # include <linux/workqueue.h>
49 # include <linux/mount.h>
50 #else /* __KERNEL__ */
51 # include <liblustre.h>
54 #include <obd_class.h>
55 #include <lustre_mds.h>
56 #include <lustre_dlm.h>
57 #include <lustre_cfg.h>
59 #include <lustre_fsfilt.h>
60 #include <lustre_quota.h>
61 #include "quota_internal.h"
64 static int target_quotacheck_callback(struct obd_export *exp,
65 struct obd_quotactl *oqctl)
67 struct ptlrpc_request *req;
68 struct obd_quotactl *body;
72 req = ptlrpc_request_alloc_pack(exp->exp_imp_reverse, &RQF_QC_CALLBACK,
73 LUSTRE_OBD_VERSION, OBD_QC_CALLBACK);
77 body = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
80 ptlrpc_request_set_replen(req);
82 rc = ptlrpc_queue_wait(req);
83 ptlrpc_req_finished(req);
88 static int target_quotacheck_thread(void *data)
90 struct quotacheck_thread_args *qta = data;
91 struct obd_export *exp;
92 struct obd_device *obd;
93 struct obd_quotactl *oqctl;
94 struct lvfs_run_ctxt saved;
97 cfs_daemonize_ctxt("quotacheck");
101 oqctl = &qta->qta_oqctl;
103 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
105 rc = fsfilt_quotacheck(obd, qta->qta_sb, oqctl);
107 CERROR("%s: fsfilt_quotacheck: %d\n", obd->obd_name, rc);
109 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
111 rc = target_quotacheck_callback(exp, oqctl);
112 class_export_put(exp);
113 cfs_up(qta->qta_sem);
118 int target_quota_check(struct obd_device *obd, struct obd_export *exp,
119 struct obd_quotactl *oqctl)
121 struct obd_device_target *obt = &obd->u.obt;
122 struct quotacheck_thread_args *qta;
130 cfs_down(&obt->obt_quotachecking);
134 qta->qta_oqctl = *oqctl;
135 qta->qta_oqctl.qc_id = obt->obt_qfmt; /* override qfmt version */
136 qta->qta_sb = obt->obt_sb;
137 qta->qta_sem = &obt->obt_quotachecking;
139 /* quotaoff firstly */
140 oqctl->qc_cmd = Q_QUOTAOFF;
141 if (!strcmp(obd->obd_type->typ_name, LUSTRE_MDS_NAME)) {
142 rc = do_mds_quota_off(obd, oqctl);
143 if (rc && rc != -EALREADY) {
144 CERROR("off quota on MDS failed: %d\n", rc);
149 rc = init_admin_quotafiles(obd, &qta->qta_oqctl);
151 CERROR("init_admin_quotafiles failed: %d\n", rc);
155 struct lvfs_run_ctxt saved;
156 struct lustre_quota_ctxt *qctxt = &obt->obt_qctxt;
158 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
159 rc = fsfilt_quotactl(obd, obt->obt_sb, oqctl);
160 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
162 qctxt->lqc_flags &= ~UGQUOTA2LQC(oqctl->qc_type);
163 } else if (!quota_is_off(qctxt, oqctl)) {
164 CERROR("off quota on OSS failed: %d\n", rc);
169 /* we get ref for exp because target_quotacheck_callback() will use this
170 * export later b=18126 */
171 class_export_get(exp);
172 rc = cfs_create_thread(target_quotacheck_thread, qta,
175 /* target_quotacheck_thread will drop the ref on exp and release
176 * obt_quotachecking */
177 CDEBUG(D_INFO, "%s: target_quotacheck_thread: %d\n",
181 CERROR("%s: error starting quotacheck_thread: %d\n",
183 class_export_put(exp);
188 cfs_up(&obt->obt_quotachecking);
193 #endif /* __KERNEL__ */