On Thu, Jul 09, 2020 at 05:04:53PM +0200, Christoph Hellwig wrote: > Instead of poking deeply into buffer cache internals when re-reading the > superblock during log recovery just generalize _xfs_buf_read and use it > there. > > Signed-off-by: Christoph Hellwig <hch@xxxxxx> > --- > fs/xfs/xfs_buf.c | 28 +++++++++++++++++++--------- > fs/xfs/xfs_buf.h | 10 ++-------- > fs/xfs/xfs_log_recover.c | 11 +++-------- > 3 files changed, 24 insertions(+), 25 deletions(-) > > diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c > index 1172d5fa06aad2..34d88c8b50854a 100644 > --- a/fs/xfs/xfs_buf.c > +++ b/fs/xfs/xfs_buf.c > @@ -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) > @@ -753,16 +762,18 @@ xfs_buf_get_map( > return 0; > } > > -STATIC int > +int > _xfs_buf_read( > - xfs_buf_t *bp, > - xfs_buf_flags_t flags) > + struct xfs_buf *bp, > + xfs_buf_flags_t flags, > + const struct xfs_buf_ops *ops) > { > - ASSERT(!(flags & XBF_WRITE)); > ASSERT(bp->b_maps[0].bm_bn != XFS_BUF_DADDR_NULL); > + ASSERT(!(flags & XBF_WRITE)); > > - bp->b_flags &= ~(XBF_WRITE | XBF_ASYNC | XBF_READ_AHEAD); > - bp->b_flags |= flags & (XBF_READ | XBF_ASYNC | XBF_READ_AHEAD); > + bp->b_flags &= ~(XBF_WRITE | XBF_ASYNC | XBF_READ_AHEAD | XBF_DONE); > + bp->b_flags |= flags & (XBF_ASYNC | XBF_READ_AHEAD); Doesn't this change mean that the caller's XBF_READ never gets set in bp->b_flags? If the buffer is already in memory but doesn't have XBF_DONE set, how does XBF_READ get set? Maybe I'm missing something? --D > + bp->b_ops = ops; > > return xfs_buf_submit(bp); > } > @@ -827,8 +838,7 @@ xfs_buf_read_map( > if (!(bp->b_flags & XBF_DONE)) { > /* Initiate the buffer read and wait. */ > XFS_STATS_INC(target->bt_mount, xb_get_read); > - bp->b_ops = ops; > - error = _xfs_buf_read(bp, flags); > + error = _xfs_buf_read(bp, flags, ops); > > /* Readahead iodone already dropped the buffer, so exit. */ > if (flags & XBF_ASYNC) > @@ -1637,7 +1647,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) > diff --git a/fs/xfs/xfs_buf.h b/fs/xfs/xfs_buf.h > index 9eb4044597c985..db172599d32dc1 100644 > --- a/fs/xfs/xfs_buf.h > +++ b/fs/xfs/xfs_buf.h > @@ -249,6 +249,8 @@ 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, > + const struct xfs_buf_ops *ops); > void xfs_buf_hold(struct xfs_buf *bp); > > /* Releasing Buffers */ > @@ -275,14 +277,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) > diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c > index b181f3253e6e74..04f76a75886744 100644 > --- a/fs/xfs/xfs_log_recover.c > +++ b/fs/xfs/xfs_log_recover.c > @@ -3305,16 +3305,11 @@ 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 in the superblock and reverify it. > */ > bp = xfs_getsb(mp); > - 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, &xfs_sb_buf_ops); > if (error) { > if (!XFS_FORCED_SHUTDOWN(mp)) { > xfs_buf_ioerror_alert(bp, __this_address); > -- > 2.26.2 >