xfstests: randholes: Fix two bugs
authorAlex Elder <aelder@sgi.com>
Thu, 14 Oct 2010 14:49:43 +0000 (14:49 +0000)
committerAlex Elder <aelder@sgi.com>
Tue, 19 Oct 2010 15:04:46 +0000 (10:04 -0500)
This patch fixes two bugs in the "randholes" test program.

First, it is possible for findblock() to return -1 if the random
block number it picks is at or above the highest in-range block
that's already been selected.  But this case isn't checked and
the value is blindly used thereafter as if it were valid.  Just
exit if this ever occurs.

Second, when the "alloconly" option is is set, blocks are
preallocated in the target file rather than actually writing them.
But unlike when the blocks are written and subsequently read, the
preallocated blocks are *not* offset by the fileoffset parameter.

I'm pretty sure nobody every noticed this because the program itself
doesn't do any verification when blocks are only preallocated.  But
it's an inconsistency and I think it ought to be fixed.

Signed-off-by: Alex Elder <aelder@sgi.com>
Acked-by: Dave Chinner <david@fromorbit.com>
src/randholes.c

index 0ac5c5aaf2e4fe344049693d33417a486e0e8ea8..7c86f0e614570821f2c32283d337de815bb3023f 100644 (file)
@@ -249,11 +249,16 @@ writeblks(char *fname, int fd)
                        fflush(stdout);
                }
                block = findblock();
-               offset = (__uint64_t)block * blocksize;
+               if (block < 0) {
+                   perror("findblock");
+                   exit(1);
+               }
+
+               offset = (__uint64_t) block * blocksize;
                if (alloconly) {
                         if (test) continue;
                         
-                       fl.l_start = offset;
+                       fl.l_start = fileoffset + offset;
                        fl.l_len = blocksize;
                        fl.l_whence = 0;