--- /dev/null
+#! /bin/sh
+# FSQA Test No. 167
+#
+# unwritten extent conversion test
+#
+#-----------------------------------------------------------------------
+# 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/$$
+rm -f $seq.full
+status=1 # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+ killall -q -TERM fsstress 2> /dev/null
+ _cleanup_testdir
+}
+
+workout()
+{
+ procs=100
+ nops=15000
+ $FSSTRESS_PROG -d $SCRATCH_MNT -p $procs -n $nops $FSSTRESS_AVOID \
+ >>$seq.full &
+ sleep 2
+}
+
+# get standard environment, filters and checks
+. ./common.rc
+. ./common.filter
+
+# 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_sync
+LOOPS=100
+
+echo "*** test unwritten extent conversion under heavy I/O"
+
+workout
+
+rm -f $TEST_FILE
+$TEST_PROG $LOOPS $TEST_FILE
+killall -q -TERM fsstress 2> /dev/null
+
+echo " *** test done"
+
+status=0
+exit
--- /dev/null
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <malloc.h>
+#include <unistd.h>
+#include <xfs/xfs.h>
+
+/* test thanks to judith@sgi.com */
+
+#define IO_SIZE 1048576
+
+void
+print_getbmapx(
+ const char *pathname,
+ int fd,
+ int64_t start,
+ int64_t limit);
+
+int
+main(int argc, char *argv[])
+{
+ int i;
+ int fd;
+ char *buf;
+ struct dioattr dio;
+ xfs_flock64_t flock;
+ off_t offset;
+ char *file;
+ int loops;
+
+ if(argc != 3) {
+ fprintf(stderr, "%s <loops> <file>\n", argv[0]);
+ exit(1);
+ }
+
+ errno = 0;
+ loops = strtoull(argv[1], NULL, 0);
+ if (errno) {
+ perror("strtoull");
+ exit(errno);
+ }
+ file = argv[2];
+
+ while (loops-- > 0) {
+ sleep(1);
+ fd = open(file, O_RDWR|O_CREAT|O_DIRECT, 0666);
+ if (fd < 0) {
+ perror("open");
+ exit(1);
+ }
+ if (xfsctl(file, fd, XFS_IOC_DIOINFO, &dio) < 0) {
+ perror("dioinfo");
+ exit(1);
+ }
+
+ if ((dio.d_miniosz > IO_SIZE) || (dio.d_maxiosz < IO_SIZE)) {
+ fprintf(stderr, "Test won't work - iosize out of range"
+ " (dio.d_miniosz=%d, dio.d_maxiosz=%d)\n",
+ dio.d_miniosz, dio.d_maxiosz);
+
+ exit(1);
+ }
+ buf = (char *)memalign(dio.d_mem , IO_SIZE);
+ if (buf == NULL) {
+ fprintf(stderr,"Can't get memory\n");
+ exit(1);
+ }
+ memset(buf,'Z',IO_SIZE);
+ offset = 0;
+
+ flock.l_whence = 0;
+ flock.l_start= 0;
+ flock.l_len = IO_SIZE*21;
+ if (xfsctl(file, fd, XFS_IOC_RESVSP64, &flock) < 0) {
+ perror("xfsctl ");
+ exit(1);
+ }
+ for (i = 0; i < 21; i++) {
+ if (pwrite(fd, buf, IO_SIZE, offset) != IO_SIZE) {
+ perror("pwrite");
+ exit(1);
+ }
+ offset += IO_SIZE;
+ }
+
+ print_getbmapx(file, fd, 0, 0);
+
+ flock.l_whence = 0;
+ flock.l_start= 0;
+ flock.l_len = 0;
+ xfsctl(file, fd, XFS_IOC_FREESP64, &flock);
+ print_getbmapx(file, fd, 0, 0);
+ close(fd);
+ }
+ exit(0);
+}
+
+void
+print_getbmapx(
+const char *pathname,
+ int fd,
+ int64_t start,
+ int64_t limit)
+{
+ struct getbmapx bmapx[50];
+ int array_size = sizeof(bmapx) / sizeof(bmapx[0]);
+ int x;
+ int foundone = 0;
+ int foundany = 0;
+
+again:
+ foundone = 0;
+ memset(bmapx, '\0', sizeof(bmapx));
+
+ bmapx[0].bmv_offset = start;
+ bmapx[0].bmv_length = -1; /* limit - start; */
+ bmapx[0].bmv_count = array_size;
+ bmapx[0].bmv_entries = 0; /* no entries filled in yet */
+
+ bmapx[0].bmv_iflags = BMV_IF_PREALLOC;
+
+ x = array_size;
+ for (;;) {
+ if (x > bmapx[0].bmv_entries) {
+ if (x != array_size) {
+ break; /* end of file */
+ }
+ if (xfsctl(pathname, fd, XFS_IOC_GETBMAPX, bmapx) < 0) {
+ fprintf(stderr, "XFS_IOC_GETBMAPX failed\n");
+ exit(1);
+ }
+ if (bmapx[0].bmv_entries == 0) {
+ break;
+ }
+ x = 1; /* back at first extent in buffer */
+ }
+ if (bmapx[x].bmv_oflags & 1) {
+ fprintf(stderr, "FOUND ONE %lld %lld %x\n",
+ bmapx[x].bmv_offset, bmapx[x].bmv_length,bmapx[x].bmv_oflags);
+ foundone = 1;
+ foundany = 1;
+ }
+ x++;
+ }
+ if (foundone) {
+ sleep(1);
+ fprintf(stderr,"Repeat\n");
+ goto again;
+ }
+ if (foundany) {
+ exit(1);
+ }
+}
+