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 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
83 int lustre_check_quota_file(struct lustre_quota_info *lqi, int type);
84 int lustre_read_quota_info(struct lustre_quota_info *lqi, int type);
85 int lustre_write_quota_info(struct lustre_quota_info *lqi, int type);
86 int lustre_read_dquot(struct lustre_dquot *dquot);
87 int lustre_commit_dquot(struct lustre_dquot *dquot);
88 int lustre_init_quota_info(struct lustre_quota_info *lqi, int type);
89 int lustre_get_qids(struct file *file, struct inode *inode, int type,
90 struct list_head *list);
97 static inline int lustre_check_quota_file(struct lustre_quota_info *lqi,
102 static inline int lustre_read_quota_info(struct lustre_quota_info *lqi,
107 static inline int lustre_write_quota_info(struct lustre_quota_info *lqi,
112 static inline int lustre_read_dquot(struct lustre_dquot *dquot)
116 static inline int lustre_commit_dquot(struct lustre_dquot *dquot)
120 static inline int lustre_init_quota_info(struct lustre_quota_info *lqi,
125 #endif /* KERNEL_VERSION(2,5,0) */
127 #define LL_DQUOT_OFF(sb) DQUOT_OFF(sb)
129 typedef int (*dqacq_handler_t) (struct obd_device * obd, struct qunit_data * qd,
131 struct lustre_quota_ctxt {
132 struct super_block *lqc_sb; /* superblock this applies to */
133 struct obd_import *lqc_import; /* import used to send dqacq/dqrel RPC */
134 dqacq_handler_t lqc_handler; /* dqacq/dqrel RPC handler, only for quota master */
135 unsigned long lqc_recovery:1, /* Doing recovery */
136 lqc_atype:2, /* Turn on user/group quota at setup automatically,
137 * 0: none, 1: user quota, 2: group quota, 3: both */
138 lqc_status:1; /* Quota status. 0:Off, 1:On */
139 spinlock_t lqc_lock; /* guard lqc_imp_valid now */
140 unsigned long lqc_iunit_sz; /* Unit size of file quota */
141 unsigned long lqc_itune_sz; /* Trigger dqacq when available file quota less than
142 * this value, trigger dqrel when available file quota
143 * more than this value + 1 iunit */
144 unsigned long lqc_bunit_sz; /* Unit size of block quota */
145 unsigned long lqc_btune_sz; /* See comment of lqc_itune_sz */
146 unsigned long lqc_limit_sz; /* When remaining quota on ost is less
147 * than this value, ost will request
153 struct lustre_quota_info {
156 struct lustre_quota_ctxt {
159 #endif /* !__KERNEL__ */
163 #define LL_DQUOT_OFF(sb) do {} while(0)
165 struct lustre_quota_info {
168 struct lustre_quota_ctxt {
171 #endif /* !HAVE_QUOTA_SUPPORT */
173 /* If the (quota limit < qunit * slave count), the slave which can't
174 * acquire qunit should set it's local limit as MIN_QLIMIT */
177 struct quotacheck_thread_args {
178 struct obd_export *qta_exp; /* obd export */
179 struct obd_quotactl qta_oqctl; /* obd_quotactl args */
180 struct super_block *qta_sb; /* obd super block */
181 atomic_t *qta_sem; /* obt_quotachecking */
185 int (*quota_init) (void);
186 int (*quota_exit) (void);
187 int (*quota_setup) (struct obd_device *);
188 int (*quota_cleanup) (struct obd_device *);
189 /* For quota master, close admin quota files */
190 int (*quota_fs_cleanup) (struct obd_device *);
191 int (*quota_ctl) (struct obd_export *, struct obd_quotactl *);
192 int (*quota_check) (struct obd_export *, struct obd_quotactl *);
193 int (*quota_recovery) (struct obd_device *);
195 /* For quota master/slave, adjust quota limit after fs operation */
196 int (*quota_adjust) (struct obd_device *, unsigned int[],
197 unsigned int[], int, int);
199 /* For quota slave, set import, trigger quota recovery */
200 int (*quota_setinfo) (struct obd_export *, struct obd_device *);
202 /* For quota slave, clear import when relative import is invalid */
203 int (*quota_clearinfo) (struct obd_export *, struct obd_device *);
205 /* For quota slave, set proper thread resoure capability */
206 int (*quota_enforce) (struct obd_device *, unsigned int);
208 /* For quota slave, check whether specified uid/gid is over quota */
209 int (*quota_getflag) (struct obd_device *, struct obdo *);
211 /* For quota slave, acquire/release quota from master if needed */
212 int (*quota_acquire) (struct obd_device *, unsigned int, unsigned int);
214 /* For quota slave, check whether specified uid/gid's remaining quota
215 * can finish a write rpc */
216 int (*quota_chkquota) (struct obd_device *, unsigned int, unsigned int,
219 /* For quota client, poll if the quota check done */
220 int (*quota_poll_check) (struct obd_export *, struct if_quotacheck *);
222 /* For quota client, check whether specified uid/gid is over quota */
223 int (*quota_chkdq) (struct client_obd *, unsigned int, unsigned int);
225 /* For quota client, set over quota flag for specifed uid/gid */
226 int (*quota_setdq) (struct client_obd *, unsigned int, unsigned int,
230 #define Q_COPY(out, in, member) (out)->member = (in)->member
232 #define QUOTA_OP(interface, op) interface->quota_ ## op
234 #define QUOTA_CHECK_OP(interface, op) \
238 if (!QUOTA_OP(interface, op)) { \
239 CERROR("no quota operation: " #op "\n"); \
240 RETURN(-EOPNOTSUPP); \
244 static inline int lquota_init(quota_interface_t *interface)
249 QUOTA_CHECK_OP(interface, init);
250 rc = QUOTA_OP(interface, init)();
254 static inline int lquota_exit(quota_interface_t *interface)
259 QUOTA_CHECK_OP(interface, exit);
260 rc = QUOTA_OP(interface, exit)();
264 static inline int lquota_setup(quota_interface_t *interface,
265 struct obd_device *obd)
270 QUOTA_CHECK_OP(interface, setup);
271 rc = QUOTA_OP(interface, setup)(obd);
275 static inline int lquota_cleanup(quota_interface_t *interface,
276 struct obd_device *obd)
281 QUOTA_CHECK_OP(interface, cleanup);
282 rc = QUOTA_OP(interface, cleanup)(obd);
286 static inline int lquota_fs_cleanup(quota_interface_t *interface,
287 struct obd_device *obd)
292 QUOTA_CHECK_OP(interface, fs_cleanup);
293 rc = QUOTA_OP(interface, fs_cleanup)(obd);
297 static inline int lquota_recovery(quota_interface_t *interface,
298 struct obd_device *obd)
303 QUOTA_CHECK_OP(interface, recovery);
304 rc = QUOTA_OP(interface, recovery)(obd);
308 static inline int lquota_adjust(quota_interface_t *interface,
309 struct obd_device *obd,
310 unsigned int qcids[],
311 unsigned int qpids[],
317 QUOTA_CHECK_OP(interface, adjust);
318 ret = QUOTA_OP(interface, adjust)(obd, qcids, qpids, rc, opc);
322 static inline int lquota_chkdq(quota_interface_t *interface,
323 struct client_obd *cli,
324 unsigned int uid, unsigned int gid)
329 QUOTA_CHECK_OP(interface, chkdq);
330 rc = QUOTA_OP(interface, chkdq)(cli, uid, gid);
334 static inline int lquota_setdq(quota_interface_t *interface,
335 struct client_obd *cli,
336 unsigned int uid, unsigned int gid,
337 obd_flag valid, obd_flag flags)
342 QUOTA_CHECK_OP(interface, setdq);
343 rc = QUOTA_OP(interface, setdq)(cli, uid, gid, valid, flags);
347 static inline int lquota_poll_check(quota_interface_t *interface,
348 struct obd_export *exp,
349 struct if_quotacheck *qchk)
354 QUOTA_CHECK_OP(interface, poll_check);
355 rc = QUOTA_OP(interface, poll_check)(exp, qchk);
360 static inline int lquota_setinfo(quota_interface_t *interface,
361 struct obd_export *exp,
362 struct obd_device *obd)
367 QUOTA_CHECK_OP(interface, setinfo);
368 rc = QUOTA_OP(interface, setinfo)(exp, obd);
372 static inline int lquota_clearinfo(quota_interface_t *interface,
373 struct obd_export *exp,
374 struct obd_device *obd)
379 QUOTA_CHECK_OP(interface, clearinfo);
380 rc = QUOTA_OP(interface, clearinfo)(exp, obd);
384 static inline int lquota_enforce(quota_interface_t *interface,
385 struct obd_device *obd,
391 QUOTA_CHECK_OP(interface, enforce);
392 rc = QUOTA_OP(interface, enforce)(obd, ignore);
396 static inline int lquota_getflag(quota_interface_t *interface,
397 struct obd_device *obd, struct obdo *oa)
402 QUOTA_CHECK_OP(interface, getflag);
403 rc = QUOTA_OP(interface, getflag)(obd, oa);
407 static inline int lquota_acquire(quota_interface_t *interface,
408 struct obd_device *obd,
409 unsigned int uid, unsigned int gid)
414 QUOTA_CHECK_OP(interface, acquire);
415 rc = QUOTA_OP(interface, acquire)(obd, uid, gid);
419 static inline int lquota_chkquota(quota_interface_t *interface,
420 struct obd_device *obd,
421 unsigned int uid, unsigned int gid,
427 QUOTA_CHECK_OP(interface, chkquota);
428 rc = QUOTA_OP(interface, chkquota)(obd, uid, gid, npage);
432 int lprocfs_rd_bunit(char *page, char **start, off_t off, int count,
433 int *eof, void *data);
434 int lprocfs_rd_iunit(char *page, char **start, off_t off, int count,
435 int *eof, void *data);
436 int lprocfs_wr_bunit(struct file *file, const char *buffer,
437 unsigned long count, void *data);
438 int lprocfs_wr_iunit(struct file *file, const char *buffer,
439 unsigned long count, void *data);
440 int lprocfs_rd_btune(char *page, char **start, off_t off, int count,
441 int *eof, void *data);
442 int lprocfs_rd_itune(char *page, char **start, off_t off, int count,
443 int *eof, void *data);
444 int lprocfs_wr_btune(struct file *file, const char *buffer,
445 unsigned long count, void *data);
446 int lprocfs_wr_itune(struct file *file, const char *buffer,
447 unsigned long count, void *data);
448 int lprocfs_rd_type(char *page, char **start, off_t off, int count,
449 int *eof, void *data);
450 int lprocfs_wr_type(struct file *file, const char *buffer,
451 unsigned long count, void *data);
452 int lprocfs_filter_rd_limit(char *page, char **start, off_t off, int count,
453 int *eof, void *data);
454 int lprocfs_filter_wr_limit(struct file *file, const char *buffer,
455 unsigned long count, void *data);
459 extern quota_interface_t osc_quota_interface;
460 extern quota_interface_t mdc_quota_interface;
461 extern quota_interface_t lov_quota_interface;
464 #endif /* _LUSTRE_QUOTA_H */