From: Dave Chinner Date: Mon, 23 Apr 2007 16:00:46 +0000 (+0000) Subject: QA test to demonstrate unwritten extent/mmap write problem X-Git-Tag: v1.1.0~499 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=99120c4055b9ff04defa4147c48ec46294076cd9;p=xfstests-dev.git QA test to demonstrate unwritten extent/mmap write problem Merge of master-melb:xfs-cmds:28456a by kenmcd. mmap vs unwritten extents test. --- diff --git a/166 b/166 new file mode 100644 index 00000000..cb7ab438 --- /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 index 00000000..3b40c43e --- /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 0330745a..ff39d020 100644 --- a/group +++ b/group @@ -245,3 +245,4 @@ pattern ajones@sgi.com 163 dmapi auto 164 rw pattern auto 165 rw pattern auto +166 rw metadata auto diff --git a/src/Makefile b/src/Makefile index a7bf0dc5..e102d05c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -12,8 +12,9 @@ TARGETS = dirstress fill fill2 getpagesize holes lstat64 \ 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 diff --git a/src/unwritten_mmap.c b/src/unwritten_mmap.c new file mode 100644 index 00000000..5e634864 --- /dev/null +++ b/src/unwritten_mmap.c @@ -0,0 +1,71 @@ +#include +#include +#include +#include +#include +#include + +/* + * 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 \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); +}