QA test to demonstrate unwritten extent/mmap write problem
authorDave Chinner <dgc@sgi.com>
Mon, 23 Apr 2007 16:00:46 +0000 (16:00 +0000)
committerDave Chinner <dgc@sgi.com>
Mon, 23 Apr 2007 16:00:46 +0000 (16:00 +0000)
Merge of master-melb:xfs-cmds:28456a by kenmcd.

  mmap vs unwritten extents test.

166 [new file with mode: 0644]
166.out [new file with mode: 0644]
group
src/Makefile
src/unwritten_mmap.c [new file with mode: 0644]

diff --git a/166 b/166
new file mode 100644 (file)
index 0000000..cb7ab43
--- /dev/null
+++ b/166
@@ -0,0 +1,54 @@
+#! /bin/sh
+# FSQA Test No. 166
+#
+# ->page-mkwrite test - unwritten extents and mmap
+#
+#-----------------------------------------------------------------------
+#  Copyright (c) 2007 Silicon Graphics, Inc.  All Rights Reserved.
+#-----------------------------------------------------------------------
+#
+# creator
+owner=dgc@sgi.com
+
+seq=`basename $0`
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1    # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+    _cleanup_testdir
+}
+
+# get standard environment, filters and checks
+. ./common.rc
+. ./common.filter
+
+_filter_blocks()
+{
+    $AWK_PROG '/[0-9]/ { print $1, $2, "XX..YY", "AG", "(AA..BB)", $6, $7 }'
+}
+
+# real QA test starts here
+_supported_fs xfs
+_supported_os Linux
+
+_setup_testdir
+_require_scratch
+_scratch_mkfs_xfs >/dev/null 2>&1
+_scratch_mount
+
+TEST_FILE=$SCRATCH_MNT/test_file
+TEST_PROG=$here/src/unwritten_mmap
+FILE_SIZE=131072
+
+rm -f $TEST_FILE
+$TEST_PROG $FILE_SIZE $TEST_FILE
+
+xfs_bmap -vp $TEST_FILE | _filter_blocks
+
+status=0
+exit
diff --git a/166.out b/166.out
new file mode 100644 (file)
index 0000000..3b40c43
--- /dev/null
+++ b/166.out
@@ -0,0 +1,6 @@
+QA output created by 164
+0: [0..31]: XX..YY AG (AA..BB) 32
+1: [32..127]: XX..YY AG (AA..BB) 96 10000
+2: [128..159]: XX..YY AG (AA..BB) 32
+3: [160..223]: XX..YY AG (AA..BB) 64 10000
+4: [224..255]: XX..YY AG (AA..BB) 32
diff --git a/group b/group
index 0330745a0e6cfb614cacb3b9a3c9f06daca2d61e..ff39d02066fe8a48347d77c9a88259c4b2de8353 100644 (file)
--- a/group
+++ b/group
@@ -245,3 +245,4 @@ pattern         ajones@sgi.com
 163 dmapi auto
 164 rw pattern auto
 165 rw pattern auto
 163 dmapi auto
 164 rw pattern auto
 165 rw pattern auto
+166 rw metadata auto
index a7bf0dc5a853d8272d37134f988c6fa4120133be..e102d05c39205bb1a1226143793b32bcb5ebe066 100644 (file)
@@ -12,8 +12,9 @@ TARGETS = dirstress fill fill2 getpagesize holes lstat64 \
        godown resvtest writemod makeextents itrash \
        multi_open_unlink dmiperf
 
        godown resvtest writemod makeextents itrash \
        multi_open_unlink dmiperf
 
-LINUX_TARGETS = loggen xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \
-       preallo_rw_pattern_writer ftrunc trunc fs_perms testx looptest locktest
+LINUX_TARGETS = loggen xfsctl bstat t_mtab getdevicesize \
+       preallo_rw_pattern_reader preallo_rw_pattern_writer ftrunc trunc \
+       fs_perms testx looptest locktest unwritten_mmap
 
 IRIX_TARGETS = open_unlink
 
 
 IRIX_TARGETS = open_unlink
 
diff --git a/src/unwritten_mmap.c b/src/unwritten_mmap.c
new file mode 100644 (file)
index 0000000..5e63486
--- /dev/null
@@ -0,0 +1,71 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <xfs/libxfs.h>
+#include <sys/mman.h>
+
+/*
+ * mmap a preallocated file and write to a set of offsets
+ * in it. We'll check to see if the underlying extents are
+ * converted correctly on writeback.
+ */
+int main(int argc, char **argv) {
+       unsigned long long o;
+       int fd, i;
+       struct xfs_flock64 space;
+       unsigned char *buf;
+
+       if(argc < 3) {
+               fprintf(stderr, "%s <count> <file [file...]>\n", argv[0]);
+               exit(1);
+       }
+
+       errno = 0;
+       o = strtoull(argv[1], NULL, 0);
+       if (errno) {
+               perror("strtoull");
+               exit(errno);
+       }
+
+       for(i = 2; i < argc; i++) {
+               unlink(argv[i]);
+               fd = open(argv[i], O_RDWR|O_CREAT|O_LARGEFILE, 0666);
+               if(fd < 0) {
+                       perror("open");
+                       exit(2);
+               }
+
+               if(ftruncate64(fd, o) < 0) {
+                       perror("ftruncate64");
+                       exit(3);
+               }
+
+               space.l_whence = SEEK_SET;
+               space.l_start = 0;
+               space.l_len = o;
+
+               if(ioctl(fd, XFS_IOC_RESVSP64, &space)) {
+                       perror("ioctl()");
+                       exit(4);
+               }
+
+               buf = mmap(NULL, (int)o, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
+               if(buf == MAP_FAILED) {
+                       perror("mmap()");
+                       exit(5);
+               } else {
+                       buf[o-1] = 0;
+                       buf[o/2] = 0;
+                       buf[0] = 0;
+                       munmap(buf, o);
+               }
+
+               fsync(fd);
+               if(close(fd) == -1) {
+                       perror("close");
+                       exit(6);
+               }
+       }
+       exit(0);
+}