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 # include <linux/smp_lock.h>
26 # include <linux/buffer_head.h>
27 # include <linux/workqueue.h>
28 # include <linux/mount.h>
29 #else /* __KERNEL__ */
30 # include <liblustre.h>
33 #include <obd_class.h>
34 #include <lustre_mds.h>
35 #include <lustre_dlm.h>
36 #include <lustre_cfg.h>
38 #include <lustre_fsfilt.h>
39 #include <lustre_quota.h>
40 #include "quota_internal.h"
43 static int target_quotacheck_callback(struct obd_export *exp,
44 struct obd_quotactl *oqctl)
46 struct ptlrpc_request *req;
47 struct obd_quotactl *body;
51 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_QC_CALLBACK,
52 LUSTRE_OBD_VERSION, OBD_QC_CALLBACK);
56 body = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
59 ptlrpc_request_set_replen(req);
61 rc = ptlrpc_queue_wait(req);
62 ptlrpc_req_finished(req);
67 static int target_quotacheck_thread(void *data)
69 struct quotacheck_thread_args *qta = data;
70 struct obd_export *exp;
71 struct obd_device *obd;
72 struct obd_quotactl *oqctl;
73 struct lvfs_run_ctxt saved;
76 ptlrpc_daemonize("quotacheck");
80 oqctl = &qta->qta_oqctl;
82 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
84 rc = fsfilt_quotacheck(obd, qta->qta_sb, oqctl);
86 CERROR("%s: fsfilt_quotacheck: %d\n", obd->obd_name, rc);
88 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
90 rc = target_quotacheck_callback(exp, oqctl);
92 atomic_inc(qta->qta_sem);
98 int target_quota_check(struct obd_export *exp, struct obd_quotactl *oqctl)
100 struct obd_device *obd = exp->exp_obd;
101 struct obd_device_target *obt = &obd->u.obt;
102 struct quotacheck_thread_args *qta;
106 if (!atomic_dec_and_test(&obt->obt_quotachecking)) {
107 CDEBUG(D_INFO, "other people are doing quotacheck\n");
108 GOTO(out, rc = -EBUSY);
113 GOTO(out, rc = -ENOMEM);
116 qta->qta_oqctl = *oqctl;
117 qta->qta_sb = obt->obt_sb;
118 qta->qta_sem = &obt->obt_quotachecking;
120 if (!strcmp(obd->obd_type->typ_name, LUSTRE_MDS_NAME)) {
122 rc = init_admin_quotafiles(obd, &qta->qta_oqctl);
124 CERROR("init_admin_quotafiles failed: %d\n", rc);
130 rc = kernel_thread(target_quotacheck_thread, qta, CLONE_VM|CLONE_FILES);
132 CDEBUG(D_INFO, "%s: target_quotacheck_thread: %d\n",
137 CERROR("%s: error starting quotacheck_thread: %d\n",
141 atomic_inc(&obt->obt_quotachecking);
145 #endif /* __KERNEL__ */
147 int client_quota_check(struct obd_export *exp, struct obd_quotactl *oqctl)
149 struct client_obd *cli = &exp->exp_obd->u.cli;
150 struct ptlrpc_request *req;
151 struct obd_quotactl *body;
155 if (!strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_MDC_NAME)) {
156 ver = LUSTRE_MDS_VERSION;
157 opc = MDS_QUOTACHECK;
158 } else if (!strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_OSC_NAME)) {
159 ver = LUSTRE_OST_VERSION;
160 opc = OST_QUOTACHECK;
165 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
166 &RQF_MDS_QUOTACHECK, ver, opc);
170 body = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
173 ptlrpc_request_set_replen(req);
175 /* the next poll will find -ENODATA, that means quotacheck is
177 cli->cl_qchk_stat = -ENODATA;
178 rc = ptlrpc_queue_wait(req);
180 cli->cl_qchk_stat = rc;
181 ptlrpc_req_finished(req);
185 int client_quota_poll_check(struct obd_export *exp, struct if_quotacheck *qchk)
187 struct client_obd *cli = &exp->exp_obd->u.cli;
191 rc = cli->cl_qchk_stat;
193 /* the client is not the previous one */
194 if (rc == CL_NOT_QUOTACHECKED)
197 qchk->obd_uuid = cli->cl_target_uuid;
198 /* FIXME change strncmp to strcmp and save the strlen op */
199 if (strncmp(exp->exp_obd->obd_type->typ_name, LUSTRE_OSC_NAME,
200 strlen(LUSTRE_OSC_NAME)))
201 memcpy(qchk->obd_type, LUSTRE_OST_NAME,
202 strlen(LUSTRE_OST_NAME));
203 else if (strncmp(exp->exp_obd->obd_type->typ_name, LUSTRE_MDC_NAME,
204 strlen(LUSTRE_MDC_NAME)))
205 memcpy(qchk->obd_type, LUSTRE_MDS_NAME,
206 strlen(LUSTRE_MDS_NAME));
211 int lov_quota_check(struct obd_export *exp, struct obd_quotactl *oqctl)
213 struct obd_device *obd = class_exp2obd(exp);
214 struct lov_obd *lov = &obd->u.lov;
218 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
221 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active) {
222 CERROR("lov idx %d inactive\n", i);
226 err = obd_quotacheck(lov->lov_tgts[i]->ltd_exp, oqctl);
227 if (err && lov->lov_tgts[i]->ltd_active && !rc)