]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
xfs: fix brainos in the refcount scrubber's rmap fragment processor
authorDarrick J. Wong <darrick.wong@oracle.com>
Mon, 9 Nov 2020 00:32:42 +0000 (16:32 -0800)
committerStefan Bader <stefan.bader@canonical.com>
Thu, 10 Dec 2020 11:06:30 +0000 (12:06 +0100)
BugLink: https://bugs.launchpad.net/bugs/1905618
[ Upstream commit 54e9b09e153842ab5adb8a460b891e11b39e9c3d ]

Fix some serious WTF in the reference count scrubber's rmap fragment
processing.  The code comment says that this loop is supposed to move
all fragment records starting at or before bno onto the worklist, but
there's no obvious reason why nr (the number of items added) should
increment starting from 1, and breaking the loop when we've added the
target number seems dubious since we could have more rmap fragments that
should have been added to the worklist.

This seems to manifest in xfs/411 when adding one to the refcount field.

Fixes: dbde19da9637 ("xfs: cross-reference the rmapbt data with the refcountbt")
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
fs/xfs/scrub/refcount.c

index 0cab11a5d39070aab46887cff8a4069a921f3eac..5c6b71b75ca10b8c755ecb0a5e8a99d6c085eb69 100644 (file)
@@ -170,7 +170,6 @@ xchk_refcountbt_process_rmap_fragments(
         */
        INIT_LIST_HEAD(&worklist);
        rbno = NULLAGBLOCK;
-       nr = 1;
 
        /* Make sure the fragments actually /are/ in agbno order. */
        bno = 0;
@@ -184,15 +183,14 @@ xchk_refcountbt_process_rmap_fragments(
         * Find all the rmaps that start at or before the refc extent,
         * and put them on the worklist.
         */
+       nr = 0;
        list_for_each_entry_safe(frag, n, &refchk->fragments, list) {
-               if (frag->rm.rm_startblock > refchk->bno)
-                       goto done;
+               if (frag->rm.rm_startblock > refchk->bno || nr > target_nr)
+                       break;
                bno = frag->rm.rm_startblock + frag->rm.rm_blockcount;
                if (bno < rbno)
                        rbno = bno;
                list_move_tail(&frag->list, &worklist);
-               if (nr == target_nr)
-                       break;
                nr++;
        }