4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
34 * lustre/lvfs/lustre_quota_fmt.h
36 * Lustre administrative quota format
37 * from include/linux/quotaio_v2.h
39 #ifndef _LUSTRE_QUOTA_FMT_H
40 #define _LUSTRE_QUOTA_FMT_H
42 #ifdef HAVE_QUOTA_SUPPORT
44 #include <linux/types.h>
45 #include <linux/quota.h>
48 * Definitions of magics and versions of current quota files
49 * Same with quota v2's magic
51 #define LUSTRE_INITQMAGICS {\
52 0xd9c01f11, /** USRQUOTA */\
53 0xd9c01927 /** GRPQUOTA */\
56 /* Invalid magics that mark quota file as inconsistent */
57 #define LUSTRE_BADQMAGICS {\
58 0xbadbadba, /** USRQUOTA */\
59 0xbadbadba /** GRPQUOTA */\
62 /* for the verson 2 of lustre_disk_dqblk*/
63 #define LUSTRE_INITQVERSIONS_V2 {\
69 * The following structure defines the format of the disk quota file
70 * (as it appears on disk) - the file is a radix tree whose leaves point
71 * to blocks of these structures. for the version 2.
73 struct lustre_disk_dqblk_v2 {
74 __u32 dqb_id; /**< id this quota applies to */
76 __u64 dqb_ihardlimit; /**< absolute limit on allocated inodes */
77 __u64 dqb_isoftlimit; /**< preferred inode limit */
78 __u64 dqb_curinodes; /**< current # allocated inodes */
79 __u64 dqb_bhardlimit; /**< absolute limit on disk space (in QUOTABLOCK_SIZE) */
80 __u64 dqb_bsoftlimit; /**< preferred limit on disk space (in QUOTABLOCK_SIZE) */
81 __u64 dqb_curspace; /**< current space occupied (in bytes) */
82 obd_time dqb_btime; /**< time limit for excessive disk use */
83 obd_time dqb_itime; /**< time limit for excessive inode use */
86 /* Number of entries in one blocks(14 entries) */
87 #define LUSTRE_DQSTRINBLK_V2 \
88 ((LUSTRE_DQBLKSIZE - sizeof(struct lustre_disk_dqdbheader)) \
89 / sizeof(struct lustre_disk_dqblk_v2))
90 #define GETENTRIES_V2(buf) (((char *)buf)+sizeof(struct lustre_disk_dqdbheader))
92 #define GETENTRIES(buf,version) ((version == LUSTRE_QUOTA_V2) ? \
93 GETENTRIES_V2(buf) : 0)
96 * Here are header structures as written on disk and their in-memory copies
98 /* First generic header */
99 struct lustre_disk_dqheader {
100 __u32 dqh_magic; /* Magic number identifying file */
101 __u32 dqh_version; /* File version */
104 /* Header with type and version specific information */
105 struct lustre_disk_dqinfo {
106 __u32 dqi_bgrace; /* Time before block soft limit becomes hard limit */
107 __u32 dqi_igrace; /* Time before inode soft limit becomes hard limit */
108 __u32 dqi_flags; /* Flags for quotafile (DQF_*) */
109 __u32 dqi_blocks; /* Number of blocks in file */
110 __u32 dqi_free_blk; /* Number of first free block in the list */
111 __u32 dqi_free_entry; /* Number of block with at least one free entry */
115 * Structure of header of block with quota structures. It is padded to 16 bytes so
116 * there will be space for exactly 21 quota-entries in a block
118 struct lustre_disk_dqdbheader {
119 __u32 dqdh_next_free; /* Number of next block with free entry */
120 __u32 dqdh_prev_free; /* Number of previous block with free entry */
121 __u16 dqdh_entries; /* Number of valid entries in block */
127 void lprocfs_quotfmt_test_init_vars(struct lprocfs_static_vars *lvars);
129 static void lprocfs_quotfmt_test_init_vars(struct lprocfs_static_vars *lvars) {}
132 #define LUSTRE_DQINFOOFF sizeof(struct lustre_disk_dqheader) /* Offset of info header in file */
133 #define LUSTRE_DQBLKSIZE_BITS 10
134 #define LUSTRE_DQBLKSIZE (1 << LUSTRE_DQBLKSIZE_BITS) /* Size of block with quota structures */
135 #define LUSTRE_DQTREEOFF 1 /* Offset of tree in file in blocks */
136 #define LUSTRE_DQTREEDEPTH 4 /* Depth of quota tree */
138 typedef char *dqbuf_t;
140 #define GETIDINDEX(id, depth) (((id) >> ((LUSTRE_DQTREEDEPTH-(depth)-1)*8)) & 0xff)
142 #define MAX_UL (0xffffffffUL)
144 #define lustre_info_dirty(info) \
145 cfs_test_bit(DQF_INFO_DIRTY_B, &(info)->dqi_flags)
152 /* come from lustre_fmt_common.c */
153 dqbuf_t getdqbuf(void);
154 void freedqbuf(dqbuf_t buf);
155 void disk2memdqb(struct lustre_mem_dqblk *m, void *d,
156 enum lustre_quota_version version);
157 void lustre_mark_info_dirty(struct lustre_mem_dqinfo *info);
158 int lustre_init_quota_header(struct lustre_quota_info *lqi, int type,
160 int lustre_init_quota_info_generic(struct lustre_quota_info *lqi, int type,
162 int lustre_read_quota_info(struct lustre_quota_info *lqi, int type);
163 int lustre_read_quota_file_info(struct file* f, struct lustre_mem_dqinfo* info);
164 int lustre_write_quota_info(struct lustre_quota_info *lqi, int type);
165 int get_free_dqblk(struct file *filp, struct lustre_mem_dqinfo *info);
166 int put_free_dqblk(struct file *filp, struct lustre_mem_dqinfo *info,
167 dqbuf_t buf, uint blk);
168 int remove_free_dqentry(struct file *filp,
169 struct lustre_mem_dqinfo *info, dqbuf_t buf,
171 int insert_free_dqentry(struct file *filp,
172 struct lustre_mem_dqinfo *info, dqbuf_t buf,
174 ssize_t quota_read(struct file *file, struct inode *inode, int type,
175 uint blk, dqbuf_t buf);
176 int walk_tree_dqentry(struct file *filp, struct inode *inode, int type,
177 uint blk, int depth, cfs_list_t *list);
178 int check_quota_file(struct file *f, struct inode *inode, int type,
179 lustre_quota_version_t version);
180 int lustre_check_quota_file(struct lustre_quota_info *lqi, int type);
181 int lustre_read_dquot(struct lustre_dquot *dquot);
182 int lustre_commit_dquot(struct lustre_dquot *dquot);
183 int lustre_init_quota_info(struct lustre_quota_info *lqi, int type);
184 int lustre_get_qids(struct file *fp, struct inode *inode, int type,
186 ssize_t lustre_read_quota(struct file *f, struct inode *inode, int type,
187 char *buf, int count, loff_t pos);
189 #define LUSTRE_ADMIN_QUOTAFILES_V2 {\
190 "admin_quotafile_v2.usr", /* user admin quotafile */\
191 "admin_quotafile_v2.grp" /* group admin quotafile */\
194 #define LUSTRE_OPQFILES_NAMES_V2 { "lquota_v2.user", "lquota_v2.group" }
195 #endif /* lustre_quota_fmt.h */