xfs: simplify xfs_zero_remaining_bytes
xfs_zero_remaining_bytes() open codes a log of buffer manupulations to do a read forllowed by a write. It can simply be replaced by an uncached read followed by a xfs_bwrite() call. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Dave Chinner <david@fromorbit.com>
This commit is contained in:
parent
ba3726742c
commit
8c15612546
|
@ -1122,14 +1122,6 @@ xfs_zero_remaining_bytes(
|
||||||
if (endoff > XFS_ISIZE(ip))
|
if (endoff > XFS_ISIZE(ip))
|
||||||
endoff = XFS_ISIZE(ip);
|
endoff = XFS_ISIZE(ip);
|
||||||
|
|
||||||
bp = xfs_buf_get_uncached(XFS_IS_REALTIME_INODE(ip) ?
|
|
||||||
mp->m_rtdev_targp : mp->m_ddev_targp,
|
|
||||||
BTOBB(mp->m_sb.sb_blocksize), 0);
|
|
||||||
if (!bp)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
xfs_buf_unlock(bp);
|
|
||||||
|
|
||||||
for (offset = startoff; offset <= endoff; offset = lastoffset + 1) {
|
for (offset = startoff; offset <= endoff; offset = lastoffset + 1) {
|
||||||
uint lock_mode;
|
uint lock_mode;
|
||||||
|
|
||||||
|
@ -1152,32 +1144,24 @@ xfs_zero_remaining_bytes(
|
||||||
ASSERT(imap.br_startblock != DELAYSTARTBLOCK);
|
ASSERT(imap.br_startblock != DELAYSTARTBLOCK);
|
||||||
if (imap.br_state == XFS_EXT_UNWRITTEN)
|
if (imap.br_state == XFS_EXT_UNWRITTEN)
|
||||||
continue;
|
continue;
|
||||||
XFS_BUF_UNDONE(bp);
|
|
||||||
XFS_BUF_UNWRITE(bp);
|
|
||||||
XFS_BUF_READ(bp);
|
|
||||||
XFS_BUF_SET_ADDR(bp, xfs_fsb_to_db(ip, imap.br_startblock));
|
|
||||||
|
|
||||||
error = xfs_buf_submit_wait(bp);
|
error = xfs_buf_read_uncached(XFS_IS_REALTIME_INODE(ip) ?
|
||||||
if (error) {
|
mp->m_rtdev_targp : mp->m_ddev_targp,
|
||||||
xfs_buf_ioerror_alert(bp,
|
xfs_fsb_to_db(ip, imap.br_startblock),
|
||||||
"xfs_zero_remaining_bytes(read)");
|
BTOBB(mp->m_sb.sb_blocksize),
|
||||||
break;
|
0, &bp, NULL);
|
||||||
}
|
if (error)
|
||||||
|
return error;
|
||||||
|
|
||||||
memset(bp->b_addr +
|
memset(bp->b_addr +
|
||||||
(offset - XFS_FSB_TO_B(mp, imap.br_startoff)),
|
(offset - XFS_FSB_TO_B(mp, imap.br_startoff)),
|
||||||
0, lastoffset - offset + 1);
|
0, lastoffset - offset + 1);
|
||||||
XFS_BUF_UNDONE(bp);
|
|
||||||
XFS_BUF_UNREAD(bp);
|
|
||||||
XFS_BUF_WRITE(bp);
|
|
||||||
|
|
||||||
error = xfs_buf_submit_wait(bp);
|
error = xfs_bwrite(bp);
|
||||||
if (error) {
|
xfs_buf_relse(bp);
|
||||||
xfs_buf_ioerror_alert(bp,
|
if (error)
|
||||||
"xfs_zero_remaining_bytes(write)");
|
return error;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
xfs_buf_free(bp);
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue