From f8b581d6769d5732007f8aeeae4f7bd4f2e2874c Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Fri, 4 Sep 2020 15:50:20 -0400 Subject: [PATCH] libxfs: actually make buffers track the per-ag structures One of the patches in 5.9 reduces the number of xfs_perag_get calls by using the b_pag pointer in struct xfs_buf. Userspace doesn't actually do anything with this field (and hence that change will cause null pointer dereferences), so start tracking b_pag. Signed-off-by: Darrick J. Wong Reviewed-by: Eric Sandeen Signed-off-by: Eric Sandeen --- libxfs/rdwr.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c index 173d0dd2c..bf238c380 100644 --- a/libxfs/rdwr.c +++ b/libxfs/rdwr.c @@ -586,12 +586,22 @@ libxfs_getbuf_flags( struct xfs_buf **bpp) { struct xfs_bufkey key = {NULL}; + int ret; key.buftarg = btp; key.blkno = blkno; key.bblen = len; - return __cache_lookup(&key, flags, bpp); + ret = __cache_lookup(&key, flags, bpp); + if (ret) + return ret; + + if (btp == btp->bt_mount->m_ddev_targp) { + (*bpp)->b_pag = xfs_perag_get(btp->bt_mount, + xfs_daddr_to_agno(btp->bt_mount, blkno)); + } + + return 0; } /* @@ -1084,6 +1094,9 @@ libxfs_brelse( return; if (bp->b_flags & LIBXFS_B_DIRTY) libxfs_whine_dirty_buf(bp); + if (bp->b_pag) + xfs_perag_put(bp->b_pag); + bp->b_pag = NULL; pthread_mutex_lock(&xfs_buf_freelist.cm_mutex); list_add(&bp->b_node.cn_mru, &xfs_buf_freelist.cm_list); -- 2.47.3