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/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 filter_quota_enforce(struct obd_device *obd, unsigned int ignore)
152 if (!ll_sb_any_quota_active(obd->u.obt.obt_sb))
156 CDEBUG(D_QUOTA, "blocks will be written with ignoring quota.\n");
157 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
159 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
165 #define GET_OA_ID(flag, oa) (flag == USRQUOTA ? oa->o_uid : oa->o_gid)
166 static int filter_quota_getflag(struct obd_device *obd, struct obdo *oa)
168 struct obd_device_target *obt = &obd->u.obt;
169 struct lustre_quota_ctxt *qctxt = &obt->obt_qctxt;
170 int err, cnt, rc = 0;
171 struct obd_quotactl *oqctl;
174 if (!ll_sb_any_quota_active(obt->obt_sb))
177 OBD_ALLOC_PTR(oqctl);
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 lustre_qunit_size *lqs = NULL;
188 lqs = quota_search_lqs(LQS_KEY(cnt, GET_OA_ID(cnt, oa)),
190 if (lqs == NULL || IS_ERR(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 CDEBUG(D_QUOTA, "set sync flag: bunit(%lu), "
199 "sync_blk(%d)\n", lqs->lqs_bunit_sz,
200 qctxt->lqc_sync_blk);
201 spin_unlock(&lqs->lqs_lock);
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;
235 static int filter_quota_acquire(struct obd_device *obd, unsigned int uid,
236 unsigned int gid, struct obd_trans_info *oti)
238 struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt;
242 rc = qctxt_adjust_qunit(obd, qctxt, uid, gid, LQUOTA_FLAGS_BLK, 1, oti);
246 /* check whether the left quota of certain uid and gid can satisfy a block_write
247 * or inode_create rpc. When need to acquire quota, return QUOTA_RET_ACQUOTA */
248 static int quota_check_common(struct obd_device *obd, unsigned int uid,
249 unsigned int gid, int count, int cycle, int isblk,
250 struct inode *inode, int frags, int pending[2])
252 struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt;
254 __u32 id[MAXQUOTAS] = { uid, gid };
255 struct qunit_data qdata[MAXQUOTAS];
257 int rc = 0, rc2[2] = { 0, 0 };
260 spin_lock(&qctxt->lqc_lock);
261 if (!qctxt->lqc_valid){
262 spin_unlock(&qctxt->lqc_lock);
265 spin_unlock(&qctxt->lqc_lock);
267 for (i = 0; i < MAXQUOTAS; i++) {
268 struct lustre_qunit_size *lqs = NULL;
270 qdata[i].qd_id = id[i];
271 qdata[i].qd_flags = i;
273 QDATA_SET_BLK(&qdata[i]);
274 qdata[i].qd_count = 0;
276 /* ignore root user */
277 if (qdata[i].qd_id == 0 && !QDATA_IS_GRP(&qdata[i]))
280 lqs = quota_search_lqs(LQS_KEY(i, id[i]), qctxt, 0);
281 if (lqs == NULL || IS_ERR(lqs))
284 rc2[i] = compute_remquota(obd, qctxt, &qdata[i], isblk);
285 spin_lock(&lqs->lqs_lock);
288 pending[i] = count * CFS_PAGE_SIZE;
289 /* in order to complete this write, we need extra
290 * meta blocks. This function can get it through
291 * data needed to be written b=16542 */
293 LASSERT(inode && frags > 0);
294 if (fsfilt_get_mblk(obd, qctxt->lqc_sb, &mb,
296 CERROR("%s: can't get extra meta "
297 "blocks\n", obd->obd_name);
300 lqs->lqs_bwrite_pending += pending[i];
303 lqs->lqs_iwrite_pending += pending[i];
307 /* if xx_rec < 0, that means quota are releasing,
308 * and it may return before we use quota. So if
309 * we find this situation, we assuming it has
310 * returned b=18491 */
311 if (isblk && lqs->lqs_blk_rec < 0) {
312 if (qdata[i].qd_count < -lqs->lqs_blk_rec)
313 qdata[i].qd_count = 0;
315 qdata[i].qd_count += lqs->lqs_blk_rec;
317 if (!isblk && lqs->lqs_ino_rec < 0) {
318 if (qdata[i].qd_count < -lqs->lqs_ino_rec)
319 qdata[i].qd_count = 0;
321 qdata[i].qd_count += lqs->lqs_ino_rec;
324 CDEBUG(D_QUOTA, "count=%d lqs_pending=%lu qd_count="LPU64
325 " isblk=%d mb=%d pending[%d]=%d\n", count,
326 isblk ? lqs->lqs_bwrite_pending : lqs->lqs_iwrite_pending,
327 qdata[i].qd_count, isblk, mb, i, pending[i]);
328 if (rc2[i] == QUOTA_RET_OK) {
329 if (isblk && qdata[i].qd_count < lqs->lqs_bwrite_pending)
330 rc2[i] = QUOTA_RET_ACQUOTA;
331 if (!isblk && qdata[i].qd_count <
332 lqs->lqs_iwrite_pending)
333 rc2[i] = QUOTA_RET_ACQUOTA;
336 spin_unlock(&lqs->lqs_lock);
338 if (lqs->lqs_blk_rec < 0 &&
340 lqs->lqs_bwrite_pending - lqs->lqs_blk_rec - mb)
341 OBD_FAIL_TIMEOUT(OBD_FAIL_QUOTA_DELAY_REL, 5);
343 /* When cycle is zero, lqs_*_pending will be changed. We will
344 * get reference of the lqs here and put reference of lqs in
345 * quota_pending_commit b=14784 */
349 /* this is for quota_search_lqs */
353 if (rc2[0] == QUOTA_RET_ACQUOTA || rc2[1] == QUOTA_RET_ACQUOTA)
354 RETURN(QUOTA_RET_ACQUOTA);
359 static int quota_chk_acq_common(struct obd_export *exp, unsigned int uid,
360 unsigned int gid, int count, int pending[2],
361 int isblk, quota_acquire acquire,
362 struct obd_trans_info *oti, struct inode *inode,
365 struct obd_device *obd = exp->exp_obd;
366 struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt;
367 struct timeval work_start;
368 struct timeval work_end;
370 struct l_wait_info lwi = { 0 };
371 int rc = 0, cycle = 0, count_err = 1;
374 CDEBUG(D_QUOTA, "check quota for %s\n", obd->obd_name);
375 if (isblk && (exp->exp_failed || exp->exp_abort_active_req))
376 /* If the client has been evicted or if it
377 * timed out and tried to reconnect already,
378 * abort the request immediately */
381 /* Unfortunately, if quota master is too busy to handle the
382 * pre-dqacq in time and quota hash on ost is used up, we
383 * have to wait for the completion of in flight dqacq/dqrel,
384 * in order to get enough quota for write b=12588 */
385 do_gettimeofday(&work_start);
386 while ((rc = quota_check_common(obd, uid, gid, count, cycle, isblk,
387 inode, frags, pending)) & QUOTA_RET_ACQUOTA) {
389 spin_lock(&qctxt->lqc_lock);
390 if (!qctxt->lqc_import && oti) {
391 spin_unlock(&qctxt->lqc_lock);
393 LASSERT(oti && oti->oti_thread &&
394 oti->oti_thread->t_watchdog);
396 lc_watchdog_disable(oti->oti_thread->t_watchdog);
397 CDEBUG(D_QUOTA, "sleep for quota master\n");
398 l_wait_event(qctxt->lqc_wait_for_qmaster, check_qm(qctxt),
400 CDEBUG(D_QUOTA, "wake up when quota master is back\n");
401 lc_watchdog_touch(oti->oti_thread->t_watchdog,
402 GET_TIMEOUT(oti->oti_thread->t_svc));
404 spin_unlock(&qctxt->lqc_lock);
409 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_HOLD_WRITE_RPC, 90);
410 /* after acquire(), we should run quota_check_common again
411 * so that we confirm there are enough quota to finish write */
412 rc = acquire(obd, uid, gid, oti);
414 /* please reference to dqacq_completion for the below */
415 /* a new request is finished, try again */
416 if (rc == QUOTA_REQ_RETURNED) {
417 CDEBUG(D_QUOTA, "finish a quota req, try again\n");
421 /* it is out of quota already */
423 CDEBUG(D_QUOTA, "out of quota, return -EDQUOT\n");
427 if (isblk && (exp->exp_failed || exp->exp_abort_active_req))
428 /* The client has been evicted or tried to
429 * to reconnect already, abort the request */
432 /* -EBUSY and others, wait a second and try again */
435 struct l_wait_info lwi;
437 if (oti && oti->oti_thread && oti->oti_thread->t_watchdog)
438 lc_watchdog_touch(oti->oti_thread->t_watchdog,
439 GET_TIMEOUT(oti->oti_thread->t_svc));
440 CDEBUG(D_QUOTA, "rc: %d, count_err: %d\n", rc,
443 init_waitqueue_head(&waitq);
444 lwi = LWI_TIMEOUT(cfs_time_seconds(min(cycle, 10)), NULL,
446 l_wait_event(waitq, 0, &lwi);
449 if (rc < 0 || cycle % 10 == 0) {
450 spin_lock(&last_print_lock);
451 if (last_print == 0 ||
452 cfs_time_before((last_print + cfs_time_seconds(30)),
453 cfs_time_current())) {
454 CWARN("still haven't managed to acquire quota "
455 "space from the quota master after %d "
456 "retries (err=%d, rc=%d)\n",
457 cycle, count_err - 1, rc);
458 last_print = cfs_time_current();
460 spin_unlock(&last_print_lock);
463 CDEBUG(D_QUOTA, "recheck quota with rc: %d, cycle: %d\n", rc,
467 do_gettimeofday(&work_end);
468 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
469 lprocfs_counter_add(qctxt->lqc_stats,
470 isblk ? LQUOTA_WAIT_FOR_CHK_BLK :
471 LQUOTA_WAIT_FOR_CHK_INO,
479 int quota_is_set(struct obd_device *obd, unsigned int uid,
480 unsigned int gid, int flag)
482 struct lustre_qunit_size *lqs;
483 __u32 id[MAXQUOTAS] = { uid, gid };
486 if (!ll_sb_any_quota_active(obd->u.obt.obt_qctxt.lqc_sb))
489 for (i = 0; i < MAXQUOTAS; i++) {
490 lqs = quota_search_lqs(LQS_KEY(i, id[i]),
491 &obd->u.obt.obt_qctxt, 0);
492 if (lqs && !IS_ERR(lqs)) {
493 if (lqs->lqs_flags & flag)
502 static int filter_quota_check(struct obd_export *exp, unsigned int uid,
503 unsigned int gid, int npage, int pending[2],
504 quota_acquire acquire, struct obd_trans_info *oti,
505 struct inode *inode, int frags)
507 return quota_is_set(exp->exp_obd, uid, gid, QB_SET) ?
508 quota_chk_acq_common(exp, uid, gid, npage, pending,
509 LQUOTA_FLAGS_BLK, acquire, oti, inode,
513 /* when a block_write or inode_create rpc is finished, adjust the record for
514 * pending blocks and inodes*/
515 static int quota_pending_commit(struct obd_device *obd, unsigned int uid,
516 unsigned int gid, int pending[2], int isblk)
518 struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt;
519 struct timeval work_start;
520 struct timeval work_end;
523 __u32 id[MAXQUOTAS] = { uid, gid };
524 struct qunit_data qdata[MAXQUOTAS];
527 CDEBUG(D_QUOTA, "%s: commit pending quota\n", obd->obd_name);
528 CLASSERT(MAXQUOTAS < 4);
530 do_gettimeofday(&work_start);
531 for (i = 0; i < MAXQUOTAS; i++) {
532 struct lustre_qunit_size *lqs = NULL;
535 qdata[i].qd_id = id[i];
536 qdata[i].qd_flags = i;
538 QDATA_SET_BLK(&qdata[i]);
539 qdata[i].qd_count = 0;
541 if (qdata[i].qd_id == 0 && !QDATA_IS_GRP(&qdata[i]))
544 lqs = quota_search_lqs(LQS_KEY(i, qdata[i].qd_id), qctxt, 0);
545 if (lqs == NULL || IS_ERR(lqs))
548 spin_lock(&lqs->lqs_lock);
550 if (lqs->lqs_bwrite_pending >= pending[i]) {
551 lqs->lqs_bwrite_pending -= pending[i];
554 CERROR("%s: there are too many blocks!\n",
558 if (lqs->lqs_iwrite_pending >= pending[i]) {
559 lqs->lqs_iwrite_pending -= pending[i];
562 CERROR("%s: there are too many files!\n",
566 CDEBUG(D_QUOTA, "%s: lqs_pending=%lu pending[%d]=%d isblk=%d\n",
568 isblk ? lqs->lqs_bwrite_pending : lqs->lqs_iwrite_pending,
569 i, pending[i], isblk);
571 spin_unlock(&lqs->lqs_lock);
573 /* When lqs_*_pening is changed back, we'll putref lqs
578 do_gettimeofday(&work_end);
579 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
580 lprocfs_counter_add(qctxt->lqc_stats,
581 isblk ? LQUOTA_WAIT_FOR_COMMIT_BLK :
582 LQUOTA_WAIT_FOR_COMMIT_INO,
588 static int filter_quota_pending_commit(struct obd_device *obd, unsigned int uid,
589 unsigned int gid, int pending[2])
591 return quota_pending_commit(obd, uid, gid, pending, LQUOTA_FLAGS_BLK);
594 static int mds_quota_init(void)
596 return lustre_dquot_init();
599 static int mds_quota_exit(void)
605 static int mds_quota_setup(struct obd_device *obd)
607 struct obd_device_target *obt = &obd->u.obt;
608 struct mds_obd *mds = &obd->u.mds;
613 obt->obt_qfmt = LUSTRE_QUOTA_V2;
615 obt->obt_qfmt = LUSTRE_QUOTA_V1;
617 mds->mds_quota_info.qi_version = LUSTRE_QUOTA_V2;
618 atomic_set(&obt->obt_quotachecking, 1);
619 /* initialize quota master and quota context */
620 sema_init(&mds->mds_qonoff_sem, 1);
621 rc = qctxt_init(obd, dqacq_handler);
623 CERROR("%s: initialize quota context failed! (rc:%d)\n",
630 static int mds_quota_cleanup(struct obd_device *obd)
632 qctxt_cleanup(&obd->u.obt.obt_qctxt, 0);
636 static int mds_quota_fs_cleanup(struct obd_device *obd)
638 struct mds_obd *mds = &obd->u.mds;
639 struct obd_quotactl oqctl;
642 memset(&oqctl, 0, sizeof(oqctl));
643 oqctl.qc_type = UGQUOTA;
645 down(&mds->mds_qonoff_sem);
646 mds_admin_quota_off(obd, &oqctl);
647 up(&mds->mds_qonoff_sem);
651 static int mds_quota_check(struct obd_export *exp, unsigned int uid,
652 unsigned int gid, int inodes, int pending[2],
653 quota_acquire acquire, struct obd_trans_info *oti,
654 struct inode *inode, int frags)
656 return quota_is_set(exp->exp_obd, uid, gid, QI_SET) ?
657 quota_chk_acq_common(exp, uid, gid, inodes, pending, 0,
658 acquire, oti, inode, frags) : 0;
661 static int mds_quota_acquire(struct obd_device *obd, unsigned int uid,
662 unsigned int gid, struct obd_trans_info *oti)
664 struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt;
668 rc = qctxt_adjust_qunit(obd, qctxt, uid, gid, 0, 1, oti);
672 static int mds_quota_pending_commit(struct obd_device *obd, unsigned int uid,
673 unsigned int gid, int pending[2])
675 return quota_pending_commit(obd, uid, gid, pending, 0);
677 #endif /* HAVE_QUOTA_SUPPORT */
678 #endif /* __KERNEL__ */
680 struct osc_quota_info {
681 struct list_head oqi_hash; /* hash list */
682 struct client_obd *oqi_cli; /* osc obd */
683 unsigned int oqi_id; /* uid/gid of a file */
684 short oqi_type; /* quota type */
687 spinlock_t qinfo_list_lock = SPIN_LOCK_UNLOCKED;
689 static struct list_head qinfo_hash[NR_DQHASH];
690 /* SLAB cache for client quota context */
691 cfs_mem_cache_t *qinfo_cachep = NULL;
693 static inline int hashfn(struct client_obd *cli, unsigned long id, int type)
694 __attribute__((__const__));
696 static inline int hashfn(struct client_obd *cli, unsigned long id, int type)
698 unsigned long tmp = ((unsigned long)cli>>6) ^ id;
699 tmp = (tmp * (MAXQUOTAS - type)) % NR_DQHASH;
703 /* caller must hold qinfo_list_lock */
704 static inline void insert_qinfo_hash(struct osc_quota_info *oqi)
706 struct list_head *head = qinfo_hash +
707 hashfn(oqi->oqi_cli, oqi->oqi_id, oqi->oqi_type);
709 LASSERT_SPIN_LOCKED(&qinfo_list_lock);
710 list_add(&oqi->oqi_hash, head);
713 /* caller must hold qinfo_list_lock */
714 static inline void remove_qinfo_hash(struct osc_quota_info *oqi)
716 LASSERT_SPIN_LOCKED(&qinfo_list_lock);
717 list_del_init(&oqi->oqi_hash);
720 /* caller must hold qinfo_list_lock */
721 static inline struct osc_quota_info *find_qinfo(struct client_obd *cli,
722 unsigned int id, int type)
724 unsigned int hashent = hashfn(cli, id, type);
725 struct osc_quota_info *oqi;
727 LASSERT_SPIN_LOCKED(&qinfo_list_lock);
728 list_for_each_entry(oqi, &qinfo_hash[hashent], oqi_hash) {
729 if (oqi->oqi_cli == cli &&
730 oqi->oqi_id == id && oqi->oqi_type == type)
736 static struct osc_quota_info *alloc_qinfo(struct client_obd *cli,
737 unsigned int id, int type)
739 struct osc_quota_info *oqi;
742 OBD_SLAB_ALLOC(oqi, qinfo_cachep, CFS_ALLOC_STD, sizeof(*oqi));
746 CFS_INIT_LIST_HEAD(&oqi->oqi_hash);
749 oqi->oqi_type = type;
754 static void free_qinfo(struct osc_quota_info *oqi)
756 OBD_SLAB_FREE(oqi, qinfo_cachep, sizeof(*oqi));
759 int osc_quota_chkdq(struct client_obd *cli, unsigned int uid, unsigned int gid)
762 int cnt, rc = QUOTA_OK;
765 spin_lock(&qinfo_list_lock);
766 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
767 struct osc_quota_info *oqi = NULL;
769 id = (cnt == USRQUOTA) ? uid : gid;
770 oqi = find_qinfo(cli, id, cnt);
776 spin_unlock(&qinfo_list_lock);
781 int osc_quota_setdq(struct client_obd *cli, unsigned int uid, unsigned int gid,
782 obd_flag valid, obd_flag flags)
790 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
791 struct osc_quota_info *oqi, *old;
793 if (!(valid & ((cnt == USRQUOTA) ?
794 OBD_MD_FLUSRQUOTA : OBD_MD_FLGRPQUOTA)))
797 id = (cnt == USRQUOTA) ? uid : gid;
798 noquota = (cnt == USRQUOTA) ?
799 (flags & OBD_FL_NO_USRQUOTA) : (flags & OBD_FL_NO_GRPQUOTA);
801 oqi = alloc_qinfo(cli, id, cnt);
807 spin_lock(&qinfo_list_lock);
808 old = find_qinfo(cli, id, cnt);
810 remove_qinfo_hash(old);
811 else if (!old && noquota)
812 insert_qinfo_hash(oqi);
813 spin_unlock(&qinfo_list_lock);
824 int osc_quota_cleanup(struct obd_device *obd)
826 struct client_obd *cli = &obd->u.cli;
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 if (oqi->oqi_cli != cli)
836 remove_qinfo_hash(oqi);
840 spin_unlock(&qinfo_list_lock);
845 int osc_quota_init(void)
850 LASSERT(qinfo_cachep == NULL);
851 qinfo_cachep = cfs_mem_cache_create("osc_quota_info",
852 sizeof(struct osc_quota_info),
857 for (i = 0; i < NR_DQHASH; i++)
858 CFS_INIT_LIST_HEAD(qinfo_hash + i);
863 int osc_quota_exit(void)
865 struct osc_quota_info *oqi, *n;
869 spin_lock(&qinfo_list_lock);
870 for (i = 0; i < NR_DQHASH; i++) {
871 list_for_each_entry_safe(oqi, n, &qinfo_hash[i], oqi_hash) {
872 remove_qinfo_hash(oqi);
876 spin_unlock(&qinfo_list_lock);
878 rc = cfs_mem_cache_destroy(qinfo_cachep);
879 LASSERTF(rc == 0, "couldn't destory qinfo_cachep slab\n");
886 #ifdef HAVE_QUOTA_SUPPORT
887 quota_interface_t mds_quota_interface = {
888 .quota_init = mds_quota_init,
889 .quota_exit = mds_quota_exit,
890 .quota_setup = mds_quota_setup,
891 .quota_cleanup = mds_quota_cleanup,
892 .quota_check = target_quota_check,
893 .quota_ctl = mds_quota_ctl,
894 .quota_fs_cleanup =mds_quota_fs_cleanup,
895 .quota_recovery = mds_quota_recovery,
896 .quota_adjust = mds_quota_adjust,
897 .quota_chkquota = mds_quota_check,
898 .quota_acquire = mds_quota_acquire,
899 .quota_pending_commit = mds_quota_pending_commit,
902 quota_interface_t filter_quota_interface = {
903 .quota_setup = filter_quota_setup,
904 .quota_cleanup = filter_quota_cleanup,
905 .quota_check = target_quota_check,
906 .quota_ctl = filter_quota_ctl,
907 .quota_setinfo = filter_quota_setinfo,
908 .quota_clearinfo = filter_quota_clearinfo,
909 .quota_enforce = filter_quota_enforce,
910 .quota_getflag = filter_quota_getflag,
911 .quota_acquire = filter_quota_acquire,
912 .quota_adjust = filter_quota_adjust,
913 .quota_chkquota = filter_quota_check,
914 .quota_adjust_qunit = filter_quota_adjust_qunit,
915 .quota_pending_commit = filter_quota_pending_commit,
918 #endif /* __KERNEL__ */
920 quota_interface_t mdc_quota_interface = {
921 .quota_ctl = client_quota_ctl,
922 .quota_check = client_quota_check,
923 .quota_poll_check = client_quota_poll_check,
926 quota_interface_t osc_quota_interface = {
927 .quota_ctl = client_quota_ctl,
928 .quota_check = client_quota_check,
929 .quota_poll_check = client_quota_poll_check,
930 .quota_init = osc_quota_init,
931 .quota_exit = osc_quota_exit,
932 .quota_chkdq = osc_quota_chkdq,
933 .quota_setdq = osc_quota_setdq,
934 .quota_cleanup = osc_quota_cleanup,
935 .quota_adjust_qunit = client_quota_adjust_qunit,
938 quota_interface_t lov_quota_interface = {
939 .quota_check = lov_quota_check,
940 .quota_ctl = lov_quota_ctl,
941 .quota_adjust_qunit = lov_quota_adjust_qunit,
946 cfs_proc_dir_entry_t *lquota_type_proc_dir = NULL;
948 static int __init init_lustre_quota(void)
950 #ifdef HAVE_QUOTA_SUPPORT
953 lquota_type_proc_dir = lprocfs_register(OBD_LQUOTA_DEVICENAME,
956 if (IS_ERR(lquota_type_proc_dir)) {
957 CERROR("LProcFS failed in lquota-init\n");
958 rc = PTR_ERR(lquota_type_proc_dir);
962 rc = qunit_cache_init();
966 PORTAL_SYMBOL_REGISTER(filter_quota_interface);
967 PORTAL_SYMBOL_REGISTER(mds_quota_interface);
969 PORTAL_SYMBOL_REGISTER(mdc_quota_interface);
970 PORTAL_SYMBOL_REGISTER(osc_quota_interface);
971 PORTAL_SYMBOL_REGISTER(lov_quota_interface);
975 static void /*__exit*/ exit_lustre_quota(void)
977 PORTAL_SYMBOL_UNREGISTER(mdc_quota_interface);
978 PORTAL_SYMBOL_UNREGISTER(osc_quota_interface);
979 PORTAL_SYMBOL_UNREGISTER(lov_quota_interface);
980 #ifdef HAVE_QUOTA_SUPPORT
981 PORTAL_SYMBOL_UNREGISTER(filter_quota_interface);
982 PORTAL_SYMBOL_UNREGISTER(mds_quota_interface);
984 qunit_cache_cleanup();
986 if (lquota_type_proc_dir)
987 lprocfs_remove(&lquota_type_proc_dir);
991 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
992 MODULE_DESCRIPTION("Lustre Quota");
993 MODULE_LICENSE("GPL");
995 cfs_module(lquota, "1.0.0", init_lustre_quota, exit_lustre_quota);
997 #ifdef HAVE_QUOTA_SUPPORT
998 EXPORT_SYMBOL(mds_quota_interface);
999 EXPORT_SYMBOL(filter_quota_interface);
1001 EXPORT_SYMBOL(mdc_quota_interface);
1002 EXPORT_SYMBOL(osc_quota_interface);
1003 EXPORT_SYMBOL(lov_quota_interface);
1004 #endif /* __KERNEL */