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