1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/lvfs/lustre_quota_fmt.h
38 * Lustre administrative quota format
39 * from include/linux/quotaio_v2.h
41 #ifndef _LUSTRE_QUOTA_FMT_H
42 #define _LUSTRE_QUOTA_FMT_H
44 #ifdef HAVE_QUOTA_SUPPORT
46 #include <linux/types.h>
47 #include <linux/quota.h>
50 * Definitions of magics and versions of current quota files
51 * Same with quota v2's magic
53 #define LUSTRE_INITQMAGICS {\
54 0xd9c01f11, /* USRQUOTA */\
55 0xd9c01927 /* GRPQUOTA */\
58 /* Invalid magics that mark quota file as inconsistent */
59 #define LUSTRE_BADQMAGICS {\
60 0xbadbadba, /* USRQUOTA */\
61 0xbadbadba /* GRPQUOTA */\
64 /* for the verson 1 of lustre_disk_dqblk*/
65 #define LUSTRE_INITQVERSIONS_V1 {\
71 * The following structure defines the format of the disk quota file
72 * (as it appears on disk) - the file is a radix tree whose leaves point
73 * to blocks of these structures. for the version 1.
75 struct lustre_disk_dqblk {
76 __u32 dqb_id; /* id this quota applies to */
77 __u32 dqb_ihardlimit; /* absolute limit on allocated inodes */
78 __u32 dqb_isoftlimit; /* preferred inode limit */
79 __u32 dqb_curinodes; /* current # allocated inodes */
80 __u32 dqb_bhardlimit; /* absolute limit on disk space (in QUOTABLOCK_SIZE) */
81 __u32 dqb_bsoftlimit; /* preferred limit on disk space (in QUOTABLOCK_SIZE) */
82 __u64 dqb_curspace; /* current space occupied (in bytes) */
83 __u64 dqb_btime; /* time limit for excessive disk use */
84 __u64 dqb_itime; /* time limit for excessive inode use */
87 /* Number of entries in one blocks(21 entries) */
88 #define LUSTRE_DQSTRINBLK \
89 ((LUSTRE_DQBLKSIZE - sizeof(struct lustre_disk_dqdbheader)) \
90 / sizeof(struct lustre_disk_dqblk))
91 #define GETENTRIES_V1(buf) (((char *)buf)+sizeof(struct lustre_disk_dqdbheader))
93 /* for the verson 2 of lustre_disk_dqblk*/
94 #define LUSTRE_INITQVERSIONS_V2 {\
100 * The following structure defines the format of the disk quota file
101 * (as it appears on disk) - the file is a radix tree whose leaves point
102 * to blocks of these structures. for the version 2.
104 struct lustre_disk_dqblk_v2 {
105 __u32 dqb_id; /* id this quota applies to */
107 __u64 dqb_ihardlimit; /* absolute limit on allocated inodes */
108 __u64 dqb_isoftlimit; /* preferred inode limit */
109 __u64 dqb_curinodes; /* current # allocated inodes */
110 __u64 dqb_bhardlimit; /* absolute limit on disk space (in QUOTABLOCK_SIZE) */
111 __u64 dqb_bsoftlimit; /* preferred limit on disk space (in QUOTABLOCK_SIZE) */
112 __u64 dqb_curspace; /* current space occupied (in bytes) */
113 __u64 dqb_btime; /* time limit for excessive disk use */
114 __u64 dqb_itime; /* time limit for excessive inode use */
117 /* Number of entries in one blocks(14 entries) */
118 #define LUSTRE_DQSTRINBLK_V2 \
119 ((LUSTRE_DQBLKSIZE - sizeof(struct lustre_disk_dqdbheader)) \
120 / sizeof(struct lustre_disk_dqblk_v2))
121 #define GETENTRIES_V2(buf) (((char *)buf)+sizeof(struct lustre_disk_dqdbheader))
123 #define GETENTRIES(buf,version) ((version == LUSTRE_QUOTA_V1) ? \
124 GETENTRIES_V1(buf) : GETENTRIES_V2(buf))
126 union lustre_disk_dqblk_un {
127 struct lustre_disk_dqblk v1;
128 struct lustre_disk_dqblk_v2 v2;
132 * Here are header structures as written on disk and their in-memory copies
134 /* First generic header */
135 struct lustre_disk_dqheader {
136 __u32 dqh_magic; /* Magic number identifying file */
137 __u32 dqh_version; /* File version */
140 /* Header with type and version specific information */
141 struct lustre_disk_dqinfo {
142 __u32 dqi_bgrace; /* Time before block soft limit becomes hard limit */
143 __u32 dqi_igrace; /* Time before inode soft limit becomes hard limit */
144 __u32 dqi_flags; /* Flags for quotafile (DQF_*) */
145 __u32 dqi_blocks; /* Number of blocks in file */
146 __u32 dqi_free_blk; /* Number of first free block in the list */
147 __u32 dqi_free_entry; /* Number of block with at least one free entry */
151 * Structure of header of block with quota structures. It is padded to 16 bytes so
152 * there will be space for exactly 21 quota-entries in a block
154 struct lustre_disk_dqdbheader {
155 __u32 dqdh_next_free; /* Number of next block with free entry */
156 __u32 dqdh_prev_free; /* Number of previous block with free entry */
157 __u16 dqdh_entries; /* Number of valid entries in block */
163 void lprocfs_quotfmt_test_init_vars(struct lprocfs_static_vars *lvars);
165 static void lprocfs_quotfmt_test_init_vars(struct lprocfs_static_vars *lvars) {}
168 #define LUSTRE_DQINFOOFF sizeof(struct lustre_disk_dqheader) /* Offset of info header in file */
169 #define LUSTRE_DQBLKSIZE_BITS 10
170 #define LUSTRE_DQBLKSIZE (1 << LUSTRE_DQBLKSIZE_BITS) /* Size of block with quota structures */
171 #define LUSTRE_DQTREEOFF 1 /* Offset of tree in file in blocks */
172 #define LUSTRE_DQTREEDEPTH 4 /* Depth of quota tree */
174 typedef char *dqbuf_t;
176 #define GETIDINDEX(id, depth) (((id) >> ((LUSTRE_DQTREEDEPTH-(depth)-1)*8)) & 0xff)
178 #define MAX_UL (0xffffffffUL)
180 #define lustre_info_dirty(info) test_bit(DQF_INFO_DIRTY_B, &(info)->dqi_flags)
183 struct list_head link;
187 /* come from lustre_fmt_common.c */
188 dqbuf_t getdqbuf(void);
189 void freedqbuf(dqbuf_t buf);
190 void disk2memdqb(struct lustre_mem_dqblk *m, void *d,
191 enum lustre_quota_version version);
192 void lustre_mark_info_dirty(struct lustre_mem_dqinfo *info);
193 int lustre_init_quota_header(struct lustre_quota_info *lqi, int type,
195 int lustre_init_quota_info_generic(struct lustre_quota_info *lqi, int type,
197 int lustre_read_quota_info(struct lustre_quota_info *lqi, int type);
198 int lustre_read_quota_file_info(struct file* f, struct lustre_mem_dqinfo* info);
199 int lustre_write_quota_info(struct lustre_quota_info *lqi, int type);
200 int get_free_dqblk(struct file *filp, struct lustre_mem_dqinfo *info);
201 int put_free_dqblk(struct file *filp, struct lustre_mem_dqinfo *info,
202 dqbuf_t buf, uint blk);
203 int remove_free_dqentry(struct file *filp,
204 struct lustre_mem_dqinfo *info, dqbuf_t buf,
206 int insert_free_dqentry(struct file *filp,
207 struct lustre_mem_dqinfo *info, dqbuf_t buf,
209 ssize_t quota_read(struct file *file, struct inode *inode, int type,
210 uint blk, dqbuf_t buf);
211 int walk_tree_dqentry(struct file *filp, struct inode *inode, int type,
212 uint blk, int depth, struct list_head *list);
213 int check_quota_file(struct file *f, struct inode *inode, int type,
214 lustre_quota_version_t version);
215 int lustre_check_quota_file(struct lustre_quota_info *lqi, int type);
216 int lustre_read_dquot(struct lustre_dquot *dquot);
217 int lustre_commit_dquot(struct lustre_dquot *dquot);
218 int lustre_init_quota_info(struct lustre_quota_info *lqi, int type);
219 int lustre_get_qids(struct file *fp, struct inode *inode, int type,
220 struct list_head *list);
222 ssize_t lustre_read_quota(struct file *f, struct inode *inode, int type,
223 char *buf, int count, loff_t pos);
225 /* comes from lustre_quota_fmt_convert.c */
226 int lustre_slave_quota_convert(lustre_quota_version_t qfmt, int type);
227 int lustre_quota_convert(struct lustre_quota_info *lqi, int type);
229 #define LUSTRE_OPQFILES_NAMES { { "lquota.user", "lquota.group" }, \
230 { "lquota_v2.user", "lquota_v2.group" } }
231 #endif /* lustre_quota_fmt.h */