Blame SOURCES/xfsprogs-3.2.1-xfs_copy-simplify-first_agbno-calculation.patch

502773
commit 263b53767a3df33f392262f539bfb35ec578f5e5
502773
Author: Eric Sandeen <sandeen@redhat.com>
502773
Date:   Thu Nov 13 10:02:22 2014 +1100
502773
502773
    xfs_copy: simplify first_agbno calculation
502773
    
502773
    After ffe9a9a xfsprogs: xfs_copy: fix data corruption of target,
502773
    xfs_copy started hitting an ASSERT for a 4k sector / 4k blocksize
502773
    filesystem:
502773
    
502773
    # dd if=/dev/zero of=test.img bs=1M count=1024
502773
    # mkfs.xfs -s size=4096 test.img
502773
    # xfs_copy test.img xfs.img
502773
    xfs_copy: xfs_copy.c:720: main: Assertion `((((((xfs_daddr_t)(3 << (mp)->m_sectbb_log)) + 1) * (1<<9)) + first_residue) % source_blocksize) == 0' failed.
502773
    Aborted
502773
    
502773
    I started digging through all the calculations below, and realized
502773
    that in the end, all it wants is the first filesystem block after
502773
    the AG header.  XFS_AGFL_BLOCK(mp) + 1 suffices for this purpose;
502773
    rip out the rest which seems overly complex and apparently bug-prone.
502773
    
502773
    I tested this by creating a 4g filesystem with combinations of
502773
    sector & block size between 512 and 4k, copying in /lib/modules,
502773
    running an xfs_copy of that, and running repair against the copy;
502773
    it all looks good.  It took a long time, but I will create a
502773
    simpler/shorter xfstest based on this.
502773
    
502773
    Reported-by: Zorro Lang <zlang@redhat.com>
502773
    Signed-off-by: Eric Sandeen <sandeen@redhat.com>
502773
    Reviewed-by: Brian Foster <bfoster@redhat.com>
502773
    Signed-off-by: Dave Chinner <david@fromorbit.com>
502773
502773
diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c
502773
index 7ce5ec9..279527c 100644
502773
--- a/copy/xfs_copy.c
502773
+++ b/copy/xfs_copy.c
502773
@@ -475,7 +475,7 @@ main(int argc, char **argv)
502773
 	int		open_flags;
502773
 	xfs_off_t	pos, end_pos;
502773
 	size_t		length;
502773
-	int		c, first_residue, tmp_residue;
502773
+	int		c;
502773
 	__uint64_t	size, sizeb;
502773
 	__uint64_t	numblocks = 0;
502773
 	int		wblocks = 0;
502773
@@ -697,27 +697,13 @@ main(int argc, char **argv)
502773
 	ASSERT(source_blocksize % source_sectorsize == 0);
502773
 	ASSERT(source_sectorsize % BBSIZE == 0);
502773
 
502773
-	if (source_blocksize > source_sectorsize)  {
502773
-		/* get number of leftover sectors in last block of ag header */
502773
-
502773
-		tmp_residue = ((XFS_AGFL_DADDR(mp) + 1) * BBSIZE)
502773
-					% source_blocksize;
502773
-		first_residue = (tmp_residue == 0) ? 0 :
502773
-			source_blocksize - tmp_residue;
502773
-		ASSERT(first_residue % source_sectorsize == 0);
502773
-	} else if (source_blocksize == source_sectorsize)  {
502773
-		first_residue = 0;
502773
-	} else  {
502773
+	if (source_blocksize < source_sectorsize)  {
502773
 		do_log(_("Error:  filesystem block size is smaller than the"
502773
 			" disk sectorsize.\nAborting XFS copy now.\n"));
502773
 		exit(1);
502773
 	}
502773
 
502773
-	first_agbno = (((XFS_AGFL_DADDR(mp) + 1) * BBSIZE)
502773
-				+ first_residue) / source_blocksize;
502773
-	ASSERT(first_agbno != 0);
502773
-	ASSERT(((((XFS_AGFL_DADDR(mp) + 1) * BBSIZE)
502773
-				+ first_residue) % source_blocksize) == 0);
502773
+	first_agbno = XFS_AGFL_BLOCK(mp) + 1;
502773
 
502773
 	/* now open targets */
502773