]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libxfs: actually make buffers track the per-ag structures
authorDarrick J. Wong <darrick.wong@oracle.com>
Fri, 4 Sep 2020 19:50:20 +0000 (15:50 -0400)
committerEric Sandeen <sandeen@sandeen.net>
Fri, 4 Sep 2020 19:50:20 +0000 (15:50 -0400)
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 <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/rdwr.c

index 173d0dd2c0062ec8f90c652926d82204ff3c689a..bf238c380e5b02f87d35b2b193d28c3deed5d273 100644 (file)
@@ -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);