Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / include / lustre_quota.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  */
4 #ifndef _LUSTRE_QUOTA_H
5 #define _LUSTRE_QUOTA_H
6
7 #if defined(__linux__)
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>
13 #else
14 #error Unsupported operating system.
15 #endif
16
17 #include <lustre/lustre_idl.h>
18 #include <lustre_net.h>
19 #include <lvfs.h>
20
21 struct obd_device;
22 struct client_obd;
23
24 #ifndef NR_DQHASH
25 #define NR_DQHASH 45
26 #endif
27
28 #ifdef HAVE_QUOTA_SUPPORT
29
30 #ifdef __KERNEL__
31
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;
40 };
41
42 struct lustre_quota_info {
43         struct file *qi_files[MAXQUOTAS];
44         struct lustre_mem_dqinfo qi_info[MAXQUOTAS];
45 };
46
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 */
50
51 struct lustre_dquot {
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;
56         /* Use count */
57         int dq_refcnt;
58         /* Pointer of quota info it belongs to */
59         struct lustre_quota_info *dq_info;
60         
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 */
67 };
68
69 struct dquot_id {
70         struct list_head        di_link;
71         __u32                   di_id;
72 };
73
74 #define QFILE_CHK               1
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
80
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);
90
91 #define LL_DQUOT_OFF(sb)    DQUOT_OFF(sb)
92
93 typedef int (*dqacq_handler_t) (struct obd_device * obd, struct qunit_data * qd,
94                                 int opc);
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 */
109 };
110
111 #else
112
113 struct lustre_quota_info {
114 };
115
116 struct lustre_quota_ctxt {
117 };
118
119 #endif  /* !__KERNEL__ */
120
121 #else
122
123 #define LL_DQUOT_OFF(sb) do {} while(0)
124
125 struct lustre_quota_info {
126 };
127
128 struct lustre_quota_ctxt {
129 };
130
131 #endif /* !HAVE_QUOTA_SUPPORT */
132
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 */
135 #define MIN_QLIMIT      1
136
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 */
142 };
143
144 typedef struct {
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 *);
154         
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); 
158         
159         /* For quota slave, set import, trigger quota recovery */
160         int (*quota_setinfo) (struct obd_export *, struct obd_device *);
161         
162         /* For quota slave, set proper thread resoure capability */
163         int (*quota_enforce) (struct obd_device *, unsigned int);
164         
165         /* For quota slave, check whether specified uid/gid is over quota */
166         int (*quota_getflag) (struct obd_device *, struct obdo *);
167         
168         /* For quota slave, acquire/release quota from master if needed */
169         int (*quota_acquire) (struct obd_device *, unsigned int, unsigned int);
170         
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,
174                                int);
175
176         /* For quota client, poll if the quota check done */
177         int (*quota_poll_check) (struct obd_export *, struct if_quotacheck *);
178         
179         /* For quota client, check whether specified uid/gid is over quota */
180         int (*quota_chkdq) (struct client_obd *, unsigned int, unsigned int);
181         
182         /* For quota client, set over quota flag for specifed uid/gid */
183         int (*quota_setdq) (struct client_obd *, unsigned int, unsigned int,
184                             obd_flag, obd_flag);
185 } quota_interface_t;
186
187 #define Q_COPY(out, in, member) (out)->member = (in)->member
188
189 #define QUOTA_OP(interface, op) interface->quota_ ## op         
190
191 #define QUOTA_CHECK_OP(interface, op)                           \
192 do {                                                            \
193         if (!interface)                                         \
194                 RETURN(0);                                      \
195         if (!QUOTA_OP(interface, op)) {                         \
196                 CERROR("no quota operation: " #op "\n");        \
197                 RETURN(-EOPNOTSUPP);                            \
198         }                                                       \
199 } while(0)
200
201 static inline int lquota_init(quota_interface_t *interface)
202 {
203         int rc;
204         ENTRY;
205         
206         QUOTA_CHECK_OP(interface, init);
207         rc = QUOTA_OP(interface, init)();
208         RETURN(rc);
209 }
210
211 static inline int lquota_exit(quota_interface_t *interface) 
212 {
213         int rc;
214         ENTRY;
215         
216         QUOTA_CHECK_OP(interface, exit);
217         rc = QUOTA_OP(interface, exit)();
218         RETURN(rc);
219 }
220
221 static inline int lquota_setup(quota_interface_t *interface,
222                                struct obd_device *obd) 
223 {
224         int rc;
225         ENTRY;
226         
227         QUOTA_CHECK_OP(interface, setup);
228         rc = QUOTA_OP(interface, setup)(obd);
229         RETURN(rc);
230 }
231
232 static inline int lquota_cleanup(quota_interface_t *interface,
233                                  struct obd_device *obd) 
234 {
235         int rc;
236         ENTRY;
237         
238         QUOTA_CHECK_OP(interface, cleanup);
239         rc = QUOTA_OP(interface, cleanup)(obd);
240         RETURN(rc);
241 }
242
243 static inline int lquota_fs_cleanup(quota_interface_t *interface,
244                                     struct obd_device *obd)
245 {
246         int rc;
247         ENTRY;
248         
249         QUOTA_CHECK_OP(interface, fs_cleanup);
250         rc = QUOTA_OP(interface, fs_cleanup)(obd);
251         RETURN(rc);
252 }
253
254 static inline int lquota_recovery(quota_interface_t *interface,
255                                   struct obd_device *obd) 
256 {        
257         int rc;
258         ENTRY;
259         
260         QUOTA_CHECK_OP(interface, recovery);
261         rc = QUOTA_OP(interface, recovery)(obd);
262         RETURN(rc);
263 }
264
265 static inline int lquota_adjust(quota_interface_t *interface,
266                                 struct obd_device *obd, 
267                                 unsigned int qcids[], 
268                                 unsigned int qpids[], 
269                                 int rc, int opc) 
270 {
271         int ret;
272         ENTRY;
273         
274         QUOTA_CHECK_OP(interface, adjust);
275         ret = QUOTA_OP(interface, adjust)(obd, qcids, qpids, rc, opc);
276         RETURN(ret);
277 }
278
279 static inline int lquota_chkdq(quota_interface_t *interface,
280                                struct client_obd *cli,
281                                unsigned int uid, unsigned int gid)
282 {
283         int rc;
284         ENTRY;
285         
286         QUOTA_CHECK_OP(interface, chkdq);
287         rc = QUOTA_OP(interface, chkdq)(cli, uid, gid);
288         RETURN(rc);
289 }
290
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)
295 {
296         int rc;
297         ENTRY;
298         
299         QUOTA_CHECK_OP(interface, setdq);
300         rc = QUOTA_OP(interface, setdq)(cli, uid, gid, valid, flags);
301         RETURN(rc);
302 }
303
304 static inline int lquota_poll_check(quota_interface_t *interface,
305                                     struct obd_export *exp,
306                                     struct if_quotacheck *qchk)
307 {
308         int rc;
309         ENTRY;
310         
311         QUOTA_CHECK_OP(interface, poll_check);
312         rc = QUOTA_OP(interface, poll_check)(exp, qchk);
313         RETURN(rc);
314 }
315
316        
317 static inline int lquota_setinfo(quota_interface_t *interface,
318                                  struct obd_export *exp, 
319                                  struct obd_device *obd) 
320 {
321         int rc;
322         ENTRY;
323
324         QUOTA_CHECK_OP(interface, setinfo);
325         rc = QUOTA_OP(interface, setinfo)(exp, obd);
326         RETURN(rc);
327 }
328
329 static inline int lquota_enforce(quota_interface_t *interface, 
330                                  struct obd_device *obd,
331                                  unsigned int ignore)
332 {
333         int rc;
334         ENTRY;
335
336         QUOTA_CHECK_OP(interface, enforce);
337         rc = QUOTA_OP(interface, enforce)(obd, ignore);
338         RETURN(rc);
339 }
340
341 static inline int lquota_getflag(quota_interface_t *interface,
342                                  struct obd_device *obd, struct obdo *oa)
343 {
344         int rc;
345         ENTRY;
346
347         QUOTA_CHECK_OP(interface, getflag);
348         rc = QUOTA_OP(interface, getflag)(obd, oa);
349         RETURN(rc);
350 }
351         
352 static inline int lquota_acquire(quota_interface_t *interface,
353                                  struct obd_device *obd, 
354                                  unsigned int uid, unsigned int gid)
355 {
356         int rc;
357         ENTRY;
358
359         QUOTA_CHECK_OP(interface, acquire);
360         rc = QUOTA_OP(interface, acquire)(obd, uid, gid);
361         RETURN(rc);
362 }
363
364 static inline int lquota_chkquota(quota_interface_t *interface,
365                                   struct obd_device *obd,
366                                   unsigned int uid, unsigned int gid,
367                                   int npage)
368 {
369         int rc;
370         ENTRY;
371         
372         QUOTA_CHECK_OP(interface, chkquota);
373         rc = QUOTA_OP(interface, chkquota)(obd, uid, gid, npage);
374         RETURN(rc);
375 }
376
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);
397
398 #ifndef __KERNEL__
399 extern quota_interface_t osc_quota_interface;
400 extern quota_interface_t mdc_quota_interface;
401 extern quota_interface_t lov_quota_interface;
402 #endif
403
404 #endif /* _LUSTRE_QUOTA_H */