Return-Path: From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Carlos Maiolino , "Darrick J . Wong" , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 089/100] xfs: Properly retry failed dquot items in case of error during buffer writeback Date: Wed, 24 Jan 2018 04:15:11 +0000 Message-ID: <20180124041414.32065-89-alexander.levin@microsoft.com> References: <20180124041414.32065-1-alexander.levin@microsoft.com> In-Reply-To: <20180124041414.32065-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: From: Carlos Maiolino [ Upstream commit 373b0589dc8d58bc09c9a28d03611ae4fb216057 ] Once the inode item writeback errors is already fixed, it's time to fix the= same problem in dquot code. Although there were no reports of users hitting this bug in dquot code (at = least none I've seen), the bug is there and I was already planning to fix it when= the correct approach to fix the inodes part was decided. This patch aims to fix the same problem in dquot code, regarding failed buf= fers being unable to be resubmitted once they are flush locked. Tested with the recently test-case sent to fstests list by Hou Tao. Reviewed-by: Brian Foster Signed-off-by: Carlos Maiolino Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Sasha Levin --- fs/xfs/xfs_dquot.c | 14 +++++++++++--- fs/xfs/xfs_dquot_item.c | 40 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/fs/xfs/xfs_dquot.c b/fs/xfs/xfs_dquot.c index cd82429d8df7..5a86495127fd 100644 --- a/fs/xfs/xfs_dquot.c +++ b/fs/xfs/xfs_dquot.c @@ -987,14 +987,22 @@ xfs_qm_dqflush_done( * holding the lock before removing the dquot from the AIL. */ if ((lip->li_flags & XFS_LI_IN_AIL) && - lip->li_lsn =3D=3D qip->qli_flush_lsn) { + ((lip->li_lsn =3D=3D qip->qli_flush_lsn) || + (lip->li_flags & XFS_LI_FAILED))) { =20 /* xfs_trans_ail_delete() drops the AIL lock. */ spin_lock(&ailp->xa_lock); - if (lip->li_lsn =3D=3D qip->qli_flush_lsn) + if (lip->li_lsn =3D=3D qip->qli_flush_lsn) { xfs_trans_ail_delete(ailp, lip, SHUTDOWN_CORRUPT_INCORE); - else + } else { + /* + * Clear the failed state since we are about to drop the + * flush lock + */ + if (lip->li_flags & XFS_LI_FAILED) + xfs_clear_li_failed(lip); spin_unlock(&ailp->xa_lock); + } } =20 /* diff --git a/fs/xfs/xfs_dquot_item.c b/fs/xfs/xfs_dquot_item.c index 2c7a1629e064..664dea105e76 100644 --- a/fs/xfs/xfs_dquot_item.c +++ b/fs/xfs/xfs_dquot_item.c @@ -137,6 +137,26 @@ xfs_qm_dqunpin_wait( wait_event(dqp->q_pinwait, (atomic_read(&dqp->q_pincount) =3D=3D 0)); } =20 +/* + * Callback used to mark a buffer with XFS_LI_FAILED when items in the buf= fer + * have been failed during writeback + * + * this informs the AIL that the dquot is already flush locked on the next= push, + * and acquires a hold on the buffer to ensure that it isn't reclaimed bef= ore + * dirty data makes it to disk. + */ +STATIC void +xfs_dquot_item_error( + struct xfs_log_item *lip, + struct xfs_buf *bp) +{ + struct xfs_dquot *dqp; + + dqp =3D DQUOT_ITEM(lip)->qli_dquot; + ASSERT(!completion_done(&dqp->q_flush)); + xfs_set_li_failed(lip, bp); +} + STATIC uint xfs_qm_dquot_logitem_push( struct xfs_log_item *lip, @@ -144,13 +164,28 @@ xfs_qm_dquot_logitem_push( __acquires(&lip->li_ailp->xa_lock) { struct xfs_dquot *dqp =3D DQUOT_ITEM(lip)->qli_dquot; - struct xfs_buf *bp =3D NULL; + struct xfs_buf *bp =3D lip->li_buf; uint rval =3D XFS_ITEM_SUCCESS; int error; =20 if (atomic_read(&dqp->q_pincount) > 0) return XFS_ITEM_PINNED; =20 + /* + * The buffer containing this item failed to be written back + * previously. Resubmit the buffer for IO + */ + if (lip->li_flags & XFS_LI_FAILED) { + if (!xfs_buf_trylock(bp)) + return XFS_ITEM_LOCKED; + + if (!xfs_buf_resubmit_failed_buffers(bp, lip, buffer_list)) + rval =3D XFS_ITEM_FLUSHING; + + xfs_buf_unlock(bp); + return rval; + } + if (!xfs_dqlock_nowait(dqp)) return XFS_ITEM_LOCKED; =20 @@ -242,7 +277,8 @@ static const struct xfs_item_ops xfs_dquot_item_ops =3D= { .iop_unlock =3D xfs_qm_dquot_logitem_unlock, .iop_committed =3D xfs_qm_dquot_logitem_committed, .iop_push =3D xfs_qm_dquot_logitem_push, - .iop_committing =3D xfs_qm_dquot_logitem_committing + .iop_committing =3D xfs_qm_dquot_logitem_committing, + .iop_error =3D xfs_dquot_item_error }; =20 /* --=20 2.11.0