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 (c) 2006, 2010, Oracle and/or its affiliates. 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/smp_lock.h>
48 # include <linux/buffer_head.h>
49 # include <linux/workqueue.h>
50 # include <linux/mount.h>
51 #else /* __KERNEL__ */
52 # include <liblustre.h>
55 #include <obd_class.h>
56 #include <lustre_mds.h>
57 #include <lustre_dlm.h>
58 #include <lustre_cfg.h>
60 #include <lustre_fsfilt.h>
61 #include <lustre_quota.h>
62 #include <lprocfs_status.h>
63 #include "quota_internal.h"
67 #ifdef HAVE_QUOTA_SUPPORT
69 static cfs_time_t last_print = 0;
70 static spinlock_t last_print_lock = SPIN_LOCK_UNLOCKED;
72 static int filter_quota_setup(struct obd_device *obd)
75 struct obd_device_target *obt = &obd->u.obt;
79 obt->obt_qfmt = LUSTRE_QUOTA_V2;
81 obt->obt_qfmt = LUSTRE_QUOTA_V1;
83 atomic_set(&obt->obt_quotachecking, 1);
84 rc = qctxt_init(obd, NULL);
86 CERROR("initialize quota context failed! (rc:%d)\n", rc);
91 static int filter_quota_cleanup(struct obd_device *obd)
93 qctxt_cleanup(&obd->u.obt.obt_qctxt, 0);
97 static int filter_quota_setinfo(struct obd_export *exp, struct obd_device *obd)
99 struct obd_import *imp;
100 struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt;
103 /* setup the quota context import */
104 spin_lock(&obd->u.obt.obt_qctxt.lqc_lock);
105 obd->u.obt.obt_qctxt.lqc_import = exp->exp_imp_reverse;
106 spin_unlock(&obd->u.obt.obt_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 = exp->exp_imp_reverse;
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, &obd->u.obt.obt_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 ptlrpc_cleanup_imp(exp->exp_imp_reverse);
141 dqacq_interrupt(qctxt);
142 CDEBUG(D_QUOTA, "%s: lqc_import of obd(%p) is invalid now.\n",
148 static int target_quota_enforce(struct obd_device *obd, unsigned int ignore)
152 if (!ll_sb_any_quota_active(obd->u.obt.obt_sb))
155 if (!!cfs_cap_raised(CFS_CAP_SYS_RESOURCE) == !!ignore)
159 CDEBUG(D_QUOTA, "blocks will be written with ignoring quota.\n");
160 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
162 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
168 #define GET_OA_ID(flag, oa) (flag == USRQUOTA ? oa->o_uid : oa->o_gid)
169 static int filter_quota_getflag(struct obd_device *obd, struct obdo *oa)
171 struct obd_device_target *obt = &obd->u.obt;
172 struct lustre_quota_ctxt *qctxt = &obt->obt_qctxt;
173 int err, cnt, rc = 0;
174 struct obd_quotactl *oqctl;
177 if (!ll_sb_any_quota_active(obt->obt_sb))
180 OBD_ALLOC_PTR(oqctl);
184 /* set over quota flags for a uid/gid */
185 oa->o_valid |= OBD_MD_FLUSRQUOTA | OBD_MD_FLGRPQUOTA;
186 oa->o_flags &= ~(OBD_FL_NO_USRQUOTA | OBD_FL_NO_GRPQUOTA);
188 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
189 struct lustre_qunit_size *lqs = NULL;
191 lqs = quota_search_lqs(LQS_KEY(cnt, GET_OA_ID(cnt, oa)),
193 if (lqs == NULL || IS_ERR(lqs)) {
197 spin_lock(&lqs->lqs_lock);
198 if (lqs->lqs_bunit_sz <= qctxt->lqc_sync_blk) {
199 oa->o_flags |= (cnt == USRQUOTA) ?
200 OBD_FL_NO_USRQUOTA : OBD_FL_NO_GRPQUOTA;
201 CDEBUG(D_QUOTA, "set sync flag: bunit(%lu), "
202 "sync_blk(%d)\n", lqs->lqs_bunit_sz,
203 qctxt->lqc_sync_blk);
204 spin_unlock(&lqs->lqs_lock);
205 /* this is for quota_search_lqs */
209 spin_unlock(&lqs->lqs_lock);
210 /* this is for quota_search_lqs */
214 memset(oqctl, 0, sizeof(*oqctl));
216 oqctl->qc_cmd = Q_GETQUOTA;
217 oqctl->qc_type = cnt;
218 oqctl->qc_id = (cnt == USRQUOTA) ? oa->o_uid : oa->o_gid;
219 err = fsfilt_quotactl(obd, obt->obt_sb, oqctl);
223 oa->o_valid &= ~((cnt == USRQUOTA) ? OBD_MD_FLUSRQUOTA :
228 if (oqctl->qc_dqblk.dqb_bhardlimit &&
229 (toqb(oqctl->qc_dqblk.dqb_curspace) >=
230 oqctl->qc_dqblk.dqb_bhardlimit))
231 oa->o_flags |= (cnt == USRQUOTA) ?
232 OBD_FL_NO_USRQUOTA : OBD_FL_NO_GRPQUOTA;
238 static int filter_quota_acquire(struct obd_device *obd, unsigned int uid,
239 unsigned int gid, struct obd_trans_info *oti)
241 struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt;
245 rc = qctxt_adjust_qunit(obd, qctxt, uid, gid, LQUOTA_FLAGS_BLK, 1, oti);
249 /* check whether the left quota of certain uid and gid can satisfy a block_write
250 * or inode_create rpc. When need to acquire quota, return QUOTA_RET_ACQUOTA */
251 static int quota_check_common(struct obd_device *obd, unsigned int uid,
252 unsigned int gid, int count, int cycle, int isblk,
253 struct inode *inode, int frags, int pending[2])
255 struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt;
257 __u32 id[MAXQUOTAS] = { uid, gid };
258 struct qunit_data qdata[MAXQUOTAS];
260 int rc = 0, rc2[2] = { 0, 0 };
263 spin_lock(&qctxt->lqc_lock);
264 if (!qctxt->lqc_valid){
265 spin_unlock(&qctxt->lqc_lock);
268 spin_unlock(&qctxt->lqc_lock);
270 for (i = 0; i < MAXQUOTAS; i++) {
271 struct lustre_qunit_size *lqs = NULL;
273 qdata[i].qd_id = id[i];
274 qdata[i].qd_flags = i;
276 QDATA_SET_BLK(&qdata[i]);
277 qdata[i].qd_count = 0;
279 /* ignore root user */
280 if (qdata[i].qd_id == 0 && !QDATA_IS_GRP(&qdata[i]))
283 lqs = quota_search_lqs(LQS_KEY(i, id[i]), qctxt, 0);
284 if (lqs == NULL || IS_ERR(lqs))
287 rc2[i] = compute_remquota(obd, qctxt, &qdata[i], isblk);
288 spin_lock(&lqs->lqs_lock);
291 pending[i] = count * CFS_PAGE_SIZE;
292 /* in order to complete this write, we need extra
293 * meta blocks. This function can get it through
294 * data needed to be written b=16542 */
296 LASSERT(inode && frags > 0);
297 if (fsfilt_get_mblk(obd, qctxt->lqc_sb, &mb,
299 CERROR("%s: can't get extra meta "
300 "blocks\n", obd->obd_name);
303 lqs->lqs_bwrite_pending += pending[i];
306 lqs->lqs_iwrite_pending += pending[i];
310 /* if xx_rec < 0, that means quota are releasing,
311 * and it may return before we use quota. So if
312 * we find this situation, we assuming it has
313 * returned b=18491 */
314 if (isblk && lqs->lqs_blk_rec < 0) {
315 if (qdata[i].qd_count < -lqs->lqs_blk_rec)
316 qdata[i].qd_count = 0;
318 qdata[i].qd_count += lqs->lqs_blk_rec;
320 if (!isblk && lqs->lqs_ino_rec < 0) {
321 if (qdata[i].qd_count < -lqs->lqs_ino_rec)
322 qdata[i].qd_count = 0;
324 qdata[i].qd_count += lqs->lqs_ino_rec;
327 CDEBUG(D_QUOTA, "count=%d lqs_pending=%lu qd_count="LPU64
328 " isblk=%d mb=%d pending[%d]=%d\n", count,
329 isblk ? lqs->lqs_bwrite_pending : lqs->lqs_iwrite_pending,
330 qdata[i].qd_count, isblk, mb, i, pending[i]);
331 if (rc2[i] == QUOTA_RET_OK) {
332 if (isblk && qdata[i].qd_count < lqs->lqs_bwrite_pending)
333 rc2[i] = QUOTA_RET_ACQUOTA;
334 if (!isblk && qdata[i].qd_count <
335 lqs->lqs_iwrite_pending)
336 rc2[i] = QUOTA_RET_ACQUOTA;
339 spin_unlock(&lqs->lqs_lock);
341 if (lqs->lqs_blk_rec < 0 &&
343 lqs->lqs_bwrite_pending - lqs->lqs_blk_rec - mb)
344 OBD_FAIL_TIMEOUT(OBD_FAIL_QUOTA_DELAY_REL, 5);
346 /* When cycle is zero, lqs_*_pending will be changed. We will
347 * get reference of the lqs here and put reference of lqs in
348 * quota_pending_commit b=14784 */
352 /* this is for quota_search_lqs */
356 if (rc2[0] == QUOTA_RET_ACQUOTA || rc2[1] == QUOTA_RET_ACQUOTA)
357 RETURN(QUOTA_RET_ACQUOTA);
362 static int quota_chk_acq_common(struct obd_export *exp, unsigned int uid,
363 unsigned int gid, int count, int pending[2],
364 int isblk, quota_acquire acquire,
365 struct obd_trans_info *oti, struct inode *inode,
368 struct obd_device *obd = exp->exp_obd;
369 struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt;
370 struct timeval work_start;
371 struct timeval work_end;
373 struct l_wait_info lwi = { 0 };
374 int rc = 0, cycle = 0, count_err = 1;
377 CDEBUG(D_QUOTA, "check quota for %s\n", obd->obd_name);
378 if (isblk && (exp->exp_failed || exp->exp_abort_active_req))
379 /* If the client has been evicted or if it
380 * timed out and tried to reconnect already,
381 * abort the request immediately */
384 /* Unfortunately, if quota master is too busy to handle the
385 * pre-dqacq in time and quota hash on ost is used up, we
386 * have to wait for the completion of in flight dqacq/dqrel,
387 * in order to get enough quota for write b=12588 */
388 do_gettimeofday(&work_start);
389 while ((rc = quota_check_common(obd, uid, gid, count, cycle, isblk,
390 inode, frags, pending)) & QUOTA_RET_ACQUOTA) {
392 spin_lock(&qctxt->lqc_lock);
393 if (!qctxt->lqc_import && oti) {
394 spin_unlock(&qctxt->lqc_lock);
396 LASSERT(oti && oti->oti_thread &&
397 oti->oti_thread->t_watchdog);
399 lc_watchdog_disable(oti->oti_thread->t_watchdog);
400 CDEBUG(D_QUOTA, "sleep for quota master\n");
401 l_wait_event(qctxt->lqc_wait_for_qmaster, check_qm(qctxt),
403 CDEBUG(D_QUOTA, "wake up when quota master is back\n");
404 lc_watchdog_touch(oti->oti_thread->t_watchdog,
405 GET_TIMEOUT(oti->oti_thread->t_svc));
407 spin_unlock(&qctxt->lqc_lock);
412 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_HOLD_WRITE_RPC, 90);
413 /* after acquire(), we should run quota_check_common again
414 * so that we confirm there are enough quota to finish write */
415 rc = acquire(obd, uid, gid, oti);
417 /* please reference to dqacq_completion for the below */
418 /* a new request is finished, try again */
419 if (rc == QUOTA_REQ_RETURNED) {
420 CDEBUG(D_QUOTA, "finish a quota req, try again\n");
424 /* it is out of quota already */
426 CDEBUG(D_QUOTA, "out of quota, return -EDQUOT\n");
430 if (isblk && (exp->exp_failed || exp->exp_abort_active_req))
431 /* The client has been evicted or tried to
432 * to reconnect already, abort the request */
435 /* -EBUSY and others, wait a second and try again */
438 struct l_wait_info lwi;
440 if (oti && oti->oti_thread && oti->oti_thread->t_watchdog)
441 lc_watchdog_touch(oti->oti_thread->t_watchdog,
442 GET_TIMEOUT(oti->oti_thread->t_svc));
443 CDEBUG(D_QUOTA, "rc: %d, count_err: %d\n", rc,
446 init_waitqueue_head(&waitq);
447 lwi = LWI_TIMEOUT(cfs_time_seconds(min(cycle, 10)), NULL,
449 l_wait_event(waitq, 0, &lwi);
452 if (rc < 0 || cycle % 10 == 0) {
453 spin_lock(&last_print_lock);
454 if (last_print == 0 ||
455 cfs_time_before((last_print + cfs_time_seconds(30)),
456 cfs_time_current())) {
457 CWARN("still haven't managed to acquire quota "
458 "space from the quota master after %d "
459 "retries (err=%d, rc=%d)\n",
460 cycle, count_err - 1, rc);
461 last_print = cfs_time_current();
463 spin_unlock(&last_print_lock);
466 CDEBUG(D_QUOTA, "recheck quota with rc: %d, cycle: %d\n", rc,
470 do_gettimeofday(&work_end);
471 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
472 lprocfs_counter_add(qctxt->lqc_stats,
473 isblk ? LQUOTA_WAIT_FOR_CHK_BLK :
474 LQUOTA_WAIT_FOR_CHK_INO,
482 int quota_is_set(struct obd_device *obd, unsigned int uid,
483 unsigned int gid, int flag)
485 struct lustre_qunit_size *lqs;
486 __u32 id[MAXQUOTAS] = { uid, gid };
489 if (!ll_sb_any_quota_active(obd->u.obt.obt_qctxt.lqc_sb))
492 for (i = 0; i < MAXQUOTAS; i++) {
493 lqs = quota_search_lqs(LQS_KEY(i, id[i]),
494 &obd->u.obt.obt_qctxt, 0);
495 if (lqs && !IS_ERR(lqs)) {
496 if (lqs->lqs_flags & flag)
505 static int filter_quota_check(struct obd_export *exp, unsigned int uid,
506 unsigned int gid, int npage, int pending[2],
507 quota_acquire acquire, struct obd_trans_info *oti,
508 struct inode *inode, int frags)
510 return quota_is_set(exp->exp_obd, uid, gid, QB_SET) ?
511 quota_chk_acq_common(exp, uid, gid, npage, pending,
512 LQUOTA_FLAGS_BLK, acquire, oti, inode,
516 /* when a block_write or inode_create rpc is finished, adjust the record for
517 * pending blocks and inodes*/
518 static int quota_pending_commit(struct obd_device *obd, unsigned int uid,
519 unsigned int gid, int pending[2], int isblk)
521 struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt;
522 struct timeval work_start;
523 struct timeval work_end;
526 __u32 id[MAXQUOTAS] = { uid, gid };
527 struct qunit_data qdata[MAXQUOTAS];
530 CDEBUG(D_QUOTA, "%s: commit pending quota\n", obd->obd_name);
531 CLASSERT(MAXQUOTAS < 4);
533 do_gettimeofday(&work_start);
534 for (i = 0; i < MAXQUOTAS; i++) {
535 struct lustre_qunit_size *lqs = NULL;
538 qdata[i].qd_id = id[i];
539 qdata[i].qd_flags = i;
541 QDATA_SET_BLK(&qdata[i]);
542 qdata[i].qd_count = 0;
544 if (qdata[i].qd_id == 0 && !QDATA_IS_GRP(&qdata[i]))
547 lqs = quota_search_lqs(LQS_KEY(i, qdata[i].qd_id), qctxt, 0);
548 if (lqs == NULL || IS_ERR(lqs))
551 spin_lock(&lqs->lqs_lock);
553 if (lqs->lqs_bwrite_pending >= pending[i]) {
554 lqs->lqs_bwrite_pending -= pending[i];
557 CERROR("%s: there are too many blocks!\n",
561 if (lqs->lqs_iwrite_pending >= pending[i]) {
562 lqs->lqs_iwrite_pending -= pending[i];
565 CERROR("%s: there are too many files!\n",
569 CDEBUG(D_QUOTA, "%s: lqs_pending=%lu pending[%d]=%d isblk=%d\n",
571 isblk ? lqs->lqs_bwrite_pending : lqs->lqs_iwrite_pending,
572 i, pending[i], isblk);
574 spin_unlock(&lqs->lqs_lock);
576 /* When lqs_*_pening is changed back, we'll putref lqs
581 do_gettimeofday(&work_end);
582 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
583 lprocfs_counter_add(qctxt->lqc_stats,
584 isblk ? LQUOTA_WAIT_FOR_COMMIT_BLK :
585 LQUOTA_WAIT_FOR_COMMIT_INO,
591 static int filter_quota_pending_commit(struct obd_device *obd, unsigned int uid,
592 unsigned int gid, int pending[2])
594 return quota_pending_commit(obd, uid, gid, pending, LQUOTA_FLAGS_BLK);
597 static int mds_quota_init(void)
599 return lustre_dquot_init();
602 static int mds_quota_exit(void)
608 static int mds_quota_setup(struct obd_device *obd)
610 struct obd_device_target *obt = &obd->u.obt;
611 struct mds_obd *mds = &obd->u.mds;
616 obt->obt_qfmt = LUSTRE_QUOTA_V2;
618 obt->obt_qfmt = LUSTRE_QUOTA_V1;
620 mds->mds_quota_info.qi_version = LUSTRE_QUOTA_V2;
621 atomic_set(&obt->obt_quotachecking, 1);
622 /* initialize quota master and quota context */
623 sema_init(&mds->mds_qonoff_sem, 1);
624 rc = qctxt_init(obd, dqacq_handler);
626 CERROR("%s: initialize quota context failed! (rc:%d)\n",
633 static int mds_quota_cleanup(struct obd_device *obd)
635 qctxt_cleanup(&obd->u.obt.obt_qctxt, 0);
639 static int mds_quota_fs_cleanup(struct obd_device *obd)
641 struct mds_obd *mds = &obd->u.mds;
642 struct obd_quotactl oqctl;
645 memset(&oqctl, 0, sizeof(oqctl));
646 oqctl.qc_type = UGQUOTA;
648 down(&mds->mds_qonoff_sem);
649 mds_admin_quota_off(obd, &oqctl);
650 up(&mds->mds_qonoff_sem);
654 static int mds_quota_check(struct obd_export *exp, unsigned int uid,
655 unsigned int gid, int inodes, int pending[2],
656 quota_acquire acquire, struct obd_trans_info *oti,
657 struct inode *inode, int frags)
659 return quota_is_set(exp->exp_obd, uid, gid, QI_SET) ?
660 quota_chk_acq_common(exp, uid, gid, inodes, pending, 0,
661 acquire, oti, inode, frags) : 0;
664 static int mds_quota_acquire(struct obd_device *obd, unsigned int uid,
665 unsigned int gid, struct obd_trans_info *oti)
667 struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt;
671 rc = qctxt_adjust_qunit(obd, qctxt, uid, gid, 0, 1, oti);
675 static int mds_quota_pending_commit(struct obd_device *obd, unsigned int uid,
676 unsigned int gid, int pending[2])
678 return quota_pending_commit(obd, uid, gid, pending, 0);
680 #endif /* HAVE_QUOTA_SUPPORT */
681 #endif /* __KERNEL__ */
683 struct osc_quota_info {
684 struct list_head oqi_hash; /* hash list */
685 struct client_obd *oqi_cli; /* osc obd */
686 unsigned int oqi_id; /* uid/gid of a file */
687 short oqi_type; /* quota type */
690 spinlock_t qinfo_list_lock = SPIN_LOCK_UNLOCKED;
692 static struct list_head qinfo_hash[NR_DQHASH];
693 /* SLAB cache for client quota context */
694 cfs_mem_cache_t *qinfo_cachep = NULL;
696 static inline int hashfn(struct client_obd *cli, unsigned long id, int type)
697 __attribute__((__const__));
699 static inline int hashfn(struct client_obd *cli, unsigned long id, int type)
701 unsigned long tmp = ((unsigned long)cli>>6) ^ id;
702 tmp = (tmp * (MAXQUOTAS - type)) % NR_DQHASH;
706 /* caller must hold qinfo_list_lock */
707 static inline void insert_qinfo_hash(struct osc_quota_info *oqi)
709 struct list_head *head = qinfo_hash +
710 hashfn(oqi->oqi_cli, oqi->oqi_id, oqi->oqi_type);
712 LASSERT_SPIN_LOCKED(&qinfo_list_lock);
713 list_add(&oqi->oqi_hash, head);
716 /* caller must hold qinfo_list_lock */
717 static inline void remove_qinfo_hash(struct osc_quota_info *oqi)
719 LASSERT_SPIN_LOCKED(&qinfo_list_lock);
720 list_del_init(&oqi->oqi_hash);
723 /* caller must hold qinfo_list_lock */
724 static inline struct osc_quota_info *find_qinfo(struct client_obd *cli,
725 unsigned int id, int type)
727 unsigned int hashent = hashfn(cli, id, type);
728 struct osc_quota_info *oqi;
730 LASSERT_SPIN_LOCKED(&qinfo_list_lock);
731 list_for_each_entry(oqi, &qinfo_hash[hashent], oqi_hash) {
732 if (oqi->oqi_cli == cli &&
733 oqi->oqi_id == id && oqi->oqi_type == type)
739 static struct osc_quota_info *alloc_qinfo(struct client_obd *cli,
740 unsigned int id, int type)
742 struct osc_quota_info *oqi;
745 OBD_SLAB_ALLOC(oqi, qinfo_cachep, CFS_ALLOC_STD, sizeof(*oqi));
749 CFS_INIT_LIST_HEAD(&oqi->oqi_hash);
752 oqi->oqi_type = type;
757 static void free_qinfo(struct osc_quota_info *oqi)
759 OBD_SLAB_FREE(oqi, qinfo_cachep, sizeof(*oqi));
762 int osc_quota_chkdq(struct client_obd *cli, unsigned int uid, unsigned int gid)
765 int cnt, rc = QUOTA_OK;
768 spin_lock(&qinfo_list_lock);
769 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
770 struct osc_quota_info *oqi = NULL;
772 id = (cnt == USRQUOTA) ? uid : gid;
773 oqi = find_qinfo(cli, id, cnt);
779 spin_unlock(&qinfo_list_lock);
784 int osc_quota_setdq(struct client_obd *cli, unsigned int uid, unsigned int gid,
785 obd_flag valid, obd_flag flags)
793 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
794 struct osc_quota_info *oqi, *old;
796 if (!(valid & ((cnt == USRQUOTA) ?
797 OBD_MD_FLUSRQUOTA : OBD_MD_FLGRPQUOTA)))
800 id = (cnt == USRQUOTA) ? uid : gid;
801 noquota = (cnt == USRQUOTA) ?
802 (flags & OBD_FL_NO_USRQUOTA) : (flags & OBD_FL_NO_GRPQUOTA);
804 oqi = alloc_qinfo(cli, id, cnt);
810 spin_lock(&qinfo_list_lock);
811 old = find_qinfo(cli, id, cnt);
813 remove_qinfo_hash(old);
814 else if (!old && noquota)
815 insert_qinfo_hash(oqi);
816 spin_unlock(&qinfo_list_lock);
827 int osc_quota_cleanup(struct obd_device *obd)
829 struct client_obd *cli = &obd->u.cli;
830 struct osc_quota_info *oqi, *n;
834 spin_lock(&qinfo_list_lock);
835 for (i = 0; i < NR_DQHASH; i++) {
836 list_for_each_entry_safe(oqi, n, &qinfo_hash[i], oqi_hash) {
837 if (oqi->oqi_cli != cli)
839 remove_qinfo_hash(oqi);
843 spin_unlock(&qinfo_list_lock);
848 int osc_quota_init(void)
853 LASSERT(qinfo_cachep == NULL);
854 qinfo_cachep = cfs_mem_cache_create("osc_quota_info",
855 sizeof(struct osc_quota_info),
860 for (i = 0; i < NR_DQHASH; i++)
861 CFS_INIT_LIST_HEAD(qinfo_hash + i);
866 int osc_quota_exit(void)
868 struct osc_quota_info *oqi, *n;
872 spin_lock(&qinfo_list_lock);
873 for (i = 0; i < NR_DQHASH; i++) {
874 list_for_each_entry_safe(oqi, n, &qinfo_hash[i], oqi_hash) {
875 remove_qinfo_hash(oqi);
879 spin_unlock(&qinfo_list_lock);
881 rc = cfs_mem_cache_destroy(qinfo_cachep);
882 LASSERTF(rc == 0, "couldn't destory qinfo_cachep slab\n");
889 #ifdef HAVE_QUOTA_SUPPORT
890 quota_interface_t mds_quota_interface = {
891 .quota_init = mds_quota_init,
892 .quota_exit = mds_quota_exit,
893 .quota_setup = mds_quota_setup,
894 .quota_cleanup = mds_quota_cleanup,
895 .quota_check = target_quota_check,
896 .quota_ctl = mds_quota_ctl,
897 .quota_fs_cleanup =mds_quota_fs_cleanup,
898 .quota_recovery = mds_quota_recovery,
899 .quota_adjust = mds_quota_adjust,
900 .quota_chkquota = mds_quota_check,
901 .quota_enforce = target_quota_enforce,
902 .quota_acquire = mds_quota_acquire,
903 .quota_pending_commit = mds_quota_pending_commit,
906 quota_interface_t filter_quota_interface = {
907 .quota_setup = filter_quota_setup,
908 .quota_cleanup = filter_quota_cleanup,
909 .quota_check = target_quota_check,
910 .quota_ctl = filter_quota_ctl,
911 .quota_setinfo = filter_quota_setinfo,
912 .quota_clearinfo = filter_quota_clearinfo,
913 .quota_enforce = target_quota_enforce,
914 .quota_getflag = filter_quota_getflag,
915 .quota_acquire = filter_quota_acquire,
916 .quota_adjust = filter_quota_adjust,
917 .quota_chkquota = filter_quota_check,
918 .quota_adjust_qunit = filter_quota_adjust_qunit,
919 .quota_pending_commit = filter_quota_pending_commit,
922 #endif /* __KERNEL__ */
924 quota_interface_t mdc_quota_interface = {
925 .quota_ctl = client_quota_ctl,
926 .quota_check = client_quota_check,
927 .quota_poll_check = client_quota_poll_check,
930 quota_interface_t osc_quota_interface = {
931 .quota_ctl = client_quota_ctl,
932 .quota_check = client_quota_check,
933 .quota_poll_check = client_quota_poll_check,
934 .quota_init = osc_quota_init,
935 .quota_exit = osc_quota_exit,
936 .quota_chkdq = osc_quota_chkdq,
937 .quota_setdq = osc_quota_setdq,
938 .quota_cleanup = osc_quota_cleanup,
939 .quota_adjust_qunit = client_quota_adjust_qunit,
942 quota_interface_t lov_quota_interface = {
943 .quota_check = lov_quota_check,
944 .quota_ctl = lov_quota_ctl,
945 .quota_adjust_qunit = lov_quota_adjust_qunit,
950 cfs_proc_dir_entry_t *lquota_type_proc_dir = NULL;
952 static int __init init_lustre_quota(void)
954 #ifdef HAVE_QUOTA_SUPPORT
957 lquota_type_proc_dir = lprocfs_register(OBD_LQUOTA_DEVICENAME,
960 if (IS_ERR(lquota_type_proc_dir)) {
961 CERROR("LProcFS failed in lquota-init\n");
962 rc = PTR_ERR(lquota_type_proc_dir);
966 rc = qunit_cache_init();
970 PORTAL_SYMBOL_REGISTER(filter_quota_interface);
971 PORTAL_SYMBOL_REGISTER(mds_quota_interface);
973 PORTAL_SYMBOL_REGISTER(mdc_quota_interface);
974 PORTAL_SYMBOL_REGISTER(osc_quota_interface);
975 PORTAL_SYMBOL_REGISTER(lov_quota_interface);
979 static void /*__exit*/ exit_lustre_quota(void)
981 PORTAL_SYMBOL_UNREGISTER(mdc_quota_interface);
982 PORTAL_SYMBOL_UNREGISTER(osc_quota_interface);
983 PORTAL_SYMBOL_UNREGISTER(lov_quota_interface);
984 #ifdef HAVE_QUOTA_SUPPORT
985 PORTAL_SYMBOL_UNREGISTER(filter_quota_interface);
986 PORTAL_SYMBOL_UNREGISTER(mds_quota_interface);
988 qunit_cache_cleanup();
990 if (lquota_type_proc_dir)
991 lprocfs_remove(&lquota_type_proc_dir);
995 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
996 MODULE_DESCRIPTION("Lustre Quota");
997 MODULE_LICENSE("GPL");
999 cfs_module(lquota, "1.0.0", init_lustre_quota, exit_lustre_quota);
1001 #ifdef HAVE_QUOTA_SUPPORT
1002 EXPORT_SYMBOL(mds_quota_interface);
1003 EXPORT_SYMBOL(filter_quota_interface);
1005 EXPORT_SYMBOL(mdc_quota_interface);
1006 EXPORT_SYMBOL(osc_quota_interface);
1007 EXPORT_SYMBOL(lov_quota_interface);
1008 #endif /* __KERNEL */