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);
992 struct bmap *bmp;
1012 bmp = sbi->bmap;
1013 if (lastblkno < 0 || lastblkno >= bmp->db_mapsize) {
1027 if (addnblocks > BPERDMAP || extblkno >= bmp->db_mapsize ||
1028 (extblkno & (bmp->db_agsize - 1)) == 0) {
1036 lblkno = BLKTODMAP(extblkno, bmp->db_l2nbperpage);
1048 rc = dbAllocNext(bmp, dp, extblkno, (int) addnblocks);
1070 * bmp - pointer to bmap descriptor
1082 static int dbAllocNext(struct bmap * bmp, struct dmap * dp, s64 blkno,
1091 jfs_error(bmp->db_ipbmap->i_sb, "Corrupt dmap page\n");
1182 return (dbAllocDmap(bmp, dp, blkno, nblocks));
1198 * bmp - pointer to bmap descriptor
1214 dbAllocNear(struct bmap * bmp,
1221 jfs_error(bmp->db_ipbmap->i_sb, "Corrupt dmap page\n");
1258 if ((rc = dbAllocDmap(bmp, dp, blkno, nblocks)) == 0)
1308 * bmp - pointer to bmap descriptor
1323 dbAllocAG(struct bmap * bmp, int agno, s64 nblocks, int l2nb, s64 * results)
1334 if (l2nb > bmp->db_agl2size) {
1335 jfs_error(bmp->db_ipbmap->i_sb,
1343 blkno = (s64) agno << bmp->db_agl2size;
1362 if (bmp->db_agsize == BPERDMAP
1363 || bmp->db_agfree[agno] == bmp->db_agsize) {
1364 rc = dbAllocCtl(bmp, nblocks, l2nb, blkno, results);
1366 (bmp->db_agfree[agno] == bmp->db_agsize)) {
1370 jfs_error(bmp->db_ipbmap->i_sb,
1379 lblkno = BLKTOCTL(blkno, bmp->db_l2nbperpage, bmp->db_aglevel);
1380 mp = read_metapage(bmp->db_ipbmap, lblkno, PSIZE, 0);
1387 jfs_error(bmp->db_ipbmap->i_sb, "Corrupt dmapctl page\n");
1400 (1 << (L2LPERCTL - (bmp->db_agheight << 1))) / bmp->db_agwidth;
1401 ti = bmp->db_agstart + bmp->db_agwidth * (agno & (agperlev - 1));
1409 for (i = 0; i < bmp->db_agwidth; i++, ti++) {
1419 for (k = bmp->db_agheight; k > 0; k--) {
1427 jfs_error(bmp->db_ipbmap->i_sb,
1437 if (bmp->db_aglevel == 2)
1439 else if (bmp->db_aglevel == 1)
1441 else /* bmp->db_aglevel == 0 */
1464 dbFindCtl(bmp, l2nb, bmp->db_aglevel - 1,
1467 jfs_error(bmp->db_ipbmap->i_sb,
1477 rc = dbAllocCtl(bmp, nblocks, l2nb, blkno, results);
1479 jfs_error(bmp->db_ipbmap->i_sb,
1508 * bmp - pointer to bmap descriptor
1521 static int dbAllocAny(struct bmap * bmp, s64 nblocks, int l2nb, s64 * results)
1532 if ((rc = dbFindCtl(bmp, l2nb, bmp->db_maxlevel, &blkno)))
1537 rc = dbAllocCtl(bmp, nblocks, l2nb, blkno, results);
1539 jfs_error(bmp->db_ipbmap->i_sb, "unable to allocate blocks\n");
1579 struct bmap *bmp = JFS_SBI(ip->i_sb)->bmap;
1597 nblocks = bmp->db_agfree[agno];
1603 jfs_error(bmp->db_ipbmap->i_sb, "no memory for trim array\n");
1613 rc = dbAllocAG(bmp, agno, nblocks, l2nb, &blkno);
1620 if (bmp->db_agfree[agno] == 0)
1624 nblocks = bmp->db_agfree[agno];
1632 jfs_error(bmp->db_ipbmap->i_sb, "-EIO\n");
1670 * bmp - pointer to bmap descriptor
1684 static int dbFindCtl(struct bmap * bmp, int l2nb, int level, s64 * blkno)
1701 lblkno = BLKTOCTL(b, bmp->db_l2nbperpage, lev);
1702 mp = read_metapage(bmp->db_ipbmap, lblkno, PSIZE, 0);
1709 jfs_error(bmp->db_ipbmap->i_sb,
1730 jfs_error(bmp->db_ipbmap->i_sb,
1787 * bmp - pointer to bmap descriptor
1803 dbAllocCtl(struct bmap * bmp, s64 nblocks, int l2nb, s64 blkno, s64 * results)
1815 lblkno = BLKTODMAP(blkno, bmp->db_l2nbperpage);
1816 mp = read_metapage(bmp->db_ipbmap, lblkno, PSIZE, 0);
1823 rc = dbAllocDmapLev(bmp, dp, (int) nblocks, l2nb, results);
1842 lblkno = BLKTODMAP(b, bmp->db_l2nbperpage);
1843 mp = read_metapage(bmp->db_ipbmap, lblkno, PSIZE, 0);
1854 jfs_error(bmp->db_ipbmap->i_sb,
1866 if ((rc = dbAllocDmap(bmp, dp, b, nb))) {
1895 lblkno = BLKTODMAP(b, bmp->db_l2nbperpage);
1896 mp = read_metapage(bmp->db_ipbmap, lblkno, PSIZE, 0);
1901 jfs_error(bmp->db_ipbmap->i_sb,
1909 if (dbFreeDmap(bmp, dp, b, BPERDMAP)) {
1914 jfs_error(bmp->db_ipbmap->i_sb, "Block Leakage\n");
1954 dbAllocDmapLev(struct bmap * bmp,
1986 if ((rc = dbAllocDmap(bmp, dp, blkno, nblocks)) == 0)
2009 * bmp - pointer to bmap descriptor
2020 static int dbAllocDmap(struct bmap * bmp, struct dmap * dp, s64 blkno,
2032 dbAllocBits(bmp, dp, blkno, nblocks);
2042 if ((rc = dbAdjCtl(bmp, blkno, dp->tree.stree[ROOT], 1, 0)))
2043 dbFreeBits(bmp, dp, blkno, nblocks);
2064 * bmp - pointer to bmap descriptor
2075 static int dbFreeDmap(struct bmap * bmp, struct dmap * dp, s64 blkno,
2087 rc = dbFreeBits(bmp, dp, blkno, nblocks);
2097 if ((rc = dbAdjCtl(bmp, blkno, dp->tree.stree[ROOT], 0, 0))) {
2108 dbAllocBits(bmp, dp, blkno, nblocks);
2128 * bmp - pointer to bmap descriptor
2137 static void dbAllocBits(struct bmap * bmp, struct dmap * dp, s64 blkno,
2213 jfs_error(bmp->db_ipbmap->i_sb,
2244 BMAP_LOCK(bmp);
2250 agno = blkno >> bmp->db_agl2size;
2251 if (agno > bmp->db_maxag)
2252 bmp->db_maxag = agno;
2255 bmp->db_agfree[agno] -= nblocks;
2256 bmp->db_nfree -= nblocks;
2258 BMAP_UNLOCK(bmp);
2275 * bmp - pointer to bmap descriptor
2284 static int dbFreeBits(struct bmap * bmp, struct dmap * dp, s64 blkno,
2388 BMAP_LOCK(bmp);
2393 agno = blkno >> bmp->db_agl2size;
2394 bmp->db_nfree += nblocks;
2395 bmp->db_agfree[agno] += nblocks;
2402 if ((bmp->db_agfree[agno] == bmp->db_agsize && agno == bmp->db_maxag) ||
2403 (agno == bmp->db_numag - 1 &&
2404 bmp->db_agfree[agno] == (bmp-> db_mapsize & (BPERDMAP - 1)))) {
2405 while (bmp->db_maxag > 0) {
2406 bmp->db_maxag -= 1;
2407 if (bmp->db_agfree[bmp->db_maxag] !=
2408 bmp->db_agsize)
2416 if (bmp->db_agpref > bmp->db_maxag)
2417 bmp->db_agpref = bmp->db_maxag;
2420 BMAP_UNLOCK(bmp);
2451 * bmp - pointer to bmap descriptor
2468 dbAdjCtl(struct bmap * bmp, s64 blkno, int newval, int alloc, int level)
2480 lblkno = BLKTOCTL(blkno, bmp->db_l2nbperpage, level);
2481 mp = read_metapage(bmp->db_ipbmap, lblkno, PSIZE, 0);
2487 jfs_error(bmp->db_ipbmap->i_sb, "Corrupt dmapctl page\n");
2551 if (level < bmp->db_maxlevel) {
2556 dbAdjCtl(bmp, blkno, dcp->stree[ROOT], alloc,
2589 assert(level == bmp->db_maxlevel);
2590 if (bmp->db_maxfreebud != oldroot) {
2591 jfs_error(bmp->db_ipbmap->i_sb,
2594 bmp->db_maxfreebud = dcp->stree[ROOT];
3190 struct bmap *bmp = JFS_SBI(ip->i_sb)->bmap;
3195 ASSERT(nblocks <= bmp->db_mapsize - blkno);
3208 lblkno = BLKTODMAP(blkno, bmp->db_l2nbperpage);
3222 if ((rc = dbAllocDmapBU(bmp, dp, blkno, nb))) {
3238 static int dbAllocDmapBU(struct bmap * bmp, struct dmap * dp, s64 blkno,
3311 BMAP_LOCK(bmp);
3317 agno = blkno >> bmp->db_agl2size;
3318 if (agno > bmp->db_maxag)
3319 bmp->db_maxag = agno;
3322 bmp->db_agfree[agno] -= nblocks;
3323 bmp->db_nfree -= nblocks;
3325 BMAP_UNLOCK(bmp);
3335 if ((rc = dbAdjCtl(bmp, blkno, tp->stree[ROOT], 1, 0)))
3336 dbFreeBits(bmp, dp, blkno, nblocks);
3370 struct bmap *bmp = sbi->bmap;
3387 bmp->db_mapsize = newsize;
3388 bmp->db_maxlevel = BMAPSZTOLEV(bmp->db_mapsize);
3392 oldl2agsize = bmp->db_agl2size;
3394 bmp->db_agl2size = l2agsize;
3395 bmp->db_agsize = 1 << l2agsize;
3398 agno = bmp->db_numag;
3399 bmp->db_numag = newsize >> l2agsize;
3400 bmp->db_numag += ((u32) newsize % (u32) bmp->db_agsize) ? 1 : 0;
3413 ag_rem = bmp->db_agfree[0]; /* save agfree[0] */
3415 bmp->db_agfree[n] = 0; /* init collection point */
3420 bmp->db_agfree[n] += bmp->db_agfree[i];
3423 bmp->db_agfree[0] += ag_rem; /* restore agfree[0] */
3426 bmp->db_agfree[n] = 0;
3432 bmp->db_maxag = bmp->db_maxag / k;
3548 bmp->db_nfree += n;
3550 bmp->db_agfree[agno] += n;
3579 bmp->db_maxfreebud = *l1leaf;
3603 bmp->db_maxfreebud = *l2leaf;
3633 struct bmap *bmp = JFS_SBI(ipbmap->i_sb)->bmap;
3648 actags = bmp->db_maxag + 1;
3649 inactags = bmp->db_numag - actags;
3650 ag_rem = bmp->db_mapsize & (bmp->db_agsize - 1); /* ??? */
3658 ((inactags - 1) << bmp->db_agl2size) + ag_rem
3659 : inactags << bmp->db_agl2size;
3665 actfree = bmp->db_nfree - inactfree;
3672 if (bmp->db_agfree[bmp->db_agpref] < avgfree) {
3673 for (bmp->db_agpref = 0; bmp->db_agpref < actags;
3674 bmp->db_agpref++) {
3675 if (bmp->db_agfree[bmp->db_agpref] >= avgfree)
3678 if (bmp->db_agpref >= bmp->db_numag) {
3691 bmp->db_aglevel = BMAPSZTOLEV(bmp->db_agsize);
3693 bmp->db_agl2size - (L2BPERDMAP + bmp->db_aglevel * L2LPERCTL);
3694 bmp->db_agheight = l2nl >> 1;
3695 bmp->db_agwidth = 1 << (l2nl - (bmp->db_agheight << 1));
3696 for (i = 5 - bmp->db_agheight, bmp->db_agstart = 0, n = 1; i > 0;
3698 bmp->db_agstart += n;