2 * Copyright (c) 2000 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * iogen - a tool for generating file/sds io for a doio process
24 #ifdef HAVE_SYS_SYSSGI_H
25 #include <sys/syssgi.h>
28 #ifdef HAVE_SYS_UUID_H
32 #ifdef HAVE_SYS_FS_XFS_FSOPS_H
33 #include <sys/fs/xfs_fsops.h>
36 #ifdef HAVE_SYS_FS_XFS_ITABLE_H
37 #include <sys/fs/xfs_itable.h>
42 #include "str_to_bytes.h"
43 #include "string_to_tokens.h"
44 #include "open_flags.h"
45 #include "random_range.h"
51 #define RAW_IO(_flags_) ((_flags_) & (O_RAW | O_SSD))
53 #define SYSERR strerror(errno)
56 * Structure for retaining test file information
60 char f_path[MAX_FNAME_LENGTH+1]; /* file name (full path) */
61 int f_length; /* length in bytes */
62 int f_iou; /* file iounit */
63 int f_riou; /* file raw iounit (for O_RAW/O_SSD) */
64 int f_dalign; /* direct I/O alignment */
65 int f_nextoff; /* offset of end of last io operation */
66 int f_type; /* file type S_IFREG, etc... */
67 int f_lastoffset; /* offset of last io operation */
68 int f_lastlength; /* length of last io operation */
72 * Simple structure for associating strings with values - useful for converting
73 * cmdline args to internal values, as well as printing internal values in
74 * a human readable form.
84 * Declare cmdline option flags/variables initialized in parse_cmdline()
87 #define OPTS "a:dhf:i:L:m:op:qr:s:t:T:O:N:"
89 int a_opt = 0; /* async io comp. types supplied */
90 int o_opt = 0; /* form overlapping requests */
91 int f_opt = 0; /* test flags */
92 int i_opt = 0; /* iterations - 0 implies infinite */
93 int L_opt = 0; /* listio min-max nstrides & nents */
94 int m_opt = 0; /* offset mode */
95 int O_opt = 0; /* file creation Open flags */
96 int p_opt = 0; /* output pipe - default is stdout */
97 int r_opt = 0; /* specify raw io multiple instead of */
98 /* getting it from the mounted on device. */
99 /* Only applies to regular files. */
100 int s_opt = 0; /* syscalls */
101 int t_opt = 0; /* min transfer size (bytes) */
102 int T_opt = 0; /* max transfer size (bytes) */
103 int q_opt = 0; /* quiet operation on startup */
104 char TagName[40]; /* name of this iogen (see Monster) */
105 struct strmap *Offset_Mode; /* M_SEQUENTIAL, M_RANDOM, etc. */
106 int Iterations; /* # requests to generate (0 --> infinite) */
107 int Time_Mode = 0; /* non-zero if Iterations is in seconds */
108 /* (ie. -i arg was suffixed with 's') */
109 char *Outpipe; /* Pipe to write output to if p_opt */
110 int Mintrans; /* min io transfer size */
111 int Maxtrans; /* max io transfer size */
112 int Rawmult; /* raw/ssd io multiple (from -r) */
113 int Minstrides; /* min # of listio strides per request */
114 int Maxstrides; /* max # of listio strides per request */
115 int Oflags; /* open(2) flags for creating files */
116 int Ocbits; /* open(2) cbits for creating files */
117 int Ocblks; /* open(2) cblks for creating files */
118 int Orealtime=0; /* flag set for -O REALTIME */
119 int Oextsize=0; /* real-time extent size */
120 int Oreserve=1; /* flag for -O [no]reserve */
121 int Oallocate=0; /* flag for -O allocate */
122 int Owrite=1; /* flag for -O nowrite */
124 int Nfiles = 0; /* # files on cmdline */
125 struct file_info *File_List; /* info about each file */
126 int Nflags = 0; /* # flags on cmdline */
127 struct strmap *Flag_List[128]; /* flags selected from cmdline */
128 int Nsyscalls = 0; /* # syscalls on cmdline */
129 struct strmap *Syscall_List[128]; /* syscalls selected on cmdline */
130 int Fileio = 0; /* flag indicating that a file */
131 /* io syscall has been chosen. */
132 int Naio_Strat_Types = 0; /* # async io completion types */
133 struct strmap *Aio_Strat_List[128]; /* Async io completion types */
138 * Map async io completion modes (-a args) names to values. Macros are
142 struct strmap Aio_Strat_Map[] = {
145 { "signal", A_SIGNAL },
153 * Offset_Mode #defines
157 #define M_SEQUENTIAL 2
161 * Map offset mode (-m args) names to values
164 struct strmap Omode_Map[] = {
165 { "random", M_RANDOM },
166 { "sequential", M_SEQUENTIAL },
167 { "reverse", M_REVERSE },
172 * Map syscall names (-s args) to values - macros are defined in doio.h.
174 #define SY_ASYNC 00001
175 #define SY_WRITE 00002
177 #define SY_LISTIO 00020
178 #define SY_NENT 00100 /* multi entry vs multi stride >>> */
180 struct strmap Syscall_Map[] = {
182 { "write", WRITE, SY_WRITE },
184 { "pwrite", PWRITE, SY_WRITE },
186 { "resvsp", RESVSP, SY_WRITE },
187 { "unresvsp", UNRESVSP, SY_WRITE },
188 { "reserve", RESVSP, SY_WRITE },
189 { "unreserve", UNRESVSP, SY_WRITE },
192 { "writev", WRITEV, SY_WRITE },
194 { "mmwrite", MMAPW, SY_WRITE },
195 { "fsync2", FSYNC2, SY_WRITE },
196 { "fdatasync", FDATASYNC, SY_WRITE },
201 * Map open flags (-f args) to values
203 #define FLG_RAW 00001
205 struct strmap Flag_Map[] = {
206 { "buffered", 0, 0 },
207 { "sync", O_SYNC, 0 },
208 { "direct", O_DIRECT, FLG_RAW },
213 * Map file types to strings
216 struct strmap Ftype_Map[] = {
217 { "regular", S_IFREG },
218 { "blk-spec", S_IFBLK },
219 { "chr-spec", S_IFCHR },
229 char Byte_Patterns[26] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
230 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
231 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
235 int form_iorequest(struct io_req *);
237 int parse_cmdline(int argc, char **argv, char *opts);
238 int help(FILE *stream);
239 int usage(FILE *stream);
247 int rseed, outfd, infinite;
254 parse_cmdline(argc, argv, OPTS);
257 * Initialize output descriptor.
262 outfd = init_output();
266 random_range_seed(rseed); /* initialize random number generator */
269 * Print out startup information, unless we're running in quiet mode
272 startup_info(stderr, rseed);
274 start_time = time(0);
277 * While iterations (or forever if Iterations == 0) - compute an
278 * io request, and write the structure to the output descriptor
281 infinite = !Iterations;
284 (! Time_Mode && Iterations--) ||
285 (Time_Mode && time(0) - start_time <= Iterations)) {
287 memset(&req, 0, sizeof(struct io_req));
288 if (form_iorequest(&req) == -1) {
289 fprintf(stderr, "iogen%s: form_iorequest() failed\n", TagName);
293 req.r_magic = DOIO_MAGIC;
294 write(outfd, (char *)&req, sizeof(req));
302 startup_info(FILE *stream, int seed)
304 char *value_to_string(), *type;
307 fprintf(stream, "\n");
308 fprintf(stream, "iogen%s starting up with the following:\n", TagName);
309 fprintf(stream, "\n");
311 fprintf(stream, "Out-pipe: %s\n",
312 p_opt ? Outpipe : "stdout");
315 fprintf(stream, "Iterations: %d", Iterations);
317 fprintf(stream, " seconds");
319 fprintf(stream, "\n");
321 fprintf(stream, "Iterations: Infinite\n");
328 "Offset-Mode: %s\n", Offset_Mode->m_string);
330 fprintf(stream, "Overlap Flag: %s\n",
331 o_opt ? "on" : "off");
334 "Mintrans: %-11d (%d blocks)\n",
335 Mintrans, (Mintrans+BSIZE-1)/BSIZE);
338 "Maxtrans: %-11d (%d blocks)\n",
339 Maxtrans, (Maxtrans+BSIZE-1)/BSIZE);
343 "O_RAW/O_SSD Multiple: (Determined by device)\n");
346 "O_RAW/O_SSD Multiple: %-11d (%d blocks)\n",
347 Rawmult, (Rawmult+BSIZE-1)/BSIZE);
349 fprintf(stream, "Syscalls: ");
350 for (i = 0; i < Nsyscalls; i++)
352 "%s ", Syscall_List[i]->m_string);
353 fprintf(stream, "\n");
355 fprintf(stream, "Aio completion types: ");
356 for (i = 0; i < Naio_Strat_Types; i++)
358 "%s ", Aio_Strat_List[i]->m_string);
359 fprintf(stream, "\n");
362 fprintf(stream, "Flags: ");
363 for (i = 0; i < Nflags; i++)
365 "%s ", Flag_List[i]->m_string);
367 fprintf(stream, "\n");
368 fprintf(stream, "\n");
369 fprintf(stream, "Test Files: \n");
370 fprintf(stream, "\n");
372 "Path Length iou raw iou file\n");
374 " (bytes) (bytes) (bytes) type\n");
376 "-----------------------------------------------------------------------------\n");
378 for (i = 0; i < Nfiles; i++) {
379 type = value_to_string(Ftype_Map, File_List[i].f_type);
380 fprintf(stream, "%-40s %12d %7d %7d %s\n",
381 File_List[i].f_path, File_List[i].f_length,
382 File_List[i].f_iou, File_List[i].f_riou, type);
388 * Initialize output descriptor. If going to stdout, its easy,
389 * otherwise, attempt to create a FIFO on path Outpipe. Exit with an
390 * error code if this cannot be done.
398 if (stat(Outpipe, &sbuf) == -1) {
399 if (errno == ENOENT) {
400 if (mkfifo(Outpipe, 0666) == -1) {
401 fprintf(stderr, "iogen%s: Could not mkfifo %s: %s\n",
402 TagName, Outpipe, SYSERR);
406 fprintf(stderr, "iogen%s: Could not stat outpipe %s: %s\n",
407 TagName, Outpipe, SYSERR);
411 if (! S_ISFIFO(sbuf.st_mode)) {
413 "iogen%s: Output file %s exists, but is not a FIFO\n",
419 if ((outfd = open(Outpipe, O_RDWR)) == -1) {
421 "iogen%s: Couldn't open outpipe %s with flags O_RDWR: %s\n",
422 TagName, Outpipe, SYSERR);
431 * Main io generation function. form_iorequest() selects a system call to
432 * do based on cmdline arguments, and proceeds to select parameters for that
435 * Returns 0 if req is filled in with a complete doio request, otherwise
443 int mult, offset = 0, length = 0, slength;
444 int minlength, maxlength, laststart, lastend;
445 int minoffset, maxoffset;
446 int maxstride, nstrides;
448 struct strmap *flags, *sc, *aio_strat;
449 struct file_info *fptr;
452 * Choose system call, flags, and file
455 sc = Syscall_List[random_range(0, Nsyscalls-1, 1, NULL)];
456 req->r_type = sc->m_value;
458 if( sc->m_flags & SY_WRITE )
459 pattern = Byte_Patterns[random_range(0, sizeof(Byte_Patterns) - 1, 1, NULL)];
464 * otherwise, we're doing file io. Choose starting offset, length,
465 * open flags, and possibly a pattern (for write/writea).
468 fptr = &File_List[random_range(0, Nfiles-1, 1, NULL)];
469 flags = Flag_List[random_range(0, Nflags-1, 1, NULL)];
472 * Choose offset/length multiple. IO going to a device, or regular
473 * IO that is O_RAW or O_SSD must be aligned on the file r_iou. Otherwise
474 * it must be aligned on the regular iou (normally 1).
477 if ( fptr->f_type == S_IFREG && (flags->m_flags & FLG_RAW) )
483 * Choose offset and length. Both must be a multiple of mult
487 * Choose length first - it must be a multiple of mult
490 laststart = fptr->f_lastoffset;
491 lastend = fptr->f_lastoffset + fptr->f_lastlength - 1;
493 minlength = (Mintrans > mult) ? Mintrans : mult;
495 switch (Offset_Mode->m_value) {
497 if (o_opt && lastend > laststart)
498 offset = random_range(laststart, lastend, 1, NULL);
500 offset = lastend + 1;
501 if (offset && (offset%mult))
502 offset += mult - (offset % mult);
504 if (minlength > fptr->f_length - offset)
507 maxlength = fptr->f_length - offset;
508 if (maxlength > Maxtrans)
509 maxlength = Maxtrans;
511 length = random_range(minlength, maxlength, mult, &errp);
513 fprintf(stderr, "iogen%s: random_range(%d, %d, %d) failed\n",
514 TagName, minlength, maxlength, mult);
521 maxlength = laststart;
523 if (maxlength > Maxtrans)
524 maxlength = Maxtrans;
526 if (minlength > maxlength) {
527 laststart = fptr->f_length;
528 lastend = fptr->f_length;
529 maxlength = Maxtrans;
532 length = random_range(minlength, maxlength, mult, &errp);
534 fprintf(stderr, "iogen%s: random_range(%d, %d, %d) failed\n",
535 TagName, minlength, maxlength, mult);
539 offset = laststart - length;
541 if (o_opt && lastend > laststart)
542 offset += random_range(1, lastend - laststart, 1, NULL);
544 if (offset && (offset%mult))
545 offset -= offset % mult;
550 length = random_range(Mintrans, Maxtrans, mult, NULL);
552 if (o_opt && lastend > laststart) {
553 minoffset = laststart - length + 1;
558 if (lastend + length > fptr->f_length) {
559 maxoffset = fptr->f_length - length;
565 maxoffset = fptr->f_length - length;
571 offset = random_range(minoffset, maxoffset, mult, &errp);
573 fprintf(stderr, "iogen%s: random_range(%d, %d, %d) failed\n",
574 TagName, minoffset, maxoffset, mult);
579 fptr->f_lastoffset = offset;
580 fptr->f_lastlength = length;
583 * Choose an async io completion strategy if necessary
585 if( sc->m_flags & SY_ASYNC )
586 aio_strat = Aio_Strat_List[random_range(0, Naio_Strat_Types - 1,
592 * fill in specific syscall record data
594 switch (sc->m_value) {
597 strcpy(req->r_data.read.r_file, fptr->f_path);
598 req->r_data.read.r_oflags = O_RDONLY | flags->m_value;
599 req->r_data.read.r_offset = offset;
600 req->r_data.read.r_nbytes = length;
601 req->r_data.read.r_uflags = (flags->m_flags & FLG_RAW) ? F_WORD_ALIGNED : 0;
602 req->r_data.read.r_aio_strat = (aio_strat==NULL) ? 0 : aio_strat->m_value;
603 req->r_data.read.r_nstrides = 1;
604 req->r_data.read.r_nent = 1;
609 strcpy(req->r_data.write.r_file, fptr->f_path);
610 req->r_data.write.r_oflags = O_WRONLY | flags->m_value;
611 req->r_data.write.r_offset = offset;
612 req->r_data.write.r_nbytes = length;
613 req->r_data.write.r_pattern = pattern;
614 req->r_data.write.r_uflags = (flags->m_flags & FLG_RAW) ? F_WORD_ALIGNED : 0;
615 req->r_data.write.r_aio_strat = (aio_strat==NULL) ? 0 : aio_strat->m_value;
616 req->r_data.write.r_nstrides = 1;
617 req->r_data.write.r_nent = 1;
637 strcpy(req->r_data.io.r_file, fptr->f_path);
638 req->r_data.io.r_oflags = ((sc->m_flags & SY_WRITE) ? O_WRONLY : O_RDONLY) | flags->m_value;
639 req->r_data.io.r_offset = offset;
640 req->r_data.io.r_nbytes = length;
641 req->r_data.io.r_pattern = pattern;
642 req->r_data.io.r_uflags = (flags->m_flags & FLG_RAW) ? F_WORD_ALIGNED : 0;
643 req->r_data.io.r_aio_strat = (aio_strat==NULL) ? 0 : aio_strat->m_value;
644 req->r_data.io.r_nstrides = 1;
645 req->r_data.io.r_nent = 1;
650 strcpy(req->r_data.io.r_file, fptr->f_path);
651 /* a subtle "feature" of mmap: a write-map requires
652 the file open read/write */
653 req->r_data.io.r_oflags = ((sc->m_flags & SY_WRITE) ? O_RDWR : O_RDONLY) | flags->m_value;
654 req->r_data.io.r_offset = offset;
655 req->r_data.io.r_nbytes = length;
656 req->r_data.io.r_pattern = pattern;
657 req->r_data.io.r_uflags = (flags->m_flags & FLG_RAW) ? F_WORD_ALIGNED : 0;
658 req->r_data.io.r_aio_strat = (aio_strat==NULL) ? 0 : aio_strat->m_value;
659 req->r_data.io.r_nstrides = 1;
660 req->r_data.io.r_nent = 1;
672 strcpy(req->r_data.io.r_file, fptr->f_path);
673 req->r_data.io.r_oflags = ((sc->m_flags & SY_WRITE) ? O_WRONLY : O_RDONLY) | flags->m_value;
674 req->r_data.io.r_offset = offset;
675 req->r_data.io.r_uflags = (flags->m_flags & FLG_RAW) ? F_WORD_ALIGNED : 0;
676 req->r_data.io.r_aio_strat = (aio_strat==NULL) ? 0 : aio_strat->m_value;
677 req->r_data.io.r_pattern = pattern;
679 /* multi-strided request...
680 * random number of strides (1...MaxStrides)
681 * length of stride must be > minlength
682 * length of stride must be % mult
684 * maxstrides = min(length / mult, overall.max#strides)
685 * nstrides = random #
686 * while( length / nstrides < minlength )
687 * nstrides = new random #
689 maxstride = length / mult;
690 if(maxstride > Maxstrides)
691 maxstride = Maxstrides;
695 nstrides = random_range(Minstrides, maxstride, 1, &errp);
697 fprintf(stderr, "iogen%s: random_range(%d, %d, %d) failed\n",
698 TagName, Minstrides, maxstride, 1);
702 slength = length / nstrides;
703 if(slength % mult != 0) {
704 if( mult > slength) {
707 slength -= slength % mult;
709 nstrides = length / slength;
710 if(nstrides > Maxstrides)
711 nstrides = Maxstrides;
714 req->r_data.io.r_nbytes = slength;
715 if( sc->m_flags & SY_NENT ) {
716 req->r_data.io.r_nstrides = 1;
717 req->r_data.io.r_nent = nstrides;
719 req->r_data.io.r_nstrides = nstrides;
720 req->r_data.io.r_nent = 1;
732 * Get information about a file that iogen uses to choose io length and
733 * offset. Information gathered is file length, iounit, and raw iounit.
734 * For regurlar files, iounit is 1, and raw iounit is the iounit of the
735 * device on which the file resides. For block/character special files
736 * the iounit and raw iounit are both the iounit of the device.
738 * Note: buffered and osync io must be iounit aligned
739 * raw and ossd io must be raw iounit aligned
744 struct file_info *rec;
749 struct dioattr finfo;
753 * Figure out if the files is regular, block or character special. Any
754 * other type is an error.
757 if (stat(rec->f_path, &sbuf) == -1) {
758 fprintf(stderr, "iogen%s: get_file_info(): Could not stat() %s: %s\n",
759 TagName, rec->f_path, SYSERR);
763 rec->f_type = sbuf.st_mode & S_IFMT;
766 * If regular, iou is 1, and we must figure out the device on
767 * which the file resides. riou is the iou (logical sector size) of
771 if (S_ISREG(sbuf.st_mode)) {
773 rec->f_length = sbuf.st_size;
776 * If -r used, take Rawmult as the raw/ssd io multiple. Otherwise
777 * attempt to determine it by looking at the device the file
782 rec->f_riou = Rawmult;
788 if( (fd = open(rec->f_path, O_RDWR|O_DIRECT, 0)) != -1 ) {
789 #ifdef XFS_IOC_DIOINFO
790 if(xfsctl(rec->f_path, fd, XFS_IOC_DIOINFO, &finfo) != -1) {
793 if(fcntl(fd, F_DIOINFO, &finfo) != -1) {
798 rec->f_riou = finfo.d_miniosz;
801 "iogen%s: Error %s (%d) getting direct I/O info of file %s\n",
802 TagName, strerror(errno), errno, rec->f_path);
806 rec->f_riou = BBSIZE;
812 rec->f_length = BSIZE;
819 * Create file path as nbytes long. If path exists, the file will either be
820 * extended or truncated to be nbytes long. Returns final size of file,
821 * or -1 if there was a failure.
825 create_file(path, nbytes)
835 struct fsxattr xattr;
836 struct dioattr finfo;
841 rval = stat(path, &sbuf);
844 if (errno == ENOENT) {
847 fprintf(stderr, "iogen%s: Could not stat file %s: %s (%d)\n",
848 TagName, path, SYSERR, errno);
852 if (! S_ISREG(sbuf.st_mode)) {
854 "iogen%s: file %s exists, but is not a regular file - cannot modify length\n",
860 if (sbuf.st_size == nbytes)
863 Oflags |= O_CREAT | O_WRONLY;
865 if ((fd = open(path, Oflags, 0666)) == -1) {
866 fprintf(stderr, "iogen%s: Could not create/open file %s: %s (%d)\n",
867 TagName, path, SYSERR, errno);
872 * Truncate file if it is longer than nbytes, otherwise attempt to
873 * pre-allocate file blocks.
876 if (sbuf.st_size > nbytes) {
877 if (ftruncate(fd, nbytes) == -1) {
879 "iogen%s: Could not ftruncate() %s to %d bytes: %s (%d)\n",
880 TagName, path, nbytes, SYSERR, errno);
888 * The file must be designated as Real-Time before any data
889 * is allocated to it.
893 bzero(&xattr, sizeof(xattr));
894 xattr.fsx_xflags = XFS_XFLAG_REALTIME;
895 /*fprintf(stderr, "set: fsx_xflags = 0x%x\n", xattr.fsx_xflags);*/
896 #ifdef XFS_IOC_FSSETXATTR
897 if( xfsctl(path, fd, XFS_IOC_FSSETXATTR, &xattr) == -1 ) {
900 if (fcntl(fd, F_FSSETXATTR, &xattr) < 0) {
905 fprintf(stderr, "iogen%s: Error %s (%d) setting XFS XATTR->Realtime on file %s\n",
906 TagName, SYSERR, errno, path);
912 #ifdef XFS_IOC_FSGETXATTR
913 if( xfsctl(path, fd, XFS_IOC_FSGETXATTR, &xattr) == -1 ) {
916 if (fcntl(fd, F_FSGETXATTR, &xattr) < 0) {
921 fprintf(stderr, "iogen%s: Error getting realtime flag %s (%d)\n",
922 TagName, SYSERR, errno);
926 fprintf(stderr, "get: fsx_xflags = 0x%x\n",
935 * Failure is ignored since XFS_IOC_RESVSP only works on XFS and the
936 * filesystem could be on some otehr filesystem.
939 f.l_whence = SEEK_SET;
944 "create_file: xfsctl(%d, RESVSP, { %d, %lld, %lld })\n",
945 fd, f.l_whence, (long long)f.l_start, (long long)f.l_len);*/
947 /* non-zeroing reservation */
948 #ifdef XFS_IOC_RESVSP
949 if( xfsctl( path, fd, XFS_IOC_RESVSP, &f ) == -1) {
951 "iogen%s: Could not xfsctl(XFS_IOC_RESVSP) %d bytes in file %s: %s (%d)\n",
952 TagName, nbytes, path, SYSERR, errno);
958 if( fcntl( fd, F_RESVSP, &f ) == -1) {
960 "iogen%s: Could not fcntl(F_RESVSP) %d bytes in file %s: %s (%d)\n",
961 TagName, nbytes, path, SYSERR, errno);
972 /* XFS_IOC_ALLOCSP allocates from the file start to l_start */
973 f.l_whence = SEEK_SET;
977 "create_file: xfsctl(%d, XFS_IOC_ALLOCSP, { %d, %lld, %lld })\n",
978 fd, f.l_whence, (long long)f.l_start,
979 (long long)f.l_len);*/
981 /* zeroing reservation */
982 #ifdef XFS_IOC_ALLOCSP
983 if( xfsctl( path, fd, XFS_IOC_ALLOCSP, &f ) == -1) {
985 "iogen%s: Could not xfsctl(XFS_IOC_ALLOCSP) %d bytes in file %s: %s (%d)\n",
986 TagName, nbytes, path, SYSERR, errno);
992 if ( fcntl(fd, F_ALLOCSP, &f) < 0) {
994 "iogen%s: Could not fcntl(F_ALLOCSP) %d bytes in file %s: %s (%d)\n",
995 TagName, nbytes, path, SYSERR, errno);
1007 * Write a byte at the end of file so that stat() sets the right
1014 if( (fd = open(path, O_CREAT|O_RDWR|O_DIRECT, 0)) != -1 ) {
1015 #ifdef XFS_IOC_DIOINFO
1016 if(xfsctl(path, fd, XFS_IOC_DIOINFO, &finfo) == -1) {
1019 if (fcntl(fd, F_DIOINFO, &finfo) < 0) {
1025 "iogen%s: Error %s (%d) getting direct I/O info for file %s\n",
1026 TagName, SYSERR, errno, path);
1029 /*fprintf(stderr, "%s: miniosz=%d\n",
1030 path, finfo.d_miniosz);*/
1033 fprintf(stderr, "iogen%s: Error %s (%d) opening file %s with flags O_CREAT|O_RDWR|O_DIRECT\n",
1034 TagName, SYSERR, errno, path);
1039 * nb is nbytes adjusted down by an even d_miniosz block
1041 * Note: the first adjustment can cause iogen to print a warning
1042 * about not being able to create a file of <nbytes> length,
1043 * since the file will be shorter.
1045 nb = nbytes-finfo.d_miniosz;
1046 nb = nb-nb%finfo.d_miniosz;
1049 "create_file_ow2: lseek(%d, %d {%d %d}, SEEK_SET)\n",
1050 fd, nb, nbytes, finfo.d_miniosz);*/
1052 if (lseek(fd, nb, SEEK_SET) == -1) {
1054 "iogen%s: Could not lseek() to EOF of file %s: %s (%d)\n\tactual offset %d file size goal %d miniosz %lld\n",
1055 TagName, path, SYSERR, errno,
1056 nb, nbytes, (long long)finfo.d_miniosz);
1061 b = buf = (char *)malloc(finfo.d_miniosz+finfo.d_mem);
1063 if( ((long)buf % finfo.d_mem != 0) ) {
1064 buf += finfo.d_mem - ((long)buf % finfo.d_mem);
1067 memset(buf, 0, finfo.d_miniosz);
1069 if ( (rval=write(fd, buf, finfo.d_miniosz)) != finfo.d_miniosz) {
1071 "iogen%s: Could not write %d byte length file %s: %s (%d)\n",
1072 TagName, nb, path, SYSERR, errno);
1074 "\twrite(%d, 0x%lx, %d) = %d\n",
1075 fd, (long)buf, finfo.d_miniosz, rval);
1077 "\toffset %d file size goal %d, miniosz=%d\n",
1078 nb, nbytes, finfo.d_miniosz);
1087 "create_file_Owrite: lseek(%d, %d {%d}, SEEK_SET)\n",
1088 fd, nbytes-1, nbytes);*/
1090 if (lseek(fd, nbytes-1, SEEK_SET) == -1) {
1092 "iogen%s: Could not lseek() to EOF in file %s: %s (%d)\n\toffset goal %d\n",
1093 TagName, path, SYSERR, errno,
1099 if ( (rval=write(fd, &c, 1)) != 1) {
1101 "iogen%s: Could not create a %d byte length file %s: %s (%d)\n",
1102 TagName, nbytes, path, SYSERR, errno);
1104 "\twrite(%d, 0x%lx, %d) = %d\n",
1105 fd, (long)&c, 1, rval);
1107 "\toffset %d file size goal %d\n",
1118 return sbuf.st_size;
1122 * Function to convert a string to its corresponding value in a strmap array.
1123 * If the string is not found in the array, the value corresponding to the
1124 * NULL string (the last element in the array) is returned.
1128 str_to_value(map, str)
1134 for (mp = map; mp->m_string != NULL; mp++)
1135 if (strcmp(mp->m_string, str) == 0)
1142 * Function to convert a string to its corresponding entry in a strmap array.
1143 * If the string is not found in the array, a NULL is returned.
1147 str_lookup(map, str)
1153 for (mp = map; mp->m_string != NULL; mp++)
1154 if (strcmp(mp->m_string, str) == 0)
1157 return((mp->m_string == NULL) ? NULL : mp);
1162 * Function to convert a value to its corresponding string in a strmap array.
1163 * If the value is not found in the array, NULL is returned.
1167 value_to_string(map, val)
1173 for (mp = map; mp->m_string != NULL; mp++)
1174 if (mp->m_value == val)
1177 return mp->m_string;
1181 * Interpret cmdline options/arguments. Exit with 1 if something on the
1182 * cmdline isn't kosher.
1186 parse_cmdline(argc, argv, opts)
1191 int o, len, nb, format_error;
1192 struct strmap *flgs, *sc;
1193 char *file, *cp, ch;
1195 struct file_info *fptr;
1197 char *openargs[5]; /* Flags, cbits, cblks */
1198 while ((o = getopt(argc, argv, opts)) != EOF) {
1202 fprintf(stderr, "iogen%s: Unrecognized option -a on this platform\n", TagName);
1207 cp = strtok(optarg, ",");
1208 while (cp != NULL) {
1209 if( (flgs = str_lookup(Flag_Map, cp)) == NULL ) {
1210 fprintf(stderr, "iogen%s: Unrecognized flags: %s\n", TagName, cp);
1214 cp = strtok(NULL, ",");
1217 if (flgs->m_value & O_SSD && ! Sds_Avail) {
1218 fprintf(stderr, "iogen%s: Warning - no sds available, ignoring ssd flag\n", TagName);
1223 Flag_List[Nflags++] = flgs;
1236 switch (sscanf(optarg, "%i%c", &Iterations, &ch)) {
1256 fprintf(stderr, "iogen%s: Illegal -i arg (%s): Must be of the format: number[s]\n", TagName, optarg);
1257 fprintf(stderr, " where 'number' is >= 0\n");
1265 fprintf(stderr, "iogen%s: Unrecognized option -L on this platform\n", TagName);
1270 if ((Offset_Mode = str_lookup(Omode_Map, optarg)) == NULL) {
1271 fprintf(stderr, "iogen%s: Illegal -m arg (%s)\n", TagName, optarg);
1279 sprintf( TagName, "(%.39s)", optarg );
1288 nopenargs = string_to_tokens(optarg, openargs, 4, ":/");
1290 if(!strcmp(openargs[0], "realtime")) {
1292 * -O realtime:extsize
1296 sscanf(openargs[1],"%i", &Oextsize);
1299 } else if( !strcmp(openargs[0], "allocate") ||
1300 !strcmp(openargs[0], "allocsp")) {
1306 } else if(!strcmp(openargs[0], "reserve")) {
1312 } else if(!strcmp(openargs[0], "noreserve")) {
1313 /* Oreserve=1 by default; this clears that default */
1315 } else if(!strcmp(openargs[0], "nowrite")) {
1316 /* Owrite=1 by default; this clears that default */
1318 } else if(!strcmp(openargs[0], "direct")) {
1319 /* this means "use direct i/o to preallocate file" */
1322 fprintf(stderr, "iogen%s: Error: -O %s error: unrecognized option\n",
1323 TagName, openargs[0]);
1327 Oflags = parse_open_flags(openargs[0], &errmsg);
1329 fprintf(stderr, "iogen%s: -O %s error: %s\n", TagName, optarg, errmsg);
1343 if ((Rawmult = str_to_bytes(optarg)) == -1 ||
1344 Rawmult < 11 || Rawmult % BSIZE) {
1345 fprintf(stderr, "iogen%s: Illegal -r arg (%s). Must be > 0 and multipe of BSIZE (%d)\n",
1346 TagName, optarg, BSIZE);
1354 cp = strtok(optarg, ",");
1355 while (cp != NULL) {
1356 if ((sc = str_lookup(Syscall_Map, cp)) == NULL) {
1357 fprintf(stderr, "iogen%s: Unrecognized syscall: %s\n", TagName, cp);
1362 /* >>> sc->m_flags & FLG_SDS */
1363 if (sc->m_value != SSREAD && sc->m_value != SSWRITE)
1366 Syscall_List[Nsyscalls++] = sc;
1367 } while ( (sc = str_lookup(++sc, cp)) != NULL);
1369 cp = strtok(NULL, ",");
1375 if ((Mintrans = str_to_bytes(optarg)) == -1) {
1376 fprintf(stderr, "iogen%s: Illegal -t arg (%s): Must have the form num[bkm]\n", TagName, optarg);
1383 if ((Maxtrans = str_to_bytes(optarg)) == -1) {
1384 fprintf(stderr, "iogen%s: Illegal -T arg (%s): Must have the form num[bkm]\n", TagName, optarg);
1410 Offset_Mode = str_lookup(Omode_Map, "sequential");
1419 Maxtrans = 256 * BSIZE;
1422 Oflags = Ocbits = Ocblks = 0;
1425 * Supply default async io completion strategy types.
1429 for (mp = Aio_Strat_Map; mp->m_string != NULL; mp++) {
1430 Aio_Strat_List[Naio_Strat_Types++] = mp;
1435 * Supply default syscalls. Default is read,write,reada,writea,listio.
1440 Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "read");
1441 Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "write");
1442 Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "pread");
1443 Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "pwrite");
1444 Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "readv");
1445 Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "writev");
1446 Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "mmread");
1447 Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "mmwrite");
1452 if (Fileio && (argc - optind < 1)) {
1453 fprintf(stderr, "iogen%s: No files specified on the cmdline\n", TagName);
1458 * Supply default file io flags - defaut is 'buffered,raw,sync,ldraw'.
1461 if (! f_opt && Fileio) {
1463 Flag_List[Nflags++] = str_lookup(Flag_Map, "buffered");
1464 Flag_List[Nflags++] = str_lookup(Flag_Map, "sync");
1468 if (optind >= argc) {
1469 fprintf(stderr, "iogen%s: No files listed on the cmdline\n", TagName);
1474 * Initialize File_List[] - only necessary if doing file io. First
1475 * space for the File_List array, then fill it in.
1478 File_List = (struct file_info *)
1479 malloc((argc-optind) * sizeof(struct file_info));
1481 if (File_List == NULL) {
1482 fprintf(stderr, "iogen%s: Could not malloc space for %d file_info structures\n", TagName, argc-optind);
1486 memset(File_List, 0, (argc-optind) * sizeof(struct file_info));
1489 while (optind < argc) {
1493 * Pick off leading len: if it's there and create/extend/trunc
1494 * the file to the desired length. Otherwise, just make sure
1495 * the file is accessable.
1498 if ((cp = strchr(argv[optind], ':')) != NULL) {
1500 if ((len = str_to_bytes(argv[optind])) == -1) {
1502 "iogen%s: illegal file length (%s) for file %s\n",
1503 TagName, argv[optind], cp+1);
1509 if (strlen(file) > MAX_FNAME_LENGTH) {
1510 fprintf(stderr, "iogen%s: Max fname length is %d chars - ignoring file %s\n",
1511 TagName, MAX_FNAME_LENGTH, file);
1516 nb = create_file(file, len);
1520 "iogen%s warning: Couldn't create file %s of %d bytes\n",
1521 TagName, file, len);
1529 file = argv[optind];
1530 if (access(file, R_OK | W_OK) == -1) {
1531 fprintf(stderr, "iogen%s: file %s cannot be accessed for reading and/or writing: %s (%d)\n",
1532 TagName, file, SYSERR, errno);
1538 * get per-file information
1541 fptr = &File_List[Nfiles];
1543 if (file[0] == '/') {
1544 strcpy(fptr->f_path, file);
1546 getcwd(fptr->f_path,
1547 sizeof(fptr->f_path)-1);
1548 strcat(fptr->f_path, "/");
1549 strcat(fptr->f_path, file);
1552 if (get_file_info(fptr) == -1) {
1553 fprintf(stderr, "iogen%s warning: Error getting file info for %s\n", TagName, file);
1557 * If the file length is smaller than our min transfer size,
1561 if (fptr->f_length < Mintrans) {
1562 fprintf(stderr, "iogen%s warning: Ignoring file %s\n",
1563 TagName, fptr->f_path);
1564 fprintf(stderr, " length (%d) is < min transfer size (%d)\n",
1565 fptr->f_length, Mintrans);
1571 * If the file length is smaller than our max transfer size,
1575 if (fptr->f_length < Maxtrans) {
1576 fprintf(stderr, "iogen%s warning: Ignoring file %s\n",
1577 TagName, fptr->f_path);
1578 fprintf(stderr, " length (%d) is < max transfer size (%d)\n",
1579 fptr->f_length, Maxtrans);
1584 if (fptr->f_length > 0) {
1585 switch (Offset_Mode->m_value) {
1587 fptr->f_lastoffset = 0;
1588 fptr->f_lastlength = 0;
1592 fptr->f_lastoffset = fptr->f_length;
1593 fptr->f_lastlength = 0;
1597 fptr->f_lastoffset = fptr->f_length / 2;
1598 fptr->f_lastlength = 0;
1610 fprintf(stderr, "iogen%s: Could not create, or gather info for any test files\n", TagName);
1623 fprintf(stream, "\n");
1625 fprintf(stream, "\t-a aio_type,... Async io completion types to choose. Supported types\n");
1626 fprintf(stream, "\t are: poll, signal, suspend, and callback.\n");
1627 fprintf(stream, "\t Default is all of the above.\n");
1629 fprintf(stream, "\t-a (Not used on Linux).\n");
1631 fprintf(stream, "\t-f flag,... Flags to use for file IO. Supported flags are\n");
1633 fprintf(stream, "\t buffered, direct, sync.\n");
1634 fprintf(stream, "\t Default is 'buffered,sync'.\n");
1636 fprintf(stream, "\t buffered, sync.\n");
1637 fprintf(stream, "\t Default is 'buffered,sync'.\n");
1639 fprintf(stream, "\t-h This help.\n");
1640 fprintf(stream, "\t-i iterations[s] # of requests to generate. 0 means causes iogen\n");
1641 fprintf(stream, "\t to run until it's killed. If iterations is suffixed\n");
1642 fprintf(stream, "\t with 's', then iterations is the number of seconds\n");
1643 fprintf(stream, "\t that iogen should run for. Default is '0'.\n");
1644 fprintf(stream, "\t-L min:max listio nstrides / nrequests range\n");
1645 fprintf(stream, "\t-m offset-mode The mode by which iogen chooses the offset for\n");
1646 fprintf(stream, "\t consectutive transfers within a given file.\n");
1647 fprintf(stream, "\t Allowed values are 'random', 'sequential',\n");
1648 fprintf(stream, "\t and 'reverse'.\n");
1649 fprintf(stream, "\t sequential is the default.\n");
1650 fprintf(stream, "\t-N tagname Tag name, for Monster.\n");
1651 fprintf(stream, "\t-o Form overlapping consecutive requests.\n");
1652 fprintf(stream, "\t-O Open flags for creating files\n");
1654 fprintf(stream, "\t realtime:extsize - put file on real-time volume\n");
1655 fprintf(stream, "\t allocate - allocate space with F_ALLOCSP\n");
1656 fprintf(stream, "\t reserve - reserve space with F_RESVSP (default)\n");
1657 fprintf(stream, "\t noreserve - do not reserve with F_RESVSP\n");
1658 fprintf(stream, "\t direct - use O_DIRECT I/O to write to the file\n");
1660 fprintf(stream, "\t {O_SYNC,etc}\n");
1662 fprintf(stream, "\t-p Output pipe. Default is stdout.\n");
1663 fprintf(stream, "\t-q Quiet mode. Normally iogen spits out info\n");
1664 fprintf(stream, "\t about test files, options, etc. before starting.\n");
1665 fprintf(stream, "\t-s syscall,... Syscalls to do. Supported syscalls are\n");
1667 fprintf(stream, "\t read, write, pread, pwrite, readv, writev,\n");
1668 fprintf(stream, "\t mmread, mmwrite, fsync2, fdatasync,\n");
1669 fprintf(stream, "\t Default is 'read,write,readv,writev,mmread,mmwrite'.\n");
1671 fprintf(stream, "\t-t mintrans Min transfer length\n");
1672 fprintf(stream, "\t-T maxtrans Max transfer length\n");
1673 fprintf(stream, "\n");
1674 fprintf(stream, "\t[len:]file,... Test files to do IO against (note ssread/sswrite\n");
1675 fprintf(stream, "\t don't need a test file). The len: syntax\n");
1676 fprintf(stream, "\t informs iogen to first create/expand/truncate the\n");
1677 fprintf(stream, "\t to the desired length.\n");
1678 fprintf(stream, "\n");
1679 fprintf(stream, "\tNote: The ssd flag causes sds transfers to also be done.\n");
1680 fprintf(stream, "\t To totally eliminate sds transfers, you must eleminate sds\n");
1681 fprintf(stream, "\t from the flags (-f) and ssread,ssrite from the syscalls (-s)\n");
1682 fprintf(stream, "\tThe mintrans, maxtrans, and len: parameters are numbers of the\n");
1683 fprintf(stream, "\tform [0-9]+[bkm]. The optional trailing b, k, or m multiplies\n");
1684 fprintf(stream, "\tthe number by blocks, kilobytes, or megabytes. If no trailing\n");
1685 fprintf(stream, "\tmultiplier is present, the number is interpreted as bytes\n");
1691 * Obvious - usage clause
1698 fprintf(stream, "usage%s: iogen [-hoq] [-a aio_type,...] [-f flag[,flag...]] [-i iterations] [-p outpipe] [-m offset-mode] [-s syscall[,syscall...]] [-t mintrans] [-T maxtrans] [ -O file-create-flags ] [[len:]file ...]\n", TagName);