Lines Matching refs:bmp

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)
64 static void dbAllocBits(struct bmap * bmp, struct dmap * dp, s64 blkno,
70 static int dbAdjCtl(struct bmap * bmp, s64 blkno, int newval, int alloc,
72 static int dbAllocAny(struct bmap * bmp, s64 nblocks, int l2nb, s64 * results);
73 static int dbAllocNext(struct bmap * bmp, struct dmap * dp, s64 blkno,
75 static int dbAllocNear(struct bmap * bmp, struct dmap * dp, s64 blkno,
78 static int dbAllocDmap(struct bmap * bmp, struct dmap * dp, s64 blkno,
80 static int dbAllocDmapLev(struct bmap * bmp, struct dmap * dp, int nblocks,
83 static int dbAllocAG(struct bmap * bmp, int agno, s64 nblocks, int l2nb,
85 static int dbAllocCtl(struct bmap * bmp, s64 nblocks, int l2nb, s64 blkno,
89 static int dbFindCtl(struct bmap * bmp, int l2nb, int level, s64 * blkno);
91 static int dbFreeBits(struct bmap * bmp, struct dmap * dp, s64 blkno,
93 static int dbFreeDmap(struct bmap * bmp, struct dmap * dp, s64 blkno,
101 static int dbAllocDmapBU(struct bmap * bmp, struct dmap * dp, s64 blkno,
155 struct bmap *bmp;
164 bmp = kmalloc(sizeof(struct bmap), GFP_KERNEL);
165 if (bmp == NULL)
179 bmp->db_mapsize = le64_to_cpu(dbmp_le->dn_mapsize);
180 bmp->db_nfree = le64_to_cpu(dbmp_le->dn_nfree);
182 bmp->db_l2nbperpage = le32_to_cpu(dbmp_le->dn_l2nbperpage);
183 if (bmp->db_l2nbperpage > L2PSIZE - L2MINBLOCKSIZE ||
184 bmp->db_l2nbperpage < 0) {
189 bmp->db_numag = le32_to_cpu(dbmp_le->dn_numag);
190 if (!bmp->db_numag) {
195 bmp->db_maxlevel = le32_to_cpu(dbmp_le->dn_maxlevel);
196 bmp->db_maxag = le32_to_cpu(dbmp_le->dn_maxag);
197 bmp->db_agpref = le32_to_cpu(dbmp_le->dn_agpref);
198 if (bmp->db_maxag >= MAXAG || bmp->db_maxag < 0 ||
199 bmp->db_agpref >= MAXAG || bmp->db_agpref < 0) {
204 bmp->db_aglevel = le32_to_cpu(dbmp_le->dn_aglevel);
205 bmp->db_agheight = le32_to_cpu(dbmp_le->dn_agheight);
206 bmp->db_agwidth = le32_to_cpu(dbmp_le->dn_agwidth);
207 bmp->db_agstart = le32_to_cpu(dbmp_le->dn_agstart);
208 bmp->db_agl2size = le32_to_cpu(dbmp_le->dn_agl2size);
209 if (bmp->db_agl2size > L2MAXL2SIZE - L2MAXAG ||
210 bmp->db_agl2size < 0) {
215 if (((bmp->db_mapsize - 1) >> bmp->db_agl2size) > MAXAG) {
221 bmp->db_agfree[i] = le64_to_cpu(dbmp_le->dn_agfree[i]);
222 bmp->db_agsize = le64_to_cpu(dbmp_le->dn_agsize);
223 bmp->db_maxfreebud = dbmp_le->dn_maxfreebud;
229 bmp->db_ipbmap = ipbmap;
230 JFS_SBI(ipbmap->i_sb)->bmap = bmp;
232 memset(bmp->db_active, 0, sizeof(bmp->db_active));
237 BMAP_LOCK_INIT(bmp);
244 kfree(bmp);
267 struct bmap *bmp = JFS_SBI(ipbmap->i_sb)->bmap;
278 kfree(bmp);
290 struct bmap *bmp = JFS_SBI(ipbmap->i_sb)->bmap;
307 dbmp_le->dn_mapsize = cpu_to_le64(bmp->db_mapsize);
308 dbmp_le->dn_nfree = cpu_to_le64(bmp->db_nfree);
309 dbmp_le->dn_l2nbperpage = cpu_to_le32(bmp->db_l2nbperpage);
310 dbmp_le->dn_numag = cpu_to_le32(bmp->db_numag);
311 dbmp_le->dn_maxlevel = cpu_to_le32(bmp->db_maxlevel);
312 dbmp_le->dn_maxag = cpu_to_le32(bmp->db_maxag);
313 dbmp_le->dn_agpref = cpu_to_le32(bmp->db_agpref);
314 dbmp_le->dn_aglevel = cpu_to_le32(bmp->db_aglevel);
315 dbmp_le->dn_agheight = cpu_to_le32(bmp->db_agheight);
316 dbmp_le->dn_agwidth = cpu_to_le32(bmp->db_agwidth);
317 dbmp_le->dn_agstart = cpu_to_le32(bmp->db_agstart);
318 dbmp_le->dn_agl2size = cpu_to_le32(bmp->db_agl2size);
320 dbmp_le->dn_agfree[i] = cpu_to_le64(bmp->db_agfree[i]);
321 dbmp_le->dn_agsize = cpu_to_le64(bmp->db_agsize);
322 dbmp_le->dn_maxfreebud = bmp->db_maxfreebud;
362 struct bmap *bmp = JFS_SBI(ip->i_sb)->bmap;
368 if (unlikely((blkno == 0) || (blkno + nblocks > bmp->db_mapsize))) {
395 lblkno = BLKTODMAP(blkno, bmp->db_l2nbperpage);
409 if ((rc = dbFreeDmap(bmp, dp, blkno, nb))) {
454 struct bmap *bmp = JFS_SBI(ipbmap->i_sb)->bmap;
464 if (blkno + nblocks > bmp->db_mapsize) {
484 lblkno = BLKTODMAP(blkno, bmp->db_l2nbperpage);
490 mp = read_metapage(bmp->db_ipbmap, lblkno, PSIZE,
635 struct bmap *bmp = JFS_SBI(ipbmap->i_sb)->bmap;
637 BMAP_LOCK(bmp);
640 avgfree = (u32)bmp->db_nfree / bmp->db_numag;
646 agpref = bmp->db_agpref;
647 if ((atomic_read(&bmp->db_active[agpref]) == 0) &&
648 (bmp->db_agfree[agpref] >= avgfree))
654 for (i = 0 ; i < bmp->db_numag; i++, agpref++) {
655 if (agpref == bmp->db_numag)
658 if (atomic_read(&bmp->db_active[agpref]))
661 if (bmp->db_agfree[agpref] >= avgfree) {
663 bmp->db_agpref = agpref;
665 } else if (bmp->db_agfree[agpref] > hwm) {
667 hwm = bmp->db_agfree[agpref];
677 bmp->db_agpref = next_best;
680 BMAP_UNLOCK(bmp);
684 return (bmp->db_agpref);
729 struct bmap *bmp;
746 bmp = JFS_SBI(ip->i_sb)->bmap;
748 mapSize = bmp->db_mapsize;
759 if (l2nb > bmp->db_agl2size) {
762 rc = dbAllocAny(bmp, nblocks, l2nb, results);
779 if (blkno >= bmp->db_mapsize)
782 agno = blkno >> bmp->db_agl2size;
788 if ((blkno & (bmp->db_agsize - 1)) == 0)
793 if (atomic_read(&bmp->db_active[agno]))
806 lblkno = BLKTODMAP(blkno, bmp->db_l2nbperpage);
816 if ((rc = dbAllocNext(bmp, dp, blkno, (int) nblocks))
827 writers = atomic_read(&bmp->db_active[agno]);
843 dbAllocNear(bmp, dp, blkno, (int) nblocks, l2nb, results))
855 if ((rc = dbAllocDmapLev(bmp, dp, (int) nblocks, l2nb, results))
872 if ((rc = dbAllocAG(bmp, agno, nblocks, l2nb, results)) != -ENOSPC)
888 if ((rc = dbAllocAG(bmp, agno, nblocks, l2nb, results)) == -ENOSPC)
889 rc = dbAllocAny(bmp, nblocks, l2nb, results);
922 struct bmap *bmp = JFS_SBI(ip->i_sb)->bmap;
936 if (nblocks <= 0 || nblocks > BPERDMAP || blkno >= bmp->db_mapsize) {
941 if (nblocks > ((s64) 1 << bmp->db_maxfreebud)) {
948 lblkno = BLKTODMAP(blkno, bmp->db_l2nbperpage);
957 rc = dbAllocNext(bmp, dp, blkno, nblocks);
1060 struct bmap *bmp;
1080 bmp = sbi->bmap;
1081 if (lastblkno < 0 || lastblkno >= bmp->db_mapsize) {
1095 if (addnblocks > BPERDMAP || extblkno >= bmp->db_mapsize ||
1096 (extblkno & (bmp->db_agsize - 1)) == 0) {
1104 lblkno = BLKTODMAP(extblkno, bmp->db_l2nbperpage);
1116 rc = dbAllocNext(bmp, dp, extblkno, (int) addnblocks);
1138 * bmp - pointer to bmap descriptor
1150 static int dbAllocNext(struct bmap * bmp, struct dmap * dp, s64 blkno,
1159 jfs_error(bmp->db_ipbmap->i_sb, "Corrupt dmap page\n");
1250 return (dbAllocDmap(bmp, dp, blkno, nblocks));
1266 * bmp - pointer to bmap descriptor
1282 dbAllocNear(struct bmap * bmp,
1289 jfs_error(bmp->db_ipbmap->i_sb, "Corrupt dmap page\n");
1326 if ((rc = dbAllocDmap(bmp, dp, blkno, nblocks)) == 0)
1376 * bmp - pointer to bmap descriptor
1391 dbAllocAG(struct bmap * bmp, int agno, s64 nblocks, int l2nb, s64 * results)
1402 if (l2nb > bmp->db_agl2size) {
1403 jfs_error(bmp->db_ipbmap->i_sb,
1411 blkno = (s64) agno << bmp->db_agl2size;
1430 if (bmp->db_agsize == BPERDMAP
1431 || bmp->db_agfree[agno] == bmp->db_agsize) {
1432 rc = dbAllocCtl(bmp, nblocks, l2nb, blkno, results);
1434 (bmp->db_agfree[agno] == bmp->db_agsize)) {
1438 jfs_error(bmp->db_ipbmap->i_sb,
1447 lblkno = BLKTOCTL(blkno, bmp->db_l2nbperpage, bmp->db_aglevel);
1448 mp = read_metapage(bmp->db_ipbmap, lblkno, PSIZE, 0);
1455 jfs_error(bmp->db_ipbmap->i_sb, "Corrupt dmapctl page\n");
1468 (1 << (L2LPERCTL - (bmp->db_agheight << 1))) / bmp->db_agwidth;
1469 ti = bmp->db_agstart + bmp->db_agwidth * (agno & (agperlev - 1));
1477 for (i = 0; i < bmp->db_agwidth; i++, ti++) {
1487 for (k = bmp->db_agheight; k > 0; k--) {
1495 jfs_error(bmp->db_ipbmap->i_sb,
1505 if (bmp->db_aglevel == 2)
1507 else if (bmp->db_aglevel == 1)
1509 else /* bmp->db_aglevel == 0 */
1532 dbFindCtl(bmp, l2nb, bmp->db_aglevel - 1,
1535 jfs_error(bmp->db_ipbmap->i_sb,
1545 rc = dbAllocCtl(bmp, nblocks, l2nb, blkno, results);
1547 jfs_error(bmp->db_ipbmap->i_sb,
1576 * bmp - pointer to bmap descriptor
1589 static int dbAllocAny(struct bmap * bmp, s64 nblocks, int l2nb, s64 * results)
1600 if ((rc = dbFindCtl(bmp, l2nb, bmp->db_maxlevel, &blkno)))
1605 rc = dbAllocCtl(bmp, nblocks, l2nb, blkno, results);
1607 jfs_error(bmp->db_ipbmap->i_sb, "unable to allocate blocks\n");
1647 struct bmap *bmp = JFS_SBI(ip->i_sb)->bmap;
1665 nblocks = bmp->db_agfree[agno];
1671 jfs_error(bmp->db_ipbmap->i_sb, "no memory for trim array\n");
1681 rc = dbAllocAG(bmp, agno, nblocks, l2nb, &blkno);
1688 if (bmp->db_agfree[agno] == 0)
1692 nblocks = bmp->db_agfree[agno];
1700 jfs_error(bmp->db_ipbmap->i_sb, "-EIO\n");
1738 * bmp - pointer to bmap descriptor
1752 static int dbFindCtl(struct bmap * bmp, int l2nb, int level, s64 * blkno)
1769 lblkno = BLKTOCTL(b, bmp->db_l2nbperpage, lev);
1770 mp = read_metapage(bmp->db_ipbmap, lblkno, PSIZE, 0);
1777 jfs_error(bmp->db_ipbmap->i_sb,
1798 jfs_error(bmp->db_ipbmap->i_sb,
1855 * bmp - pointer to bmap descriptor
1871 dbAllocCtl(struct bmap * bmp, s64 nblocks, int l2nb, s64 blkno, s64 * results)
1883 lblkno = BLKTODMAP(blkno, bmp->db_l2nbperpage);
1884 mp = read_metapage(bmp->db_ipbmap, lblkno, PSIZE, 0);
1891 rc = dbAllocDmapLev(bmp, dp, (int) nblocks, l2nb, results);
1910 lblkno = BLKTODMAP(b, bmp->db_l2nbperpage);
1911 mp = read_metapage(bmp->db_ipbmap, lblkno, PSIZE, 0);
1922 jfs_error(bmp->db_ipbmap->i_sb,
1934 if ((rc = dbAllocDmap(bmp, dp, b, nb))) {
1963 lblkno = BLKTODMAP(b, bmp->db_l2nbperpage);
1964 mp = read_metapage(bmp->db_ipbmap, lblkno, PSIZE, 0);
1969 jfs_error(bmp->db_ipbmap->i_sb,
1977 if (dbFreeDmap(bmp, dp, b, BPERDMAP)) {
1982 jfs_error(bmp->db_ipbmap->i_sb, "Block Leakage\n");
2022 dbAllocDmapLev(struct bmap * bmp,
2054 if ((rc = dbAllocDmap(bmp, dp, blkno, nblocks)) == 0)
2077 * bmp - pointer to bmap descriptor
2088 static int dbAllocDmap(struct bmap * bmp, struct dmap * dp, s64 blkno,
2100 dbAllocBits(bmp, dp, blkno, nblocks);
2110 if ((rc = dbAdjCtl(bmp, blkno, dp->tree.stree[ROOT], 1, 0)))
2111 dbFreeBits(bmp, dp, blkno, nblocks);
2132 * bmp - pointer to bmap descriptor
2143 static int dbFreeDmap(struct bmap * bmp, struct dmap * dp, s64 blkno,
2155 rc = dbFreeBits(bmp, dp, blkno, nblocks);
2165 if ((rc = dbAdjCtl(bmp, blkno, dp->tree.stree[ROOT], 0, 0))) {
2176 dbAllocBits(bmp, dp, blkno, nblocks);
2196 * bmp - pointer to bmap descriptor
2205 static void dbAllocBits(struct bmap * bmp, struct dmap * dp, s64 blkno,
2281 jfs_error(bmp->db_ipbmap->i_sb,
2312 BMAP_LOCK(bmp);
2318 agno = blkno >> bmp->db_agl2size;
2319 if (agno > bmp->db_maxag)
2320 bmp->db_maxag = agno;
2323 bmp->db_agfree[agno] -= nblocks;
2324 bmp->db_nfree -= nblocks;
2326 BMAP_UNLOCK(bmp);
2343 * bmp - pointer to bmap descriptor
2352 static int dbFreeBits(struct bmap * bmp, struct dmap * dp, s64 blkno,
2456 BMAP_LOCK(bmp);
2461 agno = blkno >> bmp->db_agl2size;
2462 bmp->db_nfree += nblocks;
2463 bmp->db_agfree[agno] += nblocks;
2470 if ((bmp->db_agfree[agno] == bmp->db_agsize && agno == bmp->db_maxag) ||
2471 (agno == bmp->db_numag - 1 &&
2472 bmp->db_agfree[agno] == (bmp-> db_mapsize & (BPERDMAP - 1)))) {
2473 while (bmp->db_maxag > 0) {
2474 bmp->db_maxag -= 1;
2475 if (bmp->db_agfree[bmp->db_maxag] !=
2476 bmp->db_agsize)
2484 if (bmp->db_agpref > bmp->db_maxag)
2485 bmp->db_agpref = bmp->db_maxag;
2488 BMAP_UNLOCK(bmp);
2519 * bmp - pointer to bmap descriptor
2536 dbAdjCtl(struct bmap * bmp, s64 blkno, int newval, int alloc, int level)
2548 lblkno = BLKTOCTL(blkno, bmp->db_l2nbperpage, level);
2549 mp = read_metapage(bmp->db_ipbmap, lblkno, PSIZE, 0);
2555 jfs_error(bmp->db_ipbmap->i_sb, "Corrupt dmapctl page\n");
2615 if (level < bmp->db_maxlevel) {
2620 dbAdjCtl(bmp, blkno, dcp->stree[ROOT], alloc,
2653 assert(level == bmp->db_maxlevel);
2654 if (bmp->db_maxfreebud != oldroot) {
2655 jfs_error(bmp->db_ipbmap->i_sb,
2658 bmp->db_maxfreebud = dcp->stree[ROOT];
3254 struct bmap *bmp = JFS_SBI(ip->i_sb)->bmap;
3259 ASSERT(nblocks <= bmp->db_mapsize - blkno);
3272 lblkno = BLKTODMAP(blkno, bmp->db_l2nbperpage);
3286 if ((rc = dbAllocDmapBU(bmp, dp, blkno, nb))) {
3302 static int dbAllocDmapBU(struct bmap * bmp, struct dmap * dp, s64 blkno,
3375 BMAP_LOCK(bmp);
3381 agno = blkno >> bmp->db_agl2size;
3382 if (agno > bmp->db_maxag)
3383 bmp->db_maxag = agno;
3386 bmp->db_agfree[agno] -= nblocks;
3387 bmp->db_nfree -= nblocks;
3389 BMAP_UNLOCK(bmp);
3399 if ((rc = dbAdjCtl(bmp, blkno, tp->stree[ROOT], 1, 0)))
3400 dbFreeBits(bmp, dp, blkno, nblocks);
3434 struct bmap *bmp = sbi->bmap;
3451 bmp->db_mapsize = newsize;
3452 bmp->db_maxlevel = BMAPSZTOLEV(bmp->db_mapsize);
3456 oldl2agsize = bmp->db_agl2size;
3458 bmp->db_agl2size = l2agsize;
3459 bmp->db_agsize = 1 << l2agsize;
3462 agno = bmp->db_numag;
3463 bmp->db_numag = newsize >> l2agsize;
3464 bmp->db_numag += ((u32) newsize % (u32) bmp->db_agsize) ? 1 : 0;
3477 ag_rem = bmp->db_agfree[0]; /* save agfree[0] */
3479 bmp->db_agfree[n] = 0; /* init collection point */
3484 bmp->db_agfree[n] += bmp->db_agfree[i];
3487 bmp->db_agfree[0] += ag_rem; /* restore agfree[0] */
3490 bmp->db_agfree[n] = 0;
3496 bmp->db_maxag = bmp->db_maxag / k;
3612 bmp->db_nfree += n;
3614 bmp->db_agfree[agno] += n;
3643 bmp->db_maxfreebud = *l1leaf;
3667 bmp->db_maxfreebud = *l2leaf;
3697 struct bmap *bmp = JFS_SBI(ipbmap->i_sb)->bmap;
3712 actags = bmp->db_maxag + 1;
3713 inactags = bmp->db_numag - actags;
3714 ag_rem = bmp->db_mapsize & (bmp->db_agsize - 1); /* ??? */
3722 ((inactags - 1) << bmp->db_agl2size) + ag_rem
3723 : inactags << bmp->db_agl2size;
3729 actfree = bmp->db_nfree - inactfree;
3736 if (bmp->db_agfree[bmp->db_agpref] < avgfree) {
3737 for (bmp->db_agpref = 0; bmp->db_agpref < actags;
3738 bmp->db_agpref++) {
3739 if (bmp->db_agfree[bmp->db_agpref] >= avgfree)
3742 if (bmp->db_agpref >= bmp->db_numag) {
3755 bmp->db_aglevel = BMAPSZTOLEV(bmp->db_agsize);
3757 bmp->db_agl2size - (L2BPERDMAP + bmp->db_aglevel * L2LPERCTL);
3758 bmp->db_agheight = l2nl >> 1;
3759 bmp->db_agwidth = 1 << (l2nl - (bmp->db_agheight << 1));
3760 for (i = 5 - bmp->db_agheight, bmp->db_agstart = 0, n = 1; i > 0;
3762 bmp->db_agstart += n;