Merge of master-melb:xfs-cmds:28456a by kenmcd.
mmap vs unwritten extents test.
--- /dev/null
+#! /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
--- /dev/null
+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
163 dmapi auto
164 rw pattern auto
165 rw pattern auto
+166 rw metadata auto
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
--- /dev/null
+#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);
+}