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 unsigned long lqc_iunit_sz; /* Unit size of file quota */
140 unsigned long lqc_itune_sz; /* Trigger dqacq when available file quota less than
141 * this value, trigger dqrel when available file quota
142 * more than this value + 1 iunit */
143 unsigned long lqc_bunit_sz; /* Unit size of block quota */
144 unsigned long lqc_btune_sz; /* See comment of lqc_itune_sz */
149 struct lustre_quota_info {
152 struct lustre_quota_ctxt {
155 #endif /* !__KERNEL__ */
159 #define LL_DQUOT_OFF(sb) do {} while(0)
161 struct lustre_quota_info {
164 struct lustre_quota_ctxt {
167 #endif /* !HAVE_QUOTA_SUPPORT */
169 /* If the (quota limit < qunit * slave count), the slave which can't
170 * acquire qunit should set it's local limit as MIN_QLIMIT */
173 struct quotacheck_thread_args {
174 struct obd_export *qta_exp; /* obd export */
175 struct obd_quotactl qta_oqctl; /* obd_quotactl args */
176 struct super_block *qta_sb; /* obd super block */
177 atomic_t *qta_sem; /* obt_quotachecking */
181 int (*quota_init) (void);
182 int (*quota_exit) (void);
183 int (*quota_setup) (struct obd_device *);
184 int (*quota_cleanup) (struct obd_device *);
185 /* For quota master, close admin quota files */
186 int (*quota_fs_cleanup) (struct obd_device *);
187 int (*quota_ctl) (struct obd_export *, struct obd_quotactl *);
188 int (*quota_check) (struct obd_export *, struct obd_quotactl *);
189 int (*quota_recovery) (struct obd_device *);
191 /* For quota master/slave, adjust quota limit after fs operation */
192 int (*quota_adjust) (struct obd_device *, unsigned int[],
193 unsigned int[], int, int);
195 /* For quota slave, set import, trigger quota recovery */
196 int (*quota_setinfo) (struct obd_export *, struct obd_device *);
198 /* For quota slave, set proper thread resoure capability */
199 int (*quota_enforce) (struct obd_device *, unsigned int);
201 /* For quota slave, check whether specified uid/gid is over quota */
202 int (*quota_getflag) (struct obd_device *, struct obdo *);
204 /* For quota slave, acquire/release quota from master if needed */
205 int (*quota_acquire) (struct obd_device *, unsigned int, unsigned int);
207 /* For quota client, poll if the quota check done */
208 int (*quota_poll_check) (struct obd_export *, struct if_quotacheck *);
210 /* For quota client, check whether specified uid/gid is over quota */
211 int (*quota_chkdq) (struct client_obd *, unsigned int, unsigned int);
213 /* For quota client, set over quota flag for specifed uid/gid */
214 int (*quota_setdq) (struct client_obd *, unsigned int, unsigned int,
218 #define Q_COPY(out, in, member) (out)->member = (in)->member
220 #define QUOTA_OP(interface, op) interface->quota_ ## op
222 #define QUOTA_CHECK_OP(interface, op) \
226 if (!QUOTA_OP(interface, op)) { \
227 CERROR("no quota operation: " #op "\n"); \
228 RETURN(-EOPNOTSUPP); \
232 static inline int lquota_init(quota_interface_t *interface)
237 QUOTA_CHECK_OP(interface, init);
238 rc = QUOTA_OP(interface, init)();
242 static inline int lquota_exit(quota_interface_t *interface)
247 QUOTA_CHECK_OP(interface, exit);
248 rc = QUOTA_OP(interface, exit)();
252 static inline int lquota_setup(quota_interface_t *interface,
253 struct obd_device *obd)
258 QUOTA_CHECK_OP(interface, setup);
259 rc = QUOTA_OP(interface, setup)(obd);
263 static inline int lquota_cleanup(quota_interface_t *interface,
264 struct obd_device *obd)
269 QUOTA_CHECK_OP(interface, cleanup);
270 rc = QUOTA_OP(interface, cleanup)(obd);
274 static inline int lquota_fs_cleanup(quota_interface_t *interface,
275 struct obd_device *obd)
280 QUOTA_CHECK_OP(interface, fs_cleanup);
281 rc = QUOTA_OP(interface, fs_cleanup)(obd);
285 static inline int lquota_recovery(quota_interface_t *interface,
286 struct obd_device *obd)
291 QUOTA_CHECK_OP(interface, recovery);
292 rc = QUOTA_OP(interface, recovery)(obd);
296 static inline int lquota_adjust(quota_interface_t *interface,
297 struct obd_device *obd,
298 unsigned int qcids[],
299 unsigned int qpids[],
305 QUOTA_CHECK_OP(interface, adjust);
306 ret = QUOTA_OP(interface, adjust)(obd, qcids, qpids, rc, opc);
310 static inline int lquota_chkdq(quota_interface_t *interface,
311 struct client_obd *cli,
312 unsigned int uid, unsigned int gid)
317 QUOTA_CHECK_OP(interface, chkdq);
318 rc = QUOTA_OP(interface, chkdq)(cli, uid, gid);
322 static inline int lquota_setdq(quota_interface_t *interface,
323 struct client_obd *cli,
324 unsigned int uid, unsigned int gid,
325 obd_flag valid, obd_flag flags)
330 QUOTA_CHECK_OP(interface, setdq);
331 rc = QUOTA_OP(interface, setdq)(cli, uid, gid, valid, flags);
335 static inline int lquota_poll_check(quota_interface_t *interface,
336 struct obd_export *exp,
337 struct if_quotacheck *qchk)
342 QUOTA_CHECK_OP(interface, poll_check);
343 rc = QUOTA_OP(interface, poll_check)(exp, qchk);
348 static inline int lquota_setinfo(quota_interface_t *interface,
349 struct obd_export *exp,
350 struct obd_device *obd)
355 QUOTA_CHECK_OP(interface, setinfo);
356 rc = QUOTA_OP(interface, setinfo)(exp, obd);
360 static inline int lquota_enforce(quota_interface_t *interface,
361 struct obd_device *obd,
367 QUOTA_CHECK_OP(interface, enforce);
368 rc = QUOTA_OP(interface, enforce)(obd, ignore);
372 static inline int lquota_getflag(quota_interface_t *interface,
373 struct obd_device *obd, struct obdo *oa)
378 QUOTA_CHECK_OP(interface, getflag);
379 rc = QUOTA_OP(interface, getflag)(obd, oa);
383 static inline int lquota_acquire(quota_interface_t *interface,
384 struct obd_device *obd,
385 unsigned int uid, unsigned int gid)
390 QUOTA_CHECK_OP(interface, acquire);
391 rc = QUOTA_OP(interface, acquire)(obd, uid, gid);
395 int lprocfs_rd_bunit(char *page, char **start, off_t off, int count,
396 int *eof, void *data);
397 int lprocfs_rd_iunit(char *page, char **start, off_t off, int count,
398 int *eof, void *data);
399 int lprocfs_wr_bunit(struct file *file, const char *buffer,
400 unsigned long count, void *data);
401 int lprocfs_wr_iunit(struct file *file, const char *buffer,
402 unsigned long count, void *data);
403 int lprocfs_rd_btune(char *page, char **start, off_t off, int count,
404 int *eof, void *data);
405 int lprocfs_rd_itune(char *page, char **start, off_t off, int count,
406 int *eof, void *data);
407 int lprocfs_wr_btune(struct file *file, const char *buffer,
408 unsigned long count, void *data);
409 int lprocfs_wr_itune(struct file *file, const char *buffer,
410 unsigned long count, void *data);
411 int lprocfs_rd_type(char *page, char **start, off_t off, int count,
412 int *eof, void *data);
413 int lprocfs_wr_type(struct file *file, const char *buffer,
414 unsigned long count, void *data);
417 extern quota_interface_t osc_quota_interface;
418 extern quota_interface_t mdc_quota_interface;
419 extern quota_interface_t lov_quota_interface;
422 #endif /* _LUSTRE_QUOTA_H */