Whamcloud - gitweb
b=23003 use obd_time instead of __u64 to store "wallclock" time
[fs/lustre-release.git] / lustre / lvfs / lustre_quota_fmt.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
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.
11  *
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).
17  *
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
21  *
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
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/lvfs/lustre_quota_fmt.h
37  *
38  * Lustre administrative quota format
39  * from include/linux/quotaio_v2.h
40  */
41 #ifndef _LUSTRE_QUOTA_FMT_H
42 #define _LUSTRE_QUOTA_FMT_H
43
44 #ifdef HAVE_QUOTA_SUPPORT
45
46 #include <linux/types.h>
47 #include <linux/quota.h>
48
49 /*
50  * Definitions of magics and versions of current quota files
51  * Same with quota v2's magic
52  */
53 #define LUSTRE_INITQMAGICS {\
54         0xd9c01f11,     /** USRQUOTA */\
55         0xd9c01927      /** GRPQUOTA */\
56 }
57
58 /* Invalid magics that mark quota file as inconsistent */
59 #define LUSTRE_BADQMAGICS {\
60         0xbadbadba,     /** USRQUOTA */\
61         0xbadbadba      /** GRPQUOTA */\
62 }
63
64 /* for the verson 2 of lustre_disk_dqblk*/
65 #define LUSTRE_INITQVERSIONS_V2 {\
66         1,              /* USRQUOTA */\
67         1               /* GRPQUOTA */\
68 }
69
70 /*
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.
74  */
75 struct lustre_disk_dqblk_v2 {
76         __u32 dqb_id;           /**< id this quota applies to */
77         __u32 padding;
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         obd_time dqb_btime;        /**< time limit for excessive disk use */
85         obd_time dqb_itime;        /**< time limit for excessive inode use */
86 };
87
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))
93
94 #define GETENTRIES(buf,version) ((version == LUSTRE_QUOTA_V2) ? \
95                                 GETENTRIES_V2(buf) : 0)
96
97 /*
98  * Here are header structures as written on disk and their in-memory copies
99  */
100 /* First generic header */
101 struct lustre_disk_dqheader {
102         __u32 dqh_magic;        /* Magic number identifying file */
103         __u32 dqh_version;      /* File version */
104 };
105
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 */
114 };
115
116 /*
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
119  */
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 */
124         __u16 dqdh_pad1;
125         __u32 dqdh_pad2;
126 };
127
128 #ifdef LPROCFS
129 void lprocfs_quotfmt_test_init_vars(struct lprocfs_static_vars *lvars);
130 #else
131 static void lprocfs_quotfmt_test_init_vars(struct lprocfs_static_vars *lvars) {}
132 #endif
133
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 */
139
140 typedef char *dqbuf_t;
141
142 #define GETIDINDEX(id, depth) (((id) >> ((LUSTRE_DQTREEDEPTH-(depth)-1)*8)) & 0xff)
143
144 #define MAX_UL (0xffffffffUL)
145
146 #define lustre_info_dirty(info) \
147         cfs_test_bit(DQF_INFO_DIRTY_B, &(info)->dqi_flags)
148
149 struct dqblk {
150         cfs_list_t link;
151         uint blk;
152 };
153
154 /* come from lustre_fmt_common.c */
155 dqbuf_t getdqbuf(void);
156 void freedqbuf(dqbuf_t buf);
157 void disk2memdqb(struct lustre_mem_dqblk *m, void *d,
158                         enum lustre_quota_version version);
159 void lustre_mark_info_dirty(struct lustre_mem_dqinfo *info);
160 int lustre_init_quota_header(struct lustre_quota_info *lqi, int type, 
161                              int fakemagics);
162 int lustre_init_quota_info_generic(struct lustre_quota_info *lqi, int type,
163                                    int fakemagics);
164 int lustre_read_quota_info(struct lustre_quota_info *lqi, int type);
165 int lustre_read_quota_file_info(struct file* f, struct lustre_mem_dqinfo* info);
166 int lustre_write_quota_info(struct lustre_quota_info *lqi, int type);
167 int get_free_dqblk(struct file *filp, struct lustre_mem_dqinfo *info);
168 int put_free_dqblk(struct file *filp, struct lustre_mem_dqinfo *info,
169                           dqbuf_t buf, uint blk);
170 int remove_free_dqentry(struct file *filp,
171                                struct lustre_mem_dqinfo *info, dqbuf_t buf,
172                                uint blk);
173 int insert_free_dqentry(struct file *filp,
174                                struct lustre_mem_dqinfo *info, dqbuf_t buf,
175                                uint blk);
176 ssize_t quota_read(struct file *file, struct inode *inode, int type,
177                    uint blk, dqbuf_t buf);
178 int walk_tree_dqentry(struct file *filp, struct inode *inode, int type,
179                       uint blk, int depth, cfs_list_t *list);
180 int check_quota_file(struct file *f, struct inode *inode, int type,
181                      lustre_quota_version_t version);
182 int lustre_check_quota_file(struct lustre_quota_info *lqi, int type);
183 int lustre_read_dquot(struct lustre_dquot *dquot);
184 int lustre_commit_dquot(struct lustre_dquot *dquot);
185 int lustre_init_quota_info(struct lustre_quota_info *lqi, int type);
186 int lustre_get_qids(struct file *fp, struct inode *inode, int type,
187                     cfs_list_t *list);
188 ssize_t lustre_read_quota(struct file *f, struct inode *inode, int type,
189                           char *buf, int count, loff_t pos);
190
191 #define LUSTRE_ADMIN_QUOTAFILES_V2 {\
192         "admin_quotafile_v2.usr",       /* user admin quotafile */\
193         "admin_quotafile_v2.grp"        /* group admin quotafile */\
194 }
195
196 #define LUSTRE_OPQFILES_NAMES_V2 { "lquota_v2.user", "lquota_v2.group" }
197 #endif                          /* lustre_quota_fmt.h */
198 #endif