Skip to content

Commit 657f101

Browse files
Brian Fosterdjwong
authored andcommitted
xfs: fix off-by-one in inode alloc block reservation calculation
The inode chunk allocation transaction reserves inobt_maxlevels-1 blocks to accommodate a full split of the inode btree. A full split requires an allocation for every existing level and a new root block, which means inobt_maxlevels is the worst case block requirement for a transaction that inserts to the inobt. This can lead to a transaction block reservation overrun when tmpfile creation allocates an inode chunk and expands the inobt to its maximum depth. This problem has been observed in conjunction with overlayfs, which makes frequent use of tmpfiles internally. The existing reservation code goes back as far as the Linux git repo history (v2.6.12). It was likely never observed as a problem because the traditional file/directory creation transactions also include worst case block reservation for directory modifications, which most likely is able to make up for a single block deficiency in the inode allocation portion of the calculation. tmpfile support is relatively more recent (v3.15), less heavily used, and only includes the inode allocation block reservation as tmpfiles aren't linked into the directory tree on creation. Fix up the inode alloc block reservation macro and a couple of the block allocator minleft parameters that enforce an allocation to leave enough free blocks in the AG for a full inobt split. Signed-off-by: Brian Foster <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent 9c516e0 commit 657f101

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

fs/xfs/libxfs/xfs_ialloc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ xfs_ialloc_ag_alloc(
688688
args.minalignslop = igeo->cluster_align - 1;
689689

690690
/* Allow space for the inode btree to split. */
691-
args.minleft = igeo->inobt_maxlevels - 1;
691+
args.minleft = igeo->inobt_maxlevels;
692692
if ((error = xfs_alloc_vextent(&args)))
693693
return error;
694694

@@ -736,7 +736,7 @@ xfs_ialloc_ag_alloc(
736736
/*
737737
* Allow space for the inode btree to split.
738738
*/
739-
args.minleft = igeo->inobt_maxlevels - 1;
739+
args.minleft = igeo->inobt_maxlevels;
740740
if ((error = xfs_alloc_vextent(&args)))
741741
return error;
742742
}

fs/xfs/libxfs/xfs_trans_space.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
#define XFS_IALLOC_SPACE_RES(mp) \
5959
(M_IGEO(mp)->ialloc_blks + \
6060
((xfs_sb_version_hasfinobt(&mp->m_sb) ? 2 : 1) * \
61-
(M_IGEO(mp)->inobt_maxlevels - 1)))
61+
M_IGEO(mp)->inobt_maxlevels))
6262

6363
/*
6464
* Space reservation values for various transactions.

0 commit comments

Comments
 (0)