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 <obd_class.h>
38 #include <lustre_mds.h>
39 #include <lustre_dlm.h>
40 #include <lustre_cfg.h>
42 #include <lustre_fsfilt.h>
43 #include <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[2] = { sizeof(struct ptlrpc_body), sizeof(*oqctl) };
55 req = ptlrpc_prep_req(exp->exp_imp_reverse, LUSTRE_OBD_VERSION,
56 OBD_QC_CALLBACK, 2, size, NULL);
60 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
63 ptlrpc_req_set_repsize(req, 1, NULL);
65 rc = ptlrpc_queue_wait(req);
66 ptlrpc_req_finished(req);
71 static int target_quotacheck_thread(void *data)
73 struct quotacheck_thread_args *qta = data;
74 struct obd_export *exp;
75 struct obd_device *obd;
76 struct obd_quotactl *oqctl;
77 struct lvfs_run_ctxt saved;
80 ptlrpc_daemonize("quotacheck");
84 oqctl = &qta->qta_oqctl;
86 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
88 rc = fsfilt_quotacheck(obd, qta->qta_sb, oqctl);
90 CERROR("%s: fsfilt_quotacheck: %d\n", obd->obd_name, rc);
92 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
94 rc = target_quotacheck_callback(exp, oqctl);
96 atomic_inc(qta->qta_sem);
102 int target_quota_check(struct obd_export *exp, struct obd_quotactl *oqctl)
104 struct obd_device *obd = exp->exp_obd;
105 struct obd_device_target *obt = &obd->u.obt;
106 struct quotacheck_thread_args *qta;
110 if (!atomic_dec_and_test(&obt->obt_quotachecking)) {
111 CDEBUG(D_INFO, "other people are doing quotacheck\n");
112 GOTO(out, rc = -EBUSY);
117 GOTO(out, rc = -ENOMEM);
120 qta->qta_oqctl = *oqctl;
121 qta->qta_sb = obt->obt_sb;
122 qta->qta_sem = &obt->obt_quotachecking;
124 if (!strcmp(obd->obd_type->typ_name, LUSTRE_MDS_NAME)) {
126 rc = init_admin_quotafiles(obd, &qta->qta_oqctl);
128 CERROR("init_admin_quotafiles failed: %d\n", rc);
134 rc = kernel_thread(target_quotacheck_thread, qta, CLONE_VM|CLONE_FILES);
136 CDEBUG(D_INFO, "%s: target_quotacheck_thread: %d\n",
141 CERROR("%s: error starting quotacheck_thread: %d\n",
145 atomic_inc(&obt->obt_quotachecking);
149 #endif /* __KERNEL__ */
151 int client_quota_check(struct obd_export *exp, struct obd_quotactl *oqctl)
153 struct client_obd *cli = &exp->exp_obd->u.cli;
154 struct ptlrpc_request *req;
155 struct obd_quotactl *body;
156 int size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
160 if (!strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_MDC_NAME)) {
161 ver = LUSTRE_MDS_VERSION;
162 opc = MDS_QUOTACHECK;
163 } else if (!strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_OSC_NAME)) {
164 ver = LUSTRE_OST_VERSION;
165 opc = OST_QUOTACHECK;
170 req = ptlrpc_prep_req(class_exp2cliimp(exp), ver, opc, 2, size, NULL);
172 GOTO(out, rc = -ENOMEM);
174 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
177 ptlrpc_req_set_repsize(req, 1, NULL);
179 /* the next poll will find -ENODATA, that means quotacheck is
181 cli->cl_qchk_stat = -ENODATA;
182 rc = ptlrpc_queue_wait(req);
184 cli->cl_qchk_stat = rc;
186 ptlrpc_req_finished(req);
190 int client_quota_poll_check(struct obd_export *exp, struct if_quotacheck *qchk)
192 struct client_obd *cli = &exp->exp_obd->u.cli;
196 rc = cli->cl_qchk_stat;
198 /* the client is not the previous one */
199 if (rc == CL_NOT_QUOTACHECKED)
202 qchk->obd_uuid = cli->cl_target_uuid;
203 /* FIXME change strncmp to strcmp and save the strlen op */
204 if (strncmp(exp->exp_obd->obd_type->typ_name, LUSTRE_OSC_NAME,
205 strlen(LUSTRE_OSC_NAME)))
206 memcpy(qchk->obd_type, LUSTRE_OST_NAME,
207 strlen(LUSTRE_OST_NAME));
208 else if (strncmp(exp->exp_obd->obd_type->typ_name, LUSTRE_MDC_NAME,
209 strlen(LUSTRE_MDC_NAME)))
210 memcpy(qchk->obd_type, LUSTRE_MDS_NAME,
211 strlen(LUSTRE_MDS_NAME));
216 int lov_quota_check(struct obd_export *exp, struct obd_quotactl *oqctl)
218 struct obd_device *obd = class_exp2obd(exp);
219 struct lov_obd *lov = &obd->u.lov;
223 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
226 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active) {
227 CERROR("lov idx %d inactive\n", i);
231 err = obd_quotacheck(lov->lov_tgts[i]->ltd_exp, oqctl);
232 if (err && lov->lov_tgts[i]->ltd_active && !rc)