1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Lustre administrative quota format
7 * include/linux/quotaio_v2.h
9 #ifndef _LUSTRE_QUOTA_FMT_H
10 #define _LUSTRE_QUOTA_FMT_H
12 #include <linux/types.h>
13 #include <linux/quota.h>
16 * Definitions of magics and versions of current quota files
17 * Same with quota v2's magic
19 #define LUSTRE_INITQMAGICS {\
20 0xd9c01f11, /* USRQUOTA */\
21 0xd9c01927 /* GRPQUOTA */\
24 /* Invalid magics that mark quota file as inconsistent */
25 #define LUSTRE_BADQMAGICS {\
26 0xbadbadba, /* USRQUOTA */\
27 0xbadbadba /* GRPQUOTA */\
30 /* for the verson 1 of lustre_disk_dqblk*/
31 #define LUSTRE_INITQVERSIONS {\
37 * The following structure defines the format of the disk quota file
38 * (as it appears on disk) - the file is a radix tree whose leaves point
39 * to blocks of these structures. for the version 1.
41 struct lustre_disk_dqblk {
42 __u32 dqb_id; /* id this quota applies to */
43 __u32 dqb_ihardlimit; /* absolute limit on allocated inodes */
44 __u32 dqb_isoftlimit; /* preferred inode limit */
45 __u32 dqb_curinodes; /* current # allocated inodes */
46 __u32 dqb_bhardlimit; /* absolute limit on disk space (in QUOTABLOCK_SIZE) */
47 __u32 dqb_bsoftlimit; /* preferred limit on disk space (in QUOTABLOCK_SIZE) */
48 __u64 dqb_curspace; /* current space occupied (in bytes) */
49 __u64 dqb_btime; /* time limit for excessive disk use */
50 __u64 dqb_itime; /* time limit for excessive inode use */
53 /* Number of entries in one blocks(21 entries) */
54 #define LUSTRE_DQSTRINBLK \
55 ((LUSTRE_DQBLKSIZE - sizeof(struct lustre_disk_dqdbheader)) \
56 / sizeof(struct lustre_disk_dqblk))
57 #define GETENTRIES_V1(buf) (((char *)buf)+sizeof(struct lustre_disk_dqdbheader))
59 /* for the verson 2 of lustre_disk_dqblk*/
60 #define LUSTRE_INITQVERSIONS_V2 {\
66 * The following structure defines the format of the disk quota file
67 * (as it appears on disk) - the file is a radix tree whose leaves point
68 * to blocks of these structures. for the version 2.
70 struct lustre_disk_dqblk_v2 {
71 __u32 dqb_id; /* id this quota applies to */
73 __u64 dqb_ihardlimit; /* absolute limit on allocated inodes */
74 __u64 dqb_isoftlimit; /* preferred inode limit */
75 __u64 dqb_curinodes; /* current # allocated inodes */
76 __u64 dqb_bhardlimit; /* absolute limit on disk space (in QUOTABLOCK_SIZE) */
77 __u64 dqb_bsoftlimit; /* preferred limit on disk space (in QUOTABLOCK_SIZE) */
78 __u64 dqb_curspace; /* current space occupied (in bytes) */
79 __u64 dqb_btime; /* time limit for excessive disk use */
80 __u64 dqb_itime; /* time limit for excessive inode use */
83 /* Number of entries in one blocks(14 entries) */
84 #define LUSTRE_DQSTRINBLK_V2 \
85 ((LUSTRE_DQBLKSIZE - sizeof(struct lustre_disk_dqdbheader)) \
86 / sizeof(struct lustre_disk_dqblk_v2))
87 #define GETENTRIES_V2(buf) (((char *)buf)+sizeof(struct lustre_disk_dqdbheader))
89 #define GETENTRIES(buf,version) ((version == LUSTRE_QUOTA_V1) ? \
90 GETENTRIES_V1(buf) : GETENTRIES_V2(buf))
93 * Here are header structures as written on disk and their in-memory copies
95 /* First generic header */
96 struct lustre_disk_dqheader {
97 __u32 dqh_magic; /* Magic number identifying file */
98 __u32 dqh_version; /* File version */
101 /* Header with type and version specific information */
102 struct lustre_disk_dqinfo {
103 __u32 dqi_bgrace; /* Time before block soft limit becomes hard limit */
104 __u32 dqi_igrace; /* Time before inode soft limit becomes hard limit */
105 __u32 dqi_flags; /* Flags for quotafile (DQF_*) */
106 __u32 dqi_blocks; /* Number of blocks in file */
107 __u32 dqi_free_blk; /* Number of first free block in the list */
108 __u32 dqi_free_entry; /* Number of block with at least one free entry */
112 * Structure of header of block with quota structures. It is padded to 16 bytes so
113 * there will be space for exactly 21 quota-entries in a block
115 struct lustre_disk_dqdbheader {
116 __u32 dqdh_next_free; /* Number of next block with free entry */
117 __u32 dqdh_prev_free; /* Number of previous block with free entry */
118 __u16 dqdh_entries; /* Number of valid entries in block */
124 void lprocfs_quotfmt_test_init_vars(struct lprocfs_static_vars *lvars);
126 static void lprocfs_quotfmt_test_init_vars(struct lprocfs_static_vars *lvars) {}
129 #define LUSTRE_DQINFOOFF sizeof(struct lustre_disk_dqheader) /* Offset of info header in file */
130 #define LUSTRE_DQBLKSIZE_BITS 10
131 #define LUSTRE_DQBLKSIZE (1 << LUSTRE_DQBLKSIZE_BITS) /* Size of block with quota structures */
132 #define LUSTRE_DQTREEOFF 1 /* Offset of tree in file in blocks */
133 #define LUSTRE_DQTREEDEPTH 4 /* Depth of quota tree */
135 typedef char *dqbuf_t;
137 #define GETIDINDEX(id, depth) (((id) >> ((LUSTRE_DQTREEDEPTH-(depth)-1)*8)) & 0xff)
139 #define MAX_UL (0xffffffffUL)
141 #define lustre_info_dirty(info) test_bit(DQF_INFO_DIRTY_B, &(info)->dqi_flags)
144 struct list_head link;
148 /* come from lustre_fmt_common.c */
149 dqbuf_t getdqbuf(void);
150 void freedqbuf(dqbuf_t buf);
151 void disk2memdqb(struct lustre_mem_dqblk *m, void *d,
152 enum lustre_quota_version version);
153 void lustre_mark_info_dirty(struct lustre_mem_dqinfo *info);
154 int lustre_init_quota_header(struct lustre_quota_info *lqi, int type,
156 int lustre_init_quota_info_generic(struct lustre_quota_info *lqi, int type,
158 int lustre_read_quota_info(struct lustre_quota_info *lqi, int type);
159 int lustre_read_quota_file_info(struct file* f, struct lustre_mem_dqinfo* info);
160 int lustre_write_quota_info(struct lustre_quota_info *lqi, int type);
161 ssize_t read_blk(struct file *filp, uint blk, dqbuf_t buf);
162 ssize_t write_blk(struct file *filp, uint blk, dqbuf_t buf);
163 int get_free_dqblk(struct file *filp, struct lustre_mem_dqinfo *info);
164 int put_free_dqblk(struct file *filp, struct lustre_mem_dqinfo *info,
165 dqbuf_t buf, uint blk);
166 int remove_free_dqentry(struct file *filp,
167 struct lustre_mem_dqinfo *info, dqbuf_t buf,
169 int insert_free_dqentry(struct file *filp,
170 struct lustre_mem_dqinfo *info, dqbuf_t buf,
172 ssize_t quota_read(struct file *file, struct inode *inode, int type,
173 uint blk, dqbuf_t buf);
174 int walk_tree_dqentry(struct file *filp, struct inode *inode, int type,
175 uint blk, int depth, struct list_head *list);
176 int check_quota_file(struct file *f, struct inode *inode, int type,
177 lustre_quota_version_t version);
178 int lustre_check_quota_file(struct lustre_quota_info *lqi, int type);
179 int lustre_read_dquot(struct lustre_dquot *dquot);
180 int lustre_commit_dquot(struct lustre_dquot *dquot);
181 int lustre_init_quota_info(struct lustre_quota_info *lqi, int type);
182 int lustre_get_qids(struct file *fp, struct inode *inode, int type,
183 struct list_head *list);
186 /* come from lustre_quota_fmt_conver.c */
187 int lustre_quota_convert(struct lustre_quota_info *lqi, int type);
189 #endif /* lustre_quota_fmt.h */