Lines Matching +full:single +full:- +full:tt

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) International Business Machines Corp., 2000-2004
35 * as it works it way up from a single dmap to the required level
38 * and request that start from the bottom by the multiple read/single
41 * take the lock in read mode. a single top-down request may proceed
42 * exclusively while multiple bottoms-up requests may proceed
49 * a single exclusive lock (BMAP_LOCK) is used to guard this information
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()
181 bmp->db_l2nbperpage = le32_to_cpu(dbmp_le->dn_l2nbperpage); in dbMount()
182 bmp->db_numag = le32_to_cpu(dbmp_le->dn_numag); in dbMount()
183 bmp->db_maxlevel = le32_to_cpu(dbmp_le->dn_maxlevel); in dbMount()
184 bmp->db_maxag = le32_to_cpu(dbmp_le->dn_maxag); in dbMount()
185 bmp->db_agpref = le32_to_cpu(dbmp_le->dn_agpref); in dbMount()
186 bmp->db_aglevel = le32_to_cpu(dbmp_le->dn_aglevel); in dbMount()
187 bmp->db_agheight = le32_to_cpu(dbmp_le->dn_agheight); in dbMount()
188 bmp->db_agwidth = le32_to_cpu(dbmp_le->dn_agwidth); in dbMount()
189 bmp->db_agstart = le32_to_cpu(dbmp_le->dn_agstart); in dbMount()
190 bmp->db_agl2size = le32_to_cpu(dbmp_le->dn_agl2size); in dbMount()
192 if ((bmp->db_l2nbperpage > L2PSIZE - L2MINBLOCKSIZE) || in dbMount()
193 (bmp->db_l2nbperpage < 0) || in dbMount()
194 !bmp->db_numag || (bmp->db_numag > MAXAG) || in dbMount()
195 (bmp->db_maxag >= MAXAG) || (bmp->db_maxag < 0) || in dbMount()
196 (bmp->db_agpref >= MAXAG) || (bmp->db_agpref < 0) || in dbMount()
197 !bmp->db_agwidth || in dbMount()
198 (bmp->db_agl2size > L2MAXL2SIZE - L2MAXAG) || in dbMount()
199 (bmp->db_agl2size < 0) || in dbMount()
200 ((bmp->db_mapsize - 1) >> bmp->db_agl2size) > MAXAG) { in dbMount()
201 err = -EINVAL; in dbMount()
206 bmp->db_agfree[i] = le64_to_cpu(dbmp_le->dn_agfree[i]); in dbMount()
207 bmp->db_agsize = le64_to_cpu(dbmp_le->dn_agsize); in dbMount()
208 bmp->db_maxfreebud = dbmp_le->dn_maxfreebud; in dbMount()
214 bmp->db_ipbmap = ipbmap; in dbMount()
215 JFS_SBI(ipbmap->i_sb)->bmap = bmp; in dbMount()
217 memset(bmp->db_active, 0, sizeof(bmp->db_active)); in dbMount()
240 * the in-core bmap descriptor is written to disk and
244 * ipbmap - pointer to in-core inode for the block map.
247 * 0 - success
248 * -EIO - i/o error
252 struct bmap *bmp = JFS_SBI(ipbmap->i_sb)->bmap; in dbUnmount()
260 truncate_inode_pages(ipbmap->i_mapping, 0); in dbUnmount()
262 /* free the memory for the in-memory bmap. */ in dbUnmount()
264 JFS_SBI(ipbmap->i_sb)->bmap = NULL; in dbUnmount()
275 struct bmap *bmp = JFS_SBI(ipbmap->i_sb)->bmap; in dbSync()
282 /* get the buffer for the on-disk bmap descriptor. */ in dbSync()
284 BMAPBLKNO << JFS_SBI(ipbmap->i_sb)->l2nbperpage, in dbSync()
288 return -EIO; in dbSync()
290 /* copy the in-memory version of the bmap to the on-disk version */ in dbSync()
291 dbmp_le = (struct dbmap_disk *) mp->data; in dbSync()
292 dbmp_le->dn_mapsize = cpu_to_le64(bmp->db_mapsize); in dbSync()
293 dbmp_le->dn_nfree = cpu_to_le64(bmp->db_nfree); in dbSync()
294 dbmp_le->dn_l2nbperpage = cpu_to_le32(bmp->db_l2nbperpage); in dbSync()
295 dbmp_le->dn_numag = cpu_to_le32(bmp->db_numag); in dbSync()
296 dbmp_le->dn_maxlevel = cpu_to_le32(bmp->db_maxlevel); in dbSync()
297 dbmp_le->dn_maxag = cpu_to_le32(bmp->db_maxag); in dbSync()
298 dbmp_le->dn_agpref = cpu_to_le32(bmp->db_agpref); in dbSync()
299 dbmp_le->dn_aglevel = cpu_to_le32(bmp->db_aglevel); in dbSync()
300 dbmp_le->dn_agheight = cpu_to_le32(bmp->db_agheight); in dbSync()
301 dbmp_le->dn_agwidth = cpu_to_le32(bmp->db_agwidth); in dbSync()
302 dbmp_le->dn_agstart = cpu_to_le32(bmp->db_agstart); in dbSync()
303 dbmp_le->dn_agl2size = cpu_to_le32(bmp->db_agl2size); in dbSync()
305 dbmp_le->dn_agfree[i] = cpu_to_le64(bmp->db_agfree[i]); in dbSync()
306 dbmp_le->dn_agsize = cpu_to_le64(bmp->db_agsize); in dbSync()
307 dbmp_le->dn_maxfreebud = bmp->db_maxfreebud; in dbSync()
315 filemap_write_and_wait(ipbmap->i_mapping); in dbSync()
332 * ip - pointer to in-core inode;
333 * blkno - starting block number to be freed.
334 * nblocks - number of blocks to be freed.
337 * 0 - success
338 * -EIO - i/o error
346 struct inode *ipbmap = JFS_SBI(ip->i_sb)->ipbmap; in dbFree()
347 struct bmap *bmp = JFS_SBI(ip->i_sb)->bmap; in dbFree()
348 struct super_block *sb = ipbmap->i_sb; in dbFree()
353 if (unlikely((blkno == 0) || (blkno + nblocks > bmp->db_mapsize))) { in dbFree()
358 jfs_error(ip->i_sb, "block to be freed is outside the map\n"); in dbFree()
359 return -EIO; in dbFree()
365 if (JFS_SBI(sb)->flag & JFS_DISCARD) in dbFree()
366 if (JFS_SBI(sb)->minblks_trim <= nblocks) in dbFree()
373 for (rem = nblocks; rem > 0; rem -= nb, blkno += nb) { in dbFree()
380 lblkno = BLKTODMAP(blkno, bmp->db_l2nbperpage); in dbFree()
384 return -EIO; in dbFree()
386 dp = (struct dmap *) mp->data; in dbFree()
391 nb = min(rem, BPERDMAP - (blkno & (BPERDMAP - 1))); in dbFree()
395 jfs_error(ip->i_sb, "error in block map\n"); in dbFree()
422 * ipbmap - pointer to in-core inode for the block map.
423 * free - 'true' if block range is to be freed from the persistent
425 * blkno - starting block number of the range.
426 * nblocks - number of contiguous blocks in the range.
427 * tblk - transaction block;
430 * 0 - success
431 * -EIO - i/o error
439 struct bmap *bmp = JFS_SBI(ipbmap->i_sb)->bmap; in dbUpdatePMap()
449 if (blkno + nblocks > bmp->db_mapsize) { in dbUpdatePMap()
453 jfs_error(ipbmap->i_sb, "blocks are outside the map\n"); in dbUpdatePMap()
454 return -EIO; in dbUpdatePMap()
458 lsn = tblk->lsn; in dbUpdatePMap()
459 log = (struct jfs_log *) JFS_SBI(tblk->sb)->log; in dbUpdatePMap()
467 for (rem = nblocks; rem > 0; rem -= nblks, blkno += nblks) { in dbUpdatePMap()
469 lblkno = BLKTODMAP(blkno, bmp->db_l2nbperpage); in dbUpdatePMap()
475 mp = read_metapage(bmp->db_ipbmap, lblkno, PSIZE, in dbUpdatePMap()
478 return -EIO; in dbUpdatePMap()
481 dp = (struct dmap *) mp->data; in dbUpdatePMap()
487 dbitno = blkno & (BPERDMAP - 1); in dbUpdatePMap()
489 nblks = min(rem, (s64)BPERDMAP - dbitno); in dbUpdatePMap()
494 * partial first and/or last) only in a single pass. a in dbUpdatePMap()
495 * single pass will also be used to update all words that in dbUpdatePMap()
499 rbits -= nbits, dbitno += nbits) { in dbUpdatePMap()
503 wbitno = dbitno & (DBWORD - 1); in dbUpdatePMap()
504 nbits = min(rbits, DBWORD - wbitno); in dbUpdatePMap()
512 (ONES << (DBWORD - nbits) >> wbitno); in dbUpdatePMap()
514 dp->pmap[word] &= in dbUpdatePMap()
517 dp->pmap[word] |= in dbUpdatePMap()
533 memset(&dp->pmap[word], 0, in dbUpdatePMap()
536 memset(&dp->pmap[word], (int) ONES, in dbUpdatePMap()
552 if (mp->lsn != 0) { in dbUpdatePMap()
554 logdiff(diffp, mp->lsn, log); in dbUpdatePMap()
556 mp->lsn = lsn; in dbUpdatePMap()
559 list_move(&mp->synclist, &tblk->synclist); in dbUpdatePMap()
563 logdiff(difft, tblk->clsn, log); in dbUpdatePMap()
564 logdiff(diffp, mp->clsn, log); in dbUpdatePMap()
566 mp->clsn = tblk->clsn; in dbUpdatePMap()
568 mp->log = log; in dbUpdatePMap()
569 mp->lsn = lsn; in dbUpdatePMap()
572 log->count++; in dbUpdatePMap()
573 list_add(&mp->synclist, &tblk->synclist); in dbUpdatePMap()
575 mp->clsn = tblk->clsn; in dbUpdatePMap()
597 * new inode allocation towards. The tie-in between inode
608 * ipbmap - pointer to in-core inode for the block map.
619 int next_best = -1; in dbNextAG()
620 struct bmap *bmp = JFS_SBI(ipbmap->i_sb)->bmap; in dbNextAG()
625 avgfree = (u32)bmp->db_nfree / bmp->db_numag; in dbNextAG()
631 agpref = bmp->db_agpref; in dbNextAG()
632 if ((atomic_read(&bmp->db_active[agpref]) == 0) && in dbNextAG()
633 (bmp->db_agfree[agpref] >= avgfree)) in dbNextAG()
639 for (i = 0 ; i < bmp->db_numag; i++, agpref++) { in dbNextAG()
640 if (agpref >= bmp->db_numag) in dbNextAG()
643 if (atomic_read(&bmp->db_active[agpref])) in dbNextAG()
646 if (bmp->db_agfree[agpref] >= avgfree) { in dbNextAG()
648 bmp->db_agpref = agpref; in dbNextAG()
650 } else if (bmp->db_agfree[agpref] > hwm) { in dbNextAG()
652 hwm = bmp->db_agfree[agpref]; in dbNextAG()
661 if (next_best != -1) in dbNextAG()
662 bmp->db_agpref = next_best; in dbNextAG()
669 return (bmp->db_agpref); in dbNextAG()
678 * the block allocation policy uses hints and a multi-step
699 * ip - pointer to in-core inode;
700 * hint - allocation hint.
701 * nblocks - number of contiguous blocks in the range.
702 * results - on successful return, set to the starting block number
706 * 0 - success
707 * -ENOSPC - insufficient disk resources
708 * -EIO - i/o error
713 struct inode *ipbmap = JFS_SBI(ip->i_sb)->ipbmap; in dbAlloc()
731 bmp = JFS_SBI(ip->i_sb)->bmap; in dbAlloc()
733 mapSize = bmp->db_mapsize; in dbAlloc()
737 jfs_error(ip->i_sb, "the hint is outside the map\n"); in dbAlloc()
738 return -EIO; in dbAlloc()
744 if (l2nb > bmp->db_agl2size) { in dbAlloc()
764 if (blkno >= bmp->db_mapsize) in dbAlloc()
767 agno = blkno >> bmp->db_agl2size; in dbAlloc()
773 if ((blkno & (bmp->db_agsize - 1)) == 0) in dbAlloc()
775 * if so, call dbNextAG() to find a non-busy in dbAlloc()
778 if (atomic_read(&bmp->db_active[agno])) in dbAlloc()
782 * single dmap. if so, try to allocate from the dmap containing in dbAlloc()
790 rc = -EIO; in dbAlloc()
791 lblkno = BLKTODMAP(blkno, bmp->db_l2nbperpage); in dbAlloc()
796 dp = (struct dmap *) mp->data; in dbAlloc()
802 != -ENOSPC) { in dbAlloc()
812 writers = atomic_read(&bmp->db_active[agno]); in dbAlloc()
814 ((writers == 1) && (JFS_IP(ip)->active_ag != agno))) { in dbAlloc()
829 != -ENOSPC) { in dbAlloc()
841 != -ENOSPC) { in dbAlloc()
857 if ((rc = dbAllocAG(bmp, agno, nblocks, l2nb, results)) != -ENOSPC) in dbAlloc()
873 if ((rc = dbAllocAG(bmp, agno, nblocks, l2nb, results)) == -ENOSPC) in dbAlloc()
903 * ip - pointer to in-core inode requiring allocation.
904 * blkno - starting block of the current allocation.
905 * nblocks - number of contiguous blocks within the current
907 * addnblocks - number of blocks to add to the allocation.
908 * results - on successful return, set to the starting block number
915 * 0 - success
916 * -ENOSPC - insufficient disk resources
917 * -EIO - i/o error
931 if (rc != -ENOSPC) in dbReAlloc()
941 (ip, blkno + nblocks - 1, addnblocks + nblocks, results)); in dbReAlloc()
957 * ip - pointer to in-core inode requiring allocation.
958 * blkno - starting block of the current allocation.
959 * nblocks - number of contiguous blocks within the current
961 * addnblocks - number of blocks to add to the allocation.
964 * 0 - success
965 * -ENOSPC - insufficient disk resources
966 * -EIO - i/o error
970 struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb); in dbExtend()
976 struct inode *ipbmap = sbi->ipbmap; in dbExtend()
980 * We don't want a non-aligned extent to cross a page boundary in dbExtend()
982 if (((rel_block = blkno & (sbi->nbperpage - 1))) && in dbExtend()
983 (rel_block + nblocks + addnblocks > sbi->nbperpage)) in dbExtend()
984 return -ENOSPC; in dbExtend()
987 lastblkno = blkno + nblocks - 1; in dbExtend()
997 bmp = sbi->bmap; in dbExtend()
998 if (lastblkno < 0 || lastblkno >= bmp->db_mapsize) { in dbExtend()
1000 jfs_error(ip->i_sb, "the block is outside the filesystem\n"); in dbExtend()
1001 return -EIO; in dbExtend()
1012 if (addnblocks > BPERDMAP || extblkno >= bmp->db_mapsize || in dbExtend()
1013 (extblkno & (bmp->db_agsize - 1)) == 0) { in dbExtend()
1015 return -ENOSPC; in dbExtend()
1021 lblkno = BLKTODMAP(extblkno, bmp->db_l2nbperpage); in dbExtend()
1025 return -EIO; in dbExtend()
1028 dp = (struct dmap *) mp->data; in dbExtend()
1055 * bmp - pointer to bmap descriptor
1056 * dp - pointer to dmap.
1057 * blkno - starting block number of the range.
1058 * nblocks - number of contiguous free blocks of the range.
1061 * 0 - success
1062 * -ENOSPC - insufficient disk resources
1063 * -EIO - i/o error
1075 if (dp->tree.leafidx != cpu_to_le32(LEAFIND)) { in dbAllocNext()
1076 jfs_error(bmp->db_ipbmap->i_sb, "Corrupt dmap page\n"); in dbAllocNext()
1077 return -EIO; in dbAllocNext()
1082 leaf = dp->tree.stree + le32_to_cpu(dp->tree.leafidx); in dbAllocNext()
1087 dbitno = blkno & (BPERDMAP - 1); in dbAllocNext()
1094 return -ENOSPC; in dbAllocNext()
1100 return -ENOSPC; in dbAllocNext()
1106 * and/or last) on an individual basis (a single pass) and examine in dbAllocNext()
1107 * the actual bits to determine if they are free. a single pass in dbAllocNext()
1111 * single leaf may describe the free space of multiple dmap in dbAllocNext()
1115 for (rembits = nblocks; rembits > 0; rembits -= nb, dbitno += nb) { in dbAllocNext()
1119 wbitno = dbitno & (DBWORD - 1); in dbAllocNext()
1120 nb = min(rembits, DBWORD - wbitno); in dbAllocNext()
1127 mask = (ONES << (DBWORD - nb) >> wbitno); in dbAllocNext()
1128 if ((mask & ~le32_to_cpu(dp->wmap[word])) != mask) in dbAllocNext()
1129 return -ENOSPC; in dbAllocNext()
1147 return -ENOSPC; in dbAllocNext()
1159 nwords -= nw; in dbAllocNext()
1183 * bmp - pointer to bmap descriptor
1184 * dp - pointer to dmap.
1185 * blkno - block number to allocate near.
1186 * nblocks - actual number of contiguous free blocks desired.
1187 * l2nb - log2 number of contiguous free blocks desired.
1188 * results - on successful return, set to the starting block number
1192 * 0 - success
1193 * -ENOSPC - insufficient disk resources
1194 * -EIO - i/o error
1205 if (dp->tree.leafidx != cpu_to_le32(LEAFIND)) { in dbAllocNear()
1206 jfs_error(bmp->db_ipbmap->i_sb, "Corrupt dmap page\n"); in dbAllocNear()
1207 return -EIO; in dbAllocNear()
1210 leaf = dp->tree.stree + le32_to_cpu(dp->tree.leafidx); in dbAllocNear()
1216 word = (blkno & (BPERDMAP - 1)) >> L2DBWORD; in dbAllocNear()
1230 blkno = le64_to_cpu(dp->start) + (word << L2DBWORD); in dbAllocNear()
1239 dbFindBits(le32_to_cpu(dp->wmap[word]), l2nb); in dbAllocNear()
1249 return -ENOSPC; in dbAllocNear()
1270 * or two sub-trees, depending on the allocation group size.
1293 * bmp - pointer to bmap descriptor
1294 * agno - allocation group number.
1295 * nblocks - actual number of contiguous free blocks desired.
1296 * l2nb - log2 number of contiguous free blocks desired.
1297 * results - on successful return, set to the starting block number
1301 * 0 - success
1302 * -ENOSPC - insufficient disk resources
1303 * -EIO - i/o error
1319 if (l2nb > bmp->db_agl2size) { in dbAllocAG()
1320 jfs_error(bmp->db_ipbmap->i_sb, in dbAllocAG()
1322 return -EIO; in dbAllocAG()
1328 blkno = (s64) agno << bmp->db_agl2size; in dbAllocAG()
1347 if (bmp->db_agsize == BPERDMAP in dbAllocAG()
1348 || bmp->db_agfree[agno] == bmp->db_agsize) { in dbAllocAG()
1350 if ((rc == -ENOSPC) && in dbAllocAG()
1351 (bmp->db_agfree[agno] == bmp->db_agsize)) { in dbAllocAG()
1355 jfs_error(bmp->db_ipbmap->i_sb, in dbAllocAG()
1364 lblkno = BLKTOCTL(blkno, bmp->db_l2nbperpage, bmp->db_aglevel); in dbAllocAG()
1365 mp = read_metapage(bmp->db_ipbmap, lblkno, PSIZE, 0); in dbAllocAG()
1367 return -EIO; in dbAllocAG()
1368 dcp = (struct dmapctl *) mp->data; in dbAllocAG()
1369 budmin = dcp->budmin; in dbAllocAG()
1371 if (dcp->leafidx != cpu_to_le32(CTLLEAFIND)) { in dbAllocAG()
1372 jfs_error(bmp->db_ipbmap->i_sb, "Corrupt dmapctl page\n"); in dbAllocAG()
1374 return -EIO; in dbAllocAG()
1385 (1 << (L2LPERCTL - (bmp->db_agheight << 1))) / bmp->db_agwidth; in dbAllocAG()
1386 ti = bmp->db_agstart + bmp->db_agwidth * (agno & (agperlev - 1)); in dbAllocAG()
1388 /* dmap control page trees fan-out by 4 and a single allocation in dbAllocAG()
1394 for (i = 0; i < bmp->db_agwidth; i++, ti++) { in dbAllocAG()
1397 if (l2nb > dcp->stree[ti]) in dbAllocAG()
1404 for (k = bmp->db_agheight; k > 0; k--) { in dbAllocAG()
1406 if (l2nb <= dcp->stree[m + n]) { in dbAllocAG()
1412 jfs_error(bmp->db_ipbmap->i_sb, in dbAllocAG()
1415 return -EIO; in dbAllocAG()
1422 if (bmp->db_aglevel == 2) in dbAllocAG()
1424 else if (bmp->db_aglevel == 1) in dbAllocAG()
1425 blkno &= ~(MAXL1SIZE - 1); in dbAllocAG()
1426 else /* bmp->db_aglevel == 0 */ in dbAllocAG()
1427 blkno &= ~(MAXL0SIZE - 1); in dbAllocAG()
1430 ((s64) (ti - le32_to_cpu(dcp->leafidx))) << budmin; in dbAllocAG()
1449 dbFindCtl(bmp, l2nb, bmp->db_aglevel - 1, in dbAllocAG()
1451 if (rc == -ENOSPC) { in dbAllocAG()
1452 jfs_error(bmp->db_ipbmap->i_sb, in dbAllocAG()
1454 return -EIO; in dbAllocAG()
1463 if (rc == -ENOSPC) { in dbAllocAG()
1464 jfs_error(bmp->db_ipbmap->i_sb, in dbAllocAG()
1466 rc = -EIO; in dbAllocAG()
1472 * return -ENOSPC. in dbAllocAG()
1476 return -ENOSPC; in dbAllocAG()
1493 * bmp - pointer to bmap descriptor
1494 * nblocks - actual number of contiguous free blocks desired.
1495 * l2nb - log2 number of contiguous free blocks desired.
1496 * results - on successful return, set to the starting block number
1500 * 0 - success
1501 * -ENOSPC - insufficient disk resources
1502 * -EIO - i/o error
1517 if ((rc = dbFindCtl(bmp, l2nb, bmp->db_maxlevel, &blkno))) in dbAllocAny()
1523 if (rc == -ENOSPC) { in dbAllocAny()
1524 jfs_error(bmp->db_ipbmap->i_sb, "unable to allocate blocks\n"); in dbAllocAny()
1525 return -EIO; in dbAllocAny()
1543 * - we work only on one ag at some time, minimizing how long we
1545 * - reading / writing the fs is possible most time, even on
1549 * - we write two times to the dmapctl and dmap pages
1550 * - but for me, this seems the best way, better ideas?
1554 * ip - pointer to in-core inode
1555 * agno - ag to trim
1556 * minlen - minimum value of contiguous blocks
1559 * s64 - actual number of blocks trimmed
1563 struct inode *ipbmap = JFS_SBI(ip->i_sb)->ipbmap; in dbDiscardAG()
1564 struct bmap *bmp = JFS_SBI(ip->i_sb)->bmap; in dbDiscardAG()
1568 struct super_block *sb = ipbmap->i_sb; in dbDiscardAG()
1573 } *totrim, *tt; in dbDiscardAG() local
1582 nblocks = bmp->db_agfree[agno]; in dbDiscardAG()
1588 jfs_error(bmp->db_ipbmap->i_sb, "no memory for trim array\n"); in dbDiscardAG()
1593 tt = totrim; in dbDiscardAG()
1597 /* 0 = okay, -EIO = fatal, -ENOSPC -> try smaller block */ in dbDiscardAG()
1600 tt->blkno = blkno; in dbDiscardAG()
1601 tt->nblocks = nblocks; in dbDiscardAG()
1602 tt++; count++; in dbDiscardAG()
1605 if (bmp->db_agfree[agno] == 0) in dbDiscardAG()
1609 nblocks = bmp->db_agfree[agno]; in dbDiscardAG()
1611 } else if (rc == -ENOSPC) { in dbDiscardAG()
1613 l2nb = BLKSTOL2(nblocks) - 1; in dbDiscardAG()
1619 jfs_error(bmp->db_ipbmap->i_sb, "-EIO\n"); in dbDiscardAG()
1624 if (unlikely(count >= range_cnt - 1)) in dbDiscardAG()
1629 tt->nblocks = 0; /* mark the current end */ in dbDiscardAG()
1630 for (tt = totrim; tt->nblocks != 0; tt++) { in dbDiscardAG()
1633 if (!(JFS_SBI(sb)->flag & JFS_DISCARD)) in dbDiscardAG()
1634 jfs_issue_discard(ip, tt->blkno, tt->nblocks); in dbDiscardAG()
1635 dbFree(ip, tt->blkno, tt->nblocks); in dbDiscardAG()
1636 trimmed += tt->nblocks; in dbDiscardAG()
1657 * bmp - pointer to bmap descriptor
1658 * level - starting dmap control page level.
1659 * l2nb - log2 number of contiguous free blocks desired.
1660 * *blkno - on entry, starting block number for conducting the search.
1665 * 0 - success
1666 * -ENOSPC - insufficient disk resources
1667 * -EIO - i/o error
1684 for (lev = level, b = *blkno; lev >= 0; lev--) { in dbFindCtl()
1688 lblkno = BLKTOCTL(b, bmp->db_l2nbperpage, lev); in dbFindCtl()
1689 mp = read_metapage(bmp->db_ipbmap, lblkno, PSIZE, 0); in dbFindCtl()
1691 return -EIO; in dbFindCtl()
1692 dcp = (struct dmapctl *) mp->data; in dbFindCtl()
1693 budmin = dcp->budmin; in dbFindCtl()
1695 if (dcp->leafidx != cpu_to_le32(CTLLEAFIND)) { in dbFindCtl()
1696 jfs_error(bmp->db_ipbmap->i_sb, in dbFindCtl()
1699 return -EIO; in dbFindCtl()
1717 jfs_error(bmp->db_ipbmap->i_sb, in dbFindCtl()
1719 return -EIO; in dbFindCtl()
1721 return -ENOSPC; in dbFindCtl()
1774 * bmp - pointer to bmap descriptor
1775 * nblocks - actual number of contiguous free blocks to allocate.
1776 * l2nb - log2 number of contiguous free blocks to allocate.
1777 * blkno - starting block number of the dmap to start the allocation
1779 * results - on successful return, set to the starting block number
1783 * 0 - success
1784 * -ENOSPC - insufficient disk resources
1785 * -EIO - i/o error
1797 /* check if the allocation request is confined to a single dmap. in dbAllocCtl()
1802 lblkno = BLKTODMAP(blkno, bmp->db_l2nbperpage); in dbAllocCtl()
1803 mp = read_metapage(bmp->db_ipbmap, lblkno, PSIZE, 0); in dbAllocCtl()
1805 return -EIO; in dbAllocCtl()
1806 dp = (struct dmap *) mp->data; in dbAllocCtl()
1808 if (dp->tree.budmin < 0) in dbAllocCtl()
1809 return -EIO; in dbAllocCtl()
1825 assert((blkno & (BPERDMAP - 1)) == 0); in dbAllocCtl()
1829 for (n = nblocks, b = blkno; n > 0; n -= nb, b += nb) { in dbAllocCtl()
1832 lblkno = BLKTODMAP(b, bmp->db_l2nbperpage); in dbAllocCtl()
1833 mp = read_metapage(bmp->db_ipbmap, lblkno, PSIZE, 0); in dbAllocCtl()
1835 rc = -EIO; in dbAllocCtl()
1838 dp = (struct dmap *) mp->data; in dbAllocCtl()
1842 if (dp->tree.stree[ROOT] != L2BPERDMAP) { in dbAllocCtl()
1844 jfs_error(bmp->db_ipbmap->i_sb, in dbAllocCtl()
1846 rc = -EIO; in dbAllocCtl()
1881 for (n = nblocks - n, b = blkno; n > 0; in dbAllocCtl()
1882 n -= BPERDMAP, b += BPERDMAP) { in dbAllocCtl()
1885 lblkno = BLKTODMAP(b, bmp->db_l2nbperpage); in dbAllocCtl()
1886 mp = read_metapage(bmp->db_ipbmap, lblkno, PSIZE, 0); in dbAllocCtl()
1891 jfs_error(bmp->db_ipbmap->i_sb, in dbAllocCtl()
1895 dp = (struct dmap *) mp->data; in dbAllocCtl()
1904 jfs_error(bmp->db_ipbmap->i_sb, "Block Leakage\n"); in dbAllocCtl()
1928 * mp - pointer to bmap descriptor
1929 * dp - pointer to dmap to attempt to allocate blocks from.
1930 * l2nb - log2 number of contiguous block desired.
1931 * nblocks - actual number of contiguous block desired.
1932 * results - on successful return, set to the starting block number
1936 * 0 - success
1937 * -ENOSPC - insufficient disk resources
1938 * -EIO - i/o error
1957 if (dbFindLeaf((dmtree_t *) &dp->tree, l2nb, &leafidx, false)) in dbAllocDmapLev()
1958 return -ENOSPC; in dbAllocDmapLev()
1961 return -EIO; in dbAllocDmapLev()
1966 blkno = le64_to_cpu(dp->start) + (leafidx << L2DBWORD); in dbAllocDmapLev()
1972 if (dp->tree.stree[leafidx + LEAFIND] < BUDMIN) in dbAllocDmapLev()
1973 blkno += dbFindBits(le32_to_cpu(dp->wmap[leafidx]), l2nb); in dbAllocDmapLev()
1999 * bmp - pointer to bmap descriptor
2000 * dp - pointer to dmap to allocate the block range from.
2001 * blkno - starting block number of the block to be allocated.
2002 * nblocks - number of blocks to be allocated.
2005 * 0 - success
2006 * -EIO - i/o error
2019 oldroot = dp->tree.stree[ROOT]; in dbAllocDmap()
2025 if (dp->tree.stree[ROOT] == oldroot) in dbAllocDmap()
2032 if ((rc = dbAdjCtl(bmp, blkno, dp->tree.stree[ROOT], 1, 0))) in dbAllocDmap()
2054 * bmp - pointer to bmap descriptor
2055 * dp - pointer to dmap to free the block range from.
2056 * blkno - starting block number of the block to be freed.
2057 * nblocks - number of blocks to be freed.
2060 * 0 - success
2061 * -EIO - i/o error
2074 oldroot = dp->tree.stree[ROOT]; in dbFreeDmap()
2080 if (rc || (dp->tree.stree[ROOT] == oldroot)) in dbFreeDmap()
2087 if ((rc = dbAdjCtl(bmp, blkno, dp->tree.stree[ROOT], 0, 0))) { in dbFreeDmap()
2088 word = (blkno & (BPERDMAP - 1)) >> L2DBWORD; in dbFreeDmap()
2095 if (dp->tree.stree[word] == NOFREE) in dbFreeDmap()
2096 dbBackSplit((dmtree_t *)&dp->tree, word, false); in dbFreeDmap()
2118 * bmp - pointer to bmap descriptor
2119 * dp - pointer to dmap to allocate bits from.
2120 * blkno - starting block number of the bits to be allocated.
2121 * nblocks - number of bits to be allocated.
2131 dmtree_t *tp = (dmtree_t *) & dp->tree; in dbAllocBits()
2136 leaf = dp->tree.stree + LEAFIND; in dbAllocBits()
2141 dbitno = blkno & (BPERDMAP - 1); in dbAllocBits()
2151 * (a single pass), allocating the bits of interest by hand and in dbAllocBits()
2152 * updating the leaf corresponding to the dmap word. a single pass in dbAllocBits()
2155 * dmap words will be marked as free in a single shot and the leaves in dbAllocBits()
2156 * will be updated. a single leaf may describe the free space of in dbAllocBits()
2160 for (rembits = nblocks; rembits > 0; rembits -= nb, dbitno += nb) { in dbAllocBits()
2164 wbitno = dbitno & (DBWORD - 1); in dbAllocBits()
2165 nb = min(rembits, DBWORD - wbitno); in dbAllocBits()
2173 dp->wmap[word] |= cpu_to_le32(ONES << (DBWORD - nb) in dbAllocBits()
2182 dbMaxBud((u8 *)&dp->wmap[word]), false); in dbAllocBits()
2192 memset(&dp->wmap[word], (int) ONES, nwords * 4); in dbAllocBits()
2201 for (; nwords > 0; nwords -= nw) { in dbAllocBits()
2203 jfs_error(bmp->db_ipbmap->i_sb, in dbAllocBits()
2232 le32_add_cpu(&dp->nfree, -nblocks); in dbAllocBits()
2240 agno = blkno >> bmp->db_agl2size; in dbAllocBits()
2241 if (agno > bmp->db_maxag) in dbAllocBits()
2242 bmp->db_maxag = agno; in dbAllocBits()
2245 bmp->db_agfree[agno] -= nblocks; in dbAllocBits()
2246 bmp->db_nfree -= nblocks; in dbAllocBits()
2265 * bmp - pointer to bmap descriptor
2266 * dp - pointer to dmap to free bits from.
2267 * blkno - starting block number of the bits to be freed.
2268 * nblocks - number of bits to be freed.
2278 dmtree_t *tp = (dmtree_t *) & dp->tree; in dbFreeBits()
2285 dbitno = blkno & (BPERDMAP - 1); in dbFreeBits()
2296 * (a single pass), freeing the bits of interest by hand and updating in dbFreeBits()
2297 * the leaf corresponding to the dmap word. a single pass will be used in dbFreeBits()
2300 * be marked as free in a single shot and the leaves will be updated. a in dbFreeBits()
2301 * single leaf may describe the free space of multiple dmap words, in dbFreeBits()
2309 for (rembits = nblocks; rembits > 0; rembits -= nb, dbitno += nb) { in dbFreeBits()
2313 wbitno = dbitno & (DBWORD - 1); in dbFreeBits()
2314 nb = min(rembits, DBWORD - wbitno); in dbFreeBits()
2322 dp->wmap[word] &= in dbFreeBits()
2323 cpu_to_le32(~(ONES << (DBWORD - nb) in dbFreeBits()
2329 dbMaxBud((u8 *)&dp->wmap[word]), false); in dbFreeBits()
2340 memset(&dp->wmap[word], 0, nwords * 4); in dbFreeBits()
2349 for (; nwords > 0; nwords -= nw) { in dbFreeBits()
2376 le32_add_cpu(&dp->nfree, nblocks); in dbFreeBits()
2383 agno = blkno >> bmp->db_agl2size; in dbFreeBits()
2384 bmp->db_nfree += nblocks; in dbFreeBits()
2385 bmp->db_agfree[agno] += nblocks; in dbFreeBits()
2392 if ((bmp->db_agfree[agno] == bmp->db_agsize && agno == bmp->db_maxag) || in dbFreeBits()
2393 (agno == bmp->db_numag - 1 && in dbFreeBits()
2394 bmp->db_agfree[agno] == (bmp-> db_mapsize & (BPERDMAP - 1)))) { in dbFreeBits()
2395 while (bmp->db_maxag > 0) { in dbFreeBits()
2396 bmp->db_maxag -= 1; in dbFreeBits()
2397 if (bmp->db_agfree[bmp->db_maxag] != in dbFreeBits()
2398 bmp->db_agsize) in dbFreeBits()
2402 /* re-establish the allocation group preference if the in dbFreeBits()
2406 if (bmp->db_agpref > bmp->db_maxag) in dbFreeBits()
2407 bmp->db_agpref = bmp->db_maxag; in dbFreeBits()
2423 * or deallocation of a range of blocks with a single dmap.
2429 * is respresented by a single leaf of the current dmapctl
2441 * bmp - pointer to bmap descriptor
2442 * blkno - the first block of a block range within a dmap. it is
2445 * newval - the new value of the lower level dmap or dmap control
2447 * alloc - 'true' if adjustment is due to an allocation.
2448 * level - current level of dmap control page (i.e. L0, L1, L2) to
2452 * 0 - success
2453 * -EIO - i/o error
2470 lblkno = BLKTOCTL(blkno, bmp->db_l2nbperpage, level); in dbAdjCtl()
2471 mp = read_metapage(bmp->db_ipbmap, lblkno, PSIZE, 0); in dbAdjCtl()
2473 return -EIO; in dbAdjCtl()
2474 dcp = (struct dmapctl *) mp->data; in dbAdjCtl()
2476 if (dcp->leafidx != cpu_to_le32(CTLLEAFIND)) { in dbAdjCtl()
2477 jfs_error(bmp->db_ipbmap->i_sb, "Corrupt dmapctl page\n"); in dbAdjCtl()
2479 return -EIO; in dbAdjCtl()
2485 leafno = BLKTOCTLLEAF(blkno, dcp->budmin); in dbAdjCtl()
2486 ti = leafno + le32_to_cpu(dcp->leafidx); in dbAdjCtl()
2491 oldval = dcp->stree[ti]; in dbAdjCtl()
2492 oldroot = dcp->stree[ROOT]; in dbAdjCtl()
2519 oldval = dcp->stree[ti]; in dbAdjCtl()
2521 dbSplit((dmtree_t *) dcp, leafno, dcp->budmin, newval, true); in dbAdjCtl()
2537 if (dcp->stree[ROOT] != oldroot) { in dbAdjCtl()
2541 if (level < bmp->db_maxlevel) { in dbAdjCtl()
2546 dbAdjCtl(bmp, blkno, dcp->stree[ROOT], alloc, in dbAdjCtl()
2562 if (dcp->stree[ti] == NOFREE) in dbAdjCtl()
2566 dcp->budmin, oldval, true); in dbAdjCtl()
2579 assert(level == bmp->db_maxlevel); in dbAdjCtl()
2580 if (bmp->db_maxfreebud != oldroot) { in dbAdjCtl()
2581 jfs_error(bmp->db_ipbmap->i_sb, in dbAdjCtl()
2584 bmp->db_maxfreebud = dcp->stree[ROOT]; in dbAdjCtl()
2604 * tp - pointer to the tree containing the leaf.
2605 * leafno - the number of the leaf to be updated.
2606 * splitsz - the size the binary buddy system starting at the leaf
2608 * newval - the new value for the leaf.
2618 s8 *leaf = tp->dmt_stree + le32_to_cpu(tp->dmt_leafidx); in dbSplit()
2622 if (leaf[leafno] > tp->dmt_budmin) { in dbSplit()
2626 * - 1 in l2) and the corresponding buddy size. in dbSplit()
2628 cursz = leaf[leafno] - 1; in dbSplit()
2629 budsz = BUDSIZE(cursz, tp->dmt_budmin); in dbSplit()
2640 cursz -= 1; in dbSplit()
2672 * tp - pointer to the tree containing the leaf.
2673 * leafno - the number of the leaf to be updated.
2683 s8 *leaf = tp->dmt_stree + le32_to_cpu(tp->dmt_leafidx); in dbBackSplit()
2698 LITOL2BSZ(leafno, le32_to_cpu(tp->dmt_l2nleafs), in dbBackSplit()
2699 tp->dmt_budmin); in dbBackSplit()
2705 budsz = BUDSIZE(size, tp->dmt_budmin); in dbBackSplit()
2714 if (bsz >= le32_to_cpu(tp->dmt_nleafs)) { in dbBackSplit()
2716 return -EIO; in dbBackSplit()
2729 cursz = leaf[bud] - 1; in dbBackSplit()
2738 return -EIO; in dbBackSplit()
2748 * the leaf with other leaves of the dmtree into a multi-leaf
2752 * tp - pointer to the tree containing the leaf.
2753 * leafno - the number of the leaf to be updated.
2754 * newval - the new value for the leaf.
2765 if (newval >= tp->dmt_budmin) { in dbJoin()
2768 leaf = tp->dmt_stree + le32_to_cpu(tp->dmt_leafidx); in dbJoin()
2778 * single system. in dbJoin()
2783 budsz = BUDSIZE(newval, tp->dmt_budmin); in dbJoin()
2787 while (budsz < le32_to_cpu(tp->dmt_nleafs)) { in dbJoin()
2800 return -EIO; in dbJoin()
2846 * tp - pointer to the tree to be adjusted.
2847 * leafno - the number of the leaf to be updated.
2848 * newval - the new value for the leaf.
2861 lp = leafno + le32_to_cpu(tp->dmt_leafidx); in dbAdjTree()
2869 if (tp->dmt_stree[lp] == newval) in dbAdjTree()
2874 tp->dmt_stree[lp] = newval; in dbAdjTree()
2878 for (k = 0; k < le32_to_cpu(tp->dmt_height); k++) { in dbAdjTree()
2885 lp = ((lp - 1) & ~0x03) + 1; in dbAdjTree()
2889 pp = (lp - 1) >> 2; in dbAdjTree()
2893 max = TREEMAX(&tp->dmt_stree[lp]); in dbAdjTree()
2898 if (tp->dmt_stree[pp] == max) in dbAdjTree()
2903 tp->dmt_stree[pp] = max; in dbAdjTree()
2905 /* parent becomes leaf for next go-round. in dbAdjTree()
2924 * tp - pointer to the tree to be searched.
2925 * l2nb - log2 number of free blocks to search for.
2926 * leafidx - return pointer to be set to the index of the leaf
2929 * is_ctl - determines if the tree is of type ctl
2932 * 0 - success
2933 * -ENOSPC - insufficient free blocks.
2946 if (l2nb > tp->dmt_stree[ROOT]) in dbFindLeaf()
2947 return -ENOSPC; in dbFindLeaf()
2953 for (k = le32_to_cpu(tp->dmt_height), ti = 1; in dbFindLeaf()
2954 k > 0; k--, ti = ((ti + n) << 2) + 1) { in dbFindLeaf()
2963 return -ENOSPC; in dbFindLeaf()
2964 if (l2nb <= tp->dmt_stree[x + n]) in dbFindLeaf()
2973 if (le32_to_cpu(tp->dmt_leafidx) >= max_idx) in dbFindLeaf()
2974 return -ENOSPC; in dbFindLeaf()
2979 *leafidx = x + n - le32_to_cpu(tp->dmt_leafidx); in dbFindLeaf()
2995 * word - dmap bitmap word value.
2996 * l2nb - number of free bits specified as a log2 number.
3015 mask = ONES << (DBWORD - nb); in dbFindBits()
3036 * bits within 32-bits of the map.
3039 * cp - pointer to the 32-bit value.
3055 * free buddy size is BUDMIN-1. in dbMaxBud()
3058 return (BUDMIN - 1); in dbMaxBud()
3072 * FUNCTION: determine the number of trailing zeros within a 32-bit
3076 * value - 32-bit value to be examined.
3097 * FUNCTION: determine the number of leading zeros within a 32-bit
3101 * value - 32-bit value to be examined.
3126 * nb - number of blocks
3136 mask = (s64) 1 << (64 - 1); in blkstol2()
3146 l2nb = (64 - 1) - l2nb; in blkstol2()
3171 * ip - pointer to in-core inode;
3172 * blkno - starting block number to be freed.
3173 * nblocks - number of blocks to be freed.
3176 * 0 - success
3177 * -EIO - i/o error
3185 struct inode *ipbmap = JFS_SBI(ip->i_sb)->ipbmap; in dbAllocBottomUp()
3186 struct bmap *bmp = JFS_SBI(ip->i_sb)->bmap; in dbAllocBottomUp()
3191 ASSERT(nblocks <= bmp->db_mapsize - blkno); in dbAllocBottomUp()
3197 for (rem = nblocks; rem > 0; rem -= nb, blkno += nb) { in dbAllocBottomUp()
3204 lblkno = BLKTODMAP(blkno, bmp->db_l2nbperpage); in dbAllocBottomUp()
3208 return -EIO; in dbAllocBottomUp()
3210 dp = (struct dmap *) mp->data; in dbAllocBottomUp()
3215 nb = min(rem, BPERDMAP - (blkno & (BPERDMAP - 1))); in dbAllocBottomUp()
3240 struct dmaptree *tp = (struct dmaptree *) & dp->tree; in dbAllocDmapBU()
3245 oldroot = tp->stree[ROOT]; in dbAllocDmapBU()
3250 dbitno = blkno & (BPERDMAP - 1); in dbAllocDmapBU()
3260 * (a single pass), allocating the bits of interest by hand and in dbAllocDmapBU()
3261 * updating the leaf corresponding to the dmap word. a single pass in dbAllocDmapBU()
3264 * dmap words will be marked as free in a single shot and the leaves in dbAllocDmapBU()
3265 * will be updated. a single leaf may describe the free space of in dbAllocDmapBU()
3269 for (rembits = nblocks; rembits > 0; rembits -= nb, dbitno += nb) { in dbAllocDmapBU()
3273 wbitno = dbitno & (DBWORD - 1); in dbAllocDmapBU()
3274 nb = min(rembits, DBWORD - wbitno); in dbAllocDmapBU()
3282 dp->wmap[word] |= cpu_to_le32(ONES << (DBWORD - nb) in dbAllocDmapBU()
3293 memset(&dp->wmap[word], (int) ONES, nwords * 4); in dbAllocDmapBU()
3302 le32_add_cpu(&dp->nfree, -nblocks); in dbAllocDmapBU()
3313 agno = blkno >> bmp->db_agl2size; in dbAllocDmapBU()
3314 if (agno > bmp->db_maxag) in dbAllocDmapBU()
3315 bmp->db_maxag = agno; in dbAllocDmapBU()
3318 bmp->db_agfree[agno] -= nblocks; in dbAllocDmapBU()
3319 bmp->db_nfree -= nblocks; in dbAllocDmapBU()
3324 if (tp->stree[ROOT] == oldroot) in dbAllocDmapBU()
3331 if ((rc = dbAdjCtl(bmp, blkno, tp->stree[ROOT], 1, 0))) in dbAllocDmapBU()
3346 * L1---------------------------------L1
3348 * L0---------L0---------L0 L0---------L0---------L0
3353 * <---old---><----------------------------extend----------------------->
3357 struct jfs_sb_info *sbi = JFS_SBI(ipbmap->i_sb); in dbExtendFS()
3358 int nbperpage = sbi->nbperpage; in dbExtendFS()
3366 struct bmap *bmp = sbi->bmap; in dbExtendFS()
3383 bmp->db_mapsize = newsize; in dbExtendFS()
3384 bmp->db_maxlevel = BMAPSZTOLEV(bmp->db_mapsize); in dbExtendFS()
3388 oldl2agsize = bmp->db_agl2size; in dbExtendFS()
3390 bmp->db_agl2size = l2agsize; in dbExtendFS()
3391 bmp->db_agsize = (s64)1 << l2agsize; in dbExtendFS()
3394 agno = bmp->db_numag; in dbExtendFS()
3395 bmp->db_numag = newsize >> l2agsize; in dbExtendFS()
3396 bmp->db_numag += ((u32) newsize % (u32) bmp->db_agsize) ? 1 : 0; in dbExtendFS()
3403 * i.e., (AGi, ..., AGj) where i = k*n and j = k*(n+1) - 1 to AGn; in dbExtendFS()
3408 k = 1 << (l2agsize - oldl2agsize); in dbExtendFS()
3409 ag_rem = bmp->db_agfree[0]; /* save agfree[0] */ in dbExtendFS()
3411 bmp->db_agfree[n] = 0; /* init collection point */ in dbExtendFS()
3416 bmp->db_agfree[n] += bmp->db_agfree[i]; in dbExtendFS()
3419 bmp->db_agfree[0] += ag_rem; /* restore agfree[0] */ in dbExtendFS()
3422 bmp->db_agfree[n] = 0; in dbExtendFS()
3428 bmp->db_maxag = bmp->db_maxag / k; in dbExtendFS()
3441 jfs_error(ipbmap->i_sb, "L2 page could not be read\n"); in dbExtendFS()
3442 return -EIO; in dbExtendFS()
3444 l2dcp = (struct dmapctl *) l2mp->data; in dbExtendFS()
3448 l2leaf = l2dcp->stree + CTLLEAFIND + k; in dbExtendFS()
3449 p = BLKTOL1(blkno, sbi->l2nbperpage); /* L1 page */ in dbExtendFS()
3457 /* read in L1 page: (blkno & (MAXL1SIZE - 1)) */ in dbExtendFS()
3461 l1dcp = (struct dmapctl *) l1mp->data; in dbExtendFS()
3464 j = (blkno & (MAXL1SIZE - 1)) >> L2MAXL0SIZE; in dbExtendFS()
3465 l1leaf = l1dcp->stree + CTLLEAFIND + j; in dbExtendFS()
3466 p = BLKTOL0(blkno, sbi->l2nbperpage); in dbExtendFS()
3474 l1dcp = (struct dmapctl *) l1mp->data; in dbExtendFS()
3478 l1leaf = l1dcp->stree + CTLLEAFIND; in dbExtendFS()
3488 /* read in L0 page: (blkno & (MAXL0SIZE - 1)) */ in dbExtendFS()
3493 l0dcp = (struct dmapctl *) l0mp->data; in dbExtendFS()
3496 i = (blkno & (MAXL0SIZE - 1)) >> in dbExtendFS()
3498 l0leaf = l0dcp->stree + CTLLEAFIND + i; in dbExtendFS()
3500 sbi->l2nbperpage); in dbExtendFS()
3508 l0dcp = (struct dmapctl *) l0mp->data; in dbExtendFS()
3512 l0leaf = l0dcp->stree + CTLLEAFIND; in dbExtendFS()
3524 if ((n = blkno & (BPERDMAP - 1))) { in dbExtendFS()
3530 n = min(nblocks, (s64)BPERDMAP - n); in dbExtendFS()
3541 dp = (struct dmap *) mp->data; in dbExtendFS()
3544 bmp->db_nfree += n; in dbExtendFS()
3545 agno = le64_to_cpu(dp->start) >> l2agsize; in dbExtendFS()
3546 bmp->db_agfree[agno] += n; in dbExtendFS()
3554 nblocks -= n; in dbExtendFS()
3575 bmp->db_maxfreebud = *l1leaf; in dbExtendFS()
3599 bmp->db_maxfreebud = *l2leaf; in dbExtendFS()
3606 jfs_error(ipbmap->i_sb, "function has not returned as expected\n"); in dbExtendFS()
3613 return -EIO; in dbExtendFS()
3629 struct bmap *bmp = JFS_SBI(ipbmap->i_sb)->bmap; in dbFinalizeBmap()
3644 actags = bmp->db_maxag + 1; in dbFinalizeBmap()
3645 inactags = bmp->db_numag - actags; in dbFinalizeBmap()
3646 ag_rem = bmp->db_mapsize & (bmp->db_agsize - 1); /* ??? */ in dbFinalizeBmap()
3654 (((s64)inactags - 1) << bmp->db_agl2size) + ag_rem in dbFinalizeBmap()
3655 : ((s64)inactags << bmp->db_agl2size); in dbFinalizeBmap()
3661 actfree = bmp->db_nfree - inactfree; in dbFinalizeBmap()
3665 * re-establish the preferred group as the leftmost in dbFinalizeBmap()
3668 if (bmp->db_agfree[bmp->db_agpref] < avgfree) { in dbFinalizeBmap()
3669 for (bmp->db_agpref = 0; bmp->db_agpref < actags; in dbFinalizeBmap()
3670 bmp->db_agpref++) { in dbFinalizeBmap()
3671 if (bmp->db_agfree[bmp->db_agpref] >= avgfree) in dbFinalizeBmap()
3674 if (bmp->db_agpref >= bmp->db_numag) { in dbFinalizeBmap()
3675 jfs_error(ipbmap->i_sb, in dbFinalizeBmap()
3687 bmp->db_aglevel = BMAPSZTOLEV(bmp->db_agsize); in dbFinalizeBmap()
3689 bmp->db_agl2size - (L2BPERDMAP + bmp->db_aglevel * L2LPERCTL); in dbFinalizeBmap()
3690 bmp->db_agheight = l2nl >> 1; in dbFinalizeBmap()
3691 bmp->db_agwidth = 1 << (l2nl - (bmp->db_agheight << 1)); in dbFinalizeBmap()
3692 for (i = 5 - bmp->db_agheight, bmp->db_agstart = 0, n = 1; i > 0; in dbFinalizeBmap()
3693 i--) { in dbFinalizeBmap()
3694 bmp->db_agstart += n; in dbFinalizeBmap()
3713 * dp - pointer to page of map
3714 * nblocks - number of blocks this page
3723 blkno = Blkno & (BPERDMAP - 1); in dbInitDmap()
3726 dp->nblocks = dp->nfree = cpu_to_le32(nblocks); in dbInitDmap()
3727 dp->start = cpu_to_le64(Blkno); in dbInitDmap()
3730 memset(&dp->wmap[0], 0, LPERDMAP * 4); in dbInitDmap()
3731 memset(&dp->pmap[0], 0, LPERDMAP * 4); in dbInitDmap()
3735 le32_add_cpu(&dp->nblocks, nblocks); in dbInitDmap()
3736 le32_add_cpu(&dp->nfree, nblocks); in dbInitDmap()
3747 for (r = nblocks; r > 0; r -= nb, blkno += nb) { in dbInitDmap()
3749 b = blkno & (DBWORD - 1); in dbInitDmap()
3751 nb = min(r, DBWORD - b); in dbInitDmap()
3756 dp->wmap[w] &= cpu_to_le32(~(ONES << (DBWORD - nb) in dbInitDmap()
3758 dp->pmap[w] &= cpu_to_le32(~(ONES << (DBWORD - nb) in dbInitDmap()
3766 memset(&dp->wmap[w], 0, nw * 4); in dbInitDmap()
3767 memset(&dp->pmap[w], 0, nw * 4); in dbInitDmap()
3776 * mark bits following the range to be freed (non-existing in dbInitDmap()
3786 /* does nblocks fall on a 32-bit boundary ? */ in dbInitDmap()
3787 b = blkno & (DBWORD - 1); in dbInitDmap()
3790 dp->wmap[w] = dp->pmap[w] = cpu_to_le32(ONES >> b); in dbInitDmap()
3796 dp->pmap[i] = dp->wmap[i] = cpu_to_le32(ONES); in dbInitDmap()
3814 * dp - dmap to complete
3815 * blkno - starting block number for this dmap
3816 * treemax - will be filled in with max free for this dmap
3827 tp = &dp->tree; in dbInitDmapTree()
3828 tp->nleafs = cpu_to_le32(LPERDMAP); in dbInitDmapTree()
3829 tp->l2nleafs = cpu_to_le32(L2LPERDMAP); in dbInitDmapTree()
3830 tp->leafidx = cpu_to_le32(LEAFIND); in dbInitDmapTree()
3831 tp->height = cpu_to_le32(4); in dbInitDmapTree()
3832 tp->budmin = BUDMIN; in dbInitDmapTree()
3835 * note: leaf is set to NOFREE(-1) if all blocks of corresponding in dbInitDmapTree()
3838 cp = tp->stree + le32_to_cpu(tp->leafidx); in dbInitDmapTree()
3840 *cp++ = dbMaxBud((u8 *) & dp->wmap[i]); in dbInitDmapTree()
3859 * cp - Pointer to the root of the tree
3860 * l2leaves- Number of leaf nodes as a power of 2
3861 * l2min - Number of blocks that can be covered by a leaf
3872 tp = dtp->stree; in dbInitTree()
3875 l2max = le32_to_cpu(dtp->l2nleafs) + dtp->budmin; in dbInitTree()
3883 * the combination will result in the left-most buddy leaf having in dbInitTree()
3891 for (l2free = dtp->budmin, bsize = 1; l2free < l2max; in dbInitTree()
3897 for (i = 0, cp = tp + le32_to_cpu(dtp->leafidx); in dbInitTree()
3898 i < le32_to_cpu(dtp->nleafs); in dbInitTree()
3903 *(cp + bsize) = -1; /* right give left */ in dbInitTree()
3918 for (child = le32_to_cpu(dtp->leafidx), in dbInitTree()
3919 nparent = le32_to_cpu(dtp->nleafs) >> 2; in dbInitTree()
3922 parent = (child - 1) >> 2; in dbInitTree()
3945 dcp->nleafs = cpu_to_le32(LPERCTL); in dbInitDmapCtl()
3946 dcp->l2nleafs = cpu_to_le32(L2LPERCTL); in dbInitDmapCtl()
3947 dcp->leafidx = cpu_to_le32(CTLLEAFIND); in dbInitDmapCtl()
3948 dcp->height = cpu_to_le32(5); in dbInitDmapCtl()
3949 dcp->budmin = L2BPERDMAP + L2LPERCTL * level; in dbInitDmapCtl()
3956 cp = &dcp->stree[CTLLEAFIND + i]; in dbInitDmapCtl()
3971 * nblocks - Number of blocks in aggregate
3985 m = ((u64) 1 << (64 - 1)); in dbGetL2AGSize()
3986 for (l2sz = 64; l2sz >= 0; l2sz--, m >>= 1) { in dbGetL2AGSize()
3996 return (l2sz - L2MAXAG); in dbGetL2AGSize()
4024 struct super_block *sb = ipbmap->i_sb; in dbMapFileSizeToMapSize()
4030 nblocks = ipbmap->i_size >> JFS_SBI(sb)->l2bsize; in dbMapFileSizeToMapSize()
4031 npages = nblocks >> JFS_SBI(sb)->l2nbperpage; in dbMapFileSizeToMapSize()
4039 npages--; /* skip the first global control page */ in dbMapFileSizeToMapSize()
4041 npages -= (2 - level); in dbMapFileSizeToMapSize()
4042 npages--; /* skip top level's control page */ in dbMapFileSizeToMapSize()
4043 for (i = level; i >= 0; i--) { in dbMapFileSizeToMapSize()
4053 npages--; in dbMapFileSizeToMapSize()