1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000 Silicon Graphics, Inc.
7 * doio - a general purpose io initiator with system call and
8 * write logging. See doio.h for the structure which defines
9 * what doio requests should look like.
14 * messages should generally be printed using doio_fprintf().
21 #include <sys/uio.h> /* for struct iovec (readv)*/
22 #include <sys/mman.h> /* for mmap(2) */
23 #include <sys/ipc.h> /* for i/o buffer in shared memory */
24 #include <sys/shm.h> /* for i/o buffer in shared memory */
26 #include <sys/time.h> /* for delays */
30 int do_xfsctl(struct io_req *);
34 #include "write_log.h"
35 #include "random_range.h"
36 #include "string_to_tokens.h"
39 #define O_SSD 0 /* so code compiles on a CRAY2 */
42 #define UINT64_T unsigned long long
45 #define O_PARALLEL 0 /* so O_PARALLEL may be used in expressions */
48 #define PPID_CHECK_INTERVAL 5 /* check ppid every <-- iterations */
49 #define MAX_AIO 256 /* maximum number of async I/O ops */
53 #define SYSERR strerror(errno)
56 * getopt() string of supported cmdline arguments.
59 #define OPTS "aC:d:ehm:n:kr:w:vU:V:M:N:"
61 #define DEF_RELEASE_INTERVAL 0
64 * Flags set in parse_cmdline() to indicate which options were selected
68 int a_opt = 0; /* abort on data compare errors */
69 int e_opt = 0; /* exec() after fork()'ing */
70 int C_opt = 0; /* Data Check Type */
71 int d_opt = 0; /* delay between operations */
72 int k_opt = 0; /* lock file regions during writes */
73 int m_opt = 0; /* generate periodic messages */
74 int n_opt = 0; /* nprocs */
75 int r_opt = 0; /* resource release interval */
76 int w_opt = 0; /* file write log file */
77 int v_opt = 0; /* verify writes if set */
78 int U_opt = 0; /* upanic() on varios conditions */
79 int V_opt = 0; /* over-ride default validation fd type */
80 int M_opt = 0; /* data buffer allocation types */
81 char TagName[40]; /* name of this doio (see Monster) */
85 * Misc globals initialized in parse_cmdline()
88 char *Prog = NULL; /* set up in parse_cmdline() */
89 int Upanic_Conditions; /* set by args to -U */
90 int Release_Interval; /* arg to -r */
91 int Nprocs; /* arg to -n */
92 char *Write_Log; /* arg to -w */
93 char *Infile; /* input file (defaults to stdin) */
94 int *Children; /* pids of child procs */
96 int Nsiblings = 0; /* tfork'ed siblings */
98 int Message_Interval = 0;
99 int Npes = 0; /* non-zero if built as an mpp multi-pe app */
100 int Vpe = -1; /* Virtual pe number if Npes >= 0 */
101 int Reqno = 1; /* request # - used in some error messages */
102 int Reqskipcnt = 0; /* count of I/O requests that are skipped */
103 int Validation_Flags;
104 char *(*Data_Check)(); /* function to call for data checking */
105 int (*Data_Fill)(); /* function to call for data filling */
106 int Nmemalloc = 0; /* number of memory allocation strategies */
107 int delayop = 0; /* delay between operations - type of delay */
108 int delaytime = 0; /* delay between operations - how long */
110 struct wlog_file Wlog;
112 int active_mmap_rw = 0; /* Indicates that mmapped I/O is occurring. */
113 /* Used by sigbus_action() in the child doio. */
116 #define SKIP_REQ -2 /* skip I/O request */
119 #define MEM_DATA 1 /* data space */
120 #define MEM_SHMEM 2 /* System V shared memory */
121 #define MEM_T3ESHMEM 3 /* T3E Shared Memory */
122 #define MEM_MMAP 4 /* mmap(2) */
124 #define MEMF_PRIVATE 0001
125 #define MEMF_AUTORESRV 0002
126 #define MEMF_LOCAL 0004
127 #define MEMF_SHARED 0010
129 #define MEMF_FIXADDR 0100
130 #define MEMF_ADDR 0200
131 #define MEMF_AUTOGROW 0400
132 #define MEMF_FILE 01000 /* regular file -- unlink on close */
133 #define MEMF_MPIN 010000 /* use mpin(2) to lock pages in memory */
140 void *space; /* memory address of allocated space */
141 int fd; /* FD open for mmaping */
143 } Memalloc[NMEMALLOC];
146 * Global file descriptors
149 int Wfd_Append; /* for appending to the write-log */
150 int Wfd_Random; /* for overlaying write-log entries */
153 * Structure for maintaining open file test descriptors. Used by
158 char c_file[MAX_FNAME_LENGTH+1];
162 int c_memalign; /* from xfsctl(XFS_IOC_DIOINFO) */
165 void *c_memaddr; /* mmapped address */
166 int c_memlen; /* length of above region */
169 #define FD_ALLOC_INCR 32 /* allocate this many fd_map structs */
173 * Globals for tracking Sds and Core usage
176 char *Memptr; /* ptr to core buffer space */
177 int Memsize; /* # bytes pointed to by Memptr */
178 /* maintained by alloc_mem() */
180 int Sdsptr; /* sds offset (always 0) */
181 int Sdssize; /* # bytes of allocated sds space */
182 /* Maintained by alloc_sds() */
188 * Signal handlers, and related globals
191 void sigint_handler(); /* Catch SIGINT in parent doio, propagate
192 * to children, does not die. */
194 void die_handler(); /* Bad sig in child doios, exit 1. */
195 void cleanup_handler(); /* Normal kill, exit 0. */
197 void sigbus_handler(); /* Handle sigbus--check active_mmap_rw to
198 decide if this should be a normal exit. */
200 void cb_handler(); /* Posix aio callback handler. */
201 void noop_handler(); /* Delayop alarm, does nothing. */
205 char *format_listio();
206 char *check_file(char *file, int offset, int length, char *pattern,
207 int pattern_length, int patshift, int fsa);
208 int doio_fprintf(FILE *stream, char *format, ...);
209 void doio_upanic(int mask);
211 void help(FILE *stream);
213 int alloc_fd( char *, int );
214 int alloc_mem( int );
215 int do_read( struct io_req * );
216 int do_write( struct io_req * );
217 int do_rw( struct io_req * );
218 int do_sync( struct io_req * );
220 int aio_unregister( int );
221 int parse_cmdline( int, char **, char * );
222 int lock_file_region( char *, int, int, int, int );
223 struct fd_cache *alloc_fdcache(char *, int);
224 int aio_register( int, int, int );
230 * Upanic conditions, and a map from symbolics to values
233 #define U_CORRUPTION 0001 /* upanic on data corruption */
234 #define U_IOSW 0002 /* upanic on bad iosw */
235 #define U_RVAL 0004 /* upanic on bad rval */
237 #define U_ALL (U_CORRUPTION | U_IOSW | U_RVAL)
241 * Used to map cmdline arguments to values
248 struct smap Upanic_Args[] = {
249 { "corruption", U_CORRUPTION },
264 struct sigaction osa;
267 struct aio_info Aio_Info[MAX_AIO];
269 struct aio_info *aio_slot();
270 int aio_done( struct aio_info * );
272 /* -C data-fill/check type */
274 struct smap checkmap[] = {
275 { "default", C_DEFAULT },
279 /* -d option delay types */
280 #define DELAY_SELECT 1
281 #define DELAY_SLEEP 2
282 #define DELAY_SGINAP 3
283 #define DELAY_ALARM 4
284 #define DELAY_ITIMER 5 /* POSIX timer */
286 struct smap delaymap[] = {
287 { "select", DELAY_SELECT },
288 { "sleep", DELAY_SLEEP },
289 { "alarm", DELAY_ALARM },
295 * strerror() does similar actions.
300 static char sys_errno[10];
301 sprintf(sys_errno, "%d", errno);
312 int i, pid, stat, ex_stat;
314 sigset_t block_mask, old_mask;
315 umask(0); /* force new file modes to known values */
318 parse_cmdline(argc, argv, OPTS);
320 random_range_seed(getpid()); /* initialize random number generator */
323 * If this is a re-exec of doio, jump directly into the doio function.
332 * Stop on all but a few signals...
334 sigemptyset(&sa.sa_mask);
335 sa.sa_handler = sigint_handler;
336 sa.sa_flags = SA_RESETHAND; /* sigint is ignored after the */
338 for (i = 1; i <= NSIG; i++) {
359 sigaction(i, &sa, NULL);
364 * If we're logging write operations, make a dummy call to wlog_open
365 * to initialize the write history file. This call must be done in
366 * the parent, to ensure that the history file exists and/or has
367 * been truncated before any children attempt to open it, as the doio
368 * children are not allowed to truncate the file.
372 strcpy(Wlog.w_file, Write_Log);
374 if (wlog_open(&Wlog, 1, 0666) < 0) {
376 "Could not create/truncate write log %s\n",
385 * Malloc space for the children pid array. Initialize all entries
389 Children = (int *)malloc(sizeof(int) * Nprocs);
390 for (i = 0; i < Nprocs; i++) {
394 sigemptyset(&block_mask);
395 sigaddset(&block_mask, SIGCHLD);
396 sigprocmask(SIG_BLOCK, &block_mask, &old_mask);
399 * Fork Nprocs. This [parent] process is a watchdog, to notify the
400 * invoker of procs which exit abnormally, and to make sure that all
401 * child procs get cleaned up. If the -e option was used, we will also
402 * re-exec. This is mostly for unicos/mk on mpp's, to ensure that not
403 * all of the doio's don't end up in the same pe.
405 * Note - if Nprocs is 1, or this doio is a multi-pe app (Npes > 1),
406 * jump directly to doio(). multi-pe apps can't fork(), and there is
407 * no reason to fork() for 1 proc.
410 if (Nprocs == 1 || Npes > 1) {
414 for (i = 0; i < Nprocs; i++) {
415 if ((pid = fork()) == -1) {
417 "(parent) Could not fork %d children: %s (%d)\n",
422 Children[Nchildren] = pid;
430 argv[0] = (char *)malloc(strlen(exec_path + 1));
431 sprintf(argv[0], "-%s", exec_path);
433 execvp(exec_path, argv);
435 "(parent) Could not execvp %s: %s (%d)\n",
436 exec_path, SYSERR, errno);
446 * Parent spins on wait(), until all children exit.
452 if ((pid = wait(&stat)) == -1) {
457 for (i = 0; i < Nchildren; i++)
458 if (Children[i] == pid)
463 if (WIFEXITED(stat)) {
464 switch (WEXITSTATUS(stat)) {
471 "(parent) pid %d exited because of an internal error\n",
473 ex_stat |= E_INTERNAL;
478 "(parent) pid %d exited because of a setup error\n",
485 "(parent) pid %d exited because of data compare errors\n",
488 ex_stat |= E_COMPARE;
497 "(parent) pid %d exited because of a usage error\n",
505 "(parent) pid %d exited with unknown status %d\n",
506 pid, WEXITSTATUS(stat));
507 ex_stat |= E_INTERNAL;
510 } else if (WIFSIGNALED(stat) && WTERMSIG(stat) != SIGINT) {
512 "(parent) pid %d terminated by signal %d\n",
513 pid, WTERMSIG(stat));
527 * main doio function. Each doio child starts here, and never returns.
533 int rval, i, infd, nbytes;
536 struct sigaction sa, def_action, ignore_action, exit_action;
537 struct sigaction sigbus_action;
539 Memsize = Sdssize = 0;
542 * Initialize the Pattern - write-type syscalls will replace Pattern[1]
543 * with the pattern passed in the request. Make sure that
544 * strlen(Pattern) is not mod 16 so that out of order words will be
548 gethostname(Host, sizeof(Host));
549 if ((cp = strchr(Host, '.')) != NULL)
552 Pattern_Length = sprintf(Pattern, "-:%d:%s:%s*", (int)getpid(), Host, Prog);
554 if (!(Pattern_Length % 16)) {
555 Pattern_Length = sprintf(Pattern, "-:%d:%s:%s**",
556 (int)getpid(), Host, Prog);
560 * Open a couple of descriptors for the write-log file. One descriptor
561 * is for appending, one for random access. Write logging is done for
562 * file corruption detection. The program doio_check is capable of
563 * doing corruption detection based on a doio write-log.
568 strcpy(Wlog.w_file, Write_Log);
570 if (wlog_open(&Wlog, 0, 0666) == -1) {
572 "Could not open write log file (%s): wlog_open() failed\n",
579 * Open the input stream - either a file or stdin
582 if (Infile == NULL) {
585 if ((infd = open(Infile, O_RDWR)) == -1) {
587 "Could not open input file (%s): %s (%d)\n",
588 Infile, SYSERR, errno);
594 * Define a set of signals that should never be masked. Receipt of
595 * these signals generally indicates a programming error, and we want
596 * a corefile at the point of error. We put SIGQUIT in this list so
597 * that ^\ will force a user core dump.
599 * Note: the handler for these should be SIG_DFL, all of them
600 * produce a corefile as the default action.
603 ignore_action.sa_handler = SIG_IGN;
604 ignore_action.sa_flags = 0;
605 sigemptyset(&ignore_action.sa_mask);
607 def_action.sa_handler = SIG_DFL;
608 def_action.sa_flags = 0;
609 sigemptyset(&def_action.sa_mask);
611 exit_action.sa_handler = cleanup_handler;
612 exit_action.sa_flags = 0;
613 sigemptyset(&exit_action.sa_mask);
615 sa.sa_handler = die_handler;
617 sigemptyset(&sa.sa_mask);
619 sigbus_action.sa_handler = sigbus_handler;
620 sigbus_action.sa_flags = 0;
621 sigemptyset(&sigbus_action.sa_mask);
623 for (i = 1; i <= NSIG; i++) {
625 /* Signals to terminate program on */
627 sigaction(i, &exit_action, NULL);
630 /* This depends on active_mmap_rw */
632 sigaction(i, &sigbus_action, NULL);
635 /* Signals to Ignore... */
641 sigaction(i, &ignore_action, NULL);
644 /* Signals to trap & report & die */
647 #ifdef SIGERR /* cray only signals */
660 sigaction(i, &sa, NULL);
664 /* Default Action for all other signals */
666 sigaction(i, &def_action, NULL);
672 * Main loop - each doio proc does this until the read returns eof (0).
673 * Call the appropriate io function based on the request type.
676 while ((nbytes = read(infd, (char *)&ioreq, sizeof(ioreq)))) {
679 * Periodically check our ppid. If it is 1, the child exits to
680 * help clean up in the case that the main doio process was
684 if (Reqno && ((Reqno % PPID_CHECK_INTERVAL) == 0)) {
685 if (getppid() == 1) {
687 "Parent doio process has exited\n");
695 "read of %d bytes from input failed: %s (%d)\n",
696 sizeof(ioreq), SYSERR, errno);
701 if (nbytes != sizeof(ioreq)) {
703 "read wrong # bytes from input stream, expected %d, got %d\n",
704 sizeof(ioreq), nbytes);
709 if (ioreq.r_magic != DOIO_MAGIC) {
711 "got a bad magic # from input stream. Expected 0%o, got 0%o\n",
712 DOIO_MAGIC, ioreq.r_magic);
718 * If we're on a Release_Interval multiple, relase all ssd and
719 * core space, and close all fd's in Fd_Map[].
722 if (Reqno && Release_Interval && ! (Reqno%Release_Interval)) {
733 switch (ioreq.r_type) {
736 rval = do_read(&ioreq);
741 rval = do_write(&ioreq);
764 rval = do_rw(&ioreq);
768 rval = do_xfsctl(&ioreq);
772 rval = do_sync(&ioreq);
776 "Don't know how to handle io request type %d\n",
782 if (rval == SKIP_REQ){
785 else if (rval != 0) {
788 "doio(): operation %d returned != 0\n",
793 if (Message_Interval && Reqno % Message_Interval == 0) {
794 doio_fprintf(stderr, "Info: %d requests done (%d skipped) by this process\n", Reqno, Reqskipcnt);
804 * Child exits normally
814 struct timeval tv_delay;
815 struct sigaction sa_al, sa_old;
820 tv_delay.tv_sec = delaytime / 1000000;
821 tv_delay.tv_usec = delaytime % 1000000;
822 /*doio_fprintf(stdout, "delay_select: %d %d\n",
823 tv_delay.tv_sec, tv_delay.tv_usec);*/
824 select(0, NULL, NULL, NULL, &tv_delay);
833 sa_al.sa_handler = noop_handler;
834 sigemptyset(&sa_al.sa_mask);
835 sigaction(SIGALRM, &sa_al, &sa_old);
836 sigemptyset(&al_mask);
838 sigsuspend(&al_mask);
839 sigaction(SIGALRM, &sa_old, 0);
846 * Format IO requests, returning a pointer to the formatted text.
848 * format_strat - formats the async i/o completion strategy
849 * format_rw - formats a read[a]/write[a] request
850 * format_sds - formats a ssread/sswrite request
851 * format_listio- formats a listio request
853 * ioreq is the doio io request structure.
856 struct smap sysnames[] = {
860 { "WRITEA", WRITEA },
861 { "SSREAD", SSREAD },
862 { "SSWRITE", SSWRITE },
863 { "LISTIO", LISTIO },
865 { "LREADA", LREADA },
866 { "LWRITE", LWRITE },
867 { "LWRITEA", LWRITEA },
868 { "LSREAD", LSREAD },
869 { "LSREADA", LSREADA },
870 { "LSWRITE", LSWRITE },
871 { "LSWRITEA", LSWRITEA },
873 /* Irix System Calls */
875 { "PWRITE", PWRITE },
877 { "AWRITE", AWRITE },
878 { "LLREAD", LLREAD },
879 { "LLAREAD", LLAREAD },
880 { "LLWRITE", LLWRITE },
881 { "LLAWRITE", LLAWRITE },
882 { "RESVSP", RESVSP },
883 { "UNRESVSP", UNRESVSP },
885 /* Irix and Linux System Calls */
887 { "WRITEV", WRITEV },
890 { "FSYNC2", FSYNC2 },
891 { "FDATASYNC", FDATASYNC },
896 struct smap aionames[] = {
898 { "signal", A_SIGNAL },
899 { "recall", A_RECALL },
900 { "recalla", A_RECALLA },
901 { "recalls", A_RECALLS },
902 { "suspend", A_SUSPEND },
903 { "callback", A_CALLBACK },
909 format_oflags(int oflags)
915 switch(oflags & 03) {
916 case O_RDONLY: strcat(flags,"O_RDONLY,"); break;
917 case O_WRONLY: strcat(flags,"O_WRONLY,"); break;
918 case O_RDWR: strcat(flags,"O_RDWR,"); break;
919 default: strcat(flags,"O_weird"); break;
923 strcat(flags,"O_EXCL,");
926 strcat(flags,"O_SYNC,");
928 if(oflags & O_DIRECT)
929 strcat(flags,"O_DIRECT,");
931 return(strdup(flags));
935 format_strat(int strategy)
941 case A_POLL: aio_strat = "POLL"; break;
942 case A_SIGNAL: aio_strat = "SIGNAL"; break;
943 case A_RECALL: aio_strat = "RECALL"; break;
944 case A_RECALLA: aio_strat = "RECALLA"; break;
945 case A_RECALLS: aio_strat = "RECALLS"; break;
946 case A_SUSPEND: aio_strat = "SUSPEND"; break;
947 case A_CALLBACK: aio_strat = "CALLBACK"; break;
948 case 0: aio_strat = "<zero>"; break;
950 sprintf(msg, "<error:%#o>", strategy);
951 aio_strat = strdup(msg);
960 struct io_req *ioreq,
968 static char *errbuf=NULL;
969 char *aio_strat, *cp;
970 struct read_req *readp = &ioreq->r_data.read;
971 struct write_req *writep = &ioreq->r_data.write;
972 struct read_req *readap = &ioreq->r_data.read;
973 struct write_req *writeap = &ioreq->r_data.write;
976 errbuf = (char *)malloc(32768);
979 cp += sprintf(cp, "Request number %d\n", Reqno);
981 switch (ioreq->r_type) {
983 cp += sprintf(cp, "syscall: read(%d, %#lo, %d)\n",
984 fd, (unsigned long) buffer, readp->r_nbytes);
985 cp += sprintf(cp, " fd %d is file %s - open flags are %#o\n",
986 fd, readp->r_file, readp->r_oflags);
987 cp += sprintf(cp, " read done at file offset %d\n",
992 cp += sprintf(cp, "syscall: write(%d, %#lo, %d)\n",
993 fd, (unsigned long) buffer, writep->r_nbytes);
994 cp += sprintf(cp, " fd %d is file %s - open flags are %#o\n",
995 fd, writep->r_file, writep->r_oflags);
996 cp += sprintf(cp, " write done at file offset %d - pattern is %s\n",
997 writep->r_offset, pattern);
1001 aio_strat = format_strat(readap->r_aio_strat);
1003 cp += sprintf(cp, "syscall: reada(%d, %#lo, %d, %#lo, %d)\n",
1004 fd, (unsigned long) buffer, readap->r_nbytes,
1005 (unsigned long) iosw, signo);
1006 cp += sprintf(cp, " fd %d is file %s - open flags are %#o\n",
1007 fd, readap->r_file, readp->r_oflags);
1008 cp += sprintf(cp, " reada done at file offset %d\n",
1010 cp += sprintf(cp, " async io completion strategy is %s\n",
1015 aio_strat = format_strat(writeap->r_aio_strat);
1017 cp += sprintf(cp, "syscall: writea(%d, %#lo, %d, %#lo, %d)\n",
1018 fd, (unsigned long) buffer, writeap->r_nbytes,
1019 (unsigned long) iosw, signo);
1020 cp += sprintf(cp, " fd %d is file %s - open flags are %#o\n",
1021 fd, writeap->r_file, writeap->r_oflags);
1022 cp += sprintf(cp, " writea done at file offset %d - pattern is %s\n",
1023 writeap->r_offset, pattern);
1024 cp += sprintf(cp, " async io completion strategy is %s\n",
1034 * Perform the various sorts of disk reads
1041 int fd, offset, nbytes, oflags, rval;
1043 struct fd_cache *fdc;
1046 * Initialize common fields - assumes r_oflags, r_file, r_offset, and
1047 * r_nbytes are at the same offset in the read_req and reada_req
1051 file = req->r_data.read.r_file;
1052 oflags = req->r_data.read.r_oflags;
1053 offset = req->r_data.read.r_offset;
1054 nbytes = req->r_data.read.r_nbytes;
1056 /*printf("read: %s, %#o, %d %d\n", file, oflags, offset, nbytes);*/
1059 * Grab an open file descriptor
1060 * Note: must be done before memory allocation so that the direct i/o
1061 * information is available in mem. allocate
1064 if ((fd = alloc_fd(file, oflags)) == -1)
1068 * Allocate core or sds - based on the O_SSD flag
1072 #define wtob(x) (x * sizeof(UINT64_T))
1075 /* get memory alignment for using DIRECT I/O */
1076 fdc = alloc_fdcache(file, oflags);
1078 if ((rval = alloc_mem(nbytes + wtob(1) * 2 + fdc->c_memalign)) < 0) {
1085 if( (req->r_data.read.r_uflags & F_WORD_ALIGNED) ) {
1087 * Force memory alignment for Direct I/O
1089 if( (oflags & O_DIRECT) && ((long)addr % fdc->c_memalign != 0) ) {
1090 addr += fdc->c_memalign - ((long)addr % fdc->c_memalign);
1093 addr += random_range(0, wtob(1) - 1, 1, NULL);
1096 switch (req->r_type) {
1098 /* move to the desired file position. */
1099 if (lseek(fd, offset, SEEK_SET) == -1) {
1100 doio_fprintf(stderr,
1101 "lseek(%d, %d, SEEK_SET) failed: %s (%d)\n",
1102 fd, offset, SYSERR, errno);
1106 if ((rval = read(fd, addr, nbytes)) == -1) {
1107 doio_fprintf(stderr,
1108 "read() request failed: %s (%d)\n%s\n",
1110 format_rw(req, fd, addr, -1, NULL, NULL));
1111 doio_upanic(U_RVAL);
1113 } else if (rval != nbytes) {
1114 doio_fprintf(stderr,
1115 "read() request returned wrong # of bytes - expected %d, got %d\n%s\n",
1117 format_rw(req, fd, addr, -1, NULL, NULL));
1118 doio_upanic(U_RVAL);
1124 return 0; /* if we get here, everything went ok */
1128 * Perform the verious types of disk writes.
1135 static int pid = -1;
1136 int fd, nbytes, oflags;
1138 int logged_write, rval, got_lock;
1139 long offset, woffset = 0;
1140 char *addr, pattern, *file, *msg;
1141 struct wlog_rec wrec;
1142 struct fd_cache *fdc;
1145 * Misc variable setup
1148 nbytes = req->r_data.write.r_nbytes;
1149 offset = req->r_data.write.r_offset;
1150 pattern = req->r_data.write.r_pattern;
1151 file = req->r_data.write.r_file;
1152 oflags = req->r_data.write.r_oflags;
1154 /*printf("pwrite: %s, %#o, %d %d\n", file, oflags, offset, nbytes);*/
1157 * Allocate core memory and possibly sds space. Initialize the data
1161 Pattern[0] = pattern;
1165 * Get a descriptor to do the io on
1168 if ((fd = alloc_fd(file, oflags)) == -1)
1171 /*printf("write: %d, %s, %#o, %d %d\n",
1172 fd, file, oflags, offset, nbytes);*/
1175 * Allocate SDS space for backdoor write if desired
1178 /* get memory alignment for using DIRECT I/O */
1179 fdc = alloc_fdcache(file, oflags);
1181 if ((rval = alloc_mem(nbytes + wtob(1) * 2 + fdc->c_memalign)) < 0) {
1187 if( (req->r_data.write.r_uflags & F_WORD_ALIGNED) ) {
1189 * Force memory alignment for Direct I/O
1191 if( (oflags & O_DIRECT) && ((long)addr % fdc->c_memalign != 0) ) {
1192 addr += fdc->c_memalign - ((long)addr % fdc->c_memalign);
1195 addr += random_range(0, wtob(1) - 1, 1, NULL);
1198 (*Data_Fill)(Memptr, nbytes, Pattern, Pattern_Length, 0);
1199 if( addr != Memptr )
1200 memmove( addr, Memptr, nbytes);
1207 if (lock_file_region(file, fd, F_WRLCK, offset, nbytes) < 0) {
1216 * Write a preliminary write-log entry. This is done so that
1217 * doio_check can do corruption detection across an interrupt/crash.
1218 * Note that w_done is set to 0. If doio_check sees this, it
1219 * re-creates the file extents as if the write completed, but does not
1220 * do any checking - see comments in doio_check for more details.
1227 wrec.w_async = (req->r_type == WRITEA) ? 1 : 0;
1228 wrec.w_oflags = oflags;
1230 wrec.w_offset = offset;
1231 wrec.w_nbytes = nbytes;
1233 wrec.w_pathlen = strlen(file);
1234 memcpy(wrec.w_path, file, wrec.w_pathlen);
1235 wrec.w_hostlen = strlen(Host);
1236 memcpy(wrec.w_host, Host, wrec.w_hostlen);
1237 wrec.w_patternlen = Pattern_Length;
1238 memcpy(wrec.w_pattern, Pattern, wrec.w_patternlen);
1242 if ((woffset = wlog_record_write(&Wlog, &wrec, -1)) == -1) {
1243 doio_fprintf(stderr,
1244 "Could not append to write-log: %s (%d)\n",
1251 switch (req->r_type ) {
1257 if (lseek(fd, offset, SEEK_SET) == -1) {
1258 doio_fprintf(stderr,
1259 "lseek(%d, %d, SEEK_SET) failed: %s (%d)\n",
1260 fd, offset, SYSERR, errno);
1264 rval = write(fd, addr, nbytes);
1267 doio_fprintf(stderr,
1268 "write() failed: %s (%d)\n%s\n",
1270 format_rw(req, fd, addr, -1, Pattern, NULL));
1271 doio_fprintf(stderr,
1272 "write() failed: %s\n\twrite(%d, %#o, %d)\n\toffset %d, nbytes%%miniou(%d)=%d, oflags=%#o memalign=%d, addr%%memalign=%d\n",
1276 fdc->c_miniosz, nbytes%fdc->c_miniosz,
1277 oflags, fdc->c_memalign, (long)addr%fdc->c_memalign);
1278 doio_upanic(U_RVAL);
1279 } else if (rval != nbytes) {
1280 doio_fprintf(stderr,
1281 "write() returned wrong # bytes - expected %d, got %d\n%s\n",
1283 format_rw(req, fd, addr, -1, Pattern, NULL));
1284 doio_upanic(U_RVAL);
1292 * Verify that the data was written correctly - check_file() returns
1293 * a non-null pointer which contains an error message if there are
1298 msg = check_file(file, offset, nbytes, Pattern, Pattern_Length,
1299 0, oflags & O_PARALLEL);
1301 doio_fprintf(stderr, "%s%s\n",
1303 format_rw(req, fd, addr, -1, Pattern, NULL)
1305 doio_upanic(U_CORRUPTION);
1312 * General cleanup ...
1314 * Write extent information to the write-log, so that doio_check can do
1315 * corruption detection. Note that w_done is set to 1, indicating that
1316 * the write has been verified as complete. We don't need to write the
1317 * filename on the second logging.
1320 if (w_opt && logged_write) {
1322 wlog_record_write(&Wlog, &wrec, woffset);
1326 * Unlock file region if necessary
1330 if (lock_file_region(file, fd, F_UNLCK, offset, nbytes) < 0) {
1336 return( (rval == -1) ? -1 : 0);
1341 * Simple routine to lock/unlock a file using fcntl()
1345 lock_file_region(fname, fd, type, start, nbytes)
1356 flk.l_start = start;
1359 if (fcntl(fd, F_SETLKW, &flk) < 0) {
1360 doio_fprintf(stderr,
1361 "fcntl(%d, %d, %#o) failed for file %s, lock type %d, offset %d, length %d: %s (%d), open flags: %#o\n",
1362 fd, F_SETLKW, &flk, fname, type,
1363 start, nbytes, SYSERR, errno,
1364 fcntl(fd, F_GETFL, 0));
1378 /* ---------------------------------------------------------------------------
1380 * A new paradigm of doing the r/w system call where there is a "stub"
1381 * function that builds the info for the system call, then does the system
1382 * call; this is called by code that is common to all system calls and does
1383 * the syscall return checking, async I/O wait, iosw check, etc.
1386 * WRITE, ASYNC, SSD/SDS,
1387 * FILE_LOCK, WRITE_LOG, VERIFY_DATA,
1391 int rval; /* syscall return */
1392 int err; /* errno */
1393 int *aioid; /* list of async I/O structures */
1396 struct syscall_info {
1399 struct status *(*sy_syscall)();
1401 char *(*sy_format)();
1406 #define SY_WRITE 00001
1407 #define SY_ASYNC 00010
1408 #define SY_IOSW 00020
1409 #define SY_SDS 00100
1412 fmt_ioreq(struct io_req *ioreq, struct syscall_info *sy, int fd)
1414 static char *errbuf=NULL;
1420 errbuf = (char *)malloc(32768);
1422 io = &ioreq->r_data.io;
1425 * Look up async I/O completion strategy
1428 aname->value != -1 && aname->value != io->r_aio_strat;
1433 cp += sprintf(cp, "Request number %d\n", Reqno);
1435 cp += sprintf(cp, " fd %d is file %s - open flags are %#o %s\n",
1436 fd, io->r_file, io->r_oflags, format_oflags(io->r_oflags));
1438 if(sy->sy_flags & SY_WRITE) {
1439 cp += sprintf(cp, " write done at file offset %d - pattern is %c (%#o)\n",
1441 (io->r_pattern == '\0') ? '?' : io->r_pattern,
1444 cp += sprintf(cp, " read done at file offset %d\n",
1448 if(sy->sy_flags & SY_ASYNC) {
1449 cp += sprintf(cp, " async io completion strategy is %s\n",
1453 cp += sprintf(cp, " number of requests is %d, strides per request is %d\n",
1454 io->r_nent, io->r_nstrides);
1456 cp += sprintf(cp, " i/o byte count = %d\n",
1459 cp += sprintf(cp, " memory alignment is %s\n",
1460 (io->r_uflags & F_WORD_ALIGNED) ? "aligned" : "unaligned");
1462 if(io->r_oflags & O_DIRECT) {
1464 struct dioattr finfo;
1466 if(xfsctl(io->r_file, fd, XFS_IOC_DIOINFO, &finfo) == -1) {
1467 cp += sprintf(cp, " Error %s (%d) getting direct I/O info\n",
1468 strerror(errno), errno);
1470 finfo.d_miniosz = 1;
1471 finfo.d_maxiosz = 1;
1474 dio_env = getenv("XFS_DIO_MIN");
1476 finfo.d_mem = finfo.d_miniosz = atoi(dio_env);
1478 cp += sprintf(cp, " DIRECT I/O: offset %% %d = %d length %% %d = %d\n",
1480 io->r_offset % finfo.d_miniosz,
1482 io->r_nbytes % finfo.d_miniosz);
1483 cp += sprintf(cp, " mem alignment 0x%x xfer size: small: %d large: %d\n",
1484 finfo.d_mem, finfo.d_miniosz, finfo.d_maxiosz);
1490 sy_pread(req, sysc, fd, addr)
1492 struct syscall_info *sysc;
1497 struct status *status;
1499 rc = pread(fd, addr, req->r_data.io.r_nbytes,
1500 req->r_data.io.r_offset);
1502 status = (struct status *)malloc(sizeof(struct status));
1503 if( status == NULL ){
1504 doio_fprintf(stderr, "malloc failed, %s/%d\n",
1505 __FILE__, __LINE__);
1508 status->aioid = NULL;
1510 status->err = errno;
1516 sy_pwrite(req, sysc, fd, addr)
1518 struct syscall_info *sysc;
1523 struct status *status;
1525 rc = pwrite(fd, addr, req->r_data.io.r_nbytes,
1526 req->r_data.io.r_offset);
1528 status = (struct status *)malloc(sizeof(struct status));
1529 if( status == NULL ){
1530 doio_fprintf(stderr, "malloc failed, %s/%d\n",
1531 __FILE__, __LINE__);
1534 status->aioid = NULL;
1536 status->err = errno;
1542 fmt_pread(struct io_req *req, struct syscall_info *sy, int fd, char *addr)
1544 static char *errbuf = NULL;
1548 errbuf = (char *)malloc(32768);
1549 if( errbuf == NULL ){
1550 doio_fprintf(stderr, "malloc failed, %s/%d\n",
1551 __FILE__, __LINE__);
1557 cp += sprintf(cp, "syscall: %s(%d, 0x%p, %d)\n",
1558 sy->sy_name, fd, addr, req->r_data.io.r_nbytes);
1563 sy_rwv(req, sysc, fd, addr, rw)
1565 struct syscall_info *sysc;
1571 struct status *status;
1572 struct iovec iov[2];
1574 status = (struct status *)malloc(sizeof(struct status));
1575 if( status == NULL ){
1576 doio_fprintf(stderr, "malloc failed, %s/%d\n",
1577 __FILE__, __LINE__);
1580 status->aioid = NULL;
1582 /* move to the desired file position. */
1583 if ((rc=lseek(fd, req->r_data.io.r_offset, SEEK_SET)) == -1) {
1585 status->err = errno;
1589 iov[0].iov_base = addr;
1590 iov[0].iov_len = req->r_data.io.r_nbytes;
1593 rc = writev(fd, iov, 1);
1595 rc = readv(fd, iov, 1);
1596 status->aioid = NULL;
1598 status->err = errno;
1603 sy_readv(req, sysc, fd, addr)
1605 struct syscall_info *sysc;
1609 return sy_rwv(req, sysc, fd, addr, 0);
1613 sy_writev(req, sysc, fd, addr)
1615 struct syscall_info *sysc;
1619 return sy_rwv(req, sysc, fd, addr, 1);
1623 fmt_readv(struct io_req *req, struct syscall_info *sy, int fd, char *addr)
1625 static char errbuf[32768];
1629 cp += sprintf(cp, "syscall: %s(%d, (iov on stack), 1)\n",
1635 sy_mmrw(req, sysc, fd, addr, rw)
1637 struct syscall_info *sysc;
1644 * This version is oriented towards mmaping the file to memory
1645 * ONCE and keeping it mapped.
1647 struct status *status;
1648 void *mrc, *memaddr;
1649 struct fd_cache *fdc;
1652 status = (struct status *)malloc(sizeof(struct status));
1653 if( status == NULL ){
1654 doio_fprintf(stderr, "malloc failed, %s/%d\n",
1655 __FILE__, __LINE__);
1658 status->aioid = NULL;
1661 fdc = alloc_fdcache(req->r_data.io.r_file, req->r_data.io.r_oflags);
1663 if( fdc->c_memaddr == NULL ) {
1664 if( fstat(fd, &sbuf) < 0 ){
1665 doio_fprintf(stderr, "fstat failed, errno=%d\n",
1667 status->err = errno;
1671 fdc->c_memlen = (int)sbuf.st_size;
1672 mrc = mmap(NULL, (int)sbuf.st_size,
1673 rw ? PROT_WRITE|PROT_READ : PROT_READ,
1676 if( mrc == MAP_FAILED ) {
1677 doio_fprintf(stderr, "mmap() failed - 0x%lx %d\n",
1679 status->err = errno;
1683 fdc->c_memaddr = mrc;
1686 memaddr = (void *)((char *)fdc->c_memaddr + req->r_data.io.r_offset);
1690 memcpy(memaddr, addr, req->r_data.io.r_nbytes);
1692 memcpy(addr, memaddr, req->r_data.io.r_nbytes);
1695 status->rval = req->r_data.io.r_nbytes;
1701 sy_mmread(req, sysc, fd, addr)
1703 struct syscall_info *sysc;
1707 return sy_mmrw(req, sysc, fd, addr, 0);
1711 sy_mmwrite(req, sysc, fd, addr)
1713 struct syscall_info *sysc;
1717 return sy_mmrw(req, sysc, fd, addr, 1);
1721 fmt_mmrw(struct io_req *req, struct syscall_info *sy, int fd, char *addr)
1723 static char errbuf[32768];
1725 struct fd_cache *fdc;
1728 fdc = alloc_fdcache(req->r_data.io.r_file, req->r_data.io.r_oflags);
1731 cp += sprintf(cp, "syscall: %s(NULL, %d, %s, MAP_SHARED, %d, 0)\n",
1734 (sy->sy_flags & SY_WRITE) ? "PROT_WRITE" : "PROT_READ",
1737 cp += sprintf(cp, "\tfile is mmaped to: 0x%lx\n",
1738 (unsigned long) fdc->c_memaddr);
1740 memaddr = (void *)((char *)fdc->c_memaddr + req->r_data.io.r_offset);
1742 cp += sprintf(cp, "\tfile-mem=0x%lx, length=%d, buffer=0x%lx\n",
1743 (unsigned long) memaddr, req->r_data.io.r_nbytes,
1744 (unsigned long) addr);
1749 struct syscall_info syscalls[] = {
1751 sy_pread, NULL, fmt_pread,
1755 sy_pwrite, NULL, fmt_pread,
1760 sy_readv, NULL, fmt_readv,
1764 sy_writev, NULL, fmt_readv,
1767 { "mmap-read", MMAPR,
1768 sy_mmread, NULL, fmt_mmrw,
1771 { "mmap-write", MMAPW,
1772 sy_mmwrite, NULL, fmt_mmrw,
1786 static int pid = -1;
1787 int fd, offset, nbytes, nstrides, nents, oflags;
1788 int rval, mem_needed, i;
1789 int logged_write, got_lock, woffset = 0, pattern;
1790 int min_byte, max_byte;
1791 char *addr, *file, *msg;
1793 struct wlog_rec wrec;
1794 struct syscall_info *sy;
1795 struct fd_cache *fdc;
1798 * Initialize common fields - assumes r_oflags, r_file, r_offset, and
1799 * r_nbytes are at the same offset in the read_req and reada_req
1802 file = req->r_data.io.r_file;
1803 oflags = req->r_data.io.r_oflags;
1804 offset = req->r_data.io.r_offset;
1805 nbytes = req->r_data.io.r_nbytes;
1806 nstrides= req->r_data.io.r_nstrides;
1807 nents = req->r_data.io.r_nent;
1808 pattern = req->r_data.io.r_pattern;
1810 if( nents >= MAX_AIO ) {
1811 doio_fprintf(stderr, "do_rw: too many list requests, %d. Maximum is %d\n",
1817 * look up system call info
1819 for(sy=syscalls; sy->sy_name != NULL && sy->sy_type != req->r_type; sy++)
1822 if(sy->sy_name == NULL) {
1823 doio_fprintf(stderr, "do_rw: unknown r_type %d.\n",
1829 * Get an open file descriptor
1830 * Note: must be done before memory allocation so that the direct i/o
1831 * information is available in mem. allocate
1834 if ((fd = alloc_fd(file, oflags)) == -1)
1838 * Allocate core memory and possibly sds space. Initialize the
1839 * data to be written. Make sure we get enough, based on the
1843 * 1 extra word for possible partial-word address "bump"
1844 * 1 extra word for dynamic pattern overrun
1845 * MPP_BUMP extra words for T3E non-hw-aligned memory address.
1848 if( sy->sy_buffer != NULL ) {
1849 mem_needed = (*sy->sy_buffer)(req, 0, 0, NULL, NULL);
1851 mem_needed = nbytes;
1854 /* get memory alignment for using DIRECT I/O */
1855 fdc = alloc_fdcache(file, oflags);
1857 if ((rval = alloc_mem(mem_needed + wtob(1) * 2 + fdc->c_memalign)) < 0) {
1861 Pattern[0] = pattern;
1864 * Allocate SDS space for backdoor write if desired
1867 if (oflags & O_SSD) {
1868 doio_fprintf(stderr, "Invalid O_SSD flag was generated for non-Cray system\n");
1875 * if io is not raw, bump the offset by a random amount
1876 * to generate non-word-aligned io.
1878 * On MPP systems, raw I/O must start on an 0x80 byte boundary.
1879 * For non-aligned I/O, bump the address from 1 to 8 words.
1882 if (! (req->r_data.io.r_uflags & F_WORD_ALIGNED)) {
1883 addr += random_range(0, wtob(1) - 1, 1, NULL);
1887 * Force memory alignment for Direct I/O
1889 if( (oflags & O_DIRECT) && ((long)addr % fdc->c_memalign != 0) ) {
1890 addr += fdc->c_memalign - ((long)addr % fdc->c_memalign);
1894 * FILL must be done on a word-aligned buffer.
1895 * Call the fill function with Memptr which is aligned,
1896 * then memmove it to the right place.
1898 if (sy->sy_flags & SY_WRITE) {
1899 (*Data_Fill)(Memptr, mem_needed, Pattern, Pattern_Length, 0);
1900 if( addr != Memptr )
1901 memmove( addr, Memptr, mem_needed);
1910 * Lock data if this is a write and locking option is set
1912 if (sy->sy_flags & SY_WRITE && k_opt) {
1913 if( sy->sy_buffer != NULL ) {
1914 (*sy->sy_buffer)(req, offset, 0, &min_byte, &max_byte);
1917 max_byte = offset + (nbytes * nstrides * nents);
1920 if (lock_file_region(file, fd, F_WRLCK,
1921 min_byte, (max_byte-min_byte+1)) < 0) {
1922 doio_fprintf(stderr,
1923 "file lock failed:\n%s\n",
1924 fmt_ioreq(req, sy, fd));
1925 doio_fprintf(stderr,
1926 " buffer(req, %d, 0, 0x%x, 0x%x)\n",
1927 offset, min_byte, max_byte);
1936 * Write a preliminary write-log entry. This is done so that
1937 * doio_check can do corruption detection across an interrupt/crash.
1938 * Note that w_done is set to 0. If doio_check sees this, it
1939 * re-creates the file extents as if the write completed, but does not
1940 * do any checking - see comments in doio_check for more details.
1943 if (sy->sy_flags & SY_WRITE && w_opt) {
1948 wrec.w_async = (sy->sy_flags & SY_ASYNC) ? 1 : 0;
1949 wrec.w_oflags = oflags;
1951 wrec.w_offset = offset;
1952 wrec.w_nbytes = nbytes; /* mem_needed -- total length */
1954 wrec.w_pathlen = strlen(file);
1955 memcpy(wrec.w_path, file, wrec.w_pathlen);
1956 wrec.w_hostlen = strlen(Host);
1957 memcpy(wrec.w_host, Host, wrec.w_hostlen);
1958 wrec.w_patternlen = Pattern_Length;
1959 memcpy(wrec.w_pattern, Pattern, wrec.w_patternlen);
1963 if ((woffset = wlog_record_write(&Wlog, &wrec, -1)) == -1) {
1964 doio_fprintf(stderr,
1965 "Could not append to write-log: %s (%d)\n",
1972 s = (*sy->sy_syscall)(req, sy, fd, addr);
1974 if( s->rval == -1 ) {
1975 doio_fprintf(stderr,
1976 "%s() request failed: %s (%d)\n%s\n%s\n",
1977 sy->sy_name, SYSERR, errno,
1978 fmt_ioreq(req, sy, fd),
1979 (*sy->sy_format)(req, sy, fd, addr));
1981 doio_upanic(U_RVAL);
1983 for(i=0; i < nents; i++) {
1984 if(s->aioid == NULL)
1986 aio_unregister(s->aioid[i]);
1991 * If the syscall was async, wait for I/O to complete
1994 if(sy->sy_flags & SY_ASYNC) {
1995 for(i=0; i < nents; i++) {
1996 aio_wait(s->aioid[i]);
2002 * Check the syscall how-much-data-written return. Look
2003 * for this in either the return value or the 'iosw'
2007 if( !(sy->sy_flags & SY_IOSW) ) {
2009 if(s->rval != mem_needed) {
2010 doio_fprintf(stderr,
2011 "%s() request returned wrong # of bytes - expected %d, got %d\n%s\n%s\n",
2012 sy->sy_name, nbytes, s->rval,
2013 fmt_ioreq(req, sy, fd),
2014 (*sy->sy_format)(req, sy, fd, addr));
2016 doio_upanic(U_RVAL);
2023 * Verify that the data was written correctly - check_file() returns
2024 * a non-null pointer which contains an error message if there are
2028 if ( rval == 0 && sy->sy_flags & SY_WRITE && v_opt) {
2029 msg = check_file(file, offset, nbytes*nstrides*nents,
2030 Pattern, Pattern_Length, 0,
2031 oflags & O_PARALLEL);
2033 doio_fprintf(stderr, "%s\n%s\n%s\n",
2035 fmt_ioreq(req, sy, fd),
2036 (*sy->sy_format)(req, sy, fd, addr));
2037 doio_upanic(U_CORRUPTION);
2043 * General cleanup ...
2045 * Write extent information to the write-log, so that doio_check can do
2046 * corruption detection. Note that w_done is set to 1, indicating that
2047 * the write has been verified as complete. We don't need to write the
2048 * filename on the second logging.
2051 if (w_opt && logged_write) {
2053 wlog_record_write(&Wlog, &wrec, woffset);
2057 * Unlock file region if necessary
2061 if (lock_file_region(file, fd, F_UNLCK,
2062 min_byte, (max_byte-min_byte+1)) < 0) {
2068 if(s->aioid != NULL)
2071 return (rval == -1) ? -1 : 0;
2076 * xfsctl-based requests
2078 * - XFS_IOC_UNRESVSP
2084 int fd, oflags, offset, nbytes;
2087 int min_byte = 0, max_byte = 0;
2088 char *file, *msg = NULL;
2089 struct xfs_flock64 flk;
2092 * Initialize common fields - assumes r_oflags, r_file, r_offset, and
2093 * r_nbytes are at the same offset in the read_req and reada_req
2096 file = req->r_data.io.r_file;
2097 oflags = req->r_data.io.r_oflags;
2098 offset = req->r_data.io.r_offset;
2099 nbytes = req->r_data.io.r_nbytes;
2102 flk.l_whence=SEEK_SET;
2107 * Get an open file descriptor
2110 if ((fd = alloc_fd(file, oflags)) == -1)
2117 * Lock data if this is locking option is set
2121 max_byte = offset + nbytes;
2123 if (lock_file_region(file, fd, F_WRLCK,
2124 min_byte, (nbytes+1)) < 0) {
2125 doio_fprintf(stderr,
2126 "file lock failed:\n");
2127 doio_fprintf(stderr,
2128 " buffer(req, %d, 0, 0x%x, 0x%x)\n",
2129 offset, min_byte, max_byte);
2137 switch (req->r_type) {
2138 case RESVSP: op=XFS_IOC_RESVSP; msg="resvsp"; break;
2139 case UNRESVSP: op=XFS_IOC_UNRESVSP; msg="unresvsp"; break;
2142 rval = xfsctl(file, fd, op, &flk);
2145 doio_fprintf(stderr,
2146 "xfsctl %s request failed: %s (%d)\n\txfsctl(%d, %s %d, {%d %lld ==> %lld}\n",
2148 fd, msg, op, flk.l_whence,
2149 (long long)flk.l_start,
2150 (long long)flk.l_len);
2152 doio_upanic(U_RVAL);
2157 * Unlock file region if necessary
2161 if (lock_file_region(file, fd, F_UNLCK,
2162 min_byte, (max_byte-min_byte+1)) < 0) {
2168 return (rval == -1) ? -1 : 0;
2172 * fsync(2) and fdatasync(2)
2183 * Initialize common fields - assumes r_oflags, r_file, r_offset, and
2184 * r_nbytes are at the same offset in the read_req and reada_req
2187 file = req->r_data.io.r_file;
2188 oflags = req->r_data.io.r_oflags;
2191 * Get an open file descriptor
2194 if ((fd = alloc_fd(file, oflags)) == -1)
2198 switch(req->r_type) {
2203 rval = fdatasync(fd);
2208 return (rval == -1) ? -1 : 0;
2212 doio_pat_fill(char *addr, int mem_needed, char *Pattern, int Pattern_Length,
2215 return pattern_fill(addr, mem_needed, Pattern, Pattern_Length, 0);
2219 doio_pat_check(buf, offset, length, pattern, pattern_length, patshift)
2227 static char errbuf[4096];
2228 int nb, i, pattern_index;
2229 char *cp, *bufend, *ep;
2230 char actual[33], expected[33];
2232 if (pattern_check(buf, length, pattern, pattern_length, patshift) != 0) {
2234 ep += sprintf(ep, "Corrupt regions follow - unprintable chars are represented as '.'\n");
2235 ep += sprintf(ep, "-----------------------------------------------------------------\n");
2237 pattern_index = patshift % pattern_length;;
2239 bufend = buf + length;
2241 while (cp < bufend) {
2242 if (*cp != pattern[pattern_index]) {
2244 if (nb > sizeof(expected)-1) {
2245 nb = sizeof(expected)-1;
2248 ep += sprintf(ep, "corrupt bytes starting at file offset %d\n", offset + (int)(cp-buf));
2251 * Fill in the expected and actual patterns
2253 bzero(expected, sizeof(expected));
2254 bzero(actual, sizeof(actual));
2256 for (i = 0; i < nb; i++) {
2257 expected[i] = pattern[(pattern_index + i) % pattern_length];
2258 if (! isprint((int)expected[i])) {
2263 if (! isprint((int)actual[i])) {
2268 ep += sprintf(ep, " 1st %2d expected bytes: %s\n", nb, expected);
2269 ep += sprintf(ep, " 1st %2d actual bytes: %s\n", nb, actual);
2276 if (pattern_index == pattern_length) {
2289 * Check the contents of a file beginning at offset, for length bytes. It
2290 * is assumed that there is a string of pattern bytes in this area of the
2291 * file. Use normal buffered reads to do the verification.
2293 * If there is a data mismatch, write a detailed message into a static buffer
2294 * suitable for the caller to print. Otherwise print NULL.
2296 * The fsa flag is set to non-zero if the buffer should be read back through
2297 * the FSA (unicos/mk). This implies the file will be opened
2298 * O_PARALLEL|O_RAW|O_WELLFORMED to do the validation. We must do this because
2299 * FSA will not allow the file to be opened for buffered io if it was
2300 * previously opened for O_PARALLEL io.
2304 check_file(file, offset, length, pattern, pattern_length, patshift, fsa)
2313 static char errbuf[4096];
2315 char *buf, *em, *ep;
2316 struct fd_cache *fdc;
2321 flags = Validation_Flags | O_RDONLY;
2326 if ((fd = alloc_fd(file, flags)) == -1) {
2328 "Could not open file %s with flags %#o (%s) for data comparison: %s (%d)\n",
2329 file, flags, format_oflags(flags),
2334 if (lseek(fd, offset, SEEK_SET) == -1) {
2336 "Could not lseek to offset %d in %s for verification: %s (%d)\n",
2337 offset, file, SYSERR, errno);
2341 /* Guarantee a properly aligned address on Direct I/O */
2342 fdc = alloc_fdcache(file, flags);
2343 if( (flags & O_DIRECT) && ((long)buf % fdc->c_memalign != 0) ) {
2344 buf += fdc->c_memalign - ((long)buf % fdc->c_memalign);
2347 if ((nb = read(fd, buf, length)) == -1) {
2349 "Could not read %d bytes from %s for verification: %s (%d)\n\tread(%d, 0x%p, %d)\n\tbuf %% alignment(%d) = %ld\n",
2350 length, file, SYSERR, errno,
2352 fdc->c_memalign, (long)buf % fdc->c_memalign);
2358 "Read wrong # bytes from %s. Expected %d, got %d\n",
2363 if( (em = (*Data_Check)(buf, offset, length, pattern, pattern_length, patshift)) != NULL ) {
2365 ep += sprintf(ep, "*** DATA COMPARISON ERROR ***\n");
2366 ep += sprintf(ep, "check_file(%s, %d, %d, %s, %d, %d) failed\n\n",
2367 file, offset, length, pattern, pattern_length, patshift);
2368 ep += sprintf(ep, "Comparison fd is %d, with open flags %#o\n",
2377 * Function to single-thread stdio output.
2381 doio_fprintf(FILE *stream, char *format, ...)
2383 static int pid = -1;
2389 date = hms(time(0));
2395 flk.l_whence = flk.l_start = flk.l_len = 0;
2396 flk.l_type = F_WRLCK;
2397 fcntl(fileno(stream), F_SETLKW, &flk);
2399 va_start(arglist, format);
2400 rval = fprintf(stream, "\n%s%s (%5d) %s\n", Prog, TagName, pid, date);
2401 rval += fprintf(stream, "---------------------\n");
2402 vfprintf(stream, format, arglist);
2407 flk.l_type = F_UNLCK;
2408 fcntl(fileno(stream), F_SETLKW, &flk);
2414 * Simple function for allocating core memory. Uses Memsize and Memptr to
2415 * keep track of the current amount allocated.
2424 int me = 0, flags, key, shmid;
2425 static int mturn = 0; /* which memory type to use */
2429 struct shmid_ds shm_ds;
2430 bzero( &shm_ds, sizeof(struct shmid_ds) );
2433 /* nbytes = -1 means "free all allocated memory" */
2434 if( nbytes == -1 ) {
2436 for(me=0; me < Nmemalloc; me++) {
2437 if(Memalloc[me].space == NULL)
2440 switch(Memalloc[me].memtype) {
2442 free(Memalloc[me].space);
2443 Memalloc[me].space = NULL;
2448 shmdt(Memalloc[me].space);
2449 Memalloc[me].space = NULL;
2450 shmctl(Memalloc[me].fd, IPC_RMID, &shm_ds);
2453 munmap(Memalloc[me].space,
2455 close(Memalloc[me].fd);
2456 if(Memalloc[me].flags & MEMF_FILE) {
2457 unlink(Memalloc[me].name);
2459 Memalloc[me].space = NULL;
2462 doio_fprintf(stderr, "alloc_mem: HELP! Unknown memory space type %d index %d\n",
2463 Memalloc[me].memtype, me);
2471 * Select a memory area (currently round-robbin)
2474 if(mturn >= Nmemalloc)
2477 M = &Memalloc[mturn];
2479 switch(M->memtype) {
2481 if( nbytes > M->size ) {
2482 if( M->space != NULL ){
2489 if( M->space == NULL ) {
2490 if( (cp = malloc( nbytes )) == NULL ) {
2491 doio_fprintf(stderr, "malloc(%d) failed: %s (%d)\n",
2492 nbytes, SYSERR, errno);
2495 M->space = (void *)cp;
2501 if( nbytes > M->size ) {
2502 if( M->space != NULL ) {
2503 munmap(M->space, M->size);
2505 if( M->flags & MEMF_FILE )
2512 if( M->space == NULL ) {
2513 if(strchr(M->name, '%')) {
2514 sprintf(filename, M->name, getpid());
2515 M->name = strdup(filename);
2518 if( (M->fd = open(M->name, O_CREAT|O_RDWR, 0666)) == -1) {
2519 doio_fprintf(stderr, "alloc_mmap: error %d (%s) opening '%s'\n",
2527 M->size = nbytes * 4;
2529 /* bias addr if MEMF_ADDR | MEMF_FIXADDR */
2530 /* >>> how to pick a memory address? */
2532 /* bias flags on MEMF_PRIVATE etc */
2533 if(M->flags & MEMF_PRIVATE)
2534 flags |= MAP_PRIVATE;
2535 if(M->flags & MEMF_SHARED)
2536 flags |= MAP_SHARED;
2538 /*printf("alloc_mem, about to mmap, fd=%d, name=(%s)\n", M->fd, M->name);*/
2539 if( (M->space = mmap(addr, M->size,
2540 PROT_READ|PROT_WRITE,
2543 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",
2546 PROT_READ|PROT_WRITE,
2547 flags, M->flags, M->fd,
2549 doio_fprintf(stderr, "\t%s%s%s%s%s",
2550 (flags & MAP_PRIVATE) ? "private " : "",
2551 (flags & MAP_SHARED) ? "shared" : "");
2558 if( nbytes > M->size ) {
2559 if( M->space != NULL ) {
2560 shmctl( M->fd, IPC_RMID, &shm_ds );
2566 if(M->space == NULL) {
2567 if(!strcmp(M->name, "private")) {
2570 sscanf(M->name, "%i", &key);
2573 M->size = M->nblks ? M->nblks * 512 : nbytes;
2575 if( nbytes > M->size ){
2577 doio_fprintf(stderr, "MEM_SHMEM: nblks(%d) too small: nbytes=%d Msize=%d, skipping this req.\n",
2578 M->nblks, nbytes, M->size );
2583 shmid = shmget(key, M->size, IPC_CREAT|0666);
2585 doio_fprintf(stderr, "shmget(0x%x, %d, CREAT) failed: %s (%d)\n",
2586 key, M->size, SYSERR, errno);
2590 M->space = shmat(shmid, NULL, SHM_RND);
2591 if( M->space == (void *)-1 ) {
2592 doio_fprintf(stderr, "shmat(0x%x, NULL, SHM_RND) failed: %s (%d)\n",
2593 shmid, SYSERR, errno);
2600 doio_fprintf(stderr, "alloc_mem: HELP! Unknown memory space type %d index %d\n",
2601 Memalloc[me].memtype, mturn);
2613 * Function to maintain a file descriptor cache, so that doio does not have
2614 * to do so many open() and close() calls. Descriptors are stored in the
2615 * cache by file name, and open flags. Each entry also has a _rtc value
2616 * associated with it which is used in aging. If doio cannot open a file
2617 * because it already has too many open (ie. system limit hit) it will close
2618 * the one in the cache that has the oldest _rtc value.
2620 * If alloc_fd() is called with a file of NULL, it will close all descriptors
2621 * in the cache, and free the memory in the cache.
2625 alloc_fd(file, oflags)
2629 struct fd_cache *fdc;
2630 struct fd_cache *alloc_fdcache(char *file, int oflags);
2632 fdc = alloc_fdcache(file, oflags);
2640 alloc_fdcache(file, oflags)
2645 struct fd_cache *free_slot, *oldest_slot, *cp;
2646 static int cache_size = 0;
2647 static struct fd_cache *cache = NULL;
2648 struct dioattr finfo;
2651 * If file is NULL, it means to free up the fd cache.
2654 if (file == NULL && cache != NULL) {
2655 for (cp = cache; cp < &cache[cache_size]; cp++) {
2656 if (cp->c_fd != -1) {
2659 if (cp->c_memaddr != NULL) {
2660 munmap(cp->c_memaddr, cp->c_memlen);
2674 * Look for a fd in the cache. If one is found, return it directly.
2675 * Otherwise, when this loop exits, oldest_slot will point to the
2676 * oldest fd slot in the cache, and free_slot will point to an
2677 * unoccupied slot if there are any.
2680 for (cp = cache; cp != NULL && cp < &cache[cache_size]; cp++) {
2681 if (cp->c_fd != -1 &&
2682 cp->c_oflags == oflags &&
2683 strcmp(cp->c_file, file) == 0) {
2688 if (cp->c_fd == -1) {
2689 if (free_slot == NULL) {
2693 if (oldest_slot == NULL ||
2694 cp->c_rtc < oldest_slot->c_rtc) {
2701 * No matching file/oflags pair was found in the cache. Attempt to
2705 if ((fd = open(file, oflags, 0666)) < 0) {
2706 if (errno != EMFILE) {
2707 doio_fprintf(stderr,
2708 "Could not open file %s with flags %#o (%s): %s (%d)\n",
2709 file, oflags, format_oflags(oflags),
2716 * If we get here, we have as many open fd's as we can have.
2717 * Close the oldest one in the cache (pointed to by
2718 * oldest_slot), and attempt to re-open.
2721 close(oldest_slot->c_fd);
2722 oldest_slot->c_fd = -1;
2723 free_slot = oldest_slot;
2725 if ((fd = open(file, oflags, 0666)) < 0) {
2726 doio_fprintf(stderr,
2727 "Could not open file %s with flags %#o (%s): %s (%d)\n",
2728 file, oflags, format_oflags(oflags),
2735 /*printf("alloc_fd: new file %s flags %#o fd %d\n", file, oflags, fd);*/
2738 * If we get here, fd is our open descriptor. If free_slot is NULL,
2739 * we need to grow the cache, otherwise free_slot is the slot that
2740 * should hold the fd info.
2743 if (free_slot == NULL) {
2744 cache = (struct fd_cache *)realloc(cache, sizeof(struct fd_cache) * (FD_ALLOC_INCR + cache_size));
2745 if (cache == NULL) {
2746 doio_fprintf(stderr, "Could not malloc() space for fd chace");
2751 cache_size += FD_ALLOC_INCR;
2753 for (cp = &cache[cache_size-FD_ALLOC_INCR];
2754 cp < &cache[cache_size]; cp++) {
2758 free_slot = &cache[cache_size - FD_ALLOC_INCR];
2762 * finally, fill in the cache slot info
2765 free_slot->c_fd = fd;
2766 free_slot->c_oflags = oflags;
2767 strcpy(free_slot->c_file, file);
2768 free_slot->c_rtc = Reqno;
2770 if (oflags & O_DIRECT) {
2773 if (xfsctl(file, fd, XFS_IOC_DIOINFO, &finfo) == -1) {
2775 finfo.d_miniosz = 1;
2776 finfo.d_maxiosz = 1;
2779 dio_env = getenv("XFS_DIO_MIN");
2781 finfo.d_mem = finfo.d_miniosz = atoi(dio_env);
2785 finfo.d_miniosz = 1;
2786 finfo.d_maxiosz = 1;
2789 free_slot->c_memalign = finfo.d_mem;
2790 free_slot->c_miniosz = finfo.d_miniosz;
2791 free_slot->c_maxiosz = finfo.d_maxiosz;
2792 free_slot->c_memaddr = NULL;
2793 free_slot->c_memlen = 0;
2800 * Signal Handling Section
2808 havesigint=1; /* in case there's a followup signal */
2817 doio_fprintf(stderr, "terminating on signal %d\n", sig);
2826 /* See sigbus_handler() in the 'ifdef sgi' case for details. Here,
2827 we don't have the siginfo stuff so the guess is weaker but we'll
2831 if( active_mmap_rw && havesigint )
2846 * SIGINT handler for the parent (original doio) process. It simply sends
2847 * a SIGINT to all of the doio children. Since they're all in the same
2848 * pgrp, this can be done with a single kill().
2856 for (i = 0; i < Nchildren; i++) {
2857 if (Children[i] != -1) {
2858 kill(Children[i], SIGINT);
2864 * Signal handler used to inform a process when async io completes. Referenced
2865 * in do_read() and do_write(). Note that the signal handler is not
2874 struct aio_info *aiop;
2876 for (i = 0; i < sizeof(Aio_Info) / sizeof(Aio_Info[0]); i++) {
2877 aiop = &Aio_Info[i];
2879 if (aiop->strategy == A_SIGNAL && aiop->sig == sig) {
2882 if (aio_done(aiop)) {
2890 * dump info on all open aio slots
2898 for (i = 0; i < sizeof(Aio_Info) / sizeof(Aio_Info[0]); i++) {
2899 if (Aio_Info[i].busy) {
2902 "Aio_Info[%03d] id=%d fd=%d signal=%d signaled=%d\n",
2906 Aio_Info[i].signalled);
2907 fprintf(stderr, "\tstrategy=%s\n",
2908 format_strat(Aio_Info[i].strategy));
2911 fprintf(stderr, "%d active async i/os\n", count);
2920 struct aio_info *aiop;
2924 for (i = 0; i < sizeof(Aio_Info) / sizeof(Aio_Info[0]); i++) {
2926 if (! Aio_Info[i].busy) {
2927 aiop = &Aio_Info[i];
2933 if (Aio_Info[i].busy && Aio_Info[i].id == aio_id) {
2934 aiop = &Aio_Info[i];
2941 doio_fprintf(stderr,"aio_slot(%d) not found. Request %d\n",
2952 aio_register(fd, strategy, sig)
2957 struct aio_info *aiop;
2959 struct sigaction sa;
2961 aiop = aio_slot(-1);
2964 aiop->strategy = strategy;
2967 if (strategy == A_SIGNAL) {
2969 aiop->signalled = 0;
2971 sa.sa_handler = aio_handler;
2973 sigemptyset(&sa.sa_mask);
2975 sigaction(sig, &sa, &aiop->osa);
2978 aiop->signalled = 0;
2985 aio_unregister(aio_id)
2988 struct aio_info *aiop;
2990 aiop = aio_slot(aio_id);
2992 if (aiop->strategy == A_SIGNAL) {
2993 sigaction(aiop->sig, &aiop->osa, NULL);
3005 #ifdef RECALL_SIZEOF
3006 long mask[RECALL_SIZEOF];
3009 struct aio_info *aiop;
3011 /*printf("aio_wait: errno %d return %d\n", aiop->aio_errno, aiop->aio_ret);*/
3018 * Format specified time into HH:MM:SS format. t is the time to format
3019 * in seconds (as returned from time(2)).
3026 static char ascii_time[9];
3029 ltime = localtime(&t);
3030 strftime(ascii_time, sizeof(ascii_time), "%H:%M:%S", ltime);
3036 * Simple routine to check if an async io request has completed.
3040 aio_done(struct aio_info *ainfo)
3042 return -1; /* invalid */
3046 * Routine to handle upanic() - it first attempts to set the panic flag. If
3047 * the flag cannot be set, an error message is issued. A call to upanic
3048 * with PA_PANIC is then done unconditionally, in case the panic flag was set
3049 * from outside the program (as with the panic(8) program).
3051 * Note - we only execute the upanic code if -U was used, and the passed in
3052 * mask is set in the Upanic_Conditions bitmask.
3059 if (U_opt == 0 || (mask & Upanic_Conditions) == 0) {
3062 doio_fprintf(stderr, "WARNING - upanic() failed\n");
3066 * Parse cmdline options/arguments and set appropriate global variables.
3067 * If the cmdline is valid, return 0 to caller. Otherwise exit with a status
3072 parse_cmdline(argc, argv, opts)
3078 char cc, *cp, *tok = NULL;
3081 extern char *optarg;
3083 char *memargs[NMEMALLOC];
3085 void parse_memalloc(char *arg);
3086 void parse_delay(char *arg);
3087 void dump_memalloc();
3089 if (*argv[0] == '-') {
3094 if ((Prog = strrchr(argv[0], '/')) == NULL) {
3101 while ((c = getopt(argc, argv, opts)) != EOF) {
3109 for(s=checkmap; s->string != NULL; s++)
3110 if(!strcmp(s->string, optarg))
3112 if (s->string == NULL) {
3114 "%s%s: Illegal -C arg (%s). Must be one of: ",
3115 Prog, TagName, tok);
3117 for (s = checkmap; s->string != NULL; s++)
3118 fprintf(stderr, "%s ", s->string);
3119 fprintf(stderr, "\n");
3125 Data_Fill = doio_pat_fill;
3126 Data_Check = doio_pat_check;
3130 "%s%s: Unrecognised -C arg '%s' %d",
3131 Prog, TagName, s->string, s->value);
3136 case 'd': /* delay between i/o ops */
3137 parse_delay(optarg);
3141 if (Npes > 1 && Nprocs > 1) {
3142 fprintf(stderr, "%s%s: Warning - Program is a multi-pe application - exec option is ignored.\n", Prog, TagName);
3157 Message_Interval = strtol(optarg, &cp, 10);
3158 if (*cp != '\0' || Message_Interval < 0) {
3159 fprintf(stderr, "%s%s: Illegal -m arg (%s): Must be an integer >= 0\n", Prog, TagName, optarg);
3165 case 'M': /* memory allocation types */
3166 nmemargs = string_to_tokens(optarg, memargs, 32, ",");
3167 for(ma=0; ma < nmemargs; ma++) {
3168 parse_memalloc(memargs[ma]);
3170 /*dump_memalloc();*/
3175 sprintf( TagName, "(%.37s)", optarg );
3179 Nprocs = strtol(optarg, &cp, 10);
3180 if (*cp != '\0' || Nprocs < 1) {
3182 "%s%s: Illegal -n arg (%s): Must be integer > 0\n",
3183 Prog, TagName, optarg);
3187 if (Npes > 1 && Nprocs > 1) {
3188 fprintf(stderr, "%s%s: Program has been built as a multi-pe app. -n1 is the only nprocs value allowed\n", Prog, TagName);
3195 Release_Interval = strtol(optarg, &cp, 10);
3196 if (*cp != '\0' || Release_Interval < 0) {
3198 "%s%s: Illegal -r arg (%s): Must be integer >= 0\n",
3199 Prog, TagName, optarg);
3216 if (strcasecmp(optarg, "sync") == 0) {
3217 Validation_Flags = O_SYNC;
3218 } else if (strcasecmp(optarg, "buffered") == 0) {
3219 Validation_Flags = 0;
3220 } else if (strcasecmp(optarg, "direct") == 0) {
3221 Validation_Flags = O_DIRECT;
3223 if (sscanf(optarg, "%i%c", &Validation_Flags, &cc) != 1) {
3224 fprintf(stderr, "%s: Invalid -V argument (%s) - must be a decimal, hex, or octal\n", Prog, optarg);
3225 fprintf(stderr, " number, or one of the following strings: 'sync',\n");
3226 fprintf(stderr, " 'buffered', 'parallel', 'ldraw', or 'raw'\n");
3233 tok = strtok(optarg, ",");
3234 while (tok != NULL) {
3235 for (s = Upanic_Args; s->string != NULL; s++)
3236 if (strcmp(s->string, tok) == 0)
3239 if (s->string == NULL) {
3241 "%s%s: Illegal -U arg (%s). Must be one of: ",
3242 Prog, TagName, tok);
3244 for (s = Upanic_Args; s->string != NULL; s++)
3245 fprintf(stderr, "%s ", s->string);
3247 fprintf(stderr, "\n");
3252 Upanic_Conditions |= s->value;
3253 tok = strtok(NULL, ",");
3271 Data_Fill = doio_pat_fill;
3272 Data_Check = doio_pat_check;
3276 Upanic_Conditions = 0;
3282 Release_Interval = DEF_RELEASE_INTERVAL;
3285 Memalloc[Nmemalloc].memtype = MEM_DATA;
3286 Memalloc[Nmemalloc].flags = 0;
3287 Memalloc[Nmemalloc].name = NULL;
3288 Memalloc[Nmemalloc].space = NULL;
3293 * Initialize input stream
3296 if (argc == optind) {
3299 Infile = argv[optind++];
3302 if (argc != optind) {
3313 * Parse memory allocation types
3317 * T3E-shmem:blksize[:nblks]
3318 * SysV-shmem:shmid:blksize:nblks
3319 * if shmid is "private", use IPC_PRIVATE
3320 * and nblks is not required
3322 * mmap:flags:filename:blksize[:nblks]
3324 * p - private (MAP_PRIVATE)
3325 * a - private, MAP_AUTORESRV
3326 * l - local (MAP_LOCAL)
3327 * s - shared (nblks required)
3330 * f - fixed address (MAP_FIXED)
3331 * A - use an address without MAP_FIXED
3332 * a - autogrow (map once at startup)
3334 * mmap:flags:devzero
3335 * mmap /dev/zero (shared not allowd)
3336 * maps the first 4096 bytes of /dev/zero
3338 * - put a directory at the beginning of the shared
3339 * regions saying what pid has what region.
3343 * nblks worth of directories - 1 int pids
3346 parse_memalloc(char *arg)
3348 char *allocargs[NMEMALLOC];
3352 if(Nmemalloc >= NMEMALLOC) {
3353 doio_fprintf(stderr, "Error - too many memory types (%d).\n",
3358 M = &Memalloc[Nmemalloc];
3360 nalloc = string_to_tokens(arg, allocargs, 32, ":");
3361 if(!strcmp(allocargs[0], "data")) {
3362 M->memtype = MEM_DATA;
3368 if(strchr(allocargs[1], 'p'))
3369 M->flags |= MEMF_MPIN;
3371 } else if(!strcmp(allocargs[0], "mmap")) {
3372 /* mmap:flags:filename[:size] */
3373 M->memtype = MEM_MMAP;
3377 if(strchr(allocargs[1], 'p'))
3378 M->flags |= MEMF_PRIVATE;
3379 if(strchr(allocargs[1], 'a'))
3380 M->flags |= MEMF_AUTORESRV;
3381 if(strchr(allocargs[1], 'l'))
3382 M->flags |= MEMF_LOCAL;
3383 if(strchr(allocargs[1], 's'))
3384 M->flags |= MEMF_SHARED;
3386 if(strchr(allocargs[1], 'f'))
3387 M->flags |= MEMF_FIXADDR;
3388 if(strchr(allocargs[1], 'A'))
3389 M->flags |= MEMF_ADDR;
3390 if(strchr(allocargs[1], 'G'))
3391 M->flags |= MEMF_AUTOGROW;
3393 if(strchr(allocargs[1], 'U'))
3394 M->flags |= MEMF_FILE;
3396 M->flags |= MEMF_PRIVATE;
3400 if(!strcmp(allocargs[2], "devzero")) {
3401 M->name = "/dev/zero";
3403 ((MEMF_PRIVATE|MEMF_LOCAL) == 0))
3404 M->flags |= MEMF_PRIVATE;
3406 M->name = allocargs[2];
3409 M->name = "/dev/zero";
3411 ((MEMF_PRIVATE|MEMF_LOCAL) == 0))
3412 M->flags |= MEMF_PRIVATE;
3416 } else if(!strcmp(allocargs[0], "shmem")) {
3417 /* shmem:shmid:size */
3418 M->memtype = MEM_SHMEM;
3422 M->name = allocargs[1];
3427 sscanf(allocargs[2], "%i", &M->nblks);
3432 if(strchr(allocargs[3], 'p'))
3433 M->flags |= MEMF_MPIN;
3438 doio_fprintf(stderr, "Error - unknown memory type '%s'.\n",
3450 if(Nmemalloc == 0) {
3451 printf("No memory allocation strategies devined\n");
3455 for(ma=0; ma < Nmemalloc; ma++) {
3456 switch(Memalloc[ma].memtype) {
3457 case MEM_DATA: mt = "data"; break;
3458 case MEM_SHMEM: mt = "shmem"; break;
3459 case MEM_MMAP: mt = "mmap"; break;
3460 default: mt = "unknown"; break;
3462 printf("mstrat[%d] = %d %s\n", ma, Memalloc[ma].memtype, mt);
3463 printf("\tflags=%#o name='%s' nblks=%d\n",
3466 Memalloc[ma].nblks);
3471 * -d <op>:<time> - doio inter-operation delay
3472 * currently this permits ONE type of delay between operations.
3476 parse_delay(char *arg)
3478 char *delayargs[NMEMALLOC];
3482 ndelay = string_to_tokens(arg, delayargs, 32, ":");
3484 doio_fprintf(stderr,
3485 "Illegal delay arg (%s). Must be operation:time\n", arg);
3488 for(s=delaymap; s->string != NULL; s++)
3489 if(!strcmp(s->string, delayargs[0]))
3491 if (s->string == NULL) {
3493 "Illegal Delay arg (%s). Must be one of: ", arg);
3495 for (s = delaymap; s->string != NULL; s++)
3496 fprintf(stderr, "%s ", s->string);
3497 fprintf(stderr, "\n");
3503 sscanf(delayargs[1], "%i", &delaytime);
3507 "Warning: extra delay arguments ignored.\n");
3513 * Usage clause - obvious
3521 * Only do this if we are on vpe 0, to avoid seeing it from every
3522 * process in the application.
3525 if (Npes > 1 && Vpe != 0) {
3529 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);
3538 * Only the app running on vpe 0 gets to issue help - this prevents
3539 * everybody in the application from doing this.
3542 if (Npes > 1 && Vpe != 0) {
3547 fprintf(stream, "\n");
3548 fprintf(stream, "\t-a abort - kill all doio processes on data compare\n");
3549 fprintf(stream, "\t errors. Normally only the erroring process exits\n");
3550 fprintf(stream, "\t-C data-pattern-type \n");
3551 fprintf(stream, "\t Available data patterns are:\n");
3552 fprintf(stream, "\t default - repeating pattern\n");
3553 fprintf(stream, "\t-d Operation:Time Inter-operation delay.\n");
3554 fprintf(stream, "\t Operations are:\n");
3555 fprintf(stream, "\t select:time (1 second=1000000)\n");
3556 fprintf(stream, "\t sleep:time (1 second=1)\n");
3557 fprintf(stream, "\t alarm:time (1 second=1)\n");
3558 fprintf(stream, "\t-e Re-exec children before entering the main\n");
3559 fprintf(stream, "\t loop. This is useful for spreading\n");
3560 fprintf(stream, "\t procs around on multi-pe systems.\n");
3561 fprintf(stream, "\t-k Lock file regions during writes using fcntl()\n");
3562 fprintf(stream, "\t-v Verify writes - this is done by doing a buffered\n");
3563 fprintf(stream, "\t read() of the data if file io was done, or\n");
3564 fprintf(stream, "\t an ssread()of the data if sds io was done\n");
3565 fprintf(stream, "\t-M Data buffer allocation method\n");
3566 fprintf(stream, "\t alloc-type[,type]\n");
3567 fprintf(stream, "\t data\n");
3568 fprintf(stream, "\t shmem:shmid:size\n");
3569 fprintf(stream, "\t mmap:flags:filename\n");
3570 fprintf(stream, "\t p - private\n");
3571 fprintf(stream, "\t s - shared (shared file must exist\n"),
3572 fprintf(stream, "\t and have needed length)\n");
3573 fprintf(stream, "\t f - fixed address (not used)\n");
3574 fprintf(stream, "\t a - specify address (not used)\n");
3575 fprintf(stream, "\t U - Unlink file when done\n");
3576 fprintf(stream, "\t The default flag is private\n");
3577 fprintf(stream, "\n");
3578 fprintf(stream, "\t-m message_interval Generate a message every 'message_interval'\n");
3579 fprintf(stream, "\t requests. An interval of 0 suppresses\n");
3580 fprintf(stream, "\t messages. The default is 0.\n");
3581 fprintf(stream, "\t-N tagname Tag name, for Monster.\n");
3582 fprintf(stream, "\t-n nprocs # of processes to start up\n");
3583 fprintf(stream, "\t-r release_interval Release all memory and close\n");
3584 fprintf(stream, "\t files every release_interval operations.\n");
3585 fprintf(stream, "\t By default procs never release memory\n");
3586 fprintf(stream, "\t or close fds unless they have to.\n");
3587 fprintf(stream, "\t-V validation_ftype The type of file descriptor to use for doing data\n");
3588 fprintf(stream, "\t validation. validation_ftype may be an octal,\n");
3589 fprintf(stream, "\t hex, or decimal number representing the open()\n");
3590 fprintf(stream, "\t flags, or may be one of the following strings:\n");
3591 fprintf(stream, "\t 'buffered' - validate using bufferd read\n");
3592 fprintf(stream, "\t 'sync' - validate using O_SYNC read\n");
3593 fprintf(stream, "\t 'direct - validate using O_DIRECT read'\n");
3594 fprintf(stream, "\t By default, 'parallel'\n");
3595 fprintf(stream, "\t is used if the write was done with O_PARALLEL\n");
3596 fprintf(stream, "\t or 'buffered' for all other writes.\n");
3597 fprintf(stream, "\t-w write_log File to log file writes to. The doio_check\n");
3598 fprintf(stream, "\t program can reconstruct datafiles using the\n");
3599 fprintf(stream, "\t write_log, and detect if a file is corrupt\n");
3600 fprintf(stream, "\t after all procs have exited.\n");
3601 fprintf(stream, "\t-U upanic_cond Comma separated list of conditions that will\n");
3602 fprintf(stream, "\t cause a call to upanic(PA_PANIC).\n");
3603 fprintf(stream, "\t 'corruption' -> upanic on bad data comparisons\n");
3604 fprintf(stream, "\t 'iosw' ---> upanic on unexpected async iosw\n");
3605 fprintf(stream, "\t 'rval' ---> upanic on unexpected syscall rvals\n");
3606 fprintf(stream, "\t 'all' ---> all of the above\n");
3607 fprintf(stream, "\n");
3608 fprintf(stream, "\tinfile Input stream - default is stdin - must be a list\n");
3609 fprintf(stream, "\t of io_req structures (see doio.h). Currently\n");
3610 fprintf(stream, "\t only the iogen program generates the proper\n");
3611 fprintf(stream, "\t format\n");