Skip to content

Commit 919522e

Browse files
committed
xfs: clean up bmap intent item recovery checking
The bmap intent item checking code in xfs_bui_item_recover is spread all over the function. We should check the recovered log item at the top before we allocate any resources or do anything else, so do that. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Dave Chinner <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]>
1 parent 929b92f commit 919522e

File tree

1 file changed

+12
-26
lines changed

1 file changed

+12
-26
lines changed

fs/xfs/xfs_bmap_item.c

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,6 @@ xfs_bui_item_recover(
437437
xfs_fsblock_t inode_fsb;
438438
xfs_filblks_t count;
439439
xfs_exntst_t state;
440-
enum xfs_bmap_intent_type type;
441-
bool op_ok;
442440
unsigned int bui_type;
443441
int whichfork;
444442
int error = 0;
@@ -456,16 +454,19 @@ xfs_bui_item_recover(
456454
XFS_FSB_TO_DADDR(mp, bmap->me_startblock));
457455
inode_fsb = XFS_BB_TO_FSB(mp, XFS_FSB_TO_DADDR(mp,
458456
XFS_INO_TO_FSB(mp, bmap->me_owner)));
459-
switch (bmap->me_flags & XFS_BMAP_EXTENT_TYPE_MASK) {
457+
state = (bmap->me_flags & XFS_BMAP_EXTENT_UNWRITTEN) ?
458+
XFS_EXT_UNWRITTEN : XFS_EXT_NORM;
459+
whichfork = (bmap->me_flags & XFS_BMAP_EXTENT_ATTR_FORK) ?
460+
XFS_ATTR_FORK : XFS_DATA_FORK;
461+
bui_type = bmap->me_flags & XFS_BMAP_EXTENT_TYPE_MASK;
462+
switch (bui_type) {
460463
case XFS_BMAP_MAP:
461464
case XFS_BMAP_UNMAP:
462-
op_ok = true;
463465
break;
464466
default:
465-
op_ok = false;
466-
break;
467+
return -EFSCORRUPTED;
467468
}
468-
if (!op_ok || startblock_fsb == 0 ||
469+
if (startblock_fsb == 0 ||
469470
bmap->me_len == 0 ||
470471
inode_fsb == 0 ||
471472
startblock_fsb >= mp->m_sb.sb_dblocks ||
@@ -493,32 +494,17 @@ xfs_bui_item_recover(
493494
if (VFS_I(ip)->i_nlink == 0)
494495
xfs_iflags_set(ip, XFS_IRECOVERY);
495496

496-
/* Process deferred bmap item. */
497-
state = (bmap->me_flags & XFS_BMAP_EXTENT_UNWRITTEN) ?
498-
XFS_EXT_UNWRITTEN : XFS_EXT_NORM;
499-
whichfork = (bmap->me_flags & XFS_BMAP_EXTENT_ATTR_FORK) ?
500-
XFS_ATTR_FORK : XFS_DATA_FORK;
501-
bui_type = bmap->me_flags & XFS_BMAP_EXTENT_TYPE_MASK;
502-
switch (bui_type) {
503-
case XFS_BMAP_MAP:
504-
case XFS_BMAP_UNMAP:
505-
type = bui_type;
506-
break;
507-
default:
508-
XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, mp);
509-
error = -EFSCORRUPTED;
510-
goto err_inode;
511-
}
512497
xfs_trans_ijoin(tp, ip, 0);
513498

514499
count = bmap->me_len;
515-
error = xfs_trans_log_finish_bmap_update(tp, budp, type, ip, whichfork,
516-
bmap->me_startoff, bmap->me_startblock, &count, state);
500+
error = xfs_trans_log_finish_bmap_update(tp, budp, bui_type, ip,
501+
whichfork, bmap->me_startoff, bmap->me_startblock,
502+
&count, state);
517503
if (error)
518504
goto err_inode;
519505

520506
if (count > 0) {
521-
ASSERT(type == XFS_BMAP_UNMAP);
507+
ASSERT(bui_type == XFS_BMAP_UNMAP);
522508
irec.br_startblock = bmap->me_startblock;
523509
irec.br_blockcount = count;
524510
irec.br_startoff = bmap->me_startoff;

0 commit comments

Comments
 (0)