1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 #ifndef _LUSTRE_QUOTA_H
5 #define _LUSTRE_QUOTA_H
8 #include <linux/lustre_quota.h>
9 #elif defined(__APPLE__)
10 #include <darwin/lustre_quota.h>
11 #elif defined(__WINNT__)
12 #include <winnt/lustre_quota.h>
14 #error Unsupported operating system.
17 #include <lustre/lustre_idl.h>
18 #include <lustre_net.h>
28 #ifdef HAVE_QUOTA_SUPPORT
32 /* structures to access admin quotafile */
33 struct lustre_mem_dqinfo {
34 unsigned int dqi_bgrace;
35 unsigned int dqi_igrace;
36 unsigned long dqi_flags;
37 unsigned int dqi_blocks;
38 unsigned int dqi_free_blk;
39 unsigned int dqi_free_entry;
42 struct lustre_quota_info {
43 struct file *qi_files[MAXQUOTAS];
44 struct lustre_mem_dqinfo qi_info[MAXQUOTAS];
47 #define DQ_STATUS_AVAIL 0x0 /* Available dquot */
48 #define DQ_STATUS_SET 0x01 /* Sombody is setting dquot */
49 #define DQ_STATUS_RECOVERY 0x02 /* dquot is in recovery */
52 /* Hash list in memory, protect by dquot_hash_lock */
53 struct list_head dq_hash;
54 /* Protect the data in lustre_dquot */
55 struct semaphore dq_sem;
58 /* Pointer of quota info it belongs to */
59 struct lustre_quota_info *dq_info;
61 loff_t dq_off; /* Offset of dquot on disk */
62 unsigned int dq_id; /* ID this applies to (uid, gid) */
63 int dq_type; /* Type fo quota (USRQUOTA, GRPQUOUTA) */
64 unsigned short dq_status; /* See DQ_STATUS_ */
65 unsigned long dq_flags; /* See DQ_ in quota.h */
66 struct mem_dqblk dq_dqb; /* Diskquota usage */
70 struct list_head di_link;
75 #define QFILE_RD_INFO 2
76 #define QFILE_WR_INFO 3
77 #define QFILE_INIT_INFO 4
78 #define QFILE_RD_DQUOT 5
79 #define QFILE_WR_DQUOT 6
81 /* admin quotafile operations */
82 int lustre_check_quota_file(struct lustre_quota_info *lqi, int type);
83 int lustre_read_quota_info(struct lustre_quota_info *lqi, int type);
84 int lustre_write_quota_info(struct lustre_quota_info *lqi, int type);
85 int lustre_read_dquot(struct lustre_dquot *dquot);
86 int lustre_commit_dquot(struct lustre_dquot *dquot);
87 int lustre_init_quota_info(struct lustre_quota_info *lqi, int type);
88 int lustre_get_qids(struct file *file, struct inode *inode, int type,
89 struct list_head *list);
91 #define LL_DQUOT_OFF(sb) DQUOT_OFF(sb)
93 typedef int (*dqacq_handler_t) (struct obd_device * obd, struct qunit_data * qd,
95 struct lustre_quota_ctxt {
96 struct super_block *lqc_sb; /* superblock this applies to */
97 struct obd_import *lqc_import; /* import used to send dqacq/dqrel RPC */
98 dqacq_handler_t lqc_handler; /* dqacq/dqrel RPC handler, only for quota master */
99 unsigned long lqc_recovery:1, /* Doing recovery */
100 lqc_atype:2, /* Turn on user/group quota at setup automatically,
101 * 0: none, 1: user quota, 2: group quota, 3: both */
102 lqc_status:1; /* Quota status. 0:Off, 1:On */
103 unsigned long lqc_iunit_sz; /* Unit size of file quota */
104 unsigned long lqc_itune_sz; /* Trigger dqacq when available file quota less than
105 * this value, trigger dqrel when available file quota
106 * more than this value + 1 iunit */
107 unsigned long lqc_bunit_sz; /* Unit size of block quota */
108 unsigned long lqc_btune_sz; /* See comment of lqc_itune_sz */
113 struct lustre_quota_info {
116 struct lustre_quota_ctxt {
119 #endif /* !__KERNEL__ */
123 #define LL_DQUOT_OFF(sb) do {} while(0)
125 struct lustre_quota_info {
128 struct lustre_quota_ctxt {
131 #endif /* !HAVE_QUOTA_SUPPORT */
133 /* If the (quota limit < qunit * slave count), the slave which can't
134 * acquire qunit should set it's local limit as MIN_QLIMIT */
137 struct quotacheck_thread_args {
138 struct obd_export *qta_exp; /* obd export */
139 struct obd_quotactl qta_oqctl; /* obd_quotactl args */
140 struct super_block *qta_sb; /* obd super block */
141 atomic_t *qta_sem; /* obt_quotachecking */
145 int (*quota_init) (void);
146 int (*quota_exit) (void);
147 int (*quota_setup) (struct obd_device *);
148 int (*quota_cleanup) (struct obd_device *);
149 /* For quota master, close admin quota files */
150 int (*quota_fs_cleanup) (struct obd_device *);
151 int (*quota_ctl) (struct obd_export *, struct obd_quotactl *);
152 int (*quota_check) (struct obd_export *, struct obd_quotactl *);
153 int (*quota_recovery) (struct obd_device *);
155 /* For quota master/slave, adjust quota limit after fs operation */
156 int (*quota_adjust) (struct obd_device *, unsigned int[],
157 unsigned int[], int, int);
159 /* For quota slave, set import, trigger quota recovery */
160 int (*quota_setinfo) (struct obd_export *, struct obd_device *);
162 /* For quota slave, set proper thread resoure capability */
163 int (*quota_enforce) (struct obd_device *, unsigned int);
165 /* For quota slave, check whether specified uid/gid is over quota */
166 int (*quota_getflag) (struct obd_device *, struct obdo *);
168 /* For quota slave, acquire/release quota from master if needed */
169 int (*quota_acquire) (struct obd_device *, unsigned int, unsigned int);
171 /* For quota slave, check whether specified uid/gid's remaining quota
172 * can finish a write rpc */
173 int (*quota_chkquota) (struct obd_device *, unsigned int, unsigned int,
176 /* For quota client, poll if the quota check done */
177 int (*quota_poll_check) (struct obd_export *, struct if_quotacheck *);
179 /* For quota client, check whether specified uid/gid is over quota */
180 int (*quota_chkdq) (struct client_obd *, unsigned int, unsigned int);
182 /* For quota client, set over quota flag for specifed uid/gid */
183 int (*quota_setdq) (struct client_obd *, unsigned int, unsigned int,
187 #define Q_COPY(out, in, member) (out)->member = (in)->member
189 #define QUOTA_OP(interface, op) interface->quota_ ## op
191 #define QUOTA_CHECK_OP(interface, op) \
195 if (!QUOTA_OP(interface, op)) { \
196 CERROR("no quota operation: " #op "\n"); \
197 RETURN(-EOPNOTSUPP); \
201 static inline int lquota_init(quota_interface_t *interface)
206 QUOTA_CHECK_OP(interface, init);
207 rc = QUOTA_OP(interface, init)();
211 static inline int lquota_exit(quota_interface_t *interface)
216 QUOTA_CHECK_OP(interface, exit);
217 rc = QUOTA_OP(interface, exit)();
221 static inline int lquota_setup(quota_interface_t *interface,
222 struct obd_device *obd)
227 QUOTA_CHECK_OP(interface, setup);
228 rc = QUOTA_OP(interface, setup)(obd);
232 static inline int lquota_cleanup(quota_interface_t *interface,
233 struct obd_device *obd)
238 QUOTA_CHECK_OP(interface, cleanup);
239 rc = QUOTA_OP(interface, cleanup)(obd);
243 static inline int lquota_fs_cleanup(quota_interface_t *interface,
244 struct obd_device *obd)
249 QUOTA_CHECK_OP(interface, fs_cleanup);
250 rc = QUOTA_OP(interface, fs_cleanup)(obd);
254 static inline int lquota_recovery(quota_interface_t *interface,
255 struct obd_device *obd)
260 QUOTA_CHECK_OP(interface, recovery);
261 rc = QUOTA_OP(interface, recovery)(obd);
265 static inline int lquota_adjust(quota_interface_t *interface,
266 struct obd_device *obd,
267 unsigned int qcids[],
268 unsigned int qpids[],
274 QUOTA_CHECK_OP(interface, adjust);
275 ret = QUOTA_OP(interface, adjust)(obd, qcids, qpids, rc, opc);
279 static inline int lquota_chkdq(quota_interface_t *interface,
280 struct client_obd *cli,
281 unsigned int uid, unsigned int gid)
286 QUOTA_CHECK_OP(interface, chkdq);
287 rc = QUOTA_OP(interface, chkdq)(cli, uid, gid);
291 static inline int lquota_setdq(quota_interface_t *interface,
292 struct client_obd *cli,
293 unsigned int uid, unsigned int gid,
294 obd_flag valid, obd_flag flags)
299 QUOTA_CHECK_OP(interface, setdq);
300 rc = QUOTA_OP(interface, setdq)(cli, uid, gid, valid, flags);
304 static inline int lquota_poll_check(quota_interface_t *interface,
305 struct obd_export *exp,
306 struct if_quotacheck *qchk)
311 QUOTA_CHECK_OP(interface, poll_check);
312 rc = QUOTA_OP(interface, poll_check)(exp, qchk);
317 static inline int lquota_setinfo(quota_interface_t *interface,
318 struct obd_export *exp,
319 struct obd_device *obd)
324 QUOTA_CHECK_OP(interface, setinfo);
325 rc = QUOTA_OP(interface, setinfo)(exp, obd);
329 static inline int lquota_enforce(quota_interface_t *interface,
330 struct obd_device *obd,
336 QUOTA_CHECK_OP(interface, enforce);
337 rc = QUOTA_OP(interface, enforce)(obd, ignore);
341 static inline int lquota_getflag(quota_interface_t *interface,
342 struct obd_device *obd, struct obdo *oa)
347 QUOTA_CHECK_OP(interface, getflag);
348 rc = QUOTA_OP(interface, getflag)(obd, oa);
352 static inline int lquota_acquire(quota_interface_t *interface,
353 struct obd_device *obd,
354 unsigned int uid, unsigned int gid)
359 QUOTA_CHECK_OP(interface, acquire);
360 rc = QUOTA_OP(interface, acquire)(obd, uid, gid);
364 static inline int lquota_chkquota(quota_interface_t *interface,
365 struct obd_device *obd,
366 unsigned int uid, unsigned int gid,
372 QUOTA_CHECK_OP(interface, chkquota);
373 rc = QUOTA_OP(interface, chkquota)(obd, uid, gid, npage);
377 int lprocfs_rd_bunit(char *page, char **start, off_t off, int count,
378 int *eof, void *data);
379 int lprocfs_rd_iunit(char *page, char **start, off_t off, int count,
380 int *eof, void *data);
381 int lprocfs_wr_bunit(struct file *file, const char *buffer,
382 unsigned long count, void *data);
383 int lprocfs_wr_iunit(struct file *file, const char *buffer,
384 unsigned long count, void *data);
385 int lprocfs_rd_btune(char *page, char **start, off_t off, int count,
386 int *eof, void *data);
387 int lprocfs_rd_itune(char *page, char **start, off_t off, int count,
388 int *eof, void *data);
389 int lprocfs_wr_btune(struct file *file, const char *buffer,
390 unsigned long count, void *data);
391 int lprocfs_wr_itune(struct file *file, const char *buffer,
392 unsigned long count, void *data);
393 int lprocfs_rd_type(char *page, char **start, off_t off, int count,
394 int *eof, void *data);
395 int lprocfs_wr_type(struct file *file, const char *buffer,
396 unsigned long count, void *data);
399 extern quota_interface_t osc_quota_interface;
400 extern quota_interface_t mdc_quota_interface;
401 extern quota_interface_t lov_quota_interface;
404 #endif /* _LUSTRE_QUOTA_H */