jfs_dmap.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:11k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

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