Skip to content

Commit 1cd738b

Browse files
Brian FosterDarrick J. Wong
authored andcommitted
xfs: consider shutdown in bmapbt cursor delete assert
The assert in xfs_btree_del_cursor() checks that the bmapbt block allocation field has been handled correctly before the cursor is freed. This field is used for accurate calculation of indirect block reservation requirements (for delayed allocations), for example. generic/019 reproduces a scenario where this assert fails because the filesystem has shutdown while in the middle of a bmbt record insertion. This occurs after a bmbt block has been allocated via the cursor but before the higher level bmap function (i.e. xfs_bmap_add_extent_hole_real()) completes and resets the field. Update the assert to accommodate the transient state if the filesystem has shutdown. While here, clean up the indentation and comments in the function. Signed-off-by: Brian Foster <bfoster@redhat.com> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
1 parent 8646b98 commit 1cd738b

1 file changed

Lines changed: 12 additions & 21 deletions

File tree

fs/xfs/libxfs/xfs_btree.c

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -353,38 +353,29 @@ xfs_btree_free_block(
353353
*/
354354
void
355355
xfs_btree_del_cursor(
356-
xfs_btree_cur_t *cur, /* btree cursor */
357-
int error) /* del because of error */
356+
struct xfs_btree_cur *cur, /* btree cursor */
357+
int error) /* del because of error */
358358
{
359-
int i; /* btree level */
359+
int i; /* btree level */
360360

361361
/*
362-
* Clear the buffer pointers, and release the buffers.
363-
* If we're doing this in the face of an error, we
364-
* need to make sure to inspect all of the entries
365-
* in the bc_bufs array for buffers to be unlocked.
366-
* This is because some of the btree code works from
367-
* level n down to 0, and if we get an error along
368-
* the way we won't have initialized all the entries
369-
* down to 0.
362+
* Clear the buffer pointers and release the buffers. If we're doing
363+
* this because of an error, inspect all of the entries in the bc_bufs
364+
* array for buffers to be unlocked. This is because some of the btree
365+
* code works from level n down to 0, and if we get an error along the
366+
* way we won't have initialized all the entries down to 0.
370367
*/
371368
for (i = 0; i < cur->bc_nlevels; i++) {
372369
if (cur->bc_bufs[i])
373370
xfs_trans_brelse(cur->bc_tp, cur->bc_bufs[i]);
374371
else if (!error)
375372
break;
376373
}
377-
/*
378-
* Can't free a bmap cursor without having dealt with the
379-
* allocated indirect blocks' accounting.
380-
*/
381-
ASSERT(cur->bc_btnum != XFS_BTNUM_BMAP ||
382-
cur->bc_ino.allocated == 0);
383-
/*
384-
* Free the cursor.
385-
*/
374+
375+
ASSERT(cur->bc_btnum != XFS_BTNUM_BMAP || cur->bc_ino.allocated == 0 ||
376+
XFS_FORCED_SHUTDOWN(cur->bc_mp));
386377
if (unlikely(cur->bc_flags & XFS_BTREE_STAGING))
387-
kmem_free((void *)cur->bc_ops);
378+
kmem_free(cur->bc_ops);
388379
kmem_cache_free(xfs_btree_cur_zone, cur);
389380
}
390381

0 commit comments

Comments
 (0)