tidy up the buffer cache implementation v3
Hi all,
this series ties up some old and new bits in the XFS buffer cache, and consolidates a fair amount of code.
Changes since v1:
- don't pass buf ops to _xfs_buf_read
- add two more cleanup patches
Changes since v1:
- fix read flag propagation in _xfs_buf_read
- improve a few commit messages and comments
Diffstat:
libxfs/xfs_log_recover.h | 1 libxfs/xfs_sb.c | 4 libxfs/xfs_trans_inode.c | 6 - xfs_buf.c | 208 +++++++++++++++++++++++++++++++------ xfs_buf.h | 17 --- xfs_buf_item.c | 264 +---------------------------------------------- xfs_buf_item.h | 12 ++ xfs_buf_item_recover.c | 2 xfs_dquot.c | 14 ++ xfs_inode.c | 6 - xfs_inode_item.c | 12 +- xfs_inode_item.h | 1 xfs_log_recover.c | 58 ++-------- xfs_mount.c | 17 --- xfs_mount.h | 1 xfs_quota.h | 8 - xfs_trace.h | 2 xfs_trans.c | 2 xfs_trans.h | 2 xfs_trans_buf.c | 46 ++------ 20 files changed, 261 insertions(+), 422 deletions(-)
PATCH 1/15 xfs: refactor the buf ioend disposition code
Handle the no-error case in xfs_buf_iodone_error as well, and to clarify the code rename the function, use the actual enum type as return value and then switch on it in the callers.
--- fs/xfs/xfs_buf_item.c | 115 +++++++++++++++++++++++------------------- 1 file changed, 62 insertions(+), 53 deletions(-)
fs/xfs/xfs_buf_item.c +62 -53
@@ -1045,24 +1045,27 @@ xfs_buf_ioerror_permanent(* * Multi-state return value: * -* XBF_IOERROR_FINISH: clear IO error retry state and run callback completions -* XBF_IOERROR_DONE: resubmitted immediately, do not run any completions -* XBF_IOERROR_FAIL: transient error, run failure callback completions and then +* XBF_IOEND_FINISH: run callback completions +* XBF_IOEND_DONE: resubmitted immediately, do not run any completions +* XBF_IOEND_FAIL: transient error, run failure callback completions and then * release the buffer */ -enum { -XBF_IOERROR_FINISH , -XBF_IOERROR_DONE , -XBF_IOERROR_FAIL , +enum xfs_buf_ioend_disposition { +XBF_IOEND_FINISH , +XBF_IOEND_DONE , +XBF_IOEND_FAIL , }; -static int -xfs_buf_iodone_error ( +static enum xfs_buf_ioend_disposition +xfs_buf_ioend_disposition (struct xfs_buf *bp) {struct xfs_mount *mp = bp->b_mount;struct xfs_error_cfg *cfg; +if (likely (!bp->b_error)) +return XBF_IOEND_FINISH ; +if (xfs_buf_ioerror_fail_without_retry (bp)) goto out_stale;
@@ -1072,7 +1075,7 @@ xfs_buf_iodone_error(if (xfs_buf_ioerror_retry (bp, cfg)) {xfs_buf_ioerror (bp,0 );xfs_buf_submit (bp); -return XBF_IOERROR_DONE ; +return XBF_IOEND_DONE ; }/*
@@ -1085,13 +1088,13 @@ xfs_buf_iodone_error( }/* Still considered a transient error. Caller will schedule retries. */ -return XBF_IOERROR_FAIL ; +return XBF_IOEND_FAIL ; out_stale:xfs_buf_stale (bp); bp->b_flags |=XBF_DONE ;trace_xfs_buf_error_relse (bp, _RET_IP_); -return XBF_IOERROR_FINISH ; +return XBF_IOEND_FINISH ; } static void
@@ -1127,6 +1130,19 @@ xfs_buf_clear_ioerror_retry_state( bp->b_first_retry_time =0 ; } +static void +xfs_buf_inode_io_fail ( +struct xfs_buf *bp) +{ +struct xfs_log_item *lip; + +list_for_each_entry (lip, &bp->b_li_list, li_bio_list) +set_bit (XFS_LI_FAILED , &lip->li_flags); + +xfs_buf_ioerror (bp,0 ); +xfs_buf_relse (bp); +} +/* * Inode buffer iodone callback function. */
@@ -1134,30 +1150,36 @@ voidxfs_buf_inode_iodone ( struct xfs_buf *bp) { -if (bp->b_error) { -struct xfs_log_item *lip; -int ret =xfs_buf_iodone_error (bp); - -if (ret ==XBF_IOERROR_FINISH ) - goto finish_iodone; -if (ret ==XBF_IOERROR_DONE ) -return ; -ASSERT (ret ==XBF_IOERROR_FAIL ); -list_for_each_entry (lip, &bp->b_li_list, li_bio_list) { -set_bit (XFS_LI_FAILED , &lip->li_flags); - } -xfs_buf_ioerror (bp,0 ); -xfs_buf_relse (bp); +switch (xfs_buf_ioend_disposition (bp)) { +case XBF_IOEND_DONE : +return ; +case XBF_IOEND_FAIL : +xfs_buf_inode_io_fail (bp);return ; +default : +break ; } -finish_iodone:xfs_buf_clear_ioerror_retry_state (bp);xfs_buf_item_done (bp);xfs_iflush_done (bp);xfs_buf_ioend_finish (bp); } +static void +xfs_buf_dquot_io_fail ( +struct xfs_buf *bp) +{ +struct xfs_log_item *lip; + +spin_lock (&bp->b_mount->m_ail->ail_lock); +list_for_each_entry (lip, &bp->b_li_list, li_bio_list) +xfs_set_li_failed (lip, bp); +spin_unlock (&bp->b_mount->m_ail->ail_lock); +xfs_buf_ioerror (bp,0 ); +xfs_buf_relse (bp); +} +/* * Dquot buffer iodone callback function. */
@@ -1165,26 +1187,16 @@ voidxfs_buf_dquot_iodone ( struct xfs_buf *bp) { -if (bp->b_error) { -struct xfs_log_item *lip; -int ret =xfs_buf_iodone_error (bp); - -if (ret ==XBF_IOERROR_FINISH ) - goto finish_iodone; -if (ret ==XBF_IOERROR_DONE ) -return ; -ASSERT (ret ==XBF_IOERROR_FAIL ); -spin_lock (&bp->b_mount->m_ail->ail_lock); -list_for_each_entry (lip, &bp->b_li_list, li_bio_list) { -xfs_set_li_failed (lip, bp); - } -spin_unlock (&bp->b_mount->m_ail->ail_lock); -xfs_buf_ioerror (bp,0 ); -xfs_buf_relse (bp); +switch (xfs_buf_ioend_disposition (bp)) { +case XBF_IOEND_DONE : +return ; +case XBF_IOEND_FAIL : +xfs_buf_dquot_io_fail (bp);return ; +default : +break ; } -finish_iodone:xfs_buf_clear_ioerror_retry_state (bp);/* a newly allocated dquot buffer might have a log item attached */ xfs_buf_item_done (bp);
@@ -1202,21 +1214,18 @@ voidxfs_buf_iodone ( struct xfs_buf *bp) { -if (bp->b_error) { -int ret =xfs_buf_iodone_error (bp); - -if (ret ==XBF_IOERROR_FINISH ) - goto finish_iodone; -if (ret ==XBF_IOERROR_DONE ) -return ; -ASSERT (ret ==XBF_IOERROR_FAIL ); +switch (xfs_buf_ioend_disposition (bp)) { +case XBF_IOEND_DONE : +return ; +case XBF_IOEND_FAIL :ASSERT (list_empty (&bp->b_li_list));xfs_buf_ioerror (bp,0 );xfs_buf_relse (bp);return ; +default : +break ; } -finish_iodone:xfs_buf_clear_ioerror_retry_state (bp);xfs_buf_item_done (bp);xfs_buf_ioend_finish (bp);
Signature · 1 line
2.28.0
PATCH 2/15 xfs: mark xfs_buf_ioend static
In reply to Christoph Hellwig--- fs/xfs/xfs_buf.c | 2 +- fs/xfs/xfs_buf.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-)
fs/xfs/xfs_buf.c +1 -1
@@ -1174,7 +1174,7 @@ xfs_buf_wait_unpin(* Buffer Utility Routines */ -void +static void xfs_buf_ioend (struct xfs_buf *bp) {
fs/xfs/xfs_buf.h +0 -1
@@ -269,7 +269,6 @@ static inline void xfs_buf_relse(xfs_buf_t *bp)/* Buffer Read and Write Routines */ extern int xfs_bwrite (struct xfs_buf *bp); -extern void xfs_buf_ioend (struct xfs_buf *bp);static inline void xfs_buf_ioend_finish (struct xfs_buf *bp) {if (bp->b_flags &XBF_ASYNC )
Signature · 1 line
2.28.0
PATCH 3/15 xfs: refactor xfs_buf_ioend
In reply to Christoph HellwigMove the log recovery I/O completion handling entirely into the log recovery code, and re-arrange the normal I/O completion handler flow to prepare to lifting more logic into common code in the next commits.
--- fs/xfs/xfs_buf.c | 41 +++++++++++++++++----------------------- fs/xfs/xfs_log_recover.c | 14 +++++++------- 2 files changed, 24 insertions(+), 31 deletions(-)
fs/xfs/xfs_buf.c +17 -24
@@ -1197,33 +1197,26 @@ xfs_buf_ioend(if (!bp->b_error) bp->b_flags |=XBF_DONE ;xfs_buf_ioend_finish (bp); -return ; - } - -if (!bp->b_error) { - bp->b_flags &= ~XBF_WRITE_FAIL ; - bp->b_flags |=XBF_DONE ; - } - -/* -* If this is a log recovery buffer, we aren't doing transactional IO -* yet so we need to let it handle IO completions. -*/ -if (bp->b_flags & _XBF_LOGRECOVERY) { + }else if (bp->b_flags & _XBF_LOGRECOVERY) { +/* +* If this is a log recovery buffer, we aren't doing +* transactional I/O yet so we need to let the log recovery code +* handle I/O completions: +*/ xlog_recover_iodone (bp); -return ; - } - -if (bp->b_flags & _XBF_INODES) { -xfs_buf_inode_iodone (bp); -return ; - } + }else { +if (!bp->b_error) { + bp->b_flags &= ~XBF_WRITE_FAIL ; + bp->b_flags |=XBF_DONE ; + } -if (bp->b_flags & _XBF_DQUOTS) { -xfs_buf_dquot_iodone (bp); -return ; +if (bp->b_flags & _XBF_INODES) +xfs_buf_inode_iodone (bp); +else if (bp->b_flags & _XBF_DQUOTS) +xfs_buf_dquot_iodone (bp); +else +xfs_buf_iodone (bp); } -xfs_buf_iodone (bp); } static void
fs/xfs/xfs_log_recover.c +7 -7
@@ -269,15 +269,15 @@ voidxlog_recover_iodone ( struct xfs_buf *bp) { -if (bp->b_error) { +if (!bp->b_error) { + bp->b_flags |=XBF_DONE ; + }else if (!XFS_FORCED_SHUTDOWN (bp->b_mount)) {/* -* We're not going to bother about retrying -* this during recovery. One strike! +* We're not going to bother about retrying this during +* recovery. One strike! */ -if (!XFS_FORCED_SHUTDOWN (bp->b_mount)) { -xfs_buf_ioerror_alert (bp, __this_address); -xfs_force_shutdown (bp->b_mount,SHUTDOWN_META_IO_ERROR ); - } +xfs_buf_ioerror_alert (bp, __this_address); +xfs_force_shutdown (bp->b_mount,SHUTDOWN_META_IO_ERROR ); }/*
Signature · 1 line
2.28.0
PATCH 4/15 xfs: move the buffer retry logic to xfs_buf.c
In reply to Christoph HellwigMove the buffer retry state machine logic to xfs_buf.c and call it once from xfs_ioend instead of duplicating it three times for the three kinds of buffers.
--- fs/xfs/libxfs/xfs_trans_inode.c | 6 +- fs/xfs/xfs_buf.c | 173 ++++++++++++++++++++- fs/xfs/xfs_buf_item.c | 260 +------------------------------- fs/xfs/xfs_buf_item.h | 12 ++ fs/xfs/xfs_dquot.c | 14 +- fs/xfs/xfs_inode.c | 6 +- fs/xfs/xfs_inode_item.c | 12 +- fs/xfs/xfs_inode_item.h | 1 - fs/xfs/xfs_quota.h | 8 - fs/xfs/xfs_trace.h | 2 +- 10 files changed, 215 insertions(+), 279 deletions(-)
fs/xfs/libxfs/xfs_trans_inode.c +3 -3
@@ -177,9 +177,9 @@ xfs_trans_log_inode(/* * Always OR in the bits from the ili_last_fields field. This is to -* coordinate with the xfs_iflush() and xfs_iflush_done() routines in -* the eventual clearing of the ili_fields bits. See the big comment in -* xfs_iflush() for an explanation of this coordination mechanism. +* coordinate with the xfs_iflush() and xfs_buf_inode_iodone() routines +* in the eventual clearing of the ili_fields bits. See the big comment +* in xfs_iflush() for an explanation of this coordination mechanism. */ iip->ili_fields |= (flags | iip->ili_last_fields | iversion_flags);spin_unlock (&iip->ili_lock);
fs/xfs/xfs_buf.c +170 -3
190 lines not on this page · raw message
fs/xfs/xfs_buf_item.c +2 -258
286 lines not on this page · raw message
fs/xfs/xfs_buf_item.h +12 -0
@@ -50,12 +50,24 @@ struct xfs_buf_log_item { };int xfs_buf_item_init (struct xfs_buf *,struct xfs_mount *); +void xfs_buf_item_done (struct xfs_buf *bp);void xfs_buf_item_relse (struct xfs_buf *);bool xfs_buf_item_put (struct xfs_buf_log_item *);void xfs_buf_item_log (struct xfs_buf_log_item *,uint ,uint );bool xfs_buf_item_dirty_format (struct xfs_buf_log_item *);void xfs_buf_inode_iodone (struct xfs_buf *); +void xfs_buf_inode_io_fail (struct xfs_buf *bp); +#ifdef CONFIG_XFS_QUOTA void xfs_buf_dquot_iodone (struct xfs_buf *); +void xfs_buf_dquot_io_fail (struct xfs_buf *bp); +#else +static inline void xfs_buf_dquot_iodone (struct xfs_buf *bp) +{ +} +static inline void xfs_buf_dquot_io_fail (struct xfs_buf *bp) +{ +} +#endif /* CONFIG_XFS_QUOTA */ void xfs_buf_iodone (struct xfs_buf *);bool xfs_buf_log_check_iovec (struct xfs_log_iovec *iovec);
fs/xfs/xfs_dquot.c +13 -1
@@ -1107,7 +1107,7 @@ xfs_qm_dqflush_done( }void -xfs_dquot_done ( +xfs_buf_dquot_iodone (struct xfs_buf *bp) {struct xfs_log_item *lip, *n;
@@ -1118,6 +1118,18 @@ xfs_dquot_done( } } +void +xfs_buf_dquot_io_fail ( +struct xfs_buf *bp) +{ +struct xfs_log_item *lip; + +spin_lock (&bp->b_mount->m_ail->ail_lock); +list_for_each_entry (lip, &bp->b_li_list, li_bio_list) +xfs_set_li_failed (lip, bp); +spin_unlock (&bp->b_mount->m_ail->ail_lock); +} +/* Check incore dquot for errors before we flush. */ static xfs_failaddr_t xfs_qm_dqflush_check(
fs/xfs/xfs_inode.c +3 -3
@@ -3553,8 +3553,8 @@ xfs_iflush(* * What we do is move the bits to the ili_last_fields field. When * logging the inode, these bits are moved back to the ili_fields field. -* In the xfs_iflush_done() routine we clear ili_last_fields, since we -* know that the information those bits represent is permanently on +* In the xfs_buf_inode_iodone() routine we clear ili_last_fields, since +* we know that the information those bits represent is permanently on * disk. As long as the flush completes before the inode is logged * again, then both ili_fields and ili_last_fields will be cleared. */
@@ -3568,7 +3568,7 @@ xfs_iflush(/* * Store the current LSN of the inode so that we can tell whether the -* item has moved in the AIL from xfs_iflush_done(). +* item has moved in the AIL from xfs_buf_inode_iodone(). */ xfs_trans_ail_copy_lsn (mp->m_ail, &iip->ili_flush_lsn, &iip->ili_item.li_lsn);
fs/xfs/xfs_inode_item.c +11 -1
@@ -715,7 +715,7 @@ xfs_iflush_finish(* as completing the flush and unlocking the inode. */ void -xfs_iflush_done ( +xfs_buf_inode_iodone (struct xfs_buf *bp) {struct xfs_log_item *lip, *n;
@@ -754,6 +754,16 @@ xfs_iflush_done(list_splice_tail (&flushed_inodes, &bp->b_li_list); } +void +xfs_buf_inode_io_fail ( +struct xfs_buf *bp) +{ +struct xfs_log_item *lip; + +list_for_each_entry (lip, &bp->b_li_list, li_bio_list) +set_bit (XFS_LI_FAILED , &lip->li_flags); +} +/* * This is the inode flushing abort routine. It is called from xfs_iflush when * the filesystem is shutting down to clean up the inode state. It is
fs/xfs/xfs_inode_item.h +0 -1
@@ -43,7 +43,6 @@ static inline int xfs_inode_clean(struct xfs_inode *ip)extern void xfs_inode_item_init (struct xfs_inode *,struct xfs_mount *);extern void xfs_inode_item_destroy (struct xfs_inode *); -extern void xfs_iflush_done (struct xfs_buf *);extern void xfs_iflush_abort (struct xfs_inode *);extern int xfs_inode_item_format_convert (xfs_log_iovec_t *,struct xfs_inode_log_format *);
fs/xfs/xfs_quota.h +0 -8
@@ -108,8 +108,6 @@ extern void xfs_qm_mount_quotas(struct xfs_mount *);extern void xfs_qm_unmount (struct xfs_mount *);extern void xfs_qm_unmount_quotas (struct xfs_mount *); -void xfs_dquot_done (struct xfs_buf *); -#else static inline int xfs_qm_vop_dqalloc(struct xfs_inode *ip, kuid_t kuid, kgid_t kgid,
@@ -151,12 +149,6 @@ static inline int xfs_trans_reserve_quota_bydquots(struct xfs_trans *tp,#define xfs_qm_mount_quotas (mp)#define xfs_qm_unmount (mp)#define xfs_qm_unmount_quotas (mp) - -static inline void xfs_dquot_done (struct xfs_buf *bp) -{ -return ; -} -#endif /* CONFIG_XFS_QUOTA */ #define xfs_trans_unreserve_quota_nblks (tp, ip, nblks, ninos, flags) \
fs/xfs/xfs_trace.h +1 -1
@@ -338,7 +338,7 @@ DEFINE_BUF_EVENT(xfs_buf_delwri_split);DEFINE_BUF_EVENT (xfs_buf_delwri_pushbuf);DEFINE_BUF_EVENT (xfs_buf_get_uncached);DEFINE_BUF_EVENT (xfs_buf_item_relse); -DEFINE_BUF_EVENT (xfs_buf_item_iodone_async); +DEFINE_BUF_EVENT (xfs_buf_iodone_async);DEFINE_BUF_EVENT (xfs_buf_error_relse);DEFINE_BUF_EVENT (xfs_buf_wait_buftarg);DEFINE_BUF_EVENT (xfs_trans_read_buf_shut);
Signature · 1 line
2.28.0
PATCH 5/15 xfs: fold xfs_buf_ioend_finish into xfs_ioend
In reply to Christoph HellwigNo need to keep a separate helper for this logic.
--- fs/xfs/xfs_buf.c | 8 +++++--- fs/xfs/xfs_buf.h | 7 ------- fs/xfs/xfs_log_recover.c | 1 - 3 files changed, 5 insertions(+), 11 deletions(-)
fs/xfs/xfs_buf.c +5 -3
@@ -1333,7 +1333,6 @@ xfs_buf_ioend( bp->b_ops->verify_read (bp);if (!bp->b_error) bp->b_flags |=XBF_DONE ; -xfs_buf_ioend_finish (bp); }else if (bp->b_flags & _XBF_LOGRECOVERY) {/* * If this is a log recovery buffer, we aren't doing
@@ -1381,9 +1380,12 @@ xfs_buf_ioend(xfs_buf_inode_iodone (bp); else if (bp->b_flags & _XBF_DQUOTS) xfs_buf_dquot_iodone(bp); - -xfs_buf_ioend_finish (bp ); } + +if (bp->b_flags &XBF_ASYNC ) +xfs_buf_relse (bp); +else +complete (&bp->b_iowait); } static void
fs/xfs/xfs_buf.h +0 -7
@@ -269,13 +269,6 @@ static inline void xfs_buf_relse(xfs_buf_t *bp)/* Buffer Read and Write Routines */ extern int xfs_bwrite (struct xfs_buf *bp); -static inline void xfs_buf_ioend_finish (struct xfs_buf *bp) -{ -if (bp->b_flags &XBF_ASYNC ) -xfs_buf_relse (bp); -else -complete (&bp->b_iowait); -}extern void __xfs_buf_ioerror (struct xfs_buf *bp,int error,xfs_failaddr_t failaddr);
fs/xfs/xfs_log_recover.c +0 -1
@@ -288,7 +288,6 @@ xlog_recover_iodone(xfs_buf_item_relse (bp);ASSERT (bp->b_log_item ==NULL ); bp->b_flags &= ~_XBF_LOGRECOVERY; -xfs_buf_ioend_finish (bp); }/*
Signature · 1 line
2.28.0
PATCH 6/15 xfs: refactor xfs_buf_ioerror_fail_without_retry
In reply to Christoph Hellwigxfs_buf_ioerror_fail_without_retry is a somewhat weird function in that it has two trivial checks that decide the return value, while the rest implements a ratelimited warning. Just lift the two checks into the caller, and give the remainder a suitable name.
--- fs/xfs/xfs_buf.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-)
fs/xfs/xfs_buf.c +15 -20
@@ -1170,36 +1170,19 @@ xfs_buf_wait_unpin(set_current_state (TASK_RUNNING ); } -/* -* Decide if we're going to retry the write after a failure, and prepare -* the buffer for retrying the write. -*/ -static bool -xfs_buf_ioerror_fail_without_retry ( +static void +xfs_buf_ioerror_alert_ratelimited (struct xfs_buf *bp) { -struct xfs_mount *mp = bp->b_mount;static unsigned long lasttime;static struct xfs_buftarg *lasttarg; -/* -* If we've already decided to shutdown the filesystem because of -* I/O errors, there's no point in giving this a retry. -*/ -if (XFS_FORCED_SHUTDOWN (mp)) -return true; -if (bp->b_target != lasttarg ||time_after (jiffies, (lasttime +5 *HZ ))) { lasttime = jiffies;xfs_buf_ioerror_alert (bp, __this_address); } lasttarg = bp->b_target; - -/* synchronous writes will have callers process the error */ -if (!(bp->b_flags &XBF_ASYNC )) -return true; -return false; } static bool
@@ -1280,7 +1263,19 @@ xfs_buf_ioend_disposition(if (likely (!bp->b_error))return XBF_IOEND_FINISH ; -if (xfs_buf_ioerror_fail_without_retry (bp)) +/* +* If we've already decided to shutdown the filesystem because of I/O +* errors, there's no point in giving this a retry. +*/ +if (XFS_FORCED_SHUTDOWN (mp)) + goto out_stale; + +xfs_buf_ioerror_alert_ratelimited (bp); + +/* +* Synchronous writes will have callers process the error. +*/ +if (!(bp->b_flags &XBF_ASYNC )) goto out_stale;trace_xfs_buf_iodone_async (bp, _RET_IP_);
Signature · 1 line
2.28.0
PATCH 7/15 xfs: remove xfs_buf_ioerror_retry
In reply to Christoph HellwigMerge xfs_buf_ioerror_retry into its only caller to make the resubmission flow a little easier to follow.
--- fs/xfs/xfs_buf.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-)
fs/xfs/xfs_buf.c +12 -21
@@ -1185,23 +1185,6 @@ xfs_buf_ioerror_alert_ratelimited( lasttarg = bp->b_target; } -static bool -xfs_buf_ioerror_retry ( -struct xfs_buf *bp, -struct xfs_error_cfg *cfg) -{ -if ((bp->b_flags & (XBF_STALE |XBF_WRITE_FAIL )) && - bp->b_last_error == bp->b_error) -return false; - - bp->b_flags |= (XBF_WRITE |XBF_DONE |XBF_WRITE_FAIL ); - bp->b_last_error = bp->b_error; -if (cfg->retry_timeout !=XFS_ERR_RETRY_FOREVER && - !bp->b_first_retry_time) - bp->b_first_retry_time = jiffies; -return true; -} -/* * Account for this latest trip around the retry handler, and decide if * we've failed enough times to constitute a permanent failure.
@@ -1281,10 +1264,13 @@ xfs_buf_ioend_disposition(trace_xfs_buf_iodone_async (bp, _RET_IP_); cfg =xfs_error_get_cfg (mp,XFS_ERR_METADATA , bp->b_error); -if (xfs_buf_ioerror_retry (bp, cfg)) { -xfs_buf_ioerror (bp,0 ); -xfs_buf_submit (bp); -return XBF_IOEND_DONE ; +if (bp->b_last_error != bp->b_error || + !(bp->b_flags & (XBF_STALE |XBF_WRITE_FAIL ))) { + bp->b_last_error = bp->b_error; +if (cfg->retry_timeout !=XFS_ERR_RETRY_FOREVER && + !bp->b_first_retry_time) + bp->b_first_retry_time = jiffies; + goto resubmit; }/*
@@ -1299,6 +1285,11 @@ xfs_buf_ioend_disposition(/* Still considered a transient error. Caller will schedule retries. */ return XBF_IOEND_FAIL ; +resubmit: +xfs_buf_ioerror (bp,0 ); + bp->b_flags |= (XBF_WRITE |XBF_DONE |XBF_WRITE_FAIL ); +xfs_buf_submit (bp); +return XBF_IOEND_DONE ; out_stale:xfs_buf_stale (bp); bp->b_flags |=XBF_DONE ;
Signature · 1 line
2.28.0
PATCH 8/15 xfs: lift the XBF_IOEND_FAIL handling into xfs_buf_ioend_disposition
In reply to Christoph HellwigKeep all the error handling code together.
--- fs/xfs/xfs_buf.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
fs/xfs/xfs_buf.c +8 -8
@@ -1283,6 +1283,14 @@ xfs_buf_ioend_disposition( }/* Still considered a transient error. Caller will schedule retries. */ +if (bp->b_flags & _XBF_INODES) +xfs_buf_inode_io_fail (bp); +else if (bp->b_flags & _XBF_DQUOTS) +xfs_buf_dquot_io_fail (bp); +else +ASSERT (list_empty (&bp->b_li_list)); +xfs_buf_ioerror (bp,0 ); +xfs_buf_relse (bp);return XBF_IOEND_FAIL ; resubmit:
@@ -1336,14 +1344,6 @@ xfs_buf_ioend(case XBF_IOEND_DONE :return ;case XBF_IOEND_FAIL : -if (bp->b_flags & _XBF_INODES) -xfs_buf_inode_io_fail (bp); -else if (bp->b_flags & _XBF_DQUOTS) -xfs_buf_dquot_io_fail (bp); -else -ASSERT (list_empty (&bp->b_li_list)); -xfs_buf_ioerror (bp,0 ); -xfs_buf_relse (bp);return ;default :break ;
Signature · 1 line
2.28.0
PATCH 9/15 xfs: simplify the xfs_buf_ioend_disposition calling convention
In reply to Christoph HellwigNow that all the actual error handling is in a single place, xfs_buf_ioend_disposition just needs to return true if took ownership of the buffer, or false if not instead of the tristate. Also move the error check back in the caller to optimize for the fast path, and give the function a better fitting name.
--- fs/xfs/xfs_buf.c | 36 +++++++++--------------------------- 1 file changed, 9 insertions(+), 27 deletions(-)
fs/xfs/xfs_buf.c +9 -27
@@ -1223,29 +1223,17 @@ xfs_buf_ioerror_permanent(* If we get repeated async write failures, then we take action according to the * error configuration we have been set up to use. * -* Multi-state return value: -* -* XBF_IOEND_FINISH: run callback completions -* XBF_IOEND_DONE: resubmitted immediately, do not run any completions -* XBF_IOEND_FAIL: transient error, run failure callback completions and then -* release the buffer +* Returns true if this function took care of error handling and the caller must +* not touch the buffer again. Return false if the caller should proceed with +* normal I/O completion handling. */ -enum xfs_buf_ioend_disposition { -XBF_IOEND_FINISH , -XBF_IOEND_DONE , -XBF_IOEND_FAIL , -}; - -static enum xfs_buf_ioend_disposition -xfs_buf_ioend_disposition ( +static bool +xfs_buf_ioend_handle_error (struct xfs_buf *bp) {struct xfs_mount *mp = bp->b_mount;struct xfs_error_cfg *cfg; -if (likely (!bp->b_error)) -return XBF_IOEND_FINISH ; -/* * If we've already decided to shutdown the filesystem because of I/O * errors, there's no point in giving this a retry.
@@ -1291,18 +1279,18 @@ xfs_buf_ioend_disposition(ASSERT (list_empty (&bp->b_li_list));xfs_buf_ioerror (bp,0 );xfs_buf_relse (bp); -return XBF_IOEND_FAIL ; +return true; resubmit:xfs_buf_ioerror (bp,0 ); bp->b_flags |= (XBF_WRITE |XBF_DONE |XBF_WRITE_FAIL );xfs_buf_submit (bp); -return XBF_IOEND_DONE ; +return true; out_stale:xfs_buf_stale (bp); bp->b_flags |=XBF_DONE ;trace_xfs_buf_error_relse (bp, _RET_IP_); -return XBF_IOEND_FINISH ; +return false; } static void
@@ -1340,14 +1328,8 @@ xfs_buf_ioend( bp->b_flags |=XBF_DONE ; } -switch (xfs_buf_ioend_disposition (bp)) { -case XBF_IOEND_DONE : -return ; -case XBF_IOEND_FAIL : +if (unlikely (bp->b_error) &&xfs_buf_ioend_handle_error (bp))return ; -default : -break ; - }/* clear the retry state */ bp->b_last_error =0 ;
Signature · 1 line
2.28.0
PATCH 10/15 xfs: use xfs_buf_item_relse in xfs_buf_item_done
In reply to Christoph HellwigReuse xfs_buf_item_relse instead of duplicating it.
--- fs/xfs/xfs_buf_item.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
fs/xfs/xfs_buf_item.c +3 -6
@@ -958,8 +958,6 @@ voidxfs_buf_item_done ( struct xfs_buf *bp) { -struct xfs_buf_log_item *bip = bp->b_log_item; -/* * If we are forcibly shutting down, this may well be off the AIL * already. That's because we simulate the log-committed callbacks to
@@ -969,8 +967,7 @@ xfs_buf_item_done(* * Either way, AIL is useless if we're forcing a shutdown. */ -xfs_trans_ail_delete (&bip->bli_item,SHUTDOWN_CORRUPT_INCORE ); - bp->b_log_item =NULL ; -xfs_buf_item_free (bip); -xfs_buf_rele (bp); +xfs_trans_ail_delete (&bp->b_log_item->bli_item, +SHUTDOWN_CORRUPT_INCORE ); +xfs_buf_item_relse (bp); }
Signature · 1 line
2.28.0
PATCH 11/15 xfs: clear the read/write flags later in xfs_buf_ioend
In reply to Christoph HellwigClear the flags at the end of xfs_buf_ioend so that they can be used during the completion.
--- fs/xfs/xfs_buf.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
fs/xfs/xfs_buf.c +5 -6
@@ -1283,12 +1283,13 @@ xfs_buf_ioend_handle_error( resubmit:xfs_buf_ioerror (bp,0 ); - bp->b_flags |= (XBF_WRITE |XBF_DONE |XBF_WRITE_FAIL ); + bp->b_flags |= (XBF_DONE |XBF_WRITE_FAIL );xfs_buf_submit (bp);return true; out_stale:xfs_buf_stale (bp); bp->b_flags |=XBF_DONE ; + bp->b_flags &= ~XBF_WRITE ;trace_xfs_buf_error_relse (bp, _RET_IP_);return false; }
@@ -1297,12 +1298,8 @@ static voidxfs_buf_ioend ( struct xfs_buf *bp) { -bool read = bp->b_flags &XBF_READ ; -trace_xfs_buf_iodone (bp, _RET_IP_); - bp->b_flags &= ~(XBF_READ |XBF_WRITE |XBF_READ_AHEAD ); -/* * Pull in IO completion errors now. We are guaranteed to be running * single threaded, so we don't need the lock to read b_io_error.
@@ -1310,7 +1307,7 @@ xfs_buf_ioend(if (!bp->b_error && bp->b_io_error)xfs_buf_ioerror (bp, bp->b_io_error); -if (read) { +if (bp->b_flags &XBF_READ ) {if (!bp->b_error && bp->b_ops) bp->b_ops->verify_read (bp);if (!bp->b_error)
@@ -1350,6 +1347,8 @@ xfs_buf_ioend(xfs_buf_dquot_iodone (bp); } + bp->b_flags &= ~(XBF_READ |XBF_WRITE |XBF_READ_AHEAD ); +if (bp->b_flags &XBF_ASYNC )xfs_buf_relse (bp);else
Signature · 1 line
2.28.0
PATCH 12/15 xfs: remove xlog_recover_iodone
In reply to Christoph HellwigThe log recovery I/O completion handler does not substancially differ from the normal one except for the fact that it:
a) never retries failed writes
b) can have log items that aren't on the AIL
c) never has inode/dquot log items attached and thus don't need to handle them
Add conditionals for (a) and (b) to the ioend code, while (c) doesn't need special handling anyway.
--- fs/xfs/libxfs/xfs_log_recover.h | 1 - fs/xfs/xfs_buf.c | 20 ++++++++++++-------- fs/xfs/xfs_buf_item.c | 4 ++++ fs/xfs/xfs_buf_item_recover.c | 2 +- fs/xfs/xfs_log_recover.c | 25 ------------------------- 5 files changed, 17 insertions(+), 35 deletions(-)
fs/xfs/libxfs/xfs_log_recover.h +0 -1
@@ -121,7 +121,6 @@ struct xlog_recover {void xlog_buf_readahead (struct xlog *log,xfs_daddr_t blkno,uint len,const struct xfs_buf_ops *ops);bool xlog_is_buffer_cancelled (struct xlog *log,xfs_daddr_t blkno,uint len); -void xlog_recover_iodone (struct xfs_buf *bp);void xlog_recover_release_intent (struct xlog *log,unsigned short intent_type,uint64_t intent_id);
fs/xfs/xfs_buf.c +12 -8
@@ -1243,6 +1243,15 @@ xfs_buf_ioend_handle_error(xfs_buf_ioerror_alert_ratelimited (bp); +/* +* We're not going to bother about retrying this during recovery. +* One strike! +*/ +if (bp->b_flags & _XBF_LOGRECOVERY) { +xfs_force_shutdown (mp,SHUTDOWN_META_IO_ERROR ); +return false; + } +/* * Synchronous writes will have callers process the error. */
@@ -1312,13 +1321,6 @@ xfs_buf_ioend( bp->b_ops->verify_read (bp);if (!bp->b_error) bp->b_flags |=XBF_DONE ; - }else if (bp->b_flags & _XBF_LOGRECOVERY) { -/* -* If this is a log recovery buffer, we aren't doing -* transactional I/O yet so we need to let the log recovery code -* handle I/O completions: -*/ -xlog_recover_iodone (bp); }else {if (!bp->b_error) { bp->b_flags &= ~XBF_WRITE_FAIL ;
@@ -1345,9 +1347,11 @@ xfs_buf_ioend(xfs_buf_inode_iodone (bp); else if (bp->b_flags & _XBF_DQUOTS) xfs_buf_dquot_iodone(bp); + } - bp->b_flags &= ~(XBF_READ |XBF_WRITE |XBF_READ_AHEAD ); + bp->b_flags &= ~(XBF_READ |XBF_WRITE |XBF_READ_AHEAD | + _XBF_LOGRECOVERY);if (bp->b_flags &XBF_ASYNC )xfs_buf_relse (bp);
fs/xfs/xfs_buf_item.c +4 -0
@@ -966,8 +966,12 @@ xfs_buf_item_done(* xfs_trans_ail_delete() takes care of these. * * Either way, AIL is useless if we're forcing a shutdown. +* +* Note that log recovery writes might have buffer items that are not on +* the AIL even when the file system is not shut down. */ xfs_trans_ail_delete (&bp->b_log_item->bli_item, + (bp->b_flags & _XBF_LOGRECOVERY) ?0 :SHUTDOWN_CORRUPT_INCORE );xfs_buf_item_relse (bp); }
fs/xfs/xfs_buf_item_recover.c +1 -1
@@ -414,7 +414,7 @@ xlog_recover_validate_buf_type(* * Write verifiers update the metadata LSN from log items attached to * the buffer. Therefore, initialize a bli purely to carry the LSN to -* the verifier. We'll clean it up in our ->iodone() callback. +* the verifier. */ if (bp->b_ops) {struct xfs_buf_log_item *bip;
fs/xfs/xfs_log_recover.c +0 -25
@@ -265,31 +265,6 @@ xlog_header_check_mount(return 0 ; } -void -xlog_recover_iodone ( -struct xfs_buf *bp) -{ -if (!bp->b_error) { - bp->b_flags |=XBF_DONE ; - }else if (!XFS_FORCED_SHUTDOWN (bp->b_mount)) { -/* -* We're not going to bother about retrying this during -* recovery. One strike! -*/ -xfs_buf_ioerror_alert (bp, __this_address); -xfs_force_shutdown (bp->b_mount,SHUTDOWN_META_IO_ERROR ); - } - -/* -* On v5 supers, a bli could be attached to update the metadata LSN. -* Clean it up. -*/ -if (bp->b_log_item) -xfs_buf_item_relse (bp); -ASSERT (bp->b_log_item ==NULL ); - bp->b_flags &= ~_XBF_LOGRECOVERY; -} -/* * This routine finds (to an approximation) the first block in the physical * log which contains the given cycle. It uses a binary search algorithm.
Signature · 1 line
2.28.0
PATCH 13/15 xfs: simplify xfs_trans_getsb
In reply to Christoph HellwigRemove the mp argument as this function is only called in transaction context, and open code xfs_getsb given that the function already accesses the buffer pointer in the mount point directly.
--- fs/xfs/libxfs/xfs_sb.c | 4 ++-- fs/xfs/xfs_trans.c | 2 +- fs/xfs/xfs_trans.h | 2 +- fs/xfs/xfs_trans_buf.c | 46 ++++++++++++++---------------------------- 4 files changed, 19 insertions(+), 35 deletions(-)
fs/xfs/libxfs/xfs_sb.c +2 -2
@@ -954,7 +954,7 @@ xfs_log_sb( struct xfs_trans *tp) {struct xfs_mount *mp = tp->t_mountp; -struct xfs_buf *bp =xfs_trans_getsb (tp, mp); +struct xfs_buf *bp =xfs_trans_getsb (tp); mp->m_sb.sb_icount =percpu_counter_sum (&mp->m_icount); mp->m_sb.sb_ifree =percpu_counter_sum (&mp->m_ifree);
@@ -1084,7 +1084,7 @@ xfs_sync_sb_buf(if (error)return error; - bp =xfs_trans_getsb (tp, mp); + bp =xfs_trans_getsb (tp);xfs_log_sb (tp);xfs_trans_bhold (tp, bp);xfs_trans_set_sync (tp);
fs/xfs/xfs_trans.c +1 -1
@@ -468,7 +468,7 @@ xfs_trans_apply_sb_deltas(xfs_buf_t *bp;int whole =0 ; - bp =xfs_trans_getsb (tp, tp->t_mountp); + bp =xfs_trans_getsb (tp); sbp = bp->b_addr;/*
fs/xfs/xfs_trans.h +1 -1
@@ -209,7 +209,7 @@ xfs_trans_read_buf( flags, bpp, ops); } -struct xfs_buf *xfs_trans_getsb (xfs_trans_t *,struct xfs_mount *); +struct xfs_buf *xfs_trans_getsb (struct xfs_trans *);void xfs_trans_brelse (xfs_trans_t *,struct xfs_buf *);void xfs_trans_bjoin (xfs_trans_t *,struct xfs_buf *);
fs/xfs/xfs_trans_buf.c +15 -31
65 lines not on this page · raw message
Signature · 1 line
2.28.0
Re: [PATCH 13/15] xfs: simplify xfs_trans_getsb
Quoted 5 lines · Christoph Hellwig
Remove the mp argument as this function is only called in transaction context, and open code
xfs_getsbgiven that the function already accesses the buffer pointer in the mount point directly.Signed-off-by Christoph Hellwig <[email protected]>
Looks pretty straightforward to me,
--D
Quoted 128 lines
--- fs/xfs/libxfs/xfs_sb.c | 4 ++-- fs/xfs/xfs_trans.c | 2 +- fs/xfs/xfs_trans.h | 2 +- fs/xfs/xfs_trans_buf.c | 46 ++++++++++++++---------------------------- 4 files changed, 19 insertions(+), 35 deletions(-)fs/xfs/libxfs/xfs_sb.c +2
-2@@ -954,7 +954,7 @@ xfs_log_sb( struct xfs_trans *tp) {struct xfs_mount *mp = tp->t_mountp; -struct xfs_buf *bp =xfs_trans_getsb (tp, mp); +struct xfs_buf *bp =xfs_trans_getsb (tp); mp->m_sb.sb_icount =percpu_counter_sum (&mp->m_icount); mp->m_sb.sb_ifree =percpu_counter_sum (&mp->m_ifree);@@ -1084,7 +1084,7 @@ xfs_sync_sb_buf(if (error)return error; - bp =xfs_trans_getsb (tp, mp); + bp =xfs_trans_getsb (tp);xfs_log_sb (tp);xfs_trans_bhold (tp, bp);xfs_trans_set_sync (tp);fs/xfs/xfs_trans.c +1
-1@@ -468,7 +468,7 @@ xfs_trans_apply_sb_deltas(xfs_buf_t *bp;int whole =0 ; - bp =xfs_trans_getsb (tp, tp->t_mountp); + bp =xfs_trans_getsb (tp); sbp = bp->b_addr;/* fs/xfs/xfs_trans.h +1
-1@@ -209,7 +209,7 @@ xfs_trans_read_buf( flags, bpp, ops); } -struct xfs_buf *xfs_trans_getsb (xfs_trans_t *,struct xfs_mount *); +struct xfs_buf *xfs_trans_getsb (struct xfs_trans *);void xfs_trans_brelse (xfs_trans_t *,struct xfs_buf *);void xfs_trans_bjoin (xfs_trans_t *,struct xfs_buf *);fs/xfs/xfs_trans_buf.c +15
-31@@ -166,50 +166,34 @@ xfs_trans_get_buf_map( }/* -* Get and lock the superblock buffer of this file system for the -* given transaction. -* -* We don't need to use incore_match() here, because the superblock -* buffer is a private buffer which we keep a pointer to in the -* mount structure. +* Get and lock the superblock buffer for the given transaction. */ -xfs_buf_t * +struct xfs_buf *xfs_trans_getsb ( -xfs_trans_t *tp, -struct xfs_mount *mp) +struct xfs_trans *tp) { -xfs_buf_t *bp; -struct xfs_buf_log_item *bip; +struct xfs_buf *bp = tp->t_mountp->m_sb_bp;/* -* Default to just trying to lock the superblock buffer -* if tp is NULL. +* Just increment the lock recursion count if the buffer is already +* attached to this transaction. */ -if (tp ==NULL ) -return xfs_getsb (mp); - -/* -* If the superblock buffer already has this transaction -* pointer in its b_fsprivate2 field, then we know we already -* have it locked. In this case we just increment the lock -* recursion count and return the buffer to the caller. -*/ - bp = mp->m_sb_bp;if (bp->b_transp == tp) { - bip = bp->b_log_item; +struct xfs_buf_log_item *bip = bp->b_log_item; +ASSERT (bip !=NULL );ASSERT (atomic_read (&bip->bli_refcount) >0 ); bip->bli_recur++; +trace_xfs_trans_getsb_recur (bip); -return bp; - } + }else { +xfs_buf_lock (bp); +xfs_buf_hold (bp); +_xfs_trans_bjoin (tp, bp,1 ); - bp =xfs_getsb (mp); -if (bp ==NULL ) -return NULL ; +trace_xfs_trans_getsb (bp->b_log_item); + } -_xfs_trans_bjoin (tp, bp,1 ); -trace_xfs_trans_getsb (bp->b_log_item);return bp; }Signature · 1 line
2.28.0
PATCH 14/15 xfs: remove xfs_getsb
In reply to Christoph HellwigMerge xfs_getsb into its only caller, and clean that one up a little bit as well.
--- fs/xfs/xfs_log_recover.c | 26 +++++++++++++------------- fs/xfs/xfs_mount.c | 17 ----------------- fs/xfs/xfs_mount.h | 1 - 3 files changed, 13 insertions(+), 31 deletions(-)
fs/xfs/xfs_log_recover.c +13 -13
@@ -3268,14 +3268,14 @@ xlog_do_log_recovery(*/ STATIC intxlog_do_recover ( -struct xlog *log, -xfs_daddr_t head_blk, -xfs_daddr_t tail_blk) +struct xlog *log, +xfs_daddr_t head_blk, +xfs_daddr_t tail_blk) { -struct xfs_mount *mp = log->l_mp; -int error; -xfs_buf_t *bp; -xfs_sb_t *sbp; +struct xfs_mount *mp = log->l_mp; +struct xfs_buf *bp = mp->m_sb_bp; +struct xfs_sb *sbp = &mp->m_sb; +int error;trace_xfs_log_recover (log, head_blk, tail_blk);
@@ -3289,9 +3289,8 @@ xlog_do_recover(/* * If IO errors happened during recovery, bail out. */ -if (XFS_FORCED_SHUTDOWN (mp)) { +if (XFS_FORCED_SHUTDOWN (mp))return -EIO ; - }/* * We now update the tail_lsn since much of the recovery has completed
@@ -3305,10 +3304,12 @@ xlog_do_recover(xlog_assign_tail_lsn (mp);/* -* Now that we've finished replaying all buffer and inode -* updates, re-read in the superblock and reverify it. +* Now that we've finished replaying all buffer and inode updates, +* re-read the superblock and reverify it. */ - bp =xfs_getsb (mp); +xfs_buf_lock (bp); +xfs_buf_hold (bp); +ASSERT (bp->b_flags &XBF_DONE ); bp->b_flags &= ~(XBF_DONE |XBF_ASYNC );ASSERT (!(bp->b_flags &XBF_WRITE )); bp->b_flags |=XBF_READ ;
@@ -3325,7 +3326,6 @@ xlog_do_recover( }/* Convert superblock from on-disk format */ - sbp = &mp->m_sb;xfs_sb_from_disk (sbp, bp->b_addr);xfs_buf_relse (bp);
fs/xfs/xfs_mount.c +0 -17
@@ -1288,23 +1288,6 @@ xfs_mod_frextents(return ret; } -/* -* xfs_getsb() is called to obtain the buffer for the superblock. -* The buffer is returned locked and read in from disk. -* The buffer should be released with a call to xfs_brelse(). -*/ -struct xfs_buf * -xfs_getsb ( -struct xfs_mount *mp) -{ -struct xfs_buf *bp = mp->m_sb_bp; - -xfs_buf_lock (bp); -xfs_buf_hold (bp); -ASSERT (bp->b_flags &XBF_DONE ); -return bp; -} -/* * Used to free the superblock along various error paths. */
fs/xfs/xfs_mount.h +0 -1
@@ -410,7 +410,6 @@ extern int xfs_mod_fdblocks(struct xfs_mount *mp, int64_t delta, bool reserved);extern int xfs_mod_frextents (struct xfs_mount *mp,int64_t delta); -extern struct xfs_buf *xfs_getsb (xfs_mount_t *);extern int xfs_readsb (xfs_mount_t *,int );extern void xfs_freesb (xfs_mount_t *);extern bool xfs_fs_writable (struct xfs_mount *mp,int level);
Signature · 1 line
2.28.0
Re: [PATCH 14/15] xfs: remove xfs_getsb
Quoted 4 lines · Christoph Hellwig
Merge
xfs_getsbinto its only caller, and clean that one up a little bit as well.Signed-off-by Christoph Hellwig <[email protected]>
Nice cleanup.
--D
Quoted 110 lines
--- fs/xfs/xfs_log_recover.c | 26 +++++++++++++------------- fs/xfs/xfs_mount.c | 17 ----------------- fs/xfs/xfs_mount.h | 1 - 3 files changed, 13 insertions(+), 31 deletions(-)fs/xfs/xfs_log_recover.c +13
-13@@ -3268,14 +3268,14 @@ xlog_do_log_recovery(*/ STATIC intxlog_do_recover ( -struct xlog *log, -xfs_daddr_t head_blk, -xfs_daddr_t tail_blk) +struct xlog *log, +xfs_daddr_t head_blk, +xfs_daddr_t tail_blk) { -struct xfs_mount *mp = log->l_mp; -int error; -xfs_buf_t *bp; -xfs_sb_t *sbp; +struct xfs_mount *mp = log->l_mp; +struct xfs_buf *bp = mp->m_sb_bp; +struct xfs_sb *sbp = &mp->m_sb; +int error;trace_xfs_log_recover (log, head_blk, tail_blk);@@ -3289,9 +3289,8 @@ xlog_do_recover(/* * If IO errors happened during recovery, bail out. */ -if (XFS_FORCED_SHUTDOWN (mp)) { +if (XFS_FORCED_SHUTDOWN (mp))return -EIO ; - }/* * We now update the tail_lsn since much of the recovery has completed @@ -3305,10 +3304,12 @@ xlog_do_recover(xlog_assign_tail_lsn (mp);/* -* Now that we've finished replaying all buffer and inode -* updates, re-read in the superblock and reverify it. +* Now that we've finished replaying all buffer and inode updates, +* re-read the superblock and reverify it. */ - bp =xfs_getsb (mp); +xfs_buf_lock (bp); +xfs_buf_hold (bp); +ASSERT (bp->b_flags &XBF_DONE ); bp->b_flags &= ~(XBF_DONE |XBF_ASYNC );ASSERT (!(bp->b_flags &XBF_WRITE )); bp->b_flags |=XBF_READ ;@@ -3325,7 +3326,6 @@ xlog_do_recover( }/* Convert superblock from on-disk format */ - sbp = &mp->m_sb;xfs_sb_from_disk (sbp, bp->b_addr);xfs_buf_relse (bp);fs/xfs/xfs_mount.c +0
-17@@ -1288,23 +1288,6 @@ xfs_mod_frextents(return ret; } -/* -* xfs_getsb() is called to obtain the buffer for the superblock. -* The buffer is returned locked and read in from disk. -* The buffer should be released with a call to xfs_brelse(). -*/ -struct xfs_buf * -xfs_getsb ( -struct xfs_mount *mp) -{ -struct xfs_buf *bp = mp->m_sb_bp; - -xfs_buf_lock (bp); -xfs_buf_hold (bp); -ASSERT (bp->b_flags &XBF_DONE ); -return bp; -} -/* * Used to free the superblock along various error paths. */ fs/xfs/xfs_mount.h +0
-1@@ -410,7 +410,6 @@ extern int xfs_mod_fdblocks(struct xfs_mount *mp, int64_t delta, bool reserved);extern int xfs_mod_frextents (struct xfs_mount *mp,int64_t delta); -extern struct xfs_buf *xfs_getsb (xfs_mount_t *);extern int xfs_readsb (xfs_mount_t *,int );extern void xfs_freesb (xfs_mount_t *);extern bool xfs_fs_writable (struct xfs_mount *mp,int level);Signature · 1 line
2.28.0
PATCH 15/15 xfs: reuse _xfs_buf_read for re-reading the superblock
In reply to Christoph HellwigInstead of poking deeply into buffer cache internals when re-reading the superblock during log recovery just generalize _xfs_buf_read and use it there. Note that we don't have to explicitly set up the ops as they must be set from the initial read.
--- fs/xfs/xfs_buf.c | 15 ++++++++++++--- fs/xfs/xfs_buf.h | 9 +-------- fs/xfs/xfs_log_recover.c | 8 +------- 3 files changed, 14 insertions(+), 18 deletions(-)
fs/xfs/xfs_buf.c +12 -3
@@ -52,6 +52,15 @@ static kmem_zone_t *xfs_buf_zone;* b_lock (trylock due to inversion) */ +static int __xfs_buf_submit (struct xfs_buf *bp,bool wait); + +static inline int +xfs_buf_submit ( +struct xfs_buf *bp) +{ +return __xfs_buf_submit (bp, !(bp->b_flags &XBF_ASYNC )); +} +static inline int xfs_buf_is_vmapped (struct xfs_buf *bp)
@@ -751,7 +760,7 @@ xfs_buf_get_map(return 0 ; } -STATIC int +int _xfs_buf_read (xfs_buf_t *bp,xfs_buf_flags_t flags)
@@ -759,7 +768,7 @@ _xfs_buf_read(ASSERT (!(flags &XBF_WRITE ));ASSERT (bp->b_maps[0 ].bm_bn !=XFS_BUF_DADDR_NULL ); - bp->b_flags &= ~(XBF_WRITE |XBF_ASYNC |XBF_READ_AHEAD ); + bp->b_flags &= ~(XBF_WRITE |XBF_ASYNC |XBF_READ_AHEAD |XBF_DONE ); bp->b_flags |= flags & (XBF_READ |XBF_ASYNC |XBF_READ_AHEAD );return xfs_buf_submit (bp);
@@ -1639,7 +1648,7 @@ xfs_buf_iowait(* safe to reference the buffer after a call to this function unless the caller * holds an additional reference itself. */ -int +static int __xfs_buf_submit (struct xfs_buf *bp,bool wait)
fs/xfs/xfs_buf.h +1 -8
@@ -249,6 +249,7 @@ int xfs_buf_get_uncached(struct xfs_buftarg *target, size_t numblks, int flags,int xfs_buf_read_uncached (struct xfs_buftarg *target,xfs_daddr_t daddr,size_t numblks,int flags,struct xfs_buf **bpp,const struct xfs_buf_ops *ops); +int _xfs_buf_read (struct xfs_buf *bp,xfs_buf_flags_t flags);void xfs_buf_hold (struct xfs_buf *bp);/* Releasing Buffers */
@@ -275,14 +276,6 @@ extern void __xfs_buf_ioerror(struct xfs_buf *bp, int error,#define xfs_buf_ioerror (bp, err) __xfs_buf_ioerror((bp), (err), __this_address)extern void xfs_buf_ioerror_alert (struct xfs_buf *bp,xfs_failaddr_t fa);void xfs_buf_ioend_fail (struct xfs_buf *); - -extern int __xfs_buf_submit (struct xfs_buf *bp,bool ); -static inline int xfs_buf_submit (struct xfs_buf *bp) -{ -bool wait = bp->b_flags &XBF_ASYNC ? false : true; -return __xfs_buf_submit (bp, wait); -} -void xfs_buf_zero (struct xfs_buf *bp,size_t boff,size_t bsize);void __xfs_buf_mark_corrupt (struct xfs_buf *bp,xfs_failaddr_t fa);#define xfs_buf_mark_corrupt (bp) __xfs_buf_mark_corrupt((bp), __this_address)
fs/xfs/xfs_log_recover.c +1 -7
@@ -3309,13 +3309,7 @@ xlog_do_recover(*/ xfs_buf_lock (bp);xfs_buf_hold (bp); -ASSERT (bp->b_flags &XBF_DONE ); - bp->b_flags &= ~(XBF_DONE |XBF_ASYNC ); -ASSERT (!(bp->b_flags &XBF_WRITE )); - bp->b_flags |=XBF_READ ; - bp->b_ops = &xfs_sb_buf_ops; - - error =xfs_buf_submit (bp); + error =_xfs_buf_read (bp,XBF_READ );if (error) {if (!XFS_FORCED_SHUTDOWN (mp)) {xfs_buf_ioerror_alert (bp, __this_address);
Signature · 1 line
2.28.0
Re: [PATCH 15/15] xfs: reuse _xfs_buf_read for re-reading the superblock
Quoted 6 lines · Christoph Hellwig
Instead of poking deeply into buffer cache internals when re-reading the superblock during log recovery just generalize
_xfs_buf_readand use it there. Note that we don't have to explicitly set up the ops as they must be set from the initial read.Signed-off-by Christoph Hellwig <[email protected]>
/me isn't too thrilled by the forward declaration of __xfs_buf_submit but oh well. :)
--D
Quoted 102 lines
--- fs/xfs/xfs_buf.c | 15 ++++++++++++--- fs/xfs/xfs_buf.h | 9 +-------- fs/xfs/xfs_log_recover.c | 8 +------- 3 files changed, 14 insertions(+), 18 deletions(-)fs/xfs/xfs_buf.c +12
-3@@ -52,6 +52,15 @@ static kmem_zone_t *xfs_buf_zone;* b_lock (trylock due to inversion) */ +static int __xfs_buf_submit (struct xfs_buf *bp,bool wait); + +static inline int +xfs_buf_submit ( +struct xfs_buf *bp) +{ +return __xfs_buf_submit (bp, !(bp->b_flags &XBF_ASYNC )); +} +static inline int xfs_buf_is_vmapped (struct xfs_buf *bp)@@ -751,7 +760,7 @@ xfs_buf_get_map(return 0 ; } -STATIC int +int _xfs_buf_read (xfs_buf_t *bp,xfs_buf_flags_t flags)@@ -759,7 +768,7 @@ _xfs_buf_read(ASSERT (!(flags &XBF_WRITE ));ASSERT (bp->b_maps[0 ].bm_bn !=XFS_BUF_DADDR_NULL ); - bp->b_flags &= ~(XBF_WRITE |XBF_ASYNC |XBF_READ_AHEAD ); + bp->b_flags &= ~(XBF_WRITE |XBF_ASYNC |XBF_READ_AHEAD |XBF_DONE ); bp->b_flags |= flags & (XBF_READ |XBF_ASYNC |XBF_READ_AHEAD );return xfs_buf_submit (bp);@@ -1639,7 +1648,7 @@ xfs_buf_iowait(* safe to reference the buffer after a call to this function unless the caller * holds an additional reference itself. */ -int +static int __xfs_buf_submit (struct xfs_buf *bp,bool wait)fs/xfs/xfs_buf.h +1
-8@@ -249,6 +249,7 @@ int xfs_buf_get_uncached(struct xfs_buftarg *target, size_t numblks, int flags,int xfs_buf_read_uncached (struct xfs_buftarg *target,xfs_daddr_t daddr,size_t numblks,int flags,struct xfs_buf **bpp,const struct xfs_buf_ops *ops); +int _xfs_buf_read (struct xfs_buf *bp,xfs_buf_flags_t flags);void xfs_buf_hold (struct xfs_buf *bp);/* Releasing Buffers */ @@ -275,14 +276,6 @@ extern void __xfs_buf_ioerror(struct xfs_buf *bp, int error,#define xfs_buf_ioerror (bp, err) __xfs_buf_ioerror((bp), (err), __this_address)extern void xfs_buf_ioerror_alert (struct xfs_buf *bp,xfs_failaddr_t fa);void xfs_buf_ioend_fail (struct xfs_buf *); - -extern int __xfs_buf_submit (struct xfs_buf *bp,bool ); -static inline int xfs_buf_submit (struct xfs_buf *bp) -{ -bool wait = bp->b_flags &XBF_ASYNC ? false : true; -return __xfs_buf_submit (bp, wait); -} -void xfs_buf_zero (struct xfs_buf *bp,size_t boff,size_t bsize);void __xfs_buf_mark_corrupt (struct xfs_buf *bp,xfs_failaddr_t fa);#define xfs_buf_mark_corrupt (bp) __xfs_buf_mark_corrupt((bp), __this_address)fs/xfs/xfs_log_recover.c +1
-7@@ -3309,13 +3309,7 @@ xlog_do_recover(*/ xfs_buf_lock (bp);xfs_buf_hold (bp); -ASSERT (bp->b_flags &XBF_DONE ); - bp->b_flags &= ~(XBF_DONE |XBF_ASYNC ); -ASSERT (!(bp->b_flags &XBF_WRITE )); - bp->b_flags |=XBF_READ ; - bp->b_ops = &xfs_sb_buf_ops; - - error =xfs_buf_submit (bp); + error =_xfs_buf_read (bp,XBF_READ );if (error) {if (!XFS_FORCED_SHUTDOWN (mp)) {xfs_buf_ioerror_alert (bp, __this_address);Signature · 1 line
2.28.0
Re: [PATCH 15/15] xfs: reuse _xfs_buf_read for re-reading the superblock
Quoted 10 lines · Darrick J. Wong
Quoted 6 lines · Christoph Hellwig
Instead of poking deeply into buffer cache internals when re-reading the superblock during log recovery just generalize
_xfs_buf_readand use it there. Note that we don't have to explicitly set up the ops as they must be set from the initial read.Signed-off-by Christoph Hellwig <[email protected]>/me isn't too thrilled by the forward declaration of
__xfs_buf_submitbut oh well. :)
Im neither, but getting rid of that would required a major rearrangement of xfs_buf.c.