1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
38 # define EXPORT_SYMTAB
40 #define DEBUG_SUBSYSTEM S_LQUOTA
43 # include <linux/version.h>
44 # include <linux/module.h>
45 # include <linux/init.h>
46 # include <linux/fs.h>
47 # include <linux/jbd.h>
48 # include <linux/smp_lock.h>
49 # include <linux/buffer_head.h>
50 # include <linux/workqueue.h>
51 # include <linux/mount.h>
52 #else /* __KERNEL__ */
53 # include <liblustre.h>
56 #include <obd_class.h>
57 #include <lustre_mds.h>
58 #include <lustre_dlm.h>
59 #include <lustre_cfg.h>
61 #include <lustre_fsfilt.h>
62 #include <lustre_quota.h>
63 #include <lprocfs_status.h>
64 #include "quota_internal.h"
68 #ifdef HAVE_QUOTA_SUPPORT
70 static cfs_time_t last_print = 0;
71 static spinlock_t last_print_lock = SPIN_LOCK_UNLOCKED;
73 static int filter_quota_setup(struct obd_device *obd)
76 struct obd_device_target *obt = &obd->u.obt;
79 init_rwsem(&obt->obt_rwsem);
80 obt->obt_qfmt = LUSTRE_QUOTA_V2;
81 atomic_set(&obt->obt_quotachecking, 1);
82 rc = qctxt_init(obd, NULL);
84 CERROR("initialize quota context failed! (rc:%d)\n", rc);
89 static int filter_quota_cleanup(struct obd_device *obd)
92 qctxt_cleanup(&obd->u.obt.obt_qctxt, 0);
96 static int filter_quota_setinfo(struct obd_device *obd, void *data)
98 struct obd_export *exp = data;
99 struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt;
100 struct obd_import *imp;
103 /* setup the quota context import */
104 spin_lock(&qctxt->lqc_lock);
105 qctxt->lqc_import = exp->exp_imp_reverse;
106 spin_unlock(&qctxt->lqc_lock);
107 CDEBUG(D_QUOTA, "%s: lqc_import(%p) of obd(%p) is reactivated now, \n",
108 obd->obd_name,exp->exp_imp_reverse, obd);
110 /* make imp's connect flags equal relative exp's connect flags
111 * adding it to avoid the scan export list
113 imp = qctxt->lqc_import;
115 imp->imp_connect_data.ocd_connect_flags |=
116 (exp->exp_connect_flags &
117 (OBD_CONNECT_QUOTA64 | OBD_CONNECT_CHANGE_QS));
119 cfs_waitq_signal(&qctxt->lqc_wait_for_qmaster);
120 /* start quota slave recovery thread. (release high limits) */
121 qslave_start_recovery(obd, qctxt);
125 static int filter_quota_clearinfo(struct obd_export *exp, struct obd_device *obd)
127 struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt;
130 /* lquota may be not set up before destroying export, b=14896 */
131 if (!obd->obd_set_up)
134 /* when exp->exp_imp_reverse is destroyed, the corresponding lqc_import
135 * should be invalid b=12374 */
136 if (qctxt->lqc_import && qctxt->lqc_import == exp->exp_imp_reverse) {
137 spin_lock(&qctxt->lqc_lock);
138 qctxt->lqc_import = NULL;
139 spin_unlock(&qctxt->lqc_lock);
140 dqacq_interrupt(qctxt);
141 CDEBUG(D_QUOTA, "%s: lqc_import of obd(%p) is invalid now.\n",
147 static int filter_quota_enforce(struct obd_device *obd, unsigned int ignore)
151 if (!sb_any_quota_enabled(obd->u.obt.obt_sb))
155 CDEBUG(D_QUOTA, "blocks will be written with ignoring quota.\n");
156 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
158 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
164 static int filter_quota_getflag(struct obd_device *obd, struct obdo *oa)
166 struct obd_device_target *obt = &obd->u.obt;
167 struct lustre_quota_ctxt *qctxt = &obt->obt_qctxt;
168 int err, cnt, rc = 0;
169 struct obd_quotactl *oqctl;
172 if (!sb_any_quota_enabled(obt->obt_sb))
175 OBD_ALLOC_PTR(oqctl);
177 CERROR("Not enough memory!");
181 /* set over quota flags for a uid/gid */
182 oa->o_valid |= OBD_MD_FLUSRQUOTA | OBD_MD_FLGRPQUOTA;
183 oa->o_flags &= ~(OBD_FL_NO_USRQUOTA | OBD_FL_NO_GRPQUOTA);
185 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
186 struct quota_adjust_qunit oqaq_tmp;
187 struct lustre_qunit_size *lqs = NULL;
189 oqaq_tmp.qaq_flags = cnt;
190 oqaq_tmp.qaq_id = (cnt == USRQUOTA) ? oa->o_uid : oa->o_gid;
192 quota_search_lqs(NULL, &oqaq_tmp, qctxt, &lqs);
194 spin_lock(&lqs->lqs_lock);
195 if (lqs->lqs_bunit_sz <= qctxt->lqc_sync_blk) {
196 oa->o_flags |= (cnt == USRQUOTA) ?
197 OBD_FL_NO_USRQUOTA : OBD_FL_NO_GRPQUOTA;
198 spin_unlock(&lqs->lqs_lock);
199 CDEBUG(D_QUOTA, "set sync flag: bunit(%lu), "
200 "sync_blk(%d)\n", lqs->lqs_bunit_sz,
201 qctxt->lqc_sync_blk);
202 /* this is for quota_search_lqs */
206 spin_unlock(&lqs->lqs_lock);
207 /* this is for quota_search_lqs */
211 memset(oqctl, 0, sizeof(*oqctl));
213 oqctl->qc_cmd = Q_GETQUOTA;
214 oqctl->qc_type = cnt;
215 oqctl->qc_id = (cnt == USRQUOTA) ? oa->o_uid : oa->o_gid;
216 err = fsfilt_quotactl(obd, obt->obt_sb, oqctl);
220 oa->o_valid &= ~((cnt == USRQUOTA) ? OBD_MD_FLUSRQUOTA :
225 if (oqctl->qc_dqblk.dqb_bhardlimit &&
226 (toqb(oqctl->qc_dqblk.dqb_curspace) >=
227 oqctl->qc_dqblk.dqb_bhardlimit))
228 oa->o_flags |= (cnt == USRQUOTA) ?
229 OBD_FL_NO_USRQUOTA : OBD_FL_NO_GRPQUOTA;
236 * check whether the left quota of certain uid and gid can satisfy a block_write
237 * or inode_create rpc. When need to acquire quota, return QUOTA_RET_ACQUOTA
239 static int quota_check_common(struct obd_device *obd, unsigned int uid,
240 unsigned int gid, int count, int cycle, int isblk,
241 struct inode *inode, int frags, int *pending)
243 struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt;
245 __u32 id[MAXQUOTAS] = { uid, gid };
246 struct qunit_data qdata[MAXQUOTAS];
248 int rc = 0, rc2[2] = { 0, 0 };
251 CLASSERT(MAXQUOTAS < 4);
252 if (!sb_any_quota_enabled(qctxt->lqc_sb))
255 spin_lock(&qctxt->lqc_lock);
256 if (!qctxt->lqc_valid){
257 spin_unlock(&qctxt->lqc_lock);
260 spin_unlock(&qctxt->lqc_lock);
262 for (i = 0; i < MAXQUOTAS; i++) {
263 struct lustre_qunit_size *lqs = NULL;
265 qdata[i].qd_id = id[i];
266 qdata[i].qd_flags = i;
268 QDATA_SET_BLK(&qdata[i]);
269 qdata[i].qd_count = 0;
271 /* ignore root user */
272 if (qdata[i].qd_id == 0 && !QDATA_IS_GRP(&qdata[i]))
275 quota_search_lqs(&qdata[i], NULL, qctxt, &lqs);
279 rc2[i] = compute_remquota(obd, qctxt, &qdata[i], isblk);
280 spin_lock(&lqs->lqs_lock);
283 *pending = count * CFS_PAGE_SIZE;
284 /* in order to complete this write, we need extra
285 * meta blocks. This function can get it through
286 * data needed to be written b=16542 */
289 rc = fsfilt_get_mblk(obd, qctxt->lqc_sb,
298 lqs->lqs_bwrite_pending += *pending;
301 lqs->lqs_iwrite_pending += *pending;
305 /* if xx_rec < 0, that means quota are releasing,
306 * and it may return before we use quota. So if
307 * we find this situation, we assuming it has
308 * returned b=18491 */
309 if (isblk && lqs->lqs_blk_rec < 0) {
310 if (qdata[i].qd_count < -lqs->lqs_blk_rec)
311 qdata[i].qd_count = 0;
313 qdata[i].qd_count += lqs->lqs_blk_rec;
315 if (!isblk && lqs->lqs_ino_rec < 0) {
316 if (qdata[i].qd_count < -lqs->lqs_ino_rec)
317 qdata[i].qd_count = 0;
319 qdata[i].qd_count += lqs->lqs_ino_rec;
323 CDEBUG(D_QUOTA, "count: %d, lqs pending: %lu, qd_count: "LPU64
324 ", metablocks: %d, isblk: %d, pending: %d.\n", count,
325 isblk ? lqs->lqs_bwrite_pending : lqs->lqs_iwrite_pending,
326 qdata[i].qd_count, mb, isblk, *pending);
327 if (rc2[i] == QUOTA_RET_OK) {
328 if (isblk && qdata[i].qd_count < lqs->lqs_bwrite_pending)
329 rc2[i] = QUOTA_RET_ACQUOTA;
330 if (!isblk && qdata[i].qd_count <
331 lqs->lqs_iwrite_pending)
332 rc2[i] = QUOTA_RET_ACQUOTA;
335 spin_unlock(&lqs->lqs_lock);
337 /* When cycle is zero, lqs_*_pending will be changed. We will
338 * get reference of the lqs here and put reference of lqs in
339 * quota_pending_commit b=14784 */
343 /* this is for quota_search_lqs */
347 if (rc2[0] == QUOTA_RET_ACQUOTA || rc2[1] == QUOTA_RET_ACQUOTA)
348 RETURN(QUOTA_RET_ACQUOTA);
353 static int quota_chk_acq_common(struct obd_device *obd, unsigned int uid,
354 unsigned int gid, int count, int *pending,
355 quota_acquire acquire,
356 struct obd_trans_info *oti, int isblk,
357 struct inode *inode, int frags)
359 struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt;
360 struct timeval work_start;
361 struct timeval work_end;
363 struct l_wait_info lwi = { 0 };
364 int rc = 0, cycle = 0, count_err = 1;
367 CDEBUG(D_QUOTA, "check quota for %s\n", obd->obd_name);
369 /* Unfortunately, if quota master is too busy to handle the
370 * pre-dqacq in time and quota hash on ost is used up, we
371 * have to wait for the completion of in flight dqacq/dqrel,
372 * in order to get enough quota for write b=12588 */
373 do_gettimeofday(&work_start);
374 while ((rc = quota_check_common(obd, uid, gid, count, cycle, isblk,
375 inode, frags, pending)) &
378 spin_lock(&qctxt->lqc_lock);
379 if (!qctxt->lqc_import && oti) {
380 spin_unlock(&qctxt->lqc_lock);
382 LASSERT(oti && oti->oti_thread &&
383 oti->oti_thread->t_watchdog);
385 lc_watchdog_disable(oti->oti_thread->t_watchdog);
386 CDEBUG(D_QUOTA, "sleep for quota master\n");
387 l_wait_event(qctxt->lqc_wait_for_qmaster, check_qm(qctxt),
389 CDEBUG(D_QUOTA, "wake up when quota master is back\n");
390 lc_watchdog_touch(oti->oti_thread->t_watchdog);
392 spin_unlock(&qctxt->lqc_lock);
397 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_HOLD_WRITE_RPC, 90);
398 /* after acquire(), we should run quota_check_common again
399 * so that we confirm there are enough quota to finish write */
400 rc = acquire(obd, uid, gid, oti, isblk);
402 /* please reference to dqacq_completion for the below */
403 /* a new request is finished, try again */
404 if (rc == QUOTA_REQ_RETURNED) {
405 CDEBUG(D_QUOTA, "finish a quota req, try again\n");
409 /* it is out of quota already */
411 CDEBUG(D_QUOTA, "out of quota, return -EDQUOT\n");
415 /* -EBUSY and others, wait a second and try again */
418 struct l_wait_info lwi;
420 if (oti && oti->oti_thread && oti->oti_thread->t_watchdog)
421 lc_watchdog_touch(oti->oti_thread->t_watchdog);
422 CDEBUG(D_QUOTA, "rc: %d, count_err: %d\n", rc,
425 init_waitqueue_head(&waitq);
426 lwi = LWI_TIMEOUT(cfs_time_seconds(min(cycle, 10)), NULL,
428 l_wait_event(waitq, 0, &lwi);
431 if (rc < 0 || cycle % 10 == 2) {
432 spin_lock(&last_print_lock);
433 if (last_print == 0 ||
434 cfs_time_before((last_print + cfs_time_seconds(30)),
435 cfs_time_current())) {
436 last_print = cfs_time_current();
437 spin_unlock(&last_print_lock);
438 CWARN("still haven't managed to acquire quota "
439 "space from the quota master after %d "
440 "retries (err=%d, rc=%d)\n",
441 cycle, count_err - 1, rc);
443 spin_unlock(&last_print_lock);
447 CDEBUG(D_QUOTA, "recheck quota with rc: %d, cycle: %d\n", rc,
450 do_gettimeofday(&work_end);
451 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
452 lprocfs_counter_add(qctxt->lqc_stats,
453 isblk ? LQUOTA_WAIT_FOR_CHK_BLK :
454 LQUOTA_WAIT_FOR_CHK_INO,
461 * when a block_write or inode_create rpc is finished, adjust the record for
462 * pending blocks and inodes
464 static int quota_pending_commit(struct obd_device *obd, unsigned int uid,
465 unsigned int gid, int pending, int isblk)
467 struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt;
468 struct timeval work_start;
469 struct timeval work_end;
472 __u32 id[MAXQUOTAS] = { uid, gid };
473 struct qunit_data qdata[MAXQUOTAS];
476 CDEBUG(D_QUOTA, "commit pending quota for %s\n", obd->obd_name);
477 CLASSERT(MAXQUOTAS < 4);
478 if (!sb_any_quota_enabled(qctxt->lqc_sb))
481 do_gettimeofday(&work_start);
482 for (i = 0; i < MAXQUOTAS; i++) {
483 struct lustre_qunit_size *lqs = NULL;
485 qdata[i].qd_id = id[i];
486 qdata[i].qd_flags = i;
488 QDATA_SET_BLK(&qdata[i]);
489 qdata[i].qd_count = 0;
491 if (qdata[i].qd_id == 0 && !QDATA_IS_GRP(&qdata[i]))
494 quota_search_lqs(&qdata[i], NULL, qctxt, &lqs);
497 spin_lock(&lqs->lqs_lock);
499 if (lqs->lqs_bwrite_pending >= pending) {
500 lqs->lqs_bwrite_pending -= pending;
501 spin_unlock(&lqs->lqs_lock);
504 spin_unlock(&lqs->lqs_lock);
506 "there are too many blocks!\n");
509 if (lqs->lqs_iwrite_pending >= pending) {
510 lqs->lqs_iwrite_pending -= pending;
511 spin_unlock(&lqs->lqs_lock);
514 spin_unlock(&lqs->lqs_lock);
516 "there are too many files!\n");
519 CDEBUG(D_QUOTA, "lqs pending: %lu, pending: %d, "
521 isblk ? lqs->lqs_bwrite_pending :
522 lqs->lqs_iwrite_pending, pending, isblk);
525 /* When lqs_*_pening is changed back, we'll putref lqs
531 do_gettimeofday(&work_end);
532 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
533 lprocfs_counter_add(qctxt->lqc_stats,
534 isblk ? LQUOTA_WAIT_FOR_COMMIT_BLK :
535 LQUOTA_WAIT_FOR_COMMIT_INO,
541 static int mds_quota_init(void)
543 return lustre_dquot_init();
546 static int mds_quota_exit(void)
552 static int mds_quota_setup(struct obd_device *obd)
554 struct obd_device_target *obt = &obd->u.obt;
555 struct mds_obd *mds = &obd->u.mds;
559 if (unlikely(mds->mds_quota)) {
560 CWARN("try to reinitialize quota context!\n");
564 init_rwsem(&obt->obt_rwsem);
565 obt->obt_qfmt = LUSTRE_QUOTA_V2;
566 mds->mds_quota_info.qi_version = LUSTRE_QUOTA_V2;
567 atomic_set(&obt->obt_quotachecking, 1);
568 /* initialize quota master and quota context */
569 sema_init(&mds->mds_qonoff_sem, 1);
570 rc = qctxt_init(obd, dqacq_handler);
572 CERROR("initialize quota context failed! (rc:%d)\n", rc);
579 static int mds_quota_cleanup(struct obd_device *obd)
582 if (unlikely(!obd->u.mds.mds_quota))
585 qctxt_cleanup(&obd->u.obt.obt_qctxt, 0);
589 static int mds_quota_setinfo(struct obd_device *obd, void *data)
591 struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt;
594 if (unlikely(!obd->u.mds.mds_quota))
598 QUOTA_MASTER_READY(qctxt);
600 QUOTA_MASTER_UNREADY(qctxt);
604 static int mds_quota_fs_cleanup(struct obd_device *obd)
606 struct mds_obd *mds = &obd->u.mds;
607 struct obd_quotactl oqctl;
610 if (unlikely(!mds->mds_quota))
614 memset(&oqctl, 0, sizeof(oqctl));
615 oqctl.qc_type = UGQUOTA;
617 down(&mds->mds_qonoff_sem);
618 mds_admin_quota_off(obd, &oqctl);
619 up(&mds->mds_qonoff_sem);
623 static int quota_acquire_common(struct obd_device *obd, unsigned int uid,
624 unsigned int gid, struct obd_trans_info *oti,
627 struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt;
631 rc = qctxt_adjust_qunit(obd, qctxt, uid, gid, isblk, 1, oti);
635 #endif /* HAVE_QUOTA_SUPPORT */
636 #endif /* __KERNEL__ */
638 struct osc_quota_info {
639 struct list_head oqi_hash; /* hash list */
640 struct client_obd *oqi_cli; /* osc obd */
641 unsigned int oqi_id; /* uid/gid of a file */
642 short oqi_type; /* quota type */
645 spinlock_t qinfo_list_lock = SPIN_LOCK_UNLOCKED;
647 static struct list_head qinfo_hash[NR_DQHASH];
648 /* SLAB cache for client quota context */
649 cfs_mem_cache_t *qinfo_cachep = NULL;
651 static inline int hashfn(struct client_obd *cli, unsigned long id, int type)
652 __attribute__((__const__));
654 static inline int hashfn(struct client_obd *cli, unsigned long id, int type)
656 unsigned long tmp = ((unsigned long)cli>>6) ^ id;
657 tmp = (tmp * (MAXQUOTAS - type)) % NR_DQHASH;
661 /* caller must hold qinfo_list_lock */
662 static inline void insert_qinfo_hash(struct osc_quota_info *oqi)
664 struct list_head *head = qinfo_hash +
665 hashfn(oqi->oqi_cli, oqi->oqi_id, oqi->oqi_type);
667 LASSERT_SPIN_LOCKED(&qinfo_list_lock);
668 list_add(&oqi->oqi_hash, head);
671 /* caller must hold qinfo_list_lock */
672 static inline void remove_qinfo_hash(struct osc_quota_info *oqi)
674 LASSERT_SPIN_LOCKED(&qinfo_list_lock);
675 list_del_init(&oqi->oqi_hash);
678 /* caller must hold qinfo_list_lock */
679 static inline struct osc_quota_info *find_qinfo(struct client_obd *cli,
680 unsigned int id, int type)
682 unsigned int hashent = hashfn(cli, id, type);
683 struct osc_quota_info *oqi;
686 LASSERT_SPIN_LOCKED(&qinfo_list_lock);
687 list_for_each_entry(oqi, &qinfo_hash[hashent], oqi_hash) {
688 if (oqi->oqi_cli == cli &&
689 oqi->oqi_id == id && oqi->oqi_type == type)
695 static struct osc_quota_info *alloc_qinfo(struct client_obd *cli,
696 unsigned int id, int type)
698 struct osc_quota_info *oqi;
701 OBD_SLAB_ALLOC(oqi, qinfo_cachep, CFS_ALLOC_STD, sizeof(*oqi));
705 CFS_INIT_LIST_HEAD(&oqi->oqi_hash);
708 oqi->oqi_type = type;
713 static void free_qinfo(struct osc_quota_info *oqi)
715 OBD_SLAB_FREE(oqi, qinfo_cachep, sizeof(*oqi));
718 int osc_quota_chkdq(struct client_obd *cli, unsigned int uid, unsigned int gid)
721 int cnt, rc = QUOTA_OK;
724 spin_lock(&qinfo_list_lock);
725 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
726 struct osc_quota_info *oqi = NULL;
728 id = (cnt == USRQUOTA) ? uid : gid;
729 oqi = find_qinfo(cli, id, cnt);
735 spin_unlock(&qinfo_list_lock);
740 int osc_quota_setdq(struct client_obd *cli, unsigned int uid, unsigned int gid,
741 obd_flag valid, obd_flag flags)
749 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
750 struct osc_quota_info *oqi, *old;
752 if (!(valid & ((cnt == USRQUOTA) ?
753 OBD_MD_FLUSRQUOTA : OBD_MD_FLGRPQUOTA)))
756 id = (cnt == USRQUOTA) ? uid : gid;
757 noquota = (cnt == USRQUOTA) ?
758 (flags & OBD_FL_NO_USRQUOTA) : (flags & OBD_FL_NO_GRPQUOTA);
760 oqi = alloc_qinfo(cli, id, cnt);
762 spin_lock(&qinfo_list_lock);
764 old = find_qinfo(cli, id, cnt);
766 remove_qinfo_hash(old);
767 else if (!old && noquota)
768 insert_qinfo_hash(oqi);
770 spin_unlock(&qinfo_list_lock);
777 CERROR("not enough mem!\n");
786 int osc_quota_cleanup(struct obd_device *obd)
788 struct client_obd *cli = &obd->u.cli;
789 struct osc_quota_info *oqi, *n;
793 spin_lock(&qinfo_list_lock);
794 for (i = 0; i < NR_DQHASH; i++) {
795 list_for_each_entry_safe(oqi, n, &qinfo_hash[i], oqi_hash) {
796 if (oqi->oqi_cli != cli)
798 remove_qinfo_hash(oqi);
802 spin_unlock(&qinfo_list_lock);
807 int osc_quota_init(void)
812 LASSERT(qinfo_cachep == NULL);
813 qinfo_cachep = cfs_mem_cache_create("osc_quota_info",
814 sizeof(struct osc_quota_info),
819 for (i = 0; i < NR_DQHASH; i++)
820 CFS_INIT_LIST_HEAD(qinfo_hash + i);
825 int osc_quota_exit(void)
827 struct osc_quota_info *oqi, *n;
831 spin_lock(&qinfo_list_lock);
832 for (i = 0; i < NR_DQHASH; i++) {
833 list_for_each_entry_safe(oqi, n, &qinfo_hash[i], oqi_hash) {
834 remove_qinfo_hash(oqi);
838 spin_unlock(&qinfo_list_lock);
840 rc = cfs_mem_cache_destroy(qinfo_cachep);
841 LASSERTF(rc == 0, "couldn't destory qinfo_cachep slab\n");
848 #ifdef HAVE_QUOTA_SUPPORT
849 quota_interface_t mds_quota_interface = {
850 .quota_init = mds_quota_init,
851 .quota_exit = mds_quota_exit,
852 .quota_setup = mds_quota_setup,
853 .quota_cleanup = mds_quota_cleanup,
854 .quota_check = target_quota_check,
855 .quota_ctl = mds_quota_ctl,
856 .quota_setinfo = mds_quota_setinfo,
857 .quota_fs_cleanup = mds_quota_fs_cleanup,
858 .quota_recovery = mds_quota_recovery,
859 .quota_adjust = mds_quota_adjust,
860 .quota_chkquota = quota_chk_acq_common,
861 .quota_acquire = quota_acquire_common,
862 .quota_pending_commit = quota_pending_commit,
865 quota_interface_t filter_quota_interface = {
866 .quota_setup = filter_quota_setup,
867 .quota_cleanup = filter_quota_cleanup,
868 .quota_check = target_quota_check,
869 .quota_ctl = filter_quota_ctl,
870 .quota_setinfo = filter_quota_setinfo,
871 .quota_clearinfo = filter_quota_clearinfo,
872 .quota_enforce = filter_quota_enforce,
873 .quota_getflag = filter_quota_getflag,
874 .quota_acquire = quota_acquire_common,
875 .quota_adjust = filter_quota_adjust,
876 .quota_chkquota = quota_chk_acq_common,
877 .quota_adjust_qunit = filter_quota_adjust_qunit,
878 .quota_pending_commit = quota_pending_commit,
881 #endif /* __KERNEL__ */
883 quota_interface_t mdc_quota_interface = {
884 .quota_ctl = client_quota_ctl,
885 .quota_check = client_quota_check,
886 .quota_poll_check = client_quota_poll_check,
889 quota_interface_t lmv_quota_interface = {
890 .quota_ctl = lmv_quota_ctl,
891 .quota_check = lmv_quota_check,
894 quota_interface_t osc_quota_interface = {
895 .quota_ctl = client_quota_ctl,
896 .quota_check = client_quota_check,
897 .quota_poll_check = client_quota_poll_check,
898 .quota_init = osc_quota_init,
899 .quota_exit = osc_quota_exit,
900 .quota_chkdq = osc_quota_chkdq,
901 .quota_setdq = osc_quota_setdq,
902 .quota_cleanup = osc_quota_cleanup,
903 .quota_adjust_qunit = client_quota_adjust_qunit,
906 quota_interface_t lov_quota_interface = {
907 .quota_ctl = lov_quota_ctl,
908 .quota_check = lov_quota_check,
909 .quota_adjust_qunit = lov_quota_adjust_qunit,
914 cfs_proc_dir_entry_t *lquota_type_proc_dir = NULL;
916 static int __init init_lustre_quota(void)
918 #ifdef HAVE_QUOTA_SUPPORT
921 lquota_type_proc_dir = lprocfs_register(OBD_LQUOTA_DEVICENAME,
924 if (IS_ERR(lquota_type_proc_dir)) {
925 CERROR("LProcFS failed in lquota-init\n");
926 rc = PTR_ERR(lquota_type_proc_dir);
930 rc = qunit_cache_init();
934 PORTAL_SYMBOL_REGISTER(filter_quota_interface);
935 PORTAL_SYMBOL_REGISTER(mds_quota_interface);
937 PORTAL_SYMBOL_REGISTER(mdc_quota_interface);
938 PORTAL_SYMBOL_REGISTER(lmv_quota_interface);
939 PORTAL_SYMBOL_REGISTER(osc_quota_interface);
940 PORTAL_SYMBOL_REGISTER(lov_quota_interface);
944 static void /*__exit*/ exit_lustre_quota(void)
946 PORTAL_SYMBOL_UNREGISTER(mdc_quota_interface);
947 PORTAL_SYMBOL_UNREGISTER(lmv_quota_interface);
948 PORTAL_SYMBOL_UNREGISTER(osc_quota_interface);
949 PORTAL_SYMBOL_UNREGISTER(lov_quota_interface);
950 #ifdef HAVE_QUOTA_SUPPORT
951 PORTAL_SYMBOL_UNREGISTER(filter_quota_interface);
952 PORTAL_SYMBOL_UNREGISTER(mds_quota_interface);
954 qunit_cache_cleanup();
956 if (lquota_type_proc_dir)
957 lprocfs_remove(&lquota_type_proc_dir);
961 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
962 MODULE_DESCRIPTION("Lustre Quota");
963 MODULE_LICENSE("GPL");
965 cfs_module(lquota, "1.0.0", init_lustre_quota, exit_lustre_quota);
967 #ifdef HAVE_QUOTA_SUPPORT
968 EXPORT_SYMBOL(mds_quota_interface);
969 EXPORT_SYMBOL(filter_quota_interface);
971 EXPORT_SYMBOL(mdc_quota_interface);
972 EXPORT_SYMBOL(lmv_quota_interface);
973 EXPORT_SYMBOL(osc_quota_interface);
974 EXPORT_SYMBOL(lov_quota_interface);
975 #endif /* __KERNEL */