xfsqa: make hole tests independent of speculative allocation patterns
authorDave Chinner <dchinner@redhat.com>
Fri, 7 Jan 2011 12:59:15 +0000 (23:59 +1100)
committerDave Chinner <david@fromorbit.com>
Fri, 7 Jan 2011 12:59:15 +0000 (23:59 +1100)
Many of the "count-the-holes" tests (008, 012, etc) do writes that extend the
file and hence allocation patterns are dependent on speculative allocation
beyond EOF behaviour. Hence if we change that behaviour, these tests all fail
because there is a different pattern of holes.

Make the tests independent of EOF preallocation behaviour by first truncating
the file to the size the test is defined to use. This prevents speculative
prealocation from occurring, and hence changes in such behaviour will not cause
the tests to fail.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
203
src/holes.c
src/randholes.c

diff --git a/203 b/203
index 6fae36146e0eea112c415bc04e63cb4a2db813fa..be69dfabc04fbf012a51e0625ffc2e79a049b444 100755 (executable)
--- a/203
+++ b/203
@@ -36,6 +36,10 @@ _write_holes()
        file=$1
        holes=$2
        let writes=$holes+1
+       let fsize=$(($writes * 0x100000))
+
+       # prevent EOF preallocation from affecting results
+       xfs_io -f $file -c "truncate $fsize"
 
        offset=0
        for i in `seq 0 $writes`; do
index 1ad5093e47504d118220fb60956431de6fdcf2b6..3be8a6644cedf8e299548a1f08505a2fa0810d58 100644 (file)
@@ -79,6 +79,17 @@ main(int argc, char *argv[])
                perror("open");
                return 1;
        }
+
+       /*
+        * Avoid allocation patterns being perturbed by different speculative
+        * preallocation beyond EOF configurations by first truncating the file
+        * to the expected maximum file size.
+        */
+       if (ftruncate(fd, filesize) < 0) {
+               perror("ftruncate");
+               exit(EXIT_FAILURE);
+       }
+
        for (i = 0; i < count; i++) {
                writeblks(fd, filesize, blocksize, interleave, i, rev);
        }
index b7c89b333e1c91565bee2e9ade1445a0a043e64d..b43da81c1fc14c55968a4b0fa4b27d830870ee00 100644 (file)
@@ -208,6 +208,16 @@ writeblks(char *fname, int fd, size_t alignment)
                memset(buffer, 0, blocksize);
        }
 
+       /*
+        * Avoid allocation patterns being perturbed by different speculative
+        * preallocation beyond EOF configurations by first truncating the file
+        * to the expected maximum file size.
+        */
+       if (ftruncate(fd, filesize) < 0) {
+               perror("ftruncate");
+               exit(EXIT_FAILURE);
+       }
+
        do {
                if (verbose && ((count % 100) == 0)) {
                        printf(".");