xfs: check return codes when flushing block devices
PATCH 1/1 xfs: check return codes when flushing block devices
From: Darrick J. Wong <[email protected]>
If a block device cache flush fails, fsync needs to report that to upper levels. If the log can't flush the data device, we should shut it down immediately because we've just violated an invariant. Hence, check the return value of blkdev_issue_flush.
--- fs/xfs/xfs_file.c | 15 ++++++++++----- fs/xfs/xfs_log.c | 7 +++++-- 2 files changed, 15 insertions(+), 7 deletions(-)
fs/xfs/xfs_file.c +10 -5
@@ -163,9 +163,11 @@ xfs_file_fsync(* inode size in case of an extending write. */ if (XFS_IS_REALTIME_INODE (ip)) -blkdev_issue_flush (mp->m_rtdev_targp->bt_bdev); + error =blkdev_issue_flush (mp->m_rtdev_targp->bt_bdev);else if (mp->m_logdev_targp != mp->m_ddev_targp) -blkdev_issue_flush (mp->m_ddev_targp->bt_bdev); + error =blkdev_issue_flush (mp->m_ddev_targp->bt_bdev); +if (error) +return error;/* * Any inode that has dirty modifications in the log is pinned. The
@@ -173,8 +175,11 @@ xfs_file_fsync(* that happen concurrently to the fsync call, but fsync semantics * only require to sync previously completed I/O. */ -if (xfs_ipincount (ip)) +if (xfs_ipincount (ip)) { error =xfs_fsync_flush_log (ip, datasync, &log_flushed); +if (error) +return error; + }/* * If we only have a single device, and the log force about was
@@ -185,9 +190,9 @@ xfs_file_fsync(*/ if (!log_flushed && !XFS_IS_REALTIME_INODE (ip) && mp->m_logdev_targp == mp->m_ddev_targp) -blkdev_issue_flush (mp->m_ddev_targp->bt_bdev); +return blkdev_issue_flush (mp->m_ddev_targp->bt_bdev); -return error; +return 0 ; } static int
fs/xfs/xfs_log.c +5 -2
@@ -1926,8 +1926,11 @@ xlog_write_iclog(* by the LSN in this iclog is on stable storage. This is slow, * but it *must* complete before we issue the external log IO. */ -if (log->l_targ != log->l_mp->m_ddev_targp) -blkdev_issue_flush (log->l_mp->m_ddev_targp->bt_bdev); +if (log->l_targ != log->l_mp->m_ddev_targp && +blkdev_issue_flush (log->l_mp->m_ddev_targp->bt_bdev)) { +xlog_force_shutdown (log,SHUTDOWN_LOG_IO_ERROR ); +return ; + } }if (iclog->ic_flags &XLOG_ICL_NEED_FUA ) iclog->ic_bio.bi_opf |=REQ_FUA ;
Quoted 32 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
If a block device cache flush fails, fsync needs to report that to upper levels. If the log can't flush the data device, we should shut it down immediately because we've just violated an invariant. Hence, check the return value of
blkdev_issue_flush.Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/xfs_file.c | 15 ++++++++++----- fs/xfs/xfs_log.c | 7 +++++-- 2 files changed, 15 insertions(+), 7 deletions(-)fs/xfs/xfs_file.c +4
-2@@ -163,9 +163,11 @@ xfs_file_fsync(* inode size in case of an extending write. */ if (XFS_IS_REALTIME_INODE (ip)) -blkdev_issue_flush (mp->m_rtdev_targp->bt_bdev); + error =blkdev_issue_flush (mp->m_rtdev_targp->bt_bdev);else if (mp->m_logdev_targp != mp->m_ddev_targp) -blkdev_issue_flush (mp->m_ddev_targp->bt_bdev); + error =blkdev_issue_flush (mp->m_ddev_targp->bt_bdev); +if (error) +return error;/* * Any inode that has dirty modifications in the log is pinned. The
fs/xfs/xfs_file.c xfs_file_fsync( · line 182
Quoted 9 lines
fs/xfs/xfs_file.c +4
-1@@ -173,8 +175,11 @@ xfs_file_fsync(* that happen concurrently to the fsync call, but fsync semantics * only require to sync previously completed I/O. */ -if (xfs_ipincount (ip)) +if (xfs_ipincount (ip)) { error =xfs_fsync_flush_log (ip, datasync, &log_flushed); +if (error) +return error; + }
Shouldn't we still try to flush the data device if necessary, even if the log flush failed?
Quoted 19 lines
fs/xfs/xfs_file.c +2
-2/* * If we only have a single device, and the log force about was @@ -185,9 +190,9 @@ xfs_file_fsync(*/ if (!log_flushed && !XFS_IS_REALTIME_INODE (ip) && mp->m_logdev_targp == mp->m_ddev_targp) -blkdev_issue_flush (mp->m_ddev_targp->bt_bdev); +return blkdev_issue_flush (mp->m_ddev_targp->bt_bdev); -return error; +return 0 ; } static intfs/xfs/xfs_log.c +0
-0
fs/xfs/xfs_log.c xlog_write_iclog( · line 1933
Quoted 10 lines
fs/xfs/xfs_log.c +5
-2@@ -1926,8 +1926,11 @@ xlog_write_iclog(* by the LSN in this iclog is on stable storage. This is slow, * but it *must* complete before we issue the external log IO. */ -if (log->l_targ != log->l_mp->m_ddev_targp) -blkdev_issue_flush (log->l_mp->m_ddev_targp->bt_bdev); +if (log->l_targ != log->l_mp->m_ddev_targp && +blkdev_issue_flush (log->l_mp->m_ddev_targp->bt_bdev)) { +xlog_force_shutdown (log,SHUTDOWN_LOG_IO_ERROR ); +return ; + }
That seems pretty drastic, though I'm not sure what else apart from ignoring the data device flush error can be done here. Also, it's not actually a log IO error - it's a data device IO error so it's a really a metadata writeback problem. Hence the use of SHUTDOWN_LOG_IO_ERROR probably needs a comment to explain why it needs to be used here...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 30 lines · Dave Chinner
Quoted 29 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
If a block device cache flush fails, fsync needs to report that to upper levels. If the log can't flush the data device, we should shut it down immediately because we've just violated an invariant. Hence, check the return value of
blkdev_issue_flush.Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/xfs_file.c | 15 ++++++++++----- fs/xfs/xfs_log.c | 7 +++++-- 2 files changed, 15 insertions(+), 7 deletions(-)fs/xfs/xfs_file.c +4
-2@@ -163,9 +163,11 @@ xfs_file_fsync(* inode size in case of an extending write. */ if (XFS_IS_REALTIME_INODE (ip)) -blkdev_issue_flush (mp->m_rtdev_targp->bt_bdev); + error =blkdev_issue_flush (mp->m_rtdev_targp->bt_bdev);else if (mp->m_logdev_targp != mp->m_ddev_targp) -blkdev_issue_flush (mp->m_ddev_targp->bt_bdev); + error =blkdev_issue_flush (mp->m_ddev_targp->bt_bdev); +if (error) +return error;
Quoted 15 lines
fs/xfs/xfs_file.c xfs_file_fsync( · line 182
Quoted 12 lines
fs/xfs/xfs_file.c +4
-1/* * Any inode that has dirty modifications in the log is pinned. The @@ -173,8 +175,11 @@ xfs_file_fsync(* that happen concurrently to the fsync call, but fsync semantics * only require to sync previously completed I/O. */ -if (xfs_ipincount (ip)) +if (xfs_ipincount (ip)) { error =xfs_fsync_flush_log (ip, datasync, &log_flushed); +if (error) +return error; + }Shouldn't we still try to flush the data device if necessary, even if the log flush failed?
Hm. I can see two points of view here -- if the system is falling down around us, just stop before we make anything worse. The other POV is that we should push as much as we can towards the storage in the hope a reboot and recovery will fix everything. And hope that the log flush doesn't do anything out of order.
So, should xfs_file_fsync return the first error but try all the calls?
Quoted 28 lines
Quoted 28 lines
fs/xfs/xfs_file.c +2
-2/* * If we only have a single device, and the log force about was @@ -185,9 +190,9 @@ xfs_file_fsync(*/ if (!log_flushed && !XFS_IS_REALTIME_INODE (ip) && mp->m_logdev_targp == mp->m_ddev_targp) -blkdev_issue_flush (mp->m_ddev_targp->bt_bdev); +return blkdev_issue_flush (mp->m_ddev_targp->bt_bdev); -return error; +return 0 ; } static intfs/xfs/xfs_log.c +4
-2@@ -1926,8 +1926,11 @@ xlog_write_iclog(* by the LSN in this iclog is on stable storage. This is slow, * but it *must* complete before we issue the external log IO. */ -if (log->l_targ != log->l_mp->m_ddev_targp) -blkdev_issue_flush (log->l_mp->m_ddev_targp->bt_bdev); +if (log->l_targ != log->l_mp->m_ddev_targp && +blkdev_issue_flush (log->l_mp->m_ddev_targp->bt_bdev)) { +xlog_force_shutdown (log,SHUTDOWN_LOG_IO_ERROR ); +return ;
Quoted 8 lines
fs/xfs/xfs_log.c xlog_write_iclog( · line 1933
Quoted 1 line
fs/xfs/xfs_log.c +1
-0+ }That seems pretty drastic, though I'm not sure what else apart from ignoring the data device flush error can be done here. Also, it's not actually a log IO error - it's a data device IO error so it's a really a metadata writeback problem. Hence the use of
SHUTDOWN_LOG_IO_ERRORprobably needs a comment to explain why it needs to be used here...
My first thought was to do that, but my second thought is -- can we do whatever the AIL does when writes back to the filesystem fail? I /think/ it retries writes, correct? I suppose this could retry the flush until it succeeds or we hit an impatience threshold.
(Alternately, define a new SHUTDOWN_LOG_* code that will print a slightly different message, on the grounds that few people have external log devices anyway.)
--D
Quoted 6 lines
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 5 lines · Dave Chinner
Quoted 5 lines
fs/xfs/xfs_file.c +0
-1@@ -173,8 +175,11 @@ xfs_file_fsync(* that happen concurrently to the fsync call, but fsync semantics * only require to sync previously completed I/O. */ -if (xfs_ipincount (ip))
Quoted 8 lines
fs/xfs/xfs_file.c xfs_file_fsync( · line 182
Quoted 5 lines
fs/xfs/xfs_file.c +4
-0+if (xfs_ipincount (ip)) { error =xfs_fsync_flush_log (ip, datasync, &log_flushed); +if (error) +return error; + }Shouldn't we still try to flush the data device if necessary, even if the log flush failed?
xfs_fsync_flush_log ails only if the log it shut down. Does it really make sense to flush the data cache for a pure overwrite of a data block when the fs is toast? I can't really see any benefit in that.
Quoted 4 lines
Quoted 4 lines
fs/xfs/xfs_log.c +4
-0+if (log->l_targ != log->l_mp->m_ddev_targp && +blkdev_issue_flush (log->l_mp->m_ddev_targp->bt_bdev)) { +xlog_force_shutdown (log,SHUTDOWN_LOG_IO_ERROR ); +return ;
Quoted 8 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ }That seems pretty drastic, though I'm not sure what else apart from ignoring the data device flush error can be done here. Also, it's not actually a log IO error - it's a data device IO error so it's a really a metadata writeback problem. Hence the use of
SHUTDOWN_LOG_IO_ERRORprobably needs a comment to explain why it needs to be used here...
Yes, the comment would be useful. But if a cache flush fails data integrity of the device must at this point be considered as fucked up beyond belief, so shutting down the log and thus the file system is the right thing to do.
So modulo a comment here the patch looks good to me.
Quoted 15 lines · Christoph Hellwig
Quoted 5 lines · Dave Chinner
Quoted 5 lines
fs/xfs/xfs_file.c +0
-1@@ -173,8 +175,11 @@ xfs_file_fsync(* that happen concurrently to the fsync call, but fsync semantics * only require to sync previously completed I/O. */ -if (xfs_ipincount (ip))Quoted 8 lines
fs/xfs/xfs_file.c xfs_file_fsync( · line 182
Quoted 5 lines
fs/xfs/xfs_file.c +4
-0+if (xfs_ipincount (ip)) { error =xfs_fsync_flush_log (ip, datasync, &log_flushed); +if (error) +return error; + }Shouldn't we still try to flush the data device if necessary, even if the log flush failed?
Quoted 3 lines
xfs_fsync_flush_logails only if the log it shut down. Does it really make sense to flush the data cache for a pure overwrite of a data block when the fs is toast? I can't really see any benefit in that.
/me guesses that once we hit the first error, the rest of the calls will probably crash and burn, and if they don't, the next fs call will, so it likely doesn't matter if we keep going or not.
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
fs/xfs/xfs_log.c +4
-0+if (log->l_targ != log->l_mp->m_ddev_targp && +blkdev_issue_flush (log->l_mp->m_ddev_targp->bt_bdev)) { +xlog_force_shutdown (log,SHUTDOWN_LOG_IO_ERROR ); +return ;Quoted 8 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ }That seems pretty drastic, though I'm not sure what else apart from ignoring the data device flush error can be done here. Also, it's not actually a log IO error - it's a data device IO error so it's a really a metadata writeback problem. Hence the use of
SHUTDOWN_LOG_IO_ERRORprobably needs a comment to explain why it needs to be used here...
Quoted 6 lines
Yes, the comment would be useful. But if a cache flush fails data integrity of the device must at this point be considered as fucked up beyond belief, so shutting down the log and thus the file system is the right thing to do.
So modulo a comment here the patch looks good to me.
Ok, will do.
--D