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 * doio - a general purpose io initiator with system call and
20 * write logging. See doio.h for the structure which defines
21 * what doio requests should look like.
26 * messages should generally be printed using doio_fprintf().
32 #include <sys/uio.h> /* for struct iovec (readv)*/
33 #include <sys/mman.h> /* for mmap(2) */
34 #include <sys/ipc.h> /* for i/o buffer in shared memory */
35 #include <sys/shm.h> /* for i/o buffer in shared memory */
37 #include <sys/time.h> /* for delays */
42 int do_xfsctl(struct io_req *);
47 #include "write_log.h"
48 #include "random_range.h"
49 #include "string_to_tokens.h"
52 #define O_SSD 0 /* so code compiles on a CRAY2 */
55 #define UINT64_T unsigned long long
58 #define O_PARALLEL 0 /* so O_PARALLEL may be used in expressions */
61 #define PPID_CHECK_INTERVAL 5 /* check ppid every <-- iterations */
62 #define MAX_AIO 256 /* maximum number of async I/O ops */
66 #define SYSERR strerror(errno)
69 * getopt() string of supported cmdline arguments.
72 #define OPTS "aC:d:ehm:n:kr:w:vU:V:M:N:"
74 #define DEF_RELEASE_INTERVAL 0
77 * Flags set in parse_cmdline() to indicate which options were selected
81 int a_opt = 0; /* abort on data compare errors */
82 int e_opt = 0; /* exec() after fork()'ing */
83 int C_opt = 0; /* Data Check Type */
84 int d_opt = 0; /* delay between operations */
85 int k_opt = 0; /* lock file regions during writes */
86 int m_opt = 0; /* generate periodic messages */
87 int n_opt = 0; /* nprocs */
88 int r_opt = 0; /* resource release interval */
89 int w_opt = 0; /* file write log file */
90 int v_opt = 0; /* verify writes if set */
91 int U_opt = 0; /* upanic() on varios conditions */
92 int V_opt = 0; /* over-ride default validation fd type */
93 int M_opt = 0; /* data buffer allocation types */
94 char TagName[40]; /* name of this doio (see Monster) */
98 * Misc globals initialized in parse_cmdline()
101 char *Prog = NULL; /* set up in parse_cmdline() */
102 int Upanic_Conditions; /* set by args to -U */
103 int Release_Interval; /* arg to -r */
104 int Nprocs; /* arg to -n */
105 char *Write_Log; /* arg to -w */
106 char *Infile; /* input file (defaults to stdin) */
107 int *Children; /* pids of child procs */
109 int Nsiblings = 0; /* tfork'ed siblings */
111 int Message_Interval = 0;
112 int Npes = 0; /* non-zero if built as an mpp multi-pe app */
113 int Vpe = -1; /* Virtual pe number if Npes >= 0 */
114 int Reqno = 1; /* request # - used in some error messages */
115 int Reqskipcnt = 0; /* count of I/O requests that are skipped */
116 int Validation_Flags;
117 char *(*Data_Check)(); /* function to call for data checking */
118 int (*Data_Fill)(); /* function to call for data filling */
119 int Nmemalloc = 0; /* number of memory allocation strategies */
120 int delayop = 0; /* delay between operations - type of delay */
121 int delaytime = 0; /* delay between operations - how long */
123 struct wlog_file Wlog;
125 int active_mmap_rw = 0; /* Indicates that mmapped I/O is occurring. */
126 /* Used by sigbus_action() in the child doio. */
129 #define SKIP_REQ -2 /* skip I/O request */
132 #define MEM_DATA 1 /* data space */
133 #define MEM_SHMEM 2 /* System V shared memory */
134 #define MEM_T3ESHMEM 3 /* T3E Shared Memory */
135 #define MEM_MMAP 4 /* mmap(2) */
137 #define MEMF_PRIVATE 0001
138 #define MEMF_AUTORESRV 0002
139 #define MEMF_LOCAL 0004
140 #define MEMF_SHARED 0010
142 #define MEMF_FIXADDR 0100
143 #define MEMF_ADDR 0200
144 #define MEMF_AUTOGROW 0400
145 #define MEMF_FILE 01000 /* regular file -- unlink on close */
146 #define MEMF_MPIN 010000 /* use mpin(2) to lock pages in memory */
153 void *space; /* memory address of allocated space */
154 int fd; /* FD open for mmaping */
156 } Memalloc[NMEMALLOC];
159 * Global file descriptors
162 int Wfd_Append; /* for appending to the write-log */
163 int Wfd_Random; /* for overlaying write-log entries */
166 * Structure for maintaining open file test descriptors. Used by
171 char c_file[MAX_FNAME_LENGTH+1];
176 int c_memalign; /* from xfsctl(XFS_IOC_DIOINFO) */
180 void *c_memaddr; /* mmapped address */
181 int c_memlen; /* length of above region */
184 #define FD_ALLOC_INCR 32 /* allocate this many fd_map structs */
188 * Globals for tracking Sds and Core usage
191 char *Memptr; /* ptr to core buffer space */
192 int Memsize; /* # bytes pointed to by Memptr */
193 /* maintained by alloc_mem() */
195 int Sdsptr; /* sds offset (always 0) */
196 int Sdssize; /* # bytes of allocated sds space */
197 /* Maintained by alloc_sds() */
203 * Signal handlers, and related globals
206 void sigint_handler(); /* Catch SIGINT in parent doio, propagate
207 * to children, does not die. */
209 void die_handler(); /* Bad sig in child doios, exit 1. */
210 void cleanup_handler(); /* Normal kill, exit 0. */
212 void sigbus_handler(); /* Handle sigbus--check active_mmap_rw to
213 decide if this should be a normal exit. */
215 void cb_handler(); /* Posix aio callback handler. */
216 void noop_handler(); /* Delayop alarm, does nothing. */
220 char *format_listio();
222 int doio_fprintf(FILE *stream, char *format, ...);
227 int alloc_fd( char *, int );
228 int alloc_mem( int );
229 int do_read( struct io_req * );
230 int do_write( struct io_req * );
231 int do_rw( struct io_req * );
232 int do_sync( struct io_req * );
234 int aio_unregister( int );
235 int parse_cmdline( int, char **, char * );
236 int lock_file_region( char *, int, int, int, int );
237 struct fd_cache *alloc_fdcache(char *, int);
238 int aio_register( int, int, int );
244 * Upanic conditions, and a map from symbolics to values
247 #define U_CORRUPTION 0001 /* upanic on data corruption */
248 #define U_IOSW 0002 /* upanic on bad iosw */
249 #define U_RVAL 0004 /* upanic on bad rval */
251 #define U_ALL (U_CORRUPTION | U_IOSW | U_RVAL)
255 * Used to map cmdline arguments to values
262 struct smap Upanic_Args[] = {
263 { "corruption", U_CORRUPTION },
278 struct sigaction osa;
281 struct aio_info Aio_Info[MAX_AIO];
283 struct aio_info *aio_slot();
284 int aio_done( struct aio_info * );
286 /* -C data-fill/check type */
288 struct smap checkmap[] = {
289 { "default", C_DEFAULT },
293 /* -d option delay types */
294 #define DELAY_SELECT 1
295 #define DELAY_SLEEP 2
296 #define DELAY_SGINAP 3
297 #define DELAY_ALARM 4
298 #define DELAY_ITIMER 5 /* POSIX timer */
300 struct smap delaymap[] = {
301 { "select", DELAY_SELECT },
302 { "sleep", DELAY_SLEEP },
303 { "alarm", DELAY_ALARM },
309 * strerror() does similar actions.
314 static char sys_errno[10];
315 sprintf(sys_errno, "%d", errno);
326 int i, pid, stat, ex_stat;
328 sigset_t block_mask, old_mask;
329 umask(0); /* force new file modes to known values */
332 parse_cmdline(argc, argv, OPTS);
334 random_range_seed(getpid()); /* initialize random number generator */
337 * If this is a re-exec of doio, jump directly into the doio function.
346 * Stop on all but a few signals...
348 sigemptyset(&sa.sa_mask);
349 sa.sa_handler = sigint_handler;
350 sa.sa_flags = SA_RESETHAND; /* sigint is ignored after the */
352 for (i = 1; i <= NSIG; i++) {
373 sigaction(i, &sa, NULL);
378 * If we're logging write operations, make a dummy call to wlog_open
379 * to initialize the write history file. This call must be done in
380 * the parent, to ensure that the history file exists and/or has
381 * been truncated before any children attempt to open it, as the doio
382 * children are not allowed to truncate the file.
386 strcpy(Wlog.w_file, Write_Log);
388 if (wlog_open(&Wlog, 1, 0666) < 0) {
390 "Could not create/truncate write log %s\n",
399 * Malloc space for the children pid array. Initialize all entries
403 Children = (int *)malloc(sizeof(int) * Nprocs);
404 for (i = 0; i < Nprocs; i++) {
408 sigemptyset(&block_mask);
409 sigaddset(&block_mask, SIGCHLD);
410 sigprocmask(SIG_BLOCK, &block_mask, &old_mask);
413 * Fork Nprocs. This [parent] process is a watchdog, to notify the
414 * invoker of procs which exit abnormally, and to make sure that all
415 * child procs get cleaned up. If the -e option was used, we will also
416 * re-exec. This is mostly for unicos/mk on mpp's, to ensure that not
417 * all of the doio's don't end up in the same pe.
419 * Note - if Nprocs is 1, or this doio is a multi-pe app (Npes > 1),
420 * jump directly to doio(). multi-pe apps can't fork(), and there is
421 * no reason to fork() for 1 proc.
424 if (Nprocs == 1 || Npes > 1) {
428 for (i = 0; i < Nprocs; i++) {
429 if ((pid = fork()) == -1) {
431 "(parent) Could not fork %d children: %s (%d)\n",
436 Children[Nchildren] = pid;
444 argv[0] = (char *)malloc(strlen(exec_path + 1));
445 sprintf(argv[0], "-%s", exec_path);
447 execvp(exec_path, argv);
449 "(parent) Could not execvp %s: %s (%d)\n",
450 exec_path, SYSERR, errno);
460 * Parent spins on wait(), until all children exit.
466 if ((pid = wait(&stat)) == -1) {
471 for (i = 0; i < Nchildren; i++)
472 if (Children[i] == pid)
477 if (WIFEXITED(stat)) {
478 switch (WEXITSTATUS(stat)) {
485 "(parent) pid %d exited because of an internal error\n",
487 ex_stat |= E_INTERNAL;
492 "(parent) pid %d exited because of a setup error\n",
499 "(parent) pid %d exited because of data compare errors\n",
502 ex_stat |= E_COMPARE;
511 "(parent) pid %d exited because of a usage error\n",
519 "(parent) pid %d exited with unknown status %d\n",
520 pid, WEXITSTATUS(stat));
521 ex_stat |= E_INTERNAL;
524 } else if (WIFSIGNALED(stat) && WTERMSIG(stat) != SIGINT) {
526 "(parent) pid %d terminated by signal %d\n",
527 pid, WTERMSIG(stat));
541 * main doio function. Each doio child starts here, and never returns.
547 int rval, i, infd, nbytes;
550 struct sigaction sa, def_action, ignore_action, exit_action;
551 struct sigaction sigbus_action;
553 Memsize = Sdssize = 0;
556 * Initialize the Pattern - write-type syscalls will replace Pattern[1]
557 * with the pattern passed in the request. Make sure that
558 * strlen(Pattern) is not mod 16 so that out of order words will be
562 gethostname(Host, sizeof(Host));
563 if ((cp = strchr(Host, '.')) != NULL)
566 Pattern_Length = sprintf(Pattern, "-:%d:%s:%s*", (int)getpid(), Host, Prog);
568 if (!(Pattern_Length % 16)) {
569 Pattern_Length = sprintf(Pattern, "-:%d:%s:%s**",
570 (int)getpid(), Host, Prog);
574 * Open a couple of descriptors for the write-log file. One descriptor
575 * is for appending, one for random access. Write logging is done for
576 * file corruption detection. The program doio_check is capable of
577 * doing corruption detection based on a doio write-log.
582 strcpy(Wlog.w_file, Write_Log);
584 if (wlog_open(&Wlog, 0, 0666) == -1) {
586 "Could not open write log file (%s): wlog_open() failed\n",
593 * Open the input stream - either a file or stdin
596 if (Infile == NULL) {
599 if ((infd = open(Infile, O_RDWR)) == -1) {
601 "Could not open input file (%s): %s (%d)\n",
602 Infile, SYSERR, errno);
608 * Define a set of signals that should never be masked. Receipt of
609 * these signals generally indicates a programming error, and we want
610 * a corefile at the point of error. We put SIGQUIT in this list so
611 * that ^\ will force a user core dump.
613 * Note: the handler for these should be SIG_DFL, all of them
614 * produce a corefile as the default action.
617 ignore_action.sa_handler = SIG_IGN;
618 ignore_action.sa_flags = 0;
619 sigemptyset(&ignore_action.sa_mask);
621 def_action.sa_handler = SIG_DFL;
622 def_action.sa_flags = 0;
623 sigemptyset(&def_action.sa_mask);
625 exit_action.sa_handler = cleanup_handler;
626 exit_action.sa_flags = 0;
627 sigemptyset(&exit_action.sa_mask);
629 sa.sa_handler = die_handler;
631 sigemptyset(&sa.sa_mask);
633 sigbus_action.sa_handler = sigbus_handler;
634 sigbus_action.sa_flags = 0;
635 sigemptyset(&sigbus_action.sa_mask);
637 for (i = 1; i <= NSIG; i++) {
639 /* Signals to terminate program on */
641 sigaction(i, &exit_action, NULL);
644 /* This depends on active_mmap_rw */
646 sigaction(i, &sigbus_action, NULL);
649 /* Signals to Ignore... */
655 sigaction(i, &ignore_action, NULL);
658 /* Signals to trap & report & die */
661 #ifdef SIGERR /* cray only signals */
674 sigaction(i, &sa, NULL);
678 /* Default Action for all other signals */
680 sigaction(i, &def_action, NULL);
686 * Main loop - each doio proc does this until the read returns eof (0).
687 * Call the appropriate io function based on the request type.
690 while ((nbytes = read(infd, (char *)&ioreq, sizeof(ioreq)))) {
693 * Periodically check our ppid. If it is 1, the child exits to
694 * help clean up in the case that the main doio process was
698 if (Reqno && ((Reqno % PPID_CHECK_INTERVAL) == 0)) {
699 if (getppid() == 1) {
701 "Parent doio process has exited\n");
709 "read of %d bytes from input failed: %s (%d)\n",
710 sizeof(ioreq), SYSERR, errno);
715 if (nbytes != sizeof(ioreq)) {
717 "read wrong # bytes from input stream, expected %d, got %d\n",
718 sizeof(ioreq), nbytes);
723 if (ioreq.r_magic != DOIO_MAGIC) {
725 "got a bad magic # from input stream. Expected 0%o, got 0%o\n",
726 DOIO_MAGIC, ioreq.r_magic);
732 * If we're on a Release_Interval multiple, relase all ssd and
733 * core space, and close all fd's in Fd_Map[].
736 if (Reqno && Release_Interval && ! (Reqno%Release_Interval)) {
747 switch (ioreq.r_type) {
750 rval = do_read(&ioreq);
755 rval = do_write(&ioreq);
778 rval = do_rw(&ioreq);
783 rval = do_xfsctl(&ioreq);
788 rval = do_sync(&ioreq);
792 "Don't know how to handle io request type %d\n",
798 if (rval == SKIP_REQ){
801 else if (rval != 0) {
804 "doio(): operation %d returned != 0\n",
809 if (Message_Interval && Reqno % Message_Interval == 0) {
810 doio_fprintf(stderr, "Info: %d requests done (%d skipped) by this process\n", Reqno, Reqskipcnt);
820 * Child exits normally
830 struct timeval tv_delay;
831 struct sigaction sa_al, sa_old;
836 tv_delay.tv_sec = delaytime / 1000000;
837 tv_delay.tv_usec = delaytime % 1000000;
838 /*doio_fprintf(stdout, "delay_select: %d %d\n",
839 tv_delay.tv_sec, tv_delay.tv_usec);*/
840 select(0, NULL, NULL, NULL, &tv_delay);
849 sa_al.sa_handler = noop_handler;
850 sigemptyset(&sa_al.sa_mask);
851 sigaction(SIGALRM, &sa_al, &sa_old);
852 sigemptyset(&al_mask);
854 sigsuspend(&al_mask);
855 sigaction(SIGALRM, &sa_old, 0);
862 * Format IO requests, returning a pointer to the formatted text.
864 * format_strat - formats the async i/o completion strategy
865 * format_rw - formats a read[a]/write[a] request
866 * format_sds - formats a ssread/sswrite request
867 * format_listio- formats a listio request
869 * ioreq is the doio io request structure.
872 struct smap sysnames[] = {
876 { "WRITEA", WRITEA },
877 { "SSREAD", SSREAD },
878 { "SSWRITE", SSWRITE },
879 { "LISTIO", LISTIO },
881 { "LREADA", LREADA },
882 { "LWRITE", LWRITE },
883 { "LWRITEA", LWRITEA },
884 { "LSREAD", LSREAD },
885 { "LSREADA", LSREADA },
886 { "LSWRITE", LSWRITE },
887 { "LSWRITEA", LSWRITEA },
889 /* Irix System Calls */
891 { "PWRITE", PWRITE },
893 { "AWRITE", AWRITE },
894 { "LLREAD", LLREAD },
895 { "LLAREAD", LLAREAD },
896 { "LLWRITE", LLWRITE },
897 { "LLAWRITE", LLAWRITE },
898 { "RESVSP", RESVSP },
899 { "UNRESVSP", UNRESVSP },
901 /* Irix and Linux System Calls */
903 { "WRITEV", WRITEV },
906 { "FSYNC2", FSYNC2 },
907 { "FDATASYNC", FDATASYNC },
912 struct smap aionames[] = {
914 { "signal", A_SIGNAL },
915 { "recall", A_RECALL },
916 { "recalla", A_RECALLA },
917 { "recalls", A_RECALLS },
918 { "suspend", A_SUSPEND },
919 { "callback", A_CALLBACK },
925 format_oflags(int oflags)
931 switch(oflags & 03) {
932 case O_RDONLY: strcat(flags,"O_RDONLY,"); break;
933 case O_WRONLY: strcat(flags,"O_WRONLY,"); break;
934 case O_RDWR: strcat(flags,"O_RDWR,"); break;
935 default: strcat(flags,"O_weird"); break;
939 strcat(flags,"O_EXCL,");
942 strcat(flags,"O_SYNC,");
944 if(oflags & O_DIRECT)
945 strcat(flags,"O_DIRECT,");
947 return(strdup(flags));
951 format_strat(int strategy)
957 case A_POLL: aio_strat = "POLL"; break;
958 case A_SIGNAL: aio_strat = "SIGNAL"; break;
959 case A_RECALL: aio_strat = "RECALL"; break;
960 case A_RECALLA: aio_strat = "RECALLA"; break;
961 case A_RECALLS: aio_strat = "RECALLS"; break;
962 case A_SUSPEND: aio_strat = "SUSPEND"; break;
963 case A_CALLBACK: aio_strat = "CALLBACK"; break;
964 case 0: aio_strat = "<zero>"; break;
966 sprintf(msg, "<error:%#o>", strategy);
967 aio_strat = strdup(msg);
976 struct io_req *ioreq,
984 static char *errbuf=NULL;
985 char *aio_strat, *cp;
986 struct read_req *readp = &ioreq->r_data.read;
987 struct write_req *writep = &ioreq->r_data.write;
988 struct read_req *readap = &ioreq->r_data.read;
989 struct write_req *writeap = &ioreq->r_data.write;
992 errbuf = (char *)malloc(32768);
995 cp += sprintf(cp, "Request number %d\n", Reqno);
997 switch (ioreq->r_type) {
999 cp += sprintf(cp, "syscall: read(%d, %#lo, %d)\n",
1000 fd, (unsigned long) buffer, readp->r_nbytes);
1001 cp += sprintf(cp, " fd %d is file %s - open flags are %#o\n",
1002 fd, readp->r_file, readp->r_oflags);
1003 cp += sprintf(cp, " read done at file offset %d\n",
1008 cp += sprintf(cp, "syscall: write(%d, %#lo, %d)\n",
1009 fd, (unsigned long) buffer, writep->r_nbytes);
1010 cp += sprintf(cp, " fd %d is file %s - open flags are %#o\n",
1011 fd, writep->r_file, writep->r_oflags);
1012 cp += sprintf(cp, " write done at file offset %d - pattern is %s\n",
1013 writep->r_offset, pattern);
1017 aio_strat = format_strat(readap->r_aio_strat);
1019 cp += sprintf(cp, "syscall: reada(%d, %#lo, %d, %#lo, %d)\n",
1020 fd, (unsigned long) buffer, readap->r_nbytes,
1021 (unsigned long) iosw, signo);
1022 cp += sprintf(cp, " fd %d is file %s - open flags are %#o\n",
1023 fd, readap->r_file, readp->r_oflags);
1024 cp += sprintf(cp, " reada done at file offset %d\n",
1026 cp += sprintf(cp, " async io completion strategy is %s\n",
1031 aio_strat = format_strat(writeap->r_aio_strat);
1033 cp += sprintf(cp, "syscall: writea(%d, %#lo, %d, %#lo, %d)\n",
1034 fd, (unsigned long) buffer, writeap->r_nbytes,
1035 (unsigned long) iosw, signo);
1036 cp += sprintf(cp, " fd %d is file %s - open flags are %#o\n",
1037 fd, writeap->r_file, writeap->r_oflags);
1038 cp += sprintf(cp, " writea done at file offset %d - pattern is %s\n",
1039 writeap->r_offset, pattern);
1040 cp += sprintf(cp, " async io completion strategy is %s\n",
1050 * Perform the various sorts of disk reads
1057 int fd, offset, nbytes, oflags, rval;
1060 struct fd_cache *fdc;
1064 * Initialize common fields - assumes r_oflags, r_file, r_offset, and
1065 * r_nbytes are at the same offset in the read_req and reada_req
1069 file = req->r_data.read.r_file;
1070 oflags = req->r_data.read.r_oflags;
1071 offset = req->r_data.read.r_offset;
1072 nbytes = req->r_data.read.r_nbytes;
1074 /*printf("read: %s, %#o, %d %d\n", file, oflags, offset, nbytes);*/
1077 * Grab an open file descriptor
1078 * Note: must be done before memory allocation so that the direct i/o
1079 * information is available in mem. allocate
1082 if ((fd = alloc_fd(file, oflags)) == -1)
1086 * Allocate core or sds - based on the O_SSD flag
1090 #define wtob(x) (x * sizeof(UINT64_T))
1094 /* get memory alignment for using DIRECT I/O */
1095 fdc = alloc_fdcache(file, oflags);
1097 if ((rval = alloc_mem(nbytes + wtob(1) * 2 + fdc->c_memalign)) < 0) {
1104 if( (req->r_data.read.r_uflags & F_WORD_ALIGNED) ) {
1106 * Force memory alignment for Direct I/O
1108 if( (oflags & O_DIRECT) && ((long)addr % fdc->c_memalign != 0) ) {
1109 addr += fdc->c_memalign - ((long)addr % fdc->c_memalign);
1112 addr += random_range(0, wtob(1) - 1, 1, NULL);
1115 if ((rval = alloc_mem(nbytes + wtob(1) * 2)) < 0) {
1120 #endif /* !NO_XFS */
1123 switch (req->r_type) {
1125 /* move to the desired file position. */
1126 if (lseek(fd, offset, SEEK_SET) == -1) {
1127 doio_fprintf(stderr,
1128 "lseek(%d, %d, SEEK_SET) failed: %s (%d)\n",
1129 fd, offset, SYSERR, errno);
1133 if ((rval = read(fd, addr, nbytes)) == -1) {
1134 doio_fprintf(stderr,
1135 "read() request failed: %s (%d)\n%s\n",
1137 format_rw(req, fd, addr, -1, NULL, NULL));
1138 doio_upanic(U_RVAL);
1140 } else if (rval != nbytes) {
1141 doio_fprintf(stderr,
1142 "read() request returned wrong # of bytes - expected %d, got %d\n%s\n",
1144 format_rw(req, fd, addr, -1, NULL, NULL));
1145 doio_upanic(U_RVAL);
1151 return 0; /* if we get here, everything went ok */
1155 * Perform the verious types of disk writes.
1162 static int pid = -1;
1163 int fd, nbytes, oflags;
1166 int logged_write, rval, got_lock;
1167 long offset, woffset = 0;
1168 char *addr, pattern, *file, *msg;
1169 struct wlog_rec wrec;
1171 struct fd_cache *fdc;
1175 * Misc variable setup
1179 nbytes = req->r_data.write.r_nbytes;
1180 offset = req->r_data.write.r_offset;
1181 pattern = req->r_data.write.r_pattern;
1182 file = req->r_data.write.r_file;
1183 oflags = req->r_data.write.r_oflags;
1185 /*printf("pwrite: %s, %#o, %d %d\n", file, oflags, offset, nbytes);*/
1188 * Allocate core memory and possibly sds space. Initialize the data
1192 Pattern[0] = pattern;
1196 * Get a descriptor to do the io on
1199 if ((fd = alloc_fd(file, oflags)) == -1)
1202 /*printf("write: %d, %s, %#o, %d %d\n",
1203 fd, file, oflags, offset, nbytes);*/
1206 * Allocate SDS space for backdoor write if desired
1210 /* get memory alignment for using DIRECT I/O */
1211 fdc = alloc_fdcache(file, oflags);
1213 if ((rval = alloc_mem(nbytes + wtob(1) * 2 + fdc->c_memalign)) < 0) {
1219 if( (req->r_data.write.r_uflags & F_WORD_ALIGNED) ) {
1221 * Force memory alignment for Direct I/O
1223 if( (oflags & O_DIRECT) && ((long)addr % fdc->c_memalign != 0) ) {
1224 addr += fdc->c_memalign - ((long)addr % fdc->c_memalign);
1227 addr += random_range(0, wtob(1) - 1, 1, NULL);
1230 (*Data_Fill)(Memptr, nbytes, Pattern, Pattern_Length, 0);
1231 if( addr != Memptr )
1232 memmove( addr, Memptr, nbytes);
1235 if ((rval = alloc_mem(nbytes + wtob(1) * 2)) < 0) {
1241 (*Data_Fill)(Memptr, nbytes, Pattern, Pattern_Length, 0);
1242 if( addr != Memptr )
1243 memmove( addr, Memptr, nbytes);
1251 if (lock_file_region(file, fd, F_WRLCK, offset, nbytes) < 0) {
1260 * Write a preliminary write-log entry. This is done so that
1261 * doio_check can do corruption detection across an interrupt/crash.
1262 * Note that w_done is set to 0. If doio_check sees this, it
1263 * re-creates the file extents as if the write completed, but does not
1264 * do any checking - see comments in doio_check for more details.
1271 wrec.w_async = (req->r_type == WRITEA) ? 1 : 0;
1272 wrec.w_oflags = oflags;
1274 wrec.w_offset = offset;
1275 wrec.w_nbytes = nbytes;
1277 wrec.w_pathlen = strlen(file);
1278 memcpy(wrec.w_path, file, wrec.w_pathlen);
1279 wrec.w_hostlen = strlen(Host);
1280 memcpy(wrec.w_host, Host, wrec.w_hostlen);
1281 wrec.w_patternlen = Pattern_Length;
1282 memcpy(wrec.w_pattern, Pattern, wrec.w_patternlen);
1286 if ((woffset = wlog_record_write(&Wlog, &wrec, -1)) == -1) {
1287 doio_fprintf(stderr,
1288 "Could not append to write-log: %s (%d)\n",
1295 switch (req->r_type ) {
1301 if (lseek(fd, offset, SEEK_SET) == -1) {
1302 doio_fprintf(stderr,
1303 "lseek(%d, %d, SEEK_SET) failed: %s (%d)\n",
1304 fd, offset, SYSERR, errno);
1308 rval = write(fd, addr, nbytes);
1311 doio_fprintf(stderr,
1312 "write() failed: %s (%d)\n%s\n",
1314 format_rw(req, fd, addr, -1, Pattern, NULL));
1316 doio_fprintf(stderr,
1317 "write() failed: %s\n\twrite(%d, %#o, %d)\n\toffset %d, nbytes%%miniou(%d)=%d, oflags=%#o memalign=%d, addr%%memalign=%d\n",
1321 fdc->c_miniosz, nbytes%fdc->c_miniosz,
1322 oflags, fdc->c_memalign, (long)addr%fdc->c_memalign);
1324 doio_fprintf(stderr,
1325 "write() failed: %s\n\twrite(%d, %#o, %d)\n\toffset %d, nbytes%%1B=%d, oflags=%#o\n",
1328 offset, nbytes%4096, oflags);
1330 doio_upanic(U_RVAL);
1331 } else if (rval != nbytes) {
1332 doio_fprintf(stderr,
1333 "write() returned wrong # bytes - expected %d, got %d\n%s\n",
1335 format_rw(req, fd, addr, -1, Pattern, NULL));
1336 doio_upanic(U_RVAL);
1344 * Verify that the data was written correctly - check_file() returns
1345 * a non-null pointer which contains an error message if there are
1350 msg = check_file(file, offset, nbytes, Pattern, Pattern_Length,
1351 0, oflags & O_PARALLEL);
1353 doio_fprintf(stderr, "%s%s\n",
1355 format_rw(req, fd, addr, -1, Pattern, NULL)
1357 doio_upanic(U_CORRUPTION);
1364 * General cleanup ...
1366 * Write extent information to the write-log, so that doio_check can do
1367 * corruption detection. Note that w_done is set to 1, indicating that
1368 * the write has been verified as complete. We don't need to write the
1369 * filename on the second logging.
1372 if (w_opt && logged_write) {
1374 wlog_record_write(&Wlog, &wrec, woffset);
1378 * Unlock file region if necessary
1382 if (lock_file_region(file, fd, F_UNLCK, offset, nbytes) < 0) {
1388 return( (rval == -1) ? -1 : 0);
1393 * Simple routine to lock/unlock a file using fcntl()
1397 lock_file_region(fname, fd, type, start, nbytes)
1408 flk.l_start = start;
1411 if (fcntl(fd, F_SETLKW, &flk) < 0) {
1412 doio_fprintf(stderr,
1413 "fcntl(%d, %d, %#o) failed for file %s, lock type %d, offset %d, length %d: %s (%d), open flags: %#o\n",
1414 fd, F_SETLKW, &flk, fname, type,
1415 start, nbytes, SYSERR, errno,
1416 fcntl(fd, F_GETFL, 0));
1430 /* ---------------------------------------------------------------------------
1432 * A new paradigm of doing the r/w system call where there is a "stub"
1433 * function that builds the info for the system call, then does the system
1434 * call; this is called by code that is common to all system calls and does
1435 * the syscall return checking, async I/O wait, iosw check, etc.
1438 * WRITE, ASYNC, SSD/SDS,
1439 * FILE_LOCK, WRITE_LOG, VERIFY_DATA,
1443 int rval; /* syscall return */
1444 int err; /* errno */
1445 int *aioid; /* list of async I/O structures */
1448 struct syscall_info {
1451 struct status *(*sy_syscall)();
1453 char *(*sy_format)();
1458 #define SY_WRITE 00001
1459 #define SY_ASYNC 00010
1460 #define SY_IOSW 00020
1461 #define SY_SDS 00100
1464 fmt_ioreq(struct io_req *ioreq, struct syscall_info *sy, int fd)
1466 static char *errbuf=NULL;
1472 errbuf = (char *)malloc(32768);
1474 io = &ioreq->r_data.io;
1477 * Look up async I/O completion strategy
1480 aname->value != -1 && aname->value != io->r_aio_strat;
1485 cp += sprintf(cp, "Request number %d\n", Reqno);
1487 cp += sprintf(cp, " fd %d is file %s - open flags are %#o %s\n",
1488 fd, io->r_file, io->r_oflags, format_oflags(io->r_oflags));
1490 if(sy->sy_flags & SY_WRITE) {
1491 cp += sprintf(cp, " write done at file offset %d - pattern is %c (%#o)\n",
1493 (io->r_pattern == '\0') ? '?' : io->r_pattern,
1496 cp += sprintf(cp, " read done at file offset %d\n",
1500 if(sy->sy_flags & SY_ASYNC) {
1501 cp += sprintf(cp, " async io completion strategy is %s\n",
1505 cp += sprintf(cp, " number of requests is %d, strides per request is %d\n",
1506 io->r_nent, io->r_nstrides);
1508 cp += sprintf(cp, " i/o byte count = %d\n",
1511 cp += sprintf(cp, " memory alignment is %s\n",
1512 (io->r_uflags & F_WORD_ALIGNED) ? "aligned" : "unaligned");
1515 if(io->r_oflags & O_DIRECT) {
1516 struct dioattr finfo;
1518 if(xfsctl(io->r_file, fd, XFS_IOC_DIOINFO, &finfo) == -1) {
1519 cp += sprintf(cp, " Error %s (%d) getting direct I/O info\n",
1520 strerror(errno), errno);
1522 finfo.d_miniosz = 1;
1523 finfo.d_maxiosz = 1;
1526 cp += sprintf(cp, " DIRECT I/O: offset %% %d = %d length %% %d = %d\n",
1528 io->r_offset % finfo.d_miniosz,
1530 io->r_nbytes % finfo.d_miniosz);
1531 cp += sprintf(cp, " mem alignment 0x%x xfer size: small: %d large: %d\n",
1532 finfo.d_mem, finfo.d_miniosz, finfo.d_maxiosz);
1540 sy_pread(req, sysc, fd, addr)
1542 struct syscall_info *sysc;
1547 struct status *status;
1549 rc = pread(fd, addr, req->r_data.io.r_nbytes,
1550 req->r_data.io.r_offset);
1552 status = (struct status *)malloc(sizeof(struct status));
1553 if( status == NULL ){
1554 doio_fprintf(stderr, "malloc failed, %s/%d\n",
1555 __FILE__, __LINE__);
1558 status->aioid = NULL;
1560 status->err = errno;
1566 sy_pwrite(req, sysc, fd, addr)
1568 struct syscall_info *sysc;
1573 struct status *status;
1575 rc = pwrite(fd, addr, req->r_data.io.r_nbytes,
1576 req->r_data.io.r_offset);
1578 status = (struct status *)malloc(sizeof(struct status));
1579 if( status == NULL ){
1580 doio_fprintf(stderr, "malloc failed, %s/%d\n",
1581 __FILE__, __LINE__);
1584 status->aioid = NULL;
1586 status->err = errno;
1592 fmt_pread(struct io_req *req, struct syscall_info *sy, int fd, char *addr)
1594 static char *errbuf = NULL;
1598 errbuf = (char *)malloc(32768);
1599 if( errbuf == NULL ){
1600 doio_fprintf(stderr, "malloc failed, %s/%d\n",
1601 __FILE__, __LINE__);
1607 cp += sprintf(cp, "syscall: %s(%d, 0x%p, %d)\n",
1608 sy->sy_name, fd, addr, req->r_data.io.r_nbytes);
1613 sy_readv(req, sysc, fd, addr)
1615 struct syscall_info *sysc;
1619 struct status *sy_rwv();
1620 return sy_rwv(req, sysc, fd, addr, 0);
1624 sy_writev(req, sysc, fd, addr)
1626 struct syscall_info *sysc;
1630 struct status *sy_rwv();
1631 return sy_rwv(req, sysc, fd, addr, 1);
1635 sy_rwv(req, sysc, fd, addr, rw)
1637 struct syscall_info *sysc;
1643 struct status *status;
1644 struct iovec iov[2];
1646 status = (struct status *)malloc(sizeof(struct status));
1647 if( status == NULL ){
1648 doio_fprintf(stderr, "malloc failed, %s/%d\n",
1649 __FILE__, __LINE__);
1652 status->aioid = NULL;
1654 /* move to the desired file position. */
1655 if ((rc=lseek(fd, req->r_data.io.r_offset, SEEK_SET)) == -1) {
1657 status->err = errno;
1661 iov[0].iov_base = addr;
1662 iov[0].iov_len = req->r_data.io.r_nbytes;
1665 rc = writev(fd, iov, 1);
1667 rc = readv(fd, iov, 1);
1668 status->aioid = NULL;
1670 status->err = errno;
1675 fmt_readv(struct io_req *req, struct syscall_info *sy, int fd, char *addr)
1677 static char errbuf[32768];
1681 cp += sprintf(cp, "syscall: %s(%d, (iov on stack), 1)\n",
1687 sy_mmread(req, sysc, fd, addr)
1689 struct syscall_info *sysc;
1693 struct status *sy_mmrw();
1694 return sy_mmrw(req, sysc, fd, addr, 0);
1698 sy_mmwrite(req, sysc, fd, addr)
1700 struct syscall_info *sysc;
1704 struct status *sy_mmrw();
1705 return sy_mmrw(req, sysc, fd, addr, 1);
1709 sy_mmrw(req, sysc, fd, addr, rw)
1711 struct syscall_info *sysc;
1718 * This version is oriented towards mmaping the file to memory
1719 * ONCE and keeping it mapped.
1721 struct status *status;
1722 void *mrc, *memaddr;
1723 struct fd_cache *fdc;
1726 status = (struct status *)malloc(sizeof(struct status));
1727 if( status == NULL ){
1728 doio_fprintf(stderr, "malloc failed, %s/%d\n",
1729 __FILE__, __LINE__);
1732 status->aioid = NULL;
1735 fdc = alloc_fdcache(req->r_data.io.r_file, req->r_data.io.r_oflags);
1737 if( fdc->c_memaddr == NULL ) {
1738 if( fstat(fd, &sbuf) < 0 ){
1739 doio_fprintf(stderr, "fstat failed, errno=%d\n",
1741 status->err = errno;
1745 fdc->c_memlen = (int)sbuf.st_size;
1746 mrc = mmap(NULL, (int)sbuf.st_size,
1747 rw ? PROT_WRITE|PROT_READ : PROT_READ,
1750 if( mrc == MAP_FAILED ) {
1751 doio_fprintf(stderr, "mmap() failed - 0x%lx %d\n",
1753 status->err = errno;
1757 fdc->c_memaddr = mrc;
1760 memaddr = (void *)((char *)fdc->c_memaddr + req->r_data.io.r_offset);
1764 memcpy(memaddr, addr, req->r_data.io.r_nbytes);
1766 memcpy(addr, memaddr, req->r_data.io.r_nbytes);
1769 status->rval = req->r_data.io.r_nbytes;
1775 fmt_mmrw(struct io_req *req, struct syscall_info *sy, int fd, char *addr)
1777 static char errbuf[32768];
1779 struct fd_cache *fdc;
1782 fdc = alloc_fdcache(req->r_data.io.r_file, req->r_data.io.r_oflags);
1785 cp += sprintf(cp, "syscall: %s(NULL, %d, %s, MAP_SHARED, %d, 0)\n",
1788 (sy->sy_flags & SY_WRITE) ? "PROT_WRITE" : "PROT_READ",
1791 cp += sprintf(cp, "\tfile is mmaped to: 0x%lx\n",
1792 (unsigned long) fdc->c_memaddr);
1794 memaddr = (void *)((char *)fdc->c_memaddr + req->r_data.io.r_offset);
1796 cp += sprintf(cp, "\tfile-mem=0x%lx, length=%d, buffer=0x%lx\n",
1797 (unsigned long) memaddr, req->r_data.io.r_nbytes,
1798 (unsigned long) addr);
1803 struct syscall_info syscalls[] = {
1805 sy_pread, NULL, fmt_pread,
1809 sy_pwrite, NULL, fmt_pread,
1814 sy_readv, NULL, fmt_readv,
1818 sy_writev, NULL, fmt_readv,
1821 { "mmap-read", MMAPR,
1822 sy_mmread, NULL, fmt_mmrw,
1825 { "mmap-write", MMAPW,
1826 sy_mmwrite, NULL, fmt_mmrw,
1840 static int pid = -1;
1841 int fd, offset, nbytes, nstrides, nents, oflags;
1842 int rval, mem_needed, i;
1843 int logged_write, got_lock, woffset = 0, pattern;
1844 int min_byte, max_byte;
1845 char *addr, *file, *msg;
1847 struct wlog_rec wrec;
1848 struct syscall_info *sy;
1850 struct fd_cache *fdc;
1854 * Initialize common fields - assumes r_oflags, r_file, r_offset, and
1855 * r_nbytes are at the same offset in the read_req and reada_req
1858 file = req->r_data.io.r_file;
1859 oflags = req->r_data.io.r_oflags;
1860 offset = req->r_data.io.r_offset;
1861 nbytes = req->r_data.io.r_nbytes;
1862 nstrides= req->r_data.io.r_nstrides;
1863 nents = req->r_data.io.r_nent;
1864 pattern = req->r_data.io.r_pattern;
1866 if( nents >= MAX_AIO ) {
1867 doio_fprintf(stderr, "do_rw: too many list requests, %d. Maximum is %d\n",
1873 * look up system call info
1875 for(sy=syscalls; sy->sy_name != NULL && sy->sy_type != req->r_type; sy++)
1878 if(sy->sy_name == NULL) {
1879 doio_fprintf(stderr, "do_rw: unknown r_type %d.\n",
1885 * Get an open file descriptor
1886 * Note: must be done before memory allocation so that the direct i/o
1887 * information is available in mem. allocate
1890 if ((fd = alloc_fd(file, oflags)) == -1)
1894 * Allocate core memory and possibly sds space. Initialize the
1895 * data to be written. Make sure we get enough, based on the
1899 * 1 extra word for possible partial-word address "bump"
1900 * 1 extra word for dynamic pattern overrun
1901 * MPP_BUMP extra words for T3E non-hw-aligned memory address.
1904 if( sy->sy_buffer != NULL ) {
1905 mem_needed = (*sy->sy_buffer)(req, 0, 0, NULL, NULL);
1907 mem_needed = nbytes;
1911 /* get memory alignment for using DIRECT I/O */
1912 fdc = alloc_fdcache(file, oflags);
1914 if ((rval = alloc_mem(mem_needed + wtob(1) * 2 + fdc->c_memalign)) < 0) {
1918 if ((rval = alloc_mem(mem_needed + wtob(1) * 2)) < 0) {
1923 Pattern[0] = pattern;
1926 * Allocate SDS space for backdoor write if desired
1929 if (oflags & O_SSD) {
1930 doio_fprintf(stderr, "Invalid O_SSD flag was generated for non-Cray system\n");
1937 * if io is not raw, bump the offset by a random amount
1938 * to generate non-word-aligned io.
1940 * On MPP systems, raw I/O must start on an 0x80 byte boundary.
1941 * For non-aligned I/O, bump the address from 1 to 8 words.
1944 if (! (req->r_data.io.r_uflags & F_WORD_ALIGNED)) {
1945 addr += random_range(0, wtob(1) - 1, 1, NULL);
1950 * Force memory alignment for Direct I/O
1952 if( (oflags & O_DIRECT) && ((long)addr % fdc->c_memalign != 0) ) {
1953 addr += fdc->c_memalign - ((long)addr % fdc->c_memalign);
1958 * FILL must be done on a word-aligned buffer.
1959 * Call the fill function with Memptr which is aligned,
1960 * then memmove it to the right place.
1962 if (sy->sy_flags & SY_WRITE) {
1963 (*Data_Fill)(Memptr, mem_needed, Pattern, Pattern_Length, 0);
1964 if( addr != Memptr )
1965 memmove( addr, Memptr, mem_needed);
1974 * Lock data if this is a write and locking option is set
1976 if (sy->sy_flags & SY_WRITE && k_opt) {
1977 if( sy->sy_buffer != NULL ) {
1978 (*sy->sy_buffer)(req, offset, 0, &min_byte, &max_byte);
1981 max_byte = offset + (nbytes * nstrides * nents);
1984 if (lock_file_region(file, fd, F_WRLCK,
1985 min_byte, (max_byte-min_byte+1)) < 0) {
1986 doio_fprintf(stderr,
1987 "file lock failed:\n%s\n",
1988 fmt_ioreq(req, sy, fd));
1989 doio_fprintf(stderr,
1990 " buffer(req, %d, 0, 0x%x, 0x%x)\n",
1991 offset, min_byte, max_byte);
2000 * Write a preliminary write-log entry. This is done so that
2001 * doio_check can do corruption detection across an interrupt/crash.
2002 * Note that w_done is set to 0. If doio_check sees this, it
2003 * re-creates the file extents as if the write completed, but does not
2004 * do any checking - see comments in doio_check for more details.
2007 if (sy->sy_flags & SY_WRITE && w_opt) {
2012 wrec.w_async = (sy->sy_flags & SY_ASYNC) ? 1 : 0;
2013 wrec.w_oflags = oflags;
2015 wrec.w_offset = offset;
2016 wrec.w_nbytes = nbytes; /* mem_needed -- total length */
2018 wrec.w_pathlen = strlen(file);
2019 memcpy(wrec.w_path, file, wrec.w_pathlen);
2020 wrec.w_hostlen = strlen(Host);
2021 memcpy(wrec.w_host, Host, wrec.w_hostlen);
2022 wrec.w_patternlen = Pattern_Length;
2023 memcpy(wrec.w_pattern, Pattern, wrec.w_patternlen);
2027 if ((woffset = wlog_record_write(&Wlog, &wrec, -1)) == -1) {
2028 doio_fprintf(stderr,
2029 "Could not append to write-log: %s (%d)\n",
2036 s = (*sy->sy_syscall)(req, sy, fd, addr);
2038 if( s->rval == -1 ) {
2039 doio_fprintf(stderr,
2040 "%s() request failed: %s (%d)\n%s\n%s\n",
2041 sy->sy_name, SYSERR, errno,
2042 fmt_ioreq(req, sy, fd),
2043 (*sy->sy_format)(req, sy, fd, addr));
2045 doio_upanic(U_RVAL);
2047 for(i=0; i < nents; i++) {
2048 if(s->aioid == NULL)
2050 aio_unregister(s->aioid[i]);
2055 * If the syscall was async, wait for I/O to complete
2058 if(sy->sy_flags & SY_ASYNC) {
2059 for(i=0; i < nents; i++) {
2060 aio_wait(s->aioid[i]);
2066 * Check the syscall how-much-data-written return. Look
2067 * for this in either the return value or the 'iosw'
2071 if( !(sy->sy_flags & SY_IOSW) ) {
2073 if(s->rval != mem_needed) {
2074 doio_fprintf(stderr,
2075 "%s() request returned wrong # of bytes - expected %d, got %d\n%s\n%s\n",
2076 sy->sy_name, nbytes, s->rval,
2077 fmt_ioreq(req, sy, fd),
2078 (*sy->sy_format)(req, sy, fd, addr));
2080 doio_upanic(U_RVAL);
2087 * Verify that the data was written correctly - check_file() returns
2088 * a non-null pointer which contains an error message if there are
2092 if ( rval == 0 && sy->sy_flags & SY_WRITE && v_opt) {
2093 msg = check_file(file, offset, nbytes*nstrides*nents,
2094 Pattern, Pattern_Length, 0,
2095 oflags & O_PARALLEL);
2097 doio_fprintf(stderr, "%s\n%s\n%s\n",
2099 fmt_ioreq(req, sy, fd),
2100 (*sy->sy_format)(req, sy, fd, addr));
2101 doio_upanic(U_CORRUPTION);
2107 * General cleanup ...
2109 * Write extent information to the write-log, so that doio_check can do
2110 * corruption detection. Note that w_done is set to 1, indicating that
2111 * the write has been verified as complete. We don't need to write the
2112 * filename on the second logging.
2115 if (w_opt && logged_write) {
2117 wlog_record_write(&Wlog, &wrec, woffset);
2121 * Unlock file region if necessary
2125 if (lock_file_region(file, fd, F_UNLCK,
2126 min_byte, (max_byte-min_byte+1)) < 0) {
2132 if(s->aioid != NULL)
2135 return (rval == -1) ? -1 : 0;
2140 * xfsctl-based requests
2142 * - XFS_IOC_UNRESVSP
2149 int fd, oflags, offset, nbytes;
2152 int min_byte = 0, max_byte = 0;
2153 char *file, *msg = NULL;
2154 struct xfs_flock64 flk;
2157 * Initialize common fields - assumes r_oflags, r_file, r_offset, and
2158 * r_nbytes are at the same offset in the read_req and reada_req
2161 file = req->r_data.io.r_file;
2162 oflags = req->r_data.io.r_oflags;
2163 offset = req->r_data.io.r_offset;
2164 nbytes = req->r_data.io.r_nbytes;
2167 flk.l_whence=SEEK_SET;
2172 * Get an open file descriptor
2175 if ((fd = alloc_fd(file, oflags)) == -1)
2182 * Lock data if this is locking option is set
2186 max_byte = offset + nbytes;
2188 if (lock_file_region(file, fd, F_WRLCK,
2189 min_byte, (nbytes+1)) < 0) {
2190 doio_fprintf(stderr,
2191 "file lock failed:\n");
2192 doio_fprintf(stderr,
2193 " buffer(req, %d, 0, 0x%x, 0x%x)\n",
2194 offset, min_byte, max_byte);
2202 switch (req->r_type) {
2203 case RESVSP: op=XFS_IOC_RESVSP; msg="resvsp"; break;
2204 case UNRESVSP: op=XFS_IOC_UNRESVSP; msg="unresvsp"; break;
2207 rval = xfsctl(file, fd, op, &flk);
2210 doio_fprintf(stderr,
2211 "xfsctl %s request failed: %s (%d)\n\txfsctl(%d, %s %d, {%d %lld ==> %lld}\n",
2213 fd, msg, op, flk.l_whence,
2214 (long long)flk.l_start,
2215 (long long)flk.l_len);
2217 doio_upanic(U_RVAL);
2222 * Unlock file region if necessary
2226 if (lock_file_region(file, fd, F_UNLCK,
2227 min_byte, (max_byte-min_byte+1)) < 0) {
2233 return (rval == -1) ? -1 : 0;
2238 * fsync(2) and fdatasync(2)
2249 * Initialize common fields - assumes r_oflags, r_file, r_offset, and
2250 * r_nbytes are at the same offset in the read_req and reada_req
2253 file = req->r_data.io.r_file;
2254 oflags = req->r_data.io.r_oflags;
2257 * Get an open file descriptor
2260 if ((fd = alloc_fd(file, oflags)) == -1)
2264 switch(req->r_type) {
2269 rval = fdatasync(fd);
2274 return (rval == -1) ? -1 : 0;
2278 doio_pat_fill(char *addr, int mem_needed, char *Pattern, int Pattern_Length,
2281 return pattern_fill(addr, mem_needed, Pattern, Pattern_Length, 0);
2285 doio_pat_check(buf, offset, length, pattern, pattern_length, patshift)
2293 static char errbuf[4096];
2294 int nb, i, pattern_index;
2295 char *cp, *bufend, *ep;
2296 char actual[33], expected[33];
2298 if (pattern_check(buf, length, pattern, pattern_length, patshift) != 0) {
2300 ep += sprintf(ep, "Corrupt regions follow - unprintable chars are represented as '.'\n");
2301 ep += sprintf(ep, "-----------------------------------------------------------------\n");
2303 pattern_index = patshift % pattern_length;;
2305 bufend = buf + length;
2307 while (cp < bufend) {
2308 if (*cp != pattern[pattern_index]) {
2310 if (nb > sizeof(expected)-1) {
2311 nb = sizeof(expected)-1;
2314 ep += sprintf(ep, "corrupt bytes starting at file offset %d\n", offset + (int)(cp-buf));
2317 * Fill in the expected and actual patterns
2319 bzero(expected, sizeof(expected));
2320 bzero(actual, sizeof(actual));
2322 for (i = 0; i < nb; i++) {
2323 expected[i] = pattern[(pattern_index + i) % pattern_length];
2324 if (! isprint((int)expected[i])) {
2329 if (! isprint((int)actual[i])) {
2334 ep += sprintf(ep, " 1st %2d expected bytes: %s\n", nb, expected);
2335 ep += sprintf(ep, " 1st %2d actual bytes: %s\n", nb, actual);
2342 if (pattern_index == pattern_length) {
2355 * Check the contents of a file beginning at offset, for length bytes. It
2356 * is assumed that there is a string of pattern bytes in this area of the
2357 * file. Use normal buffered reads to do the verification.
2359 * If there is a data mismatch, write a detailed message into a static buffer
2360 * suitable for the caller to print. Otherwise print NULL.
2362 * The fsa flag is set to non-zero if the buffer should be read back through
2363 * the FSA (unicos/mk). This implies the file will be opened
2364 * O_PARALLEL|O_RAW|O_WELLFORMED to do the validation. We must do this because
2365 * FSA will not allow the file to be opened for buffered io if it was
2366 * previously opened for O_PARALLEL io.
2370 check_file(file, offset, length, pattern, pattern_length, patshift, fsa)
2379 static char errbuf[4096];
2381 char *buf, *em, *ep;
2383 struct fd_cache *fdc;
2389 flags = Validation_Flags | O_RDONLY;
2394 if ((fd = alloc_fd(file, flags)) == -1) {
2396 "Could not open file %s with flags %#o (%s) for data comparison: %s (%d)\n",
2397 file, flags, format_oflags(flags),
2402 if (lseek(fd, offset, SEEK_SET) == -1) {
2404 "Could not lseek to offset %d in %s for verification: %s (%d)\n",
2405 offset, file, SYSERR, errno);
2410 /* Guarantee a properly aligned address on Direct I/O */
2411 fdc = alloc_fdcache(file, flags);
2412 if( (flags & O_DIRECT) && ((long)buf % fdc->c_memalign != 0) ) {
2413 buf += fdc->c_memalign - ((long)buf % fdc->c_memalign);
2417 if ((nb = read(fd, buf, length)) == -1) {
2420 "Could not read %d bytes from %s for verification: %s (%d)\n\tread(%d, 0x%p, %d)\n\tbuf %% alignment(%d) = %ld\n",
2421 length, file, SYSERR, errno,
2423 fdc->c_memalign, (long)buf % fdc->c_memalign);
2426 "Could not read %d bytes from %s for verification: %s (%d)\n",
2427 length, file, SYSERR, errno);
2435 "Read wrong # bytes from %s. Expected %d, got %d\n",
2440 if( (em = (*Data_Check)(buf, offset, length, pattern, pattern_length, patshift)) != NULL ) {
2442 ep += sprintf(ep, "*** DATA COMPARISON ERROR ***\n");
2443 ep += sprintf(ep, "check_file(%s, %d, %d, %s, %d, %d) failed\n\n",
2444 file, offset, length, pattern, pattern_length, patshift);
2445 ep += sprintf(ep, "Comparison fd is %d, with open flags %#o\n",
2454 * Function to single-thread stdio output.
2458 doio_fprintf(FILE *stream, char *format, ...)
2460 static int pid = -1;
2466 date = hms(time(0));
2472 flk.l_whence = flk.l_start = flk.l_len = 0;
2473 flk.l_type = F_WRLCK;
2474 fcntl(fileno(stream), F_SETLKW, &flk);
2476 va_start(arglist, format);
2477 rval = fprintf(stream, "\n%s%s (%5d) %s\n", Prog, TagName, pid, date);
2478 rval += fprintf(stream, "---------------------\n");
2479 vfprintf(stream, format, arglist);
2484 flk.l_type = F_UNLCK;
2485 fcntl(fileno(stream), F_SETLKW, &flk);
2491 * Simple function for allocating core memory. Uses Memsize and Memptr to
2492 * keep track of the current amount allocated.
2501 int me = 0, flags, key, shmid;
2502 static int mturn = 0; /* which memory type to use */
2506 struct shmid_ds shm_ds;
2507 bzero( &shm_ds, sizeof(struct shmid_ds) );
2510 /* nbytes = -1 means "free all allocated memory" */
2511 if( nbytes == -1 ) {
2513 for(me=0; me < Nmemalloc; me++) {
2514 if(Memalloc[me].space == NULL)
2517 switch(Memalloc[me].memtype) {
2519 free(Memalloc[me].space);
2520 Memalloc[me].space = NULL;
2525 shmdt(Memalloc[me].space);
2526 Memalloc[me].space = NULL;
2527 shmctl(Memalloc[me].fd, IPC_RMID, &shm_ds);
2530 munmap(Memalloc[me].space,
2532 close(Memalloc[me].fd);
2533 if(Memalloc[me].flags & MEMF_FILE) {
2534 unlink(Memalloc[me].name);
2536 Memalloc[me].space = NULL;
2539 doio_fprintf(stderr, "alloc_mem: HELP! Unknown memory space type %d index %d\n",
2540 Memalloc[me].memtype, me);
2548 * Select a memory area (currently round-robbin)
2551 if(mturn >= Nmemalloc)
2554 M = &Memalloc[mturn];
2556 switch(M->memtype) {
2558 if( nbytes > M->size ) {
2559 if( M->space != NULL ){
2566 if( M->space == NULL ) {
2567 if( (cp = malloc( nbytes )) == NULL ) {
2568 doio_fprintf(stderr, "malloc(%d) failed: %s (%d)\n",
2569 nbytes, SYSERR, errno);
2572 M->space = (void *)cp;
2578 if( nbytes > M->size ) {
2579 if( M->space != NULL ) {
2580 munmap(M->space, M->size);
2582 if( M->flags & MEMF_FILE )
2589 if( M->space == NULL ) {
2590 if(strchr(M->name, '%')) {
2591 sprintf(filename, M->name, getpid());
2592 M->name = strdup(filename);
2595 if( (M->fd = open(M->name, O_CREAT|O_RDWR, 0666)) == -1) {
2596 doio_fprintf(stderr, "alloc_mmap: error %d (%s) opening '%s'\n",
2604 M->size = nbytes * 4;
2606 /* bias addr if MEMF_ADDR | MEMF_FIXADDR */
2607 /* >>> how to pick a memory address? */
2609 /* bias flags on MEMF_PRIVATE etc */
2610 if(M->flags & MEMF_PRIVATE)
2611 flags |= MAP_PRIVATE;
2612 if(M->flags & MEMF_SHARED)
2613 flags |= MAP_SHARED;
2615 /*printf("alloc_mem, about to mmap, fd=%d, name=(%s)\n", M->fd, M->name);*/
2616 if( (M->space = mmap(addr, M->size,
2617 PROT_READ|PROT_WRITE,
2620 doio_fprintf(stderr, "alloc_mem: mmap error. errno %d (%s)\n\tmmap(addr 0x%x, size %d, read|write 0x%x, mmap flags 0x%x [%#o], fd %d, 0)\n\tfile %s\n",
2623 PROT_READ|PROT_WRITE,
2624 flags, M->flags, M->fd,
2626 doio_fprintf(stderr, "\t%s%s%s%s%s",
2627 (flags & MAP_PRIVATE) ? "private " : "",
2628 (flags & MAP_SHARED) ? "shared" : "");
2635 if( nbytes > M->size ) {
2636 if( M->space != NULL ) {
2637 shmctl( M->fd, IPC_RMID, &shm_ds );
2643 if(M->space == NULL) {
2644 if(!strcmp(M->name, "private")) {
2647 sscanf(M->name, "%i", &key);
2650 M->size = M->nblks ? M->nblks * 512 : nbytes;
2652 if( nbytes > M->size ){
2654 doio_fprintf(stderr, "MEM_SHMEM: nblks(%d) too small: nbytes=%d Msize=%d, skipping this req.\n",
2655 M->nblks, nbytes, M->size );
2660 shmid = shmget(key, M->size, IPC_CREAT|0666);
2662 doio_fprintf(stderr, "shmget(0x%x, %d, CREAT) failed: %s (%d)\n",
2663 key, M->size, SYSERR, errno);
2667 M->space = shmat(shmid, NULL, SHM_RND);
2668 if( M->space == (void *)-1 ) {
2669 doio_fprintf(stderr, "shmat(0x%x, NULL, SHM_RND) failed: %s (%d)\n",
2670 shmid, SYSERR, errno);
2677 doio_fprintf(stderr, "alloc_mem: HELP! Unknown memory space type %d index %d\n",
2678 Memalloc[me].memtype, mturn);
2690 * Function to maintain a file descriptor cache, so that doio does not have
2691 * to do so many open() and close() calls. Descriptors are stored in the
2692 * cache by file name, and open flags. Each entry also has a _rtc value
2693 * associated with it which is used in aging. If doio cannot open a file
2694 * because it already has too many open (ie. system limit hit) it will close
2695 * the one in the cache that has the oldest _rtc value.
2697 * If alloc_fd() is called with a file of NULL, it will close all descriptors
2698 * in the cache, and free the memory in the cache.
2702 alloc_fd(file, oflags)
2706 struct fd_cache *fdc;
2707 struct fd_cache *alloc_fdcache(char *file, int oflags);
2709 fdc = alloc_fdcache(file, oflags);
2717 alloc_fdcache(file, oflags)
2722 struct fd_cache *free_slot, *oldest_slot, *cp;
2723 static int cache_size = 0;
2724 static struct fd_cache *cache = NULL;
2726 struct dioattr finfo;
2730 * If file is NULL, it means to free up the fd cache.
2733 if (file == NULL && cache != NULL) {
2734 for (cp = cache; cp < &cache[cache_size]; cp++) {
2735 if (cp->c_fd != -1) {
2738 if (cp->c_memaddr != NULL) {
2739 munmap(cp->c_memaddr, cp->c_memlen);
2753 * Look for a fd in the cache. If one is found, return it directly.
2754 * Otherwise, when this loop exits, oldest_slot will point to the
2755 * oldest fd slot in the cache, and free_slot will point to an
2756 * unoccupied slot if there are any.
2759 for (cp = cache; cp != NULL && cp < &cache[cache_size]; cp++) {
2760 if (cp->c_fd != -1 &&
2761 cp->c_oflags == oflags &&
2762 strcmp(cp->c_file, file) == 0) {
2767 if (cp->c_fd == -1) {
2768 if (free_slot == NULL) {
2772 if (oldest_slot == NULL ||
2773 cp->c_rtc < oldest_slot->c_rtc) {
2780 * No matching file/oflags pair was found in the cache. Attempt to
2784 if ((fd = open(file, oflags, 0666)) < 0) {
2785 if (errno != EMFILE) {
2786 doio_fprintf(stderr,
2787 "Could not open file %s with flags %#o (%s): %s (%d)\n",
2788 file, oflags, format_oflags(oflags),
2795 * If we get here, we have as many open fd's as we can have.
2796 * Close the oldest one in the cache (pointed to by
2797 * oldest_slot), and attempt to re-open.
2800 close(oldest_slot->c_fd);
2801 oldest_slot->c_fd = -1;
2802 free_slot = oldest_slot;
2804 if ((fd = open(file, oflags, 0666)) < 0) {
2805 doio_fprintf(stderr,
2806 "Could not open file %s with flags %#o (%s): %s (%d)\n",
2807 file, oflags, format_oflags(oflags),
2814 /*printf("alloc_fd: new file %s flags %#o fd %d\n", file, oflags, fd);*/
2817 * If we get here, fd is our open descriptor. If free_slot is NULL,
2818 * we need to grow the cache, otherwise free_slot is the slot that
2819 * should hold the fd info.
2822 if (free_slot == NULL) {
2823 cache = (struct fd_cache *)realloc(cache, sizeof(struct fd_cache) * (FD_ALLOC_INCR + cache_size));
2824 if (cache == NULL) {
2825 doio_fprintf(stderr, "Could not malloc() space for fd chace");
2830 cache_size += FD_ALLOC_INCR;
2832 for (cp = &cache[cache_size-FD_ALLOC_INCR];
2833 cp < &cache[cache_size]; cp++) {
2837 free_slot = &cache[cache_size - FD_ALLOC_INCR];
2841 * finally, fill in the cache slot info
2844 free_slot->c_fd = fd;
2845 free_slot->c_oflags = oflags;
2846 strcpy(free_slot->c_file, file);
2847 free_slot->c_rtc = Reqno;
2850 if (oflags & O_DIRECT) {
2851 if (xfsctl(file, fd, XFS_IOC_DIOINFO, &finfo) == -1) {
2853 finfo.d_miniosz = 1;
2854 finfo.d_maxiosz = 1;
2858 finfo.d_miniosz = 1;
2859 finfo.d_maxiosz = 1;
2862 free_slot->c_memalign = finfo.d_mem;
2863 free_slot->c_miniosz = finfo.d_miniosz;
2864 free_slot->c_maxiosz = finfo.d_maxiosz;
2866 free_slot->c_memaddr = NULL;
2867 free_slot->c_memlen = 0;
2874 * Signal Handling Section
2882 havesigint=1; /* in case there's a followup signal */
2891 doio_fprintf(stderr, "terminating on signal %d\n", sig);
2900 /* See sigbus_handler() in the 'ifdef sgi' case for details. Here,
2901 we don't have the siginfo stuff so the guess is weaker but we'll
2905 if( active_mmap_rw && havesigint )
2920 * SIGINT handler for the parent (original doio) process. It simply sends
2921 * a SIGINT to all of the doio children. Since they're all in the same
2922 * pgrp, this can be done with a single kill().
2930 for (i = 0; i < Nchildren; i++) {
2931 if (Children[i] != -1) {
2932 kill(Children[i], SIGINT);
2938 * Signal handler used to inform a process when async io completes. Referenced
2939 * in do_read() and do_write(). Note that the signal handler is not
2948 struct aio_info *aiop;
2950 for (i = 0; i < sizeof(Aio_Info) / sizeof(Aio_Info[0]); i++) {
2951 aiop = &Aio_Info[i];
2953 if (aiop->strategy == A_SIGNAL && aiop->sig == sig) {
2956 if (aio_done(aiop)) {
2964 * dump info on all open aio slots
2972 for (i = 0; i < sizeof(Aio_Info) / sizeof(Aio_Info[0]); i++) {
2973 if (Aio_Info[i].busy) {
2976 "Aio_Info[%03d] id=%d fd=%d signal=%d signaled=%d\n",
2980 Aio_Info[i].signalled);
2981 fprintf(stderr, "\tstrategy=%s\n",
2982 format_strat(Aio_Info[i].strategy));
2985 fprintf(stderr, "%d active async i/os\n", count);
2994 struct aio_info *aiop;
2998 for (i = 0; i < sizeof(Aio_Info) / sizeof(Aio_Info[0]); i++) {
3000 if (! Aio_Info[i].busy) {
3001 aiop = &Aio_Info[i];
3007 if (Aio_Info[i].busy && Aio_Info[i].id == aio_id) {
3008 aiop = &Aio_Info[i];
3015 doio_fprintf(stderr,"aio_slot(%d) not found. Request %d\n",
3026 aio_register(fd, strategy, sig)
3031 struct aio_info *aiop;
3033 struct sigaction sa;
3035 aiop = aio_slot(-1);
3038 aiop->strategy = strategy;
3041 if (strategy == A_SIGNAL) {
3043 aiop->signalled = 0;
3045 sa.sa_handler = aio_handler;
3047 sigemptyset(&sa.sa_mask);
3049 sigaction(sig, &sa, &aiop->osa);
3052 aiop->signalled = 0;
3059 aio_unregister(aio_id)
3062 struct aio_info *aiop;
3064 aiop = aio_slot(aio_id);
3066 if (aiop->strategy == A_SIGNAL) {
3067 sigaction(aiop->sig, &aiop->osa, NULL);
3079 #ifdef RECALL_SIZEOF
3080 long mask[RECALL_SIZEOF];
3083 struct aio_info *aiop;
3085 /*printf("aio_wait: errno %d return %d\n", aiop->aio_errno, aiop->aio_ret);*/
3092 * Format specified time into HH:MM:SS format. t is the time to format
3093 * in seconds (as returned from time(2)).
3100 static char ascii_time[9];
3103 ltime = localtime(&t);
3104 strftime(ascii_time, sizeof(ascii_time), "%H:%M:%S", ltime);
3110 * Simple routine to check if an async io request has completed.
3114 aio_done(struct aio_info *ainfo)
3116 return -1; /* invalid */
3120 * Routine to handle upanic() - it first attempts to set the panic flag. If
3121 * the flag cannot be set, an error message is issued. A call to upanic
3122 * with PA_PANIC is then done unconditionally, in case the panic flag was set
3123 * from outside the program (as with the panic(8) program).
3125 * Note - we only execute the upanic code if -U was used, and the passed in
3126 * mask is set in the Upanic_Conditions bitmask.
3133 if (U_opt == 0 || (mask & Upanic_Conditions) == 0) {
3136 doio_fprintf(stderr, "WARNING - upanic() failed\n");
3140 * Parse cmdline options/arguments and set appropriate global variables.
3141 * If the cmdline is valid, return 0 to caller. Otherwise exit with a status
3146 parse_cmdline(argc, argv, opts)
3152 char cc, *cp, *tok = NULL;
3155 extern char *optarg;
3157 char *memargs[NMEMALLOC];
3159 void parse_memalloc(char *arg);
3160 void parse_delay(char *arg);
3161 void dump_memalloc();
3163 if (*argv[0] == '-') {
3168 if ((Prog = strrchr(argv[0], '/')) == NULL) {
3175 while ((c = getopt(argc, argv, opts)) != EOF) {
3183 for(s=checkmap; s->string != NULL; s++)
3184 if(!strcmp(s->string, optarg))
3186 if (s->string == NULL) {
3188 "%s%s: Illegal -C arg (%s). Must be one of: ",
3189 Prog, TagName, tok);
3191 for (s = checkmap; s->string != NULL; s++)
3192 fprintf(stderr, "%s ", s->string);
3193 fprintf(stderr, "\n");
3199 Data_Fill = doio_pat_fill;
3200 Data_Check = doio_pat_check;
3204 "%s%s: Unrecognised -C arg '%s' %d",
3205 Prog, TagName, s->string, s->value);
3210 case 'd': /* delay between i/o ops */
3211 parse_delay(optarg);
3215 if (Npes > 1 && Nprocs > 1) {
3216 fprintf(stderr, "%s%s: Warning - Program is a multi-pe application - exec option is ignored.\n", Prog, TagName);
3231 Message_Interval = strtol(optarg, &cp, 10);
3232 if (*cp != '\0' || Message_Interval < 0) {
3233 fprintf(stderr, "%s%s: Illegal -m arg (%s): Must be an integer >= 0\n", Prog, TagName, optarg);
3239 case 'M': /* memory allocation types */
3240 nmemargs = string_to_tokens(optarg, memargs, 32, ",");
3241 for(ma=0; ma < nmemargs; ma++) {
3242 parse_memalloc(memargs[ma]);
3244 /*dump_memalloc();*/
3249 sprintf( TagName, "(%.39s)", optarg );
3253 Nprocs = strtol(optarg, &cp, 10);
3254 if (*cp != '\0' || Nprocs < 1) {
3256 "%s%s: Illegal -n arg (%s): Must be integer > 0\n",
3257 Prog, TagName, optarg);
3261 if (Npes > 1 && Nprocs > 1) {
3262 fprintf(stderr, "%s%s: Program has been built as a multi-pe app. -n1 is the only nprocs value allowed\n", Prog, TagName);
3269 Release_Interval = strtol(optarg, &cp, 10);
3270 if (*cp != '\0' || Release_Interval < 0) {
3272 "%s%s: Illegal -r arg (%s): Must be integer >= 0\n",
3273 Prog, TagName, optarg);
3290 if (strcasecmp(optarg, "sync") == 0) {
3291 Validation_Flags = O_SYNC;
3292 } else if (strcasecmp(optarg, "buffered") == 0) {
3293 Validation_Flags = 0;
3294 } else if (strcasecmp(optarg, "direct") == 0) {
3295 Validation_Flags = O_DIRECT;
3297 if (sscanf(optarg, "%i%c", &Validation_Flags, &cc) != 1) {
3298 fprintf(stderr, "%s: Invalid -V argument (%s) - must be a decimal, hex, or octal\n", Prog, optarg);
3299 fprintf(stderr, " number, or one of the following strings: 'sync',\n");
3300 fprintf(stderr, " 'buffered', 'parallel', 'ldraw', or 'raw'\n");
3307 tok = strtok(optarg, ",");
3308 while (tok != NULL) {
3309 for (s = Upanic_Args; s->string != NULL; s++)
3310 if (strcmp(s->string, tok) == 0)
3313 if (s->string == NULL) {
3315 "%s%s: Illegal -U arg (%s). Must be one of: ",
3316 Prog, TagName, tok);
3318 for (s = Upanic_Args; s->string != NULL; s++)
3319 fprintf(stderr, "%s ", s->string);
3321 fprintf(stderr, "\n");
3326 Upanic_Conditions |= s->value;
3327 tok = strtok(NULL, ",");
3345 Data_Fill = doio_pat_fill;
3346 Data_Check = doio_pat_check;
3350 Upanic_Conditions = 0;
3356 Release_Interval = DEF_RELEASE_INTERVAL;
3359 Memalloc[Nmemalloc].memtype = MEM_DATA;
3360 Memalloc[Nmemalloc].flags = 0;
3361 Memalloc[Nmemalloc].name = NULL;
3362 Memalloc[Nmemalloc].space = NULL;
3367 * Initialize input stream
3370 if (argc == optind) {
3373 Infile = argv[optind++];
3376 if (argc != optind) {
3387 * Parse memory allocation types
3391 * T3E-shmem:blksize[:nblks]
3392 * SysV-shmem:shmid:blksize:nblks
3393 * if shmid is "private", use IPC_PRIVATE
3394 * and nblks is not required
3396 * mmap:flags:filename:blksize[:nblks]
3398 * p - private (MAP_PRIVATE)
3399 * a - private, MAP_AUTORESRV
3400 * l - local (MAP_LOCAL)
3401 * s - shared (nblks required)
3404 * f - fixed address (MAP_FIXED)
3405 * A - use an address without MAP_FIXED
3406 * a - autogrow (map once at startup)
3408 * mmap:flags:devzero
3409 * mmap /dev/zero (shared not allowd)
3410 * maps the first 4096 bytes of /dev/zero
3412 * - put a directory at the beginning of the shared
3413 * regions saying what pid has what region.
3417 * nblks worth of directories - 1 int pids
3420 parse_memalloc(char *arg)
3422 char *allocargs[NMEMALLOC];
3426 if(Nmemalloc >= NMEMALLOC) {
3427 doio_fprintf(stderr, "Error - too many memory types (%d).\n",
3432 M = &Memalloc[Nmemalloc];
3434 nalloc = string_to_tokens(arg, allocargs, 32, ":");
3435 if(!strcmp(allocargs[0], "data")) {
3436 M->memtype = MEM_DATA;
3442 if(strchr(allocargs[1], 'p'))
3443 M->flags |= MEMF_MPIN;
3445 } else if(!strcmp(allocargs[0], "mmap")) {
3446 /* mmap:flags:filename[:size] */
3447 M->memtype = MEM_MMAP;
3451 if(strchr(allocargs[1], 'p'))
3452 M->flags |= MEMF_PRIVATE;
3453 if(strchr(allocargs[1], 'a'))
3454 M->flags |= MEMF_AUTORESRV;
3455 if(strchr(allocargs[1], 'l'))
3456 M->flags |= MEMF_LOCAL;
3457 if(strchr(allocargs[1], 's'))
3458 M->flags |= MEMF_SHARED;
3460 if(strchr(allocargs[1], 'f'))
3461 M->flags |= MEMF_FIXADDR;
3462 if(strchr(allocargs[1], 'A'))
3463 M->flags |= MEMF_ADDR;
3464 if(strchr(allocargs[1], 'G'))
3465 M->flags |= MEMF_AUTOGROW;
3467 if(strchr(allocargs[1], 'U'))
3468 M->flags |= MEMF_FILE;
3470 M->flags |= MEMF_PRIVATE;
3474 if(!strcmp(allocargs[2], "devzero")) {
3475 M->name = "/dev/zero";
3477 ((MEMF_PRIVATE|MEMF_LOCAL) == 0))
3478 M->flags |= MEMF_PRIVATE;
3480 M->name = allocargs[2];
3483 M->name = "/dev/zero";
3485 ((MEMF_PRIVATE|MEMF_LOCAL) == 0))
3486 M->flags |= MEMF_PRIVATE;
3490 } else if(!strcmp(allocargs[0], "shmem")) {
3491 /* shmem:shmid:size */
3492 M->memtype = MEM_SHMEM;
3496 M->name = allocargs[1];
3501 sscanf(allocargs[2], "%i", &M->nblks);
3506 if(strchr(allocargs[3], 'p'))
3507 M->flags |= MEMF_MPIN;
3512 doio_fprintf(stderr, "Error - unknown memory type '%s'.\n",
3524 if(Nmemalloc == 0) {
3525 printf("No memory allocation strategies devined\n");
3529 for(ma=0; ma < Nmemalloc; ma++) {
3530 switch(Memalloc[ma].memtype) {
3531 case MEM_DATA: mt = "data"; break;
3532 case MEM_SHMEM: mt = "shmem"; break;
3533 case MEM_MMAP: mt = "mmap"; break;
3534 default: mt = "unknown"; break;
3536 printf("mstrat[%d] = %d %s\n", ma, Memalloc[ma].memtype, mt);
3537 printf("\tflags=%#o name='%s' nblks=%d\n",
3540 Memalloc[ma].nblks);
3545 * -d <op>:<time> - doio inter-operation delay
3546 * currently this permits ONE type of delay between operations.
3550 parse_delay(char *arg)
3552 char *delayargs[NMEMALLOC];
3556 ndelay = string_to_tokens(arg, delayargs, 32, ":");
3558 doio_fprintf(stderr,
3559 "Illegal delay arg (%s). Must be operation:time\n", arg);
3562 for(s=delaymap; s->string != NULL; s++)
3563 if(!strcmp(s->string, delayargs[0]))
3565 if (s->string == NULL) {
3567 "Illegal Delay arg (%s). Must be one of: ", arg);
3569 for (s = delaymap; s->string != NULL; s++)
3570 fprintf(stderr, "%s ", s->string);
3571 fprintf(stderr, "\n");
3577 sscanf(delayargs[1], "%i", &delaytime);
3581 "Warning: extra delay arguments ignored.\n");
3587 * Usage clause - obvious
3595 * Only do this if we are on vpe 0, to avoid seeing it from every
3596 * process in the application.
3599 if (Npes > 1 && Vpe != 0) {
3603 fprintf(stream, "usage%s: %s [-aekv] [-m message_interval] [-n nprocs] [-r release_interval] [-w write_log] [-V validation_ftype] [-U upanic_cond] [infile]\n", TagName, Prog);
3612 * Only the app running on vpe 0 gets to issue help - this prevents
3613 * everybody in the application from doing this.
3616 if (Npes > 1 && Vpe != 0) {
3621 fprintf(stream, "\n");
3622 fprintf(stream, "\t-a abort - kill all doio processes on data compare\n");
3623 fprintf(stream, "\t errors. Normally only the erroring process exits\n");
3624 fprintf(stream, "\t-C data-pattern-type \n");
3625 fprintf(stream, "\t Available data patterns are:\n");
3626 fprintf(stream, "\t default - repeating pattern\n");
3627 fprintf(stream, "\t-d Operation:Time Inter-operation delay.\n");
3628 fprintf(stream, "\t Operations are:\n");
3629 fprintf(stream, "\t select:time (1 second=1000000)\n");
3630 fprintf(stream, "\t sleep:time (1 second=1)\n");
3631 fprintf(stream, "\t alarm:time (1 second=1)\n");
3632 fprintf(stream, "\t-e Re-exec children before entering the main\n");
3633 fprintf(stream, "\t loop. This is useful for spreading\n");
3634 fprintf(stream, "\t procs around on multi-pe systems.\n");
3635 fprintf(stream, "\t-k Lock file regions during writes using fcntl()\n");
3636 fprintf(stream, "\t-v Verify writes - this is done by doing a buffered\n");
3637 fprintf(stream, "\t read() of the data if file io was done, or\n");
3638 fprintf(stream, "\t an ssread()of the data if sds io was done\n");
3639 fprintf(stream, "\t-M Data buffer allocation method\n");
3640 fprintf(stream, "\t alloc-type[,type]\n");
3641 fprintf(stream, "\t data\n");
3642 fprintf(stream, "\t shmem:shmid:size\n");
3643 fprintf(stream, "\t mmap:flags:filename\n");
3644 fprintf(stream, "\t p - private\n");
3645 fprintf(stream, "\t s - shared (shared file must exist\n"),
3646 fprintf(stream, "\t and have needed length)\n");
3647 fprintf(stream, "\t f - fixed address (not used)\n");
3648 fprintf(stream, "\t a - specify address (not used)\n");
3649 fprintf(stream, "\t U - Unlink file when done\n");
3650 fprintf(stream, "\t The default flag is private\n");
3651 fprintf(stream, "\n");
3652 fprintf(stream, "\t-m message_interval Generate a message every 'message_interval'\n");
3653 fprintf(stream, "\t requests. An interval of 0 suppresses\n");
3654 fprintf(stream, "\t messages. The default is 0.\n");
3655 fprintf(stream, "\t-N tagname Tag name, for Monster.\n");
3656 fprintf(stream, "\t-n nprocs # of processes to start up\n");
3657 fprintf(stream, "\t-r release_interval Release all memory and close\n");
3658 fprintf(stream, "\t files every release_interval operations.\n");
3659 fprintf(stream, "\t By default procs never release memory\n");
3660 fprintf(stream, "\t or close fds unless they have to.\n");
3661 fprintf(stream, "\t-V validation_ftype The type of file descriptor to use for doing data\n");
3662 fprintf(stream, "\t validation. validation_ftype may be an octal,\n");
3663 fprintf(stream, "\t hex, or decimal number representing the open()\n");
3664 fprintf(stream, "\t flags, or may be one of the following strings:\n");
3665 fprintf(stream, "\t 'buffered' - validate using bufferd read\n");
3666 fprintf(stream, "\t 'sync' - validate using O_SYNC read\n");
3667 fprintf(stream, "\t 'direct - validate using O_DIRECT read'\n");
3668 fprintf(stream, "\t By default, 'parallel'\n");
3669 fprintf(stream, "\t is used if the write was done with O_PARALLEL\n");
3670 fprintf(stream, "\t or 'buffered' for all other writes.\n");
3671 fprintf(stream, "\t-w write_log File to log file writes to. The doio_check\n");
3672 fprintf(stream, "\t program can reconstruct datafiles using the\n");
3673 fprintf(stream, "\t write_log, and detect if a file is corrupt\n");
3674 fprintf(stream, "\t after all procs have exited.\n");
3675 fprintf(stream, "\t-U upanic_cond Comma separated list of conditions that will\n");
3676 fprintf(stream, "\t cause a call to upanic(PA_PANIC).\n");
3677 fprintf(stream, "\t 'corruption' -> upanic on bad data comparisons\n");
3678 fprintf(stream, "\t 'iosw' ---> upanic on unexpected async iosw\n");
3679 fprintf(stream, "\t 'rval' ---> upanic on unexpected syscall rvals\n");
3680 fprintf(stream, "\t 'all' ---> all of the above\n");
3681 fprintf(stream, "\n");
3682 fprintf(stream, "\tinfile Input stream - default is stdin - must be a list\n");
3683 fprintf(stream, "\t of io_req structures (see doio.h). Currently\n");
3684 fprintf(stream, "\t only the iogen program generates the proper\n");
3685 fprintf(stream, "\t format\n");