Lines Matching +full:multi +full:- +full:tt

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) International Business Machines Corp., 2000-2004
41 * take the lock in read mode. a single top-down request may proceed
42 * exclusively while multiple bottoms-up requests may proceed
50 * in the face of multiple-bottoms up requests.
57 #define BMAP_LOCK_INIT(bmp) mutex_init(&bmp->db_bmaplock)
58 #define BMAP_LOCK(bmp) mutex_lock(&bmp->db_bmaplock)
59 #define BMAP_UNLOCK(bmp) mutex_unlock(&bmp->db_bmaplock)
133 2, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -1
141 * memory is allocated for the in-core bmap descriptor and
142 * the in-core descriptor is initialized from disk.
145 * ipbmap - pointer to in-core inode for the block map.
148 * 0 - success
149 * -ENOMEM - insufficient memory
150 * -EIO - i/o error
151 * -EINVAL - wrong bmap data
161 * allocate/initialize the in-memory bmap descriptor in dbMount()
163 /* allocate memory for the in-memory bmap descriptor */ in dbMount()
166 return -ENOMEM; in dbMount()
168 /* read the on-disk bmap descriptor. */ in dbMount()
170 BMAPBLKNO << JFS_SBI(ipbmap->i_sb)->l2nbperpage, in dbMount()
173 err = -EIO; in dbMount()
177 /* copy the on-disk bmap descriptor to its in-memory version. */ in dbMount()
178 dbmp_le = (struct dbmap_disk *) mp->data; in dbMount()
179 bmp->db_mapsize = le64_to_cpu(dbmp_le->dn_mapsize); in dbMount()
180 bmp->db_nfree = le64_to_cpu(dbmp_le->dn_nfree); in dbMount()
182 bmp->db_l2nbperpage = le32_to_cpu(dbmp_le->dn_l2nbperpage); in dbMount()
183 if (bmp->db_l2nbperpage > L2PSIZE - L2MINBLOCKSIZE || in dbMount()
184 bmp->db_l2nbperpage < 0) { in dbMount()
185 err = -EINVAL; in dbMount()
189 bmp->db_numag = le32_to_cpu(dbmp_le->dn_numag); in dbMount()
190 if (!bmp->db_numag || bmp->db_numag > MAXAG) { in dbMount()
191 err = -EINVAL; in dbMount()
195 bmp->db_maxlevel = le32_to_cpu(dbmp_le->dn_maxlevel); in dbMount()
196 bmp->db_maxag = le32_to_cpu(dbmp_le->dn_maxag); in dbMount()
197 bmp->db_agpref = le32_to_cpu(dbmp_le->dn_agpref); in dbMount()
198 if (bmp->db_maxag >= MAXAG || bmp->db_maxag < 0 || in dbMount()
199 bmp->db_agpref >= MAXAG || bmp->db_agpref < 0) { in dbMount()
200 err = -EINVAL; in dbMount()
204 bmp->db_aglevel = le32_to_cpu(dbmp_le->dn_aglevel); in dbMount()
205 bmp->db_agheight = le32_to_cpu(dbmp_le->dn_agheight); in dbMount()
206 bmp->db_agwidth = le32_to_cpu(dbmp_le->dn_agwidth); in dbMount()
207 if (!bmp->db_agwidth) { in dbMount()
208 err = -EINVAL; in dbMount()
211 bmp->db_agstart = le32_to_cpu(dbmp_le->dn_agstart); in dbMount()
212 bmp->db_agl2size = le32_to_cpu(dbmp_le->dn_agl2size); in dbMount()
213 if (bmp->db_agl2size > L2MAXL2SIZE - L2MAXAG || in dbMount()
214 bmp->db_agl2size < 0) { in dbMount()
215 err = -EINVAL; in dbMount()
219 if (((bmp->db_mapsize - 1) >> bmp->db_agl2size) > MAXAG) { in dbMount()
220 err = -EINVAL; in dbMount()
225 bmp->db_agfree[i] = le64_to_cpu(dbmp_le->dn_agfree[i]); in dbMount()
226 bmp->db_agsize = le64_to_cpu(dbmp_le->dn_agsize); in dbMount()
227 bmp->db_maxfreebud = dbmp_le->dn_maxfreebud; in dbMount()
233 bmp->db_ipbmap = ipbmap; in dbMount()
234 JFS_SBI(ipbmap->i_sb)->bmap = bmp; in dbMount()
236 memset(bmp->db_active, 0, sizeof(bmp->db_active)); in dbMount()
259 * the in-core bmap descriptor is written to disk and
263 * ipbmap - pointer to in-core inode for the block map.
266 * 0 - success
267 * -EIO - i/o error
271 struct bmap *bmp = JFS_SBI(ipbmap->i_sb)->bmap; in dbUnmount()
279 truncate_inode_pages(ipbmap->i_mapping, 0); in dbUnmount()
281 /* free the memory for the in-memory bmap. */ in dbUnmount()
283 JFS_SBI(ipbmap->i_sb)->bmap = NULL; in dbUnmount()
294 struct bmap *bmp = JFS_SBI(ipbmap->i_sb)->bmap; in dbSync()
301 /* get the buffer for the on-disk bmap descriptor. */ in dbSync()
303 BMAPBLKNO << JFS_SBI(ipbmap->i_sb)->l2nbperpage, in dbSync()
307 return -EIO; in dbSync()
309 /* copy the in-memory version of the bmap to the on-disk version */ in dbSync()
310 dbmp_le = (struct dbmap_disk *) mp->data; in dbSync()
311 dbmp_le->dn_mapsize = cpu_to_le64(bmp->db_mapsize); in dbSync()
312 dbmp_le->dn_nfree = cpu_to_le64(bmp->db_nfree); in dbSync()
313 dbmp_le->dn_l2nbperpage = cpu_to_le32(bmp->db_l2nbperpage); in dbSync()
314 dbmp_le->dn_numag = cpu_to_le32(bmp->db_numag); in dbSync()
315 dbmp_le->dn_maxlevel = cpu_to_le32(bmp->db_maxlevel); in dbSync()
316 dbmp_le->dn_maxag = cpu_to_le32(bmp->db_maxag); in dbSync()
317 dbmp_le->dn_agpref = cpu_to_le32(bmp->db_agpref); in dbSync()
318 dbmp_le->dn_aglevel = cpu_to_le32(bmp->db_aglevel); in dbSync()
319 dbmp_le->dn_agheight = cpu_to_le32(bmp->db_agheight); in dbSync()
320 dbmp_le->dn_agwidth = cpu_to_le32(bmp->db_agwidth); in dbSync()
321 dbmp_le->dn_agstart = cpu_to_le32(bmp->db_agstart); in dbSync()
322 dbmp_le->dn_agl2size = cpu_to_le32(bmp->db_agl2size); in dbSync()
324 dbmp_le->dn_agfree[i] = cpu_to_le64(bmp->db_agfree[i]); in dbSync()
325 dbmp_le->dn_agsize = cpu_to_le64(bmp->db_agsize); in dbSync()
326 dbmp_le->dn_maxfreebud = bmp->db_maxfreebud; in dbSync()
334 filemap_write_and_wait(ipbmap->i_mapping); in dbSync()
351 * ip - pointer to in-core inode;
352 * blkno - starting block number to be freed.
353 * nblocks - number of blocks to be freed.
356 * 0 - success
357 * -EIO - i/o error
365 struct inode *ipbmap = JFS_SBI(ip->i_sb)->ipbmap; in dbFree()
366 struct bmap *bmp = JFS_SBI(ip->i_sb)->bmap; in dbFree()
367 struct super_block *sb = ipbmap->i_sb; in dbFree()
372 if (unlikely((blkno == 0) || (blkno + nblocks > bmp->db_mapsize))) { in dbFree()
377 jfs_error(ip->i_sb, "block to be freed is outside the map\n"); in dbFree()
378 return -EIO; in dbFree()
384 if (JFS_SBI(sb)->flag & JFS_DISCARD) in dbFree()
385 if (JFS_SBI(sb)->minblks_trim <= nblocks) in dbFree()
392 for (rem = nblocks; rem > 0; rem -= nb, blkno += nb) { in dbFree()
399 lblkno = BLKTODMAP(blkno, bmp->db_l2nbperpage); in dbFree()
403 return -EIO; in dbFree()
405 dp = (struct dmap *) mp->data; in dbFree()
410 nb = min(rem, BPERDMAP - (blkno & (BPERDMAP - 1))); in dbFree()
414 jfs_error(ip->i_sb, "error in block map\n"); in dbFree()
441 * ipbmap - pointer to in-core inode for the block map.
442 * free - 'true' if block range is to be freed from the persistent
444 * blkno - starting block number of the range.
445 * nblocks - number of contiguous blocks in the range.
446 * tblk - transaction block;
449 * 0 - success
450 * -EIO - i/o error
458 struct bmap *bmp = JFS_SBI(ipbmap->i_sb)->bmap; in dbUpdatePMap()
468 if (blkno + nblocks > bmp->db_mapsize) { in dbUpdatePMap()
472 jfs_error(ipbmap->i_sb, "blocks are outside the map\n"); in dbUpdatePMap()
473 return -EIO; in dbUpdatePMap()
477 lsn = tblk->lsn; in dbUpdatePMap()
478 log = (struct jfs_log *) JFS_SBI(tblk->sb)->log; in dbUpdatePMap()
486 for (rem = nblocks; rem > 0; rem -= nblks, blkno += nblks) { in dbUpdatePMap()
488 lblkno = BLKTODMAP(blkno, bmp->db_l2nbperpage); in dbUpdatePMap()
494 mp = read_metapage(bmp->db_ipbmap, lblkno, PSIZE, in dbUpdatePMap()
497 return -EIO; in dbUpdatePMap()
500 dp = (struct dmap *) mp->data; in dbUpdatePMap()
506 dbitno = blkno & (BPERDMAP - 1); in dbUpdatePMap()
508 nblks = min(rem, (s64)BPERDMAP - dbitno); in dbUpdatePMap()
518 rbits -= nbits, dbitno += nbits) { in dbUpdatePMap()
522 wbitno = dbitno & (DBWORD - 1); in dbUpdatePMap()
523 nbits = min(rbits, DBWORD - wbitno); in dbUpdatePMap()
531 (ONES << (DBWORD - nbits) >> wbitno); in dbUpdatePMap()
533 dp->pmap[word] &= in dbUpdatePMap()
536 dp->pmap[word] |= in dbUpdatePMap()
552 memset(&dp->pmap[word], 0, in dbUpdatePMap()
555 memset(&dp->pmap[word], (int) ONES, in dbUpdatePMap()
571 if (mp->lsn != 0) { in dbUpdatePMap()
573 logdiff(diffp, mp->lsn, log); in dbUpdatePMap()
575 mp->lsn = lsn; in dbUpdatePMap()
578 list_move(&mp->synclist, &tblk->synclist); in dbUpdatePMap()
582 logdiff(difft, tblk->clsn, log); in dbUpdatePMap()
583 logdiff(diffp, mp->clsn, log); in dbUpdatePMap()
585 mp->clsn = tblk->clsn; in dbUpdatePMap()
587 mp->log = log; in dbUpdatePMap()
588 mp->lsn = lsn; in dbUpdatePMap()
591 log->count++; in dbUpdatePMap()
592 list_add(&mp->synclist, &tblk->synclist); in dbUpdatePMap()
594 mp->clsn = tblk->clsn; in dbUpdatePMap()
616 * new inode allocation towards. The tie-in between inode
627 * ipbmap - pointer to in-core inode for the block map.
638 int next_best = -1; in dbNextAG()
639 struct bmap *bmp = JFS_SBI(ipbmap->i_sb)->bmap; in dbNextAG()
644 avgfree = (u32)bmp->db_nfree / bmp->db_numag; in dbNextAG()
650 agpref = bmp->db_agpref; in dbNextAG()
651 if ((atomic_read(&bmp->db_active[agpref]) == 0) && in dbNextAG()
652 (bmp->db_agfree[agpref] >= avgfree)) in dbNextAG()
658 for (i = 0 ; i < bmp->db_numag; i++, agpref++) { in dbNextAG()
659 if (agpref >= bmp->db_numag) in dbNextAG()
662 if (atomic_read(&bmp->db_active[agpref])) in dbNextAG()
665 if (bmp->db_agfree[agpref] >= avgfree) { in dbNextAG()
667 bmp->db_agpref = agpref; in dbNextAG()
669 } else if (bmp->db_agfree[agpref] > hwm) { in dbNextAG()
671 hwm = bmp->db_agfree[agpref]; in dbNextAG()
680 if (next_best != -1) in dbNextAG()
681 bmp->db_agpref = next_best; in dbNextAG()
688 return (bmp->db_agpref); in dbNextAG()
697 * the block allocation policy uses hints and a multi-step
718 * ip - pointer to in-core inode;
719 * hint - allocation hint.
720 * nblocks - number of contiguous blocks in the range.
721 * results - on successful return, set to the starting block number
725 * 0 - success
726 * -ENOSPC - insufficient disk resources
727 * -EIO - i/o error
732 struct inode *ipbmap = JFS_SBI(ip->i_sb)->ipbmap; in dbAlloc()
750 bmp = JFS_SBI(ip->i_sb)->bmap; in dbAlloc()
752 mapSize = bmp->db_mapsize; in dbAlloc()
756 jfs_error(ip->i_sb, "the hint is outside the map\n"); in dbAlloc()
757 return -EIO; in dbAlloc()
763 if (l2nb > bmp->db_agl2size) { in dbAlloc()
783 if (blkno >= bmp->db_mapsize) in dbAlloc()
786 agno = blkno >> bmp->db_agl2size; in dbAlloc()
792 if ((blkno & (bmp->db_agsize - 1)) == 0) in dbAlloc()
794 * if so, call dbNextAG() to find a non-busy in dbAlloc()
797 if (atomic_read(&bmp->db_active[agno])) in dbAlloc()
809 rc = -EIO; in dbAlloc()
810 lblkno = BLKTODMAP(blkno, bmp->db_l2nbperpage); in dbAlloc()
815 dp = (struct dmap *) mp->data; in dbAlloc()
821 != -ENOSPC) { in dbAlloc()
831 writers = atomic_read(&bmp->db_active[agno]); in dbAlloc()
833 ((writers == 1) && (JFS_IP(ip)->active_ag != agno))) { in dbAlloc()
848 != -ENOSPC) { in dbAlloc()
860 != -ENOSPC) { in dbAlloc()
876 if ((rc = dbAllocAG(bmp, agno, nblocks, l2nb, results)) != -ENOSPC) in dbAlloc()
892 if ((rc = dbAllocAG(bmp, agno, nblocks, l2nb, results)) == -ENOSPC) in dbAlloc()
922 * ip - pointer to in-core inode requiring allocation.
923 * blkno - starting block of the current allocation.
924 * nblocks - number of contiguous blocks within the current
926 * addnblocks - number of blocks to add to the allocation.
927 * results - on successful return, set to the starting block number
934 * 0 - success
935 * -ENOSPC - insufficient disk resources
936 * -EIO - i/o error
950 if (rc != -ENOSPC) in dbReAlloc()
960 (ip, blkno + nblocks - 1, addnblocks + nblocks, results)); in dbReAlloc()
976 * ip - pointer to in-core inode requiring allocation.
977 * blkno - starting block of the current allocation.
978 * nblocks - number of contiguous blocks within the current
980 * addnblocks - number of blocks to add to the allocation.
983 * 0 - success
984 * -ENOSPC - insufficient disk resources
985 * -EIO - i/o error
989 struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb); in dbExtend()
995 struct inode *ipbmap = sbi->ipbmap; in dbExtend()
999 * We don't want a non-aligned extent to cross a page boundary in dbExtend()
1001 if (((rel_block = blkno & (sbi->nbperpage - 1))) && in dbExtend()
1002 (rel_block + nblocks + addnblocks > sbi->nbperpage)) in dbExtend()
1003 return -ENOSPC; in dbExtend()
1006 lastblkno = blkno + nblocks - 1; in dbExtend()
1016 bmp = sbi->bmap; in dbExtend()
1017 if (lastblkno < 0 || lastblkno >= bmp->db_mapsize) { in dbExtend()
1019 jfs_error(ip->i_sb, "the block is outside the filesystem\n"); in dbExtend()
1020 return -EIO; in dbExtend()
1031 if (addnblocks > BPERDMAP || extblkno >= bmp->db_mapsize || in dbExtend()
1032 (extblkno & (bmp->db_agsize - 1)) == 0) { in dbExtend()
1034 return -ENOSPC; in dbExtend()
1040 lblkno = BLKTODMAP(extblkno, bmp->db_l2nbperpage); in dbExtend()
1044 return -EIO; in dbExtend()
1047 dp = (struct dmap *) mp->data; in dbExtend()
1074 * bmp - pointer to bmap descriptor
1075 * dp - pointer to dmap.
1076 * blkno - starting block number of the range.
1077 * nblocks - number of contiguous free blocks of the range.
1080 * 0 - success
1081 * -ENOSPC - insufficient disk resources
1082 * -EIO - i/o error
1094 if (dp->tree.leafidx != cpu_to_le32(LEAFIND)) { in dbAllocNext()
1095 jfs_error(bmp->db_ipbmap->i_sb, "Corrupt dmap page\n"); in dbAllocNext()
1096 return -EIO; in dbAllocNext()
1101 leaf = dp->tree.stree + le32_to_cpu(dp->tree.leafidx); in dbAllocNext()
1106 dbitno = blkno & (BPERDMAP - 1); in dbAllocNext()
1113 return -ENOSPC; in dbAllocNext()
1119 return -ENOSPC; in dbAllocNext()
1134 for (rembits = nblocks; rembits > 0; rembits -= nb, dbitno += nb) { in dbAllocNext()
1138 wbitno = dbitno & (DBWORD - 1); in dbAllocNext()
1139 nb = min(rembits, DBWORD - wbitno); in dbAllocNext()
1146 mask = (ONES << (DBWORD - nb) >> wbitno); in dbAllocNext()
1147 if ((mask & ~le32_to_cpu(dp->wmap[word])) != mask) in dbAllocNext()
1148 return -ENOSPC; in dbAllocNext()
1166 return -ENOSPC; in dbAllocNext()
1178 nwords -= nw; in dbAllocNext()
1202 * bmp - pointer to bmap descriptor
1203 * dp - pointer to dmap.
1204 * blkno - block number to allocate near.
1205 * nblocks - actual number of contiguous free blocks desired.
1206 * l2nb - log2 number of contiguous free blocks desired.
1207 * results - on successful return, set to the starting block number
1211 * 0 - success
1212 * -ENOSPC - insufficient disk resources
1213 * -EIO - i/o error
1224 if (dp->tree.leafidx != cpu_to_le32(LEAFIND)) { in dbAllocNear()
1225 jfs_error(bmp->db_ipbmap->i_sb, "Corrupt dmap page\n"); in dbAllocNear()
1226 return -EIO; in dbAllocNear()
1229 leaf = dp->tree.stree + le32_to_cpu(dp->tree.leafidx); in dbAllocNear()
1235 word = (blkno & (BPERDMAP - 1)) >> L2DBWORD; in dbAllocNear()
1249 blkno = le64_to_cpu(dp->start) + (word << L2DBWORD); in dbAllocNear()
1258 dbFindBits(le32_to_cpu(dp->wmap[word]), l2nb); in dbAllocNear()
1268 return -ENOSPC; in dbAllocNear()
1289 * or two sub-trees, depending on the allocation group size.
1312 * bmp - pointer to bmap descriptor
1313 * agno - allocation group number.
1314 * nblocks - actual number of contiguous free blocks desired.
1315 * l2nb - log2 number of contiguous free blocks desired.
1316 * results - on successful return, set to the starting block number
1320 * 0 - success
1321 * -ENOSPC - insufficient disk resources
1322 * -EIO - i/o error
1338 if (l2nb > bmp->db_agl2size) { in dbAllocAG()
1339 jfs_error(bmp->db_ipbmap->i_sb, in dbAllocAG()
1341 return -EIO; in dbAllocAG()
1347 blkno = (s64) agno << bmp->db_agl2size; in dbAllocAG()
1366 if (bmp->db_agsize == BPERDMAP in dbAllocAG()
1367 || bmp->db_agfree[agno] == bmp->db_agsize) { in dbAllocAG()
1369 if ((rc == -ENOSPC) && in dbAllocAG()
1370 (bmp->db_agfree[agno] == bmp->db_agsize)) { in dbAllocAG()
1374 jfs_error(bmp->db_ipbmap->i_sb, in dbAllocAG()
1383 lblkno = BLKTOCTL(blkno, bmp->db_l2nbperpage, bmp->db_aglevel); in dbAllocAG()
1384 mp = read_metapage(bmp->db_ipbmap, lblkno, PSIZE, 0); in dbAllocAG()
1386 return -EIO; in dbAllocAG()
1387 dcp = (struct dmapctl *) mp->data; in dbAllocAG()
1388 budmin = dcp->budmin; in dbAllocAG()
1390 if (dcp->leafidx != cpu_to_le32(CTLLEAFIND)) { in dbAllocAG()
1391 jfs_error(bmp->db_ipbmap->i_sb, "Corrupt dmapctl page\n"); in dbAllocAG()
1393 return -EIO; in dbAllocAG()
1404 (1 << (L2LPERCTL - (bmp->db_agheight << 1))) / bmp->db_agwidth; in dbAllocAG()
1405 ti = bmp->db_agstart + bmp->db_agwidth * (agno & (agperlev - 1)); in dbAllocAG()
1407 /* dmap control page trees fan-out by 4 and a single allocation in dbAllocAG()
1413 for (i = 0; i < bmp->db_agwidth; i++, ti++) { in dbAllocAG()
1416 if (l2nb > dcp->stree[ti]) in dbAllocAG()
1423 for (k = bmp->db_agheight; k > 0; k--) { in dbAllocAG()
1425 if (l2nb <= dcp->stree[m + n]) { in dbAllocAG()
1431 jfs_error(bmp->db_ipbmap->i_sb, in dbAllocAG()
1434 return -EIO; in dbAllocAG()
1441 if (bmp->db_aglevel == 2) in dbAllocAG()
1443 else if (bmp->db_aglevel == 1) in dbAllocAG()
1444 blkno &= ~(MAXL1SIZE - 1); in dbAllocAG()
1445 else /* bmp->db_aglevel == 0 */ in dbAllocAG()
1446 blkno &= ~(MAXL0SIZE - 1); in dbAllocAG()
1449 ((s64) (ti - le32_to_cpu(dcp->leafidx))) << budmin; in dbAllocAG()
1468 dbFindCtl(bmp, l2nb, bmp->db_aglevel - 1, in dbAllocAG()
1470 if (rc == -ENOSPC) { in dbAllocAG()
1471 jfs_error(bmp->db_ipbmap->i_sb, in dbAllocAG()
1473 return -EIO; in dbAllocAG()
1482 if (rc == -ENOSPC) { in dbAllocAG()
1483 jfs_error(bmp->db_ipbmap->i_sb, in dbAllocAG()
1485 rc = -EIO; in dbAllocAG()
1491 * return -ENOSPC. in dbAllocAG()
1495 return -ENOSPC; in dbAllocAG()
1512 * bmp - pointer to bmap descriptor
1513 * nblocks - actual number of contiguous free blocks desired.
1514 * l2nb - log2 number of contiguous free blocks desired.
1515 * results - on successful return, set to the starting block number
1519 * 0 - success
1520 * -ENOSPC - insufficient disk resources
1521 * -EIO - i/o error
1536 if ((rc = dbFindCtl(bmp, l2nb, bmp->db_maxlevel, &blkno))) in dbAllocAny()
1542 if (rc == -ENOSPC) { in dbAllocAny()
1543 jfs_error(bmp->db_ipbmap->i_sb, "unable to allocate blocks\n"); in dbAllocAny()
1544 return -EIO; in dbAllocAny()
1562 * - we work only on one ag at some time, minimizing how long we
1564 * - reading / writing the fs is possible most time, even on
1568 * - we write two times to the dmapctl and dmap pages
1569 * - but for me, this seems the best way, better ideas?
1573 * ip - pointer to in-core inode
1574 * agno - ag to trim
1575 * minlen - minimum value of contiguous blocks
1578 * s64 - actual number of blocks trimmed
1582 struct inode *ipbmap = JFS_SBI(ip->i_sb)->ipbmap; in dbDiscardAG()
1583 struct bmap *bmp = JFS_SBI(ip->i_sb)->bmap; in dbDiscardAG()
1587 struct super_block *sb = ipbmap->i_sb; in dbDiscardAG()
1592 } *totrim, *tt; in dbDiscardAG() local
1601 nblocks = bmp->db_agfree[agno]; in dbDiscardAG()
1607 jfs_error(bmp->db_ipbmap->i_sb, "no memory for trim array\n"); in dbDiscardAG()
1612 tt = totrim; in dbDiscardAG()
1616 /* 0 = okay, -EIO = fatal, -ENOSPC -> try smaller block */ in dbDiscardAG()
1619 tt->blkno = blkno; in dbDiscardAG()
1620 tt->nblocks = nblocks; in dbDiscardAG()
1621 tt++; count++; in dbDiscardAG()
1624 if (bmp->db_agfree[agno] == 0) in dbDiscardAG()
1628 nblocks = bmp->db_agfree[agno]; in dbDiscardAG()
1630 } else if (rc == -ENOSPC) { in dbDiscardAG()
1632 l2nb = BLKSTOL2(nblocks) - 1; in dbDiscardAG()
1638 jfs_error(bmp->db_ipbmap->i_sb, "-EIO\n"); in dbDiscardAG()
1643 if (unlikely(count >= range_cnt - 1)) in dbDiscardAG()
1648 tt->nblocks = 0; /* mark the current end */ in dbDiscardAG()
1649 for (tt = totrim; tt->nblocks != 0; tt++) { in dbDiscardAG()
1652 if (!(JFS_SBI(sb)->flag & JFS_DISCARD)) in dbDiscardAG()
1653 jfs_issue_discard(ip, tt->blkno, tt->nblocks); in dbDiscardAG()
1654 dbFree(ip, tt->blkno, tt->nblocks); in dbDiscardAG()
1655 trimmed += tt->nblocks; in dbDiscardAG()
1676 * bmp - pointer to bmap descriptor
1677 * level - starting dmap control page level.
1678 * l2nb - log2 number of contiguous free blocks desired.
1679 * *blkno - on entry, starting block number for conducting the search.
1684 * 0 - success
1685 * -ENOSPC - insufficient disk resources
1686 * -EIO - i/o error
1703 for (lev = level, b = *blkno; lev >= 0; lev--) { in dbFindCtl()
1707 lblkno = BLKTOCTL(b, bmp->db_l2nbperpage, lev); in dbFindCtl()
1708 mp = read_metapage(bmp->db_ipbmap, lblkno, PSIZE, 0); in dbFindCtl()
1710 return -EIO; in dbFindCtl()
1711 dcp = (struct dmapctl *) mp->data; in dbFindCtl()
1712 budmin = dcp->budmin; in dbFindCtl()
1714 if (dcp->leafidx != cpu_to_le32(CTLLEAFIND)) { in dbFindCtl()
1715 jfs_error(bmp->db_ipbmap->i_sb, in dbFindCtl()
1718 return -EIO; in dbFindCtl()
1736 jfs_error(bmp->db_ipbmap->i_sb, in dbFindCtl()
1738 return -EIO; in dbFindCtl()
1740 return -ENOSPC; in dbFindCtl()
1793 * bmp - pointer to bmap descriptor
1794 * nblocks - actual number of contiguous free blocks to allocate.
1795 * l2nb - log2 number of contiguous free blocks to allocate.
1796 * blkno - starting block number of the dmap to start the allocation
1798 * results - on successful return, set to the starting block number
1802 * 0 - success
1803 * -ENOSPC - insufficient disk resources
1804 * -EIO - i/o error
1821 lblkno = BLKTODMAP(blkno, bmp->db_l2nbperpage); in dbAllocCtl()
1822 mp = read_metapage(bmp->db_ipbmap, lblkno, PSIZE, 0); in dbAllocCtl()
1824 return -EIO; in dbAllocCtl()
1825 dp = (struct dmap *) mp->data; in dbAllocCtl()
1827 if (dp->tree.budmin < 0) in dbAllocCtl()
1828 return -EIO; in dbAllocCtl()
1844 assert((blkno & (BPERDMAP - 1)) == 0); in dbAllocCtl()
1848 for (n = nblocks, b = blkno; n > 0; n -= nb, b += nb) { in dbAllocCtl()
1851 lblkno = BLKTODMAP(b, bmp->db_l2nbperpage); in dbAllocCtl()
1852 mp = read_metapage(bmp->db_ipbmap, lblkno, PSIZE, 0); in dbAllocCtl()
1854 rc = -EIO; in dbAllocCtl()
1857 dp = (struct dmap *) mp->data; in dbAllocCtl()
1861 if (dp->tree.stree[ROOT] != L2BPERDMAP) { in dbAllocCtl()
1863 jfs_error(bmp->db_ipbmap->i_sb, in dbAllocCtl()
1865 rc = -EIO; in dbAllocCtl()
1900 for (n = nblocks - n, b = blkno; n > 0; in dbAllocCtl()
1901 n -= BPERDMAP, b += BPERDMAP) { in dbAllocCtl()
1904 lblkno = BLKTODMAP(b, bmp->db_l2nbperpage); in dbAllocCtl()
1905 mp = read_metapage(bmp->db_ipbmap, lblkno, PSIZE, 0); in dbAllocCtl()
1910 jfs_error(bmp->db_ipbmap->i_sb, in dbAllocCtl()
1914 dp = (struct dmap *) mp->data; in dbAllocCtl()
1923 jfs_error(bmp->db_ipbmap->i_sb, "Block Leakage\n"); in dbAllocCtl()
1947 * mp - pointer to bmap descriptor
1948 * dp - pointer to dmap to attempt to allocate blocks from.
1949 * l2nb - log2 number of contiguous block desired.
1950 * nblocks - actual number of contiguous block desired.
1951 * results - on successful return, set to the starting block number
1955 * 0 - success
1956 * -ENOSPC - insufficient disk resources
1957 * -EIO - i/o error
1976 if (dbFindLeaf((dmtree_t *) &dp->tree, l2nb, &leafidx, false)) in dbAllocDmapLev()
1977 return -ENOSPC; in dbAllocDmapLev()
1980 return -EIO; in dbAllocDmapLev()
1985 blkno = le64_to_cpu(dp->start) + (leafidx << L2DBWORD); in dbAllocDmapLev()
1991 if (dp->tree.stree[leafidx + LEAFIND] < BUDMIN) in dbAllocDmapLev()
1992 blkno += dbFindBits(le32_to_cpu(dp->wmap[leafidx]), l2nb); in dbAllocDmapLev()
2018 * bmp - pointer to bmap descriptor
2019 * dp - pointer to dmap to allocate the block range from.
2020 * blkno - starting block number of the block to be allocated.
2021 * nblocks - number of blocks to be allocated.
2024 * 0 - success
2025 * -EIO - i/o error
2038 oldroot = dp->tree.stree[ROOT]; in dbAllocDmap()
2044 if (dp->tree.stree[ROOT] == oldroot) in dbAllocDmap()
2051 if ((rc = dbAdjCtl(bmp, blkno, dp->tree.stree[ROOT], 1, 0))) in dbAllocDmap()
2073 * bmp - pointer to bmap descriptor
2074 * dp - pointer to dmap to free the block range from.
2075 * blkno - starting block number of the block to be freed.
2076 * nblocks - number of blocks to be freed.
2079 * 0 - success
2080 * -EIO - i/o error
2093 oldroot = dp->tree.stree[ROOT]; in dbFreeDmap()
2099 if (rc || (dp->tree.stree[ROOT] == oldroot)) in dbFreeDmap()
2106 if ((rc = dbAdjCtl(bmp, blkno, dp->tree.stree[ROOT], 0, 0))) { in dbFreeDmap()
2107 word = (blkno & (BPERDMAP - 1)) >> L2DBWORD; in dbFreeDmap()
2114 if (dp->tree.stree[word] == NOFREE) in dbFreeDmap()
2115 dbBackSplit((dmtree_t *)&dp->tree, word, false); in dbFreeDmap()
2137 * bmp - pointer to bmap descriptor
2138 * dp - pointer to dmap to allocate bits from.
2139 * blkno - starting block number of the bits to be allocated.
2140 * nblocks - number of bits to be allocated.
2150 dmtree_t *tp = (dmtree_t *) & dp->tree; in dbAllocBits()
2155 leaf = dp->tree.stree + LEAFIND; in dbAllocBits()
2160 dbitno = blkno & (BPERDMAP - 1); in dbAllocBits()
2179 for (rembits = nblocks; rembits > 0; rembits -= nb, dbitno += nb) { in dbAllocBits()
2183 wbitno = dbitno & (DBWORD - 1); in dbAllocBits()
2184 nb = min(rembits, DBWORD - wbitno); in dbAllocBits()
2192 dp->wmap[word] |= cpu_to_le32(ONES << (DBWORD - nb) in dbAllocBits()
2201 dbMaxBud((u8 *)&dp->wmap[word]), false); in dbAllocBits()
2211 memset(&dp->wmap[word], (int) ONES, nwords * 4); in dbAllocBits()
2220 for (; nwords > 0; nwords -= nw) { in dbAllocBits()
2222 jfs_error(bmp->db_ipbmap->i_sb, in dbAllocBits()
2251 le32_add_cpu(&dp->nfree, -nblocks); in dbAllocBits()
2259 agno = blkno >> bmp->db_agl2size; in dbAllocBits()
2260 if (agno > bmp->db_maxag) in dbAllocBits()
2261 bmp->db_maxag = agno; in dbAllocBits()
2264 bmp->db_agfree[agno] -= nblocks; in dbAllocBits()
2265 bmp->db_nfree -= nblocks; in dbAllocBits()
2284 * bmp - pointer to bmap descriptor
2285 * dp - pointer to dmap to free bits from.
2286 * blkno - starting block number of the bits to be freed.
2287 * nblocks - number of bits to be freed.
2297 dmtree_t *tp = (dmtree_t *) & dp->tree; in dbFreeBits()
2304 dbitno = blkno & (BPERDMAP - 1); in dbFreeBits()
2328 for (rembits = nblocks; rembits > 0; rembits -= nb, dbitno += nb) { in dbFreeBits()
2332 wbitno = dbitno & (DBWORD - 1); in dbFreeBits()
2333 nb = min(rembits, DBWORD - wbitno); in dbFreeBits()
2341 dp->wmap[word] &= in dbFreeBits()
2342 cpu_to_le32(~(ONES << (DBWORD - nb) in dbFreeBits()
2348 dbMaxBud((u8 *)&dp->wmap[word]), false); in dbFreeBits()
2359 memset(&dp->wmap[word], 0, nwords * 4); in dbFreeBits()
2368 for (; nwords > 0; nwords -= nw) { in dbFreeBits()
2395 le32_add_cpu(&dp->nfree, nblocks); in dbFreeBits()
2402 agno = blkno >> bmp->db_agl2size; in dbFreeBits()
2403 bmp->db_nfree += nblocks; in dbFreeBits()
2404 bmp->db_agfree[agno] += nblocks; in dbFreeBits()
2411 if ((bmp->db_agfree[agno] == bmp->db_agsize && agno == bmp->db_maxag) || in dbFreeBits()
2412 (agno == bmp->db_numag - 1 && in dbFreeBits()
2413 bmp->db_agfree[agno] == (bmp-> db_mapsize & (BPERDMAP - 1)))) { in dbFreeBits()
2414 while (bmp->db_maxag > 0) { in dbFreeBits()
2415 bmp->db_maxag -= 1; in dbFreeBits()
2416 if (bmp->db_agfree[bmp->db_maxag] != in dbFreeBits()
2417 bmp->db_agsize) in dbFreeBits()
2421 /* re-establish the allocation group preference if the in dbFreeBits()
2425 if (bmp->db_agpref > bmp->db_maxag) in dbFreeBits()
2426 bmp->db_agpref = bmp->db_maxag; in dbFreeBits()
2460 * bmp - pointer to bmap descriptor
2461 * blkno - the first block of a block range within a dmap. it is
2464 * newval - the new value of the lower level dmap or dmap control
2466 * alloc - 'true' if adjustment is due to an allocation.
2467 * level - current level of dmap control page (i.e. L0, L1, L2) to
2471 * 0 - success
2472 * -EIO - i/o error
2489 lblkno = BLKTOCTL(blkno, bmp->db_l2nbperpage, level); in dbAdjCtl()
2490 mp = read_metapage(bmp->db_ipbmap, lblkno, PSIZE, 0); in dbAdjCtl()
2492 return -EIO; in dbAdjCtl()
2493 dcp = (struct dmapctl *) mp->data; in dbAdjCtl()
2495 if (dcp->leafidx != cpu_to_le32(CTLLEAFIND)) { in dbAdjCtl()
2496 jfs_error(bmp->db_ipbmap->i_sb, "Corrupt dmapctl page\n"); in dbAdjCtl()
2498 return -EIO; in dbAdjCtl()
2504 leafno = BLKTOCTLLEAF(blkno, dcp->budmin); in dbAdjCtl()
2505 ti = leafno + le32_to_cpu(dcp->leafidx); in dbAdjCtl()
2510 oldval = dcp->stree[ti]; in dbAdjCtl()
2511 oldroot = dcp->stree[ROOT]; in dbAdjCtl()
2538 oldval = dcp->stree[ti]; in dbAdjCtl()
2540 dbSplit((dmtree_t *) dcp, leafno, dcp->budmin, newval, true); in dbAdjCtl()
2556 if (dcp->stree[ROOT] != oldroot) { in dbAdjCtl()
2560 if (level < bmp->db_maxlevel) { in dbAdjCtl()
2565 dbAdjCtl(bmp, blkno, dcp->stree[ROOT], alloc, in dbAdjCtl()
2581 if (dcp->stree[ti] == NOFREE) in dbAdjCtl()
2585 dcp->budmin, oldval, true); in dbAdjCtl()
2598 assert(level == bmp->db_maxlevel); in dbAdjCtl()
2599 if (bmp->db_maxfreebud != oldroot) { in dbAdjCtl()
2600 jfs_error(bmp->db_ipbmap->i_sb, in dbAdjCtl()
2603 bmp->db_maxfreebud = dcp->stree[ROOT]; in dbAdjCtl()
2623 * tp - pointer to the tree containing the leaf.
2624 * leafno - the number of the leaf to be updated.
2625 * splitsz - the size the binary buddy system starting at the leaf
2627 * newval - the new value for the leaf.
2637 s8 *leaf = tp->dmt_stree + le32_to_cpu(tp->dmt_leafidx); in dbSplit()
2641 if (leaf[leafno] > tp->dmt_budmin) { in dbSplit()
2645 * - 1 in l2) and the corresponding buddy size. in dbSplit()
2647 cursz = leaf[leafno] - 1; in dbSplit()
2648 budsz = BUDSIZE(cursz, tp->dmt_budmin); in dbSplit()
2659 cursz -= 1; in dbSplit()
2691 * tp - pointer to the tree containing the leaf.
2692 * leafno - the number of the leaf to be updated.
2702 s8 *leaf = tp->dmt_stree + le32_to_cpu(tp->dmt_leafidx); in dbBackSplit()
2717 LITOL2BSZ(leafno, le32_to_cpu(tp->dmt_l2nleafs), in dbBackSplit()
2718 tp->dmt_budmin); in dbBackSplit()
2724 budsz = BUDSIZE(size, tp->dmt_budmin); in dbBackSplit()
2733 if (bsz >= le32_to_cpu(tp->dmt_nleafs)) { in dbBackSplit()
2735 return -EIO; in dbBackSplit()
2748 cursz = leaf[bud] - 1; in dbBackSplit()
2757 return -EIO; in dbBackSplit()
2767 * the leaf with other leaves of the dmtree into a multi-leaf
2771 * tp - pointer to the tree containing the leaf.
2772 * leafno - the number of the leaf to be updated.
2773 * newval - the new value for the leaf.
2784 if (newval >= tp->dmt_budmin) { in dbJoin()
2787 leaf = tp->dmt_stree + le32_to_cpu(tp->dmt_leafidx); in dbJoin()
2802 budsz = BUDSIZE(newval, tp->dmt_budmin); in dbJoin()
2806 while (budsz < le32_to_cpu(tp->dmt_nleafs)) { in dbJoin()
2819 return -EIO; in dbJoin()
2865 * tp - pointer to the tree to be adjusted.
2866 * leafno - the number of the leaf to be updated.
2867 * newval - the new value for the leaf.
2880 lp = leafno + le32_to_cpu(tp->dmt_leafidx); in dbAdjTree()
2888 if (tp->dmt_stree[lp] == newval) in dbAdjTree()
2893 tp->dmt_stree[lp] = newval; in dbAdjTree()
2897 for (k = 0; k < le32_to_cpu(tp->dmt_height); k++) { in dbAdjTree()
2904 lp = ((lp - 1) & ~0x03) + 1; in dbAdjTree()
2908 pp = (lp - 1) >> 2; in dbAdjTree()
2912 max = TREEMAX(&tp->dmt_stree[lp]); in dbAdjTree()
2917 if (tp->dmt_stree[pp] == max) in dbAdjTree()
2922 tp->dmt_stree[pp] = max; in dbAdjTree()
2924 /* parent becomes leaf for next go-round. in dbAdjTree()
2943 * tp - pointer to the tree to be searched.
2944 * l2nb - log2 number of free blocks to search for.
2945 * leafidx - return pointer to be set to the index of the leaf
2948 * is_ctl - determines if the tree is of type ctl
2951 * 0 - success
2952 * -ENOSPC - insufficient free blocks.
2965 if (l2nb > tp->dmt_stree[ROOT]) in dbFindLeaf()
2966 return -ENOSPC; in dbFindLeaf()
2972 for (k = le32_to_cpu(tp->dmt_height), ti = 1; in dbFindLeaf()
2973 k > 0; k--, ti = ((ti + n) << 2) + 1) { in dbFindLeaf()
2982 return -ENOSPC; in dbFindLeaf()
2983 if (l2nb <= tp->dmt_stree[x + n]) in dbFindLeaf()
2992 if (le32_to_cpu(tp->dmt_leafidx) >= max_idx) in dbFindLeaf()
2993 return -ENOSPC; in dbFindLeaf()
2998 *leafidx = x + n - le32_to_cpu(tp->dmt_leafidx); in dbFindLeaf()
3014 * word - dmap bitmap word value.
3015 * l2nb - number of free bits specified as a log2 number.
3034 mask = ONES << (DBWORD - nb); in dbFindBits()
3055 * bits within 32-bits of the map.
3058 * cp - pointer to the 32-bit value.
3074 * free buddy size is BUDMIN-1. in dbMaxBud()
3077 return (BUDMIN - 1); in dbMaxBud()
3091 * FUNCTION: determine the number of trailing zeros within a 32-bit
3095 * value - 32-bit value to be examined.
3116 * FUNCTION: determine the number of leading zeros within a 32-bit
3120 * value - 32-bit value to be examined.
3145 * nb - number of blocks
3155 mask = (s64) 1 << (64 - 1); in blkstol2()
3165 l2nb = (64 - 1) - l2nb; in blkstol2()
3190 * ip - pointer to in-core inode;
3191 * blkno - starting block number to be freed.
3192 * nblocks - number of blocks to be freed.
3195 * 0 - success
3196 * -EIO - i/o error
3204 struct inode *ipbmap = JFS_SBI(ip->i_sb)->ipbmap; in dbAllocBottomUp()
3205 struct bmap *bmp = JFS_SBI(ip->i_sb)->bmap; in dbAllocBottomUp()
3210 ASSERT(nblocks <= bmp->db_mapsize - blkno); in dbAllocBottomUp()
3216 for (rem = nblocks; rem > 0; rem -= nb, blkno += nb) { in dbAllocBottomUp()
3223 lblkno = BLKTODMAP(blkno, bmp->db_l2nbperpage); in dbAllocBottomUp()
3227 return -EIO; in dbAllocBottomUp()
3229 dp = (struct dmap *) mp->data; in dbAllocBottomUp()
3234 nb = min(rem, BPERDMAP - (blkno & (BPERDMAP - 1))); in dbAllocBottomUp()
3259 struct dmaptree *tp = (struct dmaptree *) & dp->tree; in dbAllocDmapBU()
3264 oldroot = tp->stree[ROOT]; in dbAllocDmapBU()
3269 dbitno = blkno & (BPERDMAP - 1); in dbAllocDmapBU()
3288 for (rembits = nblocks; rembits > 0; rembits -= nb, dbitno += nb) { in dbAllocDmapBU()
3292 wbitno = dbitno & (DBWORD - 1); in dbAllocDmapBU()
3293 nb = min(rembits, DBWORD - wbitno); in dbAllocDmapBU()
3301 dp->wmap[word] |= cpu_to_le32(ONES << (DBWORD - nb) in dbAllocDmapBU()
3312 memset(&dp->wmap[word], (int) ONES, nwords * 4); in dbAllocDmapBU()
3321 le32_add_cpu(&dp->nfree, -nblocks); in dbAllocDmapBU()
3332 agno = blkno >> bmp->db_agl2size; in dbAllocDmapBU()
3333 if (agno > bmp->db_maxag) in dbAllocDmapBU()
3334 bmp->db_maxag = agno; in dbAllocDmapBU()
3337 bmp->db_agfree[agno] -= nblocks; in dbAllocDmapBU()
3338 bmp->db_nfree -= nblocks; in dbAllocDmapBU()
3343 if (tp->stree[ROOT] == oldroot) in dbAllocDmapBU()
3350 if ((rc = dbAdjCtl(bmp, blkno, tp->stree[ROOT], 1, 0))) in dbAllocDmapBU()
3365 * L1---------------------------------L1
3367 * L0---------L0---------L0 L0---------L0---------L0
3372 * <---old---><----------------------------extend----------------------->
3376 struct jfs_sb_info *sbi = JFS_SBI(ipbmap->i_sb); in dbExtendFS()
3377 int nbperpage = sbi->nbperpage; in dbExtendFS()
3385 struct bmap *bmp = sbi->bmap; in dbExtendFS()
3402 bmp->db_mapsize = newsize; in dbExtendFS()
3403 bmp->db_maxlevel = BMAPSZTOLEV(bmp->db_mapsize); in dbExtendFS()
3407 oldl2agsize = bmp->db_agl2size; in dbExtendFS()
3409 bmp->db_agl2size = l2agsize; in dbExtendFS()
3410 bmp->db_agsize = (s64)1 << l2agsize; in dbExtendFS()
3413 agno = bmp->db_numag; in dbExtendFS()
3414 bmp->db_numag = newsize >> l2agsize; in dbExtendFS()
3415 bmp->db_numag += ((u32) newsize % (u32) bmp->db_agsize) ? 1 : 0; in dbExtendFS()
3422 * i.e., (AGi, ..., AGj) where i = k*n and j = k*(n+1) - 1 to AGn; in dbExtendFS()
3427 k = 1 << (l2agsize - oldl2agsize); in dbExtendFS()
3428 ag_rem = bmp->db_agfree[0]; /* save agfree[0] */ in dbExtendFS()
3430 bmp->db_agfree[n] = 0; /* init collection point */ in dbExtendFS()
3435 bmp->db_agfree[n] += bmp->db_agfree[i]; in dbExtendFS()
3438 bmp->db_agfree[0] += ag_rem; /* restore agfree[0] */ in dbExtendFS()
3441 bmp->db_agfree[n] = 0; in dbExtendFS()
3447 bmp->db_maxag = bmp->db_maxag / k; in dbExtendFS()
3460 jfs_error(ipbmap->i_sb, "L2 page could not be read\n"); in dbExtendFS()
3461 return -EIO; in dbExtendFS()
3463 l2dcp = (struct dmapctl *) l2mp->data; in dbExtendFS()
3467 l2leaf = l2dcp->stree + CTLLEAFIND + k; in dbExtendFS()
3468 p = BLKTOL1(blkno, sbi->l2nbperpage); /* L1 page */ in dbExtendFS()
3476 /* read in L1 page: (blkno & (MAXL1SIZE - 1)) */ in dbExtendFS()
3480 l1dcp = (struct dmapctl *) l1mp->data; in dbExtendFS()
3483 j = (blkno & (MAXL1SIZE - 1)) >> L2MAXL0SIZE; in dbExtendFS()
3484 l1leaf = l1dcp->stree + CTLLEAFIND + j; in dbExtendFS()
3485 p = BLKTOL0(blkno, sbi->l2nbperpage); in dbExtendFS()
3493 l1dcp = (struct dmapctl *) l1mp->data; in dbExtendFS()
3497 l1leaf = l1dcp->stree + CTLLEAFIND; in dbExtendFS()
3507 /* read in L0 page: (blkno & (MAXL0SIZE - 1)) */ in dbExtendFS()
3512 l0dcp = (struct dmapctl *) l0mp->data; in dbExtendFS()
3515 i = (blkno & (MAXL0SIZE - 1)) >> in dbExtendFS()
3517 l0leaf = l0dcp->stree + CTLLEAFIND + i; in dbExtendFS()
3519 sbi->l2nbperpage); in dbExtendFS()
3527 l0dcp = (struct dmapctl *) l0mp->data; in dbExtendFS()
3531 l0leaf = l0dcp->stree + CTLLEAFIND; in dbExtendFS()
3543 if ((n = blkno & (BPERDMAP - 1))) { in dbExtendFS()
3549 n = min(nblocks, (s64)BPERDMAP - n); in dbExtendFS()
3560 dp = (struct dmap *) mp->data; in dbExtendFS()
3563 bmp->db_nfree += n; in dbExtendFS()
3564 agno = le64_to_cpu(dp->start) >> l2agsize; in dbExtendFS()
3565 bmp->db_agfree[agno] += n; in dbExtendFS()
3573 nblocks -= n; in dbExtendFS()
3594 bmp->db_maxfreebud = *l1leaf; in dbExtendFS()
3618 bmp->db_maxfreebud = *l2leaf; in dbExtendFS()
3625 jfs_error(ipbmap->i_sb, "function has not returned as expected\n"); in dbExtendFS()
3632 return -EIO; in dbExtendFS()
3648 struct bmap *bmp = JFS_SBI(ipbmap->i_sb)->bmap; in dbFinalizeBmap()
3663 actags = bmp->db_maxag + 1; in dbFinalizeBmap()
3664 inactags = bmp->db_numag - actags; in dbFinalizeBmap()
3665 ag_rem = bmp->db_mapsize & (bmp->db_agsize - 1); /* ??? */ in dbFinalizeBmap()
3673 (((s64)inactags - 1) << bmp->db_agl2size) + ag_rem in dbFinalizeBmap()
3674 : ((s64)inactags << bmp->db_agl2size); in dbFinalizeBmap()
3680 actfree = bmp->db_nfree - inactfree; in dbFinalizeBmap()
3684 * re-establish the preferred group as the leftmost in dbFinalizeBmap()
3687 if (bmp->db_agfree[bmp->db_agpref] < avgfree) { in dbFinalizeBmap()
3688 for (bmp->db_agpref = 0; bmp->db_agpref < actags; in dbFinalizeBmap()
3689 bmp->db_agpref++) { in dbFinalizeBmap()
3690 if (bmp->db_agfree[bmp->db_agpref] >= avgfree) in dbFinalizeBmap()
3693 if (bmp->db_agpref >= bmp->db_numag) { in dbFinalizeBmap()
3694 jfs_error(ipbmap->i_sb, in dbFinalizeBmap()
3706 bmp->db_aglevel = BMAPSZTOLEV(bmp->db_agsize); in dbFinalizeBmap()
3708 bmp->db_agl2size - (L2BPERDMAP + bmp->db_aglevel * L2LPERCTL); in dbFinalizeBmap()
3709 bmp->db_agheight = l2nl >> 1; in dbFinalizeBmap()
3710 bmp->db_agwidth = 1 << (l2nl - (bmp->db_agheight << 1)); in dbFinalizeBmap()
3711 for (i = 5 - bmp->db_agheight, bmp->db_agstart = 0, n = 1; i > 0; in dbFinalizeBmap()
3712 i--) { in dbFinalizeBmap()
3713 bmp->db_agstart += n; in dbFinalizeBmap()
3732 * dp - pointer to page of map
3733 * nblocks - number of blocks this page
3742 blkno = Blkno & (BPERDMAP - 1); in dbInitDmap()
3745 dp->nblocks = dp->nfree = cpu_to_le32(nblocks); in dbInitDmap()
3746 dp->start = cpu_to_le64(Blkno); in dbInitDmap()
3749 memset(&dp->wmap[0], 0, LPERDMAP * 4); in dbInitDmap()
3750 memset(&dp->pmap[0], 0, LPERDMAP * 4); in dbInitDmap()
3754 le32_add_cpu(&dp->nblocks, nblocks); in dbInitDmap()
3755 le32_add_cpu(&dp->nfree, nblocks); in dbInitDmap()
3766 for (r = nblocks; r > 0; r -= nb, blkno += nb) { in dbInitDmap()
3768 b = blkno & (DBWORD - 1); in dbInitDmap()
3770 nb = min(r, DBWORD - b); in dbInitDmap()
3775 dp->wmap[w] &= cpu_to_le32(~(ONES << (DBWORD - nb) in dbInitDmap()
3777 dp->pmap[w] &= cpu_to_le32(~(ONES << (DBWORD - nb) in dbInitDmap()
3785 memset(&dp->wmap[w], 0, nw * 4); in dbInitDmap()
3786 memset(&dp->pmap[w], 0, nw * 4); in dbInitDmap()
3795 * mark bits following the range to be freed (non-existing in dbInitDmap()
3805 /* does nblocks fall on a 32-bit boundary ? */ in dbInitDmap()
3806 b = blkno & (DBWORD - 1); in dbInitDmap()
3809 dp->wmap[w] = dp->pmap[w] = cpu_to_le32(ONES >> b); in dbInitDmap()
3815 dp->pmap[i] = dp->wmap[i] = cpu_to_le32(ONES); in dbInitDmap()
3833 * dp - dmap to complete
3834 * blkno - starting block number for this dmap
3835 * treemax - will be filled in with max free for this dmap
3846 tp = &dp->tree; in dbInitDmapTree()
3847 tp->nleafs = cpu_to_le32(LPERDMAP); in dbInitDmapTree()
3848 tp->l2nleafs = cpu_to_le32(L2LPERDMAP); in dbInitDmapTree()
3849 tp->leafidx = cpu_to_le32(LEAFIND); in dbInitDmapTree()
3850 tp->height = cpu_to_le32(4); in dbInitDmapTree()
3851 tp->budmin = BUDMIN; in dbInitDmapTree()
3854 * note: leaf is set to NOFREE(-1) if all blocks of corresponding in dbInitDmapTree()
3857 cp = tp->stree + le32_to_cpu(tp->leafidx); in dbInitDmapTree()
3859 *cp++ = dbMaxBud((u8 *) & dp->wmap[i]); in dbInitDmapTree()
3878 * cp - Pointer to the root of the tree
3879 * l2leaves- Number of leaf nodes as a power of 2
3880 * l2min - Number of blocks that can be covered by a leaf
3891 tp = dtp->stree; in dbInitTree()
3894 l2max = le32_to_cpu(dtp->l2nleafs) + dtp->budmin; in dbInitTree()
3902 * the combination will result in the left-most buddy leaf having in dbInitTree()
3910 for (l2free = dtp->budmin, bsize = 1; l2free < l2max; in dbInitTree()
3916 for (i = 0, cp = tp + le32_to_cpu(dtp->leafidx); in dbInitTree()
3917 i < le32_to_cpu(dtp->nleafs); in dbInitTree()
3922 *(cp + bsize) = -1; /* right give left */ in dbInitTree()
3937 for (child = le32_to_cpu(dtp->leafidx), in dbInitTree()
3938 nparent = le32_to_cpu(dtp->nleafs) >> 2; in dbInitTree()
3941 parent = (child - 1) >> 2; in dbInitTree()
3964 dcp->nleafs = cpu_to_le32(LPERCTL); in dbInitDmapCtl()
3965 dcp->l2nleafs = cpu_to_le32(L2LPERCTL); in dbInitDmapCtl()
3966 dcp->leafidx = cpu_to_le32(CTLLEAFIND); in dbInitDmapCtl()
3967 dcp->height = cpu_to_le32(5); in dbInitDmapCtl()
3968 dcp->budmin = L2BPERDMAP + L2LPERCTL * level; in dbInitDmapCtl()
3975 cp = &dcp->stree[CTLLEAFIND + i]; in dbInitDmapCtl()
3990 * nblocks - Number of blocks in aggregate
4004 m = ((u64) 1 << (64 - 1)); in dbGetL2AGSize()
4005 for (l2sz = 64; l2sz >= 0; l2sz--, m >>= 1) { in dbGetL2AGSize()
4015 return (l2sz - L2MAXAG); in dbGetL2AGSize()
4043 struct super_block *sb = ipbmap->i_sb; in dbMapFileSizeToMapSize()
4049 nblocks = ipbmap->i_size >> JFS_SBI(sb)->l2bsize; in dbMapFileSizeToMapSize()
4050 npages = nblocks >> JFS_SBI(sb)->l2nbperpage; in dbMapFileSizeToMapSize()
4058 npages--; /* skip the first global control page */ in dbMapFileSizeToMapSize()
4060 npages -= (2 - level); in dbMapFileSizeToMapSize()
4061 npages--; /* skip top level's control page */ in dbMapFileSizeToMapSize()
4062 for (i = level; i >= 0; i--) { in dbMapFileSizeToMapSize()
4072 npages--; in dbMapFileSizeToMapSize()