xref: /OK3568_Linux_fs/kernel/fs/jfs/jfs_imap.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  *   Copyright (C) International Business Machines Corp., 2000-2002
4*4882a593Smuzhiyun  */
5*4882a593Smuzhiyun #ifndef	_H_JFS_IMAP
6*4882a593Smuzhiyun #define _H_JFS_IMAP
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun #include "jfs_txnmgr.h"
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun /*
11*4882a593Smuzhiyun  *	jfs_imap.h: disk inode manager
12*4882a593Smuzhiyun  */
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun #define	EXTSPERIAG	128	/* number of disk inode extent per iag	*/
15*4882a593Smuzhiyun #define IMAPBLKNO	0	/* lblkno of dinomap within inode map	*/
16*4882a593Smuzhiyun #define SMAPSZ		4	/* number of words per summary map	*/
17*4882a593Smuzhiyun #define	EXTSPERSUM	32	/* number of extents per summary map entry */
18*4882a593Smuzhiyun #define	L2EXTSPERSUM	5	/* l2 number of extents per summary map */
19*4882a593Smuzhiyun #define	PGSPERIEXT	4	/* number of 4K pages per dinode extent */
20*4882a593Smuzhiyun #define	MAXIAGS		((1<<20)-1)	/* maximum number of iags	*/
21*4882a593Smuzhiyun #define	MAXAG		128	/* maximum number of allocation groups	*/
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun #define AMAPSIZE	512	/* bytes in the IAG allocation maps */
24*4882a593Smuzhiyun #define SMAPSIZE	16	/* bytes in the IAG summary maps */
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun /* convert inode number to iag number */
27*4882a593Smuzhiyun #define	INOTOIAG(ino)	((ino) >> L2INOSPERIAG)
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun /* convert iag number to logical block number of the iag page */
30*4882a593Smuzhiyun #define IAGTOLBLK(iagno,l2nbperpg)	(((iagno) + 1) << (l2nbperpg))
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun /* get the starting block number of the 4K page of an inode extent
33*4882a593Smuzhiyun  * that contains ino.
34*4882a593Smuzhiyun  */
35*4882a593Smuzhiyun #define INOPBLK(pxd,ino,l2nbperpg)	(addressPXD((pxd)) +		\
36*4882a593Smuzhiyun 	((((ino) & (INOSPEREXT-1)) >> L2INOSPERPAGE) << (l2nbperpg)))
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun /*
39*4882a593Smuzhiyun  *	inode allocation map:
40*4882a593Smuzhiyun  *
41*4882a593Smuzhiyun  * inode allocation map consists of
42*4882a593Smuzhiyun  * . the inode map control page and
43*4882a593Smuzhiyun  * . inode allocation group pages (per 4096 inodes)
44*4882a593Smuzhiyun  * which are addressed by standard JFS xtree.
45*4882a593Smuzhiyun  */
46*4882a593Smuzhiyun /*
47*4882a593Smuzhiyun  *	inode allocation group page (per 4096 inodes of an AG)
48*4882a593Smuzhiyun  */
49*4882a593Smuzhiyun struct iag {
50*4882a593Smuzhiyun 	__le64 agstart;		/* 8: starting block of ag		*/
51*4882a593Smuzhiyun 	__le32 iagnum;		/* 4: inode allocation group number	*/
52*4882a593Smuzhiyun 	__le32 inofreefwd;	/* 4: ag inode free list forward	*/
53*4882a593Smuzhiyun 	__le32 inofreeback;	/* 4: ag inode free list back		*/
54*4882a593Smuzhiyun 	__le32 extfreefwd;	/* 4: ag inode extent free list forward	*/
55*4882a593Smuzhiyun 	__le32 extfreeback;	/* 4: ag inode extent free list back	*/
56*4882a593Smuzhiyun 	__le32 iagfree;		/* 4: iag free list			*/
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun 	/* summary map: 1 bit per inode extent */
59*4882a593Smuzhiyun 	__le32 inosmap[SMAPSZ];	/* 16: sum map of mapwords w/ free inodes;
60*4882a593Smuzhiyun 				 *	note: this indicates free and backed
61*4882a593Smuzhiyun 				 *	inodes, if the extent is not backed the
62*4882a593Smuzhiyun 				 *	value will be 1.  if the extent is
63*4882a593Smuzhiyun 				 *	backed but all inodes are being used the
64*4882a593Smuzhiyun 				 *	value will be 1.  if the extent is
65*4882a593Smuzhiyun 				 *	backed but at least one of the inodes is
66*4882a593Smuzhiyun 				 *	free the value will be 0.
67*4882a593Smuzhiyun 				 */
68*4882a593Smuzhiyun 	__le32 extsmap[SMAPSZ];	/* 16: sum map of mapwords w/ free extents */
69*4882a593Smuzhiyun 	__le32 nfreeinos;	/* 4: number of free inodes		*/
70*4882a593Smuzhiyun 	__le32 nfreeexts;	/* 4: number of free extents		*/
71*4882a593Smuzhiyun 	/* (72) */
72*4882a593Smuzhiyun 	u8 pad[1976];		/* 1976: pad to 2048 bytes */
73*4882a593Smuzhiyun 	/* allocation bit map: 1 bit per inode (0 - free, 1 - allocated) */
74*4882a593Smuzhiyun 	__le32 wmap[EXTSPERIAG];	/* 512: working allocation map */
75*4882a593Smuzhiyun 	__le32 pmap[EXTSPERIAG];	/* 512: persistent allocation map */
76*4882a593Smuzhiyun 	pxd_t inoext[EXTSPERIAG];	/* 1024: inode extent addresses */
77*4882a593Smuzhiyun };				/* (4096) */
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun /*
80*4882a593Smuzhiyun  *	per AG control information (in inode map control page)
81*4882a593Smuzhiyun  */
82*4882a593Smuzhiyun struct iagctl_disk {
83*4882a593Smuzhiyun 	__le32 inofree;		/* 4: free inode list anchor		*/
84*4882a593Smuzhiyun 	__le32 extfree;		/* 4: free extent list anchor		*/
85*4882a593Smuzhiyun 	__le32 numinos;		/* 4: number of backed inodes		*/
86*4882a593Smuzhiyun 	__le32 numfree;		/* 4: number of free inodes		*/
87*4882a593Smuzhiyun };				/* (16) */
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun struct iagctl {
90*4882a593Smuzhiyun 	int inofree;		/* free inode list anchor		*/
91*4882a593Smuzhiyun 	int extfree;		/* free extent list anchor		*/
92*4882a593Smuzhiyun 	int numinos;		/* number of backed inodes		*/
93*4882a593Smuzhiyun 	int numfree;		/* number of free inodes		*/
94*4882a593Smuzhiyun };
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun /*
97*4882a593Smuzhiyun  *	per fileset/aggregate inode map control page
98*4882a593Smuzhiyun  */
99*4882a593Smuzhiyun struct dinomap_disk {
100*4882a593Smuzhiyun 	__le32 in_freeiag;	/* 4: free iag list anchor	*/
101*4882a593Smuzhiyun 	__le32 in_nextiag;	/* 4: next free iag number	*/
102*4882a593Smuzhiyun 	__le32 in_numinos;	/* 4: num of backed inodes	*/
103*4882a593Smuzhiyun 	__le32 in_numfree;	/* 4: num of free backed inodes */
104*4882a593Smuzhiyun 	__le32 in_nbperiext;	/* 4: num of blocks per inode extent */
105*4882a593Smuzhiyun 	__le32 in_l2nbperiext;	/* 4: l2 of in_nbperiext	*/
106*4882a593Smuzhiyun 	__le32 in_diskblock;	/* 4: for standalone test driver */
107*4882a593Smuzhiyun 	__le32 in_maxag;	/* 4: for standalone test driver */
108*4882a593Smuzhiyun 	u8 pad[2016];		/* 2016: pad to 2048		*/
109*4882a593Smuzhiyun 	struct iagctl_disk in_agctl[MAXAG]; /* 2048: AG control information */
110*4882a593Smuzhiyun };				/* (4096) */
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun struct dinomap {
113*4882a593Smuzhiyun 	int in_freeiag;		/* free iag list anchor		*/
114*4882a593Smuzhiyun 	int in_nextiag;		/* next free iag number		*/
115*4882a593Smuzhiyun 	int in_numinos;		/* num of backed inodes		*/
116*4882a593Smuzhiyun 	int in_numfree;		/* num of free backed inodes	*/
117*4882a593Smuzhiyun 	int in_nbperiext;	/* num of blocks per inode extent */
118*4882a593Smuzhiyun 	int in_l2nbperiext;	/* l2 of in_nbperiext		*/
119*4882a593Smuzhiyun 	int in_diskblock;	/* for standalone test driver	*/
120*4882a593Smuzhiyun 	int in_maxag;		/* for standalone test driver	*/
121*4882a593Smuzhiyun 	struct iagctl in_agctl[MAXAG];	/* AG control information */
122*4882a593Smuzhiyun };
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun /*
125*4882a593Smuzhiyun  *	In-core inode map control page
126*4882a593Smuzhiyun  */
127*4882a593Smuzhiyun struct inomap {
128*4882a593Smuzhiyun 	struct dinomap im_imap;		/* 4096: inode allocation control */
129*4882a593Smuzhiyun 	struct inode *im_ipimap;	/* 4: ptr to inode for imap	*/
130*4882a593Smuzhiyun 	struct mutex im_freelock;	/* 4: iag free list lock	*/
131*4882a593Smuzhiyun 	struct mutex im_aglock[MAXAG];	/* 512: per AG locks		*/
132*4882a593Smuzhiyun 	u32 *im_DBGdimap;
133*4882a593Smuzhiyun 	atomic_t im_numinos;	/* num of backed inodes */
134*4882a593Smuzhiyun 	atomic_t im_numfree;	/* num of free backed inodes */
135*4882a593Smuzhiyun };
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun #define	im_freeiag	im_imap.in_freeiag
138*4882a593Smuzhiyun #define	im_nextiag	im_imap.in_nextiag
139*4882a593Smuzhiyun #define	im_agctl	im_imap.in_agctl
140*4882a593Smuzhiyun #define	im_nbperiext	im_imap.in_nbperiext
141*4882a593Smuzhiyun #define	im_l2nbperiext	im_imap.in_l2nbperiext
142*4882a593Smuzhiyun 
143*4882a593Smuzhiyun /* for standalone testdriver
144*4882a593Smuzhiyun  */
145*4882a593Smuzhiyun #define	im_diskblock	im_imap.in_diskblock
146*4882a593Smuzhiyun #define	im_maxag	im_imap.in_maxag
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun extern int diFree(struct inode *);
149*4882a593Smuzhiyun extern int diAlloc(struct inode *, bool, struct inode *);
150*4882a593Smuzhiyun extern int diSync(struct inode *);
151*4882a593Smuzhiyun /* external references */
152*4882a593Smuzhiyun extern int diUpdatePMap(struct inode *ipimap, unsigned long inum,
153*4882a593Smuzhiyun 			bool is_free, struct tblock * tblk);
154*4882a593Smuzhiyun extern int diExtendFS(struct inode *ipimap, struct inode *ipbmap);
155*4882a593Smuzhiyun extern int diMount(struct inode *);
156*4882a593Smuzhiyun extern int diUnmount(struct inode *, int);
157*4882a593Smuzhiyun extern int diRead(struct inode *);
158*4882a593Smuzhiyun extern struct inode *diReadSpecial(struct super_block *, ino_t, int);
159*4882a593Smuzhiyun extern void diWriteSpecial(struct inode *, int);
160*4882a593Smuzhiyun extern void diFreeSpecial(struct inode *);
161*4882a593Smuzhiyun extern int diWrite(tid_t tid, struct inode *);
162*4882a593Smuzhiyun #endif				/* _H_JFS_IMAP */
163