]> git-server-git.apps.pok.os.sepia.ceph.com Git - xfsprogs-dev.git/commitdiff
xfs: fix endianness issue in xfs_ag_shrink_space libxfs-5.14-sync_2021-07-02
authorDarrick J. Wong <djwong@kernel.org>
Mon, 21 Jun 2021 18:53:03 +0000 (11:53 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Fri, 2 Jul 2021 23:28:41 +0000 (16:28 -0700)
The AGI buffer is in big-endian format, so we must convert the
endianness to CPU format to do any comparisons.

Fixes: 46141dc891f7 ("xfs: introduce xfs_ag_shrink_space()")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
libxfs/xfs_ag.c

index cf4d65a387ad5408681b5b407824cefccacff72d..bb25c304ac59e623354d72f2bcd51f28d4641bd9 100644 (file)
@@ -509,6 +509,7 @@ xfs_ag_shrink_space(
        struct xfs_buf          *agibp, *agfbp;
        struct xfs_agi          *agi;
        struct xfs_agf          *agf;
+       xfs_agblock_t           aglen;
        int                     error, err2;
 
        ASSERT(agno == mp->m_sb.sb_agcount - 1);
@@ -523,14 +524,14 @@ xfs_ag_shrink_space(
                return error;
 
        agf = agfbp->b_addr;
+       aglen = be32_to_cpu(agi->agi_length);
        /* some extra paranoid checks before we shrink the ag */
        if (XFS_IS_CORRUPT(mp, agf->agf_length != agi->agi_length))
                return -EFSCORRUPTED;
-       if (delta >= agi->agi_length)
+       if (delta >= aglen)
                return -EINVAL;
 
-       args.fsbno = XFS_AGB_TO_FSB(mp, agno,
-                                   be32_to_cpu(agi->agi_length) - delta);
+       args.fsbno = XFS_AGB_TO_FSB(mp, agno, aglen - delta);
 
        /*
         * Disable perag reservations so it doesn't cause the allocation request