Whamcloud - gitweb
LU-812 compat: clean up mutex lock to use kernel mutex primitive
[fs/lustre-release.git] / lustre / include / lustre_quota.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
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.
11  *
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).
17  *
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
21  *
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
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30  * Use is subject to license terms.
31  *
32  * Copyright (c) 2012, Whamcloud, Inc.
33  */
34 /*
35  * This file is part of Lustre, http://www.lustre.org/
36  * Lustre is a trademark of Sun Microsystems, Inc.
37  */
38
39 #ifndef _LUSTRE_QUOTA_H
40 #define _LUSTRE_QUOTA_H
41
42 /** \defgroup quota quota
43  *
44  * @{
45  */
46
47 #if defined(__linux__)
48 #include <linux/lustre_quota.h>
49 #elif defined(__APPLE__)
50 #include <darwin/lustre_quota.h>
51 #elif defined(__WINNT__)
52 #include <winnt/lustre_quota.h>
53 #else
54 #error Unsupported operating system.
55 #endif
56
57 #include <lustre_net.h>
58 #include <lustre/lustre_idl.h>
59 #include <lvfs.h>
60 #include <obd_support.h>
61
62 struct obd_device;
63 struct client_obd;
64
65 #ifndef NR_DQHASH
66 #define NR_DQHASH 45
67 #endif
68
69 #ifndef QUOTABLOCK_BITS
70 #define QUOTABLOCK_BITS 10
71 #endif
72
73 #ifndef QUOTABLOCK_SIZE
74 #define QUOTABLOCK_SIZE (1 << QUOTABLOCK_BITS)
75 #endif
76
77 #ifndef toqb
78 #define toqb(x) (((x) + QUOTABLOCK_SIZE - 1) >> QUOTABLOCK_BITS)
79 #endif
80
81 #ifdef HAVE_QUOTA_SUPPORT
82
83 #ifndef MAX_IQ_TIME
84 #define MAX_IQ_TIME  604800     /* (7*24*60*60) 1 week */
85 #endif
86
87 #ifndef MAX_DQ_TIME
88 #define MAX_DQ_TIME  604800     /* (7*24*60*60) 1 week */
89 #endif
90
91 #ifdef __KERNEL__
92
93 #ifdef LPROCFS
94 enum {
95         LQUOTA_FIRST_STAT = 0,
96         /** @{ */
97         /**
98          * these four are for measuring quota requests, for both of
99          * quota master and quota slaves
100          */
101         LQUOTA_SYNC_ACQ = LQUOTA_FIRST_STAT,
102         LQUOTA_SYNC_REL,
103         LQUOTA_ASYNC_ACQ,
104         LQUOTA_ASYNC_REL,
105         /** }@ */
106         /** @{ */
107         /**
108          * these four measure how much time I/O threads spend on dealing
109          * with quota before and after writing data or creating files,
110          * only for quota slaves(lquota_chkquota and lquota_pending_commit)
111          */
112         LQUOTA_WAIT_FOR_CHK_BLK,
113         LQUOTA_WAIT_FOR_CHK_INO,
114         LQUOTA_WAIT_FOR_COMMIT_BLK,
115         LQUOTA_WAIT_FOR_COMMIT_INO,
116         /** }@ */
117         /** @{ */
118         /**
119          * these two are for measuring time waiting return of quota reqs
120          * (qctxt_wait_pending_dqacq), only for quota salves
121          */
122         LQUOTA_WAIT_PENDING_BLK_QUOTA,
123         LQUOTA_WAIT_PENDING_INO_QUOTA,
124         /** }@ */
125         /** @{ */
126         /**
127          * these two are for those when they are calling
128          * qctxt_wait_pending_dqacq, the quota req has returned already,
129          * only for quota salves
130          */
131         LQUOTA_NOWAIT_PENDING_BLK_QUOTA,
132         LQUOTA_NOWAIT_PENDING_INO_QUOTA,
133         /** }@ */
134         /** @{ */
135         /**
136          * these are for quota ctl
137          */
138         LQUOTA_QUOTA_CTL,
139         /** }@ */
140         /** @{ */
141         /**
142          * these are for adjust quota qunit, for both of
143          * quota master and quota slaves
144          */
145         LQUOTA_ADJUST_QUNIT,
146         LQUOTA_LAST_STAT
147         /** }@ */
148 };
149 #endif  /* LPROCFS */
150
151 /* structures to access admin quotafile */
152 struct lustre_mem_dqinfo {
153         unsigned int dqi_bgrace;
154         unsigned int dqi_igrace;
155         unsigned long dqi_flags;
156         unsigned int dqi_blocks;
157         unsigned int dqi_free_blk;
158         unsigned int dqi_free_entry;
159 };
160
161 struct lustre_quota_info {
162         struct file *qi_files[MAXQUOTAS];
163         struct lustre_mem_dqinfo qi_info[MAXQUOTAS];
164         lustre_quota_version_t qi_version;
165 };
166
167 struct lustre_mem_dqblk {
168         __u64 dqb_bhardlimit;   /**< absolute limit on disk blks alloc */
169         __u64 dqb_bsoftlimit;   /**< preferred limit on disk blks */
170         __u64 dqb_curspace;     /**< current used space */
171         __u64 dqb_ihardlimit;   /**< absolute limit on allocated inodes */
172         __u64 dqb_isoftlimit;   /**< preferred inode limit */
173         __u64 dqb_curinodes;    /**< current # allocated inodes */
174         time_t dqb_btime;       /**< time limit for excessive disk use */
175         time_t dqb_itime;       /**< time limit for excessive inode use */
176 };
177
178 struct lustre_dquot {
179         /** Hash list in memory, protect by dquot_hash_lock */
180         cfs_list_t dq_hash;
181         /** Protect the data in lustre_dquot */
182         cfs_mutex_t dq_mutex;
183         /** Use count */
184         cfs_atomic_t dq_refcnt;
185         /** Pointer of quota info it belongs to */
186         struct lustre_quota_info *dq_info;
187         /** Offset of dquot on disk */
188         loff_t dq_off;
189         /** ID this applies to (uid, gid) */
190         unsigned int dq_id;
191         /** Type fo quota (USRQUOTA, GRPQUOUTA) */
192         int dq_type;
193         /** See DQ_ in quota.h */
194         unsigned long dq_flags;
195         /** Diskquota usage */
196         struct lustre_mem_dqblk dq_dqb;
197 };
198
199 struct dquot_id {
200         cfs_list_t              di_link;
201         __u32                   di_id;
202         __u32                   di_flag;
203 };
204 /* set inode quota limitation on a quota uid/gid */
205 #define QI_SET                (1 << 30)
206 /* set block quota limitation on a quota uid/gid */
207 #define QB_SET                (1 << 31)
208
209 #define QFILE_CHK               1
210 #define QFILE_RD_INFO           2
211 #define QFILE_WR_INFO           3
212 #define QFILE_INIT_INFO         4
213 #define QFILE_RD_DQUOT          5
214 #define QFILE_WR_DQUOT          6
215 #define QFILE_CONVERT           7
216
217 /* admin quotafile operations */
218 int lustre_check_quota_file(struct lustre_quota_info *lqi, int type);
219 int lustre_read_quota_info(struct lustre_quota_info *lqi, int type);
220 int lustre_write_quota_info(struct lustre_quota_info *lqi, int type);
221 int lustre_read_dquot(struct lustre_dquot *dquot);
222 int lustre_commit_dquot(struct lustre_dquot *dquot);
223 int lustre_init_quota_info(struct lustre_quota_info *lqi, int type);
224 int lustre_get_qids(struct file *file, struct inode *inode, int type,
225                     cfs_list_t *list);
226 int lustre_quota_convert(struct lustre_quota_info *lqi, int type);
227
228 typedef int (*dqacq_handler_t) (struct obd_device * obd, struct qunit_data * qd,
229                                 int opc);
230
231 /* user quota is turned on on filter */
232 #define LQC_USRQUOTA_FLAG (1 << 0)
233 /* group quota is turned on on filter */
234 #define LQC_GRPQUOTA_FLAG (1 << 1)
235
236 #define UGQUOTA2LQC(id) ((Q_TYPEMATCH(id, USRQUOTA) ? LQC_USRQUOTA_FLAG : 0) | \
237                          (Q_TYPEMATCH(id, GRPQUOTA) ? LQC_GRPQUOTA_FLAG : 0))
238
239 struct lustre_quota_ctxt {
240         /** superblock this applies to */
241         struct super_block *lqc_sb;
242         /** obd_device_target for obt_rwsem */
243         struct obd_device_target *lqc_obt;
244         /** import used to send dqacq/dqrel RPC */
245         struct obd_import *lqc_import;
246         /** dqacq/dqrel RPC handler, only for quota master */
247         dqacq_handler_t lqc_handler;
248         /** quota flags */
249         unsigned long lqc_flags;
250         /** @{ */
251         unsigned long lqc_recovery:1,   /** Doing recovery */
252                       lqc_switch_qs:1,  /**
253                                          * the function of change qunit size
254                                          * 0:Off, 1:On
255                                          */
256                       lqc_valid:1,      /** this qctxt is valid or not */
257                       lqc_setup:1;      /**
258                                          * tell whether of not quota_type has
259                                          * been processed, so that the master
260                                          * knows when it can start processing
261                                          * incoming acq/rel quota requests
262                                          */
263         /** }@ */
264         /**
265          * original unit size of file quota and
266          * upper limitation for adjust file qunit
267          */
268         unsigned long lqc_iunit_sz;
269         /**
270          * Trigger dqacq when available file
271          * quota less than this value, trigger
272          * dqrel when available file quota
273          * more than this value + 1 iunit
274          */
275         unsigned long lqc_itune_sz;
276         /**
277          * original unit size of block quota and
278          * upper limitation for adjust block qunit
279          */
280         unsigned long lqc_bunit_sz;
281         /** See comment of lqc_itune_sz */
282         unsigned long lqc_btune_sz;
283         /** all lustre_qunit_size structures */
284         cfs_hash_t   *lqc_lqs_hash;
285
286         /** @{ */
287         /**
288          * the values below are relative to how master change its qunit sizes
289          */
290         /**
291          * this affects the boundary of
292          * shrinking and enlarging qunit size. default=4
293          */
294         unsigned long lqc_cqs_boundary_factor;
295         /** the least value of block qunit */
296         unsigned long lqc_cqs_least_bunit;
297         /** the least value of inode qunit */
298         unsigned long lqc_cqs_least_iunit;
299         /**
300          * when enlarging, qunit size will
301          * mutilple it; when shrinking,
302          * qunit size will divide it
303          */
304         unsigned long lqc_cqs_qs_factor;
305         /**
306          * avoid ping-pong effect of
307          * adjusting qunit size. How many
308          * seconds must be waited between
309          * enlarging and shinking qunit
310          */
311         /** }@ */
312         int           lqc_switch_seconds;
313         /**
314          * when blk qunit reaches this value,
315          * later write reqs from client should be sync b=16642
316          */
317         int           lqc_sync_blk;
318         /** guard lqc_imp_valid now */
319         cfs_spinlock_t lqc_lock;
320         /**
321          * when mds isn't connected, threads
322          * on osts who send the quota reqs
323          * with wait==1 will be put here b=14840
324          */
325         cfs_waitq_t   lqc_wait_for_qmaster;
326         struct proc_dir_entry *lqc_proc_dir;
327         /** lquota statistics */
328         struct lprocfs_stats  *lqc_stats;
329         /** the number of used hashed lqs */
330         cfs_atomic_t  lqc_lqs;
331         /** no lqs are in use */
332         cfs_waitq_t   lqc_lqs_waitq;
333 };
334
335 #define QUOTA_MASTER_READY(qctxt)   (qctxt)->lqc_setup = 1
336 #define QUOTA_MASTER_UNREADY(qctxt) (qctxt)->lqc_setup = 0
337
338 struct lustre_qunit_size {
339         cfs_hlist_node_t lqs_hash; /** the hash entry */
340         unsigned int lqs_id;        /** id of user/group */
341         unsigned long lqs_flags;    /** 31st bit is QB_SET, 30th bit is QI_SET
342                                      * other bits are same as LQUOTA_FLAGS_*
343                                      */
344         unsigned long lqs_iunit_sz; /** Unit size of file quota currently */
345         /**
346          * Trigger dqacq when available file quota
347          * less than this value, trigger dqrel
348          * when more than this value + 1 iunit
349          */
350         unsigned long lqs_itune_sz;
351         unsigned long lqs_bunit_sz; /** Unit size of block quota currently */
352         unsigned long lqs_btune_sz; /** See comment of lqs itune sz */
353         /** the blocks reached ost and don't finish */
354         unsigned long lqs_bwrite_pending;
355         /** the inodes reached mds and don't finish */
356         unsigned long lqs_iwrite_pending;
357         /** when inodes are allocated/released, this value will record it */
358         long long lqs_ino_rec;
359         /** when blocks are allocated/released, this value will record it */
360         long long lqs_blk_rec;
361         cfs_atomic_t lqs_refcount;
362         cfs_time_t lqs_last_bshrink;   /** time of last block shrink */
363         cfs_time_t lqs_last_ishrink;   /** time of last inode shrink */
364         cfs_spinlock_t lqs_lock;
365         unsigned long long lqs_key;    /** hash key */
366         struct lustre_quota_ctxt *lqs_ctxt; /** quota ctxt */
367 };
368
369 #define LQS_IS_GRP(lqs)      ((lqs)->lqs_flags & LQUOTA_FLAGS_GRP)
370 #define LQS_IS_ADJBLK(lqs)   ((lqs)->lqs_flags & LQUOTA_FLAGS_ADJBLK)
371 #define LQS_IS_ADJINO(lqs)   ((lqs)->lqs_flags & LQUOTA_FLAGS_ADJINO)
372 #define LQS_IS_RECOVERY(lqs) ((lqs)->lqs_flags & LQUOTA_FLAGS_RECOVERY)
373 #define LQS_IS_SETQUOTA(lqs) ((lqs)->lqs_flags & LQUOTA_FLAGS_SETQUOTA)
374
375 #define LQS_SET_GRP(lqs)       ((lqs)->lqs_flags |= LQUOTA_FLAGS_GRP)
376 #define LQS_SET_ADJBLK(lqs)    ((lqs)->lqs_flags |= LQUOTA_FLAGS_ADJBLK)
377 #define LQS_SET_ADJINO(lqs)    ((lqs)->lqs_flags |= LQUOTA_FLAGS_ADJINO)
378 #define LQS_SET_RECOVERY(lqs)  ((lqs)->lqs_flags |= LQUOTA_FLAGS_RECOVERY)
379 #define LQS_SET_SETQUOTA(lqs)  ((lqs)->lqs_flags |= LQUOTA_FLAGS_SETQUOTA)
380
381 #define LQS_CLEAR_RECOVERY(lqs)  ((lqs)->lqs_flags &= ~LQUOTA_FLAGS_RECOVERY)
382 #define LQS_CLEAR_SETQUOTA(lqs)  ((lqs)->lqs_flags &= ~LQUOTA_FLAGS_SETQUOTA)
383
384 /* In the hash for lustre_qunit_size, the key is decided by
385  * grp_or_usr and uid/gid, in here, I combine these two values,
386  * which will make comparing easier and more efficient */
387 #define LQS_KEY(is_grp, id)  ((is_grp ? 1ULL << 32: 0) + id)
388 #define LQS_KEY_ID(key)      (key & 0xffffffff)
389 #define LQS_KEY_GRP(key)     (key >> 32)
390
391 static inline void lqs_getref(struct lustre_qunit_size *lqs)
392 {
393         int count = cfs_atomic_inc_return(&lqs->lqs_refcount);
394
395         CDEBUG(D_INFO, "lqs=%p refcount %d\n", lqs, count);
396 }
397
398 static inline void lqs_putref(struct lustre_qunit_size *lqs)
399 {
400         int count = cfs_atomic_read(&lqs->lqs_refcount);
401
402         LASSERT(count > 0);
403         CDEBUG(D_INFO, "lqs=%p refcount %d\n", lqs, count - 1);
404
405         if (cfs_atomic_dec_and_test(&lqs->lqs_refcount)) {
406                 if (cfs_atomic_dec_and_test(&lqs->lqs_ctxt->lqc_lqs))
407                         cfs_waitq_signal(&lqs->lqs_ctxt->lqc_lqs_waitq);
408                 OBD_FREE_PTR(lqs);
409         }
410 }
411
412 #else
413
414 struct lustre_quota_info {
415 };
416
417 struct lustre_quota_ctxt {
418 };
419
420 #define QUOTA_MASTER_READY(qctxt)
421 #define QUOTA_MASTER_UNREADY(qctxt)
422
423 #endif  /* !__KERNEL__ */
424
425 #else
426
427 #define LL_DQUOT_OFF(sb) do {} while(0)
428
429 struct lustre_quota_info {
430 };
431
432 struct lustre_quota_ctxt {
433 };
434
435 #endif /* !HAVE_QUOTA_SUPPORT */
436
437 /* If the (quota limit < qunit * slave count), the slave which can't
438  * acquire qunit should set it's local limit as MIN_QLIMIT */
439 #define MIN_QLIMIT      1
440
441 struct quotacheck_thread_args {
442         struct obd_export   *qta_exp;   /** obd export */
443         struct obd_device   *qta_obd;   /** obd device */
444         struct obd_quotactl  qta_oqctl; /** obd_quotactl args */
445         struct super_block  *qta_sb;    /** obd super block */
446         cfs_semaphore_t     *qta_sem;   /** obt_quotachecking */
447 };
448
449 struct obd_trans_info;
450 typedef int (*quota_acquire)(struct obd_device *obd, const unsigned int id[],
451                              struct obd_trans_info *oti, int isblk);
452
453 typedef struct {
454         int (*quota_init) (void);
455         int (*quota_exit) (void);
456         int (*quota_setup) (struct obd_device *);
457         int (*quota_cleanup) (struct obd_device *);
458         /**
459          * For quota master, close admin quota files
460          */
461         int (*quota_fs_cleanup) (struct obd_device *);
462         int (*quota_ctl) (struct obd_device *, struct obd_export *,
463                           struct obd_quotactl *);
464         int (*quota_check) (struct obd_device *, struct obd_export *,
465                             struct obd_quotactl *);
466         int (*quota_recovery) (struct obd_device *);
467
468         /**
469          * For quota master/slave, adjust quota limit after fs operation
470          */
471         int (*quota_adjust) (struct obd_device *, const unsigned int[],
472                              const unsigned int[], int, int);
473
474         /**
475          * For quota slave, set import, trigger quota recovery,
476          * For quota master, set lqc_setup
477          */
478         int (*quota_setinfo) (struct obd_device *, void *);
479
480         /**
481          * For quota slave, clear import when relative import is invalid
482          */
483         int (*quota_clearinfo) (struct obd_export *, struct obd_device *);
484
485         /**
486          * For quota slave, set proper thread resoure capability
487          */
488         int (*quota_enforce) (struct obd_device *, unsigned int);
489
490         /**
491          * For quota slave, check whether specified uid/gid is over quota
492          */
493         int (*quota_getflag) (struct obd_device *, struct obdo *);
494
495 #ifdef __KERNEL__
496         /**
497          * For quota slave, acquire/release quota from master if needed
498          */
499         int (*quota_acquire) (struct obd_device *, const unsigned int [],
500                               struct obd_trans_info *, int);
501
502         /**
503          * For quota slave, check whether specified uid/gid's remaining quota
504          * can finish a block_write or inode_create rpc. It updates the pending
505          * record of block and inode, acquires quota if necessary
506          */
507         int (*quota_chkquota) (struct obd_device *, struct obd_export *,
508                                const unsigned int [], int [],
509                                int, quota_acquire, struct obd_trans_info *,
510                                int, struct inode *, int);
511
512         /**
513          * For quota client, the actions after the pending write is committed
514          */
515         int (*quota_pending_commit) (struct obd_device *, const unsigned int [],
516                                      int [], int);
517 #endif
518
519         /**
520          * For quota client, poll if the quota check done
521          */
522         int (*quota_poll_check) (struct obd_export *, struct if_quotacheck *);
523
524         /**
525          * For quota client, check whether specified uid/gid is over quota
526          */
527         int (*quota_chkdq) (struct client_obd *, const unsigned int []);
528
529         /**
530          * For quota client, set over quota flag for specifed uid/gid
531          */
532         int (*quota_setdq) (struct client_obd *, const unsigned int [],
533                             obd_flag, obd_flag);
534
535         /**
536          * For adjusting qunit size b=10600
537          */
538         int (*quota_adjust_qunit) (struct obd_export *exp,
539                                    struct quota_adjust_qunit *oqaq,
540                                    struct lustre_quota_ctxt *qctxt,
541                                    struct ptlrpc_request_set *rqset);
542
543 } quota_interface_t;
544
545 #define Q_COPY(out, in, member) (out)->member = (in)->member
546
547 #define QUOTA_OP(interface, op) interface->quota_ ## op
548
549 #define QUOTA_CHECK_OP(interface, op)                           \
550 do {                                                            \
551         if (!interface)                                         \
552                 RETURN(0);                                      \
553         if (!QUOTA_OP(interface, op)) {                         \
554                 CERROR("no quota operation: " #op "\n");        \
555                 RETURN(-EOPNOTSUPP);                            \
556         }                                                       \
557 } while(0)
558
559 static inline int lquota_init(quota_interface_t *interface)
560 {
561         int rc;
562         ENTRY;
563
564         QUOTA_CHECK_OP(interface, init);
565         rc = QUOTA_OP(interface, init)();
566         RETURN(rc);
567 }
568
569 static inline int lquota_exit(quota_interface_t *interface)
570 {
571         int rc;
572         ENTRY;
573
574         QUOTA_CHECK_OP(interface, exit);
575         rc = QUOTA_OP(interface, exit)();
576         RETURN(rc);
577 }
578
579 static inline int lquota_setup(quota_interface_t *interface,
580                                struct obd_device *obd)
581 {
582         int rc;
583         ENTRY;
584
585         QUOTA_CHECK_OP(interface, setup);
586         rc = QUOTA_OP(interface, setup)(obd);
587         RETURN(rc);
588 }
589
590 static inline int lquota_cleanup(quota_interface_t *interface,
591                                  struct obd_device *obd)
592 {
593         int rc;
594         ENTRY;
595
596         QUOTA_CHECK_OP(interface, cleanup);
597         rc = QUOTA_OP(interface, cleanup)(obd);
598         RETURN(rc);
599 }
600
601 static inline int lquota_fs_cleanup(quota_interface_t *interface,
602                                     struct obd_device *obd)
603 {
604         int rc;
605         ENTRY;
606
607         QUOTA_CHECK_OP(interface, fs_cleanup);
608         rc = QUOTA_OP(interface, fs_cleanup)(obd);
609         RETURN(rc);
610 }
611
612 static inline int lquota_recovery(quota_interface_t *interface,
613                                   struct obd_device *obd)
614 {
615         int rc;
616         ENTRY;
617
618         QUOTA_CHECK_OP(interface, recovery);
619         rc = QUOTA_OP(interface, recovery)(obd);
620         RETURN(rc);
621 }
622
623 static inline int lquota_check(quota_interface_t *interface,
624                                struct obd_device *obd,
625                                struct obd_export *exp,
626                                struct obd_quotactl *oqctl)
627 {
628         int rc;
629         ENTRY;
630
631         QUOTA_CHECK_OP(interface, check);
632         rc = QUOTA_OP(interface, check)(obd, exp, oqctl);
633         RETURN(rc);
634 }
635
636 static inline int lquota_ctl(quota_interface_t *interface,
637                              struct obd_device *obd,
638                              struct obd_quotactl *oqctl)
639 {
640         int rc;
641         ENTRY;
642
643         QUOTA_CHECK_OP(interface, ctl);
644         rc = QUOTA_OP(interface, ctl)(obd, NULL, oqctl);
645         RETURN(rc);
646 }
647
648 static inline int lquota_adjust(quota_interface_t *interface,
649                                 struct obd_device *obd,
650                                 const unsigned int qcids[],
651                                 const unsigned int qpids[],
652                                 int rc, int opc)
653 {
654         int ret;
655         ENTRY;
656
657         QUOTA_CHECK_OP(interface, adjust);
658         ret = QUOTA_OP(interface, adjust)(obd, qcids, qpids, rc, opc);
659         RETURN(ret);
660 }
661
662 static inline int lquota_setinfo(quota_interface_t *interface,
663                                  struct obd_device *obd,
664                                  void *data)
665 {
666         int rc;
667         ENTRY;
668
669         QUOTA_CHECK_OP(interface, setinfo);
670         rc = QUOTA_OP(interface, setinfo)(obd, data);
671         RETURN(rc);
672 }
673
674 static inline int lquota_clearinfo(quota_interface_t *interface,
675                                    struct obd_export *exp,
676                                    struct obd_device *obd)
677 {
678         int rc;
679         ENTRY;
680
681         QUOTA_CHECK_OP(interface, clearinfo);
682         rc = QUOTA_OP(interface, clearinfo)(exp, obd);
683         RETURN(rc);
684 }
685
686 static inline int lquota_enforce(quota_interface_t *interface,
687                                  struct obd_device *obd,
688                                  unsigned int ignore)
689 {
690         int rc;
691         ENTRY;
692
693         QUOTA_CHECK_OP(interface, enforce);
694         rc = QUOTA_OP(interface, enforce)(obd, ignore);
695         RETURN(rc);
696 }
697
698 static inline int lquota_getflag(quota_interface_t *interface,
699                                  struct obd_device *obd, struct obdo *oa)
700 {
701         int rc;
702         ENTRY;
703
704         QUOTA_CHECK_OP(interface, getflag);
705         rc = QUOTA_OP(interface, getflag)(obd, oa);
706         RETURN(rc);
707 }
708
709 #ifdef __KERNEL__
710 static inline int lquota_chkquota(quota_interface_t *interface,
711                                   struct obd_device *obd,
712                                   struct obd_export *exp,
713                                   const unsigned int id[], int pending[],
714                                   int count, struct obd_trans_info *oti,
715                                   int isblk, void *data, int frags)
716 {
717         int rc;
718         ENTRY;
719
720         QUOTA_CHECK_OP(interface, chkquota);
721         QUOTA_CHECK_OP(interface, acquire);
722         rc = QUOTA_OP(interface, chkquota)(obd, exp, id, pending, count,
723                                            QUOTA_OP(interface, acquire), oti,
724                                            isblk, (struct inode *)data, frags);
725         RETURN(rc);
726 }
727
728 static inline int lquota_pending_commit(quota_interface_t *interface,
729                                         struct obd_device *obd,
730                                         const unsigned int id[],
731                                         int pending[], int isblk)
732 {
733         int rc;
734         ENTRY;
735
736         QUOTA_CHECK_OP(interface, pending_commit);
737         rc = QUOTA_OP(interface, pending_commit)(obd, id, pending, isblk);
738         RETURN(rc);
739 }
740 #endif
741
742 #ifndef __KERNEL__
743 #ifndef MAXQUOTAS
744 #define MAXQUOTAS 2
745 #endif
746
747 #ifndef USRQUOTA
748 #define USRQUOTA 0
749 #endif
750
751 #ifndef GRPQUOTA
752 #define GRPQUOTA 1
753 #endif
754
755 #endif
756
757 #define LUSTRE_ADMIN_QUOTAFILES_V2 {\
758         "admin_quotafile_v2.usr",       /** user admin quotafile */\
759         "admin_quotafile_v2.grp"        /** group admin quotafile */\
760 }
761
762 /*
763  * Definitions of structures for vfsv0 quota format
764  * Source linux/fs/quota/quotaio_v2.h
765  *
766  * The following definitions are normally found in private kernel headers.
767  * However, some sites build Lustre against kernel development headers rather
768  * than than full kernel source, so we provide them here for compatibility.
769  */
770 #ifdef __KERNEL__
771 # if !defined(HAVE_QUOTAIO_H) && !defined(HAVE_FS_QUOTA_QUOTAIO_H) && \
772      !defined(HAVE_FS_QUOTAIO_H)
773
774 #include <linux/types.h>
775 #include <linux/quota.h>
776
777 #define V2_INITQMAGICS {\
778         0xd9c01f11,     /* USRQUOTA */\
779         0xd9c01927      /* GRPQUOTA */\
780 }
781
782 /* Header with type and version specific information */
783 struct v2_disk_dqinfo {
784         __le32 dqi_bgrace;      /* Time before block soft limit becomes hard limit */
785         __le32 dqi_igrace;      /* Time before inode soft limit becomes hard limit */
786         __le32 dqi_flags;       /* Flags for quotafile (DQF_*) */
787         __le32 dqi_blocks;      /* Number of blocks in file */
788         __le32 dqi_free_blk;    /* Number of first free block in the list */
789         __le32 dqi_free_entry;  /* Number of block with at least one free entry */
790 };
791
792 /* First generic header */
793 struct v2_disk_dqheader {
794         __le32 dqh_magic;       /* Magic number identifying file */
795         __le32 dqh_version;     /* File version */
796 };
797 #define V2_DQINFOOFF    sizeof(struct v2_disk_dqheader) /* Offset of info header in file */
798 #define QT_TREEOFF      1                               /* Offset of tree in file in blocks */
799 #define V2_DQTREEOFF    QT_TREEOFF
800
801 # endif /* !defined(HAVE_QUOTAIO_V1_H) ... */
802 #endif  /* __KERNEL__ */
803
804 /** @} quota */
805
806 #endif /* _LUSTRE_QUOTA_H */