Whamcloud - gitweb
d7084a983bc678580b644dec4be43244d28e6e65
[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 /* quota proc file handling functions */
50 #ifdef LPROCFS
51 int lprocfs_rd_bunit(char *page, char **start, off_t off, int count, 
52                      int *eof, void *data)
53 {
54         struct obd_device *obd = (struct obd_device *)data;
55         LASSERT(obd != NULL);
56
57         return snprintf(page, count, "%lu\n", 
58                         obd->u.obt.obt_qctxt.lqc_bunit_sz);
59 }
60 EXPORT_SYMBOL(lprocfs_rd_bunit);
61
62 int lprocfs_rd_iunit(char *page, char **start, off_t off, int count, 
63                      int *eof, void *data)
64 {
65         struct obd_device *obd = (struct obd_device *)data;
66         LASSERT(obd != NULL);
67
68         return snprintf(page, count, "%lu\n", 
69                         obd->u.obt.obt_qctxt.lqc_iunit_sz);
70 }
71 EXPORT_SYMBOL(lprocfs_rd_iunit);
72
73 int lprocfs_wr_bunit(struct file *file, const char *buffer,
74                      unsigned long count, void *data)
75 {
76         struct obd_device *obd = (struct obd_device *)data;
77         int val, rc;
78         LASSERT(obd != NULL);
79
80         rc = lprocfs_write_helper(buffer, count, &val);
81
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
253 int lprocfs_wr_type(struct file *file, const char *buffer,
254                     unsigned long count, void *data)
255 {
256         struct obd_device *obd = (struct obd_device *)data;
257         struct obd_device_target *obt = &obd->u.obt;
258         int type = 0;
259         char stype[MAX_STYPE_SIZE + 1] = "";
260         LASSERT(obd != NULL);
261
262         if (copy_from_user(stype, buffer, MAX_STYPE_SIZE))
263                 return -EFAULT;
264
265         if (strchr(stype, 'u'))
266                 type |= USER_QUOTA;
267         if (strchr(stype, 'g'))
268                 type |= GROUP_QUOTA;
269         
270         obt->obt_qctxt.lqc_atype = type;
271
272         if (type == 0)
273                 return count;
274
275         if (!strcmp(obd->obd_type->typ_name, LUSTRE_MDS_NAME))
276                 auto_quota_on(obd, type - 1, obt->obt_sb, 1);
277         else if (!strcmp(obd->obd_type->typ_name, LUSTRE_OST_NAME))
278                 auto_quota_on(obd, type - 1, obt->obt_sb, 0);
279         else 
280                 return -EFAULT;
281
282         return count;
283 }
284 EXPORT_SYMBOL(lprocfs_wr_type);
285 #endif /* LPROCFS */
286
287 static int filter_quota_setup(struct obd_device *obd)
288 {
289         int rc = 0;
290         struct obd_device_target *obt = &obd->u.obt;
291         ENTRY;
292
293         atomic_set(&obt->obt_quotachecking, 1);
294         rc = qctxt_init(&obt->obt_qctxt, obt->obt_sb, NULL);
295         if (rc) {
296                 CERROR("initialize quota context failed! (rc:%d)\n", rc);
297                 RETURN(rc);
298         }
299
300         RETURN(rc);
301 }
302
303 static int filter_quota_cleanup(struct obd_device *obd)
304 {
305         qctxt_cleanup(&obd->u.obt.obt_qctxt, 0);
306         return 0;
307 }
308
309 static int filter_quota_setinfo(struct obd_export *exp, struct obd_device *obd)
310 {
311         struct obd_import *imp;
312
313         /* setup the quota context import */
314         obd->u.obt.obt_qctxt.lqc_import = exp->exp_imp_reverse;
315
316         /* make imp's connect flags equal relative exp's connect flags 
317          * adding it to avoid the scan export list
318          */
319         imp = exp->exp_imp_reverse;
320         if (imp)
321                 imp->imp_connect_data.ocd_connect_flags |= 
322                         (exp->exp_connect_flags & OBD_CONNECT_QUOTA64);
323
324         /* start quota slave recovery thread. (release high limits) */
325         qslave_start_recovery(obd, &obd->u.obt.obt_qctxt);
326         return 0;
327 }
328 static int filter_quota_enforce(struct obd_device *obd, unsigned int ignore)
329 {
330         ENTRY;
331
332         if (!sb_any_quota_enabled(obd->u.obt.obt_sb))
333                 RETURN(0);
334
335         if (ignore)
336                 cap_raise(current->cap_effective, CAP_SYS_RESOURCE);
337         else
338                 cap_lower(current->cap_effective, CAP_SYS_RESOURCE);
339
340         RETURN(0);
341 }
342
343 static int filter_quota_getflag(struct obd_device *obd, struct obdo *oa)
344 {
345         struct obd_device_target *obt = &obd->u.obt;
346         int err, cnt, rc = 0;
347         struct obd_quotactl *oqctl;
348         ENTRY;
349
350         if (!sb_any_quota_enabled(obt->obt_sb))
351                 RETURN(0);
352
353         oa->o_flags &= ~(OBD_FL_NO_USRQUOTA | OBD_FL_NO_GRPQUOTA);
354
355         OBD_ALLOC_PTR(oqctl);
356         if (!oqctl) {
357                 CERROR("Not enough memory!");
358                 RETURN(-ENOMEM);
359         }
360
361         for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
362                 memset(oqctl, 0, sizeof(*oqctl));
363
364                 oqctl->qc_cmd = Q_GETQUOTA;
365                 oqctl->qc_type = cnt;
366                 oqctl->qc_id = (cnt == USRQUOTA) ? oa->o_uid : oa->o_gid;
367                 err = fsfilt_quotactl(obd, obt->obt_sb, oqctl);
368                 if (err) {
369                         if (!rc)
370                                 rc = err;
371                         continue;
372                 }
373
374                 /* set over quota flags for a uid/gid */
375                 oa->o_valid |= (cnt == USRQUOTA) ?
376                                OBD_MD_FLUSRQUOTA : OBD_MD_FLGRPQUOTA;
377                 if (oqctl->qc_dqblk.dqb_bhardlimit &&
378                    (toqb(oqctl->qc_dqblk.dqb_curspace) >
379                     oqctl->qc_dqblk.dqb_bhardlimit))
380                         oa->o_flags |= (cnt == USRQUOTA) ?
381                                 OBD_FL_NO_USRQUOTA : OBD_FL_NO_GRPQUOTA;
382         }
383         OBD_FREE_PTR(oqctl);
384         RETURN(rc);
385 }
386
387 static int filter_quota_acquire(struct obd_device *obd, unsigned int uid,
388                                 unsigned int gid)
389 {
390         struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt;
391         int rc;
392         ENTRY;
393
394         rc = qctxt_adjust_qunit(obd, qctxt, uid, gid, 1, 1);
395         RETURN(rc == -EAGAIN);
396 }
397
398 static int mds_quota_init(void)
399 {
400         return lustre_dquot_init();
401 }
402
403 static int mds_quota_exit(void)
404 {
405         lustre_dquot_exit();
406         return 0;
407 }
408
409 /* check whether the left quota of certain uid and uid can satisfy a write rpc
410  * when need to acquire quota, return QUOTA_RET_ACQUOTA */
411 static int filter_quota_check(struct obd_device *obd, unsigned int uid, 
412                               unsigned int gid, int npage)
413 {
414         struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt;
415         int i;
416         __u32 id[MAXQUOTAS] = { uid, gid };
417         struct qunit_data qdata[MAXQUOTAS];
418         int rc;
419         ENTRY;
420
421         CLASSERT(MAXQUOTAS < 4);
422         if (!sb_any_quota_enabled(qctxt->lqc_sb))
423                 RETURN(0);
424
425         for (i = 0; i < MAXQUOTAS; i++) {
426                 qdata[i].qd_id = id[i];
427                 qdata[i].qd_flags = i;
428                 qdata[i].qd_flags |= QUOTA_IS_BLOCK;
429                 qdata[i].qd_count = 0;
430
431                 qctxt_wait_pending_dqacq(qctxt, id[i], i, 1);
432                 rc = compute_remquota(obd, qctxt, &qdata[i]);
433                 if (rc == QUOTA_RET_OK && 
434                     qdata[i].qd_count < npage * CFS_PAGE_SIZE)
435                         RETURN(QUOTA_RET_ACQUOTA);
436         }
437
438         RETURN(rc);
439 }
440
441 static int mds_quota_setup(struct obd_device *obd)
442 {
443         struct obd_device_target *obt = &obd->u.obt;
444         struct mds_obd *mds = &obd->u.mds;
445         int rc;
446         ENTRY;
447
448         atomic_set(&obt->obt_quotachecking, 1);
449         /* initialize quota master and quota context */
450         sema_init(&mds->mds_qonoff_sem, 1);
451         rc = qctxt_init(&obt->obt_qctxt, obt->obt_sb, dqacq_handler);
452         if (rc) {
453                 CERROR("initialize quota context failed! (rc:%d)\n", rc);
454                 RETURN(rc);
455         }
456
457         RETURN(rc);
458 }
459
460 static int mds_quota_cleanup(struct obd_device *obd)
461 {
462         qctxt_cleanup(&obd->u.obt.obt_qctxt, 0);
463         RETURN(0);
464 }
465
466 static int mds_quota_fs_cleanup(struct obd_device *obd)
467 {
468         struct mds_obd *mds = &obd->u.mds;
469         int i;
470         ENTRY;
471
472         /* close admin quota files */
473         down(&mds->mds_qonoff_sem);
474         for (i = 0; i < MAXQUOTAS; i++) {
475                 if (mds->mds_quota_info.qi_files[i]) {
476                         filp_close(mds->mds_quota_info.qi_files[i], 0);
477                         mds->mds_quota_info.qi_files[i] = NULL;
478                 }
479         }
480         up(&mds->mds_qonoff_sem);
481         RETURN(0);
482 }
483 #endif /* __KERNEL__ */
484
485 struct osc_quota_info {
486         struct list_head        oqi_hash;       /* hash list */
487         struct client_obd      *oqi_cli;        /* osc obd */
488         unsigned int            oqi_id;         /* uid/gid of a file */
489         short                   oqi_type;       /* quota type */
490 };
491
492 spinlock_t qinfo_list_lock = SPIN_LOCK_UNLOCKED;
493
494 static struct list_head qinfo_hash[NR_DQHASH];
495 /* SLAB cache for client quota context */
496 cfs_mem_cache_t *qinfo_cachep = NULL;
497
498 static inline int hashfn(struct client_obd *cli, unsigned long id, int type)
499                          __attribute__((__const__));
500
501 static inline int hashfn(struct client_obd *cli, unsigned long id, int type)
502 {
503         unsigned long tmp = ((unsigned long)cli>>6) ^ id;
504         tmp = (tmp * (MAXQUOTAS - type)) % NR_DQHASH;
505         return tmp;
506 }
507
508 /* caller must hold qinfo_list_lock */
509 static inline void insert_qinfo_hash(struct osc_quota_info *oqi)
510 {
511         struct list_head *head = qinfo_hash +
512                 hashfn(oqi->oqi_cli, oqi->oqi_id, oqi->oqi_type);
513
514         LASSERT_SPIN_LOCKED(&qinfo_list_lock);
515         list_add(&oqi->oqi_hash, head);
516 }
517
518 /* caller must hold qinfo_list_lock */
519 static inline void remove_qinfo_hash(struct osc_quota_info *oqi)
520 {
521         LASSERT_SPIN_LOCKED(&qinfo_list_lock);
522         list_del_init(&oqi->oqi_hash);
523 }
524
525 /* caller must hold qinfo_list_lock */
526 static inline struct osc_quota_info *find_qinfo(struct client_obd *cli,
527                                                 unsigned int id, int type)
528 {
529         unsigned int hashent = hashfn(cli, id, type);
530         struct osc_quota_info *oqi;
531
532         LASSERT_SPIN_LOCKED(&qinfo_list_lock);
533         list_for_each_entry(oqi, &qinfo_hash[hashent], oqi_hash) {
534                 if (oqi->oqi_cli == cli &&
535                     oqi->oqi_id == id && oqi->oqi_type == type)
536                         return oqi;
537         }
538         return NULL;
539 }
540
541 static struct osc_quota_info *alloc_qinfo(struct client_obd *cli,
542                                           unsigned int id, int type)
543 {
544         struct osc_quota_info *oqi;
545         ENTRY;
546
547         OBD_SLAB_ALLOC(oqi, qinfo_cachep, CFS_ALLOC_STD, sizeof(*oqi));
548         if(!oqi)
549                 RETURN(NULL);
550
551         INIT_LIST_HEAD(&oqi->oqi_hash);
552         oqi->oqi_cli = cli;
553         oqi->oqi_id = id;
554         oqi->oqi_type = type;
555
556         RETURN(oqi);
557 }
558
559 static void free_qinfo(struct osc_quota_info *oqi)
560 {
561         OBD_SLAB_FREE(oqi, qinfo_cachep, sizeof(*oqi));
562 }
563
564 int osc_quota_chkdq(struct client_obd *cli,
565                     unsigned int uid, unsigned int gid)
566 {
567         unsigned int id;
568         int cnt, rc = QUOTA_OK;
569         ENTRY;
570
571         spin_lock(&qinfo_list_lock);
572         for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
573                 struct osc_quota_info *oqi = NULL;
574
575                 id = (cnt == USRQUOTA) ? uid : gid;
576                 oqi = find_qinfo(cli, id, cnt);
577                 if (oqi) {
578                         rc = NO_QUOTA;
579                         break;
580                 }
581         }
582         spin_unlock(&qinfo_list_lock);
583
584         RETURN(rc);
585 }
586
587 int osc_quota_setdq(struct client_obd *cli,
588                     unsigned int uid, unsigned int gid,
589                     obd_flag valid, obd_flag flags)
590 {
591         unsigned int id;
592         obd_flag noquota;
593         int cnt, rc = 0;
594         ENTRY;
595
596
597         for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
598                 struct osc_quota_info *oqi, *old;
599
600                 if (!(valid & ((cnt == USRQUOTA) ?
601                     OBD_MD_FLUSRQUOTA : OBD_MD_FLGRPQUOTA)))
602                         continue;
603
604                 id = (cnt == USRQUOTA) ? uid : gid;
605                 noquota = (cnt == USRQUOTA) ?
606                     (flags & OBD_FL_NO_USRQUOTA) : (flags & OBD_FL_NO_GRPQUOTA);
607
608                 oqi = alloc_qinfo(cli, id, cnt);
609                 if (oqi) {
610                         spin_lock(&qinfo_list_lock);
611
612                         old = find_qinfo(cli, id, cnt);
613                         if (old && !noquota)
614                                 remove_qinfo_hash(old);
615                         else if (!old && noquota)
616                                 insert_qinfo_hash(oqi);
617
618                         spin_unlock(&qinfo_list_lock);
619
620                         if (old || !noquota)
621                                 free_qinfo(oqi);
622                         if (old && !noquota)
623                                 free_qinfo(old);
624                 } else {
625                         CERROR("not enough mem!\n");
626                         rc = -ENOMEM;
627                         break;
628                 }
629         }
630
631         RETURN(rc);
632 }
633
634 int osc_quota_cleanup(struct obd_device *obd)
635 {
636         struct client_obd *cli = &obd->u.cli;
637         struct osc_quota_info *oqi, *n;
638         int i;
639         ENTRY;
640
641         spin_lock(&qinfo_list_lock);
642         for (i = 0; i < NR_DQHASH; i++) {
643                 list_for_each_entry_safe(oqi, n, &qinfo_hash[i], oqi_hash) {
644                         if (oqi->oqi_cli != cli)
645                                 continue;
646                         remove_qinfo_hash(oqi);
647                         free_qinfo(oqi);
648                 }
649         }
650         spin_unlock(&qinfo_list_lock);
651
652         RETURN(0);
653 }
654
655 int osc_quota_init(void)
656 {
657         int i;
658         ENTRY;
659
660         LASSERT(qinfo_cachep == NULL);
661         qinfo_cachep = cfs_mem_cache_create("osc_quota_info",
662                                          sizeof(struct osc_quota_info),
663                                          0, 0);
664         if (!qinfo_cachep)
665                 RETURN(-ENOMEM);
666
667         for (i = 0; i < NR_DQHASH; i++)
668                 INIT_LIST_HEAD(qinfo_hash + i);
669
670         RETURN(0);
671 }
672
673 int osc_quota_exit(void)
674 {
675         struct osc_quota_info *oqi, *n;
676         int i, rc;
677         ENTRY;
678
679         spin_lock(&qinfo_list_lock);
680         for (i = 0; i < NR_DQHASH; i++) {
681                 list_for_each_entry_safe(oqi, n, &qinfo_hash[i], oqi_hash) {
682                         remove_qinfo_hash(oqi);
683                         free_qinfo(oqi);
684                 }
685         }
686         spin_unlock(&qinfo_list_lock);
687
688         rc = cfs_mem_cache_destroy(qinfo_cachep);
689         LASSERTF(rc == 0, "couldn't destory qinfo_cachep slab\n");
690         qinfo_cachep = NULL;
691
692         RETURN(0);
693 }
694
695 #ifdef __KERNEL__
696 quota_interface_t mds_quota_interface = {
697         .quota_init     = mds_quota_init,
698         .quota_exit     = mds_quota_exit,
699         .quota_setup    = mds_quota_setup,
700         .quota_cleanup  = mds_quota_cleanup,
701         .quota_check    = target_quota_check,
702         .quota_ctl      = mds_quota_ctl,
703         .quota_fs_cleanup       =mds_quota_fs_cleanup,
704         .quota_recovery = mds_quota_recovery,
705         .quota_adjust   = mds_quota_adjust,
706 };
707
708 quota_interface_t filter_quota_interface = {
709         .quota_setup    = filter_quota_setup,
710         .quota_cleanup  = filter_quota_cleanup,
711         .quota_check    = target_quota_check,
712         .quota_ctl      = filter_quota_ctl,
713         .quota_setinfo  = filter_quota_setinfo,
714         .quota_enforce  = filter_quota_enforce,
715         .quota_getflag  = filter_quota_getflag,
716         .quota_acquire  = filter_quota_acquire,
717         .quota_adjust   = filter_quota_adjust,
718         .quota_chkquota = filter_quota_check,
719 };
720 #endif /* __KERNEL__ */
721
722 quota_interface_t mdc_quota_interface = {
723         .quota_ctl      = client_quota_ctl,
724         .quota_check    = client_quota_check,
725         .quota_poll_check = client_quota_poll_check,
726 };
727
728 quota_interface_t osc_quota_interface = {
729         .quota_ctl      = client_quota_ctl,
730         .quota_check    = client_quota_check,
731         .quota_poll_check = client_quota_poll_check,
732         .quota_init     = osc_quota_init,
733         .quota_exit     = osc_quota_exit,
734         .quota_chkdq    = osc_quota_chkdq,
735         .quota_setdq    = osc_quota_setdq,
736         .quota_cleanup  = osc_quota_cleanup,
737 };
738
739 quota_interface_t lov_quota_interface = {
740         .quota_check    = lov_quota_check,
741         .quota_ctl      = lov_quota_ctl,
742 };
743
744 #ifdef __KERNEL__
745 static int __init init_lustre_quota(void)
746 {
747         int rc = qunit_cache_init();
748         if (rc)
749                 return rc;
750         PORTAL_SYMBOL_REGISTER(filter_quota_interface);
751         PORTAL_SYMBOL_REGISTER(mds_quota_interface);
752         PORTAL_SYMBOL_REGISTER(mdc_quota_interface);
753         PORTAL_SYMBOL_REGISTER(osc_quota_interface);
754         PORTAL_SYMBOL_REGISTER(lov_quota_interface);
755         return 0;
756 }
757
758 static void /*__exit*/ exit_lustre_quota(void)
759 {
760         PORTAL_SYMBOL_UNREGISTER(filter_quota_interface);
761         PORTAL_SYMBOL_UNREGISTER(mds_quota_interface);
762         PORTAL_SYMBOL_UNREGISTER(mdc_quota_interface);
763         PORTAL_SYMBOL_UNREGISTER(osc_quota_interface);
764         PORTAL_SYMBOL_UNREGISTER(lov_quota_interface);
765
766         qunit_cache_cleanup();
767 }
768
769 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
770 MODULE_DESCRIPTION("Lustre Quota");
771 MODULE_LICENSE("GPL");
772
773 cfs_module(lquota, "1.0.0", init_lustre_quota, exit_lustre_quota);
774
775 EXPORT_SYMBOL(mds_quota_interface);
776 EXPORT_SYMBOL(filter_quota_interface);
777 EXPORT_SYMBOL(mdc_quota_interface);
778 EXPORT_SYMBOL(osc_quota_interface);
779 EXPORT_SYMBOL(lov_quota_interface);
780 #endif /* __KERNEL */