]> err.no Git - linux-2.6/blobdiff - fs/jfs/jfs_dmap.c
/home/lenb/linux-2.6 branch 'acpi-2.6.12'
[linux-2.6] / fs / jfs / jfs_dmap.c
index d86e467c6e421628a2f845668b5da630581bdf7e..0732f206ca60aa5323a24a0a76b68ded3809bd90 100644 (file)
 #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.
  *
@@ -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
@@ -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);
 
@@ -416,16 +376,12 @@ 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))) {
                        release_metapage(mp);
                        IREAD_UNLOCK(ipbmap);
                        return (rc);
                }
-
-               DBFREE(bmp->db_DBmap, bmp->db_mapsize, blkno, nb);
        }
 
        /* write the last buffer. */
@@ -471,6 +427,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 +461,7 @@ dbUpdatePMap(struct inode *ipbmap,
                                           0);
                        if (mp == NULL)
                                return -EIO;
+                       metapage_wait_for_io(mp);
                }
                dp = (struct dmap *) mp->data;
 
@@ -578,34 +536,32 @@ dbUpdatePMap(struct inode *ipbmap,
                if (mp->lsn != 0) {
                        /* inherit older/smaller lsn */
                        logdiff(diffp, mp->lsn, log);
+                       LOGSYNC_LOCK(log, flags);
                        if (difft < diffp) {
                                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);
+                       LOGSYNC_UNLOCK(log, flags);
                } else {
                        mp->log = log;
                        mp->lsn = lsn;
 
                        /* insert bp after tblock in logsync list */
-                       LOGSYNC_LOCK(log);
+                       LOGSYNC_LOCK(log, flags);
 
                        log->count++;
                        list_add(&mp->synclist, &tblk->synclist);
 
                        mp->clsn = tblk->clsn;
-                       LOGSYNC_UNLOCK(log);
+                       LOGSYNC_UNLOCK(log, flags);
                }
        }
 
@@ -784,10 +740,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 +797,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 +822,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 +834,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 +849,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 +867,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);
@@ -1001,10 +938,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 +1089,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 +1099,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);
 
@@ -3194,16 +3127,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. */
@@ -4050,223 +3979,3 @@ s64 dbMapFileSizeToMapSize(struct inode * ipbmap)
 
        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 */