xfs: switch to NOFS allocation under i_lock in xfs_da_state_alloc
[safe/jmp/linux-2.6] / fs / xfs / xfs_da_btree.c
index edc0aef..bd0bb6d 100644 (file)
@@ -1503,7 +1503,7 @@ xfs_da_path_shift(xfs_da_state_t *state, xfs_da_state_path_t *path,
  * This is implemented with some source-level loop unrolling.
  */
 xfs_dahash_t
-xfs_da_hashname(const uchar_t *name, int namelen)
+xfs_da_hashname(const __uint8_t *name, int namelen)
 {
        xfs_dahash_t hash;
 
@@ -1566,11 +1566,14 @@ xfs_da_grow_inode(xfs_da_args_t *args, xfs_dablk_t *new_blkno)
        int nmap, error, w, count, c, got, i, mapi;
        xfs_trans_t *tp;
        xfs_mount_t *mp;
+       xfs_drfsbno_t   nblks;
 
        dp = args->dp;
        mp = dp->i_mount;
        w = args->whichfork;
        tp = args->trans;
+       nblks = dp->i_d.di_nblocks;
+
        /*
         * For new directories adjust the file offset and block count.
         */
@@ -1594,7 +1597,7 @@ xfs_da_grow_inode(xfs_da_args_t *args, xfs_dablk_t *new_blkno)
        nmap = 1;
        ASSERT(args->firstblock != NULL);
        if ((error = xfs_bmapi(tp, dp, bno, count,
-                       XFS_BMAPI_AFLAG(w)|XFS_BMAPI_WRITE|XFS_BMAPI_METADATA|
+                       xfs_bmapi_aflag(w)|XFS_BMAPI_WRITE|XFS_BMAPI_METADATA|
                        XFS_BMAPI_CONTIG,
                        args->firstblock, args->total, &map, &nmap,
                        args->flist, NULL))) {
@@ -1615,7 +1618,7 @@ xfs_da_grow_inode(xfs_da_args_t *args, xfs_dablk_t *new_blkno)
                        nmap = MIN(XFS_BMAP_MAX_NMAP, count);
                        c = (int)(bno + count - b);
                        if ((error = xfs_bmapi(tp, dp, b, c,
-                                       XFS_BMAPI_AFLAG(w)|XFS_BMAPI_WRITE|
+                                       xfs_bmapi_aflag(w)|XFS_BMAPI_WRITE|
                                        XFS_BMAPI_METADATA,
                                        args->firstblock, args->total,
                                        &mapp[mapi], &nmap, args->flist,
@@ -1647,6 +1650,8 @@ xfs_da_grow_inode(xfs_da_args_t *args, xfs_dablk_t *new_blkno)
        }
        if (mapp != &map)
                kmem_free(mapp);
+       /* account for newly allocated blocks in reserved blocks total */
+       args->total -= dp->i_d.di_nblocks - nblks;
        *new_blkno = (xfs_dablk_t)bno;
        return 0;
 }
@@ -1877,7 +1882,7 @@ xfs_da_shrink_inode(xfs_da_args_t *args, xfs_dablk_t dead_blkno,
                 * the last block to the place we want to kill.
                 */
                if ((error = xfs_bunmapi(tp, dp, dead_blkno, count,
-                               XFS_BMAPI_AFLAG(w)|XFS_BMAPI_METADATA,
+                               xfs_bmapi_aflag(w)|XFS_BMAPI_METADATA,
                                0, args->firstblock, args->flist, NULL,
                                &done)) == ENOSPC) {
                        if (w != XFS_DATA_FORK)
@@ -1982,7 +1987,7 @@ xfs_da_do_buf(
                        if ((error = xfs_bmapi(trans, dp, (xfs_fileoff_t)bno,
                                        nfsb,
                                        XFS_BMAPI_METADATA |
-                                               XFS_BMAPI_AFLAG(whichfork),
+                                               xfs_bmapi_aflag(whichfork),
                                        NULL, 0, mapp, &nmap, NULL, NULL)))
                                goto exit0;
                }
@@ -2196,7 +2201,7 @@ kmem_zone_t *xfs_dabuf_zone;              /* dabuf zone */
 xfs_da_state_t *
 xfs_da_state_alloc(void)
 {
-       return kmem_zone_zalloc(xfs_da_state_zone, KM_SLEEP);
+       return kmem_zone_zalloc(xfs_da_state_zone, KM_NOFS);
 }
 
 /*
@@ -2240,7 +2245,7 @@ xfs_da_state_free(xfs_da_state_t *state)
 
 #ifdef XFS_DABUF_DEBUG
 xfs_dabuf_t    *xfs_dabuf_global_list;
-spinlock_t     xfs_dabuf_global_lock;
+static DEFINE_SPINLOCK(xfs_dabuf_global_lock);
 #endif
 
 /*