Commit a7444053 authored by David Chinner's avatar David Chinner Committed by Lachlan McIlroy

[XFS] Account for allocated blocks when expanding directories

When we create a directory, we reserve a number of blocks for the maximum
possible expansion of of the directory due to various btree splits,
freespace allocation, etc. Unfortunately, each allocation is not reflected
in the total number of blocks still available to the transaction, so the
maximal reservation is used over and over again.

This leads to problems where an allocation group has only enough blocks
for *some* of the allocations required for the directory modification.
After the first N allocations, the remaining blocks in the allocation
group drops below the total reservation, and subsequent allocations fail
because the allocator will not allow the allocation to proceed if the AG
does not have the enough blocks available for the entire allocation total.

This results in an ENOSPC occurring after an allocation has already
occurred. This results in aborting the directory operation (leaving the
directory in an inconsistent state) and cancelling a dirty transaction,
which results in a filesystem shutdown.

Avoid the problem by reflecting the number of blocks allocated in any
directory expansion in the total number of blocks available to the
modification in progress. This prevents a directory modification from
being aborted part way through with an ENOSPC.

SGI-PV: 988144

SGI-Modid: xfs-linux-melb:xfs-kern:32340a
Signed-off-by: default avatarDavid Chinner <david@fromorbit.com>
Signed-off-by: default avatarLachlan McIlroy <lachlan@sgi.com>
parent 8c38ab03
...@@ -1566,11 +1566,14 @@ xfs_da_grow_inode(xfs_da_args_t *args, xfs_dablk_t *new_blkno) ...@@ -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; int nmap, error, w, count, c, got, i, mapi;
xfs_trans_t *tp; xfs_trans_t *tp;
xfs_mount_t *mp; xfs_mount_t *mp;
xfs_drfsbno_t nblks;
dp = args->dp; dp = args->dp;
mp = dp->i_mount; mp = dp->i_mount;
w = args->whichfork; w = args->whichfork;
tp = args->trans; tp = args->trans;
nblks = dp->i_d.di_nblocks;
/* /*
* For new directories adjust the file offset and block count. * For new directories adjust the file offset and block count.
*/ */
...@@ -1647,6 +1650,8 @@ xfs_da_grow_inode(xfs_da_args_t *args, xfs_dablk_t *new_blkno) ...@@ -1647,6 +1650,8 @@ xfs_da_grow_inode(xfs_da_args_t *args, xfs_dablk_t *new_blkno)
} }
if (mapp != &map) if (mapp != &map)
kmem_free(mapp); 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; *new_blkno = (xfs_dablk_t)bno;
return 0; return 0;
} }
......
...@@ -525,11 +525,13 @@ xfs_dir2_grow_inode( ...@@ -525,11 +525,13 @@ xfs_dir2_grow_inode(
xfs_mount_t *mp; xfs_mount_t *mp;
int nmap; /* number of bmap entries */ int nmap; /* number of bmap entries */
xfs_trans_t *tp; xfs_trans_t *tp;
xfs_drfsbno_t nblks;
xfs_dir2_trace_args_s("grow_inode", args, space); xfs_dir2_trace_args_s("grow_inode", args, space);
dp = args->dp; dp = args->dp;
tp = args->trans; tp = args->trans;
mp = dp->i_mount; mp = dp->i_mount;
nblks = dp->i_d.di_nblocks;
/* /*
* Set lowest possible block in the space requested. * Set lowest possible block in the space requested.
*/ */
...@@ -622,7 +624,11 @@ xfs_dir2_grow_inode( ...@@ -622,7 +624,11 @@ xfs_dir2_grow_inode(
*/ */
if (mapp != &map) if (mapp != &map)
kmem_free(mapp); kmem_free(mapp);
/* account for newly allocated blocks in reserved blocks total */
args->total -= dp->i_d.di_nblocks - nblks;
*dbp = xfs_dir2_da_to_db(mp, (xfs_dablk_t)bno); *dbp = xfs_dir2_da_to_db(mp, (xfs_dablk_t)bno);
/* /*
* Update file's size if this is the data space and it grew. * Update file's size if this is the data space and it grew.
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment