fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / fs / jfs / jfs_dmap.c
index d86e467..23546c8 100644 (file)
@@ -3,16 +3,16 @@
  *
  *   This program is free software;  you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or 
+ *   the Free Software Foundation; either version 2 of the License, or
  *   (at your option) any later version.
- * 
+ *
  *   This program is distributed in the hope that it will be useful,
  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
  *   the GNU General Public License for more details.
  *
  *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software 
+ *   along with this program;  if not, write to the Free Software
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
 #include "jfs_metapage.h"
 #include "jfs_debug.h"
 
-/*
- *     Debug code for double-checking block map
- */
-/* #define     _JFS_DEBUG_DMAP 1 */
-
-#ifdef _JFS_DEBUG_DMAP
-#define DBINITMAP(size,ipbmap,results) \
-       DBinitmap(size,ipbmap,results)
-#define DBALLOC(dbmap,mapsize,blkno,nblocks) \
-       DBAlloc(dbmap,mapsize,blkno,nblocks)
-#define DBFREE(dbmap,mapsize,blkno,nblocks) \
-       DBFree(dbmap,mapsize,blkno,nblocks)
-#define DBALLOCCK(dbmap,mapsize,blkno,nblocks) \
-       DBAllocCK(dbmap,mapsize,blkno,nblocks)
-#define DBFREECK(dbmap,mapsize,blkno,nblocks) \
-       DBFreeCK(dbmap,mapsize,blkno,nblocks)
-
-static void DBinitmap(s64, struct inode *, u32 **);
-static void DBAlloc(uint *, s64, s64, s64);
-static void DBFree(uint *, s64, s64, s64);
-static void DBAllocCK(uint *, s64, s64, s64);
-static void DBFreeCK(uint *, s64, s64, s64);
-#else
-#define DBINITMAP(size,ipbmap,results)
-#define DBALLOC(dbmap, mapsize, blkno, nblocks)
-#define DBFREE(dbmap, mapsize, blkno, nblocks)
-#define DBALLOCCK(dbmap, mapsize, blkno, nblocks)
-#define DBFREECK(dbmap, mapsize, blkno, nblocks)
-#endif                         /* _JFS_DEBUG_DMAP */
-
 /*
  *     SERIALIZATION of the Block Allocation Map.
  *
  *     the working state of the block allocation map is accessed in
  *     two directions:
- *     
+ *
  *     1) allocation and free requests that start at the dmap
  *        level and move up through the dmap control pages (i.e.
  *        the vast majority of requests).
- * 
- *     2) allocation requests that start at dmap control page
+ *
+ *     2) allocation requests that start at dmap control page
  *        level and work down towards the dmaps.
- *     
- *     the serialization scheme used here is as follows. 
  *
- *     requests which start at the bottom are serialized against each 
- *     other through buffers and each requests holds onto its buffers 
- *     as it works it way up from a single dmap to the required level 
+ *     the serialization scheme used here is as follows.
+ *
+ *     requests which start at the bottom are serialized against each
+ *     other through buffers and each requests holds onto its buffers
+ *     as it works it way up from a single dmap to the required level
  *     of dmap control page.
  *     requests that start at the top are serialized against each other
  *     and request that start from the bottom by the multiple read/single
  *     write inode lock of the bmap inode. requests starting at the top
  *     take this lock in write mode while request starting at the bottom
  *     take the lock in read mode.  a single top-down request may proceed
- *     exclusively while multiple bottoms-up requests may proceed 
- *     simultaneously (under the protection of busy buffers).
- *     
+ *     exclusively while multiple bottoms-up requests may proceed
+ *     simultaneously (under the protection of busy buffers).
+ *
  *     in addition to information found in dmaps and dmap control pages,
  *     the working state of the block allocation map also includes read/
  *     write information maintained in the bmap descriptor (i.e. total
@@ -89,14 +59,14 @@ static void DBFreeCK(uint *, s64, s64, s64);
  *     a single exclusive lock (BMAP_LOCK) is used to guard this information
  *     in the face of multiple-bottoms up requests.
  *     (lock ordering: IREAD_LOCK, BMAP_LOCK);
- *     
+ *
  *     accesses to the persistent state of the block allocation map (limited
  *     to the persistent bitmaps in dmaps) is guarded by (busy) buffers.
  */
 
-#define BMAP_LOCK_INIT(bmp)    init_MUTEX(&bmp->db_bmaplock)
-#define BMAP_LOCK(bmp)         down(&bmp->db_bmaplock)
-#define BMAP_UNLOCK(bmp)       up(&bmp->db_bmaplock)
+#define BMAP_LOCK_INIT(bmp)    mutex_init(&bmp->db_bmaplock)
+#define BMAP_LOCK(bmp)         mutex_lock(&bmp->db_bmaplock)
+#define BMAP_UNLOCK(bmp)       mutex_unlock(&bmp->db_bmaplock)
 
 /*
  * forward references
@@ -104,8 +74,8 @@ static void DBFreeCK(uint *, s64, s64, s64);
 static void dbAllocBits(struct bmap * bmp, struct dmap * dp, s64 blkno,
                        int nblocks);
 static void dbSplit(dmtree_t * tp, int leafno, int splitsz, int newval);
-static void dbBackSplit(dmtree_t * tp, int leafno);
-static void dbJoin(dmtree_t * tp, int leafno, int newval);
+static int dbBackSplit(dmtree_t * tp, int leafno);
+static int dbJoin(dmtree_t * tp, int leafno, int newval);
 static void dbAdjTree(dmtree_t * tp, int leafno, int newval);
 static int dbAdjCtl(struct bmap * bmp, s64 blkno, int newval, int alloc,
                    int level);
@@ -128,8 +98,8 @@ static int dbExtend(struct inode *ip, s64 blkno, s64 nblocks, s64 addnblocks);
 static int dbFindBits(u32 word, int l2nb);
 static int dbFindCtl(struct bmap * bmp, int l2nb, int level, s64 * blkno);
 static int dbFindLeaf(dmtree_t * tp, int l2nb, int *leafidx);
-static void dbFreeBits(struct bmap * bmp, struct dmap * dp, s64 blkno,
-                      int nblocks);
+static int dbFreeBits(struct bmap * bmp, struct dmap * dp, s64 blkno,
+                     int nblocks);
 static int dbFreeDmap(struct bmap * bmp, struct dmap * dp, s64 blkno,
                      int nblocks);
 static int dbMaxBud(u8 * cp);
@@ -150,12 +120,12 @@ static int dbGetL2AGSize(s64 nblocks);
 /*
  *     buddy table
  *
- * table used for determining buddy sizes within characters of 
+ * table used for determining buddy sizes within characters of
  * dmap bitmap words.  the characters themselves serve as indexes
  * into the table, with the table elements yielding the maximum
  * binary buddy of free bits within the character.
  */
-static s8 budtab[256] = {
+static const s8 budtab[256] = {
        3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
        2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
        2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@@ -176,7 +146,7 @@ static s8 budtab[256] = {
 
 
 /*
- * NAME:       dbMount()
+ * NAME:       dbMount()
  *
  * FUNCTION:   initializate the block allocation map.
  *
@@ -242,7 +212,6 @@ int dbMount(struct inode *ipbmap)
        JFS_SBI(ipbmap->i_sb)->bmap = bmp;
 
        memset(bmp->db_active, 0, sizeof(bmp->db_active));
-       DBINITMAP(bmp->db_mapsize, ipbmap, &bmp->db_DBmap);
 
        /*
         * allocate/initialize the bmap lock
@@ -254,12 +223,12 @@ int dbMount(struct inode *ipbmap)
 
 
 /*
- * NAME:       dbUnmount()
+ * NAME:       dbUnmount()
  *
  * FUNCTION:   terminate the block allocation map in preparation for
  *             file system unmount.
  *
- *             the in-core bmap descriptor is written to disk and
+ *             the in-core bmap descriptor is written to disk and
  *             the memory for this descriptor is freed.
  *
  * PARAMETERS:
@@ -272,7 +241,6 @@ int dbMount(struct inode *ipbmap)
 int dbUnmount(struct inode *ipbmap, int mounterror)
 {
        struct bmap *bmp = JFS_SBI(ipbmap->i_sb)->bmap;
-       int i;
 
        if (!(mounterror || isReadOnly(ipbmap)))
                dbSync(ipbmap);
@@ -282,14 +250,6 @@ int dbUnmount(struct inode *ipbmap, int mounterror)
         */
        truncate_inode_pages(ipbmap->i_mapping, 0);
 
-       /*
-        * Sanity Check
-        */
-       for (i = 0; i < bmp->db_numag; i++)
-               if (atomic_read(&bmp->db_active[i]))
-                       printk(KERN_ERR "dbUnmount: db_active[%d] = %d\n",
-                              i, atomic_read(&bmp->db_active[i]));
-
        /* free the memory for the in-memory bmap. */
        kfree(bmp);
 
@@ -342,10 +302,8 @@ int dbSync(struct inode *ipbmap)
        /*
         * write out dirty pages of bmap
         */
-       filemap_fdatawrite(ipbmap->i_mapping);
-       filemap_fdatawait(ipbmap->i_mapping);
+       filemap_write_and_wait(ipbmap->i_mapping);
 
-       ipbmap->i_state |= I_DIRTY;
        diWriteSpecial(ipbmap, 0);
 
        return (0);
@@ -353,7 +311,7 @@ int dbSync(struct inode *ipbmap)
 
 
 /*
- * NAME:       dbFree()
+ * NAME:       dbFree()
  *
  * FUNCTION:   free the specified block range from the working block
  *             allocation map.
@@ -416,16 +374,13 @@ int dbFree(struct inode *ip, s64 blkno, s64 nblocks)
                 */
                nb = min(rem, BPERDMAP - (blkno & (BPERDMAP - 1)));
 
-               DBALLOCCK(bmp->db_DBmap, bmp->db_mapsize, blkno, nb);
-
                /* free the blocks. */
                if ((rc = dbFreeDmap(bmp, dp, blkno, nb))) {
+                       jfs_error(ip->i_sb, "dbFree: error in block map\n");
                        release_metapage(mp);
                        IREAD_UNLOCK(ipbmap);
                        return (rc);
                }
-
-               DBFREE(bmp->db_DBmap, bmp->db_mapsize, blkno, nb);
        }
 
        /* write the last buffer. */
@@ -442,14 +397,14 @@ int dbFree(struct inode *ip, s64 blkno, s64 nblocks)
  *
  * FUNCTION:    update the allocation state (free or allocate) of the
  *             specified block range in the persistent block allocation map.
- *             
+ *
  *             the blocks will be updated in the persistent map one
  *             dmap at a time.
  *
  * PARAMETERS:
  *      ipbmap -  pointer to in-core inode for the block map.
- *      free   - TRUE if block range is to be freed from the persistent
- *               map; FALSE if it is to   be allocated.
+ *      free   -  'true' if block range is to be freed from the persistent
+ *                map; 'false' if it is to   be allocated.
  *      blkno  -  starting block number of the range.
  *      nblocks        -  number of contiguous blocks in the range.
  *      tblk   -  transaction block;
@@ -471,6 +426,7 @@ dbUpdatePMap(struct inode *ipbmap,
        struct metapage *mp;
        struct jfs_log *log;
        int lsn, difft, diffp;
+       unsigned long flags;
 
        /* the blocks better be within the mapsize. */
        if (blkno + nblocks > bmp->db_mapsize) {
@@ -504,6 +460,7 @@ dbUpdatePMap(struct inode *ipbmap,
                                           0);
                        if (mp == NULL)
                                return -EIO;
+                       metapage_wait_for_io(mp);
                }
                dp = (struct dmap *) mp->data;
 
@@ -518,7 +475,7 @@ dbUpdatePMap(struct inode *ipbmap,
                /* update the bits of the dmap words. the first and last
                 * words may only have a subset of their bits updated. if
                 * this is the case, we'll work against that word (i.e.
-                * partial first and/or last) only in a single pass.  a 
+                * partial first and/or last) only in a single pass.  a
                 * single pass will also be used to update all words that
                 * are to have all their bits updated.
                 */
@@ -575,6 +532,7 @@ dbUpdatePMap(struct inode *ipbmap,
 
                lastlblkno = lblkno;
 
+               LOGSYNC_LOCK(log, flags);
                if (mp->lsn != 0) {
                        /* inherit older/smaller lsn */
                        logdiff(diffp, mp->lsn, log);
@@ -582,31 +540,25 @@ dbUpdatePMap(struct inode *ipbmap,
                                mp->lsn = lsn;
 
                                /* move bp after tblock in logsync list */
-                               LOGSYNC_LOCK(log);
                                list_move(&mp->synclist, &tblk->synclist);
-                               LOGSYNC_UNLOCK(log);
                        }
 
                        /* inherit younger/larger clsn */
-                       LOGSYNC_LOCK(log);
                        logdiff(difft, tblk->clsn, log);
                        logdiff(diffp, mp->clsn, log);
                        if (difft > diffp)
                                mp->clsn = tblk->clsn;
-                       LOGSYNC_UNLOCK(log);
                } else {
                        mp->log = log;
                        mp->lsn = lsn;
 
                        /* insert bp after tblock in logsync list */
-                       LOGSYNC_LOCK(log);
-
                        log->count++;
                        list_add(&mp->synclist, &tblk->synclist);
 
                        mp->clsn = tblk->clsn;
-                       LOGSYNC_UNLOCK(log);
                }
+               LOGSYNC_UNLOCK(log, flags);
        }
 
        /* write the last buffer. */
@@ -710,11 +662,11 @@ unlock:
  *             the block allocation policy uses hints and a multi-step
  *             approach.
  *
- *             for allocation requests smaller than the number of blocks
+ *             for allocation requests smaller than the number of blocks
  *             per dmap, we first try to allocate the new blocks
  *             immediately following the hint.  if these blocks are not
  *             available, we try to allocate blocks near the hint.  if
- *             no blocks near the hint are available, we next try to 
+ *             no blocks near the hint are available, we next try to
  *             allocate within the same dmap as contains the hint.
  *
  *             if no blocks are available in the dmap or the allocation
@@ -761,7 +713,7 @@ int dbAlloc(struct inode *ip, s64 hint, s64 nblocks, s64 * results)
 #endif                         /* _STILL_TO_PORT */
 
        /* get the log2 number of blocks to be allocated.
-        * if the number of blocks is not a log2 multiple, 
+        * if the number of blocks is not a log2 multiple,
         * it will be rounded up to the next log2 multiple.
         */
        l2nb = BLKSTOL2(nblocks);
@@ -784,10 +736,6 @@ int dbAlloc(struct inode *ip, s64 hint, s64 nblocks, s64 * results)
                IWRITE_LOCK(ipbmap);
 
                rc = dbAllocAny(bmp, nblocks, l2nb, results);
-               if (rc == 0) {
-                       DBALLOC(bmp->db_DBmap, bmp->db_mapsize, *results,
-                               nblocks);
-               }
 
                goto write_unlock;
        }
@@ -845,8 +793,6 @@ int dbAlloc(struct inode *ip, s64 hint, s64 nblocks, s64 * results)
                    != -ENOSPC) {
                        if (rc == 0) {
                                *results = blkno;
-                               DBALLOC(bmp->db_DBmap, bmp->db_mapsize,
-                                       *results, nblocks);
                                mark_metapage_dirty(mp);
                        }
 
@@ -872,11 +818,8 @@ int dbAlloc(struct inode *ip, s64 hint, s64 nblocks, s64 * results)
                if ((rc =
                     dbAllocNear(bmp, dp, blkno, (int) nblocks, l2nb, results))
                    != -ENOSPC) {
-                       if (rc == 0) {
-                               DBALLOC(bmp->db_DBmap, bmp->db_mapsize,
-                                       *results, nblocks);
+                       if (rc == 0)
                                mark_metapage_dirty(mp);
-                       }
 
                        release_metapage(mp);
                        goto read_unlock;
@@ -887,11 +830,8 @@ int dbAlloc(struct inode *ip, s64 hint, s64 nblocks, s64 * results)
                 */
                if ((rc = dbAllocDmapLev(bmp, dp, (int) nblocks, l2nb, results))
                    != -ENOSPC) {
-                       if (rc == 0) {
-                               DBALLOC(bmp->db_DBmap, bmp->db_mapsize,
-                                       *results, nblocks);
+                       if (rc == 0)
                                mark_metapage_dirty(mp);
-                       }
 
                        release_metapage(mp);
                        goto read_unlock;
@@ -905,13 +845,9 @@ int dbAlloc(struct inode *ip, s64 hint, s64 nblocks, s64 * results)
         * the same allocation group as the hint.
         */
        IWRITE_LOCK(ipbmap);
-       if ((rc = dbAllocAG(bmp, agno, nblocks, l2nb, results))
-           != -ENOSPC) {
-               if (rc == 0)
-                       DBALLOC(bmp->db_DBmap, bmp->db_mapsize,
-                               *results, nblocks);
+       if ((rc = dbAllocAG(bmp, agno, nblocks, l2nb, results)) != -ENOSPC)
                goto write_unlock;
-       }
+
        IWRITE_UNLOCK(ipbmap);
 
 
@@ -927,9 +863,6 @@ int dbAlloc(struct inode *ip, s64 hint, s64 nblocks, s64 * results)
         */
        if ((rc = dbAllocAG(bmp, agno, nblocks, l2nb, results)) == -ENOSPC)
                rc = dbAllocAny(bmp, nblocks, l2nb, results);
-       if (rc == 0) {
-               DBALLOC(bmp->db_DBmap, bmp->db_mapsize, *results, nblocks);
-       }
 
       write_unlock:
        IWRITE_UNLOCK(ipbmap);
@@ -973,7 +906,7 @@ int dbAllocExact(struct inode *ip, s64 blkno, int nblocks)
         * validate extent request:
         *
         * note: defragfs policy:
-        *  max 64 blocks will be moved.  
+        *  max 64 blocks will be moved.
         *  allocation request size must be satisfied from a single dmap.
         */
        if (nblocks <= 0 || nblocks > BPERDMAP || blkno >= bmp->db_mapsize) {
@@ -1001,10 +934,9 @@ int dbAllocExact(struct inode *ip, s64 blkno, int nblocks)
 
        IREAD_UNLOCK(ipbmap);
 
-       if (rc == 0) {
-               DBALLOC(bmp->db_DBmap, bmp->db_mapsize, blkno, nblocks);
+       if (rc == 0)
                mark_metapage_dirty(mp);
-       }
+
        release_metapage(mp);
 
        return (rc);
@@ -1153,7 +1085,6 @@ static int dbExtend(struct inode *ip, s64 blkno, s64 nblocks, s64 addnblocks)
                return -EIO;
        }
 
-       DBALLOCCK(bmp->db_DBmap, bmp->db_mapsize, blkno, nblocks);
        dp = (struct dmap *) mp->data;
 
        /* try to allocate the blocks immediately following the
@@ -1164,11 +1095,9 @@ static int dbExtend(struct inode *ip, s64 blkno, s64 nblocks, s64 addnblocks)
        IREAD_UNLOCK(ipbmap);
 
        /* were we successful ? */
-       if (rc == 0) {
-               DBALLOC(bmp->db_DBmap, bmp->db_mapsize, extblkno,
-                       addnblocks);
+       if (rc == 0)
                write_metapage(mp);
-       else
+       else
                /* we were not successful */
                release_metapage(mp);
 
@@ -1404,7 +1333,7 @@ dbAllocNear(struct bmap * bmp,
  *             or two sub-trees, depending on the allocation group size.
  *             we search the top nodes of these subtrees left to right for
  *             sufficient free space.  if sufficient free space is found,
- *             the subtree is searched to find the leftmost leaf that 
+ *             the subtree is searched to find the leftmost leaf that
  *             has free space.  once we have made it to the leaf, we
  *             move the search to the next lower level dmap control page
  *             corresponding to this leaf.  we continue down the dmap control
@@ -1469,7 +1398,7 @@ dbAllocAG(struct bmap * bmp, int agno, s64 nblocks, int l2nb, s64 * results)
         * that fully describes the allocation group since the allocation
         * group is already fully described by a dmap.  in this case, we
         * just call dbAllocCtl() to search the dmap tree and allocate the
-        * required space if available.  
+        * required space if available.
         *
         * if the allocation group is completely free, dbAllocCtl() is
         * also called to allocate the required space.  this is done for
@@ -1521,7 +1450,7 @@ dbAllocAG(struct bmap * bmp, int agno, s64 nblocks, int l2nb, s64 * results)
            (1 << (L2LPERCTL - (bmp->db_agheigth << 1))) / bmp->db_agwidth;
        ti = bmp->db_agstart + bmp->db_agwidth * (agno & (agperlev - 1));
 
-       /* dmap control page trees fan-out by 4 and a single allocation 
+       /* dmap control page trees fan-out by 4 and a single allocation
         * group may be described by 1 or 2 subtrees within the ag level
         * dmap control page, depending upon the ag size. examine the ag's
         * subtrees for sufficient free space, starting with the leftmost
@@ -1704,7 +1633,7 @@ static int dbFindCtl(struct bmap * bmp, int l2nb, int level, s64 * blkno)
 
        /* starting at the specified dmap control page level and block
         * number, search down the dmap control levels for the starting
-        * block number of a dmap page that contains or starts off 
+        * block number of a dmap page that contains or starts off
         * sufficient free blocks.
         */
        for (lev = level, b = *blkno; lev >= 0; lev--) {
@@ -1748,7 +1677,7 @@ static int dbFindCtl(struct bmap * bmp, int l2nb, int level, s64 * blkno)
                }
 
                /* adjust the block number to reflect the location within
-                * the dmap control page (i.e. the leaf) at which free 
+                * the dmap control page (i.e. the leaf) at which free
                 * space was found.
                 */
                b += (((s64) leafidx) << budmin);
@@ -1771,12 +1700,12 @@ static int dbFindCtl(struct bmap * bmp, int l2nb, int level, s64 * blkno)
  * NAME:       dbAllocCtl()
  *
  * FUNCTION:    attempt to allocate a specified number of contiguous
- *             blocks starting within a specific dmap.  
- *             
+ *             blocks starting within a specific dmap.
+ *
  *             this routine is called by higher level routines that search
  *             the dmap control pages above the actual dmaps for contiguous
  *             free space.  the result of successful searches by these
- *             routines are the starting block numbers within dmaps, with
+ *             routines are the starting block numbers within dmaps, with
  *             the dmaps themselves containing the desired contiguous free
  *             space or starting a contiguous free space of desired size
  *             that is made up of the blocks of one or more dmaps. these
@@ -1943,14 +1872,14 @@ dbAllocCtl(struct bmap * bmp, s64 nblocks, int l2nb, s64 blkno, s64 * results)
  *
  * FUNCTION:    attempt to allocate a specified number of contiguous blocks
  *             from a specified dmap.
- *             
+ *
  *             this routine checks if the contiguous blocks are available.
  *             if so, nblocks of blocks are allocated; otherwise, ENOSPC is
  *             returned.
  *
  * PARAMETERS:
  *      mp     -  pointer to bmap descriptor
- *      dp     -  pointer to dmap to attempt to allocate blocks from. 
+ *      dp     -  pointer to dmap to attempt to allocate blocks from.
  *      l2nb   -  log2 number of contiguous block desired.
  *      nblocks        -  actual number of contiguous block desired.
  *      results        -  on successful return, set to the starting block number
@@ -1961,7 +1890,7 @@ dbAllocCtl(struct bmap * bmp, s64 nblocks, int l2nb, s64 blkno, s64 * results)
  *      -ENOSPC        - insufficient disk resources
  *      -EIO   - i/o error
  *
- * serialization: IREAD_LOCK(ipbmap), e.g., from dbAlloc(), or 
+ * serialization: IREAD_LOCK(ipbmap), e.g., from dbAlloc(), or
  *     IWRITE_LOCK(ipbmap), e.g., dbAllocCtl(), held on entry/exit;
  */
 static int
@@ -2087,7 +2016,7 @@ static int dbFreeDmap(struct bmap * bmp, struct dmap * dp, s64 blkno,
                      int nblocks)
 {
        s8 oldroot;
-       int rc, word;
+       int rc = 0, word;
 
        /* save the current value of the root (i.e. maximum free string)
         * of the dmap tree.
@@ -2095,15 +2024,15 @@ static int dbFreeDmap(struct bmap * bmp, struct dmap * dp, s64 blkno,
        oldroot = dp->tree.stree[ROOT];
 
        /* free the specified (blocks) bits */
-       dbFreeBits(bmp, dp, blkno, nblocks);
+       rc = dbFreeBits(bmp, dp, blkno, nblocks);
 
-       /* if the root has not changed, done. */
-       if (dp->tree.stree[ROOT] == oldroot)
-               return (0);
+       /* if error or the root has not changed, done. */
+       if (rc || (dp->tree.stree[ROOT] == oldroot))
+               return (rc);
 
        /* root changed. bubble the change up to the dmap control pages.
         * if the adjustment of the upper level control pages fails,
-        * backout the deallocation. 
+        * backout the deallocation.
         */
        if ((rc = dbAdjCtl(bmp, blkno, dp->tree.stree[ROOT], 0, 0))) {
                word = (blkno & (BPERDMAP - 1)) >> L2DBWORD;
@@ -2288,15 +2217,16 @@ static void dbAllocBits(struct bmap * bmp, struct dmap * dp, s64 blkno,
  *      blkno  -  starting block number of the bits to be freed.
  *      nblocks        -  number of bits to be freed.
  *
- * RETURN VALUES: none
+ * RETURN VALUES: 0 for success
  *
  * serialization: IREAD_LOCK(ipbmap) or IWRITE_LOCK(ipbmap) held on entry/exit;
  */
-static void dbFreeBits(struct bmap * bmp, struct dmap * dp, s64 blkno,
+static int dbFreeBits(struct bmap * bmp, struct dmap * dp, s64 blkno,
                       int nblocks)
 {
        int dbitno, word, rembits, nb, nwords, wbitno, nw, agno;
        dmtree_t *tp = (dmtree_t *) & dp->tree;
+       int rc = 0;
        int size;
 
        /* determine the bit number and word within the dmap of the
@@ -2315,7 +2245,7 @@ static void dbFreeBits(struct bmap * bmp, struct dmap * dp, s64 blkno,
         * words (i.e. partial first and/or last) on an individual basis
         * (a single pass), freeing the bits of interest by hand and updating
         * the leaf corresponding to the dmap word. a single pass will be used
-        * for all dmap words fully contained within the specified range.  
+        * for all dmap words fully contained within the specified range.
         * within this pass, the bits of all fully contained dmap words will
         * be marked as free in a single shot and the leaves will be updated. a
         * single leaf may describe the free space of multiple dmap words,
@@ -2337,7 +2267,7 @@ static void dbFreeBits(struct bmap * bmp, struct dmap * dp, s64 blkno,
                 */
                if (nb < DBWORD) {
                        /* free (zero) the appropriate bits within this
-                        * dmap word. 
+                        * dmap word.
                         */
                        dp->wmap[word] &=
                            cpu_to_le32(~(ONES << (DBWORD - nb)
@@ -2345,8 +2275,10 @@ static void dbFreeBits(struct bmap * bmp, struct dmap * dp, s64 blkno,
 
                        /* update the leaf for this dmap word.
                         */
-                       dbJoin(tp, word,
-                              dbMaxBud((u8 *) & dp->wmap[word]));
+                       rc = dbJoin(tp, word,
+                                   dbMaxBud((u8 *) & dp->wmap[word]));
+                       if (rc)
+                               return rc;
 
                        word += 1;
                } else {
@@ -2377,7 +2309,9 @@ static void dbFreeBits(struct bmap * bmp, struct dmap * dp, s64 blkno,
 
                                /* update the leaf.
                                 */
-                               dbJoin(tp, word, size);
+                               rc = dbJoin(tp, word, size);
+                               if (rc)
+                                       return rc;
 
                                /* get the number of dmap words handled.
                                 */
@@ -2393,7 +2327,7 @@ static void dbFreeBits(struct bmap * bmp, struct dmap * dp, s64 blkno,
 
        BMAP_LOCK(bmp);
 
-       /* update the free count for the allocation group and 
+       /* update the free count for the allocation group and
         * map.
         */
        agno = blkno >> bmp->db_agl2size;
@@ -2424,6 +2358,8 @@ static void dbFreeBits(struct bmap * bmp, struct dmap * dp, s64 blkno,
        }
 
        BMAP_UNLOCK(bmp);
+
+       return 0;
 }
 
 
@@ -2442,7 +2378,7 @@ static void dbFreeBits(struct bmap * bmp, struct dmap * dp, s64 blkno,
  *             or deallocation resulted in the root change.  this range
  *             is respresented by a single leaf of the current dmapctl
  *             and the leaf will be updated with this value, possibly
- *             causing a binary buddy system within the leaves to be 
+ *             causing a binary buddy system within the leaves to be
  *             split or joined.  the update may also cause the dmapctl's
  *             dmtree to be updated.
  *
@@ -2458,7 +2394,7 @@ static void dbFreeBits(struct bmap * bmp, struct dmap * dp, s64 blkno,
  *                requires the dmap control page to be adjusted.
  *      newval -  the new value of the lower level dmap or dmap control
  *                page root.
- *      alloc  -  TRUE if adjustment is due to an allocation.
+ *      alloc  -  'true' if adjustment is due to an allocation.
  *      level  -  current level of dmap control page (i.e. L0, L1, L2) to
  *                be adjusted.
  *
@@ -2526,12 +2462,16 @@ dbAdjCtl(struct bmap * bmp, s64 blkno, int newval, int alloc, int level)
                 * that it is at the front of a binary buddy system.
                 */
                if (oldval == NOFREE) {
-                       dbBackSplit((dmtree_t *) dcp, leafno);
+                       rc = dbBackSplit((dmtree_t *) dcp, leafno);
+                       if (rc)
+                               return rc;
                        oldval = dcp->stree[ti];
                }
                dbSplit((dmtree_t *) dcp, leafno, dcp->budmin, newval);
        } else {
-               dbJoin((dmtree_t *) dcp, leafno, newval);
+               rc = dbJoin((dmtree_t *) dcp, leafno, newval);
+               if (rc)
+                       return rc;
        }
 
        /* check if the root of the current dmap control page changed due
@@ -2650,7 +2590,7 @@ static void dbSplit(dmtree_t * tp, int leafno, int splitsz, int newval)
                }
        }
 
-       /* adjust the dmap tree to reflect the specified leaf's new 
+       /* adjust the dmap tree to reflect the specified leaf's new
         * value.
         */
        dbAdjTree(tp, leafno, newval);
@@ -2684,7 +2624,7 @@ static void dbSplit(dmtree_t * tp, int leafno, int splitsz, int newval)
  *
  * serialization: IREAD_LOCK(ipbmap) or IWRITE_LOCK(ipbmap) held on entry/exit;
  */
-static void dbBackSplit(dmtree_t * tp, int leafno)
+static int dbBackSplit(dmtree_t * tp, int leafno)
 {
        int budsz, bud, w, bsz, size;
        int cursz;
@@ -2698,7 +2638,7 @@ static void dbBackSplit(dmtree_t * tp, int leafno)
        /* the back split is accomplished by iteratively finding the leaf
         * that starts the buddy system that contains the specified leaf and
         * splitting that system in two.  this iteration continues until
-        * the specified leaf becomes the start of a buddy system. 
+        * the specified leaf becomes the start of a buddy system.
         *
         * determine maximum possible l2 size for the specified leaf.
         */
@@ -2719,7 +2659,10 @@ static void dbBackSplit(dmtree_t * tp, int leafno)
                 */
                for (w = leafno, bsz = budsz;; bsz <<= 1,
                     w = (w < bud) ? w : bud) {
-                       assert(bsz < le32_to_cpu(tp->dmt_nleafs));
+                       if (bsz >= le32_to_cpu(tp->dmt_nleafs)) {
+                               jfs_err("JFS: block map error in dbBackSplit");
+                               return -EIO;
+                       }
 
                        /* determine the buddy.
                         */
@@ -2738,7 +2681,11 @@ static void dbBackSplit(dmtree_t * tp, int leafno)
                }
        }
 
-       assert(leaf[leafno] == size);
+       if (leaf[leafno] != size) {
+               jfs_err("JFS: wrong leaf value in dbBackSplit");
+               return -EIO;
+       }
+       return 0;
 }
 
 
@@ -2756,7 +2703,7 @@ static void dbBackSplit(dmtree_t * tp, int leafno)
  *
  * RETURN VALUES: none
  */
-static void dbJoin(dmtree_t * tp, int leafno, int newval)
+static int dbJoin(dmtree_t * tp, int leafno, int newval)
 {
        int budsz, buddy;
        s8 *leaf;
@@ -2796,7 +2743,9 @@ static void dbJoin(dmtree_t * tp, int leafno, int newval)
                        if (newval > leaf[buddy])
                                break;
 
-                       assert(newval == leaf[buddy]);
+                       /* It shouldn't be less */
+                       if (newval < leaf[buddy])
+                               return -EIO;
 
                        /* check which (leafno or buddy) is the left buddy.
                         * the left buddy gets to claim the blocks resulting
@@ -2828,6 +2777,8 @@ static void dbJoin(dmtree_t * tp, int leafno, int newval)
        /* update the leaf value.
         */
        dbAdjTree(tp, leafno, newval);
+
+       return 0;
 }
 
 
@@ -2902,7 +2853,7 @@ static void dbAdjTree(dmtree_t * tp, int leafno, int newval)
  * NAME:       dbFindLeaf()
  *
  * FUNCTION:    search a dmtree_t for sufficient free blocks, returning
- *             the index of a leaf describing the free blocks if 
+ *             the index of a leaf describing the free blocks if
  *             sufficient free blocks are found.
  *
  *             the search starts at the top of the dmtree_t tree and
@@ -2918,7 +2869,7 @@ static void dbAdjTree(dmtree_t * tp, int leafno, int newval)
  *
  * RETURN VALUES:
  *      0      - success
- *      -ENOSPC        - insufficient free blocks. 
+ *      -ENOSPC        - insufficient free blocks.
  */
 static int dbFindLeaf(dmtree_t * tp, int l2nb, int *leafidx)
 {
@@ -3108,7 +3059,7 @@ static int cntlz(u32 value)
  * RETURN VALUES:
  *      log2 number of blocks
  */
-int blkstol2(s64 nb)
+static int blkstol2(s64 nb)
 {
        int l2nb;
        s64 mask;               /* meant to be signed */
@@ -3139,7 +3090,7 @@ int blkstol2(s64 nb)
 
 
 /*
- * NAME:       dbAllocBottomUp()
+ * NAME:       dbAllocBottomUp()
  *
  * FUNCTION:   alloc the specified block range from the working block
  *             allocation map.
@@ -3194,16 +3145,12 @@ int dbAllocBottomUp(struct inode *ip, s64 blkno, s64 nblocks)
                 */
                nb = min(rem, BPERDMAP - (blkno & (BPERDMAP - 1)));
 
-               DBFREECK(bmp->db_DBmap, bmp->db_mapsize, blkno, nb);
-
                /* allocate the blocks. */
                if ((rc = dbAllocDmapBU(bmp, dp, blkno, nb))) {
                        release_metapage(mp);
                        IREAD_UNLOCK(ipbmap);
                        return (rc);
                }
-
-               DBALLOC(bmp->db_DBmap, bmp->db_mapsize, blkno, nb);
        }
 
        /* write the last buffer. */
@@ -3294,7 +3241,7 @@ static int dbAllocDmapBU(struct bmap * bmp, struct dmap * dp, s64 blkno,
        BMAP_LOCK(bmp);
 
        /* if this allocation group is completely free,
-        * update the highest active allocation group number 
+        * update the highest active allocation group number
         * if this allocation group is the new max.
         */
        agno = blkno >> bmp->db_agl2size;
@@ -3326,7 +3273,7 @@ static int dbAllocDmapBU(struct bmap * bmp, struct dmap * dp, s64 blkno,
  * NAME:       dbExtendFS()
  *
  * FUNCTION:   extend bmap from blkno for nblocks;
- *             dbExtendFS() updates bmap ready for dbAllocBottomUp();
+ *             dbExtendFS() updates bmap ready for dbAllocBottomUp();
  *
  * L2
  *  |
@@ -3337,13 +3284,13 @@ static int dbAllocDmapBU(struct bmap * bmp, struct dmap * dp, s64 blkno,
  *       d0,...,dn  d0,...,dn  d0,...,dn    d0,...,dn  d0,...,dn  d0,.,dm;
  * L2L1L0d0,...,dnL0d0,...,dnL0d0,...,dnL1L0d0,...,dnL0d0,...,dnL0d0,..dm
  *
- * <---old---><----------------------------extend----------------------->   
+ * <---old---><----------------------------extend----------------------->
  */
 int dbExtendFS(struct inode *ipbmap, s64 blkno,        s64 nblocks)
 {
        struct jfs_sb_info *sbi = JFS_SBI(ipbmap->i_sb);
        int nbperpage = sbi->nbperpage;
-       int i, i0 = TRUE, j, j0 = TRUE, k, n;
+       int i, i0 = true, j, j0 = true, k, n;
        s64 newsize;
        s64 p;
        struct metapage *mp, *l2mp, *l1mp = NULL, *l0mp = NULL;
@@ -3383,7 +3330,7 @@ int dbExtendFS(struct inode *ipbmap, s64 blkno,   s64 nblocks)
        bmp->db_numag += ((u32) newsize % (u32) bmp->db_agsize) ? 1 : 0;
 
        /*
-        *      reconfigure db_agfree[] 
+        *      reconfigure db_agfree[]
         * from old AG configuration to new AG configuration;
         *
         * coalesce contiguous k (newAGSize/oldAGSize) AGs;
@@ -3451,7 +3398,7 @@ int dbExtendFS(struct inode *ipbmap, s64 blkno,   s64 nblocks)
                        j = (blkno & (MAXL1SIZE - 1)) >> L2MAXL0SIZE;
                        l1leaf = l1dcp->stree + CTLLEAFIND + j;
                        p = BLKTOL0(blkno, sbi->l2nbperpage);
-                       j0 = FALSE;
+                       j0 = false;
                } else {
                        /* assign/init L1 page */
                        l1mp = get_metapage(ipbmap, p, PSIZE, 0);
@@ -3485,7 +3432,7 @@ int dbExtendFS(struct inode *ipbmap, s64 blkno,   s64 nblocks)
                                l0leaf = l0dcp->stree + CTLLEAFIND + i;
                                p = BLKTODMAP(blkno,
                                              sbi->l2nbperpage);
-                               i0 = FALSE;
+                               i0 = false;
                        } else {
                                /* assign/init L0 page */
                                l0mp = get_metapage(ipbmap, p, PSIZE, 0);
@@ -3544,7 +3491,7 @@ int dbExtendFS(struct inode *ipbmap, s64 blkno,   s64 nblocks)
                        }       /* for each dmap in a L0 */
 
                        /*
-                        * build current L0 page from its leaves, and 
+                        * build current L0 page from its leaves, and
                         * initialize corresponding parent L1 leaf
                         */
                        *l1leaf = dbInitDmapCtl(l0dcp, 0, ++i);
@@ -3568,7 +3515,7 @@ int dbExtendFS(struct inode *ipbmap, s64 blkno,   s64 nblocks)
                }               /* for each L0 in a L1 */
 
                /*
-                * build current L1 page from its leaves, and 
+                * build current L1 page from its leaves, and
                 * initialize corresponding parent L2 leaf
                 */
                *l2leaf = dbInitDmapCtl(l1dcp, 1, ++j);
@@ -3623,7 +3570,7 @@ void dbFinalizeBmap(struct inode *ipbmap)
         *      finalize bmap control page
         */
 //finalize:
-       /* 
+       /*
         * compute db_agpref: preferred ag to allocate from
         * (the leftmost ag with average free space in it);
         */
@@ -3667,9 +3614,9 @@ void dbFinalizeBmap(struct inode *ipbmap)
 
        /*
         * compute db_aglevel, db_agheigth, db_width, db_agstart:
-        * an ag is covered in aglevel dmapctl summary tree, 
-        * at agheight level height (from leaf) with agwidth number of nodes 
-        * each, which starts at agstart index node of the smmary tree node 
+        * an ag is covered in aglevel dmapctl summary tree,
+        * at agheight level height (from leaf) with agwidth number of nodes
+        * each, which starts at agstart index node of the smmary tree node
         * array;
         */
        bmp->db_aglevel = BMAPSZTOLEV(bmp->db_agsize);
@@ -3688,13 +3635,13 @@ void dbFinalizeBmap(struct inode *ipbmap)
 
 /*
  * NAME:       dbInitDmap()/ujfs_idmap_page()
- *                                                                    
+ *
  * FUNCTION:   initialize working/persistent bitmap of the dmap page
  *             for the specified number of blocks:
- *                                                                    
+ *
  *             at entry, the bitmaps had been initialized as free (ZEROS);
- *             The number of blocks will only account for the actually 
- *             existing blocks. Blocks which don't actually exist in 
+ *             The number of blocks will only account for the actually
+ *             existing blocks. Blocks which don't actually exist in
  *             the aggregate will be marked as allocated (ONES);
  *
  * PARAMETERS:
@@ -3730,7 +3677,7 @@ static int dbInitDmap(struct dmap * dp, s64 Blkno, int nblocks)
 
        /*
         * free the bits corresponding to the block range (ZEROS):
-        * note: not all bits of the first and last words may be contained 
+        * note: not all bits of the first and last words may be contained
         * within the block range.
         */
        for (r = nblocks; r > 0; r -= nb, blkno += nb) {
@@ -3762,7 +3709,7 @@ static int dbInitDmap(struct dmap * dp, s64 Blkno, int nblocks)
        }
 
        /*
-        * mark bits following the range to be freed (non-existing 
+        * mark bits following the range to be freed (non-existing
         * blocks) as allocated (ONES)
         */
 
@@ -3794,11 +3741,11 @@ static int dbInitDmap(struct dmap * dp, s64 Blkno, int nblocks)
 
 /*
  * NAME:       dbInitDmapTree()/ujfs_complete_dmap()
- *                                                                    
+ *
  * FUNCTION:   initialize summary tree of the specified dmap:
  *
  *             at entry, bitmap of the dmap has been initialized;
- *                                                                    
+ *
  * PARAMETERS:
  *     dp      - dmap to complete
  *     blkno   - starting block number for this dmap
@@ -3822,7 +3769,7 @@ static int dbInitDmapTree(struct dmap * dp)
 
        /* init each leaf from corresponding wmap word:
         * note: leaf is set to NOFREE(-1) if all blocks of corresponding
-        * bitmap word are allocated. 
+        * bitmap word are allocated.
         */
        cp = tp->stree + le32_to_cpu(tp->leafidx);
        for (i = 0; i < LPERDMAP; i++)
@@ -3835,10 +3782,10 @@ static int dbInitDmapTree(struct dmap * dp)
 
 /*
  * NAME:       dbInitTree()/ujfs_adjtree()
- *                                                                    
+ *
  * FUNCTION:   initialize binary buddy summary tree of a dmap or dmapctl.
  *
- *             at entry, the leaves of the tree has been initialized 
+ *             at entry, the leaves of the tree has been initialized
  *             from corresponding bitmap word or root of summary tree
  *             of the child control page;
  *             configure binary buddy system at the leaf level, then
@@ -3866,15 +3813,15 @@ static int dbInitTree(struct dmaptree * dtp)
        /*
         * configure the leaf levevl into binary buddy system
         *
-        * Try to combine buddies starting with a buddy size of 1 
-        * (i.e. two leaves). At a buddy size of 1 two buddy leaves 
-        * can be combined if both buddies have a maximum free of l2min; 
-        * the combination will result in the left-most buddy leaf having 
-        * a maximum free of l2min+1.  
-        * After processing all buddies for a given size, process buddies 
-        * at the next higher buddy size (i.e. current size * 2) and 
-        * the next maximum free (current free + 1).  
-        * This continues until the maximum possible buddy combination 
+        * Try to combine buddies starting with a buddy size of 1
+        * (i.e. two leaves). At a buddy size of 1 two buddy leaves
+        * can be combined if both buddies have a maximum free of l2min;
+        * the combination will result in the left-most buddy leaf having
+        * a maximum free of l2min+1.
+        * After processing all buddies for a given size, process buddies
+        * at the next higher buddy size (i.e. current size * 2) and
+        * the next maximum free (current free + 1).
+        * This continues until the maximum possible buddy combination
         * yields maximum free.
         */
        for (l2free = dtp->budmin, bsize = 1; l2free < l2max;
@@ -3898,10 +3845,10 @@ static int dbInitTree(struct dmaptree * dtp)
         * bubble summary information of leaves up the tree.
         *
         * Starting at the leaf node level, the four nodes described by
-        * the higher level parent node are compared for a maximum free and 
-        * this maximum becomes the value of the parent node.  
-        * when all lower level nodes are processed in this fashion then 
-        * move up to the next level (parent becomes a lower level node) and 
+        * the higher level parent node are compared for a maximum free and
+        * this maximum becomes the value of the parent node.
+        * when all lower level nodes are processed in this fashion then
+        * move up to the next level (parent becomes a lower level node) and
         * continue the process for that level.
         */
        for (child = le32_to_cpu(dtp->leafidx),
@@ -3910,7 +3857,7 @@ static int dbInitTree(struct dmaptree * dtp)
                /* get index of 1st node of parent level */
                parent = (child - 1) >> 2;
 
-               /* set the value of the parent node as the maximum 
+               /* set the value of the parent node as the maximum
                 * of the four nodes of the current level.
                 */
                for (i = 0, cp = tp + child, cp1 = tp + parent;
@@ -3938,8 +3885,8 @@ static int dbInitDmapCtl(struct dmapctl * dcp, int level, int i)
        dcp->budmin = L2BPERDMAP + L2LPERCTL * level;
 
        /*
-        * initialize the leaves of current level that were not covered 
-        * by the specified input block range (i.e. the leaves have no 
+        * initialize the leaves of current level that were not covered
+        * by the specified input block range (i.e. the leaves have no
         * low level dmapctl or dmap).
         */
        cp = &dcp->stree[CTLLEAFIND + i];
@@ -3953,9 +3900,9 @@ static int dbInitDmapCtl(struct dmapctl * dcp, int level, int i)
 
 /*
  * NAME:       dbGetL2AGSize()/ujfs_getagl2size()
- *                                                                    
+ *
  * FUNCTION:   Determine log2(allocation group size) from aggregate size
- *                                                                    
+ *
  * PARAMETERS:
  *     nblocks - Number of blocks in aggregate
  *
@@ -3988,8 +3935,8 @@ static int dbGetL2AGSize(s64 nblocks)
 
 /*
  * NAME:       dbMapFileSizeToMapSize()
- *                                                                    
- * FUNCTION:   compute number of blocks the block allocation map file 
+ *
+ * FUNCTION:   compute number of blocks the block allocation map file
  *             can cover from the map file size;
  *
  * RETURNS:    Number of blocks which can be covered by this block map file;
@@ -4021,7 +3968,7 @@ s64 dbMapFileSizeToMapSize(struct inode * ipbmap)
        npages = nblocks >> JFS_SBI(sb)->l2nbperpage;
        level = BMAPPGTOLEV(npages);
 
-       /* At each level, accumulate the number of dmap pages covered by 
+       /* At each level, accumulate the number of dmap pages covered by
         * the number of full child levels below it;
         * repeat for the last incomplete child level.
         */
@@ -4043,230 +3990,10 @@ s64 dbMapFileSizeToMapSize(struct inode * ipbmap)
                npages--;
        }
 
-       /* convert the number of dmaps into the number of blocks 
+       /* convert the number of dmaps into the number of blocks
         * which can be covered by the dmaps;
         */
        nblocks = ndmaps << L2BPERDMAP;
 
        return (nblocks);
 }
-
-
-#ifdef _JFS_DEBUG_DMAP
-/*
- *     DBinitmap()
- */
-static void DBinitmap(s64 size, struct inode *ipbmap, u32 ** results)
-{
-       int npages;
-       u32 *dbmap, *d;
-       int n;
-       s64 lblkno, cur_block;
-       struct dmap *dp;
-       struct metapage *mp;
-
-       npages = size / 32768;
-       npages += (size % 32768) ? 1 : 0;
-
-       dbmap = (u32 *) xmalloc(npages * 4096, L2PSIZE, kernel_heap);
-       if (dbmap == NULL)
-               BUG();  /* Not robust since this is only unused debug code */
-
-       for (n = 0, d = dbmap; n < npages; n++, d += 1024)
-               bzero(d, 4096);
-
-       /* Need to initialize from disk map pages
-        */
-       for (d = dbmap, cur_block = 0; cur_block < size;
-            cur_block += BPERDMAP, d += LPERDMAP) {
-               lblkno = BLKTODMAP(cur_block,
-                                  JFS_SBI(ipbmap->i_sb)->bmap->
-                                  db_l2nbperpage);
-               mp = read_metapage(ipbmap, lblkno, PSIZE, 0);
-               if (mp == NULL) {
-                       jfs_error(ipbmap->i_sb,
-                                 "DBinitmap: could not read disk map page");
-                       continue;
-               }
-               dp = (struct dmap *) mp->data;
-
-               for (n = 0; n < LPERDMAP; n++)
-                       d[n] = le32_to_cpu(dp->wmap[n]);
-
-               release_metapage(mp);
-       }
-
-       *results = dbmap;
-}
-
-
-/*
- *     DBAlloc()
- */
-void DBAlloc(uint * dbmap, s64 mapsize, s64 blkno, s64 nblocks)
-{
-       int word, nb, bitno;
-       u32 mask;
-
-       assert(blkno > 0 && blkno < mapsize);
-       assert(nblocks > 0 && nblocks <= mapsize);
-
-       assert(blkno + nblocks <= mapsize);
-
-       dbmap += (blkno / 32);
-       while (nblocks > 0) {
-               bitno = blkno & (32 - 1);
-               nb = min(nblocks, 32 - bitno);
-
-               mask = (0xffffffff << (32 - nb) >> bitno);
-               assert((mask & *dbmap) == 0);
-               *dbmap |= mask;
-
-               dbmap++;
-               blkno += nb;
-               nblocks -= nb;
-       }
-}
-
-
-/*
- *     DBFree()
- */
-static void DBFree(uint * dbmap, s64 mapsize, s64 blkno, s64 nblocks)
-{
-       int word, nb, bitno;
-       u32 mask;
-
-       assert(blkno > 0 && blkno < mapsize);
-       assert(nblocks > 0 && nblocks <= mapsize);
-
-       assert(blkno + nblocks <= mapsize);
-
-       dbmap += (blkno / 32);
-       while (nblocks > 0) {
-               bitno = blkno & (32 - 1);
-               nb = min(nblocks, 32 - bitno);
-
-               mask = (0xffffffff << (32 - nb) >> bitno);
-               assert((mask & *dbmap) == mask);
-               *dbmap &= ~mask;
-
-               dbmap++;
-               blkno += nb;
-               nblocks -= nb;
-       }
-}
-
-
-/*
- *     DBAllocCK()
- */
-static void DBAllocCK(uint * dbmap, s64 mapsize, s64 blkno, s64 nblocks)
-{
-       int word, nb, bitno;
-       u32 mask;
-
-       assert(blkno > 0 && blkno < mapsize);
-       assert(nblocks > 0 && nblocks <= mapsize);
-
-       assert(blkno + nblocks <= mapsize);
-
-       dbmap += (blkno / 32);
-       while (nblocks > 0) {
-               bitno = blkno & (32 - 1);
-               nb = min(nblocks, 32 - bitno);
-
-               mask = (0xffffffff << (32 - nb) >> bitno);
-               assert((mask & *dbmap) == mask);
-
-               dbmap++;
-               blkno += nb;
-               nblocks -= nb;
-       }
-}
-
-
-/*
- *     DBFreeCK()
- */
-static void DBFreeCK(uint * dbmap, s64 mapsize, s64 blkno, s64 nblocks)
-{
-       int word, nb, bitno;
-       u32 mask;
-
-       assert(blkno > 0 && blkno < mapsize);
-       assert(nblocks > 0 && nblocks <= mapsize);
-
-       assert(blkno + nblocks <= mapsize);
-
-       dbmap += (blkno / 32);
-       while (nblocks > 0) {
-               bitno = blkno & (32 - 1);
-               nb = min(nblocks, 32 - bitno);
-
-               mask = (0xffffffff << (32 - nb) >> bitno);
-               assert((mask & *dbmap) == 0);
-
-               dbmap++;
-               blkno += nb;
-               nblocks -= nb;
-       }
-}
-
-
-/*
- *     dbPrtMap()
- */
-static void dbPrtMap(struct bmap * bmp)
-{
-       printk("   mapsize:   %d%d\n", bmp->db_mapsize);
-       printk("   nfree:     %d%d\n", bmp->db_nfree);
-       printk("   numag:     %d\n", bmp->db_numag);
-       printk("   agsize:    %d%d\n", bmp->db_agsize);
-       printk("   agl2size:  %d\n", bmp->db_agl2size);
-       printk("   agwidth:   %d\n", bmp->db_agwidth);
-       printk("   agstart:   %d\n", bmp->db_agstart);
-       printk("   agheigth:  %d\n", bmp->db_agheigth);
-       printk("   aglevel:   %d\n", bmp->db_aglevel);
-       printk("   maxlevel:  %d\n", bmp->db_maxlevel);
-       printk("   maxag:     %d\n", bmp->db_maxag);
-       printk("   agpref:    %d\n", bmp->db_agpref);
-       printk("   l2nbppg:   %d\n", bmp->db_l2nbperpage);
-}
-
-
-/*
- *     dbPrtCtl()
- */
-static void dbPrtCtl(struct dmapctl * dcp)
-{
-       int i, j, n;
-
-       printk("   height:    %08x\n", le32_to_cpu(dcp->height));
-       printk("   leafidx:   %08x\n", le32_to_cpu(dcp->leafidx));
-       printk("   budmin:    %08x\n", dcp->budmin);
-       printk("   nleafs:    %08x\n", le32_to_cpu(dcp->nleafs));
-       printk("   l2nleafs:  %08x\n", le32_to_cpu(dcp->l2nleafs));
-
-       printk("\n Tree:\n");
-       for (i = 0; i < CTLLEAFIND; i += 8) {
-               n = min(8, CTLLEAFIND - i);
-
-               for (j = 0; j < n; j++)
-                       printf("  [%03x]: %02x", i + j,
-                              (char) dcp->stree[i + j]);
-               printf("\n");
-       }
-
-       printk("\n Tree Leaves:\n");
-       for (i = 0; i < LPERCTL; i += 8) {
-               n = min(8, LPERCTL - i);
-
-               for (j = 0; j < n; j++)
-                       printf("  [%03x]: %02x",
-                              i + j,
-                              (char) dcp->stree[i + j + CTLLEAFIND]);
-               printf("\n");
-       }
-}
-#endif                         /* _JFS_DEBUG_DMAP */