From ca4ede505bfe805b07bfa81fb0bc06609da90399 Mon Sep 17 00:00:00 2001 From: ngie Date: Thu, 16 Apr 2015 08:05:56 +0000 Subject: - Fix style(9) a bit -- Fix whitespace -- Use err/errx -- Remove superfluous braces - Be a bit more defensive with input from the end-user - Don't die dividing by 0 on a zero-byte file --- tools/regression/aio/aiop/Makefile | 2 + tools/regression/aio/aiop/aiop.c | 112 ++++++++++++++++++------------------- 2 files changed, 57 insertions(+), 57 deletions(-) diff --git a/tools/regression/aio/aiop/Makefile b/tools/regression/aio/aiop/Makefile index aac9a3b..38d9db6 100644 --- a/tools/regression/aio/aiop/Makefile +++ b/tools/regression/aio/aiop/Makefile @@ -3,4 +3,6 @@ PROG= aiop MAN= +WARNS= 6 + .include diff --git a/tools/regression/aio/aiop/aiop.c b/tools/regression/aio/aiop/aiop.c index 3e64dbe..98a176e 100644 --- a/tools/regression/aio/aiop/aiop.c +++ b/tools/regression/aio/aiop/aiop.c @@ -39,21 +39,22 @@ #include __FBSDID("$FreeBSD$"); -#include -#include -#include -#include -#include #include -#include -#include -#include #include +#include +#include +#include #include +#include +#include +#include #include +#include +#include +#include #include -#include -#include +#include +#include /* * This is a bit of a quick hack to do parallel IO testing through POSIX AIO. @@ -84,14 +85,12 @@ disk_getsize(int fd) { off_t mediasize; - if (ioctl(fd, DIOCGMEDIASIZE, &mediasize) < 0) { - perror("ioctl(DIOCGMEDIASIZE)"); - exit(1); - } - return mediasize; + if (ioctl(fd, DIOCGMEDIASIZE, &mediasize) < 0) + err(1, "ioctl(DIOCGMEDIASIZE)"); + return (mediasize); } -iot_t +static iot_t choose_aio(iot_t iomask) { /* choose a random read or write event, limited by the mask */ @@ -102,7 +101,7 @@ choose_aio(iot_t iomask) return (random() & 0x01 ? IOT_READ : IOT_WRITE); } -void +static void set_aio(struct aiocb *a, iot_t iot, int fd, off_t offset, int size, char *buf) { int r; @@ -115,10 +114,8 @@ set_aio(struct aiocb *a, iot_t iot, int fd, off_t offset, int size, char *buf) r = aio_read(a); else r = aio_write(a); - if (r != 0) { - perror("set_aio"); - exit(1); - } + if (r != 0) + err(1, "set_aio call failed"); } int @@ -134,30 +131,35 @@ main(int argc, char *argv[]) off_t file_size, offset; struct aiocb *a; int i, n; - struct timeval st, et, rt; - float f_rt; + struct timeval st, et, rt; + float f_rt; iot_t iowhat; if (argc < 6) { - printf("Usage: %s \n", argv[0]); + printf("Usage: %s \n", + argv[0]); exit(1); } fn = argv[1]; io_size = atoi(argv[2]); + if (io_size <= 0) + errx(1, "the I/O size must be >0"); nrun = atoi(argv[3]); + if (nrun <= 0) + errx(1, "the number of runs must be >0"); aio_len = atoi(argv[4]); - if (strcmp(argv[5], "ro") == 0) { + if (aio_len <= 0) + errx(1, "AIO concurrency must be >0"); + if (strcmp(argv[5], "ro") == 0) iowhat = IOT_READ; - } else if (strcmp(argv[5], "rw") == 0) { + else if (strcmp(argv[5], "rw") == 0) iowhat = IOT_READ | IOT_WRITE; - } else if (strcmp(argv[5], "wo") == 0) { + else if (strcmp(argv[5], "wo") == 0) iowhat = IOT_WRITE; - } else { - fprintf(stderr, "needs to be ro, rw, wo!\n"); - exit(1); - } + else + errx(1, "the I/O type needs to be \"ro\", \"rw\", or \"wo\"!\n"); /* * Random returns values between 0 and (2^32)-1; only good for 4 gig. @@ -171,35 +173,31 @@ main(int argc, char *argv[]) else fd = open(fn, O_RDWR | O_DIRECT); - if (fd < 0) { - perror("open"); - exit(1); - } - if (fstat(fd, &sb) < 0) { - perror("fstat"); - exit(1); - } + if (fd < 0) + err(1, "open failed"); + if (fstat(fd, &sb) < 0) + err(1, "fstat failed"); if (S_ISREG(sb.st_mode)) { file_size = sb.st_size; } else if (S_ISBLK(sb.st_mode) || S_ISCHR(sb.st_mode)) { file_size = disk_getsize(fd); - } else { - perror("unknown file type\n"); - exit(1); - } + } else + errx(1, "unknown file type"); + if (file_size <= 0) + errx(1, "path provided too small"); + printf("File: %s; File size %jd bytes\n", fn, (intmax_t)file_size); aio = calloc(aio_len, sizeof(struct aiocb)); abuf = calloc(aio_len, sizeof(char *)); - for (i = 0; i < aio_len; i++) { + for (i = 0; i < aio_len; i++) abuf[i] = calloc(1, io_size * sizeof(char)); - } /* Fill with the initial contents */ - gettimeofday(&st, NULL); + gettimeofday(&st, NULL); for (i = 0; i < aio_len; i++) { - offset = random() % (file_size / io_size); - offset *= io_size; + offset = random() % (file_size / io_size); + offset *= io_size; set_aio(aio + i, choose_aio(iowhat), fd, offset, io_size, abuf[i]); } @@ -208,18 +206,18 @@ main(int argc, char *argv[]) n = a - aio; assert(n < aio_len); assert(n >= 0); - offset = random() % (file_size / io_size); - offset *= io_size; + offset = random() % (file_size / io_size); + offset *= io_size; set_aio(aio + n, choose_aio(iowhat), fd, offset, io_size, abuf[n]); } - gettimeofday(&et, NULL); - timersub(&et, &st, &rt); - f_rt = ((float) (rt.tv_usec)) / 1000000.0; - f_rt += (float) (rt.tv_sec); - printf("Runtime: %.2f seconds, ", f_rt); - printf("Op rate: %.2f ops/sec, ", ((float) (nrun)) / f_rt); - printf("Avg transfer rate: %.2f bytes/sec\n", ((float) (nrun)) * ((float)io_size) / f_rt); + gettimeofday(&et, NULL); + timersub(&et, &st, &rt); + f_rt = ((float) (rt.tv_usec)) / 1000000.0; + f_rt += (float) (rt.tv_sec); + printf("Runtime: %.2f seconds, ", f_rt); + printf("Op rate: %.2f ops/sec, ", ((float) (nrun)) / f_rt); + printf("Avg transfer rate: %.2f bytes/sec\n", ((float) (nrun)) * ((float)io_size) / f_rt); -- cgit v1.1