xfs: handle dquot buffer readahead in log recovery correctly
PATCH 1/1 xfs: handle dquot buffer readahead in log recovery correctly
From: Dave Chinner <[email protected]>
When we do dquot readahead in log recovery, we do not use a verifier as the underlying buffer may not have dquots in it. e.g. the allocation operation hasn't yet been replayed. Hence we do not want to fail recovery because we detect an operation to be replayed has not been run yet. This problem was addressed for inodes in commit d891400 ("xfs: inode buffers may not be valid during recovery readahead") but the problem was not recognised to exist for dquots and their buffers as the dquot readahead did not have a verifier.
The result of not using a verifier is that when the buffer is then next read to replay a dquot modification, the dquot buffer verifier will only be attached to the buffer if *readahead is not complete*. Hence we can read the buffer, replay the dquot changes and then add it to the delwri submission list without it having a verifier attached to it. This then generates warnings in xfs_buf_ioapply(), which catches and warns about this case.
Fix this and make it handle the same readahead verifier error cases as for inode buffers by adding a new readahead verifier that has a write operation as well as a read operation that marks the buffer as not done if any corruption is detected. Also make sure we don't run readahead if the dquot buffer has been marked as cancelled by recovery.
This will result in readahead either succeeding and the buffer having a valid write verifier, or readahead failing and the buffer state requiring the subsequent read to resubmit the IO with the new verifier. In either case, this will result in the buffer always ending up with a valid write verifier on it.
--- fs/xfs/libxfs/xfs_dquot_buf.c | 32 ++++++++++++++++++++++++++------ fs/xfs/libxfs/xfs_quota_defs.h | 2 +- fs/xfs/libxfs/xfs_shared.h | 1 + fs/xfs/xfs_log_recover.c | 9 +++++++-- 4 files changed, 35 insertions(+), 9 deletions(-)
fs/xfs/libxfs/xfs_dquot_buf.c +26 -6
@@ -54,7 +54,7 @@ xfs_dqcheck(xfs_dqid_t id, uint type, /* used only when IO_dorepair is true */ uint flags, - char *str) + const char *str) { xfs_dqblk_t *d = (xfs_dqblk_t *)ddq;int errs =0 ;
@@ -207,7 +207,8 @@ xfs_dquot_buf_verify_crc( STATIC boolxfs_dquot_buf_verify (struct xfs_mount *mp, -struct xfs_buf *bp) +struct xfs_buf *bp, +int warn) {struct xfs_dqblk *d = (struct xfs_dqblk *)bp->b_addr;xfs_dqid_t id =0 ;
@@ -240,8 +241,7 @@ xfs_dquot_buf_verify(if (i ==0 ) id =be32_to_cpu (ddq->d_id); - error =xfs_dqcheck (mp, ddq, id + i,0 ,XFS_QMOPT_DOWARN , -"xfs_dquot_buf_verify" ); + error =xfs_dqcheck (mp, ddq, id + i,0 , warn, __func__);if (error)return false; }
@@ -256,7 +256,7 @@ xfs_dquot_buf_read_verify(if (!xfs_dquot_buf_verify_crc (mp, bp))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (!xfs_dquot_buf_verify (mp, bp)) +else if (!xfs_dquot_buf_verify (mp, bp,XFS_QMOPT_DOWARN ))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error)
@@ -264,6 +264,21 @@ xfs_dquot_buf_read_verify( }/* +* readahead errors are silent and simply leave the buffer as !done so +* a real read will then be run with the xfs_dquot_buf_ops verifier. +*/ +static void +xfs_dquot_buf_readahead_verify ( +struct xfs_buf *bp) +{ +struct xfs_mount *mp = bp->b_target->bt_mount; + +if (!xfs_dquot_buf_verify_crc (mp, bp) && + !xfs_dquot_buf_verify (mp, bp,0 )) + bp->b_flags &= ~XBF_DONE ; +} + +/* * we don't calculate the CRC here as that is done when the dquot is flushed to * the buffer after the update is done. This ensures that the dquot in the * buffer always has an up-to-date CRC value.
@@ -274,7 +289,7 @@ xfs_dquot_buf_write_verify( {struct xfs_mount *mp = bp->b_target->bt_mount; -if (!xfs_dquot_buf_verify (mp, bp)) { +if (!xfs_dquot_buf_verify (mp, bp,XFS_QMOPT_DOWARN )) {xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);return ;
@@ -287,3 +302,8 @@ const struct xfs_buf_ops xfs_dquot_buf_ops = { .verify_write = xfs_dquot_buf_write_verify, }; +const struct xfs_buf_ops xfs_dquot_buf_ra_ops = { + .name ="xfs_dquot_ra" , + .verify_read = xfs_dquot_buf_readahead_verify, + .verify_write = xfs_dquot_buf_write_verify, +};
fs/xfs/libxfs/xfs_quota_defs.h +1 -1
@@ -153,7 +153,7 @@ typedef __uint16_t xfs_qwarncnt_t;#define XFS_QMOPT_RESBLK_MASK (XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_RES_RTBLKS)extern int xfs_dqcheck (struct xfs_mount *mp,xfs_disk_dquot_t *ddq, -xfs_dqid_t id,uint type,uint flags,char *str); +xfs_dqid_t id,uint type,uint flags,const char *str);extern int xfs_calc_dquots_per_chunk (unsigned int nbblks);#endif /* __XFS_QUOTA_H__ */
fs/xfs/libxfs/xfs_shared.h +1 -0
@@ -49,6 +49,7 @@ extern const struct xfs_buf_ops xfs_inobt_buf_ops;extern const struct xfs_buf_ops xfs_inode_buf_ops;extern const struct xfs_buf_ops xfs_inode_buf_ra_ops;extern const struct xfs_buf_ops xfs_dquot_buf_ops; +extern const struct xfs_buf_ops xfs_dquot_buf_ra_ops;extern const struct xfs_buf_ops xfs_sb_buf_ops;extern const struct xfs_buf_ops xfs_sb_quiet_buf_ops;extern const struct xfs_buf_ops xfs_symlink_buf_ops;
fs/xfs/xfs_log_recover.c +7 -2
@@ -3521,6 +3521,7 @@ xlog_recover_dquot_ra_pass2(struct xfs_disk_dquot *recddq;struct xfs_dq_logformat *dq_f;uint type; +int len;if (mp->m_qflags ==0 )
@@ -3541,8 +3542,12 @@ xlog_recover_dquot_ra_pass2(ASSERT (dq_f);ASSERT (dq_f->qlf_len ==1 ); -xfs_buf_readahead (mp->m_ddev_targp, dq_f->qlf_blkno, -XFS_FSB_TO_BB (mp, dq_f->qlf_len),NULL ); + len =XFS_FSB_TO_BB (mp, dq_f->qlf_len); +if (xlog_peek_buffer_cancelled (log, dq_f->qlf_blkno, len,0 )) +return ; + +xfs_buf_readahead (mp->m_ddev_targp, dq_f->qlf_blkno, len, + &xfs_dquot_buf_ra_ops); }STATIC void
Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Quoted 44 lines · Dave Chinner
From: Dave Chinner <[email protected]>
When we do dquot readahead in log recovery, we do not use a verifier as the underlying buffer may not have dquots in it. e.g. the allocation operation hasn't yet been replayed. Hence we do not want to fail recovery because we detect an operation to be replayed has not been run yet. This problem was addressed for inodes in commit d891400 ("xfs: inode buffers may not be valid during recovery readahead") but the problem was not recognised to exist for dquots and their buffers as the dquot readahead did not have a verifier.
The result of not using a verifier is that when the buffer is then next read to replay a dquot modification, the dquot buffer verifier will only be attached to the buffer if *readahead is not complete*. Hence we can read the buffer, replay the dquot changes and then add it to the delwri submission list without it having a verifier attached to it. This then generates warnings in
xfs_buf_ioapply(), which catches and warns about this case.Fix this and make it handle the same readahead verifier error cases as for inode buffers by adding a new readahead verifier that has a write operation as well as a read operation that marks the buffer as not done if any corruption is detected. Also make sure we don't run readahead if the dquot buffer has been marked as cancelled by recovery.
This will result in readahead either succeeding and the buffer having a valid write verifier, or readahead failing and the buffer state requiring the subsequent read to resubmit the IO with the new verifier. In either case, this will result in the buffer always ending up with a valid write verifier on it.
Signed-off-by Dave Chinner <[email protected]>--- fs/xfs/libxfs/xfs_dquot_buf.c | 32 ++++++++++++++++++++++++++------ fs/xfs/libxfs/xfs_quota_defs.h | 2 +- fs/xfs/libxfs/xfs_shared.h | 1 + fs/xfs/xfs_log_recover.c | 9 +++++++-- 4 files changed, 35 insertions(+), 9 deletions(-)fs/xfs/libxfs/xfs_dquot_buf.c +0
-0
...
Quoted 6 lines
fs/xfs/libxfs/xfs_dquot_buf.c +2
-0@@ -264,6 +264,21 @@ xfs_dquot_buf_read_verify( }/* +* readahead errors are silent and simply leave the buffer as !done so +* a real read will then be run with the xfs_dquot_buf_ops verifier.
fs/xfs/libxfs/xfs_dquot_buf.c xfs_dquot_buf_read_verify( · line 278
Quoted 10 lines
fs/xfs/libxfs/xfs_dquot_buf.c +10
-0+*/ +static void +xfs_dquot_buf_readahead_verify ( +struct xfs_buf *bp) +{ +struct xfs_mount *mp = bp->b_target->bt_mount; + +if (!xfs_dquot_buf_verify_crc (mp, bp) && + !xfs_dquot_buf_verify (mp, bp,0 )) + bp->b_flags &= ~XBF_DONE ;
Shouldn't this condition trigger if either the crc or buffer verification fails (not if both fail)?
Also, xfs_buf_ioend() sets XBF_DONE when bp->b_error == 0 after the read verifier is invoked. I don't see bp->b_error being set here, so it looks like clearing this flag wouldn't have any effect.
Brian
Quoted 83 lines
fs/xfs/libxfs/xfs_dquot_buf.c +9
-1+} + +/* * we don't calculate the CRC here as that is done when the dquot is flushed to * the buffer after the update is done. This ensures that the dquot in the * buffer always has an up-to-date CRC value. @@ -274,7 +289,7 @@ xfs_dquot_buf_write_verify( {struct xfs_mount *mp = bp->b_target->bt_mount; -if (!xfs_dquot_buf_verify (mp, bp)) { +if (!xfs_dquot_buf_verify (mp, bp,XFS_QMOPT_DOWARN )) {xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);return ;@@ -287,3 +302,8 @@ const struct xfs_buf_ops xfs_dquot_buf_ops = { .verify_write = xfs_dquot_buf_write_verify, }; +const struct xfs_buf_ops xfs_dquot_buf_ra_ops = { + .name ="xfs_dquot_ra" , + .verify_read = xfs_dquot_buf_readahead_verify, + .verify_write = xfs_dquot_buf_write_verify, +};fs/xfs/libxfs/xfs_quota_defs.h +1
-1@@ -153,7 +153,7 @@ typedef __uint16_t xfs_qwarncnt_t;#define XFS_QMOPT_RESBLK_MASK (XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_RES_RTBLKS)extern int xfs_dqcheck (struct xfs_mount *mp,xfs_disk_dquot_t *ddq, -xfs_dqid_t id,uint type,uint flags,char *str); +xfs_dqid_t id,uint type,uint flags,const char *str);extern int xfs_calc_dquots_per_chunk (unsigned int nbblks);#endif /* __XFS_QUOTA_H__ */ fs/xfs/libxfs/xfs_shared.h +1
-0@@ -49,6 +49,7 @@ extern const struct xfs_buf_ops xfs_inobt_buf_ops;extern const struct xfs_buf_ops xfs_inode_buf_ops;extern const struct xfs_buf_ops xfs_inode_buf_ra_ops;extern const struct xfs_buf_ops xfs_dquot_buf_ops; +extern const struct xfs_buf_ops xfs_dquot_buf_ra_ops;extern const struct xfs_buf_ops xfs_sb_buf_ops;extern const struct xfs_buf_ops xfs_sb_quiet_buf_ops;extern const struct xfs_buf_ops xfs_symlink_buf_ops;fs/xfs/xfs_log_recover.c +7
-2@@ -3521,6 +3521,7 @@ xlog_recover_dquot_ra_pass2(struct xfs_disk_dquot *recddq;struct xfs_dq_logformat *dq_f;uint type; +int len;if (mp->m_qflags ==0 )@@ -3541,8 +3542,12 @@ xlog_recover_dquot_ra_pass2(ASSERT (dq_f);ASSERT (dq_f->qlf_len ==1 ); -xfs_buf_readahead (mp->m_ddev_targp, dq_f->qlf_blkno, -XFS_FSB_TO_BB (mp, dq_f->qlf_len),NULL ); + len =XFS_FSB_TO_BB (mp, dq_f->qlf_len); +if (xlog_peek_buffer_cancelled (log, dq_f->qlf_blkno, len,0 )) +return ; + +xfs_buf_readahead (mp->m_ddev_targp, dq_f->qlf_blkno, len, + &xfs_dquot_buf_ra_ops); }STATIC voidSignature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 26 lines · Dave Chinner
From: Dave Chinner <[email protected]>
When we do dquot readahead in log recovery, we do not use a verifier as the underlying buffer may not have dquots in it. e.g. the allocation operation hasn't yet been replayed. Hence we do not want to fail recovery because we detect an operation to be replayed has not been run yet. This problem was addressed for inodes in commit d891400 ("xfs: inode buffers may not be valid during recovery readahead") but the problem was not recognised to exist for dquots and their buffers as the dquot readahead did not have a verifier.
The result of not using a verifier is that when the buffer is then next read to replay a dquot modification, the dquot buffer verifier will only be attached to the buffer if *readahead is not complete*. Hence we can read the buffer, replay the dquot changes and then add it to the delwri submission list without it having a verifier attached to it. This then generates warnings in
xfs_buf_ioapply(), which catches and warns about this case.Fix this and make it handle the same readahead verifier error cases as for inode buffers by adding a new readahead verifier that has a write operation as well as a read operation that marks the buffer as not done if any corruption is detected. Also make sure we don't run readahead if the dquot buffer has been marked as cancelled by recovery.
Quoted 5 lines
This will result in readahead either succeeding and the buffer having a valid write verifier, or readahead failing and the buffer state requiring the subsequent read to resubmit the IO with the new verifier. In either case, this will result in the buffer always ending up with a valid write verifier on it.
Checked this patch on 4.1.15.
When the issue occured I started seeing thousands of "_xfs_buf_ioapply: no ops on block ..." entries in logs.
With this patch these are all gone.
Signature · 6 lines
Arkadiusz Miśkiewicz, arekm / ( maven.pl | pld-linux.org ) _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Quoted 4 lines · Brian Foster
Quoted 3 lines · Dave Chinner
(quoted diff) +0
-0@@ -264,6 +264,21 @@ xfs_dquot_buf_read_verify( }
Quoted 16 lines
fs/xfs/libxfs/xfs_dquot_buf.c xfs_dquot_buf_read_verify( · line 278
Quoted 13 lines
fs/xfs/libxfs/xfs_dquot_buf.c +12
-0/* +* readahead errors are silent and simply leave the buffer as !done so +* a real read will then be run with the xfs_dquot_buf_ops verifier. +*/ +static void +xfs_dquot_buf_readahead_verify ( +struct xfs_buf *bp) +{ +struct xfs_mount *mp = bp->b_target->bt_mount; + +if (!xfs_dquot_buf_verify_crc (mp, bp) && + !xfs_dquot_buf_verify (mp, bp,0 )) + bp->b_flags &= ~XBF_DONE ;Shouldn't this condition trigger if either the crc or buffer verification fails (not if both fail)?
Yup, got my logic tangled there.
Quoted 3 lines
Also,
xfs_buf_ioend()setsXBF_DONEwhenbp->b_error== 0 after the read verifier is invoked. I don't seebp->b_errorbeing set here, so it looks like clearing this flag wouldn't have any effect.
Hmmm - I just copied that from the inode readahead verifier. So that's not working properly, either. I'll fix that, too.
Thanks, Brian.
Cheers,
Dave.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v2 1/1 xfs: handle dquot buffer readahead in log recovery correctly
In reply to Dave ChinnerFrom: Dave Chinner <[email protected]>
When we do dquot readahead in log recovery, we do not use a verifier as the underlying buffer may not have dquots in it. e.g. the allocation operation hasn't yet been replayed. Hence we do not want to fail recovery because we detect an operation to be replayed has not been run yet. This problem was addressed for inodes in commit d891400 ("xfs: inode buffers may not be valid during recovery readahead") but the problem was not recognised to exist for dquots and their buffers as the dquot readahead did not have a verifier.
The result of not using a verifier is that when the buffer is then next read to replay a dquot modification, the dquot buffer verifier will only be attached to the buffer if *readahead is not complete*. Hence we can read the buffer, replay the dquot changes and then add it to the delwri submission list without it having a verifier attached to it. This then generates warnings in xfs_buf_ioapply(), which catches and warns about this case.
Fix this and make it handle the same readahead verifier error cases as for inode buffers by adding a new readahead verifier that has a write operation as well as a read operation that marks the buffer as not done if any corruption is detected. Also make sure we don't run readahead if the dquot buffer has been marked as cancelled by recovery.
This will result in readahead either succeeding and the buffer having a valid write verifier, or readahead failing and the buffer state requiring the subsequent read to resubmit the IO with the new verifier. In either case, this will result in the buffer always ending up with a valid write verifier on it.
Note: we also need to fix the inode buffer readahead error handling to mark the buffer with EIO. Brian noticed the code I copied from there wrong during review, so fix it at the same time. Add comments linking the two functions that handle readahead verifier errors together so we don't forget this behavioural link in future.
---
Version 2
- fix logic error in determining if verify failed
- set error on buffer when verifier fails
- fix inode buffer readahead verifier to set error when it fails
- better comments, link dquot and inode buffer ra verifiers in the comments
fs/xfs/libxfs/xfs_dquot_buf.c | 36 ++++++++++++++++++++++++++++++------ fs/xfs/libxfs/xfs_inode_buf.c | 14 +++++++++----- fs/xfs/libxfs/xfs_quota_defs.h | 2 +- fs/xfs/libxfs/xfs_shared.h | 1 + fs/xfs/xfs_log_recover.c | 9 +++++++-- 5 files changed, 48 insertions(+), 14 deletions(-)
fs/xfs/libxfs/xfs_dquot_buf.c +30 -6
@@ -54,7 +54,7 @@ xfs_dqcheck(xfs_dqid_t id, uint type, /* used only when IO_dorepair is true */ uint flags, - char *str) + const char *str) { xfs_dqblk_t *d = (xfs_dqblk_t *)ddq;int errs =0 ;
@@ -207,7 +207,8 @@ xfs_dquot_buf_verify_crc( STATIC boolxfs_dquot_buf_verify (struct xfs_mount *mp, -struct xfs_buf *bp) +struct xfs_buf *bp, +int warn) {struct xfs_dqblk *d = (struct xfs_dqblk *)bp->b_addr;xfs_dqid_t id =0 ;
@@ -240,8 +241,7 @@ xfs_dquot_buf_verify(if (i ==0 ) id =be32_to_cpu (ddq->d_id); - error =xfs_dqcheck (mp, ddq, id + i,0 ,XFS_QMOPT_DOWARN , -"xfs_dquot_buf_verify" ); + error =xfs_dqcheck (mp, ddq, id + i,0 , warn, __func__);if (error)return false; }
@@ -256,7 +256,7 @@ xfs_dquot_buf_read_verify(if (!xfs_dquot_buf_verify_crc (mp, bp))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (!xfs_dquot_buf_verify (mp, bp)) +else if (!xfs_dquot_buf_verify (mp, bp,XFS_QMOPT_DOWARN ))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error)
@@ -264,6 +264,25 @@ xfs_dquot_buf_read_verify( }/* +* readahead errors are silent and simply leave the buffer as !done so a real +* read will then be run with the xfs_dquot_buf_ops verifier. See +* xfs_inode_buf_verify() for why we use EIO and ~XBF_DONE here rather than +* reporting the failure. +*/ +static void +xfs_dquot_buf_readahead_verify ( +struct xfs_buf *bp) +{ +struct xfs_mount *mp = bp->b_target->bt_mount; + +if (!xfs_dquot_buf_verify_crc (mp, bp) || + !xfs_dquot_buf_verify (mp, bp,0 )) { +xfs_buf_ioerror (bp, -EIO ); + bp->b_flags &= ~XBF_DONE ; + } +} + +/* * we don't calculate the CRC here as that is done when the dquot is flushed to * the buffer after the update is done. This ensures that the dquot in the * buffer always has an up-to-date CRC value.
@@ -274,7 +293,7 @@ xfs_dquot_buf_write_verify( {struct xfs_mount *mp = bp->b_target->bt_mount; -if (!xfs_dquot_buf_verify (mp, bp)) { +if (!xfs_dquot_buf_verify (mp, bp,XFS_QMOPT_DOWARN )) {xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);return ;
@@ -287,3 +306,8 @@ const struct xfs_buf_ops xfs_dquot_buf_ops = { .verify_write = xfs_dquot_buf_write_verify, }; +const struct xfs_buf_ops xfs_dquot_buf_ra_ops = { + .name ="xfs_dquot_ra" , + .verify_read = xfs_dquot_buf_readahead_verify, + .verify_write = xfs_dquot_buf_write_verify, +};
fs/xfs/libxfs/xfs_inode_buf.c +9 -5
@@ -62,11 +62,14 @@ xfs_inobp_check(* has not had the inode cores stamped into it. Hence for readahead, the buffer * may be potentially invalid. * -* If the readahead buffer is invalid, we don't want to mark it with an error, -* but we do want to clear the DONE status of the buffer so that a followup read -* will re-read it from disk. This will ensure that we don't get an unnecessary -* warnings during log recovery and we don't get unnecssary panics on debug -* kernels. +* If the readahead buffer is invalid, we need to mark it with an error and +* clear the DONE status of the buffer so that a followup read will re-read it +* from disk. We don't report the error otherwise to avoid warnings during log +* recovery and we don't get unnecssary panics on debug kernels. We use EIO here +* because all we want to do is say readahead failed; there is no-one to report +* the error to, so this will distinguish it from a non-ra verifier failure. +* Changes to this readahead error behavour also need to be reflected in +* xfs_dquot_buf_readahead_verify(). */ static void xfs_inode_buf_verify(
@@ -92,6 +95,7 @@ xfs_inode_buf_verify( XFS_ERRTAG_ITOBP_INOTOBP, XFS_RANDOM_ITOBP_INOTOBP))) {if (readahead) { +xfs_buf_ioerror (bp, -EIO ); bp->b_flags &= ~XBF_DONE ;return ; }
fs/xfs/libxfs/xfs_quota_defs.h +1 -1
@@ -153,7 +153,7 @@ typedef __uint16_t xfs_qwarncnt_t;#define XFS_QMOPT_RESBLK_MASK (XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_RES_RTBLKS)extern int xfs_dqcheck (struct xfs_mount *mp,xfs_disk_dquot_t *ddq, -xfs_dqid_t id,uint type,uint flags,char *str); +xfs_dqid_t id,uint type,uint flags,const char *str);extern int xfs_calc_dquots_per_chunk (unsigned int nbblks);#endif /* __XFS_QUOTA_H__ */
fs/xfs/libxfs/xfs_shared.h +1 -0
@@ -49,6 +49,7 @@ extern const struct xfs_buf_ops xfs_inobt_buf_ops;extern const struct xfs_buf_ops xfs_inode_buf_ops;extern const struct xfs_buf_ops xfs_inode_buf_ra_ops;extern const struct xfs_buf_ops xfs_dquot_buf_ops; +extern const struct xfs_buf_ops xfs_dquot_buf_ra_ops;extern const struct xfs_buf_ops xfs_sb_buf_ops;extern const struct xfs_buf_ops xfs_sb_quiet_buf_ops;extern const struct xfs_buf_ops xfs_symlink_buf_ops;
fs/xfs/xfs_log_recover.c +7 -2
@@ -3521,6 +3521,7 @@ xlog_recover_dquot_ra_pass2(struct xfs_disk_dquot *recddq;struct xfs_dq_logformat *dq_f;uint type; +int len;if (mp->m_qflags ==0 )
@@ -3541,8 +3542,12 @@ xlog_recover_dquot_ra_pass2(ASSERT (dq_f);ASSERT (dq_f->qlf_len ==1 ); -xfs_buf_readahead (mp->m_ddev_targp, dq_f->qlf_blkno, -XFS_FSB_TO_BB (mp, dq_f->qlf_len),NULL ); + len =XFS_FSB_TO_BB (mp, dq_f->qlf_len); +if (xlog_peek_buffer_cancelled (log, dq_f->qlf_blkno, len,0 )) +return ; + +xfs_buf_readahead (mp->m_ddev_targp, dq_f->qlf_blkno, len, + &xfs_dquot_buf_ra_ops); }STATIC void
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 61 lines · Dave Chinner
From: Dave Chinner <[email protected]>
When we do dquot readahead in log recovery, we do not use a verifier as the underlying buffer may not have dquots in it. e.g. the allocation operation hasn't yet been replayed. Hence we do not want to fail recovery because we detect an operation to be replayed has not been run yet. This problem was addressed for inodes in commit d891400 ("xfs: inode buffers may not be valid during recovery readahead") but the problem was not recognised to exist for dquots and their buffers as the dquot readahead did not have a verifier.
The result of not using a verifier is that when the buffer is then next read to replay a dquot modification, the dquot buffer verifier will only be attached to the buffer if *readahead is not complete*. Hence we can read the buffer, replay the dquot changes and then add it to the delwri submission list without it having a verifier attached to it. This then generates warnings in
xfs_buf_ioapply(), which catches and warns about this case.Fix this and make it handle the same readahead verifier error cases as for inode buffers by adding a new readahead verifier that has a write operation as well as a read operation that marks the buffer as not done if any corruption is detected. Also make sure we don't run readahead if the dquot buffer has been marked as cancelled by recovery.
This will result in readahead either succeeding and the buffer having a valid write verifier, or readahead failing and the buffer state requiring the subsequent read to resubmit the IO with the new verifier. In either case, this will result in the buffer always ending up with a valid write verifier on it.
Note: we also need to fix the inode buffer readahead error handling to mark the buffer with EIO. Brian noticed the code I copied from there wrong during review, so fix it at the same time. Add comments linking the two functions that handle readahead verifier errors together so we don't forget this behavioural link in future.
cc <[email protected]> # 3.12 - currentSigned-off-by Dave Chinner <[email protected]>---
Version 2
- fix logic error in determining if verify failed
- set error on buffer when verifier fails
- fix inode buffer readahead verifier to set error when it fails
- better comments, link dquot and inode buffer ra verifiers in the commentsfs/xfs/libxfs/xfs_dquot_buf.c | 36 ++++++++++++++++++++++++++++++------ fs/xfs/libxfs/xfs_inode_buf.c | 14 +++++++++----- fs/xfs/libxfs/xfs_quota_defs.h | 2 +- fs/xfs/libxfs/xfs_shared.h | 1 + fs/xfs/xfs_log_recover.c | 9 +++++++-- 5 files changed, 48 insertions(+), 14 deletions(-)fs/xfs/libxfs/xfs_dquot_buf.c +0
-0
...
Quoted 9 lines
fs/xfs/libxfs/xfs_dquot_buf.c +5
-0@@ -264,6 +264,25 @@ xfs_dquot_buf_read_verify( }/* +* readahead errors are silent and simply leave the buffer as !done so a real +* read will then be run with the xfs_dquot_buf_ops verifier. See +* xfs_inode_buf_verify() for why we use EIO and ~XBF_DONE here rather than +* reporting the failure. +*/
fs/xfs/libxfs/xfs_dquot_buf.c xfs_dquot_buf_read_verify( · line 281
Quoted 10 lines
fs/xfs/libxfs/xfs_dquot_buf.c +10
-0+static void +xfs_dquot_buf_readahead_verify ( +struct xfs_buf *bp) +{ +struct xfs_mount *mp = bp->b_target->bt_mount; + +if (!xfs_dquot_buf_verify_crc (mp, bp) || + !xfs_dquot_buf_verify (mp, bp,0 )) { +xfs_buf_ioerror (bp, -EIO ); + bp->b_flags &= ~XBF_DONE ;
Do we really need to clear the flag if the I/O infrastructure doesn't set it until after the verifier is invoked? It's harmless, so if the intent is to just be cautious or future-proof:
... but it does look slightly confusing, without a mention in the comments at least.
Brian
Quoted 110 lines
fs/xfs/libxfs/xfs_dquot_buf.c +10
-1+ } +} + +/* * we don't calculate the CRC here as that is done when the dquot is flushed to * the buffer after the update is done. This ensures that the dquot in the * buffer always has an up-to-date CRC value. @@ -274,7 +293,7 @@ xfs_dquot_buf_write_verify( {struct xfs_mount *mp = bp->b_target->bt_mount; -if (!xfs_dquot_buf_verify (mp, bp)) { +if (!xfs_dquot_buf_verify (mp, bp,XFS_QMOPT_DOWARN )) {xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);return ;@@ -287,3 +306,8 @@ const struct xfs_buf_ops xfs_dquot_buf_ops = { .verify_write = xfs_dquot_buf_write_verify, }; +const struct xfs_buf_ops xfs_dquot_buf_ra_ops = { + .name ="xfs_dquot_ra" , + .verify_read = xfs_dquot_buf_readahead_verify, + .verify_write = xfs_dquot_buf_write_verify, +};fs/xfs/libxfs/xfs_inode_buf.c +9
-5@@ -62,11 +62,14 @@ xfs_inobp_check(* has not had the inode cores stamped into it. Hence for readahead, the buffer * may be potentially invalid. * -* If the readahead buffer is invalid, we don't want to mark it with an error, -* but we do want to clear the DONE status of the buffer so that a followup read -* will re-read it from disk. This will ensure that we don't get an unnecessary -* warnings during log recovery and we don't get unnecssary panics on debug -* kernels. +* If the readahead buffer is invalid, we need to mark it with an error and +* clear the DONE status of the buffer so that a followup read will re-read it +* from disk. We don't report the error otherwise to avoid warnings during log +* recovery and we don't get unnecssary panics on debug kernels. We use EIO here +* because all we want to do is say readahead failed; there is no-one to report +* the error to, so this will distinguish it from a non-ra verifier failure. +* Changes to this readahead error behavour also need to be reflected in +* xfs_dquot_buf_readahead_verify(). */ static void xfs_inode_buf_verify(@@ -92,6 +95,7 @@ xfs_inode_buf_verify( XFS_ERRTAG_ITOBP_INOTOBP, XFS_RANDOM_ITOBP_INOTOBP))) {if (readahead) { +xfs_buf_ioerror (bp, -EIO ); bp->b_flags &= ~XBF_DONE ;return ; }fs/xfs/libxfs/xfs_quota_defs.h +1
-1@@ -153,7 +153,7 @@ typedef __uint16_t xfs_qwarncnt_t;#define XFS_QMOPT_RESBLK_MASK (XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_RES_RTBLKS)extern int xfs_dqcheck (struct xfs_mount *mp,xfs_disk_dquot_t *ddq, -xfs_dqid_t id,uint type,uint flags,char *str); +xfs_dqid_t id,uint type,uint flags,const char *str);extern int xfs_calc_dquots_per_chunk (unsigned int nbblks);#endif /* __XFS_QUOTA_H__ */ fs/xfs/libxfs/xfs_shared.h +1
-0@@ -49,6 +49,7 @@ extern const struct xfs_buf_ops xfs_inobt_buf_ops;extern const struct xfs_buf_ops xfs_inode_buf_ops;extern const struct xfs_buf_ops xfs_inode_buf_ra_ops;extern const struct xfs_buf_ops xfs_dquot_buf_ops; +extern const struct xfs_buf_ops xfs_dquot_buf_ra_ops;extern const struct xfs_buf_ops xfs_sb_buf_ops;extern const struct xfs_buf_ops xfs_sb_quiet_buf_ops;extern const struct xfs_buf_ops xfs_symlink_buf_ops;fs/xfs/xfs_log_recover.c +7
-2@@ -3521,6 +3521,7 @@ xlog_recover_dquot_ra_pass2(struct xfs_disk_dquot *recddq;struct xfs_dq_logformat *dq_f;uint type; +int len;if (mp->m_qflags ==0 )@@ -3541,8 +3542,12 @@ xlog_recover_dquot_ra_pass2(ASSERT (dq_f);ASSERT (dq_f->qlf_len ==1 ); -xfs_buf_readahead (mp->m_ddev_targp, dq_f->qlf_blkno, -XFS_FSB_TO_BB (mp, dq_f->qlf_len),NULL ); + len =XFS_FSB_TO_BB (mp, dq_f->qlf_len); +if (xlog_peek_buffer_cancelled (log, dq_f->qlf_blkno, len,0 )) +return ; + +xfs_buf_readahead (mp->m_ddev_targp, dq_f->qlf_blkno, len, + &xfs_dquot_buf_ra_ops); }STATIC void
Quoted 4 lines
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
[slightly hacked up quoting order so it makes sense]
Quoted 5 lines · Brian Foster
Quoted 4 lines · Dave Chinner
From: Dave Chinner <[email protected]>
When we do dquot readahead in log recovery, we do not use a verifier
......
Quoted 2 lines
Quoted 2 lines
write operation as well as a read operation that marks the buffer as not done if any corruption is detected. Also make sure we don't run
Marking the buffer not done mentioned here...
.....
Quoted 6 lines
Quoted 6 lines
/*
+ * readahead errors are silent and simply leave the buffer as !done so a real
+ * read will then be run with thexfs_dquot_buf_opsverifier. See
+ *xfs_inode_buf_verify()for why we use EIO and ~XBF_DONE here rather than
+ * reporting the failure.
... and here ...
Quoted 4 lines
Quoted 4 lines
fs/xfs/libxfs/xfs_inode_buf.c +0
-0@@ -62,11 +62,14 @@ xfs_inobp_check(* has not had the inode cores stamped into it. Hence for readahead, the buffer * may be potentially invalid. *
Quoted 8 lines
fs/xfs/libxfs/xfs_inode_buf.c xfs_inobp_check( · line 67
Quoted 8 lines
fs/xfs/libxfs/xfs_inode_buf.c +3
-5-* If the readahead buffer is invalid, we don't want to mark it with an error, -* but we do want to clear the DONE status of the buffer so that a followup read -* will re-read it from disk. This will ensure that we don't get an unnecessary -* warnings during log recovery and we don't get unnecssary panics on debug -* kernels. +* If the readahead buffer is invalid, we need to mark it with an error and +* clear the DONE status of the buffer so that a followup read will re-read it +* from disk. We don't report the error otherwise to avoid warnings during log
... and here ...
Quoted 4 lines
Do we really need to clear the flag if the I/O infrastructure doesn't set it until after the verifier is invoked? It's harmless, [...] ... but it does look slightly confusing, without a mention in the comments at least.
I mentioned it 3 times. ;)
Is there something I can do to make it more obvious what the comments are referring to?
Quoted 7 lines
Quoted 7 lines
fs/xfs/libxfs/xfs_dquot_buf.c +7
-0+*/ +static void +xfs_dquot_buf_readahead_verify ( +struct xfs_buf *bp) +{ +struct xfs_mount *mp = bp->b_target->bt_mount; +
Quoted 8 lines
fs/xfs/libxfs/xfs_dquot_buf.c xfs_dquot_buf_read_verify( · line 281
Quoted 4 lines
fs/xfs/libxfs/xfs_dquot_buf.c +4
-0+if (!xfs_dquot_buf_verify_crc (mp, bp) || + !xfs_dquot_buf_verify (mp, bp,0 )) { +xfs_buf_ioerror (bp, -EIO ); + bp->b_flags &= ~XBF_DONE ;Do we really need to clear the flag if the I/O infrastructure doesn't set it until after the verifier is invoked? It's harmless, so if the intent is to just be cautious or future-proof:
It's intended to cover the case that a verifier is run on a buffer that has already been read in successfully. This doesn't occur in the kernel code, but it most definitely does in the userspace code. Strictly speaking it's not necessary (at the moment) for the userspace code as it ignores the kernel buffer flags, but I figured it's better to leave it there for documentation of expected behaviour and to ensure we don't leave a landmine if we ever run a readahead verifier on a buffer that is already marked as done...
Quoted 1 line
Reviewed-by Brian Foster <[email protected]>
Thanks!
Cheers,
Dave.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Quoted 44 lines · Dave Chinner
[slightly hacked up quoting order so it makes sense]
Quoted 5 lines · Brian Foster
Quoted 4 lines · Dave Chinner
From: Dave Chinner <[email protected]>
When we do dquot readahead in log recovery, we do not use a verifier
......
Quoted 2 lines
Quoted 2 lines
write operation as well as a read operation that marks the buffer as not done if any corruption is detected. Also make sure we don't run
Marking the buffer not done mentioned here...
.....
Quoted 6 lines
Quoted 6 lines
/*
+ * readahead errors are silent and simply leave the buffer as !done so a real
+ * read will then be run with thexfs_dquot_buf_opsverifier. See
+ *xfs_inode_buf_verify()for why we use EIO and ~XBF_DONE here rather than
+ * reporting the failure.... and here ...
Quoted 4 lines
Quoted 4 lines
fs/xfs/libxfs/xfs_inode_buf.c +0
-0@@ -62,11 +62,14 @@ xfs_inobp_check(* has not had the inode cores stamped into it. Hence for readahead, the buffer * may be potentially invalid. * Quoted 8 lines
fs/xfs/libxfs/xfs_inode_buf.c xfs_inobp_check( · line 67
Quoted 8 lines
fs/xfs/libxfs/xfs_inode_buf.c +3
-5-* If the readahead buffer is invalid, we don't want to mark it with an error, -* but we do want to clear the DONE status of the buffer so that a followup read -* will re-read it from disk. This will ensure that we don't get an unnecessary -* warnings during log recovery and we don't get unnecssary panics on debug -* kernels. +* If the readahead buffer is invalid, we need to mark it with an error and +* clear the DONE status of the buffer so that a followup read will re-read it +* from disk. We don't report the error otherwise to avoid warnings during log ... and here ...
Quoted 4 lines
Do we really need to clear the flag if the I/O infrastructure doesn't set it until after the verifier is invoked? It's harmless, [...] ... but it does look slightly confusing, without a mention in the comments at least.
Quoted 5 lines
I mentioned it 3 times. ;)
Is there something I can do to make it more obvious what the comments are referring to?
It's obvious from the code alone that the verifier marks the buffer not done. ;) I'm not not sure how that relates to my question... which is why does the verifier clear the flag before we've reached the point where the flag would ever be set (when setting the error state is sufficient)?
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
fs/xfs/libxfs/xfs_dquot_buf.c +7
-0+*/ +static void +xfs_dquot_buf_readahead_verify ( +struct xfs_buf *bp) +{ +struct xfs_mount *mp = bp->b_target->bt_mount; +Quoted 8 lines
fs/xfs/libxfs/xfs_dquot_buf.c xfs_dquot_buf_read_verify( · line 281
Quoted 4 lines
fs/xfs/libxfs/xfs_dquot_buf.c +4
-0+if (!xfs_dquot_buf_verify_crc (mp, bp) || + !xfs_dquot_buf_verify (mp, bp,0 )) { +xfs_buf_ioerror (bp, -EIO ); + bp->b_flags &= ~XBF_DONE ;Do we really need to clear the flag if the I/O infrastructure doesn't set it until after the verifier is invoked? It's harmless, so if the intent is to just be cautious or future-proof:
Quoted 9 lines
It's intended to cover the case that a verifier is run on a buffer that has already been read in successfully. This doesn't occur in the kernel code, but it most definitely does in the userspace code. Strictly speaking it's not necessary (at the moment) for the userspace code as it ignores the kernel buffer flags, but I figured it's better to leave it there for documentation of expected behaviour and to ensure we don't leave a landmine if we ever run a readahead verifier on a buffer that is already marked as done...
Ok, that's kind of what I figured modulo the userspace case. Sounds reasonable enough, thanks.
Brian
Quoted 15 lines
Quoted 1 line
Reviewed-by Brian Foster <[email protected]>Thanks!
Cheers,
Dave.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs