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 2 of lustre_disk_dqblk*/
65 #define LUSTRE_INITQVERSIONS_V2 {\
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 2.
75 struct lustre_disk_dqblk_v2 {
76 __u32 dqb_id; /**< id this quota applies to */
78 __u64 dqb_ihardlimit; /**< absolute limit on allocated inodes */
79 __u64 dqb_isoftlimit; /**< preferred inode limit */
80 __u64 dqb_curinodes; /**< current # allocated inodes */
81 __u64 dqb_bhardlimit; /**< absolute limit on disk space (in QUOTABLOCK_SIZE) */
82 __u64 dqb_bsoftlimit; /**< preferred limit on disk space (in QUOTABLOCK_SIZE) */
83 __u64 dqb_curspace; /**< current space occupied (in bytes) */
84 __u64 dqb_btime; /**< time limit for excessive disk use */
85 __u64 dqb_itime; /**< time limit for excessive inode use */
88 /* Number of entries in one blocks(14 entries) */
89 #define LUSTRE_DQSTRINBLK_V2 \
90 ((LUSTRE_DQBLKSIZE - sizeof(struct lustre_disk_dqdbheader)) \
91 / sizeof(struct lustre_disk_dqblk_v2))
92 #define GETENTRIES_V2(buf) (((char *)buf)+sizeof(struct lustre_disk_dqdbheader))
94 #define GETENTRIES(buf,version) ((version == LUSTRE_QUOTA_V2) ? \
95 GETENTRIES_V2(buf) : 0)
98 * Here are header structures as written on disk and their in-memory copies
100 /* First generic header */
101 struct lustre_disk_dqheader {
102 __u32 dqh_magic; /* Magic number identifying file */
103 __u32 dqh_version; /* File version */
106 /* Header with type and version specific information */
107 struct lustre_disk_dqinfo {
108 __u32 dqi_bgrace; /* Time before block soft limit becomes hard limit */
109 __u32 dqi_igrace; /* Time before inode soft limit becomes hard limit */
110 __u32 dqi_flags; /* Flags for quotafile (DQF_*) */
111 __u32 dqi_blocks; /* Number of blocks in file */
112 __u32 dqi_free_blk; /* Number of first free block in the list */
113 __u32 dqi_free_entry; /* Number of block with at least one free entry */
117 * Structure of header of block with quota structures. It is padded to 16 bytes so
118 * there will be space for exactly 21 quota-entries in a block
120 struct lustre_disk_dqdbheader {
121 __u32 dqdh_next_free; /* Number of next block with free entry */
122 __u32 dqdh_prev_free; /* Number of previous block with free entry */
123 __u16 dqdh_entries; /* Number of valid entries in block */
129 void lprocfs_quotfmt_test_init_vars(struct lprocfs_static_vars *lvars);
131 static void lprocfs_quotfmt_test_init_vars(struct lprocfs_static_vars *lvars) {}
134 #define LUSTRE_DQINFOOFF sizeof(struct lustre_disk_dqheader) /* Offset of info header in file */
135 #define LUSTRE_DQBLKSIZE_BITS 10
136 #define LUSTRE_DQBLKSIZE (1 << LUSTRE_DQBLKSIZE_BITS) /* Size of block with quota structures */
137 #define LUSTRE_DQTREEOFF 1 /* Offset of tree in file in blocks */
138 #define LUSTRE_DQTREEDEPTH 4 /* Depth of quota tree */
140 typedef char *dqbuf_t;
142 #define GETIDINDEX(id, depth) (((id) >> ((LUSTRE_DQTREEDEPTH-(depth)-1)*8)) & 0xff)
144 #define MAX_UL (0xffffffffUL)
146 #define lustre_info_dirty(info) test_bit(DQF_INFO_DIRTY_B, &(info)->dqi_flags)
149 struct list_head link;
153 /* come from lustre_fmt_common.c */
154 dqbuf_t getdqbuf(void);
155 void freedqbuf(dqbuf_t buf);
156 void disk2memdqb(struct lustre_mem_dqblk *m, void *d,
157 enum lustre_quota_version version);
158 void lustre_mark_info_dirty(struct lustre_mem_dqinfo *info);
159 int lustre_init_quota_header(struct lustre_quota_info *lqi, int type,
161 int lustre_init_quota_info_generic(struct lustre_quota_info *lqi, int type,
163 int lustre_read_quota_info(struct lustre_quota_info *lqi, int type);
164 int lustre_read_quota_file_info(struct file* f, struct lustre_mem_dqinfo* info);
165 int lustre_write_quota_info(struct lustre_quota_info *lqi, int type);
166 ssize_t read_blk(struct file *filp, uint blk, dqbuf_t buf);
167 ssize_t write_blk(struct file *filp, uint blk, dqbuf_t buf);
168 int get_free_dqblk(struct file *filp, struct lustre_mem_dqinfo *info);
169 int put_free_dqblk(struct file *filp, struct lustre_mem_dqinfo *info,
170 dqbuf_t buf, uint blk);
171 int remove_free_dqentry(struct file *filp,
172 struct lustre_mem_dqinfo *info, dqbuf_t buf,
174 int insert_free_dqentry(struct file *filp,
175 struct lustre_mem_dqinfo *info, dqbuf_t buf,
177 ssize_t quota_read(struct file *file, struct inode *inode, int type,
178 uint blk, dqbuf_t buf);
179 int walk_tree_dqentry(struct file *filp, struct inode *inode, int type,
180 uint blk, int depth, struct list_head *list);
181 int check_quota_file(struct file *f, struct inode *inode, int type,
182 lustre_quota_version_t version);
183 int lustre_check_quota_file(struct lustre_quota_info *lqi, int type);
184 int lustre_read_dquot(struct lustre_dquot *dquot);
185 int lustre_commit_dquot(struct lustre_dquot *dquot);
186 int lustre_init_quota_info(struct lustre_quota_info *lqi, int type);
187 int lustre_get_qids(struct file *fp, struct inode *inode, int type,
188 struct list_head *list);
190 #define LUSTRE_ADMIN_QUOTAFILES_V2 {\
191 "admin_quotafile_v2.usr", /* user admin quotafile */\
192 "admin_quotafile_v2.grp" /* group admin quotafile */\
195 #define LUSTRE_OPQFILES_NAMES_V2 { "lquota_v2.user", "lquota_v2.group" }
196 #endif /* lustre_quota_fmt.h */