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