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