Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

xfs: trim the mapp array accordingly in xfs_da_grow_inode_int

Take a look at the for-loop in xfs_da_grow_inode_int:
======
for(){
nmap = min(XFS_BMAP_MAX_NMAP, count);
...
error = xfs_bmapi_write(...,&mapp[mapi], &nmap);//(..., $1, $2)
...
mapi += nmap;
}
=====
where $1 stands for the start address of the array,
while $2 is used to indicate the size of the array.

The array $1 will advance by $nmap in each iteration after
the allocation of extents.
But the size $2 still remains unchanged, which is determined by
min(XFS_BMAP_MAX_NMAP, count).

It seems that it has forgotten to trim the mapp array after each
iteration, so change it.

Signed-off-by: Shida Zhang <zhangshida@kylinos.cn>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Dave Chinner <david@fromorbit.com>

authored by

Shida Zhang and committed by
Dave Chinner
44159659 dc256418

+1 -1
+1 -1
fs/xfs/libxfs/xfs_da_btree.c
··· 2192 2192 */ 2193 2193 mapp = kmem_alloc(sizeof(*mapp) * count, 0); 2194 2194 for (b = *bno, mapi = 0; b < *bno + count; ) { 2195 - nmap = min(XFS_BMAP_MAX_NMAP, count); 2196 2195 c = (int)(*bno + count - b); 2196 + nmap = min(XFS_BMAP_MAX_NMAP, c); 2197 2197 error = xfs_bmapi_write(tp, dp, b, c, 2198 2198 xfs_bmapi_aflag(w)|XFS_BMAPI_METADATA, 2199 2199 args->total, &mapp[mapi], &nmap);