Linux Audio

Check our new training course

Loading...
v4.17
 
  1/*
  2 *   Copyright (C) International Business Machines Corp., 2000-2002
  3 *
  4 *   This program is free software;  you can redistribute it and/or modify
  5 *   it under the terms of the GNU General Public License as published by
  6 *   the Free Software Foundation; either version 2 of the License, or
  7 *   (at your option) any later version.
  8 *
  9 *   This program is distributed in the hope that it will be useful,
 10 *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
 11 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
 12 *   the GNU General Public License for more details.
 13 *
 14 *   You should have received a copy of the GNU General Public License
 15 *   along with this program;  if not, write to the Free Software
 16 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 17 */
 18#ifndef	_H_JFS_DMAP
 19#define _H_JFS_DMAP
 20
 21#include "jfs_txnmgr.h"
 22
 23#define BMAPVERSION	1	/* version number */
 24#define	TREESIZE	(256+64+16+4+1)	/* size of a dmap tree */
 25#define	LEAFIND		(64+16+4+1)	/* index of 1st leaf of a dmap tree */
 26#define LPERDMAP	256	/* num leaves per dmap tree */
 27#define L2LPERDMAP	8	/* l2 number of leaves per dmap tree */
 28#define	DBWORD		32	/* # of blks covered by a map word */
 29#define	L2DBWORD	5	/* l2 # of blks covered by a mword */
 30#define BUDMIN		L2DBWORD	/* max free string in a map word */
 31#define BPERDMAP	(LPERDMAP * DBWORD)	/* num of blks per dmap */
 32#define L2BPERDMAP	13	/* l2 num of blks per dmap */
 33#define CTLTREESIZE	(1024+256+64+16+4+1)	/* size of a dmapctl tree */
 34#define CTLLEAFIND	(256+64+16+4+1)	/* idx of 1st leaf of a dmapctl tree */
 35#define LPERCTL		1024	/* num of leaves per dmapctl tree */
 36#define L2LPERCTL	10	/* l2 num of leaves per dmapctl tree */
 37#define	ROOT		0	/* index of the root of a tree */
 38#define	NOFREE		((s8) -1)	/* no blocks free */
 39#define	MAXAG		128	/* max number of allocation groups */
 40#define L2MAXAG		7	/* l2 max num of AG */
 41#define L2MINAGSZ	25	/* l2 of minimum AG size in bytes */
 42#define	BMAPBLKNO	0	/* lblkno of bmap within the map */
 43
 44/*
 45 * maximum l2 number of disk blocks at the various dmapctl levels.
 46 */
 47#define	L2MAXL0SIZE	(L2BPERDMAP + 1 * L2LPERCTL)
 48#define	L2MAXL1SIZE	(L2BPERDMAP + 2 * L2LPERCTL)
 49#define	L2MAXL2SIZE	(L2BPERDMAP + 3 * L2LPERCTL)
 50
 51/*
 52 * maximum number of disk blocks at the various dmapctl levels.
 53 */
 54#define	MAXL0SIZE	((s64)1 << L2MAXL0SIZE)
 55#define	MAXL1SIZE	((s64)1 << L2MAXL1SIZE)
 56#define	MAXL2SIZE	((s64)1 << L2MAXL2SIZE)
 57
 58#define	MAXMAPSIZE	MAXL2SIZE	/* maximum aggregate map size */
 59
 60/*
 61 * determine the maximum free string for four (lower level) nodes
 62 * of the tree.
 63 */
 64static inline signed char TREEMAX(signed char *cp)
 65{
 66	signed char tmp1, tmp2;
 67
 68	tmp1 = max(*(cp+2), *(cp+3));
 69	tmp2 = max(*(cp), *(cp+1));
 70
 71	return max(tmp1, tmp2);
 72}
 73
 74/*
 75 * convert disk block number to the logical block number of the dmap
 76 * describing the disk block.  s is the log2(number of logical blocks per page)
 77 *
 78 * The calculation figures out how many logical pages are in front of the dmap.
 79 *	- the number of dmaps preceding it
 80 *	- the number of L0 pages preceding its L0 page
 81 *	- the number of L1 pages preceding its L1 page
 82 *	- 3 is added to account for the L2, L1, and L0 page for this dmap
 83 *	- 1 is added to account for the control page of the map.
 84 */
 85#define BLKTODMAP(b,s)    \
 86	((((b) >> 13) + ((b) >> 23) + ((b) >> 33) + 3 + 1) << (s))
 87
 88/*
 89 * convert disk block number to the logical block number of the LEVEL 0
 90 * dmapctl describing the disk block.  s is the log2(number of logical blocks
 91 * per page)
 92 *
 93 * The calculation figures out how many logical pages are in front of the L0.
 94 *	- the number of dmap pages preceding it
 95 *	- the number of L0 pages preceding it
 96 *	- the number of L1 pages preceding its L1 page
 97 *	- 2 is added to account for the L2, and L1 page for this L0
 98 *	- 1 is added to account for the control page of the map.
 99 */
100#define BLKTOL0(b,s)      \
101	(((((b) >> 23) << 10) + ((b) >> 23) + ((b) >> 33) + 2 + 1) << (s))
102
103/*
104 * convert disk block number to the logical block number of the LEVEL 1
105 * dmapctl describing the disk block.  s is the log2(number of logical blocks
106 * per page)
107 *
108 * The calculation figures out how many logical pages are in front of the L1.
109 *	- the number of dmap pages preceding it
110 *	- the number of L0 pages preceding it
111 *	- the number of L1 pages preceding it
112 *	- 1 is added to account for the L2 page
113 *	- 1 is added to account for the control page of the map.
114 */
115#define BLKTOL1(b,s)      \
116     (((((b) >> 33) << 20) + (((b) >> 33) << 10) + ((b) >> 33) + 1 + 1) << (s))
117
118/*
119 * convert disk block number to the logical block number of the dmapctl
120 * at the specified level which describes the disk block.
121 */
122#define BLKTOCTL(b,s,l)   \
123	(((l) == 2) ? 1 : ((l) == 1) ? BLKTOL1((b),(s)) : BLKTOL0((b),(s)))
124
125/*
126 * convert aggregate map size to the zero origin dmapctl level of the
127 * top dmapctl.
128 */
129#define	BMAPSZTOLEV(size)	\
130	(((size) <= MAXL0SIZE) ? 0 : ((size) <= MAXL1SIZE) ? 1 : 2)
131
132/* convert disk block number to allocation group number.
133 */
134#define BLKTOAG(b,sbi)	((b) >> ((sbi)->bmap->db_agl2size))
135
136/* convert allocation group number to starting disk block
137 * number.
138 */
139#define AGTOBLK(a,ip)	\
140	((s64)(a) << (JFS_SBI((ip)->i_sb)->bmap->db_agl2size))
141
142/*
143 *	dmap summary tree
144 *
145 * dmaptree must be consistent with dmapctl.
146 */
147struct dmaptree {
148	__le32 nleafs;		/* 4: number of tree leafs	*/
149	__le32 l2nleafs;	/* 4: l2 number of tree leafs	*/
150	__le32 leafidx;		/* 4: index of first tree leaf	*/
151	__le32 height;		/* 4: height of the tree	*/
152	s8 budmin;		/* 1: min l2 tree leaf value to combine */
153	s8 stree[TREESIZE];	/* TREESIZE: tree		*/
154	u8 pad[2];		/* 2: pad to word boundary	*/
155};				/* - 360 -			*/
156
157/*
158 *	dmap page per 8K blocks bitmap
159 */
160struct dmap {
161	__le32 nblocks;		/* 4: num blks covered by this dmap	*/
162	__le32 nfree;		/* 4: num of free blks in this dmap	*/
163	__le64 start;		/* 8: starting blkno for this dmap	*/
164	struct dmaptree tree;	/* 360: dmap tree			*/
165	u8 pad[1672];		/* 1672: pad to 2048 bytes		*/
166	__le32 wmap[LPERDMAP];	/* 1024: bits of the working map	*/
167	__le32 pmap[LPERDMAP];	/* 1024: bits of the persistent map	*/
168};				/* - 4096 -				*/
169
170/*
171 *	disk map control page per level.
172 *
173 * dmapctl must be consistent with dmaptree.
174 */
175struct dmapctl {
176	__le32 nleafs;		/* 4: number of tree leafs	*/
177	__le32 l2nleafs;	/* 4: l2 number of tree leafs	*/
178	__le32 leafidx;		/* 4: index of the first tree leaf	*/
179	__le32 height;		/* 4: height of tree		*/
180	s8 budmin;		/* 1: minimum l2 tree leaf value	*/
181	s8 stree[CTLTREESIZE];	/* CTLTREESIZE: dmapctl tree	*/
182	u8 pad[2714];		/* 2714: pad to 4096		*/
183};				/* - 4096 -			*/
184
185/*
186 *	common definition for dmaptree within dmap and dmapctl
187 */
188typedef union dmtree {
189	struct dmaptree t1;
190	struct dmapctl t2;
191} dmtree_t;
192
193/* macros for accessing fields within dmtree */
194#define	dmt_nleafs	t1.nleafs
195#define	dmt_l2nleafs	t1.l2nleafs
196#define	dmt_leafidx	t1.leafidx
197#define	dmt_height	t1.height
198#define	dmt_budmin	t1.budmin
199#define	dmt_stree	t1.stree
200
201/*
202 *	on-disk aggregate disk allocation map descriptor.
203 */
204struct dbmap_disk {
205	__le64 dn_mapsize;	/* 8: number of blocks in aggregate	*/
206	__le64 dn_nfree;	/* 8: num free blks in aggregate map	*/
207	__le32 dn_l2nbperpage;	/* 4: number of blks per page		*/
208	__le32 dn_numag;	/* 4: total number of ags		*/
209	__le32 dn_maxlevel;	/* 4: number of active ags		*/
210	__le32 dn_maxag;	/* 4: max active alloc group number	*/
211	__le32 dn_agpref;	/* 4: preferred alloc group (hint)	*/
212	__le32 dn_aglevel;	/* 4: dmapctl level holding the AG	*/
213	__le32 dn_agheight;	/* 4: height in dmapctl of the AG	*/
214	__le32 dn_agwidth;	/* 4: width in dmapctl of the AG	*/
215	__le32 dn_agstart;	/* 4: start tree index at AG height	*/
216	__le32 dn_agl2size;	/* 4: l2 num of blks per alloc group	*/
217	__le64 dn_agfree[MAXAG];/* 8*MAXAG: per AG free count		*/
218	__le64 dn_agsize;	/* 8: num of blks per alloc group	*/
219	s8 dn_maxfreebud;	/* 1: max free buddy system		*/
220	u8 pad[3007];		/* 3007: pad to 4096			*/
221};				/* - 4096 -				*/
222
223struct dbmap {
224	s64 dn_mapsize;		/* number of blocks in aggregate	*/
225	s64 dn_nfree;		/* num free blks in aggregate map	*/
226	int dn_l2nbperpage;	/* number of blks per page		*/
227	int dn_numag;		/* total number of ags			*/
228	int dn_maxlevel;	/* number of active ags			*/
229	int dn_maxag;		/* max active alloc group number	*/
230	int dn_agpref;		/* preferred alloc group (hint)		*/
231	int dn_aglevel;		/* dmapctl level holding the AG		*/
232	int dn_agheight;	/* height in dmapctl of the AG		*/
233	int dn_agwidth;		/* width in dmapctl of the AG		*/
234	int dn_agstart;		/* start tree index at AG height	*/
235	int dn_agl2size;	/* l2 num of blks per alloc group	*/
236	s64 dn_agfree[MAXAG];	/* per AG free count			*/
237	s64 dn_agsize;		/* num of blks per alloc group		*/
238	signed char dn_maxfreebud;	/* max free buddy system	*/
239};				/* - 4096 -				*/
240/*
241 *	in-memory aggregate disk allocation map descriptor.
242 */
243struct bmap {
244	struct dbmap db_bmap;		/* on-disk aggregate map descriptor */
245	struct inode *db_ipbmap;	/* ptr to aggregate map incore inode */
246	struct mutex db_bmaplock;	/* aggregate map lock */
247	atomic_t db_active[MAXAG];	/* count of active, open files in AG */
248	u32 *db_DBmap;
249};
250
251/* macros for accessing fields within in-memory aggregate map descriptor */
252#define	db_mapsize	db_bmap.dn_mapsize
253#define	db_nfree	db_bmap.dn_nfree
254#define	db_agfree	db_bmap.dn_agfree
255#define	db_agsize	db_bmap.dn_agsize
256#define	db_agl2size	db_bmap.dn_agl2size
257#define	db_agwidth	db_bmap.dn_agwidth
258#define	db_agheight	db_bmap.dn_agheight
259#define	db_agstart	db_bmap.dn_agstart
260#define	db_numag	db_bmap.dn_numag
261#define	db_maxlevel	db_bmap.dn_maxlevel
262#define	db_aglevel	db_bmap.dn_aglevel
263#define	db_agpref	db_bmap.dn_agpref
264#define	db_maxag	db_bmap.dn_maxag
265#define	db_maxfreebud	db_bmap.dn_maxfreebud
266#define	db_l2nbperpage	db_bmap.dn_l2nbperpage
267
268/*
269 * macros for various conversions needed by the allocators.
270 * blkstol2(), cntlz(), and cnttz() are operating system dependent functions.
271 */
272/* convert number of blocks to log2 number of blocks, rounding up to
273 * the next log2 value if blocks is not a l2 multiple.
274 */
275#define	BLKSTOL2(d)		(blkstol2(d))
276
277/* convert number of leafs to log2 leaf value */
278#define	NLSTOL2BSZ(n)		(31 - cntlz((n)) + BUDMIN)
279
280/* convert leaf index to log2 leaf value */
281#define	LITOL2BSZ(n,m,b)	((((n) == 0) ? (m) : cnttz((n))) + (b))
282
283/* convert a block number to a dmap control leaf index */
284#define BLKTOCTLLEAF(b,m)	\
285	(((b) & (((s64)1 << ((m) + L2LPERCTL)) - 1)) >> (m))
286
287/* convert log2 leaf value to buddy size */
288#define	BUDSIZE(s,m)		(1 << ((s) - (m)))
289
290/*
291 *	external references.
292 */
293extern int dbMount(struct inode *ipbmap);
294
295extern int dbUnmount(struct inode *ipbmap, int mounterror);
296
297extern int dbFree(struct inode *ipbmap, s64 blkno, s64 nblocks);
298
299extern int dbUpdatePMap(struct inode *ipbmap,
300			int free, s64 blkno, s64 nblocks, struct tblock * tblk);
301
302extern int dbNextAG(struct inode *ipbmap);
303
304extern int dbAlloc(struct inode *ipbmap, s64 hint, s64 nblocks, s64 * results);
305
306extern int dbReAlloc(struct inode *ipbmap,
307		     s64 blkno, s64 nblocks, s64 addnblocks, s64 * results);
308
309extern int dbSync(struct inode *ipbmap);
310extern int dbAllocBottomUp(struct inode *ip, s64 blkno, s64 nblocks);
311extern int dbExtendFS(struct inode *ipbmap, s64 blkno, s64 nblocks);
312extern void dbFinalizeBmap(struct inode *ipbmap);
313extern s64 dbMapFileSizeToMapSize(struct inode *ipbmap);
314extern s64 dbDiscardAG(struct inode *ip, int agno, s64 minlen);
315
316#endif				/* _H_JFS_DMAP */
v6.13.7
  1/* SPDX-License-Identifier: GPL-2.0-or-later */
  2/*
  3 *   Copyright (C) International Business Machines Corp., 2000-2002
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  4 */
  5#ifndef	_H_JFS_DMAP
  6#define _H_JFS_DMAP
  7
  8#include "jfs_txnmgr.h"
  9
 10#define BMAPVERSION	1	/* version number */
 11#define	TREESIZE	(256+64+16+4+1)	/* size of a dmap tree */
 12#define	LEAFIND		(64+16+4+1)	/* index of 1st leaf of a dmap tree */
 13#define LPERDMAP	256	/* num leaves per dmap tree */
 14#define L2LPERDMAP	8	/* l2 number of leaves per dmap tree */
 15#define	DBWORD		32	/* # of blks covered by a map word */
 16#define	L2DBWORD	5	/* l2 # of blks covered by a mword */
 17#define BUDMIN		L2DBWORD	/* max free string in a map word */
 18#define BPERDMAP	(LPERDMAP * DBWORD)	/* num of blks per dmap */
 19#define L2BPERDMAP	13	/* l2 num of blks per dmap */
 20#define CTLTREESIZE	(1024+256+64+16+4+1)	/* size of a dmapctl tree */
 21#define CTLLEAFIND	(256+64+16+4+1)	/* idx of 1st leaf of a dmapctl tree */
 22#define LPERCTL		1024	/* num of leaves per dmapctl tree */
 23#define L2LPERCTL	10	/* l2 num of leaves per dmapctl tree */
 24#define	ROOT		0	/* index of the root of a tree */
 25#define	NOFREE		((s8) -1)	/* no blocks free */
 26#define	MAXAG		128	/* max number of allocation groups */
 27#define L2MAXAG		7	/* l2 max num of AG */
 28#define L2MINAGSZ	25	/* l2 of minimum AG size in bytes */
 29#define	BMAPBLKNO	0	/* lblkno of bmap within the map */
 30
 31/*
 32 * maximum l2 number of disk blocks at the various dmapctl levels.
 33 */
 34#define	L2MAXL0SIZE	(L2BPERDMAP + 1 * L2LPERCTL)
 35#define	L2MAXL1SIZE	(L2BPERDMAP + 2 * L2LPERCTL)
 36#define	L2MAXL2SIZE	(L2BPERDMAP + 3 * L2LPERCTL)
 37
 38/*
 39 * maximum number of disk blocks at the various dmapctl levels.
 40 */
 41#define	MAXL0SIZE	((s64)1 << L2MAXL0SIZE)
 42#define	MAXL1SIZE	((s64)1 << L2MAXL1SIZE)
 43#define	MAXL2SIZE	((s64)1 << L2MAXL2SIZE)
 44
 45#define	MAXMAPSIZE	MAXL2SIZE	/* maximum aggregate map size */
 46
 47/*
 48 * determine the maximum free string for four (lower level) nodes
 49 * of the tree.
 50 */
 51static inline signed char TREEMAX(signed char *cp)
 52{
 53	signed char tmp1, tmp2;
 54
 55	tmp1 = max(*(cp+2), *(cp+3));
 56	tmp2 = max(*(cp), *(cp+1));
 57
 58	return max(tmp1, tmp2);
 59}
 60
 61/*
 62 * convert disk block number to the logical block number of the dmap
 63 * describing the disk block.  s is the log2(number of logical blocks per page)
 64 *
 65 * The calculation figures out how many logical pages are in front of the dmap.
 66 *	- the number of dmaps preceding it
 67 *	- the number of L0 pages preceding its L0 page
 68 *	- the number of L1 pages preceding its L1 page
 69 *	- 3 is added to account for the L2, L1, and L0 page for this dmap
 70 *	- 1 is added to account for the control page of the map.
 71 */
 72#define BLKTODMAP(b,s)    \
 73	((((b) >> 13) + ((b) >> 23) + ((b) >> 33) + 3 + 1) << (s))
 74
 75/*
 76 * convert disk block number to the logical block number of the LEVEL 0
 77 * dmapctl describing the disk block.  s is the log2(number of logical blocks
 78 * per page)
 79 *
 80 * The calculation figures out how many logical pages are in front of the L0.
 81 *	- the number of dmap pages preceding it
 82 *	- the number of L0 pages preceding it
 83 *	- the number of L1 pages preceding its L1 page
 84 *	- 2 is added to account for the L2, and L1 page for this L0
 85 *	- 1 is added to account for the control page of the map.
 86 */
 87#define BLKTOL0(b,s)      \
 88	(((((b) >> 23) << 10) + ((b) >> 23) + ((b) >> 33) + 2 + 1) << (s))
 89
 90/*
 91 * convert disk block number to the logical block number of the LEVEL 1
 92 * dmapctl describing the disk block.  s is the log2(number of logical blocks
 93 * per page)
 94 *
 95 * The calculation figures out how many logical pages are in front of the L1.
 96 *	- the number of dmap pages preceding it
 97 *	- the number of L0 pages preceding it
 98 *	- the number of L1 pages preceding it
 99 *	- 1 is added to account for the L2 page
100 *	- 1 is added to account for the control page of the map.
101 */
102#define BLKTOL1(b,s)      \
103     (((((b) >> 33) << 20) + (((b) >> 33) << 10) + ((b) >> 33) + 1 + 1) << (s))
104
105/*
106 * convert disk block number to the logical block number of the dmapctl
107 * at the specified level which describes the disk block.
108 */
109#define BLKTOCTL(b,s,l)   \
110	(((l) == 2) ? 1 : ((l) == 1) ? BLKTOL1((b),(s)) : BLKTOL0((b),(s)))
111
112/*
113 * convert aggregate map size to the zero origin dmapctl level of the
114 * top dmapctl.
115 */
116#define	BMAPSZTOLEV(size)	\
117	(((size) <= MAXL0SIZE) ? 0 : ((size) <= MAXL1SIZE) ? 1 : 2)
118
119/* convert disk block number to allocation group number.
120 */
121#define BLKTOAG(b,sbi)	((b) >> ((sbi)->bmap->db_agl2size))
122
123/* convert allocation group number to starting disk block
124 * number.
125 */
126#define AGTOBLK(a,ip)	\
127	((s64)(a) << (JFS_SBI((ip)->i_sb)->bmap->db_agl2size))
128
129/*
130 *	dmap summary tree
131 *
132 * dmaptree must be consistent with dmapctl.
133 */
134struct dmaptree {
135	__le32 nleafs;		/* 4: number of tree leafs	*/
136	__le32 l2nleafs;	/* 4: l2 number of tree leafs	*/
137	__le32 leafidx;		/* 4: index of first tree leaf	*/
138	__le32 height;		/* 4: height of the tree	*/
139	s8 budmin;		/* 1: min l2 tree leaf value to combine */
140	s8 stree[TREESIZE];	/* TREESIZE: tree		*/
141	u8 pad[2];		/* 2: pad to word boundary	*/
142};				/* - 360 -			*/
143
144/*
145 *	dmap page per 8K blocks bitmap
146 */
147struct dmap {
148	__le32 nblocks;		/* 4: num blks covered by this dmap	*/
149	__le32 nfree;		/* 4: num of free blks in this dmap	*/
150	__le64 start;		/* 8: starting blkno for this dmap	*/
151	struct dmaptree tree;	/* 360: dmap tree			*/
152	u8 pad[1672];		/* 1672: pad to 2048 bytes		*/
153	__le32 wmap[LPERDMAP];	/* 1024: bits of the working map	*/
154	__le32 pmap[LPERDMAP];	/* 1024: bits of the persistent map	*/
155};				/* - 4096 -				*/
156
157/*
158 *	disk map control page per level.
159 *
160 * dmapctl must be consistent with dmaptree.
161 */
162struct dmapctl {
163	__le32 nleafs;		/* 4: number of tree leafs	*/
164	__le32 l2nleafs;	/* 4: l2 number of tree leafs	*/
165	__le32 leafidx;		/* 4: index of the first tree leaf	*/
166	__le32 height;		/* 4: height of tree		*/
167	s8 budmin;		/* 1: minimum l2 tree leaf value	*/
168	s8 stree[CTLTREESIZE];	/* CTLTREESIZE: dmapctl tree	*/
169	u8 pad[2714];		/* 2714: pad to 4096		*/
170};				/* - 4096 -			*/
171
172/*
173 *	common definition for dmaptree within dmap and dmapctl
174 */
175typedef union dmtree {
176	struct dmaptree t1;
177	struct dmapctl t2;
178} dmtree_t;
179
180/* macros for accessing fields within dmtree */
181#define	dmt_nleafs	t1.nleafs
182#define	dmt_l2nleafs	t1.l2nleafs
183#define	dmt_leafidx	t1.leafidx
184#define	dmt_height	t1.height
185#define	dmt_budmin	t1.budmin
186#define	dmt_stree	t2.stree
187
188/*
189 *	on-disk aggregate disk allocation map descriptor.
190 */
191struct dbmap_disk {
192	__le64 dn_mapsize;	/* 8: number of blocks in aggregate	*/
193	__le64 dn_nfree;	/* 8: num free blks in aggregate map	*/
194	__le32 dn_l2nbperpage;	/* 4: number of blks per page		*/
195	__le32 dn_numag;	/* 4: total number of ags		*/
196	__le32 dn_maxlevel;	/* 4: number of active ags		*/
197	__le32 dn_maxag;	/* 4: max active alloc group number	*/
198	__le32 dn_agpref;	/* 4: preferred alloc group (hint)	*/
199	__le32 dn_aglevel;	/* 4: dmapctl level holding the AG	*/
200	__le32 dn_agheight;	/* 4: height in dmapctl of the AG	*/
201	__le32 dn_agwidth;	/* 4: width in dmapctl of the AG	*/
202	__le32 dn_agstart;	/* 4: start tree index at AG height	*/
203	__le32 dn_agl2size;	/* 4: l2 num of blks per alloc group	*/
204	__le64 dn_agfree[MAXAG];/* 8*MAXAG: per AG free count		*/
205	__le64 dn_agsize;	/* 8: num of blks per alloc group	*/
206	s8 dn_maxfreebud;	/* 1: max free buddy system		*/
207	u8 pad[3007];		/* 3007: pad to 4096			*/
208};				/* - 4096 -				*/
209
210struct dbmap {
211	s64 dn_mapsize;		/* number of blocks in aggregate	*/
212	s64 dn_nfree;		/* num free blks in aggregate map	*/
213	int dn_l2nbperpage;	/* number of blks per page		*/
214	int dn_numag;		/* total number of ags			*/
215	int dn_maxlevel;	/* number of active ags			*/
216	int dn_maxag;		/* max active alloc group number	*/
217	int dn_agpref;		/* preferred alloc group (hint)		*/
218	int dn_aglevel;		/* dmapctl level holding the AG		*/
219	int dn_agheight;	/* height in dmapctl of the AG		*/
220	int dn_agwidth;		/* width in dmapctl of the AG		*/
221	int dn_agstart;		/* start tree index at AG height	*/
222	int dn_agl2size;	/* l2 num of blks per alloc group	*/
223	s64 dn_agfree[MAXAG];	/* per AG free count			*/
224	s64 dn_agsize;		/* num of blks per alloc group		*/
225	signed char dn_maxfreebud;	/* max free buddy system	*/
226};				/* - 4096 -				*/
227/*
228 *	in-memory aggregate disk allocation map descriptor.
229 */
230struct bmap {
231	struct dbmap db_bmap;		/* on-disk aggregate map descriptor */
232	struct inode *db_ipbmap;	/* ptr to aggregate map incore inode */
233	struct mutex db_bmaplock;	/* aggregate map lock */
234	atomic_t db_active[MAXAG];	/* count of active, open files in AG */
235	u32 *db_DBmap;
236};
237
238/* macros for accessing fields within in-memory aggregate map descriptor */
239#define	db_mapsize	db_bmap.dn_mapsize
240#define	db_nfree	db_bmap.dn_nfree
241#define	db_agfree	db_bmap.dn_agfree
242#define	db_agsize	db_bmap.dn_agsize
243#define	db_agl2size	db_bmap.dn_agl2size
244#define	db_agwidth	db_bmap.dn_agwidth
245#define	db_agheight	db_bmap.dn_agheight
246#define	db_agstart	db_bmap.dn_agstart
247#define	db_numag	db_bmap.dn_numag
248#define	db_maxlevel	db_bmap.dn_maxlevel
249#define	db_aglevel	db_bmap.dn_aglevel
250#define	db_agpref	db_bmap.dn_agpref
251#define	db_maxag	db_bmap.dn_maxag
252#define	db_maxfreebud	db_bmap.dn_maxfreebud
253#define	db_l2nbperpage	db_bmap.dn_l2nbperpage
254
255/*
256 * macros for various conversions needed by the allocators.
257 * blkstol2(), cntlz(), and cnttz() are operating system dependent functions.
258 */
259/* convert number of blocks to log2 number of blocks, rounding up to
260 * the next log2 value if blocks is not a l2 multiple.
261 */
262#define	BLKSTOL2(d)		(blkstol2(d))
263
264/* convert number of leafs to log2 leaf value */
265#define	NLSTOL2BSZ(n)		(31 - cntlz((n)) + BUDMIN)
266
267/* convert leaf index to log2 leaf value */
268#define	LITOL2BSZ(n,m,b)	((((n) == 0) ? (m) : cnttz((n))) + (b))
269
270/* convert a block number to a dmap control leaf index */
271#define BLKTOCTLLEAF(b,m)	\
272	(((b) & (((s64)1 << ((m) + L2LPERCTL)) - 1)) >> (m))
273
274/* convert log2 leaf value to buddy size */
275#define	BUDSIZE(s,m)		(1 << ((s) - (m)))
276
277/*
278 *	external references.
279 */
280extern int dbMount(struct inode *ipbmap);
281
282extern int dbUnmount(struct inode *ipbmap, int mounterror);
283
284extern int dbFree(struct inode *ipbmap, s64 blkno, s64 nblocks);
285
286extern int dbUpdatePMap(struct inode *ipbmap,
287			int free, s64 blkno, s64 nblocks, struct tblock * tblk);
288
289extern int dbNextAG(struct inode *ipbmap);
290
291extern int dbAlloc(struct inode *ipbmap, s64 hint, s64 nblocks, s64 * results);
292
293extern int dbReAlloc(struct inode *ipbmap,
294		     s64 blkno, s64 nblocks, s64 addnblocks, s64 * results);
295
296extern int dbSync(struct inode *ipbmap);
297extern int dbAllocBottomUp(struct inode *ip, s64 blkno, s64 nblocks);
298extern int dbExtendFS(struct inode *ipbmap, s64 blkno, s64 nblocks);
299extern void dbFinalizeBmap(struct inode *ipbmap);
300extern s64 dbMapFileSizeToMapSize(struct inode *ipbmap);
301extern s64 dbDiscardAG(struct inode *ip, int agno, s64 minlen);
302
303#endif				/* _H_JFS_DMAP */