Whamcloud - gitweb
This patch is to slove OSS hangs after "All ost request buffers busy"
[fs/lustre-release.git] / lustre / quota / quota_interface.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  lustre/quota/quota_interface.c
5  *
6  *  Copyright (c) 2001-2005 Cluster File Systems, Inc.
7  *
8  *   This file is part of Lustre, http://www.lustre.org.
9  *
10  *   No redistribution or use is permitted outside of Cluster File Systems, Inc.
11  *
12  */
13 #ifndef EXPORT_SYMTAB
14 # define EXPORT_SYMTAB
15 #endif
16 #define DEBUG_SUBSYSTEM S_MDS
17
18 #ifdef __KERNEL__
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 # if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
26 #  include <linux/smp_lock.h>
27 #  include <linux/buffer_head.h>
28 #  include <linux/workqueue.h>
29 #  include <linux/mount.h>
30 # else
31 #  include <linux/locks.h>
32 # endif
33 #else /* __KERNEL__ */
34 # include <liblustre.h>
35 #endif
36
37 #include <obd_class.h>
38 #include <lustre_mds.h>
39 #include <lustre_dlm.h>
40 #include <lustre_cfg.h>
41 #include <obd_ost.h>
42 #include <lustre_fsfilt.h>
43 #include <lustre_quota.h>
44 #include <lprocfs_status.h>
45 #include "quota_internal.h"
46
47
48 #ifdef __KERNEL__
49
50 /* quota proc file handling functions */
51 #ifdef LPROCFS
52 int lprocfs_rd_bunit(char *page, char **start, off_t off, int count, 
53                      int *eof, void *data)
54 {
55         struct obd_device *obd = (struct obd_device *)data;
56         LASSERT(obd != NULL);
57
58         return snprintf(page, count, "%lu\n", 
59                         obd->u.obt.obt_qctxt.lqc_bunit_sz);
60 }
61 EXPORT_SYMBOL(lprocfs_rd_bunit);
62
63 int lprocfs_rd_iunit(char *page, char **start, off_t off, int count, 
64                      int *eof, void *data)
65 {
66         struct obd_device *obd = (struct obd_device *)data;
67         LASSERT(obd != NULL);
68
69         return snprintf(page, count, "%lu\n", 
70                         obd->u.obt.obt_qctxt.lqc_iunit_sz);
71 }
72 EXPORT_SYMBOL(lprocfs_rd_iunit);
73
74 int lprocfs_wr_bunit(struct file *file, const char *buffer,
75                      unsigned long count, void *data)
76 {
77         struct obd_device *obd = (struct obd_device *)data;
78         int val, rc;
79         LASSERT(obd != NULL);
80
81         rc = lprocfs_write_helper(buffer, count, &val);
82         if (rc)
83                 return rc;
84
85         if (val % QUOTABLOCK_SIZE ||
86             val <= obd->u.obt.obt_qctxt.lqc_btune_sz)
87                 return -EINVAL;
88
89         obd->u.obt.obt_qctxt.lqc_bunit_sz = val;
90         return count;
91 }
92 EXPORT_SYMBOL(lprocfs_wr_bunit);
93
94 int lprocfs_wr_iunit(struct file *file, const char *buffer,
95                      unsigned long count, void *data)
96 {
97         struct obd_device *obd = (struct obd_device *)data;
98         int val, rc;
99         LASSERT(obd != NULL);
100
101         rc = lprocfs_write_helper(buffer, count, &val);
102         if (rc)
103                 return rc;
104
105         if (val <= obd->u.obt.obt_qctxt.lqc_itune_sz)
106                 return -EINVAL;
107
108         obd->u.obt.obt_qctxt.lqc_iunit_sz = val;
109         return count;
110 }
111 EXPORT_SYMBOL(lprocfs_wr_iunit);
112
113 int lprocfs_rd_btune(char *page, char **start, off_t off, int count, 
114                      int *eof, void *data)
115 {
116         struct obd_device *obd = (struct obd_device *)data;
117         LASSERT(obd != NULL);
118
119         return snprintf(page, count, "%lu\n", 
120                         obd->u.obt.obt_qctxt.lqc_btune_sz);
121 }
122 EXPORT_SYMBOL(lprocfs_rd_btune);
123
124 int lprocfs_rd_itune(char *page, char **start, off_t off, int count, 
125                      int *eof, void *data)
126 {
127         struct obd_device *obd = (struct obd_device *)data;
128         LASSERT(obd != NULL);
129
130         return snprintf(page, count, "%lu\n", 
131                         obd->u.obt.obt_qctxt.lqc_itune_sz);
132 }
133 EXPORT_SYMBOL(lprocfs_rd_itune);
134
135 int lprocfs_wr_btune(struct file *file, const char *buffer,
136                      unsigned long count, void *data)
137 {
138         struct obd_device *obd = (struct obd_device *)data;
139         int val, rc;
140         LASSERT(obd != NULL);
141
142         rc = lprocfs_write_helper(buffer, count, &val);
143         if (rc)
144                 return rc;
145         
146         if (val <= QUOTABLOCK_SIZE * MIN_QLIMIT || val % QUOTABLOCK_SIZE || 
147             val >= obd->u.obt.obt_qctxt.lqc_bunit_sz)
148                 return -EINVAL;
149
150         obd->u.obt.obt_qctxt.lqc_btune_sz = val;
151         return count;
152 }
153 EXPORT_SYMBOL(lprocfs_wr_btune);
154
155 int lprocfs_wr_itune(struct file *file, const char *buffer,
156                      unsigned long count, void *data)
157 {
158         struct obd_device *obd = (struct obd_device *)data;
159         int val, rc;
160         LASSERT(obd != NULL);
161
162         rc = lprocfs_write_helper(buffer, count, &val);
163         if (rc)
164                 return rc;
165         
166         if (val <= MIN_QLIMIT || 
167             val >= obd->u.obt.obt_qctxt.lqc_iunit_sz)
168                 return -EINVAL;
169
170         obd->u.obt.obt_qctxt.lqc_itune_sz = val;
171         return count;
172 }
173 EXPORT_SYMBOL(lprocfs_wr_itune);
174
175 #define USER_QUOTA      1
176 #define GROUP_QUOTA     2
177
178 #define MAX_STYPE_SIZE  4
179 int lprocfs_rd_type(char *page, char **start, off_t off, int count, 
180                     int *eof, void *data)
181 {
182         struct obd_device *obd = (struct obd_device *)data;
183         char stype[MAX_STYPE_SIZE + 1] = "";
184         int type = obd->u.obt.obt_qctxt.lqc_atype;
185         LASSERT(obd != NULL);
186
187         if (type == 0) {
188                 strcpy(stype, "off");
189         } else {
190                 if (type & USER_QUOTA)
191                         strcat(stype, "u");
192                 if (type & GROUP_QUOTA)
193                         strcat(stype, "g");
194         }
195         
196         return snprintf(page, count, "%s\n", stype);
197 }
198 EXPORT_SYMBOL(lprocfs_rd_type);
199
200 static int auto_quota_on(struct obd_device *obd, int type, 
201                          struct super_block *sb, int is_master)
202 {
203         struct obd_quotactl *oqctl;
204         struct lvfs_run_ctxt saved;
205         int rc;
206         ENTRY;
207
208         LASSERT(type == USRQUOTA || type == GRPQUOTA || type == UGQUOTA);
209
210         /* quota already turned on */
211         if (obd->u.obt.obt_qctxt.lqc_status)
212                 RETURN(0);
213
214         OBD_ALLOC_PTR(oqctl);
215         if (!oqctl)
216                 RETURN(-ENOMEM);
217
218         oqctl->qc_type = type;
219         oqctl->qc_cmd = Q_QUOTAON;
220         oqctl->qc_id = QFMT_LDISKFS;
221
222         push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
223
224         if (!is_master)
225                 goto local_quota;
226
227         /* turn on cluster wide quota */
228         rc = mds_admin_quota_on(obd, oqctl);
229         if (rc) {
230                 CDEBUG(rc == -ENOENT ? D_QUOTA : D_ERROR, 
231                        "auto-enable admin quota failed. rc=%d\n", rc);
232                 GOTO(out_pop, rc);
233         }
234 local_quota:
235         /* turn on local quota */
236         rc = fsfilt_quotactl(obd, sb, oqctl);
237         if (rc) {
238                 CDEBUG(rc == -ENOENT ? D_QUOTA : D_ERROR, 
239                        "auto-enable local quota failed. rc=%d\n", rc);
240                 if (is_master)
241                         mds_quota_off(obd, oqctl);
242         } else {
243                 obd->u.obt.obt_qctxt.lqc_status = 1;
244         }
245 out_pop:
246         pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
247
248         OBD_FREE_PTR(oqctl);
249         RETURN(rc);
250 }
251
252 int lprocfs_wr_type(struct file *file, const char *buffer,
253                     unsigned long count, void *data)
254 {
255         struct obd_device *obd = (struct obd_device *)data;
256         struct obd_device_target *obt = &obd->u.obt;
257         int type = 0;
258         char stype[MAX_STYPE_SIZE + 1] = "";
259         LASSERT(obd != NULL);
260
261         if (copy_from_user(stype, buffer, MAX_STYPE_SIZE))
262                 return -EFAULT;
263
264         if (strchr(stype, 'u'))
265                 type |= USER_QUOTA;
266         if (strchr(stype, 'g'))
267                 type |= GROUP_QUOTA;
268         
269         obt->obt_qctxt.lqc_atype = type;
270
271         if (type == 0)
272                 return count;
273
274         if (!strcmp(obd->obd_type->typ_name, LUSTRE_MDS_NAME))
275                 auto_quota_on(obd, type - 1, obt->obt_sb, 1);
276         else if (!strcmp(obd->obd_type->typ_name, LUSTRE_OST_NAME))
277                 auto_quota_on(obd, type - 1, obt->obt_sb, 0);
278         else 
279                 return -EFAULT;
280
281         return count;
282 }
283 EXPORT_SYMBOL(lprocfs_wr_type);
284 #endif /* LPROCFS */
285
286 static int filter_quota_setup(struct obd_device *obd)
287 {
288         int rc = 0;
289         struct obd_device_target *obt = &obd->u.obt;
290         ENTRY;
291
292         atomic_set(&obt->obt_quotachecking, 1);
293         rc = qctxt_init(&obt->obt_qctxt, obt->obt_sb, NULL);
294         if (rc) {
295                 CERROR("initialize quota context failed! (rc:%d)\n", rc);
296                 RETURN(rc);
297         }
298         RETURN(rc);
299 }
300
301 static int filter_quota_cleanup(struct obd_device *obd)
302 {
303         qctxt_cleanup(&obd->u.obt.obt_qctxt, 0);
304         return 0;
305 }
306
307 static int filter_quota_setinfo(struct obd_export *exp, struct obd_device *obd)
308 {
309         struct obd_import *imp;
310
311         /* setup the quota context import */
312         obd->u.obt.obt_qctxt.lqc_import = exp->exp_imp_reverse;
313
314         /* make imp's connect flags equal relative exp's connect flags 
315          * adding it to avoid the scan export list
316          */
317         imp = exp->exp_imp_reverse;
318         if (imp)
319                 imp->imp_connect_data.ocd_connect_flags |= 
320                         (exp->exp_connect_flags & OBD_CONNECT_QUOTA64);
321
322         /* start quota slave recovery thread. (release high limits) */
323         qslave_start_recovery(obd, &obd->u.obt.obt_qctxt);
324         return 0;
325 }
326 static int filter_quota_enforce(struct obd_device *obd, unsigned int ignore)
327 {
328         ENTRY;
329
330         if (!sb_any_quota_enabled(obd->u.obt.obt_sb))
331                 RETURN(0);
332
333         if (ignore)
334                 cap_raise(current->cap_effective, CAP_SYS_RESOURCE);
335         else
336                 cap_lower(current->cap_effective, CAP_SYS_RESOURCE);
337
338         RETURN(0);
339 }
340
341 static int filter_quota_getflag(struct obd_device *obd, struct obdo *oa)
342 {
343         struct obd_device_target *obt = &obd->u.obt;
344         int err, cnt, rc = 0;
345         struct obd_quotactl *oqctl;
346         ENTRY;
347
348         if (!sb_any_quota_enabled(obt->obt_sb))
349                 RETURN(0);
350
351         oa->o_flags &= ~(OBD_FL_NO_USRQUOTA | OBD_FL_NO_GRPQUOTA);
352
353         OBD_ALLOC_PTR(oqctl);
354         if (!oqctl) {
355                 CERROR("Not enough memory!");
356                 RETURN(-ENOMEM);
357         }
358
359         for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
360                 memset(oqctl, 0, sizeof(*oqctl));
361
362                 oqctl->qc_cmd = Q_GETQUOTA;
363                 oqctl->qc_type = cnt;
364                 oqctl->qc_id = (cnt == USRQUOTA) ? oa->o_uid : oa->o_gid;
365                 err = fsfilt_quotactl(obd, obt->obt_sb, oqctl);
366                 if (err) {
367                         if (!rc)
368                                 rc = err;
369                         continue;
370                 }
371
372                 /* set over quota flags for a uid/gid */
373                 oa->o_valid |= (cnt == USRQUOTA) ?
374                                OBD_MD_FLUSRQUOTA : OBD_MD_FLGRPQUOTA;
375                 if (oqctl->qc_dqblk.dqb_bhardlimit &&
376                    (toqb(oqctl->qc_dqblk.dqb_curspace) > 
377                     oqctl->qc_dqblk.dqb_bhardlimit))
378                         oa->o_flags |= (cnt == USRQUOTA) ? 
379                                 OBD_FL_NO_USRQUOTA : OBD_FL_NO_GRPQUOTA;
380         }
381         OBD_FREE_PTR(oqctl);
382         RETURN(rc);
383 }
384
385 static int filter_quota_acquire(struct obd_device *obd, unsigned int uid, 
386                                 unsigned int gid)
387 {
388         struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt;
389         int rc;
390         ENTRY;
391
392         rc = qctxt_adjust_qunit(obd, qctxt, uid, gid, 1, 1);
393         RETURN(rc == -EAGAIN);
394 }
395
396 /* check whether the left quota of certain uid and uid can satisfy a write rpc
397  * when need to acquire quota, return QUOTA_RET_ACQUOTA */
398 static int filter_quota_check(struct obd_device *obd, unsigned int uid, 
399                               unsigned int gid, int npage)
400 {
401         struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt;
402         int i;
403         __u32 id[MAXQUOTAS] = { uid, gid };
404         struct qunit_data qdata[MAXQUOTAS];
405         int rc;
406         ENTRY;
407
408         CLASSERT(MAXQUOTAS < 4);
409         if (!sb_any_quota_enabled(qctxt->lqc_sb))
410                 RETURN(0);
411
412         for (i = 0; i < MAXQUOTAS; i++) {
413                 qdata[i].qd_id = id[i];
414                 qdata[i].qd_flags = i;
415                 qdata[i].qd_flags |= QUOTA_IS_BLOCK;
416                 qdata[i].qd_count = 0;
417
418                 qctxt_wait_pending_dqacq(qctxt, id[i], i, 1);
419                 rc = compute_remquota(obd, qctxt, &qdata[i]);
420                 if (rc == QUOTA_RET_OK && 
421                     qdata[i].qd_count < npage * CFS_PAGE_SIZE)
422                         RETURN(QUOTA_RET_ACQUOTA);
423         }
424
425         RETURN(rc);
426 }
427
428 static int mds_quota_init(void)
429 {
430         return lustre_dquot_init();
431 }
432
433 static int mds_quota_exit(void)
434 {
435         lustre_dquot_exit();
436         return 0;
437 }
438
439 static int mds_quota_setup(struct obd_device *obd)
440 {
441         struct obd_device_target *obt = &obd->u.obt;
442         struct mds_obd *mds = &obd->u.mds;
443         int rc;
444         ENTRY;
445
446         atomic_set(&obt->obt_quotachecking, 1);
447         /* initialize quota master and quota context */
448         sema_init(&mds->mds_qonoff_sem, 1);
449         rc = qctxt_init(&obt->obt_qctxt, obt->obt_sb, dqacq_handler);
450         if (rc) {
451                 CERROR("initialize quota context failed! (rc:%d)\n", rc);
452                 RETURN(rc);
453         }
454         RETURN(rc);
455 }
456
457 static int mds_quota_cleanup(struct obd_device *obd)
458 {
459         qctxt_cleanup(&obd->u.obt.obt_qctxt, 0);
460         RETURN(0);
461 }
462
463 static int mds_quota_fs_cleanup(struct obd_device *obd)
464 {
465         struct mds_obd *mds = &obd->u.mds;
466         int i;
467         ENTRY;
468
469         /* close admin quota files */
470         down(&mds->mds_qonoff_sem);
471         for (i = 0; i < MAXQUOTAS; i++) {
472                 if (mds->mds_quota_info.qi_files[i]) {
473                         filp_close(mds->mds_quota_info.qi_files[i], 0);
474                         mds->mds_quota_info.qi_files[i] = NULL;
475                 }
476         }
477         up(&mds->mds_qonoff_sem);
478         RETURN(0);
479 }
480 #endif /* __KERNEL__ */
481
482 struct osc_quota_info {
483         struct list_head        oqi_hash;       /* hash list */
484         struct client_obd      *oqi_cli;        /* osc obd */
485         unsigned int            oqi_id;         /* uid/gid of a file */
486         short                   oqi_type;       /* quota type */
487 };
488
489 spinlock_t qinfo_list_lock = SPIN_LOCK_UNLOCKED;
490
491 static struct list_head qinfo_hash[NR_DQHASH];
492 /* SLAB cache for client quota context */
493 cfs_mem_cache_t *qinfo_cachep = NULL;
494
495 static inline int hashfn(struct client_obd *cli, unsigned long id, int type)
496                          __attribute__((__const__));
497
498 static inline int hashfn(struct client_obd *cli, unsigned long id, int type)
499 {
500         unsigned long tmp = ((unsigned long)cli>>6) ^ id;
501         tmp = (tmp * (MAXQUOTAS - type)) % NR_DQHASH;
502         return tmp;
503 }
504
505 /* caller must hold qinfo_list_lock */
506 static inline void insert_qinfo_hash(struct osc_quota_info *oqi)
507 {
508         struct list_head *head = qinfo_hash + 
509                 hashfn(oqi->oqi_cli, oqi->oqi_id, oqi->oqi_type);
510
511         LASSERT_SPIN_LOCKED(&qinfo_list_lock);
512         list_add(&oqi->oqi_hash, head);
513 }
514
515 /* caller must hold qinfo_list_lock */
516 static inline void remove_qinfo_hash(struct osc_quota_info *oqi)
517 {
518         LASSERT_SPIN_LOCKED(&qinfo_list_lock);
519         list_del_init(&oqi->oqi_hash);
520 }
521
522 /* caller must hold qinfo_list_lock */
523 static inline struct osc_quota_info *find_qinfo(struct client_obd *cli,
524                                                 unsigned int id, int type)
525 {
526         unsigned int hashent = hashfn(cli, id, type);
527         struct osc_quota_info *oqi;
528
529         LASSERT_SPIN_LOCKED(&qinfo_list_lock);
530         list_for_each_entry(oqi, &qinfo_hash[hashent], oqi_hash) {
531                 if (oqi->oqi_cli == cli &&
532                     oqi->oqi_id == id && oqi->oqi_type == type)
533                         return oqi;
534         }
535         return NULL;
536 }
537
538 static struct osc_quota_info *alloc_qinfo(struct client_obd *cli,
539                                           unsigned int id, int type)
540 {
541         struct osc_quota_info *oqi;
542         ENTRY;
543
544         OBD_SLAB_ALLOC(oqi, qinfo_cachep, CFS_ALLOC_STD, sizeof(*oqi));
545         if(!oqi)
546                 RETURN(NULL);
547
548         INIT_LIST_HEAD(&oqi->oqi_hash);
549         oqi->oqi_cli = cli;
550         oqi->oqi_id = id;
551         oqi->oqi_type = type;
552
553         RETURN(oqi);
554 }
555
556 static void free_qinfo(struct osc_quota_info *oqi)
557 {
558         OBD_SLAB_FREE(oqi, qinfo_cachep, sizeof(*oqi));
559 }
560
561 int osc_quota_chkdq(struct client_obd *cli, 
562                     unsigned int uid, unsigned int gid)
563 {
564         unsigned int id;
565         int cnt, rc = QUOTA_OK;
566         ENTRY;
567
568         spin_lock(&qinfo_list_lock);
569         for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
570                 struct osc_quota_info *oqi = NULL;
571
572                 id = (cnt == USRQUOTA) ? uid : gid;
573                 oqi = find_qinfo(cli, id, cnt);
574                 if (oqi) {
575                         rc = NO_QUOTA;
576                         break;
577                 }
578         }
579         spin_unlock(&qinfo_list_lock);
580
581         RETURN(rc);
582 }
583
584 int osc_quota_setdq(struct client_obd *cli, 
585                     unsigned int uid, unsigned int gid,
586                     obd_flag valid, obd_flag flags)
587 {
588         unsigned int id;
589         obd_flag noquota;
590         int cnt, rc = 0;
591         ENTRY;
592
593
594         for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
595                 struct osc_quota_info *oqi, *old;
596
597                 if (!(valid & ((cnt == USRQUOTA) ? 
598                     OBD_MD_FLUSRQUOTA : OBD_MD_FLGRPQUOTA)))
599                         continue;
600
601                 id = (cnt == USRQUOTA) ? uid : gid;
602                 noquota = (cnt == USRQUOTA) ? 
603                     (flags & OBD_FL_NO_USRQUOTA) : (flags & OBD_FL_NO_GRPQUOTA);
604
605                 oqi = alloc_qinfo(cli, id, cnt);
606                 if (oqi) {
607                         spin_lock(&qinfo_list_lock);
608
609                         old = find_qinfo(cli, id, cnt);
610                         if (old && !noquota)
611                                 remove_qinfo_hash(old);
612                         else if (!old && noquota)
613                                 insert_qinfo_hash(oqi);
614
615                         spin_unlock(&qinfo_list_lock);
616
617                         if (old || !noquota)
618                                 free_qinfo(oqi);
619                         if (old && !noquota)
620                                 free_qinfo(old);
621                 } else {
622                         CERROR("not enough mem!\n");
623                         rc = -ENOMEM;
624                         break;
625                 }
626         }
627
628         RETURN(rc);
629 }
630
631 int osc_quota_cleanup(struct obd_device *obd)
632 {
633         struct client_obd *cli = &obd->u.cli;
634         struct osc_quota_info *oqi, *n;
635         int i;
636         ENTRY;
637
638         spin_lock(&qinfo_list_lock);
639         for (i = 0; i < NR_DQHASH; i++) {
640                 list_for_each_entry_safe(oqi, n, &qinfo_hash[i], oqi_hash) {
641                         if (oqi->oqi_cli != cli)
642                                 continue;
643                         remove_qinfo_hash(oqi);
644                         free_qinfo(oqi);
645                 }
646         }
647         spin_unlock(&qinfo_list_lock);
648
649         RETURN(0);
650 }
651
652 int osc_quota_init(void)
653 {
654         int i;
655         ENTRY;
656
657         LASSERT(qinfo_cachep == NULL);
658         qinfo_cachep = cfs_mem_cache_create("osc_quota_info",
659                                          sizeof(struct osc_quota_info),
660                                          0, 0);
661         if (!qinfo_cachep)
662                 RETURN(-ENOMEM);
663
664         for (i = 0; i < NR_DQHASH; i++)
665                 INIT_LIST_HEAD(qinfo_hash + i);
666
667         RETURN(0);
668 }
669
670 int osc_quota_exit(void)
671 {
672         struct osc_quota_info *oqi, *n;
673         int i, rc;
674         ENTRY;
675
676         spin_lock(&qinfo_list_lock);
677         for (i = 0; i < NR_DQHASH; i++) {
678                 list_for_each_entry_safe(oqi, n, &qinfo_hash[i], oqi_hash) {
679                         remove_qinfo_hash(oqi);
680                         free_qinfo(oqi);
681                 }
682         }
683         spin_unlock(&qinfo_list_lock);
684
685         rc = cfs_mem_cache_destroy(qinfo_cachep);
686         LASSERTF(rc == 0, "couldn't destory qinfo_cachep slab\n");
687         qinfo_cachep = NULL;
688
689         RETURN(0);
690 }
691
692 #ifdef __KERNEL__
693 quota_interface_t mds_quota_interface = {
694         .quota_init     = mds_quota_init,
695         .quota_exit     = mds_quota_exit,
696         .quota_setup    = mds_quota_setup,
697         .quota_cleanup  = mds_quota_cleanup,
698         .quota_check    = target_quota_check,
699         .quota_ctl      = mds_quota_ctl,
700         .quota_fs_cleanup       =mds_quota_fs_cleanup,
701         .quota_recovery = mds_quota_recovery,
702         .quota_adjust   = mds_quota_adjust,
703 };
704
705 quota_interface_t filter_quota_interface = {
706         .quota_setup    = filter_quota_setup,
707         .quota_cleanup  = filter_quota_cleanup,
708         .quota_check    = target_quota_check,
709         .quota_ctl      = filter_quota_ctl,
710         .quota_setinfo  = filter_quota_setinfo,
711         .quota_enforce  = filter_quota_enforce,
712         .quota_getflag  = filter_quota_getflag,
713         .quota_acquire  = filter_quota_acquire,
714         .quota_adjust   = filter_quota_adjust,
715         .quota_chkquota = filter_quota_check,
716 };
717 #endif /* __KERNEL__ */
718
719 quota_interface_t mdc_quota_interface = {
720         .quota_ctl      = client_quota_ctl,
721         .quota_check    = client_quota_check,
722         .quota_poll_check = client_quota_poll_check,
723 };
724
725 quota_interface_t osc_quota_interface = {
726         .quota_ctl      = client_quota_ctl,
727         .quota_check    = client_quota_check,
728         .quota_poll_check = client_quota_poll_check,
729         .quota_init     = osc_quota_init,
730         .quota_exit     = osc_quota_exit,
731         .quota_chkdq    = osc_quota_chkdq,
732         .quota_setdq    = osc_quota_setdq,
733         .quota_cleanup  = osc_quota_cleanup,
734 };
735
736 quota_interface_t lov_quota_interface = {
737         .quota_check    = lov_quota_check,
738         .quota_ctl      = lov_quota_ctl,
739 };
740
741 #ifdef __KERNEL__
742 static int __init init_lustre_quota(void)
743 {
744         int rc = qunit_cache_init();
745         if (rc)
746                 return rc;
747         PORTAL_SYMBOL_REGISTER(filter_quota_interface);
748         PORTAL_SYMBOL_REGISTER(mds_quota_interface);
749         PORTAL_SYMBOL_REGISTER(mdc_quota_interface);
750         PORTAL_SYMBOL_REGISTER(osc_quota_interface);
751         PORTAL_SYMBOL_REGISTER(lov_quota_interface);
752         return 0;
753 }
754
755 static void /*__exit*/ exit_lustre_quota(void)
756 {
757         PORTAL_SYMBOL_UNREGISTER(filter_quota_interface);
758         PORTAL_SYMBOL_UNREGISTER(mds_quota_interface);
759         PORTAL_SYMBOL_UNREGISTER(mdc_quota_interface);
760         PORTAL_SYMBOL_UNREGISTER(osc_quota_interface);
761         PORTAL_SYMBOL_UNREGISTER(lov_quota_interface);
762
763         qunit_cache_cleanup();
764 }
765
766 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
767 MODULE_DESCRIPTION("Lustre Quota");
768 MODULE_LICENSE("GPL");
769
770 cfs_module(lquota, "1.0.0", init_lustre_quota, exit_lustre_quota);
771
772 EXPORT_SYMBOL(mds_quota_interface);
773 EXPORT_SYMBOL(filter_quota_interface);
774 EXPORT_SYMBOL(mdc_quota_interface);
775 EXPORT_SYMBOL(osc_quota_interface);
776 EXPORT_SYMBOL(lov_quota_interface);
777 #endif /* __KERNEL */