Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  *   Copyright (C) International Business Machines Corp., 2000-2002
0004  */
0005 #ifndef _H_JFS_DMAP
0006 #define _H_JFS_DMAP
0007 
0008 #include "jfs_txnmgr.h"
0009 
0010 #define BMAPVERSION 1   /* version number */
0011 #define TREESIZE    (256+64+16+4+1) /* size of a dmap tree */
0012 #define LEAFIND     (64+16+4+1) /* index of 1st leaf of a dmap tree */
0013 #define LPERDMAP    256 /* num leaves per dmap tree */
0014 #define L2LPERDMAP  8   /* l2 number of leaves per dmap tree */
0015 #define DBWORD      32  /* # of blks covered by a map word */
0016 #define L2DBWORD    5   /* l2 # of blks covered by a mword */
0017 #define BUDMIN      L2DBWORD    /* max free string in a map word */
0018 #define BPERDMAP    (LPERDMAP * DBWORD) /* num of blks per dmap */
0019 #define L2BPERDMAP  13  /* l2 num of blks per dmap */
0020 #define CTLTREESIZE (1024+256+64+16+4+1)    /* size of a dmapctl tree */
0021 #define CTLLEAFIND  (256+64+16+4+1) /* idx of 1st leaf of a dmapctl tree */
0022 #define LPERCTL     1024    /* num of leaves per dmapctl tree */
0023 #define L2LPERCTL   10  /* l2 num of leaves per dmapctl tree */
0024 #define ROOT        0   /* index of the root of a tree */
0025 #define NOFREE      ((s8) -1)   /* no blocks free */
0026 #define MAXAG       128 /* max number of allocation groups */
0027 #define L2MAXAG     7   /* l2 max num of AG */
0028 #define L2MINAGSZ   25  /* l2 of minimum AG size in bytes */
0029 #define BMAPBLKNO   0   /* lblkno of bmap within the map */
0030 
0031 /*
0032  * maximum l2 number of disk blocks at the various dmapctl levels.
0033  */
0034 #define L2MAXL0SIZE (L2BPERDMAP + 1 * L2LPERCTL)
0035 #define L2MAXL1SIZE (L2BPERDMAP + 2 * L2LPERCTL)
0036 #define L2MAXL2SIZE (L2BPERDMAP + 3 * L2LPERCTL)
0037 
0038 /*
0039  * maximum number of disk blocks at the various dmapctl levels.
0040  */
0041 #define MAXL0SIZE   ((s64)1 << L2MAXL0SIZE)
0042 #define MAXL1SIZE   ((s64)1 << L2MAXL1SIZE)
0043 #define MAXL2SIZE   ((s64)1 << L2MAXL2SIZE)
0044 
0045 #define MAXMAPSIZE  MAXL2SIZE   /* maximum aggregate map size */
0046 
0047 /*
0048  * determine the maximum free string for four (lower level) nodes
0049  * of the tree.
0050  */
0051 static inline signed char TREEMAX(signed char *cp)
0052 {
0053     signed char tmp1, tmp2;
0054 
0055     tmp1 = max(*(cp+2), *(cp+3));
0056     tmp2 = max(*(cp), *(cp+1));
0057 
0058     return max(tmp1, tmp2);
0059 }
0060 
0061 /*
0062  * convert disk block number to the logical block number of the dmap
0063  * describing the disk block.  s is the log2(number of logical blocks per page)
0064  *
0065  * The calculation figures out how many logical pages are in front of the dmap.
0066  *  - the number of dmaps preceding it
0067  *  - the number of L0 pages preceding its L0 page
0068  *  - the number of L1 pages preceding its L1 page
0069  *  - 3 is added to account for the L2, L1, and L0 page for this dmap
0070  *  - 1 is added to account for the control page of the map.
0071  */
0072 #define BLKTODMAP(b,s)    \
0073     ((((b) >> 13) + ((b) >> 23) + ((b) >> 33) + 3 + 1) << (s))
0074 
0075 /*
0076  * convert disk block number to the logical block number of the LEVEL 0
0077  * dmapctl describing the disk block.  s is the log2(number of logical blocks
0078  * per page)
0079  *
0080  * The calculation figures out how many logical pages are in front of the L0.
0081  *  - the number of dmap pages preceding it
0082  *  - the number of L0 pages preceding it
0083  *  - the number of L1 pages preceding its L1 page
0084  *  - 2 is added to account for the L2, and L1 page for this L0
0085  *  - 1 is added to account for the control page of the map.
0086  */
0087 #define BLKTOL0(b,s)      \
0088     (((((b) >> 23) << 10) + ((b) >> 23) + ((b) >> 33) + 2 + 1) << (s))
0089 
0090 /*
0091  * convert disk block number to the logical block number of the LEVEL 1
0092  * dmapctl describing the disk block.  s is the log2(number of logical blocks
0093  * per page)
0094  *
0095  * The calculation figures out how many logical pages are in front of the L1.
0096  *  - the number of dmap pages preceding it
0097  *  - the number of L0 pages preceding it
0098  *  - the number of L1 pages preceding it
0099  *  - 1 is added to account for the L2 page
0100  *  - 1 is added to account for the control page of the map.
0101  */
0102 #define BLKTOL1(b,s)      \
0103      (((((b) >> 33) << 20) + (((b) >> 33) << 10) + ((b) >> 33) + 1 + 1) << (s))
0104 
0105 /*
0106  * convert disk block number to the logical block number of the dmapctl
0107  * at the specified level which describes the disk block.
0108  */
0109 #define BLKTOCTL(b,s,l)   \
0110     (((l) == 2) ? 1 : ((l) == 1) ? BLKTOL1((b),(s)) : BLKTOL0((b),(s)))
0111 
0112 /*
0113  * convert aggregate map size to the zero origin dmapctl level of the
0114  * top dmapctl.
0115  */
0116 #define BMAPSZTOLEV(size)   \
0117     (((size) <= MAXL0SIZE) ? 0 : ((size) <= MAXL1SIZE) ? 1 : 2)
0118 
0119 /* convert disk block number to allocation group number.
0120  */
0121 #define BLKTOAG(b,sbi)  ((b) >> ((sbi)->bmap->db_agl2size))
0122 
0123 /* convert allocation group number to starting disk block
0124  * number.
0125  */
0126 #define AGTOBLK(a,ip)   \
0127     ((s64)(a) << (JFS_SBI((ip)->i_sb)->bmap->db_agl2size))
0128 
0129 /*
0130  *  dmap summary tree
0131  *
0132  * dmaptree must be consistent with dmapctl.
0133  */
0134 struct dmaptree {
0135     __le32 nleafs;      /* 4: number of tree leafs  */
0136     __le32 l2nleafs;    /* 4: l2 number of tree leafs   */
0137     __le32 leafidx;     /* 4: index of first tree leaf  */
0138     __le32 height;      /* 4: height of the tree    */
0139     s8 budmin;      /* 1: min l2 tree leaf value to combine */
0140     s8 stree[TREESIZE]; /* TREESIZE: tree       */
0141     u8 pad[2];      /* 2: pad to word boundary  */
0142 };              /* - 360 -          */
0143 
0144 /*
0145  *  dmap page per 8K blocks bitmap
0146  */
0147 struct dmap {
0148     __le32 nblocks;     /* 4: num blks covered by this dmap */
0149     __le32 nfree;       /* 4: num of free blks in this dmap */
0150     __le64 start;       /* 8: starting blkno for this dmap  */
0151     struct dmaptree tree;   /* 360: dmap tree           */
0152     u8 pad[1672];       /* 1672: pad to 2048 bytes      */
0153     __le32 wmap[LPERDMAP];  /* 1024: bits of the working map    */
0154     __le32 pmap[LPERDMAP];  /* 1024: bits of the persistent map */
0155 };              /* - 4096 -             */
0156 
0157 /*
0158  *  disk map control page per level.
0159  *
0160  * dmapctl must be consistent with dmaptree.
0161  */
0162 struct dmapctl {
0163     __le32 nleafs;      /* 4: number of tree leafs  */
0164     __le32 l2nleafs;    /* 4: l2 number of tree leafs   */
0165     __le32 leafidx;     /* 4: index of the first tree leaf  */
0166     __le32 height;      /* 4: height of tree        */
0167     s8 budmin;      /* 1: minimum l2 tree leaf value    */
0168     s8 stree[CTLTREESIZE];  /* CTLTREESIZE: dmapctl tree    */
0169     u8 pad[2714];       /* 2714: pad to 4096        */
0170 };              /* - 4096 -         */
0171 
0172 /*
0173  *  common definition for dmaptree within dmap and dmapctl
0174  */
0175 typedef union dmtree {
0176     struct dmaptree t1;
0177     struct dmapctl t2;
0178 } dmtree_t;
0179 
0180 /* macros for accessing fields within dmtree */
0181 #define dmt_nleafs  t1.nleafs
0182 #define dmt_l2nleafs    t1.l2nleafs
0183 #define dmt_leafidx t1.leafidx
0184 #define dmt_height  t1.height
0185 #define dmt_budmin  t1.budmin
0186 #define dmt_stree   t2.stree
0187 
0188 /*
0189  *  on-disk aggregate disk allocation map descriptor.
0190  */
0191 struct dbmap_disk {
0192     __le64 dn_mapsize;  /* 8: number of blocks in aggregate */
0193     __le64 dn_nfree;    /* 8: num free blks in aggregate map    */
0194     __le32 dn_l2nbperpage;  /* 4: number of blks per page       */
0195     __le32 dn_numag;    /* 4: total number of ags       */
0196     __le32 dn_maxlevel; /* 4: number of active ags      */
0197     __le32 dn_maxag;    /* 4: max active alloc group number */
0198     __le32 dn_agpref;   /* 4: preferred alloc group (hint)  */
0199     __le32 dn_aglevel;  /* 4: dmapctl level holding the AG  */
0200     __le32 dn_agheight; /* 4: height in dmapctl of the AG   */
0201     __le32 dn_agwidth;  /* 4: width in dmapctl of the AG    */
0202     __le32 dn_agstart;  /* 4: start tree index at AG height */
0203     __le32 dn_agl2size; /* 4: l2 num of blks per alloc group    */
0204     __le64 dn_agfree[MAXAG];/* 8*MAXAG: per AG free count       */
0205     __le64 dn_agsize;   /* 8: num of blks per alloc group   */
0206     s8 dn_maxfreebud;   /* 1: max free buddy system     */
0207     u8 pad[3007];       /* 3007: pad to 4096            */
0208 };              /* - 4096 -             */
0209 
0210 struct dbmap {
0211     s64 dn_mapsize;     /* number of blocks in aggregate    */
0212     s64 dn_nfree;       /* num free blks in aggregate map   */
0213     int dn_l2nbperpage; /* number of blks per page      */
0214     int dn_numag;       /* total number of ags          */
0215     int dn_maxlevel;    /* number of active ags         */
0216     int dn_maxag;       /* max active alloc group number    */
0217     int dn_agpref;      /* preferred alloc group (hint)     */
0218     int dn_aglevel;     /* dmapctl level holding the AG     */
0219     int dn_agheight;    /* height in dmapctl of the AG      */
0220     int dn_agwidth;     /* width in dmapctl of the AG       */
0221     int dn_agstart;     /* start tree index at AG height    */
0222     int dn_agl2size;    /* l2 num of blks per alloc group   */
0223     s64 dn_agfree[MAXAG];   /* per AG free count            */
0224     s64 dn_agsize;      /* num of blks per alloc group      */
0225     signed char dn_maxfreebud;  /* max free buddy system    */
0226 };              /* - 4096 -             */
0227 /*
0228  *  in-memory aggregate disk allocation map descriptor.
0229  */
0230 struct bmap {
0231     struct dbmap db_bmap;       /* on-disk aggregate map descriptor */
0232     struct inode *db_ipbmap;    /* ptr to aggregate map incore inode */
0233     struct mutex db_bmaplock;   /* aggregate map lock */
0234     atomic_t db_active[MAXAG];  /* count of active, open files in AG */
0235     u32 *db_DBmap;
0236 };
0237 
0238 /* macros for accessing fields within in-memory aggregate map descriptor */
0239 #define db_mapsize  db_bmap.dn_mapsize
0240 #define db_nfree    db_bmap.dn_nfree
0241 #define db_agfree   db_bmap.dn_agfree
0242 #define db_agsize   db_bmap.dn_agsize
0243 #define db_agl2size db_bmap.dn_agl2size
0244 #define db_agwidth  db_bmap.dn_agwidth
0245 #define db_agheight db_bmap.dn_agheight
0246 #define db_agstart  db_bmap.dn_agstart
0247 #define db_numag    db_bmap.dn_numag
0248 #define db_maxlevel db_bmap.dn_maxlevel
0249 #define db_aglevel  db_bmap.dn_aglevel
0250 #define db_agpref   db_bmap.dn_agpref
0251 #define db_maxag    db_bmap.dn_maxag
0252 #define db_maxfreebud   db_bmap.dn_maxfreebud
0253 #define db_l2nbperpage  db_bmap.dn_l2nbperpage
0254 
0255 /*
0256  * macros for various conversions needed by the allocators.
0257  * blkstol2(), cntlz(), and cnttz() are operating system dependent functions.
0258  */
0259 /* convert number of blocks to log2 number of blocks, rounding up to
0260  * the next log2 value if blocks is not a l2 multiple.
0261  */
0262 #define BLKSTOL2(d)     (blkstol2(d))
0263 
0264 /* convert number of leafs to log2 leaf value */
0265 #define NLSTOL2BSZ(n)       (31 - cntlz((n)) + BUDMIN)
0266 
0267 /* convert leaf index to log2 leaf value */
0268 #define LITOL2BSZ(n,m,b)    ((((n) == 0) ? (m) : cnttz((n))) + (b))
0269 
0270 /* convert a block number to a dmap control leaf index */
0271 #define BLKTOCTLLEAF(b,m)   \
0272     (((b) & (((s64)1 << ((m) + L2LPERCTL)) - 1)) >> (m))
0273 
0274 /* convert log2 leaf value to buddy size */
0275 #define BUDSIZE(s,m)        (1 << ((s) - (m)))
0276 
0277 /*
0278  *  external references.
0279  */
0280 extern int dbMount(struct inode *ipbmap);
0281 
0282 extern int dbUnmount(struct inode *ipbmap, int mounterror);
0283 
0284 extern int dbFree(struct inode *ipbmap, s64 blkno, s64 nblocks);
0285 
0286 extern int dbUpdatePMap(struct inode *ipbmap,
0287             int free, s64 blkno, s64 nblocks, struct tblock * tblk);
0288 
0289 extern int dbNextAG(struct inode *ipbmap);
0290 
0291 extern int dbAlloc(struct inode *ipbmap, s64 hint, s64 nblocks, s64 * results);
0292 
0293 extern int dbReAlloc(struct inode *ipbmap,
0294              s64 blkno, s64 nblocks, s64 addnblocks, s64 * results);
0295 
0296 extern int dbSync(struct inode *ipbmap);
0297 extern int dbAllocBottomUp(struct inode *ip, s64 blkno, s64 nblocks);
0298 extern int dbExtendFS(struct inode *ipbmap, s64 blkno, s64 nblocks);
0299 extern void dbFinalizeBmap(struct inode *ipbmap);
0300 extern s64 dbMapFileSizeToMapSize(struct inode *ipbmap);
0301 extern s64 dbDiscardAG(struct inode *ip, int agno, s64 minlen);
0302 
0303 #endif              /* _H_JFS_DMAP */