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 #include <linux/types.h>
43 #include <linux/quota.h>
46 * Definitions of magics and versions of current quota files
47 * Same with quota v2's magic
49 #define LUSTRE_INITQMAGICS {\
50 0xd9c01f11, /** USRQUOTA */\
51 0xd9c01927 /** GRPQUOTA */\
54 /* Invalid magics that mark quota file as inconsistent */
55 #define LUSTRE_BADQMAGICS {\
56 0xbadbadba, /** USRQUOTA */\
57 0xbadbadba /** GRPQUOTA */\
60 /* for the verson 2 of lustre_disk_dqblk*/
61 #define LUSTRE_INITQVERSIONS_V2 {\
67 * The following structure defines the format of the disk quota file
68 * (as it appears on disk) - the file is a radix tree whose leaves point
69 * to blocks of these structures. for the version 2.
71 struct lustre_disk_dqblk_v2 {
72 __u32 dqb_id; /**< id this quota applies to */
74 __u64 dqb_ihardlimit; /**< absolute limit on allocated inodes */
75 __u64 dqb_isoftlimit; /**< preferred inode limit */
76 __u64 dqb_curinodes; /**< current # allocated inodes */
77 __u64 dqb_bhardlimit; /**< absolute limit on disk space (in QUOTABLOCK_SIZE) */
78 __u64 dqb_bsoftlimit; /**< preferred limit on disk space (in QUOTABLOCK_SIZE) */
79 __u64 dqb_curspace; /**< current space occupied (in bytes) */
80 obd_time dqb_btime; /**< time limit for excessive disk use */
81 obd_time dqb_itime; /**< time limit for excessive inode use */
84 /* Number of entries in one blocks(14 entries) */
85 #define LUSTRE_DQSTRINBLK_V2 \
86 ((LUSTRE_DQBLKSIZE - sizeof(struct lustre_disk_dqdbheader)) \
87 / sizeof(struct lustre_disk_dqblk_v2))
88 #define GETENTRIES_V2(buf) (((char *)buf)+sizeof(struct lustre_disk_dqdbheader))
90 #define GETENTRIES(buf,version) ((version == LUSTRE_QUOTA_V2) ? \
91 GETENTRIES_V2(buf) : 0)
94 * Here are header structures as written on disk and their in-memory copies
96 /* First generic header */
97 struct lustre_disk_dqheader {
98 __u32 dqh_magic; /* Magic number identifying file */
99 __u32 dqh_version; /* File version */
102 /* Header with type and version specific information */
103 struct lustre_disk_dqinfo {
104 __u32 dqi_bgrace; /* Time before block soft limit becomes hard limit */
105 __u32 dqi_igrace; /* Time before inode soft limit becomes hard limit */
106 __u32 dqi_flags; /* Flags for quotafile (DQF_*) */
107 __u32 dqi_blocks; /* Number of blocks in file */
108 __u32 dqi_free_blk; /* Number of first free block in the list */
109 __u32 dqi_free_entry; /* Number of block with at least one free entry */
113 * Structure of header of block with quota structures. It is padded to 16 bytes so
114 * there will be space for exactly 21 quota-entries in a block
116 struct lustre_disk_dqdbheader {
117 __u32 dqdh_next_free; /* Number of next block with free entry */
118 __u32 dqdh_prev_free; /* Number of previous block with free entry */
119 __u16 dqdh_entries; /* Number of valid entries in block */
125 void lprocfs_quotfmt_test_init_vars(struct lprocfs_static_vars *lvars);
127 static void lprocfs_quotfmt_test_init_vars(struct lprocfs_static_vars *lvars) {}
130 #define LUSTRE_DQINFOOFF sizeof(struct lustre_disk_dqheader) /* Offset of info header in file */
131 #define LUSTRE_DQBLKSIZE_BITS 10
132 #define LUSTRE_DQBLKSIZE (1 << LUSTRE_DQBLKSIZE_BITS) /* Size of block with quota structures */
133 #define LUSTRE_DQTREEOFF 1 /* Offset of tree in file in blocks */
134 #define LUSTRE_DQTREEDEPTH 4 /* Depth of quota tree */
136 typedef char *dqbuf_t;
138 #define GETIDINDEX(id, depth) (((id) >> ((LUSTRE_DQTREEDEPTH-(depth)-1)*8)) & 0xff)
140 #define MAX_UL (0xffffffffUL)
142 #define lustre_info_dirty(info) \
143 cfs_test_bit(DQF_INFO_DIRTY_B, &(info)->dqi_flags)
150 /* come from lustre_fmt_common.c */
151 dqbuf_t getdqbuf(void);
152 void freedqbuf(dqbuf_t buf);
153 void disk2memdqb(struct lustre_mem_dqblk *m, void *d,
154 enum lustre_quota_version version);
155 void lustre_mark_info_dirty(struct lustre_mem_dqinfo *info);
156 int lustre_init_quota_header(struct lustre_quota_info *lqi, int type,
158 int lustre_init_quota_info_generic(struct lustre_quota_info *lqi, int type,
160 int lustre_read_quota_info(struct lustre_quota_info *lqi, int type);
161 int lustre_read_quota_file_info(struct file* f, struct lustre_mem_dqinfo* info);
162 int lustre_write_quota_info(struct lustre_quota_info *lqi, int type);
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, cfs_list_t *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,
184 ssize_t lustre_read_quota(struct file *f, struct inode *inode, int type,
185 char *buf, int count, loff_t pos);
187 #define LUSTRE_ADMIN_QUOTAFILES_V2 {\
188 "admin_quotafile_v2.usr", /* user admin quotafile */\
189 "admin_quotafile_v2.grp" /* group admin quotafile */\
192 #define LUSTRE_OPQFILES_NAMES_V2 { "lquota_v2.user", "lquota_v2.group" }
193 #endif /* lustre_quota_fmt.h */