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