1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * lustre/quota/quota_context.c
7 * Copyright (c) 2001-2005 Cluster File Systems, Inc.
8 * Author: Niu YaWei <niu@clusterfs.com>
10 * This file is part of Lustre, http://www.lustre.org.
12 * No redistribution or use is permitted outside of Cluster File Systems, Inc.
16 # define EXPORT_SYMTAB
19 #define DEBUG_SUBSYSTEM S_MDS
21 #include <linux/version.h>
23 #include <asm/unistd.h>
24 #include <linux/slab.h>
25 #include <linux/quotaops.h>
26 #include <linux/module.h>
27 #include <linux/init.h>
29 #include <obd_class.h>
30 #include <lustre_quota.h>
31 #include <lustre_fsfilt.h>
32 #include "quota_internal.h"
34 unsigned long default_bunit_sz = 100 * 1024 * 1024; /* 100M bytes */
35 unsigned long default_btune_ratio = 50; /* 50 percentage */
36 unsigned long default_iunit_sz = 5000; /* 5000 inodes */
37 unsigned long default_itune_ratio = 50; /* 50 percentage */
39 kmem_cache_t *qunit_cachep = NULL;
40 struct list_head qunit_hash[NR_DQHASH];
41 spinlock_t qunit_hash_lock = SPIN_LOCK_UNLOCKED;
44 struct list_head lq_hash; /* Hash list in memory */
45 atomic_t lq_refcnt; /* Use count */
46 struct lustre_quota_ctxt *lq_ctxt; /* Quota context this applies to */
47 struct qunit_data lq_data; /* See qunit_data */
48 unsigned int lq_opc; /* QUOTA_DQACQ, QUOTA_DQREL */
49 struct list_head lq_waiters; /* All write threads waiting for this qunit */
52 int should_translate_quota (struct obd_import *imp)
57 if (imp->imp_connect_data.ocd_connect_flags & OBD_CONNECT_QUOTA64)
63 void qunit_cache_cleanup(void)
68 spin_lock(&qunit_hash_lock);
69 for (i = 0; i < NR_DQHASH; i++)
70 LASSERT(list_empty(qunit_hash + i));
71 spin_unlock(&qunit_hash_lock);
74 #ifdef HAVE_KMEM_CACHE_DESTROY_INT
76 rc = kmem_cache_destroy(qunit_cachep);
77 LASSERTF(rc == 0, "couldn't destory qunit_cache slab\n");
79 kmem_cache_destroy(qunit_cachep);
86 int qunit_cache_init(void)
91 LASSERT(qunit_cachep == NULL);
92 qunit_cachep = kmem_cache_create("ll_qunit_cache",
93 sizeof(struct lustre_qunit),
98 spin_lock(&qunit_hash_lock);
99 for (i = 0; i < NR_DQHASH; i++)
100 INIT_LIST_HEAD(qunit_hash + i);
101 spin_unlock(&qunit_hash_lock);
106 qunit_hashfn(struct lustre_quota_ctxt *qctxt, struct qunit_data *qdata)
107 __attribute__((__const__));
110 qunit_hashfn(struct lustre_quota_ctxt *qctxt, struct qunit_data *qdata)
112 unsigned int id = qdata->qd_id;
113 unsigned int type = qdata->qd_flags & QUOTA_IS_GRP;
115 unsigned long tmp = ((unsigned long)qctxt >> L1_CACHE_SHIFT) ^ id;
116 tmp = (tmp * (MAXQUOTAS - type)) % NR_DQHASH;
120 /* caller must hold qunit_hash_lock */
121 static inline struct lustre_qunit *find_qunit(unsigned int hashent,
122 struct lustre_quota_ctxt *qctxt,
123 struct qunit_data *qdata)
125 struct lustre_qunit *qunit = NULL;
126 struct qunit_data *tmp;
128 LASSERT_SPIN_LOCKED(&qunit_hash_lock);
129 list_for_each_entry(qunit, qunit_hash + hashent, lq_hash) {
130 tmp = &qunit->lq_data;
131 if (qunit->lq_ctxt == qctxt &&
132 qdata->qd_id == tmp->qd_id && qdata->qd_flags == tmp->qd_flags)
138 /* check_cur_qunit - check the current usage of qunit.
139 * @qctxt: quota context
140 * @qdata: the type of quota unit to be checked
142 * return: 1 - need acquire qunit;
143 * 2 - need release qunit;
144 * 0 - need do nothing.
148 check_cur_qunit(struct obd_device *obd,
149 struct lustre_quota_ctxt *qctxt, struct qunit_data *qdata)
151 struct super_block *sb = qctxt->lqc_sb;
152 unsigned long qunit_sz, tune_sz;
154 struct obd_quotactl *qctl;
156 __u32 qdata_type = qdata->qd_flags & QUOTA_IS_GRP;
157 __u32 is_blk = (qdata->qd_flags & QUOTA_IS_BLOCK) >> 1;
160 if (!sb_any_quota_enabled(sb))
163 /* ignore root user */
164 if (qdata->qd_id == 0 && qdata_type == USRQUOTA)
171 /* get fs quota usage & limit */
172 qctl->qc_cmd = Q_GETQUOTA;
173 qctl->qc_id = qdata->qd_id;
174 qctl->qc_type = qdata_type;
175 ret = fsfilt_quotactl(obd, sb, qctl);
177 if (ret == -ESRCH) /* no limit */
180 CERROR("can't get fs quota usage! (rc:%d)\n", ret);
185 usage = qctl->qc_dqblk.dqb_curspace;
186 limit = qctl->qc_dqblk.dqb_bhardlimit << QUOTABLOCK_BITS;
187 qunit_sz = qctxt->lqc_bunit_sz;
188 tune_sz = qctxt->lqc_btune_sz;
190 LASSERT(!(qunit_sz % QUOTABLOCK_SIZE));
192 usage = qctl->qc_dqblk.dqb_curinodes;
193 limit = qctl->qc_dqblk.dqb_ihardlimit;
194 qunit_sz = qctxt->lqc_iunit_sz;
195 tune_sz = qctxt->lqc_itune_sz;
198 /* ignore the no quota limit case */
202 /* we don't count the MIN_QLIMIT */
203 if ((limit == MIN_QLIMIT && !is_blk) ||
204 (toqb(limit) == MIN_QLIMIT && is_blk))
207 LASSERT(qdata->qd_count == 0);
208 if (limit <= usage + tune_sz) {
209 while (qdata->qd_count + limit <= usage + tune_sz)
210 qdata->qd_count += qunit_sz;
212 } else if (limit > usage + qunit_sz + tune_sz) {
213 while (limit - qdata->qd_count > usage + qunit_sz + tune_sz)
214 qdata->qd_count += qunit_sz;
217 LASSERT(ret == 0 || qdata->qd_count);
224 /* caller must hold qunit_hash_lock */
225 static struct lustre_qunit *dqacq_in_flight(struct lustre_quota_ctxt *qctxt,
226 struct qunit_data *qdata)
228 unsigned int hashent = qunit_hashfn(qctxt, qdata);
229 struct lustre_qunit *qunit;
232 LASSERT_SPIN_LOCKED(&qunit_hash_lock);
233 qunit = find_qunit(hashent, qctxt, qdata);
237 static struct lustre_qunit *alloc_qunit(struct lustre_quota_ctxt *qctxt,
238 struct qunit_data *qdata, int opc)
240 struct lustre_qunit *qunit = NULL;
243 OBD_SLAB_ALLOC(qunit, qunit_cachep, SLAB_NOFS, sizeof(*qunit));
247 INIT_LIST_HEAD(&qunit->lq_hash);
248 INIT_LIST_HEAD(&qunit->lq_waiters);
249 atomic_set(&qunit->lq_refcnt, 1);
250 qunit->lq_ctxt = qctxt;
251 memcpy(&qunit->lq_data, qdata, sizeof(*qdata));
257 static inline void free_qunit(struct lustre_qunit *qunit)
259 OBD_SLAB_FREE(qunit, qunit_cachep, sizeof(*qunit));
262 static inline void qunit_get(struct lustre_qunit *qunit)
264 atomic_inc(&qunit->lq_refcnt);
267 static void qunit_put(struct lustre_qunit *qunit)
269 LASSERT(atomic_read(&qunit->lq_refcnt));
270 if (atomic_dec_and_test(&qunit->lq_refcnt))
275 insert_qunit_nolock(struct lustre_quota_ctxt *qctxt, struct lustre_qunit *qunit)
277 struct list_head *head;
279 LASSERT(list_empty(&qunit->lq_hash));
280 head = qunit_hash + qunit_hashfn(qctxt, &qunit->lq_data);
281 list_add(&qunit->lq_hash, head);
284 static void remove_qunit_nolock(struct lustre_qunit *qunit)
286 LASSERT(!list_empty(&qunit->lq_hash));
287 list_del_init(&qunit->lq_hash);
290 struct qunit_waiter {
291 struct list_head qw_entry;
292 cfs_waitq_t qw_waitq;
296 #define INC_QLIMIT(limit, count) (limit == MIN_QLIMIT) ? \
297 (limit = count) : (limit += count)
300 /* FIXME check if this mds is the master of specified id */
302 is_master(struct obd_device *obd, struct lustre_quota_ctxt *qctxt,
303 unsigned int id, int type)
305 return qctxt->lqc_handler ? 1 : 0;
309 schedule_dqacq(struct obd_device *obd, struct lustre_quota_ctxt *qctxt,
310 struct qunit_data *qdata, int opc, int wait);
312 static int split_before_schedule_dqacq(struct obd_device *obd, struct lustre_quota_ctxt *qctxt,
313 struct qunit_data *qdata, int opc, int wait)
316 struct qunit_data tmp_qdata;
320 if (qctxt->lqc_import)
321 while (should_translate_quota(qctxt->lqc_import) &&
322 qdata->qd_count > MAX_QUOTA_COUNT32) {
325 tmp_qdata.qd_count = MAX_QUOTA_COUNT32;
326 qdata->qd_count -= tmp_qdata.qd_count;
327 ret = schedule_dqacq(obd, qctxt, &tmp_qdata, opc, wait);
332 if (qdata->qd_count){
333 ret = schedule_dqacq(obd, qctxt, qdata, opc, wait);
342 dqacq_completion(struct obd_device *obd,
343 struct lustre_quota_ctxt *qctxt,
344 struct qunit_data *qdata, int rc, int opc)
346 struct lustre_qunit *qunit = NULL;
347 struct super_block *sb = qctxt->lqc_sb;
348 unsigned long qunit_sz;
349 struct qunit_waiter *qw, *tmp;
351 __u32 qdata_type = qdata->qd_flags & QUOTA_IS_GRP;
352 __u32 is_blk = (qdata->qd_flags & QUOTA_IS_BLOCK) >> 1;
353 __u64 qd_tmp = qdata->qd_count;
358 qunit_sz = is_blk ? qctxt->lqc_bunit_sz : qctxt->lqc_iunit_sz;
359 div_r = do_div(qd_tmp, qunit_sz);
362 /* update local operational quota file */
364 __u32 count = QUSG(qdata->qd_count, is_blk);
365 struct obd_quotactl *qctl;
370 GOTO(out, err = -ENOMEM);
372 /* acq/rel qunit for specified uid/gid is serialized,
373 * so there is no race between get fs quota limit and
374 * set fs quota limit */
375 qctl->qc_cmd = Q_GETQUOTA;
376 qctl->qc_id = qdata->qd_id;
377 qctl->qc_type = qdata_type;
378 err = fsfilt_quotactl(obd, sb, qctl);
380 CERROR("error get quota fs limit! (rc:%d)\n", err);
385 qctl->qc_dqblk.dqb_valid = QIF_BLIMITS;
386 hardlimit = &qctl->qc_dqblk.dqb_bhardlimit;
388 qctl->qc_dqblk.dqb_valid = QIF_ILIMITS;
389 hardlimit = &qctl->qc_dqblk.dqb_ihardlimit;
394 INC_QLIMIT(*hardlimit, count);
397 LASSERT(count < *hardlimit);
404 /* clear quota limit */
408 qctl->qc_cmd = Q_SETQUOTA;
409 err = fsfilt_quotactl(obd, sb, qctl);
411 CERROR("error set quota fs limit! (rc:%d)\n", err);
413 QDATA_DEBUG(qdata, "%s completion\n",
414 opc == QUOTA_DQACQ ? "DQACQ" : "DQREL");
417 } else if (rc == -EDQUOT) {
418 QDATA_DEBUG(qdata, "acquire qunit got EDQUOT.\n");
419 } else if (rc == -EBUSY) {
420 QDATA_DEBUG(qdata, "it's is recovering, got EBUSY.\n");
422 CERROR("acquire qunit got error! (rc:%d)\n", rc);
425 /* remove the qunit from hash */
426 spin_lock(&qunit_hash_lock);
428 qunit = dqacq_in_flight(qctxt, qdata);
429 /* this qunit has been removed by qctxt_cleanup() */
431 spin_unlock(&qunit_hash_lock);
435 LASSERT(opc == qunit->lq_opc);
436 remove_qunit_nolock(qunit);
438 /* wake up all waiters */
439 list_for_each_entry_safe(qw, tmp, &qunit->lq_waiters, qw_entry) {
440 list_del_init(&qw->qw_entry);
442 wake_up(&qw->qw_waitq);
445 spin_unlock(&qunit_hash_lock);
449 /* don't reschedule in such cases:
450 * - acq/rel failure, but not for quota recovery.
451 * - local dqacq/dqrel.
452 * - local disk io failure.
454 if (err || (rc && rc != -EBUSY) ||
455 is_master(obd, qctxt, qdata->qd_id, qdata_type))
458 /* reschedule another dqacq/dqrel if needed */
460 rc = check_cur_qunit(obd, qctxt, qdata);
463 opc = rc == 1 ? QUOTA_DQACQ : QUOTA_DQREL;
464 rc = split_before_schedule_dqacq(obd, qctxt, qdata, opc, 0);
465 QDATA_DEBUG(qdata, "reschedudle opc(%d) rc(%d)\n", opc, rc);
470 struct dqacq_async_args {
471 struct lustre_quota_ctxt *aa_ctxt;
472 struct lustre_qunit *aa_qunit;
475 static int dqacq_interpret(struct ptlrpc_request *req, void *data, int rc)
477 struct dqacq_async_args *aa = (struct dqacq_async_args *)data;
478 struct lustre_quota_ctxt *qctxt = aa->aa_ctxt;
479 struct lustre_qunit *qunit = aa->aa_qunit;
480 struct obd_device *obd = req->rq_import->imp_obd;
481 struct qunit_data *qdata = NULL;
482 struct qunit_data_old *qdata_old = NULL;
486 LASSERT(req->rq_import);
487 if ((req->rq_import->imp_connect_data.ocd_connect_flags & OBD_CONNECT_QUOTA64) &&
488 !OBD_FAIL_CHECK(OBD_FAIL_QUOTA_QD_COUNT_32BIT)) {
489 CDEBUG(D_QUOTA, "qd_count is 64bit!\n");
490 qdata = lustre_swab_reqbuf(req, REPLY_REC_OFF, sizeof(*qdata), lustre_swab_qdata);
492 CDEBUG(D_QUOTA, "qd_count is 32bit!\n");
493 qdata_old = lustre_swab_reqbuf(req, REPLY_REC_OFF, sizeof(struct qunit_data_old),
494 lustre_swab_qdata_old);
495 qdata = lustre_quota_old_to_new(qdata_old);
498 DEBUG_REQ(D_ERROR, req, "error unpacking qunit_data\n");
502 LASSERT(qdata->qd_id == qunit->lq_data.qd_id &&
503 (qdata->qd_flags & QUOTA_IS_GRP) == (qunit->lq_data.qd_flags & QUOTA_IS_GRP) &&
504 (qdata->qd_count == qunit->lq_data.qd_count ||
505 qdata->qd_count == 0));
507 QDATA_DEBUG(qdata, "%s interpret rc(%d).\n",
508 lustre_msg_get_opc(req->rq_reqmsg) == QUOTA_DQACQ ?
509 "DQACQ" : "DQREL", rc);
511 rc = dqacq_completion(obd, qctxt, qdata, rc,
512 lustre_msg_get_opc(req->rq_reqmsg));
517 static int got_qunit(struct qunit_waiter *waiter)
521 spin_lock(&qunit_hash_lock);
522 rc = list_empty(&waiter->qw_entry);
523 spin_unlock(&qunit_hash_lock);
528 schedule_dqacq(struct obd_device *obd,
529 struct lustre_quota_ctxt *qctxt,
530 struct qunit_data *qdata, int opc, int wait)
532 struct lustre_qunit *qunit, *empty;
533 struct qunit_waiter qw;
534 struct l_wait_info lwi = { 0 };
535 struct ptlrpc_request *req;
536 struct qunit_data *reqdata;
537 struct dqacq_async_args *aa;
538 int size[2] = { sizeof(struct ptlrpc_body), sizeof(*reqdata) };
542 INIT_LIST_HEAD(&qw.qw_entry);
543 init_waitqueue_head(&qw.qw_waitq);
546 if ((empty = alloc_qunit(qctxt, qdata, opc)) == NULL)
549 spin_lock(&qunit_hash_lock);
551 qunit = dqacq_in_flight(qctxt, qdata);
554 list_add_tail(&qw.qw_entry, &qunit->lq_waiters);
555 spin_unlock(&qunit_hash_lock);
558 goto wait_completion;
561 insert_qunit_nolock(qctxt, qunit);
563 list_add_tail(&qw.qw_entry, &qunit->lq_waiters);
564 spin_unlock(&qunit_hash_lock);
568 /* master is going to dqacq/dqrel from itself */
569 if (is_master(obd, qctxt, qdata->qd_id, qdata->qd_flags & QUOTA_IS_GRP)) {
571 QDATA_DEBUG(qdata, "local %s.\n",
572 opc == QUOTA_DQACQ ? "DQACQ" : "DQREL");
573 rc = qctxt->lqc_handler(obd, qdata, opc);
574 rc2 = dqacq_completion(obd, qctxt, qdata, rc, opc);
575 RETURN((rc && rc != -EDQUOT) ? rc : rc2);
578 /* build dqacq/dqrel request */
579 LASSERT(qctxt->lqc_import);
580 req = ptlrpc_prep_req(qctxt->lqc_import, LUSTRE_MDS_VERSION, opc, 2,
583 dqacq_completion(obd, qctxt, qdata, -ENOMEM, opc);
587 LASSERT(!should_translate_quota(qctxt->lqc_import) ||
588 qdata->qd_count <= MAX_QUOTA_COUNT32);
589 if (should_translate_quota(qctxt->lqc_import) ||
590 OBD_FAIL_CHECK(OBD_FAIL_QUOTA_QD_COUNT_32BIT))
592 struct qunit_data_old *reqdata_old, *tmp;
594 reqdata_old = lustre_msg_buf(req->rq_reqmsg, REPLY_REC_OFF,
595 sizeof(*reqdata_old));
596 tmp = lustre_quota_new_to_old(qdata);
598 size[1] = sizeof(*reqdata_old);
599 CDEBUG(D_QUOTA, "qd_count is 32bit!\n");
601 reqdata = lustre_msg_buf(req->rq_reqmsg, REPLY_REC_OFF,
604 size[1] = sizeof(*reqdata);
605 CDEBUG(D_QUOTA, "qd_count is 64bit!\n");
607 ptlrpc_req_set_repsize(req, 2, size);
609 CLASSERT(sizeof(*aa) <= sizeof(req->rq_async_args));
610 aa = (struct dqacq_async_args *)&req->rq_async_args;
612 aa->aa_qunit = qunit;
614 req->rq_interpret_reply = dqacq_interpret;
615 ptlrpcd_add_req(req);
617 QDATA_DEBUG(qdata, "%s scheduled.\n",
618 opc == QUOTA_DQACQ ? "DQACQ" : "DQREL");
621 struct qunit_data *p = &qunit->lq_data;
622 QDATA_DEBUG(p, "wait for dqacq.\n");
624 l_wait_event(qw.qw_waitq, got_qunit(&qw), &lwi);
628 CDEBUG(D_QUOTA, "wait dqacq done. (rc:%d)\n", qw.qw_rc);
634 qctxt_adjust_qunit(struct obd_device *obd, struct lustre_quota_ctxt *qctxt,
635 uid_t uid, gid_t gid, __u32 isblk, int wait)
637 int ret, rc = 0, i = USRQUOTA;
638 __u32 id[MAXQUOTAS] = { uid, gid };
639 struct qunit_data qdata[MAXQUOTAS];
642 CLASSERT(MAXQUOTAS < 4);
643 if (!sb_any_quota_enabled(qctxt->lqc_sb))
646 for (i = 0; i < MAXQUOTAS; i++) {
647 qdata[i].qd_id = id[i];
648 qdata[i].qd_flags = 0;
649 qdata[i].qd_flags |= i;
650 qdata[i].qd_flags |= isblk ? QUOTA_IS_BLOCK : 0;
651 qdata[i].qd_count = 0;
653 ret = check_cur_qunit(obd, qctxt, &qdata[i]);
656 /* need acquire or release */
657 opc = ret == 1 ? QUOTA_DQACQ : QUOTA_DQREL;
658 ret = split_before_schedule_dqacq(obd, qctxt, &qdata[i],
669 qctxt_wait_pending_dqacq(struct lustre_quota_ctxt *qctxt, unsigned int id,
670 unsigned short type, int isblk)
672 struct lustre_qunit *qunit = NULL;
673 struct qunit_waiter qw;
674 struct qunit_data qdata;
675 struct l_wait_info lwi = { 0 };
678 INIT_LIST_HEAD(&qw.qw_entry);
679 init_waitqueue_head(&qw.qw_waitq);
684 qdata.qd_flags |= type;
685 qdata.qd_flags |= isblk ? QUOTA_IS_BLOCK : 0;
688 spin_lock(&qunit_hash_lock);
690 qunit = dqacq_in_flight(qctxt, &qdata);
692 list_add_tail(&qw.qw_entry, &qunit->lq_waiters);
694 spin_unlock(&qunit_hash_lock);
697 struct qunit_data *p = &qdata;
698 QDATA_DEBUG(p, "wait for dqacq completion.\n");
699 l_wait_event(qw.qw_waitq, got_qunit(&qw), &lwi);
700 QDATA_DEBUG(p, "wait dqacq done. (rc:%d)\n", qw.qw_rc);
706 qctxt_init(struct lustre_quota_ctxt *qctxt, struct super_block *sb,
707 dqacq_handler_t handler)
712 rc = ptlrpcd_addref();
716 qctxt->lqc_handler = handler;
718 qctxt->lqc_import = NULL;
719 qctxt->lqc_recovery = 0;
720 qctxt->lqc_atype = 0;
721 qctxt->lqc_status= 0;
722 qctxt->lqc_bunit_sz = default_bunit_sz;
723 qctxt->lqc_btune_sz = default_bunit_sz / 100 * default_btune_ratio;
724 qctxt->lqc_iunit_sz = default_iunit_sz;
725 qctxt->lqc_itune_sz = default_iunit_sz * default_itune_ratio / 100;
730 void qctxt_cleanup(struct lustre_quota_ctxt *qctxt, int force)
732 struct lustre_qunit *qunit, *tmp;
733 struct qunit_waiter *qw, *tmp2;
737 spin_lock(&qunit_hash_lock);
739 for (i = 0; i < NR_DQHASH; i++) {
740 list_for_each_entry_safe(qunit, tmp, &qunit_hash[i], lq_hash) {
741 if (qunit->lq_ctxt != qctxt)
744 remove_qunit_nolock(qunit);
745 /* wake up all waiters */
746 list_for_each_entry_safe(qw, tmp2, &qunit->lq_waiters,
748 list_del_init(&qw->qw_entry);
750 wake_up(&qw->qw_waitq);
756 spin_unlock(&qunit_hash_lock);
763 struct qslave_recov_thread_data {
764 struct obd_device *obd;
765 struct lustre_quota_ctxt *qctxt;
766 struct completion comp;
769 /* FIXME only recovery block quota by now */
770 static int qslave_recovery_main(void *arg)
772 struct qslave_recov_thread_data *data = arg;
773 struct obd_device *obd = data->obd;
774 struct lustre_quota_ctxt *qctxt = data->qctxt;
779 ptlrpc_daemonize("qslave_recovd");
781 complete(&data->comp);
783 if (qctxt->lqc_recovery)
785 qctxt->lqc_recovery = 1;
787 for (type = USRQUOTA; type < MAXQUOTAS; type++) {
788 struct qunit_data qdata;
789 struct quota_info *dqopt = sb_dqopt(qctxt->lqc_sb);
790 struct list_head id_list;
791 struct dquot_id *dqid, *tmp;
794 LOCK_DQONOFF_MUTEX(dqopt);
795 if (!sb_has_quota_enabled(qctxt->lqc_sb, type)) {
796 UNLOCK_DQONOFF_MUTEX(dqopt);
800 LASSERT(dqopt->files[type] != NULL);
801 INIT_LIST_HEAD(&id_list);
802 #ifndef KERNEL_SUPPORTS_QUOTA_READ
803 rc = fsfilt_qids(obd, dqopt->files[type], NULL, type, &id_list);
805 rc = fsfilt_qids(obd, NULL, dqopt->files[type], type, &id_list);
807 UNLOCK_DQONOFF_MUTEX(dqopt);
809 CERROR("Get ids from quota file failed. (rc:%d)\n", rc);
811 list_for_each_entry_safe(dqid, tmp, &id_list, di_link) {
812 list_del_init(&dqid->di_link);
813 /* skip slave recovery on itself */
814 if (is_master(obd, qctxt, dqid->di_id, type))
816 if (rc && rc != -EBUSY)
819 qdata.qd_id = dqid->di_id;
821 qdata.qd_flags |= type;
822 qdata.qd_flags |= QUOTA_IS_BLOCK;
825 ret = check_cur_qunit(obd, qctxt, &qdata);
828 opc = ret == 1 ? QUOTA_DQACQ : QUOTA_DQREL;
829 rc = split_before_schedule_dqacq(obd, qctxt, &qdata, opc, 0);
834 CDEBUG(rc == -EBUSY ? D_QUOTA : D_ERROR,
835 "qslave recovery failed! (id:%d type:%d "
836 " rc:%d)\n", dqid->di_id, type, rc);
842 qctxt->lqc_recovery = 0;
847 qslave_start_recovery(struct obd_device *obd, struct lustre_quota_ctxt *qctxt)
849 struct qslave_recov_thread_data data;
853 if (!sb_any_quota_enabled(qctxt->lqc_sb))
858 init_completion(&data.comp);
860 rc = kernel_thread(qslave_recovery_main, &data, CLONE_VM|CLONE_FILES);
862 CERROR("Cannot start quota recovery thread: rc %d\n", rc);
865 wait_for_completion(&data.comp);