1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * lustre/quota/quota_check.c
6 * Copyright (c) 2005 Cluster File Systems, Inc.
8 * This file is part of Lustre, http://www.lustre.org.
10 * No redistribution or use is permitted outside of Cluster File Systems, Inc.
14 # define EXPORT_SYMTAB
16 #define DEBUG_SUBSYSTEM S_MDS
19 # include <linux/version.h>
20 # include <linux/module.h>
21 # include <linux/init.h>
22 # include <linux/fs.h>
23 # include <linux/jbd.h>
24 # include <linux/ext3_fs.h>
25 # if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
26 # include <linux/smp_lock.h>
27 # include <linux/buffer_head.h>
28 # include <linux/workqueue.h>
29 # include <linux/mount.h>
31 # include <linux/locks.h>
33 #else /* __KERNEL__ */
34 # include <liblustre.h>
37 #include <linux/obd_class.h>
38 #include <linux/lustre_mds.h>
39 #include <linux/lustre_dlm.h>
40 #include <linux/lustre_cfg.h>
41 #include <linux/obd_ost.h>
42 #include <linux/lustre_fsfilt.h>
43 #include <linux/lustre_quota.h>
44 #include "quota_internal.h"
47 static int target_quotacheck_callback(struct obd_export *exp,
48 struct obd_quotactl *oqctl)
50 struct ptlrpc_request *req;
51 struct obd_quotactl *body;
52 int rc, size = sizeof(*oqctl);
55 req = ptlrpc_prep_req(exp->exp_imp_reverse, LUSTRE_OBD_VERSION,
56 OBD_QC_CALLBACK, 1, &size, NULL);
60 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
63 req->rq_replen = lustre_msg_size(0, NULL);
65 rc = ptlrpc_queue_wait(req);
66 ptlrpc_req_finished(req);
71 static int target_quotacheck_thread(void *data)
74 struct quotacheck_thread_args *qta = data;
75 struct obd_export *exp;
76 struct obd_device *obd;
77 struct obd_quotactl *oqctl;
78 struct lvfs_run_ctxt saved;
84 SIGNAL_MASK_LOCK(current, flags);
85 sigfillset(¤t->blocked);
87 SIGNAL_MASK_UNLOCK(current, flags);
89 THREAD_NAME(cfs_curproc_comm(), CFS_CURPROC_COMM_MAX, "%s",
95 oqctl = &qta->qta_oqctl;
97 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
99 rc = fsfilt_quotacheck(obd, qta->qta_sb, oqctl);
101 CERROR("%s: fsfilt_quotacheck: %d\n", obd->obd_name, rc);
103 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
105 rc = target_quotacheck_callback(exp, oqctl);
107 atomic_inc(qta->qta_sem);
113 int target_quota_check(struct obd_export *exp, struct obd_quotactl *oqctl)
115 struct obd_device *obd = exp->exp_obd;
116 struct obd_device_target *obt = &obd->u.obt;
117 struct quotacheck_thread_args *qta;
121 if (!atomic_dec_and_test(&obt->obt_quotachecking)) {
122 CDEBUG(D_INFO, "other people are doing quotacheck\n");
123 GOTO(out, rc = -EBUSY);
128 GOTO(out, rc = -ENOMEM);
131 qta->qta_oqctl = *oqctl;
132 qta->qta_sb = obt->obt_sb;
133 qta->qta_sem = &obt->obt_quotachecking;
135 if (!strcmp(obd->obd_type->typ_name, LUSTRE_MDS_NAME)) {
137 rc = init_admin_quotafiles(obd, &qta->qta_oqctl);
139 CERROR("init_admin_quotafiles failed: %d\n", rc);
145 rc = kernel_thread(target_quotacheck_thread, qta, CLONE_VM|CLONE_FILES);
147 CDEBUG(D_INFO, "%s: target_quotacheck_thread: %d\n",
152 CERROR("%s: error starting quotacheck_thread: %d\n",
156 atomic_inc(&obt->obt_quotachecking);
160 #endif /* __KERNEL__ */
162 int client_quota_check(struct obd_export *exp, struct obd_quotactl *oqctl)
164 struct client_obd *cli = &exp->exp_obd->u.cli;
165 struct ptlrpc_request *req;
166 struct obd_quotactl *body;
167 int size = sizeof(*body), opc, version;
171 if (!strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_MDC_NAME)) {
172 version = LUSTRE_MDS_VERSION;
173 opc = MDS_QUOTACHECK;
174 } else if (!strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_OSC_NAME)) {
175 version = LUSTRE_OST_VERSION;
176 opc = OST_QUOTACHECK;
181 req = ptlrpc_prep_req(class_exp2cliimp(exp), version, opc, 1, &size,
184 GOTO(out, rc = -ENOMEM);
186 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
189 req->rq_replen = lustre_msg_size(0, NULL);
191 /* the next poll will find -ENODATA, that means quotacheck is
193 cli->cl_qchk_stat = -ENODATA;
194 rc = ptlrpc_queue_wait(req);
196 cli->cl_qchk_stat = rc;
198 ptlrpc_req_finished(req);
202 int client_quota_poll_check(struct obd_export *exp, struct if_quotacheck *qchk)
204 struct client_obd *cli = &exp->exp_obd->u.cli;
208 rc = cli->cl_qchk_stat;
210 /* the client is not the previous one */
211 if (rc == CL_NOT_QUOTACHECKED)
214 qchk->obd_uuid = cli->cl_import->imp_target_uuid;
215 if (strncmp(exp->exp_obd->obd_type->typ_name, LUSTRE_OSC_NAME,
216 strlen(LUSTRE_OSC_NAME)))
217 memcpy(qchk->obd_type, LUSTRE_FILTER_NAME,
218 strlen(LUSTRE_FILTER_NAME));
219 else if (strncmp(exp->exp_obd->obd_type->typ_name, LUSTRE_MDC_NAME,
220 strlen(LUSTRE_MDC_NAME)))
221 memcpy(qchk->obd_type, LUSTRE_MDS_NAME,
222 strlen(LUSTRE_MDS_NAME));
227 int lov_quota_check(struct obd_export *exp, struct obd_quotactl *oqctl)
229 struct obd_device *obd = class_exp2obd(exp);
230 struct lov_obd *lov = &obd->u.lov;
234 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
237 if (!lov->tgts[i].active) {
238 CERROR("lov idx %d inactive\n", i);
242 err = obd_quotacheck(lov->tgts[i].ltd_exp, oqctl);
243 if (err && lov->tgts[i].active && !rc)