diff options
author | Sage Weil <sage@newdream.net> | 2012-04-19 18:27:34 +0200 |
---|---|---|
committer | Sage Weil <sage@newdream.net> | 2012-04-21 01:51:00 +0200 |
commit | e861e20a1aa364915b7e090574adcee019080a42 (patch) | |
tree | b93687715567d76ab12b5de3da23321426fbf9ca | |
parent | admin_socket: add a separate debug subsys/level (diff) | |
download | ceph-e861e20a1aa364915b7e090574adcee019080a42.tar.xz ceph-e861e20a1aa364915b7e090574adcee019080a42.zip |
revert to xfstests' fsx, which has discard support
-rw-r--r-- | src/test/rbd/fsx.c | 1194 |
1 files changed, 862 insertions, 332 deletions
diff --git a/src/test/rbd/fsx.c b/src/test/rbd/fsx.c index 966b5a7c6c3..b36c201ed17 100644 --- a/src/test/rbd/fsx.c +++ b/src/test/rbd/fsx.c @@ -1,63 +1,45 @@ -// -*- mode:C; tab-width:8; c-basic-offset:8; indent-tabs-mode:t -*- /* - * Copyright (c) 1998-2001 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * The contents of this file constitute Original Code as defined in and - * are subject to the Apple Public Source License Version 2.0 (the - * "License"). You may not use this file except in compliance with the - * License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this file. - * - * This Original Code and all software distributed under the License are - * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License. - * - * @APPLE_LICENSE_HEADER_END@ + * Copyright (C) 1991, NeXT Computer, Inc. All Rights Reserverd. * * File: fsx.c * Author: Avadis Tevanian, Jr. * * File system exerciser. * - * Rewrite and enhancements 1998-2001 Conrad Minshall -- conrad@mac.com - * - * Various features from Joe Sokol, Pat Dirks, and Clark Warner. + * Rewritten 8/98 by Conrad Minshall. * - * Small changes to work under Linux -- davej@suse.de - * - * Sundry porting patches from Guy Harris 12/2001 + * Small changes to work under Linux -- davej. * * Checks for mmap last-page zero fill. - * - * Updated license to APSL 2.0, 2004/7/27 - Jordan Hubbard - * - * $FreeBSD: src/tools/regression/fsx/fsx.c,v 1.6 2008/02/19 07:09:18 ru Exp $ - * */ -#include <sys/types.h> -#include <sys/stat.h> +#include "global.h" + +#include <limits.h> #include <time.h> -#include <fcntl.h> +#include <strings.h> +#include <sys/file.h> #include <sys/mman.h> -#include <limits.h> +#ifdef HAVE_ERR_H +#include <err.h> +#endif #include <signal.h> #include <stdio.h> +#include <stddef.h> #include <stdlib.h> #include <string.h> -#include <unistd.h> #include <stdarg.h> #include <errno.h> -#include <math.h> +#ifdef AIO +#include <libaio.h> +#endif +#ifdef FALLOCATE +#include <linux/falloc.h> +#endif -#include "include/rados/librados.h" -#include "include/rbd/librbd.h" +#ifndef MAP_FILE +# define MAP_FILE 0 +#endif #define NUMPRINTCOLUMNS 32 /* # columns of data to print on each line */ @@ -77,28 +59,58 @@ int logptr = 0; /* current position in log */ int logcount = 0; /* total ops */ /* - * Define operations + * The operation matrix is complex due to conditional execution of different + * features. Hence when we come to deciding what operation to run, we need to + * be careful in how we select the different operations. The active operations + * are mapped to numbers as follows: + * + * lite !lite + * READ: 0 0 + * WRITE: 1 1 + * MAPREAD: 2 2 + * MAPWRITE: 3 3 + * TRUNCATE: - 4 + * FALLOCATE: - 5 + * PUNCH HOLE: - 6 + * + * When mapped read/writes are disabled, they are simply converted to normal + * reads and writes. When fallocate/fpunch calls are disabled, they are + * converted to OP_SKIPPED. Hence OP_SKIPPED needs to have a number higher than + * the operation selction matrix, as does the OP_CLOSEOPEN which is an + * operation modifier rather than an operation in itself. + * + * Because of the "lite" version, we also need to have different "maximum + * operation" defines to allow the ops to be selected correctly based on the + * mode being run. */ -#define OP_READ 1 -#define OP_WRITE 2 -#define OP_TRUNCATE 3 -#define OP_CLOSEOPEN 4 -#define OP_MAPREAD 5 -#define OP_MAPWRITE 6 -#define OP_SKIPPED 7 +/* common operations */ +#define OP_READ 0 +#define OP_WRITE 1 +#define OP_MAPREAD 2 +#define OP_MAPWRITE 3 +#define OP_MAX_LITE 4 -int page_size; -int page_mask; +/* !lite operations */ +#define OP_TRUNCATE 4 +#define OP_FALLOCATE 5 +#define OP_PUNCH_HOLE 6 +#define OP_MAX_FULL 7 + +/* operation modifiers */ +#define OP_CLOSEOPEN 100 +#define OP_SKIPPED 101 + +#undef PAGE_SIZE +#define PAGE_SIZE getpagesize() +#undef PAGE_MASK +#define PAGE_MASK (PAGE_SIZE - 1) char *original_buf; /* a pointer to the original data */ char *good_buf; /* a pointer to the correct data */ char *temp_buf; /* a pointer to the current data */ -char *pool; /* name of the pool our test image is in */ -char *iname; /* name of our test image */ -rados_t cluster; /* cluster handle */ -rados_ioctx_t ioctx; /* handle for our test pool */ -rbd_image_t image; /* handle for our test image */ +char *fname; /* name of our test file */ +int fd; /* fd for our test file */ off_t file_size = 0; off_t biggest = 0; @@ -109,6 +121,8 @@ unsigned long simulatedopcount = 0; /* -b flag */ int closeprob = 0; /* -c flag */ int debug = 0; /* -d flag */ unsigned long debugstart = 0; /* -D flag */ +int flush = 0; /* -f flag */ +int do_fsync = 0; /* -y flag */ unsigned long maxfilelen = 256 * 1024; /* -l flag */ int sizechecks = 1; /* -n flag disables them */ int maxoplen = 64 * 1024; /* -o flag */ @@ -116,6 +130,7 @@ int quiet = 0; /* -q flag */ unsigned long progressinterval = 0; /* -p flag */ int readbdy = 1; /* -r flag */ int style = 0; /* -s flag */ +int prealloc = 0; /* -x flag */ int truncbdy = 1; /* -t flag */ int writebdy = 1; /* -w flag */ long monitorstart = -1; /* -m flag */ @@ -124,57 +139,73 @@ int lite = 0; /* -L flag */ long numops = -1; /* -N flag */ int randomoplen = 1; /* -O flag disables it */ int seed = 1; /* -S flag */ -int mapped_writes = 1; /* -W flag disables */ +int mapped_writes = 1; /* -W flag disables */ +int fallocate_calls = 1; /* -F flag disables */ +int punch_hole_calls = 1; /* -H flag disables */ int mapped_reads = 1; /* -R flag disables it */ int fsxgoodfd = 0; +int o_direct; /* -Z */ +int aio = 0; + +int page_size; +int page_mask; +int mmap_mask; +#ifdef AIO +int aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset); +#define READ 0 +#define WRITE 1 +#define fsxread(a,b,c,d) aio_rw(READ, a,b,c,d) +#define fsxwrite(a,b,c,d) aio_rw(WRITE, a,b,c,d) +#else +#define fsxread(a,b,c,d) read(a,b,c) +#define fsxwrite(a,b,c,d) write(a,b,c) +#endif + FILE * fsxlogf = NULL; int badoff = -1; int closeopen = 0; +static void *round_ptr_up(void *ptr, unsigned long align, unsigned long offset) +{ + unsigned long ret = (unsigned long)ptr; + + ret = ((ret + align - 1) & ~(align - 1)); + ret += offset; + return (void *)ret; +} void -vwarnc(code, fmt, ap) - int code; - const char *fmt; - va_list ap; -{ - fprintf(stderr, "fsx: "); - if (fmt != NULL) { - vfprintf(stderr, fmt, ap); - fprintf(stderr, ": "); - } - fprintf(stderr, "%s\n", strerror(code)); +vwarnc(int code, const char *fmt, va_list ap) { + fprintf(stderr, "fsx: "); + if (fmt != NULL) { + vfprintf(stderr, fmt, ap); + fprintf(stderr, ": "); + } + fprintf(stderr, "%s\n", strerror(code)); } void -warn(const char * fmt, ...) -{ +warn(const char * fmt, ...) { va_list ap; va_start(ap, fmt); vwarnc(errno, fmt, ap); va_end(ap); } -void -simple_err(const char *msg, int err) -{ - fprintf(stderr, "%s: %s", msg, strerror(-err)); -} +#define BUF_SIZE 1024 void prt(char *fmt, ...) { va_list args; + char buffer[BUF_SIZE]; va_start(args, fmt); - vfprintf(stdout, fmt, args); + vsnprintf(buffer, BUF_SIZE, fmt, args); va_end(args); - - if (fsxlogf) { - va_start(args, fmt); - vfprintf(fsxlogf, fmt, args); - va_end(args); - } + fprintf(stdout, buffer); + if (fsxlogf) + fprintf(fsxlogf, buffer); } void @@ -183,11 +214,6 @@ prterr(char *prefix) prt("%s%s%s\n", prefix, prefix ? ": " : "", strerror(errno)); } -void -prterrcode(char *prefix, int code) -{ - prt("%s%s%s\n", prefix, prefix ? ": " : "", strerror(-code)); -} void log4(int operation, int arg0, int arg1, int arg2) @@ -213,6 +239,7 @@ logdump(void) { int i, count, down; struct log_entry *lp; + char *falloc_type[3] = {"PAST_EOF", "EXTENDING", "INTERIOR"}; prt("LOG DUMP (%d total operations):\n", logcount); if (logcount < LOGSIZE) { @@ -226,14 +253,14 @@ logdump(void) int opnum; opnum = i+1 + (logcount/LOGSIZE)*LOGSIZE; - prt("%d(%d mod 256): ", opnum, opnum%256); + prt("%d(%3d mod 256): ", opnum, opnum%256); lp = &oplog[i]; if ((closeopen = lp->operation < 0)) lp->operation = ~ lp->operation; switch (lp->operation) { case OP_MAPREAD: - prt("MAPREAD\t0x%x thru 0x%x\t(0x%x bytes)", + prt("MAPREAD 0x%x thru 0x%x\t(0x%x bytes)", lp->args[0], lp->args[0] + lp->args[1] - 1, lp->args[1]); if (badoff >= lp->args[0] && badoff < @@ -249,7 +276,7 @@ logdump(void) prt("\t******WWWW"); break; case OP_READ: - prt("READ\t0x%x thru 0x%x\t(0x%x bytes)", + prt("READ 0x%x thru 0x%x\t(0x%x bytes)", lp->args[0], lp->args[0] + lp->args[1] - 1, lp->args[1]); if (badoff >= lp->args[0] && @@ -257,7 +284,7 @@ logdump(void) prt("\t***RRRR***"); break; case OP_WRITE: - prt("WRITE\t0x%x thru 0x%x\t(0x%x bytes)", + prt("WRITE 0x%x thru 0x%x\t(0x%x bytes)", lp->args[0], lp->args[0] + lp->args[1] - 1, lp->args[1]); if (lp->args[0] > lp->args[2]) @@ -276,6 +303,23 @@ logdump(void) badoff < lp->args[!!down]) prt("\t******WWWW"); break; + case OP_FALLOCATE: + /* 0: offset 1: length 2: where alloced */ + prt("FALLOC 0x%x thru 0x%x\t(0x%x bytes) %s", + lp->args[0], lp->args[0] + lp->args[1], + lp->args[1], falloc_type[lp->args[2]]); + if (badoff >= lp->args[0] && + badoff < lp->args[0] + lp->args[1]) + prt("\t******FFFF"); + break; + case OP_PUNCH_HOLE: + prt("PUNCH 0x%x thru 0x%x\t(0x%x bytes)", + lp->args[0], lp->args[0] + lp->args[1] - 1, + lp->args[1]); + if (badoff >= lp->args[0] && badoff < + lp->args[0] + lp->args[1]) + prt("\t******PPPP"); + break; case OP_SKIPPED: prt("SKIPPED (no operation)"); break; @@ -294,12 +338,12 @@ logdump(void) void -save_buffer(char *buffer, off_t bufferlength, int image) +save_buffer(char *buffer, off_t bufferlength, int fd) { off_t ret; ssize_t byteswritten; - if (image <= 0 || bufferlength == 0) + if (fd <= 0 || bufferlength == 0) return; if (bufferlength > SSIZE_MAX) { @@ -307,7 +351,7 @@ save_buffer(char *buffer, off_t bufferlength, int image) exit(67); } if (lite) { - off_t size_by_seek = lseek(image, (off_t)0, SEEK_END); + off_t size_by_seek = lseek(fd, (off_t)0, SEEK_END); if (size_by_seek == (off_t)-1) prterr("save_buffer: lseek eof"); else if (bufferlength > size_by_seek) { @@ -317,11 +361,11 @@ save_buffer(char *buffer, off_t bufferlength, int image) } } - ret = lseek(image, (off_t)0, SEEK_SET); + ret = lseek(fd, (off_t)0, SEEK_SET); if (ret == (off_t)-1) prterr("save_buffer: lseek 0"); - byteswritten = write(image, buffer, (size_t)bufferlength); + byteswritten = write(fd, buffer, (size_t)bufferlength); if (byteswritten != bufferlength) { if (byteswritten == -1) prterr("save_buffer write"); @@ -343,7 +387,7 @@ report_failure(int status) save_buffer(good_buf, file_size, fsxgoodfd); prt("Correct content saved for comparison\n"); prt("(maybe hexdump \"%s\" vs \"%s.fsxgood\")\n", - iname, iname); + fname, fname); } close(fsxgoodfd); } @@ -352,7 +396,7 @@ report_failure(int status) #define short_at(cp) ((unsigned short)((*((unsigned char *)(cp)) << 8) | \ - *(((unsigned char *)(cp)) + 1))) + *(((unsigned char *)(cp)) + 1))) void check_buffers(unsigned offset, unsigned size) @@ -364,18 +408,27 @@ check_buffers(unsigned offset, unsigned size) unsigned bad = 0; if (memcmp(good_buf + offset, temp_buf, size) != 0) { - prt("READ BAD DATA: offset = 0x%x, size = 0x%x\n", - offset, size); + prt("READ BAD DATA: offset = 0x%x, size = 0x%x, fname = %s\n", + offset, size, fname); prt("OFFSET\tGOOD\tBAD\tRANGE\n"); while (size > 0) { c = good_buf[offset]; t = temp_buf[i]; if (c != t) { - if (n == 0) { + if (n < 16) { bad = short_at(&temp_buf[i]); - prt("0x%5x\t0x%04x\t0x%04x", offset, - short_at(&good_buf[offset]), bad); + prt("0x%5x\t0x%04x\t0x%04x", offset, + short_at(&good_buf[offset]), bad); op = temp_buf[offset & 1 ? i+1 : i]; + prt("\t0x%5x\n", n); + if (op) + prt("operation# (mod 256) for " + "the bad data may be %u\n", + ((unsigned)op & 0xff)); + else + prt("operation# (mod 256) for " + "the bad data unknown, check" + " HOLE and EXTEND ops\n"); } n++; badoff = offset; @@ -384,14 +437,6 @@ check_buffers(unsigned offset, unsigned size) i++; size--; } - if (n) { - prt("\t0x%5x\n", n); - if (bad) - prt("operation# (mod 256) for the bad data may be %u\n", ((unsigned)op & 0xff)); - else - prt("operation# (mod 256) for the bad data unknown, check HOLE and EXTEND ops\n"); - } else - prt("????????????????\n"); report_failure(110); } } @@ -400,16 +445,19 @@ check_buffers(unsigned offset, unsigned size) void check_size(void) { - rbd_image_info_t statbuf; - int ret; + struct stat statbuf; + off_t size_by_seek; - if ((ret = rbd_stat(image, &statbuf, sizeof(statbuf))) < 0) { - prterrcode("check_size: fstat", ret); + if (fstat(fd, &statbuf)) { + prterr("check_size: fstat"); + statbuf.st_size = -1; } - if ((unsigned)file_size != statbuf.size) { - prt("Size error: expected 0x%llx stat 0x%llx\n", + size_by_seek = lseek(fd, (off_t)0, SEEK_END); + if (file_size != statbuf.st_size || file_size != size_by_seek) { + prt("Size error: expected 0x%llx stat 0x%llx seek 0x%llx\n", (unsigned long long)file_size, - (unsigned long long)statbuf.size); + (unsigned long long)statbuf.st_size, + (unsigned long long)size_by_seek); report_failure(120); } } @@ -418,89 +466,58 @@ check_size(void) void check_trunc_hack(void) { - rbd_image_info_t statbuf; + struct stat statbuf; - rbd_resize(image, (off_t)0); - rbd_resize(image, (off_t)100000); - rbd_stat(image, &statbuf, sizeof(statbuf)); - if (statbuf.size != (off_t)100000) { + ftruncate(fd, (off_t)0); + ftruncate(fd, (off_t)100000); + fstat(fd, &statbuf); + if (statbuf.st_size != (off_t)100000) { prt("no extend on truncate! not posix!\n"); exit(130); } - rbd_resize(image, (off_t)0); + ftruncate(fd, 0); } - -int -create_image() +void +doflush(unsigned offset, unsigned size) { - int r; - int order = 0; - r = rados_create(&cluster, NULL); - if (r < 0) { - simple_err("Could not create cluster handle", r); - return r; - } - rados_conf_parse_env(cluster, NULL); - r = rados_conf_read_file(cluster, NULL); - if (r < 0) { - simple_err("Error reading ceph config file", r); - goto failed_shutdown; - } - r = rados_connect(cluster); - if (r < 0) { - simple_err("Error connecting to cluster", r); - goto failed_shutdown; - } - r = rados_pool_create(cluster, pool); - if (r < 0) { - simple_err("Error creating pool", r); - goto failed_shutdown; - } - r = rados_ioctx_create(cluster, pool, &ioctx); - if (r < 0) { - simple_err("Error creating ioctx", r); - goto failed_pool; - } - r = rbd_create(ioctx, iname, 0, &order); - if (r < 0) { - simple_err("Error creating image", r); - goto failed_open; - } + unsigned pg_offset; + unsigned map_size; + char *p; - return 0; - - failed_open: - rados_ioctx_destroy(ioctx); - failed_pool: - rados_pool_delete(cluster, pool); - failed_shutdown: - rados_shutdown(cluster); - return r; -} + if (o_direct == O_DIRECT) + return; -void delete_image() -{ - rbd_remove(ioctx, iname); - rados_ioctx_destroy(ioctx); - rados_pool_delete(cluster, pool); - rados_shutdown(cluster); -} + pg_offset = offset & mmap_mask; + map_size = pg_offset + size; -void cleanup_image() -{ - rbd_close(image); - delete_image(); + if ((p = (char *)mmap(0, map_size, PROT_READ | PROT_WRITE, + MAP_FILE | MAP_SHARED, fd, + (off_t)(offset - pg_offset))) == (char *)-1) { + prterr("doflush: mmap"); + report_failure(202); + } + if (msync(p, map_size, MS_INVALIDATE) != 0) { + prterr("doflush: msync"); + report_failure(203); + } + if (munmap(p, map_size) != 0) { + prterr("doflush: munmap"); + report_failure(204); + } } void doread(unsigned offset, unsigned size) { - int ret; + off_t ret; + unsigned iret; offset -= offset % readbdy; + if (o_direct) + size -= size % readbdy; if (size == 0) { - if (!quiet && testcalls > simulatedopcount) + if (!quiet && testcalls > simulatedopcount && !o_direct) prt("skipping zero size read\n"); log4(OP_SKIPPED, OP_READ, offset, size); return; @@ -517,30 +534,36 @@ doread(unsigned offset, unsigned size) if (testcalls <= simulatedopcount) return; - if (!quiet && ((progressinterval && - testcalls % progressinterval == 0) || - (debug && - (monitorstart == -1 || - (offset + size > monitorstart && - (monitorend == -1 || offset <= monitorend)))))) + if (!quiet && + ((progressinterval && testcalls % progressinterval == 0) || + (debug && + (monitorstart == -1 || + (offset + size > monitorstart && + (monitorend == -1 || offset <= monitorend)))))) prt("%lu read\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls, offset, offset + size - 1, size); - ret = rbd_read(image, offset, size, temp_buf); - if (ret != (int)size) { - if (ret < 0) - prterrcode("doread: read", ret); + ret = lseek(fd, (off_t)offset, SEEK_SET); + if (ret == (off_t)-1) { + prterr("doread: lseek"); + report_failure(140); + } + iret = fsxread(fd, temp_buf, size, offset); + if (iret != size) { + if (iret == -1) + prterr("doread: read"); else prt("short read: 0x%x bytes instead of 0x%x\n", - ret, size); + iret, size); report_failure(141); } check_buffers(offset, size); } + void check_eofpage(char *s, unsigned offset, char *p, int size) { - uintptr_t last_page, should_be_zero; + unsigned long last_page, should_be_zero; if (offset + size <= (file_size & ~page_mask)) return; @@ -550,7 +573,7 @@ check_eofpage(char *s, unsigned offset, char *p, int size) * beyond the true end of the file mapping * (as required by mmap def in 1996 posix 1003.1) */ - last_page = ((uintptr_t)p + (offset & page_mask) + size) & ~page_mask; + last_page = ((unsigned long)p + (offset & page_mask) + size) & ~page_mask; for (should_be_zero = last_page + (file_size & page_mask); should_be_zero < last_page + page_size; @@ -565,6 +588,62 @@ check_eofpage(char *s, unsigned offset, char *p, int size) void +domapread(unsigned offset, unsigned size) +{ + unsigned pg_offset; + unsigned map_size; + char *p; + + offset -= offset % readbdy; + if (size == 0) { + if (!quiet && testcalls > simulatedopcount) + prt("skipping zero size read\n"); + log4(OP_SKIPPED, OP_MAPREAD, offset, size); + return; + } + if (size + offset > file_size) { + if (!quiet && testcalls > simulatedopcount) + prt("skipping seek/read past end of file\n"); + log4(OP_SKIPPED, OP_MAPREAD, offset, size); + return; + } + + log4(OP_MAPREAD, offset, size, 0); + + if (testcalls <= simulatedopcount) + return; + + if (!quiet && + ((progressinterval && testcalls % progressinterval == 0) || + (debug && + (monitorstart == -1 || + (offset + size > monitorstart && + (monitorend == -1 || offset <= monitorend)))))) + prt("%lu mapread\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls, + offset, offset + size - 1, size); + + pg_offset = offset & PAGE_MASK; + map_size = pg_offset + size; + + if ((p = (char *)mmap(0, map_size, PROT_READ, MAP_SHARED, fd, + (off_t)(offset - pg_offset))) == (char *)-1) { + prterr("domapread: mmap"); + report_failure(190); + } + memcpy(temp_buf, p + pg_offset, size); + + check_eofpage("Read", offset, p, size); + + if (munmap(p, map_size) != 0) { + prterr("domapread: munmap"); + report_failure(191); + } + + check_buffers(offset, size); +} + + +void gendata(char *original_buf, char *good_buf, unsigned offset, unsigned size) { while (size--) { @@ -579,12 +658,14 @@ gendata(char *original_buf, char *good_buf, unsigned offset, unsigned size) void dowrite(unsigned offset, unsigned size) { - ssize_t ret; - off_t newsize; + off_t ret; + unsigned iret; offset -= offset % writebdy; + if (o_direct) + size -= size % writebdy; if (size == 0) { - if (!quiet && testcalls > simulatedopcount) + if (!quiet && testcalls > simulatedopcount && !o_direct) prt("skipping zero size write\n"); log4(OP_SKIPPED, OP_WRITE, offset, size); return; @@ -594,44 +675,121 @@ dowrite(unsigned offset, unsigned size) gendata(original_buf, good_buf, offset, size); if (file_size < offset + size) { - newsize = ceil(((double)offset + size) / truncbdy) * truncbdy; - if (file_size < newsize) - memset(good_buf + file_size, '\0', newsize - file_size); - file_size = newsize; + if (file_size < offset) + memset(good_buf + file_size, '\0', offset - file_size); + file_size = offset + size; if (lite) { warn("Lite file size bug in fsx!"); report_failure(149); } - ret = rbd_resize(image, newsize); - if (ret < 0) { - prterrcode("dowrite: resize", ret); - report_failure(150); - } else { - prt("resized to 0x%x ", newsize); - } } if (testcalls <= simulatedopcount) return; - if (!quiet && ((progressinterval && - testcalls % progressinterval == 0) || + if (!quiet && + ((progressinterval && testcalls % progressinterval == 0) || (debug && - (monitorstart == -1 || - (offset + size > monitorstart && - (monitorend == -1 || offset <= monitorend)))))) + (monitorstart == -1 || + (offset + size > monitorstart && + (monitorend == -1 || offset <= monitorend)))))) prt("%lu write\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls, offset, offset + size - 1, size); - - ret = rbd_write(image, offset, size, good_buf + offset); - if (ret != size) { - if (ret < 0) - prterrcode("dowrite: rbd_write", ret); + ret = lseek(fd, (off_t)offset, SEEK_SET); + if (ret == (off_t)-1) { + prterr("dowrite: lseek"); + report_failure(150); + } + iret = fsxwrite(fd, good_buf + offset, size, offset); + if (iret != size) { + if (iret == -1) + prterr("dowrite: write"); else prt("short write: 0x%x bytes instead of 0x%x\n", - ret, size); + iret, size); report_failure(151); } + if (do_fsync) { + if (fsync(fd)) { + prt("fsync() failed: %s\n", strerror(errno)); + report_failure(152); + } + } + if (flush) { + doflush(offset, size); + } +} + + +void +domapwrite(unsigned offset, unsigned size) +{ + unsigned pg_offset; + unsigned map_size; + off_t cur_filesize; + char *p; + + offset -= offset % writebdy; + if (size == 0) { + if (!quiet && testcalls > simulatedopcount) + prt("skipping zero size write\n"); + log4(OP_SKIPPED, OP_MAPWRITE, offset, size); + return; + } + cur_filesize = file_size; + + log4(OP_MAPWRITE, offset, size, 0); + + gendata(original_buf, good_buf, offset, size); + if (file_size < offset + size) { + if (file_size < offset) + memset(good_buf + file_size, '\0', offset - file_size); + file_size = offset + size; + if (lite) { + warn("Lite file size bug in fsx!"); + report_failure(200); + } + } + + if (testcalls <= simulatedopcount) + return; + + if (!quiet && + ((progressinterval && testcalls % progressinterval == 0) || + (debug && + (monitorstart == -1 || + (offset + size > monitorstart && + (monitorend == -1 || offset <= monitorend)))))) + prt("%lu mapwrite\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls, + offset, offset + size - 1, size); + + if (file_size > cur_filesize) { + if (ftruncate(fd, file_size) == -1) { + prterr("domapwrite: ftruncate"); + exit(201); + } + } + pg_offset = offset & PAGE_MASK; + map_size = pg_offset + size; + + if ((p = (char *)mmap(0, map_size, PROT_READ | PROT_WRITE, + MAP_FILE | MAP_SHARED, fd, + (off_t)(offset - pg_offset))) == (char *)-1) { + prterr("domapwrite: mmap"); + report_failure(202); + } + memcpy(p + pg_offset, good_buf + offset, size); + if (msync(p, map_size, 0) != 0) { + prterr("domapwrite: msync"); + report_failure(203); + } + + check_eofpage("Write", offset, p, size); + + if (munmap(p, map_size) != 0) { + prterr("domapwrite: munmap"); + report_failure(204); + } } @@ -639,7 +797,6 @@ void dotruncate(unsigned size) { int oldsize = file_size; - int ret; size -= size % truncbdy; if (size > biggest) { @@ -652,8 +809,6 @@ dotruncate(unsigned size) if (size > file_size) memset(good_buf + file_size, '\0', size - file_size); - else if (size < file_size) - memset(good_buf + size, '\0', file_size - size); file_size = size; if (testcalls <= simulatedopcount) @@ -661,33 +816,153 @@ dotruncate(unsigned size) if ((progressinterval && testcalls % progressinterval == 0) || (debug && (monitorstart == -1 || monitorend == -1 || - size <= monitorend))) + size <= monitorend))) prt("%lu trunc\tfrom 0x%x to 0x%x\n", testcalls, oldsize, size); - if ((ret = rbd_resize(image, size)) < 0) { - prt("rbd_resize: %x\n", size); - prterrcode("dotruncate: ftruncate", ret); + if (ftruncate(fd, (off_t)size) == -1) { + prt("ftruncate1: %x\n", size); + prterr("dotruncate: ftruncate"); report_failure(160); } } +#ifdef FALLOC_FL_PUNCH_HOLE +void +do_punch_hole(unsigned offset, unsigned length) +{ + unsigned end_offset; + int max_offset = 0; + int max_len = 0; + int mode = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE; + + if (length == 0) { + if (!quiet && testcalls > simulatedopcount) + prt("skipping zero length punch hole\n"); + log4(OP_SKIPPED, OP_PUNCH_HOLE, offset, length); + return; + } + + if (file_size <= (loff_t)offset) { + if (!quiet && testcalls > simulatedopcount) + prt("skipping hole punch off the end of the file\n"); + log4(OP_SKIPPED, OP_PUNCH_HOLE, offset, length); + return; + } + + end_offset = offset + length; + + log4(OP_PUNCH_HOLE, offset, length, 0); + + if (testcalls <= simulatedopcount) + return; + + if ((progressinterval && testcalls % progressinterval == 0) || + (debug && (monitorstart == -1 || monitorend == -1 || + end_offset <= monitorend))) { + prt("%lu punch\tfrom 0x%x to 0x%x, (0x%x bytes)\n", testcalls, + offset, offset+length, length); + } + if (fallocate(fd, mode, (loff_t)offset, (loff_t)length) == -1) { + prt("%punch hole: %x to %x\n", offset, length); + prterr("do_punch_hole: fallocate"); + report_failure(161); + } + + + max_offset = offset < file_size ? offset : file_size; + max_len = max_offset + length <= file_size ? length : + file_size - max_offset; + memset(good_buf + max_offset, '\0', max_len); +} + +#else +void +do_punch_hole(unsigned offset, unsigned length) +{ + return; +} +#endif + +#ifdef FALLOCATE +/* fallocate is basically a no-op unless extending, then a lot like a truncate */ +void +do_preallocate(unsigned offset, unsigned length) +{ + unsigned end_offset; + int keep_size; + + if (length == 0) { + if (!quiet && testcalls > simulatedopcount) + prt("skipping zero length fallocate\n"); + log4(OP_SKIPPED, OP_FALLOCATE, offset, length); + return; + } + + keep_size = random() % 2; + + end_offset = keep_size ? 0 : offset + length; + + if (end_offset > biggest) { + biggest = end_offset; + if (!quiet && testcalls > simulatedopcount) + prt("fallocating to largest ever: 0x%x\n", end_offset); + } + + /* + * last arg matches fallocate string array index in logdump: + * 0: allocate past EOF + * 1: extending prealloc + * 2: interior prealloc + */ + log4(OP_FALLOCATE, offset, length, (end_offset > file_size) ? (keep_size ? 0 : 1) : 2); + + if (end_offset > file_size) { + memset(good_buf + file_size, '\0', end_offset - file_size); + file_size = end_offset; + } + + if (testcalls <= simulatedopcount) + return; + + if ((progressinterval && testcalls % progressinterval == 0) || + (debug && (monitorstart == -1 || monitorend == -1 || + end_offset <= monitorend))) + prt("%lu falloc\tfrom 0x%x to 0x%x (0x%x bytes)\n", testcalls, + offset, offset + length, length); + if (fallocate(fd, keep_size ? FALLOC_FL_KEEP_SIZE : 0, (loff_t)offset, (loff_t)length) == -1) { + prt("fallocate: %x to %x\n", offset, length); + prterr("do_preallocate: fallocate"); + report_failure(161); + } +} +#else +void +do_preallocate(unsigned offset, unsigned length) +{ + return; +} +#endif void writefileimage() { - ssize_t ret; + ssize_t iret; - ret = rbd_write(image, 0, file_size, good_buf); - if (ret != file_size) { - if (ret < 0) - prterrcode("writefileimage: write", ret); + if (lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) { + prterr("writefileimage: lseek"); + report_failure(171); + } + iret = write(fd, good_buf, file_size); + if ((off_t)iret != file_size) { + if (iret == -1) + prterr("writefileimage: write"); else prt("short write: 0x%x bytes instead of 0x%llx\n", - ret, (unsigned long long)file_size); + iret, (unsigned long long)file_size); report_failure(172); } - if (lite ? 0 : (ret = rbd_resize(image, file_size)) < 0) { - prt("rbd_resize: %llx\n", (unsigned long long)file_size); - prterrcode("writefileimage: rbd_resize", ret); + if (lite ? 0 : ftruncate(fd, file_size) == -1) { + prt("ftruncate2: %llx\n", (unsigned long long)file_size); + prterr("writefileimage: ftruncate"); report_failure(173); } } @@ -695,24 +970,32 @@ writefileimage() void docloseopen(void) -{ - int ret; +{ if (testcalls <= simulatedopcount) return; if (debug) prt("%lu close/open\n", testcalls); - if ((ret = rbd_close(image)) < 0) { - prterrcode("docloseopen: close", ret); + if (close(fd)) { + prterr("docloseopen: close"); report_failure(180); } - ret = rbd_open(ioctx, iname, &image, NULL); - if (ret < 0) { - prterrcode("docloseopen: open", ret); + fd = open(fname, O_RDWR|o_direct, 0); + if (fd < 0) { + prterr("docloseopen: open"); report_failure(181); } } +#define TRIM_OFF_LEN(off, len, size) \ +do { \ + if (size) \ + (off) %= (size); \ + else \ + (off) = 0; \ + if ((off) + (len) > (size)) \ + (len) = (size) - (off); \ +} while (0) void test(void) @@ -720,12 +1003,7 @@ test(void) unsigned long offset; unsigned long size = maxoplen; unsigned long rv = random(); - unsigned long op = rv % (3 + !lite + mapped_writes); - - /* turn off the map read if necessary */ - - if (op == 2 && !mapped_reads) - op = 0; + unsigned long op; if (simulatedopcount > 0 && testcalls == simulatedopcount) writefileimage(); @@ -733,7 +1011,7 @@ test(void) testcalls++; if (closeprob) - closeopen = (rv >> 3) < (1ul << 28) / closeprob; + closeopen = (rv >> 3) < (1 << 28) / closeprob; if (debugstart > 0 && testcalls >= debugstart) debug = 1; @@ -741,44 +1019,82 @@ test(void) if (!quiet && testcalls < simulatedopcount && testcalls % 100000 == 0) prt("%lu...\n", testcalls); - /* - * READ: op = 0 - * WRITE: op = 1 - * MAPREAD: op = 2 - * TRUNCATE: op = 3 - * MAPWRITE: op = 3 or 4 - */ - if (lite ? 0 : op == 3 && style == 0) /* vanilla truncate? */ - dotruncate(random() % maxfilelen); - else { - if (randomoplen) - size = random() % (maxoplen+1); - if (lite ? 0 : op == 3) - dotruncate(size); - else { - offset = random(); - if (op == 1 || op == (lite ? 3 : 4)) { - offset %= maxfilelen; - if (offset + size > maxfilelen) - size = maxfilelen - offset; - if (op != 1) - exit(182); - else - dowrite(offset, size); - } else { - if (file_size) - offset %= file_size; - else - offset = 0; - if (offset + size > (unsigned long)file_size) - size = file_size - offset; - if (op != 0) - exit(183); - else - doread(offset, size); - } + offset = random(); + if (randomoplen) + size = random() % (maxoplen + 1); + + /* calculate appropriate op to run */ + if (lite) + op = rv % OP_MAX_LITE; + else + op = rv % OP_MAX_FULL; + + switch (op) { + case OP_MAPREAD: + if (!mapped_reads) + op = OP_READ; + break; + case OP_MAPWRITE: + if (!mapped_writes) + op = OP_WRITE; + break; + case OP_FALLOCATE: + if (!fallocate_calls) { + log4(OP_SKIPPED, OP_FALLOCATE, offset, size); + goto out; + } + break; + case OP_PUNCH_HOLE: + if (!punch_hole_calls) { + log4(OP_SKIPPED, OP_PUNCH_HOLE, offset, size); + goto out; } + break; } + + switch (op) { + case OP_READ: + TRIM_OFF_LEN(offset, size, file_size); + doread(offset, size); + break; + + case OP_WRITE: + TRIM_OFF_LEN(offset, size, maxfilelen); + dowrite(offset, size); + break; + + case OP_MAPREAD: + TRIM_OFF_LEN(offset, size, file_size); + domapread(offset, size); + break; + + case OP_MAPWRITE: + TRIM_OFF_LEN(offset, size, maxfilelen); + domapwrite(offset, size); + break; + + case OP_TRUNCATE: + if (!style) + size = random() % maxfilelen; + dotruncate(size); + break; + + case OP_FALLOCATE: + TRIM_OFF_LEN(offset, size, maxfilelen); + do_preallocate(offset, size); + break; + + case OP_PUNCH_HOLE: + TRIM_OFF_LEN(offset, size, file_size); + do_punch_hole(offset, size); + break; + default: + prterr("test: unknown operation"); + report_failure(42); + break; + } + +out: if (sizechecks && testcalls > simulatedopcount) check_size(); if (closeopen) @@ -801,10 +1117,11 @@ void usage(void) { fprintf(stdout, "usage: %s", - "fsx [-dnqLOW] [-b opnum] [-c Prob] [-l flen] [-m start:end] [-o oplen] [-p progressinterval] [-r readbdy] [-s style] [-t truncbdy] [-w writebdy] [-D startingop] [-N numops] [-P dirpath] [-S seed] iname\n\ + "fsx [-dnqxAFLOWZ] [-b opnum] [-c Prob] [-l flen] [-m start:end] [-o oplen] [-p progressinterval] [-r readbdy] [-s style] [-t truncbdy] [-w writebdy] [-D startingop] [-N numops] [-P dirpath] [-S seed] fname\n\ -b opnum: beginning operation number (default 1)\n\ -c P: 1 in P chance of file close+open at each op (default infinity)\n\ -d: debug output for all operations\n\ + -f flush and invalidate cache after I/O\n\ -l flen: the upper bound on file size (default 262144)\n\ -m startop:endop: monitor (print debug output) specified byte range (default 0:infinity)\n\ -n: no verifications of file size\n\ @@ -815,24 +1132,36 @@ usage(void) -s style: 1 gives smaller truncates (default 0)\n\ -t truncbdy: 4096 would make truncates page aligned (default 1)\n\ -w writebdy: 4096 would make writes page aligned (default 1)\n\ - -D startingop: debug output starting at specified operation\n\ - -L: fsxLite - no file creations & no file size changes\n\ + -x: preallocate file space before starting, XFS only (default 0)\n\ + -y synchronize changes to a file\n" + +#ifdef AIO +" -A: Use the AIO system calls\n" +#endif +" -D startingop: debug output starting at specified operation\n" +#ifdef FALLOCATE +" -F: Do not use fallocate (preallocation) calls\n" +#endif +#ifdef FALLOC_FL_PUNCH_HOLE +" -H: Do not use punch hole calls\n" +#endif +" -L: fsxLite - no file creations & no file size changes\n\ -N numops: total # operations to do (default infinity)\n\ -O: use oplen (see -o flag) for every op (default random)\n\ - -P dirpath: save .fsxlog and .fsxgood files in dirpath (default ./)\n\ + -P: save .fsxlog and .fsxgood files in dirpath (default ./)\n\ -S seed: for random # generator (default 1) 0 gets timestamp\n\ -W: mapped write operations DISabled\n\ - -R: mapped read operations DISabled)\n\ - poolname: this is REQUIRED (no default)\n\ - imagename: this is REQUIRED (no default)\n"); - exit(89); + -R: read() system calls only (mapped reads disabled)\n\ + -Z: O_DIRECT (use -R, -W, -r and -w too)\n\ + fname: this filename is REQUIRED (no default)\n"); + exit(90); } int getnum(char *s, char **e) { - int ret = -1; + int ret; *e = (char *) 0; ret = strtol(s, e, 0); @@ -862,10 +1191,149 @@ getnum(char *s, char **e) return (ret); } +#ifdef AIO + +#define QSZ 1024 +io_context_t io_ctx; +struct iocb iocb; + +int aio_setup() +{ + int ret; + ret = io_queue_init(QSZ, &io_ctx); + if (ret != 0) { + fprintf(stderr, "aio_setup: io_queue_init failed: %s\n", + strerror(ret)); + return(-1); + } + return(0); +} + +int +__aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset) +{ + struct io_event event; + static struct timespec ts; + struct iocb *iocbs[] = { &iocb }; + int ret; + long res; + + if (rw == READ) { + io_prep_pread(&iocb, fd, buf, len, offset); + } else { + io_prep_pwrite(&iocb, fd, buf, len, offset); + } + + ts.tv_sec = 30; + ts.tv_nsec = 0; + ret = io_submit(io_ctx, 1, iocbs); + if (ret != 1) { + fprintf(stderr, "errcode=%d\n", ret); + fprintf(stderr, "aio_rw: io_submit failed: %s\n", + strerror(ret)); + goto out_error; + } + + ret = io_getevents(io_ctx, 1, 1, &event, &ts); + if (ret != 1) { + if (ret == 0) + fprintf(stderr, "aio_rw: no events available\n"); + else { + fprintf(stderr, "errcode=%d\n", -ret); + fprintf(stderr, "aio_rw: io_getevents failed: %s\n", + strerror(-ret)); + } + goto out_error; + } + if (len != event.res) { + /* + * The b0rked libaio defines event.res as unsigned. + * However the kernel strucuture has it signed, + * and it's used to pass negated error value. + * Till the library is fixed use the temp var. + */ + res = (long)event.res; + if (res >= 0) + fprintf(stderr, "bad io length: %lu instead of %u\n", + res, len); + else { + fprintf(stderr, "errcode=%ld\n", -res); + fprintf(stderr, "aio_rw: async io failed: %s\n", + strerror(-res)); + ret = res; + goto out_error; + } + + } + return event.res; + +out_error: + /* + * The caller expects error return in traditional libc + * convention, i.e. -1 and the errno set to error. + */ + errno = -ret; + return -1; +} + +int aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset) +{ + int ret; + + if (aio) { + ret = __aio_rw(rw, fd, buf, len, offset); + } else { + if (rw == READ) + ret = read(fd, buf, len); + else + ret = write(fd, buf, len); + } + return ret; +} + +#endif + +void +test_fallocate() +{ +#ifdef FALLOCATE + if (!lite && fallocate_calls) { + if (fallocate(fd, 0, 0, 1) && errno == EOPNOTSUPP) { + if(!quiet) + warn("main: filesystem does not support fallocate, disabling\n"); + fallocate_calls = 0; + } else { + ftruncate(fd, 0); + } + } +#else /* ! FALLOCATE */ + fallocate_calls = 0; +#endif + +} + +void +test_punch_hole() +{ +#ifdef FALLOC_FL_PUNCH_HOLE + if (!lite && punch_hole_calls) { + if (fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, + 0, 1) && errno == EOPNOTSUPP) { + if(!quiet) + warn("main: filesystem does not support fallocate punch hole, disabling"); + punch_hole_calls = 0; + } else + ftruncate(fd, 0); + } +#else /* ! PUNCH HOLE */ + punch_hole_calls = 0; +#endif +} + int main(int argc, char **argv) { - int i, ch, ret; + int i, style, ch; char *endp; char goodfile[1024]; char logfile[1024]; @@ -875,11 +1343,13 @@ main(int argc, char **argv) page_size = getpagesize(); page_mask = page_size - 1; + mmap_mask = page_mask; + setvbuf(stdout, (char *)0, _IOLBF, 0); /* line buffered stdout */ - while ((ch = getopt(argc, argv, "b:c:dl:m:no:p:qr:s:t:w:D:LN:OP:RS:W")) - != -1) + while ((ch = getopt(argc, argv, "b:c:dfl:m:no:p:qr:s:t:w:xyAD:FHLN:OP:RS:WZ")) + != EOF) switch (ch) { case 'b': simulatedopcount = getnum(optarg, &endp); @@ -902,6 +1372,9 @@ main(int argc, char **argv) case 'd': debug = 1; break; + case 'f': + flush = 1; + break; case 'l': maxfilelen = getnum(optarg, &endp); if (maxfilelen <= 0) @@ -929,6 +1402,8 @@ main(int argc, char **argv) break; case 'p': progressinterval = getnum(optarg, &endp); + if (progressinterval == 0) + usage(); break; case 'q': quiet = 1; @@ -953,15 +1428,28 @@ main(int argc, char **argv) if (writebdy <= 0) usage(); break; + case 'x': + prealloc = 1; + break; + case 'y': + do_fsync = 1; + break; + case 'A': + aio = 1; + break; case 'D': debugstart = getnum(optarg, &endp); if (debugstart < 1) usage(); break; + case 'F': + fallocate_calls = 0; + break; + case 'H': + punch_hole_calls = 0; + break; case 'L': - lite = 1; - prt("lite mode not supported for rbd"); - exit(1); + lite = 1; break; case 'N': numops = getnum(optarg, &endp); @@ -977,11 +1465,11 @@ main(int argc, char **argv) strncpy(logfile, optarg, sizeof(logfile)); strcat(logfile, "/"); break; - case 'R': - mapped_reads = 0; - break; + case 'R': + mapped_reads = 0; + break; case 'S': - seed = getnum(optarg, &endp); + seed = getnum(optarg, &endp); if (seed == 0) seed = time(0) % 10000; if (!quiet) @@ -990,21 +1478,22 @@ main(int argc, char **argv) usage(); break; case 'W': - mapped_writes = 0; + mapped_writes = 0; if (!quiet) fprintf(stdout, "mapped writes DISABLED\n"); break; - + case 'Z': + o_direct = O_DIRECT; + break; default: usage(); /* NOTREACHED */ } argc -= optind; argv += optind; - if (argc != 2) + if (argc != 1) usage(); - pool = argv[0]; - iname = argv[1]; + fname = argv[0]; signal(SIGHUP, cleanup); signal(SIGINT, cleanup); @@ -1019,60 +1508,101 @@ main(int argc, char **argv) initstate(seed, state, 256); setstate(state); - - ret = create_image(); - if (ret < 0) { - prterrcode(iname, ret); - exit(90); - } - ret = rbd_open(ioctx, iname, &image, NULL); - if (ret < 0) { - simple_err("Error opening image", ret); - delete_image(); + fd = open(fname, + O_RDWR|(lite ? 0 : O_CREAT|O_TRUNC)|o_direct, 0666); + if (fd < 0) { + prterr(fname); exit(91); } - atexit(cleanup_image); - - strncat(goodfile, iname, 256); +#ifdef XFS + if (prealloc) { + xfs_flock64_t resv = { 0 }; +#ifdef HAVE_XFS_PLATFORM_DEFS_H + if (!platform_test_xfs_fd(fd)) { + prterr(fname); + fprintf(stderr, "main: cannot prealloc, non XFS\n"); + exit(96); + } +#endif + resv.l_len = maxfilelen; + if ((xfsctl(fname, fd, XFS_IOC_RESVSP, &resv)) < 0) { + prterr(fname); + exit(97); + } + } +#endif + strncat(goodfile, fname, 256); strcat (goodfile, ".fsxgood"); fsxgoodfd = open(goodfile, O_RDWR|O_CREAT|O_TRUNC, 0666); if (fsxgoodfd < 0) { prterr(goodfile); exit(92); } - strncat(logfile, iname, 256); + strncat(logfile, fname, 256); strcat (logfile, ".fsxlog"); fsxlogf = fopen(logfile, "w"); if (fsxlogf == NULL) { prterr(logfile); exit(93); } + +#ifdef AIO + if (aio) + aio_setup(); +#endif + + if (lite) { + off_t ret; + file_size = maxfilelen = lseek(fd, (off_t)0, SEEK_END); + if (file_size == (off_t)-1) { + prterr(fname); + warn("main: lseek eof"); + exit(94); + } + ret = lseek(fd, (off_t)0, SEEK_SET); + if (ret == (off_t)-1) { + prterr(fname); + warn("main: lseek 0"); + exit(95); + } + } original_buf = (char *) malloc(maxfilelen); - for (i = 0; i < (int)maxfilelen; i++) + for (i = 0; i < maxfilelen; i++) original_buf[i] = random() % 256; - good_buf = (char *) malloc(maxfilelen); + good_buf = (char *) malloc(maxfilelen + writebdy); + good_buf = round_ptr_up(good_buf, writebdy, 0); memset(good_buf, '\0', maxfilelen); - temp_buf = (char *) malloc(maxoplen); + temp_buf = (char *) malloc(maxoplen + readbdy); + temp_buf = round_ptr_up(temp_buf, readbdy, 0); memset(temp_buf, '\0', maxoplen); if (lite) { /* zero entire existing file */ ssize_t written; - written = rbd_write(image, 0, (size_t)maxfilelen, good_buf); - if (written != (int)maxfilelen) { - if (written < 0) { - prterrcode(iname, written); + written = write(fd, good_buf, (size_t)maxfilelen); + if (written != maxfilelen) { + if (written == -1) { + prterr(fname); warn("main: error on write"); } else - warn("main: short write, 0x%x bytes instead of 0x%x\n", - (unsigned)written, maxfilelen); + warn("main: short write, 0x%x bytes instead " + "of 0x%lx\n", + (unsigned)written, + maxfilelen); exit(98); } } else check_trunc_hack(); + test_fallocate(); + test_punch_hole(); + while (numops == -1 || numops--) test(); + if (close(fd)) { + prterr("close"); + report_failure(99); + } prt("All operations completed A-OK!\n"); exit(0); |