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 */
41 int do_xfsctl(struct io_req *);
45 #include "write_log.h"
46 #include "random_range.h"
47 #include "string_to_tokens.h"
50 #define O_SSD 0 /* so code compiles on a CRAY2 */
53 #define UINT64_T unsigned long long
56 #define O_PARALLEL 0 /* so O_PARALLEL may be used in expressions */
59 #define PPID_CHECK_INTERVAL 5 /* check ppid every <-- iterations */
60 #define MAX_AIO 256 /* maximum number of async I/O ops */
64 #define SYSERR strerror(errno)
67 * getopt() string of supported cmdline arguments.
70 #define OPTS "aC:d:ehm:n:kr:w:vU:V:M:N:"
72 #define DEF_RELEASE_INTERVAL 0
75 * Flags set in parse_cmdline() to indicate which options were selected
79 int a_opt = 0; /* abort on data compare errors */
80 int e_opt = 0; /* exec() after fork()'ing */
81 int C_opt = 0; /* Data Check Type */
82 int d_opt = 0; /* delay between operations */
83 int k_opt = 0; /* lock file regions during writes */
84 int m_opt = 0; /* generate periodic messages */
85 int n_opt = 0; /* nprocs */
86 int r_opt = 0; /* resource release interval */
87 int w_opt = 0; /* file write log file */
88 int v_opt = 0; /* verify writes if set */
89 int U_opt = 0; /* upanic() on varios conditions */
90 int V_opt = 0; /* over-ride default validation fd type */
91 int M_opt = 0; /* data buffer allocation types */
92 char TagName[40]; /* name of this doio (see Monster) */
96 * Misc globals initialized in parse_cmdline()
99 char *Prog = NULL; /* set up in parse_cmdline() */
100 int Upanic_Conditions; /* set by args to -U */
101 int Release_Interval; /* arg to -r */
102 int Nprocs; /* arg to -n */
103 char *Write_Log; /* arg to -w */
104 char *Infile; /* input file (defaults to stdin) */
105 int *Children; /* pids of child procs */
107 int Nsiblings = 0; /* tfork'ed siblings */
109 int Message_Interval = 0;
110 int Npes = 0; /* non-zero if built as an mpp multi-pe app */
111 int Vpe = -1; /* Virtual pe number if Npes >= 0 */
112 int Reqno = 1; /* request # - used in some error messages */
113 int Reqskipcnt = 0; /* count of I/O requests that are skipped */
114 int Validation_Flags;
115 char *(*Data_Check)(); /* function to call for data checking */
116 int (*Data_Fill)(); /* function to call for data filling */
117 int Nmemalloc = 0; /* number of memory allocation strategies */
118 int delayop = 0; /* delay between operations - type of delay */
119 int delaytime = 0; /* delay between operations - how long */
121 struct wlog_file Wlog;
123 int active_mmap_rw = 0; /* Indicates that mmapped I/O is occurring. */
124 /* Used by sigbus_action() in the child doio. */
127 #define SKIP_REQ -2 /* skip I/O request */
130 #define MEM_DATA 1 /* data space */
131 #define MEM_SHMEM 2 /* System V shared memory */
132 #define MEM_T3ESHMEM 3 /* T3E Shared Memory */
133 #define MEM_MMAP 4 /* mmap(2) */
135 #define MEMF_PRIVATE 0001
136 #define MEMF_AUTORESRV 0002
137 #define MEMF_LOCAL 0004
138 #define MEMF_SHARED 0010
140 #define MEMF_FIXADDR 0100
141 #define MEMF_ADDR 0200
142 #define MEMF_AUTOGROW 0400
143 #define MEMF_FILE 01000 /* regular file -- unlink on close */
144 #define MEMF_MPIN 010000 /* use mpin(2) to lock pages in memory */
151 void *space; /* memory address of allocated space */
152 int fd; /* FD open for mmaping */
154 } Memalloc[NMEMALLOC];
157 * Global file descriptors
160 int Wfd_Append; /* for appending to the write-log */
161 int Wfd_Random; /* for overlaying write-log entries */
164 * Structure for maintaining open file test descriptors. Used by
169 char c_file[MAX_FNAME_LENGTH+1];
173 int c_memalign; /* from xfsctl(XFS_IOC_DIOINFO) */
176 void *c_memaddr; /* mmapped address */
177 int c_memlen; /* length of above region */
180 #define FD_ALLOC_INCR 32 /* allocate this many fd_map structs */
184 * Globals for tracking Sds and Core usage
187 char *Memptr; /* ptr to core buffer space */
188 int Memsize; /* # bytes pointed to by Memptr */
189 /* maintained by alloc_mem() */
191 int Sdsptr; /* sds offset (always 0) */
192 int Sdssize; /* # bytes of allocated sds space */
193 /* Maintained by alloc_sds() */
199 * Signal handlers, and related globals
202 void sigint_handler(); /* Catch SIGINT in parent doio, propagate
203 * to children, does not die. */
205 void die_handler(); /* Bad sig in child doios, exit 1. */
206 void cleanup_handler(); /* Normal kill, exit 0. */
208 void sigbus_handler(); /* Handle sigbus--check active_mmap_rw to
209 decide if this should be a normal exit. */
211 void cb_handler(); /* Posix aio callback handler. */
212 void noop_handler(); /* Delayop alarm, does nothing. */
216 char *format_listio();
217 char *check_file(char *file, int offset, int length, char *pattern,
218 int pattern_length, int patshift, int fsa);
219 int doio_fprintf(FILE *stream, char *format, ...);
220 void doio_upanic(int mask);
222 void help(FILE *stream);
224 int alloc_fd( char *, int );
225 int alloc_mem( int );
226 int do_read( struct io_req * );
227 int do_write( struct io_req * );
228 int do_rw( struct io_req * );
229 int do_sync( struct io_req * );
231 int aio_unregister( int );
232 int parse_cmdline( int, char **, char * );
233 int lock_file_region( char *, int, int, int, int );
234 struct fd_cache *alloc_fdcache(char *, int);
235 int aio_register( int, int, int );
241 * Upanic conditions, and a map from symbolics to values
244 #define U_CORRUPTION 0001 /* upanic on data corruption */
245 #define U_IOSW 0002 /* upanic on bad iosw */
246 #define U_RVAL 0004 /* upanic on bad rval */
248 #define U_ALL (U_CORRUPTION | U_IOSW | U_RVAL)
252 * Used to map cmdline arguments to values
259 struct smap Upanic_Args[] = {
260 { "corruption", U_CORRUPTION },
275 struct sigaction osa;
278 struct aio_info Aio_Info[MAX_AIO];
280 struct aio_info *aio_slot();
281 int aio_done( struct aio_info * );
283 /* -C data-fill/check type */
285 struct smap checkmap[] = {
286 { "default", C_DEFAULT },
290 /* -d option delay types */
291 #define DELAY_SELECT 1
292 #define DELAY_SLEEP 2
293 #define DELAY_SGINAP 3
294 #define DELAY_ALARM 4
295 #define DELAY_ITIMER 5 /* POSIX timer */
297 struct smap delaymap[] = {
298 { "select", DELAY_SELECT },
299 { "sleep", DELAY_SLEEP },
300 { "alarm", DELAY_ALARM },
306 * strerror() does similar actions.
311 static char sys_errno[10];
312 sprintf(sys_errno, "%d", errno);
323 int i, pid, stat, ex_stat;
325 sigset_t block_mask, old_mask;
326 umask(0); /* force new file modes to known values */
329 parse_cmdline(argc, argv, OPTS);
331 random_range_seed(getpid()); /* initialize random number generator */
334 * If this is a re-exec of doio, jump directly into the doio function.
343 * Stop on all but a few signals...
345 sigemptyset(&sa.sa_mask);
346 sa.sa_handler = sigint_handler;
347 sa.sa_flags = SA_RESETHAND; /* sigint is ignored after the */
349 for (i = 1; i <= NSIG; i++) {
370 sigaction(i, &sa, NULL);
375 * If we're logging write operations, make a dummy call to wlog_open
376 * to initialize the write history file. This call must be done in
377 * the parent, to ensure that the history file exists and/or has
378 * been truncated before any children attempt to open it, as the doio
379 * children are not allowed to truncate the file.
383 strcpy(Wlog.w_file, Write_Log);
385 if (wlog_open(&Wlog, 1, 0666) < 0) {
387 "Could not create/truncate write log %s\n",
396 * Malloc space for the children pid array. Initialize all entries
400 Children = (int *)malloc(sizeof(int) * Nprocs);
401 for (i = 0; i < Nprocs; i++) {
405 sigemptyset(&block_mask);
406 sigaddset(&block_mask, SIGCHLD);
407 sigprocmask(SIG_BLOCK, &block_mask, &old_mask);
410 * Fork Nprocs. This [parent] process is a watchdog, to notify the
411 * invoker of procs which exit abnormally, and to make sure that all
412 * child procs get cleaned up. If the -e option was used, we will also
413 * re-exec. This is mostly for unicos/mk on mpp's, to ensure that not
414 * all of the doio's don't end up in the same pe.
416 * Note - if Nprocs is 1, or this doio is a multi-pe app (Npes > 1),
417 * jump directly to doio(). multi-pe apps can't fork(), and there is
418 * no reason to fork() for 1 proc.
421 if (Nprocs == 1 || Npes > 1) {
425 for (i = 0; i < Nprocs; i++) {
426 if ((pid = fork()) == -1) {
428 "(parent) Could not fork %d children: %s (%d)\n",
433 Children[Nchildren] = pid;
441 argv[0] = (char *)malloc(strlen(exec_path + 1));
442 sprintf(argv[0], "-%s", exec_path);
444 execvp(exec_path, argv);
446 "(parent) Could not execvp %s: %s (%d)\n",
447 exec_path, SYSERR, errno);
457 * Parent spins on wait(), until all children exit.
463 if ((pid = wait(&stat)) == -1) {
468 for (i = 0; i < Nchildren; i++)
469 if (Children[i] == pid)
474 if (WIFEXITED(stat)) {
475 switch (WEXITSTATUS(stat)) {
482 "(parent) pid %d exited because of an internal error\n",
484 ex_stat |= E_INTERNAL;
489 "(parent) pid %d exited because of a setup error\n",
496 "(parent) pid %d exited because of data compare errors\n",
499 ex_stat |= E_COMPARE;
508 "(parent) pid %d exited because of a usage error\n",
516 "(parent) pid %d exited with unknown status %d\n",
517 pid, WEXITSTATUS(stat));
518 ex_stat |= E_INTERNAL;
521 } else if (WIFSIGNALED(stat) && WTERMSIG(stat) != SIGINT) {
523 "(parent) pid %d terminated by signal %d\n",
524 pid, WTERMSIG(stat));
538 * main doio function. Each doio child starts here, and never returns.
544 int rval, i, infd, nbytes;
547 struct sigaction sa, def_action, ignore_action, exit_action;
548 struct sigaction sigbus_action;
550 Memsize = Sdssize = 0;
553 * Initialize the Pattern - write-type syscalls will replace Pattern[1]
554 * with the pattern passed in the request. Make sure that
555 * strlen(Pattern) is not mod 16 so that out of order words will be
559 gethostname(Host, sizeof(Host));
560 if ((cp = strchr(Host, '.')) != NULL)
563 Pattern_Length = sprintf(Pattern, "-:%d:%s:%s*", (int)getpid(), Host, Prog);
565 if (!(Pattern_Length % 16)) {
566 Pattern_Length = sprintf(Pattern, "-:%d:%s:%s**",
567 (int)getpid(), Host, Prog);
571 * Open a couple of descriptors for the write-log file. One descriptor
572 * is for appending, one for random access. Write logging is done for
573 * file corruption detection. The program doio_check is capable of
574 * doing corruption detection based on a doio write-log.
579 strcpy(Wlog.w_file, Write_Log);
581 if (wlog_open(&Wlog, 0, 0666) == -1) {
583 "Could not open write log file (%s): wlog_open() failed\n",
590 * Open the input stream - either a file or stdin
593 if (Infile == NULL) {
596 if ((infd = open(Infile, O_RDWR)) == -1) {
598 "Could not open input file (%s): %s (%d)\n",
599 Infile, SYSERR, errno);
605 * Define a set of signals that should never be masked. Receipt of
606 * these signals generally indicates a programming error, and we want
607 * a corefile at the point of error. We put SIGQUIT in this list so
608 * that ^\ will force a user core dump.
610 * Note: the handler for these should be SIG_DFL, all of them
611 * produce a corefile as the default action.
614 ignore_action.sa_handler = SIG_IGN;
615 ignore_action.sa_flags = 0;
616 sigemptyset(&ignore_action.sa_mask);
618 def_action.sa_handler = SIG_DFL;
619 def_action.sa_flags = 0;
620 sigemptyset(&def_action.sa_mask);
622 exit_action.sa_handler = cleanup_handler;
623 exit_action.sa_flags = 0;
624 sigemptyset(&exit_action.sa_mask);
626 sa.sa_handler = die_handler;
628 sigemptyset(&sa.sa_mask);
630 sigbus_action.sa_handler = sigbus_handler;
631 sigbus_action.sa_flags = 0;
632 sigemptyset(&sigbus_action.sa_mask);
634 for (i = 1; i <= NSIG; i++) {
636 /* Signals to terminate program on */
638 sigaction(i, &exit_action, NULL);
641 /* This depends on active_mmap_rw */
643 sigaction(i, &sigbus_action, NULL);
646 /* Signals to Ignore... */
652 sigaction(i, &ignore_action, NULL);
655 /* Signals to trap & report & die */
658 #ifdef SIGERR /* cray only signals */
671 sigaction(i, &sa, NULL);
675 /* Default Action for all other signals */
677 sigaction(i, &def_action, NULL);
683 * Main loop - each doio proc does this until the read returns eof (0).
684 * Call the appropriate io function based on the request type.
687 while ((nbytes = read(infd, (char *)&ioreq, sizeof(ioreq)))) {
690 * Periodically check our ppid. If it is 1, the child exits to
691 * help clean up in the case that the main doio process was
695 if (Reqno && ((Reqno % PPID_CHECK_INTERVAL) == 0)) {
696 if (getppid() == 1) {
698 "Parent doio process has exited\n");
706 "read of %d bytes from input failed: %s (%d)\n",
707 sizeof(ioreq), SYSERR, errno);
712 if (nbytes != sizeof(ioreq)) {
714 "read wrong # bytes from input stream, expected %d, got %d\n",
715 sizeof(ioreq), nbytes);
720 if (ioreq.r_magic != DOIO_MAGIC) {
722 "got a bad magic # from input stream. Expected 0%o, got 0%o\n",
723 DOIO_MAGIC, ioreq.r_magic);
729 * If we're on a Release_Interval multiple, relase all ssd and
730 * core space, and close all fd's in Fd_Map[].
733 if (Reqno && Release_Interval && ! (Reqno%Release_Interval)) {
744 switch (ioreq.r_type) {
747 rval = do_read(&ioreq);
752 rval = do_write(&ioreq);
775 rval = do_rw(&ioreq);
779 rval = do_xfsctl(&ioreq);
783 rval = do_sync(&ioreq);
787 "Don't know how to handle io request type %d\n",
793 if (rval == SKIP_REQ){
796 else if (rval != 0) {
799 "doio(): operation %d returned != 0\n",
804 if (Message_Interval && Reqno % Message_Interval == 0) {
805 doio_fprintf(stderr, "Info: %d requests done (%d skipped) by this process\n", Reqno, Reqskipcnt);
815 * Child exits normally
825 struct timeval tv_delay;
826 struct sigaction sa_al, sa_old;
831 tv_delay.tv_sec = delaytime / 1000000;
832 tv_delay.tv_usec = delaytime % 1000000;
833 /*doio_fprintf(stdout, "delay_select: %d %d\n",
834 tv_delay.tv_sec, tv_delay.tv_usec);*/
835 select(0, NULL, NULL, NULL, &tv_delay);
844 sa_al.sa_handler = noop_handler;
845 sigemptyset(&sa_al.sa_mask);
846 sigaction(SIGALRM, &sa_al, &sa_old);
847 sigemptyset(&al_mask);
849 sigsuspend(&al_mask);
850 sigaction(SIGALRM, &sa_old, 0);
857 * Format IO requests, returning a pointer to the formatted text.
859 * format_strat - formats the async i/o completion strategy
860 * format_rw - formats a read[a]/write[a] request
861 * format_sds - formats a ssread/sswrite request
862 * format_listio- formats a listio request
864 * ioreq is the doio io request structure.
867 struct smap sysnames[] = {
871 { "WRITEA", WRITEA },
872 { "SSREAD", SSREAD },
873 { "SSWRITE", SSWRITE },
874 { "LISTIO", LISTIO },
876 { "LREADA", LREADA },
877 { "LWRITE", LWRITE },
878 { "LWRITEA", LWRITEA },
879 { "LSREAD", LSREAD },
880 { "LSREADA", LSREADA },
881 { "LSWRITE", LSWRITE },
882 { "LSWRITEA", LSWRITEA },
884 /* Irix System Calls */
886 { "PWRITE", PWRITE },
888 { "AWRITE", AWRITE },
889 { "LLREAD", LLREAD },
890 { "LLAREAD", LLAREAD },
891 { "LLWRITE", LLWRITE },
892 { "LLAWRITE", LLAWRITE },
893 { "RESVSP", RESVSP },
894 { "UNRESVSP", UNRESVSP },
896 /* Irix and Linux System Calls */
898 { "WRITEV", WRITEV },
901 { "FSYNC2", FSYNC2 },
902 { "FDATASYNC", FDATASYNC },
907 struct smap aionames[] = {
909 { "signal", A_SIGNAL },
910 { "recall", A_RECALL },
911 { "recalla", A_RECALLA },
912 { "recalls", A_RECALLS },
913 { "suspend", A_SUSPEND },
914 { "callback", A_CALLBACK },
920 format_oflags(int oflags)
926 switch(oflags & 03) {
927 case O_RDONLY: strcat(flags,"O_RDONLY,"); break;
928 case O_WRONLY: strcat(flags,"O_WRONLY,"); break;
929 case O_RDWR: strcat(flags,"O_RDWR,"); break;
930 default: strcat(flags,"O_weird"); break;
934 strcat(flags,"O_EXCL,");
937 strcat(flags,"O_SYNC,");
939 if(oflags & O_DIRECT)
940 strcat(flags,"O_DIRECT,");
942 return(strdup(flags));
946 format_strat(int strategy)
952 case A_POLL: aio_strat = "POLL"; break;
953 case A_SIGNAL: aio_strat = "SIGNAL"; break;
954 case A_RECALL: aio_strat = "RECALL"; break;
955 case A_RECALLA: aio_strat = "RECALLA"; break;
956 case A_RECALLS: aio_strat = "RECALLS"; break;
957 case A_SUSPEND: aio_strat = "SUSPEND"; break;
958 case A_CALLBACK: aio_strat = "CALLBACK"; break;
959 case 0: aio_strat = "<zero>"; break;
961 sprintf(msg, "<error:%#o>", strategy);
962 aio_strat = strdup(msg);
971 struct io_req *ioreq,
979 static char *errbuf=NULL;
980 char *aio_strat, *cp;
981 struct read_req *readp = &ioreq->r_data.read;
982 struct write_req *writep = &ioreq->r_data.write;
983 struct read_req *readap = &ioreq->r_data.read;
984 struct write_req *writeap = &ioreq->r_data.write;
987 errbuf = (char *)malloc(32768);
990 cp += sprintf(cp, "Request number %d\n", Reqno);
992 switch (ioreq->r_type) {
994 cp += sprintf(cp, "syscall: read(%d, %#lo, %d)\n",
995 fd, (unsigned long) buffer, readp->r_nbytes);
996 cp += sprintf(cp, " fd %d is file %s - open flags are %#o\n",
997 fd, readp->r_file, readp->r_oflags);
998 cp += sprintf(cp, " read done at file offset %d\n",
1003 cp += sprintf(cp, "syscall: write(%d, %#lo, %d)\n",
1004 fd, (unsigned long) buffer, writep->r_nbytes);
1005 cp += sprintf(cp, " fd %d is file %s - open flags are %#o\n",
1006 fd, writep->r_file, writep->r_oflags);
1007 cp += sprintf(cp, " write done at file offset %d - pattern is %s\n",
1008 writep->r_offset, pattern);
1012 aio_strat = format_strat(readap->r_aio_strat);
1014 cp += sprintf(cp, "syscall: reada(%d, %#lo, %d, %#lo, %d)\n",
1015 fd, (unsigned long) buffer, readap->r_nbytes,
1016 (unsigned long) iosw, signo);
1017 cp += sprintf(cp, " fd %d is file %s - open flags are %#o\n",
1018 fd, readap->r_file, readp->r_oflags);
1019 cp += sprintf(cp, " reada done at file offset %d\n",
1021 cp += sprintf(cp, " async io completion strategy is %s\n",
1026 aio_strat = format_strat(writeap->r_aio_strat);
1028 cp += sprintf(cp, "syscall: writea(%d, %#lo, %d, %#lo, %d)\n",
1029 fd, (unsigned long) buffer, writeap->r_nbytes,
1030 (unsigned long) iosw, signo);
1031 cp += sprintf(cp, " fd %d is file %s - open flags are %#o\n",
1032 fd, writeap->r_file, writeap->r_oflags);
1033 cp += sprintf(cp, " writea done at file offset %d - pattern is %s\n",
1034 writeap->r_offset, pattern);
1035 cp += sprintf(cp, " async io completion strategy is %s\n",
1045 * Perform the various sorts of disk reads
1052 int fd, offset, nbytes, oflags, rval;
1054 struct fd_cache *fdc;
1057 * Initialize common fields - assumes r_oflags, r_file, r_offset, and
1058 * r_nbytes are at the same offset in the read_req and reada_req
1062 file = req->r_data.read.r_file;
1063 oflags = req->r_data.read.r_oflags;
1064 offset = req->r_data.read.r_offset;
1065 nbytes = req->r_data.read.r_nbytes;
1067 /*printf("read: %s, %#o, %d %d\n", file, oflags, offset, nbytes);*/
1070 * Grab an open file descriptor
1071 * Note: must be done before memory allocation so that the direct i/o
1072 * information is available in mem. allocate
1075 if ((fd = alloc_fd(file, oflags)) == -1)
1079 * Allocate core or sds - based on the O_SSD flag
1083 #define wtob(x) (x * sizeof(UINT64_T))
1086 /* get memory alignment for using DIRECT I/O */
1087 fdc = alloc_fdcache(file, oflags);
1089 if ((rval = alloc_mem(nbytes + wtob(1) * 2 + fdc->c_memalign)) < 0) {
1096 if( (req->r_data.read.r_uflags & F_WORD_ALIGNED) ) {
1098 * Force memory alignment for Direct I/O
1100 if( (oflags & O_DIRECT) && ((long)addr % fdc->c_memalign != 0) ) {
1101 addr += fdc->c_memalign - ((long)addr % fdc->c_memalign);
1104 addr += random_range(0, wtob(1) - 1, 1, NULL);
1107 switch (req->r_type) {
1109 /* move to the desired file position. */
1110 if (lseek(fd, offset, SEEK_SET) == -1) {
1111 doio_fprintf(stderr,
1112 "lseek(%d, %d, SEEK_SET) failed: %s (%d)\n",
1113 fd, offset, SYSERR, errno);
1117 if ((rval = read(fd, addr, nbytes)) == -1) {
1118 doio_fprintf(stderr,
1119 "read() request failed: %s (%d)\n%s\n",
1121 format_rw(req, fd, addr, -1, NULL, NULL));
1122 doio_upanic(U_RVAL);
1124 } else if (rval != nbytes) {
1125 doio_fprintf(stderr,
1126 "read() request returned wrong # of bytes - expected %d, got %d\n%s\n",
1128 format_rw(req, fd, addr, -1, NULL, NULL));
1129 doio_upanic(U_RVAL);
1135 return 0; /* if we get here, everything went ok */
1139 * Perform the verious types of disk writes.
1146 static int pid = -1;
1147 int fd, nbytes, oflags;
1149 int logged_write, rval, got_lock;
1150 long offset, woffset = 0;
1151 char *addr, pattern, *file, *msg;
1152 struct wlog_rec wrec;
1153 struct fd_cache *fdc;
1156 * Misc variable setup
1159 nbytes = req->r_data.write.r_nbytes;
1160 offset = req->r_data.write.r_offset;
1161 pattern = req->r_data.write.r_pattern;
1162 file = req->r_data.write.r_file;
1163 oflags = req->r_data.write.r_oflags;
1165 /*printf("pwrite: %s, %#o, %d %d\n", file, oflags, offset, nbytes);*/
1168 * Allocate core memory and possibly sds space. Initialize the data
1172 Pattern[0] = pattern;
1176 * Get a descriptor to do the io on
1179 if ((fd = alloc_fd(file, oflags)) == -1)
1182 /*printf("write: %d, %s, %#o, %d %d\n",
1183 fd, file, oflags, offset, nbytes);*/
1186 * Allocate SDS space for backdoor write if desired
1189 /* get memory alignment for using DIRECT I/O */
1190 fdc = alloc_fdcache(file, oflags);
1192 if ((rval = alloc_mem(nbytes + wtob(1) * 2 + fdc->c_memalign)) < 0) {
1198 if( (req->r_data.write.r_uflags & F_WORD_ALIGNED) ) {
1200 * Force memory alignment for Direct I/O
1202 if( (oflags & O_DIRECT) && ((long)addr % fdc->c_memalign != 0) ) {
1203 addr += fdc->c_memalign - ((long)addr % fdc->c_memalign);
1206 addr += random_range(0, wtob(1) - 1, 1, NULL);
1209 (*Data_Fill)(Memptr, nbytes, Pattern, Pattern_Length, 0);
1210 if( addr != Memptr )
1211 memmove( addr, Memptr, nbytes);
1218 if (lock_file_region(file, fd, F_WRLCK, offset, nbytes) < 0) {
1227 * Write a preliminary write-log entry. This is done so that
1228 * doio_check can do corruption detection across an interrupt/crash.
1229 * Note that w_done is set to 0. If doio_check sees this, it
1230 * re-creates the file extents as if the write completed, but does not
1231 * do any checking - see comments in doio_check for more details.
1238 wrec.w_async = (req->r_type == WRITEA) ? 1 : 0;
1239 wrec.w_oflags = oflags;
1241 wrec.w_offset = offset;
1242 wrec.w_nbytes = nbytes;
1244 wrec.w_pathlen = strlen(file);
1245 memcpy(wrec.w_path, file, wrec.w_pathlen);
1246 wrec.w_hostlen = strlen(Host);
1247 memcpy(wrec.w_host, Host, wrec.w_hostlen);
1248 wrec.w_patternlen = Pattern_Length;
1249 memcpy(wrec.w_pattern, Pattern, wrec.w_patternlen);
1253 if ((woffset = wlog_record_write(&Wlog, &wrec, -1)) == -1) {
1254 doio_fprintf(stderr,
1255 "Could not append to write-log: %s (%d)\n",
1262 switch (req->r_type ) {
1268 if (lseek(fd, offset, SEEK_SET) == -1) {
1269 doio_fprintf(stderr,
1270 "lseek(%d, %d, SEEK_SET) failed: %s (%d)\n",
1271 fd, offset, SYSERR, errno);
1275 rval = write(fd, addr, nbytes);
1278 doio_fprintf(stderr,
1279 "write() failed: %s (%d)\n%s\n",
1281 format_rw(req, fd, addr, -1, Pattern, NULL));
1282 doio_fprintf(stderr,
1283 "write() failed: %s\n\twrite(%d, %#o, %d)\n\toffset %d, nbytes%%miniou(%d)=%d, oflags=%#o memalign=%d, addr%%memalign=%d\n",
1287 fdc->c_miniosz, nbytes%fdc->c_miniosz,
1288 oflags, fdc->c_memalign, (long)addr%fdc->c_memalign);
1289 doio_upanic(U_RVAL);
1290 } else if (rval != nbytes) {
1291 doio_fprintf(stderr,
1292 "write() returned wrong # bytes - expected %d, got %d\n%s\n",
1294 format_rw(req, fd, addr, -1, Pattern, NULL));
1295 doio_upanic(U_RVAL);
1303 * Verify that the data was written correctly - check_file() returns
1304 * a non-null pointer which contains an error message if there are
1309 msg = check_file(file, offset, nbytes, Pattern, Pattern_Length,
1310 0, oflags & O_PARALLEL);
1312 doio_fprintf(stderr, "%s%s\n",
1314 format_rw(req, fd, addr, -1, Pattern, NULL)
1316 doio_upanic(U_CORRUPTION);
1323 * General cleanup ...
1325 * Write extent information to the write-log, so that doio_check can do
1326 * corruption detection. Note that w_done is set to 1, indicating that
1327 * the write has been verified as complete. We don't need to write the
1328 * filename on the second logging.
1331 if (w_opt && logged_write) {
1333 wlog_record_write(&Wlog, &wrec, woffset);
1337 * Unlock file region if necessary
1341 if (lock_file_region(file, fd, F_UNLCK, offset, nbytes) < 0) {
1347 return( (rval == -1) ? -1 : 0);
1352 * Simple routine to lock/unlock a file using fcntl()
1356 lock_file_region(fname, fd, type, start, nbytes)
1367 flk.l_start = start;
1370 if (fcntl(fd, F_SETLKW, &flk) < 0) {
1371 doio_fprintf(stderr,
1372 "fcntl(%d, %d, %#o) failed for file %s, lock type %d, offset %d, length %d: %s (%d), open flags: %#o\n",
1373 fd, F_SETLKW, &flk, fname, type,
1374 start, nbytes, SYSERR, errno,
1375 fcntl(fd, F_GETFL, 0));
1389 /* ---------------------------------------------------------------------------
1391 * A new paradigm of doing the r/w system call where there is a "stub"
1392 * function that builds the info for the system call, then does the system
1393 * call; this is called by code that is common to all system calls and does
1394 * the syscall return checking, async I/O wait, iosw check, etc.
1397 * WRITE, ASYNC, SSD/SDS,
1398 * FILE_LOCK, WRITE_LOG, VERIFY_DATA,
1402 int rval; /* syscall return */
1403 int err; /* errno */
1404 int *aioid; /* list of async I/O structures */
1407 struct syscall_info {
1410 struct status *(*sy_syscall)();
1412 char *(*sy_format)();
1417 #define SY_WRITE 00001
1418 #define SY_ASYNC 00010
1419 #define SY_IOSW 00020
1420 #define SY_SDS 00100
1423 fmt_ioreq(struct io_req *ioreq, struct syscall_info *sy, int fd)
1425 static char *errbuf=NULL;
1431 errbuf = (char *)malloc(32768);
1433 io = &ioreq->r_data.io;
1436 * Look up async I/O completion strategy
1439 aname->value != -1 && aname->value != io->r_aio_strat;
1444 cp += sprintf(cp, "Request number %d\n", Reqno);
1446 cp += sprintf(cp, " fd %d is file %s - open flags are %#o %s\n",
1447 fd, io->r_file, io->r_oflags, format_oflags(io->r_oflags));
1449 if(sy->sy_flags & SY_WRITE) {
1450 cp += sprintf(cp, " write done at file offset %d - pattern is %c (%#o)\n",
1452 (io->r_pattern == '\0') ? '?' : io->r_pattern,
1455 cp += sprintf(cp, " read done at file offset %d\n",
1459 if(sy->sy_flags & SY_ASYNC) {
1460 cp += sprintf(cp, " async io completion strategy is %s\n",
1464 cp += sprintf(cp, " number of requests is %d, strides per request is %d\n",
1465 io->r_nent, io->r_nstrides);
1467 cp += sprintf(cp, " i/o byte count = %d\n",
1470 cp += sprintf(cp, " memory alignment is %s\n",
1471 (io->r_uflags & F_WORD_ALIGNED) ? "aligned" : "unaligned");
1473 if(io->r_oflags & O_DIRECT) {
1475 struct dioattr finfo;
1477 if(xfsctl(io->r_file, fd, XFS_IOC_DIOINFO, &finfo) == -1) {
1478 cp += sprintf(cp, " Error %s (%d) getting direct I/O info\n",
1479 strerror(errno), errno);
1481 finfo.d_miniosz = 1;
1482 finfo.d_maxiosz = 1;
1485 dio_env = getenv("XFS_DIO_MIN");
1487 finfo.d_mem = finfo.d_miniosz = atoi(dio_env);
1489 cp += sprintf(cp, " DIRECT I/O: offset %% %d = %d length %% %d = %d\n",
1491 io->r_offset % finfo.d_miniosz,
1493 io->r_nbytes % finfo.d_miniosz);
1494 cp += sprintf(cp, " mem alignment 0x%x xfer size: small: %d large: %d\n",
1495 finfo.d_mem, finfo.d_miniosz, finfo.d_maxiosz);
1501 sy_pread(req, sysc, fd, addr)
1503 struct syscall_info *sysc;
1508 struct status *status;
1510 rc = pread(fd, addr, req->r_data.io.r_nbytes,
1511 req->r_data.io.r_offset);
1513 status = (struct status *)malloc(sizeof(struct status));
1514 if( status == NULL ){
1515 doio_fprintf(stderr, "malloc failed, %s/%d\n",
1516 __FILE__, __LINE__);
1519 status->aioid = NULL;
1521 status->err = errno;
1527 sy_pwrite(req, sysc, fd, addr)
1529 struct syscall_info *sysc;
1534 struct status *status;
1536 rc = pwrite(fd, addr, req->r_data.io.r_nbytes,
1537 req->r_data.io.r_offset);
1539 status = (struct status *)malloc(sizeof(struct status));
1540 if( status == NULL ){
1541 doio_fprintf(stderr, "malloc failed, %s/%d\n",
1542 __FILE__, __LINE__);
1545 status->aioid = NULL;
1547 status->err = errno;
1553 fmt_pread(struct io_req *req, struct syscall_info *sy, int fd, char *addr)
1555 static char *errbuf = NULL;
1559 errbuf = (char *)malloc(32768);
1560 if( errbuf == NULL ){
1561 doio_fprintf(stderr, "malloc failed, %s/%d\n",
1562 __FILE__, __LINE__);
1568 cp += sprintf(cp, "syscall: %s(%d, 0x%p, %d)\n",
1569 sy->sy_name, fd, addr, req->r_data.io.r_nbytes);
1574 sy_rwv(req, sysc, fd, addr, rw)
1576 struct syscall_info *sysc;
1582 struct status *status;
1583 struct iovec iov[2];
1585 status = (struct status *)malloc(sizeof(struct status));
1586 if( status == NULL ){
1587 doio_fprintf(stderr, "malloc failed, %s/%d\n",
1588 __FILE__, __LINE__);
1591 status->aioid = NULL;
1593 /* move to the desired file position. */
1594 if ((rc=lseek(fd, req->r_data.io.r_offset, SEEK_SET)) == -1) {
1596 status->err = errno;
1600 iov[0].iov_base = addr;
1601 iov[0].iov_len = req->r_data.io.r_nbytes;
1604 rc = writev(fd, iov, 1);
1606 rc = readv(fd, iov, 1);
1607 status->aioid = NULL;
1609 status->err = errno;
1614 sy_readv(req, sysc, fd, addr)
1616 struct syscall_info *sysc;
1620 return sy_rwv(req, sysc, fd, addr, 0);
1624 sy_writev(req, sysc, fd, addr)
1626 struct syscall_info *sysc;
1630 return sy_rwv(req, sysc, fd, addr, 1);
1634 fmt_readv(struct io_req *req, struct syscall_info *sy, int fd, char *addr)
1636 static char errbuf[32768];
1640 cp += sprintf(cp, "syscall: %s(%d, (iov on stack), 1)\n",
1646 sy_mmrw(req, sysc, fd, addr, rw)
1648 struct syscall_info *sysc;
1655 * This version is oriented towards mmaping the file to memory
1656 * ONCE and keeping it mapped.
1658 struct status *status;
1659 void *mrc, *memaddr;
1660 struct fd_cache *fdc;
1663 status = (struct status *)malloc(sizeof(struct status));
1664 if( status == NULL ){
1665 doio_fprintf(stderr, "malloc failed, %s/%d\n",
1666 __FILE__, __LINE__);
1669 status->aioid = NULL;
1672 fdc = alloc_fdcache(req->r_data.io.r_file, req->r_data.io.r_oflags);
1674 if( fdc->c_memaddr == NULL ) {
1675 if( fstat(fd, &sbuf) < 0 ){
1676 doio_fprintf(stderr, "fstat failed, errno=%d\n",
1678 status->err = errno;
1682 fdc->c_memlen = (int)sbuf.st_size;
1683 mrc = mmap(NULL, (int)sbuf.st_size,
1684 rw ? PROT_WRITE|PROT_READ : PROT_READ,
1687 if( mrc == MAP_FAILED ) {
1688 doio_fprintf(stderr, "mmap() failed - 0x%lx %d\n",
1690 status->err = errno;
1694 fdc->c_memaddr = mrc;
1697 memaddr = (void *)((char *)fdc->c_memaddr + req->r_data.io.r_offset);
1701 memcpy(memaddr, addr, req->r_data.io.r_nbytes);
1703 memcpy(addr, memaddr, req->r_data.io.r_nbytes);
1706 status->rval = req->r_data.io.r_nbytes;
1712 sy_mmread(req, sysc, fd, addr)
1714 struct syscall_info *sysc;
1718 return sy_mmrw(req, sysc, fd, addr, 0);
1722 sy_mmwrite(req, sysc, fd, addr)
1724 struct syscall_info *sysc;
1728 return sy_mmrw(req, sysc, fd, addr, 1);
1732 fmt_mmrw(struct io_req *req, struct syscall_info *sy, int fd, char *addr)
1734 static char errbuf[32768];
1736 struct fd_cache *fdc;
1739 fdc = alloc_fdcache(req->r_data.io.r_file, req->r_data.io.r_oflags);
1742 cp += sprintf(cp, "syscall: %s(NULL, %d, %s, MAP_SHARED, %d, 0)\n",
1745 (sy->sy_flags & SY_WRITE) ? "PROT_WRITE" : "PROT_READ",
1748 cp += sprintf(cp, "\tfile is mmaped to: 0x%lx\n",
1749 (unsigned long) fdc->c_memaddr);
1751 memaddr = (void *)((char *)fdc->c_memaddr + req->r_data.io.r_offset);
1753 cp += sprintf(cp, "\tfile-mem=0x%lx, length=%d, buffer=0x%lx\n",
1754 (unsigned long) memaddr, req->r_data.io.r_nbytes,
1755 (unsigned long) addr);
1760 struct syscall_info syscalls[] = {
1762 sy_pread, NULL, fmt_pread,
1766 sy_pwrite, NULL, fmt_pread,
1771 sy_readv, NULL, fmt_readv,
1775 sy_writev, NULL, fmt_readv,
1778 { "mmap-read", MMAPR,
1779 sy_mmread, NULL, fmt_mmrw,
1782 { "mmap-write", MMAPW,
1783 sy_mmwrite, NULL, fmt_mmrw,
1797 static int pid = -1;
1798 int fd, offset, nbytes, nstrides, nents, oflags;
1799 int rval, mem_needed, i;
1800 int logged_write, got_lock, woffset = 0, pattern;
1801 int min_byte, max_byte;
1802 char *addr, *file, *msg;
1804 struct wlog_rec wrec;
1805 struct syscall_info *sy;
1806 struct fd_cache *fdc;
1809 * Initialize common fields - assumes r_oflags, r_file, r_offset, and
1810 * r_nbytes are at the same offset in the read_req and reada_req
1813 file = req->r_data.io.r_file;
1814 oflags = req->r_data.io.r_oflags;
1815 offset = req->r_data.io.r_offset;
1816 nbytes = req->r_data.io.r_nbytes;
1817 nstrides= req->r_data.io.r_nstrides;
1818 nents = req->r_data.io.r_nent;
1819 pattern = req->r_data.io.r_pattern;
1821 if( nents >= MAX_AIO ) {
1822 doio_fprintf(stderr, "do_rw: too many list requests, %d. Maximum is %d\n",
1828 * look up system call info
1830 for(sy=syscalls; sy->sy_name != NULL && sy->sy_type != req->r_type; sy++)
1833 if(sy->sy_name == NULL) {
1834 doio_fprintf(stderr, "do_rw: unknown r_type %d.\n",
1840 * Get an open file descriptor
1841 * Note: must be done before memory allocation so that the direct i/o
1842 * information is available in mem. allocate
1845 if ((fd = alloc_fd(file, oflags)) == -1)
1849 * Allocate core memory and possibly sds space. Initialize the
1850 * data to be written. Make sure we get enough, based on the
1854 * 1 extra word for possible partial-word address "bump"
1855 * 1 extra word for dynamic pattern overrun
1856 * MPP_BUMP extra words for T3E non-hw-aligned memory address.
1859 if( sy->sy_buffer != NULL ) {
1860 mem_needed = (*sy->sy_buffer)(req, 0, 0, NULL, NULL);
1862 mem_needed = nbytes;
1865 /* get memory alignment for using DIRECT I/O */
1866 fdc = alloc_fdcache(file, oflags);
1868 if ((rval = alloc_mem(mem_needed + wtob(1) * 2 + fdc->c_memalign)) < 0) {
1872 Pattern[0] = pattern;
1875 * Allocate SDS space for backdoor write if desired
1878 if (oflags & O_SSD) {
1879 doio_fprintf(stderr, "Invalid O_SSD flag was generated for non-Cray system\n");
1886 * if io is not raw, bump the offset by a random amount
1887 * to generate non-word-aligned io.
1889 * On MPP systems, raw I/O must start on an 0x80 byte boundary.
1890 * For non-aligned I/O, bump the address from 1 to 8 words.
1893 if (! (req->r_data.io.r_uflags & F_WORD_ALIGNED)) {
1894 addr += random_range(0, wtob(1) - 1, 1, NULL);
1898 * Force memory alignment for Direct I/O
1900 if( (oflags & O_DIRECT) && ((long)addr % fdc->c_memalign != 0) ) {
1901 addr += fdc->c_memalign - ((long)addr % fdc->c_memalign);
1905 * FILL must be done on a word-aligned buffer.
1906 * Call the fill function with Memptr which is aligned,
1907 * then memmove it to the right place.
1909 if (sy->sy_flags & SY_WRITE) {
1910 (*Data_Fill)(Memptr, mem_needed, Pattern, Pattern_Length, 0);
1911 if( addr != Memptr )
1912 memmove( addr, Memptr, mem_needed);
1921 * Lock data if this is a write and locking option is set
1923 if (sy->sy_flags & SY_WRITE && k_opt) {
1924 if( sy->sy_buffer != NULL ) {
1925 (*sy->sy_buffer)(req, offset, 0, &min_byte, &max_byte);
1928 max_byte = offset + (nbytes * nstrides * nents);
1931 if (lock_file_region(file, fd, F_WRLCK,
1932 min_byte, (max_byte-min_byte+1)) < 0) {
1933 doio_fprintf(stderr,
1934 "file lock failed:\n%s\n",
1935 fmt_ioreq(req, sy, fd));
1936 doio_fprintf(stderr,
1937 " buffer(req, %d, 0, 0x%x, 0x%x)\n",
1938 offset, min_byte, max_byte);
1947 * Write a preliminary write-log entry. This is done so that
1948 * doio_check can do corruption detection across an interrupt/crash.
1949 * Note that w_done is set to 0. If doio_check sees this, it
1950 * re-creates the file extents as if the write completed, but does not
1951 * do any checking - see comments in doio_check for more details.
1954 if (sy->sy_flags & SY_WRITE && w_opt) {
1959 wrec.w_async = (sy->sy_flags & SY_ASYNC) ? 1 : 0;
1960 wrec.w_oflags = oflags;
1962 wrec.w_offset = offset;
1963 wrec.w_nbytes = nbytes; /* mem_needed -- total length */
1965 wrec.w_pathlen = strlen(file);
1966 memcpy(wrec.w_path, file, wrec.w_pathlen);
1967 wrec.w_hostlen = strlen(Host);
1968 memcpy(wrec.w_host, Host, wrec.w_hostlen);
1969 wrec.w_patternlen = Pattern_Length;
1970 memcpy(wrec.w_pattern, Pattern, wrec.w_patternlen);
1974 if ((woffset = wlog_record_write(&Wlog, &wrec, -1)) == -1) {
1975 doio_fprintf(stderr,
1976 "Could not append to write-log: %s (%d)\n",
1983 s = (*sy->sy_syscall)(req, sy, fd, addr);
1985 if( s->rval == -1 ) {
1986 doio_fprintf(stderr,
1987 "%s() request failed: %s (%d)\n%s\n%s\n",
1988 sy->sy_name, SYSERR, errno,
1989 fmt_ioreq(req, sy, fd),
1990 (*sy->sy_format)(req, sy, fd, addr));
1992 doio_upanic(U_RVAL);
1994 for(i=0; i < nents; i++) {
1995 if(s->aioid == NULL)
1997 aio_unregister(s->aioid[i]);
2002 * If the syscall was async, wait for I/O to complete
2005 if(sy->sy_flags & SY_ASYNC) {
2006 for(i=0; i < nents; i++) {
2007 aio_wait(s->aioid[i]);
2013 * Check the syscall how-much-data-written return. Look
2014 * for this in either the return value or the 'iosw'
2018 if( !(sy->sy_flags & SY_IOSW) ) {
2020 if(s->rval != mem_needed) {
2021 doio_fprintf(stderr,
2022 "%s() request returned wrong # of bytes - expected %d, got %d\n%s\n%s\n",
2023 sy->sy_name, nbytes, s->rval,
2024 fmt_ioreq(req, sy, fd),
2025 (*sy->sy_format)(req, sy, fd, addr));
2027 doio_upanic(U_RVAL);
2034 * Verify that the data was written correctly - check_file() returns
2035 * a non-null pointer which contains an error message if there are
2039 if ( rval == 0 && sy->sy_flags & SY_WRITE && v_opt) {
2040 msg = check_file(file, offset, nbytes*nstrides*nents,
2041 Pattern, Pattern_Length, 0,
2042 oflags & O_PARALLEL);
2044 doio_fprintf(stderr, "%s\n%s\n%s\n",
2046 fmt_ioreq(req, sy, fd),
2047 (*sy->sy_format)(req, sy, fd, addr));
2048 doio_upanic(U_CORRUPTION);
2054 * General cleanup ...
2056 * Write extent information to the write-log, so that doio_check can do
2057 * corruption detection. Note that w_done is set to 1, indicating that
2058 * the write has been verified as complete. We don't need to write the
2059 * filename on the second logging.
2062 if (w_opt && logged_write) {
2064 wlog_record_write(&Wlog, &wrec, woffset);
2068 * Unlock file region if necessary
2072 if (lock_file_region(file, fd, F_UNLCK,
2073 min_byte, (max_byte-min_byte+1)) < 0) {
2079 if(s->aioid != NULL)
2082 return (rval == -1) ? -1 : 0;
2087 * xfsctl-based requests
2089 * - XFS_IOC_UNRESVSP
2095 int fd, oflags, offset, nbytes;
2098 int min_byte = 0, max_byte = 0;
2099 char *file, *msg = NULL;
2100 struct xfs_flock64 flk;
2103 * Initialize common fields - assumes r_oflags, r_file, r_offset, and
2104 * r_nbytes are at the same offset in the read_req and reada_req
2107 file = req->r_data.io.r_file;
2108 oflags = req->r_data.io.r_oflags;
2109 offset = req->r_data.io.r_offset;
2110 nbytes = req->r_data.io.r_nbytes;
2113 flk.l_whence=SEEK_SET;
2118 * Get an open file descriptor
2121 if ((fd = alloc_fd(file, oflags)) == -1)
2128 * Lock data if this is locking option is set
2132 max_byte = offset + nbytes;
2134 if (lock_file_region(file, fd, F_WRLCK,
2135 min_byte, (nbytes+1)) < 0) {
2136 doio_fprintf(stderr,
2137 "file lock failed:\n");
2138 doio_fprintf(stderr,
2139 " buffer(req, %d, 0, 0x%x, 0x%x)\n",
2140 offset, min_byte, max_byte);
2148 switch (req->r_type) {
2149 case RESVSP: op=XFS_IOC_RESVSP; msg="resvsp"; break;
2150 case UNRESVSP: op=XFS_IOC_UNRESVSP; msg="unresvsp"; break;
2153 rval = xfsctl(file, fd, op, &flk);
2156 doio_fprintf(stderr,
2157 "xfsctl %s request failed: %s (%d)\n\txfsctl(%d, %s %d, {%d %lld ==> %lld}\n",
2159 fd, msg, op, flk.l_whence,
2160 (long long)flk.l_start,
2161 (long long)flk.l_len);
2163 doio_upanic(U_RVAL);
2168 * Unlock file region if necessary
2172 if (lock_file_region(file, fd, F_UNLCK,
2173 min_byte, (max_byte-min_byte+1)) < 0) {
2179 return (rval == -1) ? -1 : 0;
2183 * fsync(2) and fdatasync(2)
2194 * Initialize common fields - assumes r_oflags, r_file, r_offset, and
2195 * r_nbytes are at the same offset in the read_req and reada_req
2198 file = req->r_data.io.r_file;
2199 oflags = req->r_data.io.r_oflags;
2202 * Get an open file descriptor
2205 if ((fd = alloc_fd(file, oflags)) == -1)
2209 switch(req->r_type) {
2214 rval = fdatasync(fd);
2219 return (rval == -1) ? -1 : 0;
2223 doio_pat_fill(char *addr, int mem_needed, char *Pattern, int Pattern_Length,
2226 return pattern_fill(addr, mem_needed, Pattern, Pattern_Length, 0);
2230 doio_pat_check(buf, offset, length, pattern, pattern_length, patshift)
2238 static char errbuf[4096];
2239 int nb, i, pattern_index;
2240 char *cp, *bufend, *ep;
2241 char actual[33], expected[33];
2243 if (pattern_check(buf, length, pattern, pattern_length, patshift) != 0) {
2245 ep += sprintf(ep, "Corrupt regions follow - unprintable chars are represented as '.'\n");
2246 ep += sprintf(ep, "-----------------------------------------------------------------\n");
2248 pattern_index = patshift % pattern_length;;
2250 bufend = buf + length;
2252 while (cp < bufend) {
2253 if (*cp != pattern[pattern_index]) {
2255 if (nb > sizeof(expected)-1) {
2256 nb = sizeof(expected)-1;
2259 ep += sprintf(ep, "corrupt bytes starting at file offset %d\n", offset + (int)(cp-buf));
2262 * Fill in the expected and actual patterns
2264 bzero(expected, sizeof(expected));
2265 bzero(actual, sizeof(actual));
2267 for (i = 0; i < nb; i++) {
2268 expected[i] = pattern[(pattern_index + i) % pattern_length];
2269 if (! isprint((int)expected[i])) {
2274 if (! isprint((int)actual[i])) {
2279 ep += sprintf(ep, " 1st %2d expected bytes: %s\n", nb, expected);
2280 ep += sprintf(ep, " 1st %2d actual bytes: %s\n", nb, actual);
2287 if (pattern_index == pattern_length) {
2300 * Check the contents of a file beginning at offset, for length bytes. It
2301 * is assumed that there is a string of pattern bytes in this area of the
2302 * file. Use normal buffered reads to do the verification.
2304 * If there is a data mismatch, write a detailed message into a static buffer
2305 * suitable for the caller to print. Otherwise print NULL.
2307 * The fsa flag is set to non-zero if the buffer should be read back through
2308 * the FSA (unicos/mk). This implies the file will be opened
2309 * O_PARALLEL|O_RAW|O_WELLFORMED to do the validation. We must do this because
2310 * FSA will not allow the file to be opened for buffered io if it was
2311 * previously opened for O_PARALLEL io.
2315 check_file(file, offset, length, pattern, pattern_length, patshift, fsa)
2324 static char errbuf[4096];
2326 char *buf, *em, *ep;
2327 struct fd_cache *fdc;
2332 flags = Validation_Flags | O_RDONLY;
2337 if ((fd = alloc_fd(file, flags)) == -1) {
2339 "Could not open file %s with flags %#o (%s) for data comparison: %s (%d)\n",
2340 file, flags, format_oflags(flags),
2345 if (lseek(fd, offset, SEEK_SET) == -1) {
2347 "Could not lseek to offset %d in %s for verification: %s (%d)\n",
2348 offset, file, SYSERR, errno);
2352 /* Guarantee a properly aligned address on Direct I/O */
2353 fdc = alloc_fdcache(file, flags);
2354 if( (flags & O_DIRECT) && ((long)buf % fdc->c_memalign != 0) ) {
2355 buf += fdc->c_memalign - ((long)buf % fdc->c_memalign);
2358 if ((nb = read(fd, buf, length)) == -1) {
2360 "Could not read %d bytes from %s for verification: %s (%d)\n\tread(%d, 0x%p, %d)\n\tbuf %% alignment(%d) = %ld\n",
2361 length, file, SYSERR, errno,
2363 fdc->c_memalign, (long)buf % fdc->c_memalign);
2369 "Read wrong # bytes from %s. Expected %d, got %d\n",
2374 if( (em = (*Data_Check)(buf, offset, length, pattern, pattern_length, patshift)) != NULL ) {
2376 ep += sprintf(ep, "*** DATA COMPARISON ERROR ***\n");
2377 ep += sprintf(ep, "check_file(%s, %d, %d, %s, %d, %d) failed\n\n",
2378 file, offset, length, pattern, pattern_length, patshift);
2379 ep += sprintf(ep, "Comparison fd is %d, with open flags %#o\n",
2388 * Function to single-thread stdio output.
2392 doio_fprintf(FILE *stream, char *format, ...)
2394 static int pid = -1;
2400 date = hms(time(0));
2406 flk.l_whence = flk.l_start = flk.l_len = 0;
2407 flk.l_type = F_WRLCK;
2408 fcntl(fileno(stream), F_SETLKW, &flk);
2410 va_start(arglist, format);
2411 rval = fprintf(stream, "\n%s%s (%5d) %s\n", Prog, TagName, pid, date);
2412 rval += fprintf(stream, "---------------------\n");
2413 vfprintf(stream, format, arglist);
2418 flk.l_type = F_UNLCK;
2419 fcntl(fileno(stream), F_SETLKW, &flk);
2425 * Simple function for allocating core memory. Uses Memsize and Memptr to
2426 * keep track of the current amount allocated.
2435 int me = 0, flags, key, shmid;
2436 static int mturn = 0; /* which memory type to use */
2440 struct shmid_ds shm_ds;
2441 bzero( &shm_ds, sizeof(struct shmid_ds) );
2444 /* nbytes = -1 means "free all allocated memory" */
2445 if( nbytes == -1 ) {
2447 for(me=0; me < Nmemalloc; me++) {
2448 if(Memalloc[me].space == NULL)
2451 switch(Memalloc[me].memtype) {
2453 free(Memalloc[me].space);
2454 Memalloc[me].space = NULL;
2459 shmdt(Memalloc[me].space);
2460 Memalloc[me].space = NULL;
2461 shmctl(Memalloc[me].fd, IPC_RMID, &shm_ds);
2464 munmap(Memalloc[me].space,
2466 close(Memalloc[me].fd);
2467 if(Memalloc[me].flags & MEMF_FILE) {
2468 unlink(Memalloc[me].name);
2470 Memalloc[me].space = NULL;
2473 doio_fprintf(stderr, "alloc_mem: HELP! Unknown memory space type %d index %d\n",
2474 Memalloc[me].memtype, me);
2482 * Select a memory area (currently round-robbin)
2485 if(mturn >= Nmemalloc)
2488 M = &Memalloc[mturn];
2490 switch(M->memtype) {
2492 if( nbytes > M->size ) {
2493 if( M->space != NULL ){
2500 if( M->space == NULL ) {
2501 if( (cp = malloc( nbytes )) == NULL ) {
2502 doio_fprintf(stderr, "malloc(%d) failed: %s (%d)\n",
2503 nbytes, SYSERR, errno);
2506 M->space = (void *)cp;
2512 if( nbytes > M->size ) {
2513 if( M->space != NULL ) {
2514 munmap(M->space, M->size);
2516 if( M->flags & MEMF_FILE )
2523 if( M->space == NULL ) {
2524 if(strchr(M->name, '%')) {
2525 sprintf(filename, M->name, getpid());
2526 M->name = strdup(filename);
2529 if( (M->fd = open(M->name, O_CREAT|O_RDWR, 0666)) == -1) {
2530 doio_fprintf(stderr, "alloc_mmap: error %d (%s) opening '%s'\n",
2538 M->size = nbytes * 4;
2540 /* bias addr if MEMF_ADDR | MEMF_FIXADDR */
2541 /* >>> how to pick a memory address? */
2543 /* bias flags on MEMF_PRIVATE etc */
2544 if(M->flags & MEMF_PRIVATE)
2545 flags |= MAP_PRIVATE;
2546 if(M->flags & MEMF_SHARED)
2547 flags |= MAP_SHARED;
2549 /*printf("alloc_mem, about to mmap, fd=%d, name=(%s)\n", M->fd, M->name);*/
2550 if( (M->space = mmap(addr, M->size,
2551 PROT_READ|PROT_WRITE,
2554 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",
2557 PROT_READ|PROT_WRITE,
2558 flags, M->flags, M->fd,
2560 doio_fprintf(stderr, "\t%s%s%s%s%s",
2561 (flags & MAP_PRIVATE) ? "private " : "",
2562 (flags & MAP_SHARED) ? "shared" : "");
2569 if( nbytes > M->size ) {
2570 if( M->space != NULL ) {
2571 shmctl( M->fd, IPC_RMID, &shm_ds );
2577 if(M->space == NULL) {
2578 if(!strcmp(M->name, "private")) {
2581 sscanf(M->name, "%i", &key);
2584 M->size = M->nblks ? M->nblks * 512 : nbytes;
2586 if( nbytes > M->size ){
2588 doio_fprintf(stderr, "MEM_SHMEM: nblks(%d) too small: nbytes=%d Msize=%d, skipping this req.\n",
2589 M->nblks, nbytes, M->size );
2594 shmid = shmget(key, M->size, IPC_CREAT|0666);
2596 doio_fprintf(stderr, "shmget(0x%x, %d, CREAT) failed: %s (%d)\n",
2597 key, M->size, SYSERR, errno);
2601 M->space = shmat(shmid, NULL, SHM_RND);
2602 if( M->space == (void *)-1 ) {
2603 doio_fprintf(stderr, "shmat(0x%x, NULL, SHM_RND) failed: %s (%d)\n",
2604 shmid, SYSERR, errno);
2611 doio_fprintf(stderr, "alloc_mem: HELP! Unknown memory space type %d index %d\n",
2612 Memalloc[me].memtype, mturn);
2624 * Function to maintain a file descriptor cache, so that doio does not have
2625 * to do so many open() and close() calls. Descriptors are stored in the
2626 * cache by file name, and open flags. Each entry also has a _rtc value
2627 * associated with it which is used in aging. If doio cannot open a file
2628 * because it already has too many open (ie. system limit hit) it will close
2629 * the one in the cache that has the oldest _rtc value.
2631 * If alloc_fd() is called with a file of NULL, it will close all descriptors
2632 * in the cache, and free the memory in the cache.
2636 alloc_fd(file, oflags)
2640 struct fd_cache *fdc;
2641 struct fd_cache *alloc_fdcache(char *file, int oflags);
2643 fdc = alloc_fdcache(file, oflags);
2651 alloc_fdcache(file, oflags)
2656 struct fd_cache *free_slot, *oldest_slot, *cp;
2657 static int cache_size = 0;
2658 static struct fd_cache *cache = NULL;
2659 struct dioattr finfo;
2662 * If file is NULL, it means to free up the fd cache.
2665 if (file == NULL && cache != NULL) {
2666 for (cp = cache; cp < &cache[cache_size]; cp++) {
2667 if (cp->c_fd != -1) {
2670 if (cp->c_memaddr != NULL) {
2671 munmap(cp->c_memaddr, cp->c_memlen);
2685 * Look for a fd in the cache. If one is found, return it directly.
2686 * Otherwise, when this loop exits, oldest_slot will point to the
2687 * oldest fd slot in the cache, and free_slot will point to an
2688 * unoccupied slot if there are any.
2691 for (cp = cache; cp != NULL && cp < &cache[cache_size]; cp++) {
2692 if (cp->c_fd != -1 &&
2693 cp->c_oflags == oflags &&
2694 strcmp(cp->c_file, file) == 0) {
2699 if (cp->c_fd == -1) {
2700 if (free_slot == NULL) {
2704 if (oldest_slot == NULL ||
2705 cp->c_rtc < oldest_slot->c_rtc) {
2712 * No matching file/oflags pair was found in the cache. Attempt to
2716 if ((fd = open(file, oflags, 0666)) < 0) {
2717 if (errno != EMFILE) {
2718 doio_fprintf(stderr,
2719 "Could not open file %s with flags %#o (%s): %s (%d)\n",
2720 file, oflags, format_oflags(oflags),
2727 * If we get here, we have as many open fd's as we can have.
2728 * Close the oldest one in the cache (pointed to by
2729 * oldest_slot), and attempt to re-open.
2732 close(oldest_slot->c_fd);
2733 oldest_slot->c_fd = -1;
2734 free_slot = oldest_slot;
2736 if ((fd = open(file, oflags, 0666)) < 0) {
2737 doio_fprintf(stderr,
2738 "Could not open file %s with flags %#o (%s): %s (%d)\n",
2739 file, oflags, format_oflags(oflags),
2746 /*printf("alloc_fd: new file %s flags %#o fd %d\n", file, oflags, fd);*/
2749 * If we get here, fd is our open descriptor. If free_slot is NULL,
2750 * we need to grow the cache, otherwise free_slot is the slot that
2751 * should hold the fd info.
2754 if (free_slot == NULL) {
2755 cache = (struct fd_cache *)realloc(cache, sizeof(struct fd_cache) * (FD_ALLOC_INCR + cache_size));
2756 if (cache == NULL) {
2757 doio_fprintf(stderr, "Could not malloc() space for fd chace");
2762 cache_size += FD_ALLOC_INCR;
2764 for (cp = &cache[cache_size-FD_ALLOC_INCR];
2765 cp < &cache[cache_size]; cp++) {
2769 free_slot = &cache[cache_size - FD_ALLOC_INCR];
2773 * finally, fill in the cache slot info
2776 free_slot->c_fd = fd;
2777 free_slot->c_oflags = oflags;
2778 strcpy(free_slot->c_file, file);
2779 free_slot->c_rtc = Reqno;
2781 if (oflags & O_DIRECT) {
2784 if (xfsctl(file, fd, XFS_IOC_DIOINFO, &finfo) == -1) {
2786 finfo.d_miniosz = 1;
2787 finfo.d_maxiosz = 1;
2790 dio_env = getenv("XFS_DIO_MIN");
2792 finfo.d_mem = finfo.d_miniosz = atoi(dio_env);
2796 finfo.d_miniosz = 1;
2797 finfo.d_maxiosz = 1;
2800 free_slot->c_memalign = finfo.d_mem;
2801 free_slot->c_miniosz = finfo.d_miniosz;
2802 free_slot->c_maxiosz = finfo.d_maxiosz;
2803 free_slot->c_memaddr = NULL;
2804 free_slot->c_memlen = 0;
2811 * Signal Handling Section
2819 havesigint=1; /* in case there's a followup signal */
2828 doio_fprintf(stderr, "terminating on signal %d\n", sig);
2837 /* See sigbus_handler() in the 'ifdef sgi' case for details. Here,
2838 we don't have the siginfo stuff so the guess is weaker but we'll
2842 if( active_mmap_rw && havesigint )
2857 * SIGINT handler for the parent (original doio) process. It simply sends
2858 * a SIGINT to all of the doio children. Since they're all in the same
2859 * pgrp, this can be done with a single kill().
2867 for (i = 0; i < Nchildren; i++) {
2868 if (Children[i] != -1) {
2869 kill(Children[i], SIGINT);
2875 * Signal handler used to inform a process when async io completes. Referenced
2876 * in do_read() and do_write(). Note that the signal handler is not
2885 struct aio_info *aiop;
2887 for (i = 0; i < sizeof(Aio_Info) / sizeof(Aio_Info[0]); i++) {
2888 aiop = &Aio_Info[i];
2890 if (aiop->strategy == A_SIGNAL && aiop->sig == sig) {
2893 if (aio_done(aiop)) {
2901 * dump info on all open aio slots
2909 for (i = 0; i < sizeof(Aio_Info) / sizeof(Aio_Info[0]); i++) {
2910 if (Aio_Info[i].busy) {
2913 "Aio_Info[%03d] id=%d fd=%d signal=%d signaled=%d\n",
2917 Aio_Info[i].signalled);
2918 fprintf(stderr, "\tstrategy=%s\n",
2919 format_strat(Aio_Info[i].strategy));
2922 fprintf(stderr, "%d active async i/os\n", count);
2931 struct aio_info *aiop;
2935 for (i = 0; i < sizeof(Aio_Info) / sizeof(Aio_Info[0]); i++) {
2937 if (! Aio_Info[i].busy) {
2938 aiop = &Aio_Info[i];
2944 if (Aio_Info[i].busy && Aio_Info[i].id == aio_id) {
2945 aiop = &Aio_Info[i];
2952 doio_fprintf(stderr,"aio_slot(%d) not found. Request %d\n",
2963 aio_register(fd, strategy, sig)
2968 struct aio_info *aiop;
2970 struct sigaction sa;
2972 aiop = aio_slot(-1);
2975 aiop->strategy = strategy;
2978 if (strategy == A_SIGNAL) {
2980 aiop->signalled = 0;
2982 sa.sa_handler = aio_handler;
2984 sigemptyset(&sa.sa_mask);
2986 sigaction(sig, &sa, &aiop->osa);
2989 aiop->signalled = 0;
2996 aio_unregister(aio_id)
2999 struct aio_info *aiop;
3001 aiop = aio_slot(aio_id);
3003 if (aiop->strategy == A_SIGNAL) {
3004 sigaction(aiop->sig, &aiop->osa, NULL);
3016 #ifdef RECALL_SIZEOF
3017 long mask[RECALL_SIZEOF];
3020 struct aio_info *aiop;
3022 /*printf("aio_wait: errno %d return %d\n", aiop->aio_errno, aiop->aio_ret);*/
3029 * Format specified time into HH:MM:SS format. t is the time to format
3030 * in seconds (as returned from time(2)).
3037 static char ascii_time[9];
3040 ltime = localtime(&t);
3041 strftime(ascii_time, sizeof(ascii_time), "%H:%M:%S", ltime);
3047 * Simple routine to check if an async io request has completed.
3051 aio_done(struct aio_info *ainfo)
3053 return -1; /* invalid */
3057 * Routine to handle upanic() - it first attempts to set the panic flag. If
3058 * the flag cannot be set, an error message is issued. A call to upanic
3059 * with PA_PANIC is then done unconditionally, in case the panic flag was set
3060 * from outside the program (as with the panic(8) program).
3062 * Note - we only execute the upanic code if -U was used, and the passed in
3063 * mask is set in the Upanic_Conditions bitmask.
3070 if (U_opt == 0 || (mask & Upanic_Conditions) == 0) {
3073 doio_fprintf(stderr, "WARNING - upanic() failed\n");
3077 * Parse cmdline options/arguments and set appropriate global variables.
3078 * If the cmdline is valid, return 0 to caller. Otherwise exit with a status
3083 parse_cmdline(argc, argv, opts)
3089 char cc, *cp, *tok = NULL;
3092 extern char *optarg;
3094 char *memargs[NMEMALLOC];
3096 void parse_memalloc(char *arg);
3097 void parse_delay(char *arg);
3098 void dump_memalloc();
3100 if (*argv[0] == '-') {
3105 if ((Prog = strrchr(argv[0], '/')) == NULL) {
3112 while ((c = getopt(argc, argv, opts)) != EOF) {
3120 for(s=checkmap; s->string != NULL; s++)
3121 if(!strcmp(s->string, optarg))
3123 if (s->string == NULL) {
3125 "%s%s: Illegal -C arg (%s). Must be one of: ",
3126 Prog, TagName, tok);
3128 for (s = checkmap; s->string != NULL; s++)
3129 fprintf(stderr, "%s ", s->string);
3130 fprintf(stderr, "\n");
3136 Data_Fill = doio_pat_fill;
3137 Data_Check = doio_pat_check;
3141 "%s%s: Unrecognised -C arg '%s' %d",
3142 Prog, TagName, s->string, s->value);
3147 case 'd': /* delay between i/o ops */
3148 parse_delay(optarg);
3152 if (Npes > 1 && Nprocs > 1) {
3153 fprintf(stderr, "%s%s: Warning - Program is a multi-pe application - exec option is ignored.\n", Prog, TagName);
3168 Message_Interval = strtol(optarg, &cp, 10);
3169 if (*cp != '\0' || Message_Interval < 0) {
3170 fprintf(stderr, "%s%s: Illegal -m arg (%s): Must be an integer >= 0\n", Prog, TagName, optarg);
3176 case 'M': /* memory allocation types */
3177 nmemargs = string_to_tokens(optarg, memargs, 32, ",");
3178 for(ma=0; ma < nmemargs; ma++) {
3179 parse_memalloc(memargs[ma]);
3181 /*dump_memalloc();*/
3186 sprintf( TagName, "(%.39s)", optarg );
3190 Nprocs = strtol(optarg, &cp, 10);
3191 if (*cp != '\0' || Nprocs < 1) {
3193 "%s%s: Illegal -n arg (%s): Must be integer > 0\n",
3194 Prog, TagName, optarg);
3198 if (Npes > 1 && Nprocs > 1) {
3199 fprintf(stderr, "%s%s: Program has been built as a multi-pe app. -n1 is the only nprocs value allowed\n", Prog, TagName);
3206 Release_Interval = strtol(optarg, &cp, 10);
3207 if (*cp != '\0' || Release_Interval < 0) {
3209 "%s%s: Illegal -r arg (%s): Must be integer >= 0\n",
3210 Prog, TagName, optarg);
3227 if (strcasecmp(optarg, "sync") == 0) {
3228 Validation_Flags = O_SYNC;
3229 } else if (strcasecmp(optarg, "buffered") == 0) {
3230 Validation_Flags = 0;
3231 } else if (strcasecmp(optarg, "direct") == 0) {
3232 Validation_Flags = O_DIRECT;
3234 if (sscanf(optarg, "%i%c", &Validation_Flags, &cc) != 1) {
3235 fprintf(stderr, "%s: Invalid -V argument (%s) - must be a decimal, hex, or octal\n", Prog, optarg);
3236 fprintf(stderr, " number, or one of the following strings: 'sync',\n");
3237 fprintf(stderr, " 'buffered', 'parallel', 'ldraw', or 'raw'\n");
3244 tok = strtok(optarg, ",");
3245 while (tok != NULL) {
3246 for (s = Upanic_Args; s->string != NULL; s++)
3247 if (strcmp(s->string, tok) == 0)
3250 if (s->string == NULL) {
3252 "%s%s: Illegal -U arg (%s). Must be one of: ",
3253 Prog, TagName, tok);
3255 for (s = Upanic_Args; s->string != NULL; s++)
3256 fprintf(stderr, "%s ", s->string);
3258 fprintf(stderr, "\n");
3263 Upanic_Conditions |= s->value;
3264 tok = strtok(NULL, ",");
3282 Data_Fill = doio_pat_fill;
3283 Data_Check = doio_pat_check;
3287 Upanic_Conditions = 0;
3293 Release_Interval = DEF_RELEASE_INTERVAL;
3296 Memalloc[Nmemalloc].memtype = MEM_DATA;
3297 Memalloc[Nmemalloc].flags = 0;
3298 Memalloc[Nmemalloc].name = NULL;
3299 Memalloc[Nmemalloc].space = NULL;
3304 * Initialize input stream
3307 if (argc == optind) {
3310 Infile = argv[optind++];
3313 if (argc != optind) {
3324 * Parse memory allocation types
3328 * T3E-shmem:blksize[:nblks]
3329 * SysV-shmem:shmid:blksize:nblks
3330 * if shmid is "private", use IPC_PRIVATE
3331 * and nblks is not required
3333 * mmap:flags:filename:blksize[:nblks]
3335 * p - private (MAP_PRIVATE)
3336 * a - private, MAP_AUTORESRV
3337 * l - local (MAP_LOCAL)
3338 * s - shared (nblks required)
3341 * f - fixed address (MAP_FIXED)
3342 * A - use an address without MAP_FIXED
3343 * a - autogrow (map once at startup)
3345 * mmap:flags:devzero
3346 * mmap /dev/zero (shared not allowd)
3347 * maps the first 4096 bytes of /dev/zero
3349 * - put a directory at the beginning of the shared
3350 * regions saying what pid has what region.
3354 * nblks worth of directories - 1 int pids
3357 parse_memalloc(char *arg)
3359 char *allocargs[NMEMALLOC];
3363 if(Nmemalloc >= NMEMALLOC) {
3364 doio_fprintf(stderr, "Error - too many memory types (%d).\n",
3369 M = &Memalloc[Nmemalloc];
3371 nalloc = string_to_tokens(arg, allocargs, 32, ":");
3372 if(!strcmp(allocargs[0], "data")) {
3373 M->memtype = MEM_DATA;
3379 if(strchr(allocargs[1], 'p'))
3380 M->flags |= MEMF_MPIN;
3382 } else if(!strcmp(allocargs[0], "mmap")) {
3383 /* mmap:flags:filename[:size] */
3384 M->memtype = MEM_MMAP;
3388 if(strchr(allocargs[1], 'p'))
3389 M->flags |= MEMF_PRIVATE;
3390 if(strchr(allocargs[1], 'a'))
3391 M->flags |= MEMF_AUTORESRV;
3392 if(strchr(allocargs[1], 'l'))
3393 M->flags |= MEMF_LOCAL;
3394 if(strchr(allocargs[1], 's'))
3395 M->flags |= MEMF_SHARED;
3397 if(strchr(allocargs[1], 'f'))
3398 M->flags |= MEMF_FIXADDR;
3399 if(strchr(allocargs[1], 'A'))
3400 M->flags |= MEMF_ADDR;
3401 if(strchr(allocargs[1], 'G'))
3402 M->flags |= MEMF_AUTOGROW;
3404 if(strchr(allocargs[1], 'U'))
3405 M->flags |= MEMF_FILE;
3407 M->flags |= MEMF_PRIVATE;
3411 if(!strcmp(allocargs[2], "devzero")) {
3412 M->name = "/dev/zero";
3414 ((MEMF_PRIVATE|MEMF_LOCAL) == 0))
3415 M->flags |= MEMF_PRIVATE;
3417 M->name = allocargs[2];
3420 M->name = "/dev/zero";
3422 ((MEMF_PRIVATE|MEMF_LOCAL) == 0))
3423 M->flags |= MEMF_PRIVATE;
3427 } else if(!strcmp(allocargs[0], "shmem")) {
3428 /* shmem:shmid:size */
3429 M->memtype = MEM_SHMEM;
3433 M->name = allocargs[1];
3438 sscanf(allocargs[2], "%i", &M->nblks);
3443 if(strchr(allocargs[3], 'p'))
3444 M->flags |= MEMF_MPIN;
3449 doio_fprintf(stderr, "Error - unknown memory type '%s'.\n",
3461 if(Nmemalloc == 0) {
3462 printf("No memory allocation strategies devined\n");
3466 for(ma=0; ma < Nmemalloc; ma++) {
3467 switch(Memalloc[ma].memtype) {
3468 case MEM_DATA: mt = "data"; break;
3469 case MEM_SHMEM: mt = "shmem"; break;
3470 case MEM_MMAP: mt = "mmap"; break;
3471 default: mt = "unknown"; break;
3473 printf("mstrat[%d] = %d %s\n", ma, Memalloc[ma].memtype, mt);
3474 printf("\tflags=%#o name='%s' nblks=%d\n",
3477 Memalloc[ma].nblks);
3482 * -d <op>:<time> - doio inter-operation delay
3483 * currently this permits ONE type of delay between operations.
3487 parse_delay(char *arg)
3489 char *delayargs[NMEMALLOC];
3493 ndelay = string_to_tokens(arg, delayargs, 32, ":");
3495 doio_fprintf(stderr,
3496 "Illegal delay arg (%s). Must be operation:time\n", arg);
3499 for(s=delaymap; s->string != NULL; s++)
3500 if(!strcmp(s->string, delayargs[0]))
3502 if (s->string == NULL) {
3504 "Illegal Delay arg (%s). Must be one of: ", arg);
3506 for (s = delaymap; s->string != NULL; s++)
3507 fprintf(stderr, "%s ", s->string);
3508 fprintf(stderr, "\n");
3514 sscanf(delayargs[1], "%i", &delaytime);
3518 "Warning: extra delay arguments ignored.\n");
3524 * Usage clause - obvious
3532 * Only do this if we are on vpe 0, to avoid seeing it from every
3533 * process in the application.
3536 if (Npes > 1 && Vpe != 0) {
3540 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);
3549 * Only the app running on vpe 0 gets to issue help - this prevents
3550 * everybody in the application from doing this.
3553 if (Npes > 1 && Vpe != 0) {
3558 fprintf(stream, "\n");
3559 fprintf(stream, "\t-a abort - kill all doio processes on data compare\n");
3560 fprintf(stream, "\t errors. Normally only the erroring process exits\n");
3561 fprintf(stream, "\t-C data-pattern-type \n");
3562 fprintf(stream, "\t Available data patterns are:\n");
3563 fprintf(stream, "\t default - repeating pattern\n");
3564 fprintf(stream, "\t-d Operation:Time Inter-operation delay.\n");
3565 fprintf(stream, "\t Operations are:\n");
3566 fprintf(stream, "\t select:time (1 second=1000000)\n");
3567 fprintf(stream, "\t sleep:time (1 second=1)\n");
3568 fprintf(stream, "\t alarm:time (1 second=1)\n");
3569 fprintf(stream, "\t-e Re-exec children before entering the main\n");
3570 fprintf(stream, "\t loop. This is useful for spreading\n");
3571 fprintf(stream, "\t procs around on multi-pe systems.\n");
3572 fprintf(stream, "\t-k Lock file regions during writes using fcntl()\n");
3573 fprintf(stream, "\t-v Verify writes - this is done by doing a buffered\n");
3574 fprintf(stream, "\t read() of the data if file io was done, or\n");
3575 fprintf(stream, "\t an ssread()of the data if sds io was done\n");
3576 fprintf(stream, "\t-M Data buffer allocation method\n");
3577 fprintf(stream, "\t alloc-type[,type]\n");
3578 fprintf(stream, "\t data\n");
3579 fprintf(stream, "\t shmem:shmid:size\n");
3580 fprintf(stream, "\t mmap:flags:filename\n");
3581 fprintf(stream, "\t p - private\n");
3582 fprintf(stream, "\t s - shared (shared file must exist\n"),
3583 fprintf(stream, "\t and have needed length)\n");
3584 fprintf(stream, "\t f - fixed address (not used)\n");
3585 fprintf(stream, "\t a - specify address (not used)\n");
3586 fprintf(stream, "\t U - Unlink file when done\n");
3587 fprintf(stream, "\t The default flag is private\n");
3588 fprintf(stream, "\n");
3589 fprintf(stream, "\t-m message_interval Generate a message every 'message_interval'\n");
3590 fprintf(stream, "\t requests. An interval of 0 suppresses\n");
3591 fprintf(stream, "\t messages. The default is 0.\n");
3592 fprintf(stream, "\t-N tagname Tag name, for Monster.\n");
3593 fprintf(stream, "\t-n nprocs # of processes to start up\n");
3594 fprintf(stream, "\t-r release_interval Release all memory and close\n");
3595 fprintf(stream, "\t files every release_interval operations.\n");
3596 fprintf(stream, "\t By default procs never release memory\n");
3597 fprintf(stream, "\t or close fds unless they have to.\n");
3598 fprintf(stream, "\t-V validation_ftype The type of file descriptor to use for doing data\n");
3599 fprintf(stream, "\t validation. validation_ftype may be an octal,\n");
3600 fprintf(stream, "\t hex, or decimal number representing the open()\n");
3601 fprintf(stream, "\t flags, or may be one of the following strings:\n");
3602 fprintf(stream, "\t 'buffered' - validate using bufferd read\n");
3603 fprintf(stream, "\t 'sync' - validate using O_SYNC read\n");
3604 fprintf(stream, "\t 'direct - validate using O_DIRECT read'\n");
3605 fprintf(stream, "\t By default, 'parallel'\n");
3606 fprintf(stream, "\t is used if the write was done with O_PARALLEL\n");
3607 fprintf(stream, "\t or 'buffered' for all other writes.\n");
3608 fprintf(stream, "\t-w write_log File to log file writes to. The doio_check\n");
3609 fprintf(stream, "\t program can reconstruct datafiles using the\n");
3610 fprintf(stream, "\t write_log, and detect if a file is corrupt\n");
3611 fprintf(stream, "\t after all procs have exited.\n");
3612 fprintf(stream, "\t-U upanic_cond Comma separated list of conditions that will\n");
3613 fprintf(stream, "\t cause a call to upanic(PA_PANIC).\n");
3614 fprintf(stream, "\t 'corruption' -> upanic on bad data comparisons\n");
3615 fprintf(stream, "\t 'iosw' ---> upanic on unexpected async iosw\n");
3616 fprintf(stream, "\t 'rval' ---> upanic on unexpected syscall rvals\n");
3617 fprintf(stream, "\t 'all' ---> all of the above\n");
3618 fprintf(stream, "\n");
3619 fprintf(stream, "\tinfile Input stream - default is stdin - must be a list\n");
3620 fprintf(stream, "\t of io_req structures (see doio.h). Currently\n");
3621 fprintf(stream, "\t only the iogen program generates the proper\n");
3622 fprintf(stream, "\t format\n");