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().
33 #include <sys/uio.h> /* for struct iovec (readv)*/
34 #include <sys/mman.h> /* for mmap(2) */
35 #include <sys/ipc.h> /* for i/o buffer in shared memory */
36 #include <sys/shm.h> /* for i/o buffer in shared memory */
38 #include <sys/time.h> /* for delays */
42 int do_xfsctl(struct io_req *);
46 #include "write_log.h"
47 #include "random_range.h"
48 #include "string_to_tokens.h"
51 #define O_SSD 0 /* so code compiles on a CRAY2 */
54 #define UINT64_T unsigned long long
57 #define O_PARALLEL 0 /* so O_PARALLEL may be used in expressions */
60 #define PPID_CHECK_INTERVAL 5 /* check ppid every <-- iterations */
61 #define MAX_AIO 256 /* maximum number of async I/O ops */
65 #define SYSERR strerror(errno)
68 * getopt() string of supported cmdline arguments.
71 #define OPTS "aC:d:ehm:n:kr:w:vU:V:M:N:"
73 #define DEF_RELEASE_INTERVAL 0
76 * Flags set in parse_cmdline() to indicate which options were selected
80 int a_opt = 0; /* abort on data compare errors */
81 int e_opt = 0; /* exec() after fork()'ing */
82 int C_opt = 0; /* Data Check Type */
83 int d_opt = 0; /* delay between operations */
84 int k_opt = 0; /* lock file regions during writes */
85 int m_opt = 0; /* generate periodic messages */
86 int n_opt = 0; /* nprocs */
87 int r_opt = 0; /* resource release interval */
88 int w_opt = 0; /* file write log file */
89 int v_opt = 0; /* verify writes if set */
90 int U_opt = 0; /* upanic() on varios conditions */
91 int V_opt = 0; /* over-ride default validation fd type */
92 int M_opt = 0; /* data buffer allocation types */
93 char TagName[40]; /* name of this doio (see Monster) */
97 * Misc globals initialized in parse_cmdline()
100 char *Prog = NULL; /* set up in parse_cmdline() */
101 int Upanic_Conditions; /* set by args to -U */
102 int Release_Interval; /* arg to -r */
103 int Nprocs; /* arg to -n */
104 char *Write_Log; /* arg to -w */
105 char *Infile; /* input file (defaults to stdin) */
106 int *Children; /* pids of child procs */
108 int Nsiblings = 0; /* tfork'ed siblings */
110 int Message_Interval = 0;
111 int Npes = 0; /* non-zero if built as an mpp multi-pe app */
112 int Vpe = -1; /* Virtual pe number if Npes >= 0 */
113 int Reqno = 1; /* request # - used in some error messages */
114 int Reqskipcnt = 0; /* count of I/O requests that are skipped */
115 int Validation_Flags;
116 char *(*Data_Check)(); /* function to call for data checking */
117 int (*Data_Fill)(); /* function to call for data filling */
118 int Nmemalloc = 0; /* number of memory allocation strategies */
119 int delayop = 0; /* delay between operations - type of delay */
120 int delaytime = 0; /* delay between operations - how long */
122 struct wlog_file Wlog;
124 int active_mmap_rw = 0; /* Indicates that mmapped I/O is occurring. */
125 /* Used by sigbus_action() in the child doio. */
128 #define SKIP_REQ -2 /* skip I/O request */
131 #define MEM_DATA 1 /* data space */
132 #define MEM_SHMEM 2 /* System V shared memory */
133 #define MEM_T3ESHMEM 3 /* T3E Shared Memory */
134 #define MEM_MMAP 4 /* mmap(2) */
136 #define MEMF_PRIVATE 0001
137 #define MEMF_AUTORESRV 0002
138 #define MEMF_LOCAL 0004
139 #define MEMF_SHARED 0010
141 #define MEMF_FIXADDR 0100
142 #define MEMF_ADDR 0200
143 #define MEMF_AUTOGROW 0400
144 #define MEMF_FILE 01000 /* regular file -- unlink on close */
145 #define MEMF_MPIN 010000 /* use mpin(2) to lock pages in memory */
152 void *space; /* memory address of allocated space */
153 int fd; /* FD open for mmaping */
155 } Memalloc[NMEMALLOC];
158 * Global file descriptors
161 int Wfd_Append; /* for appending to the write-log */
162 int Wfd_Random; /* for overlaying write-log entries */
165 * Structure for maintaining open file test descriptors. Used by
170 char c_file[MAX_FNAME_LENGTH+1];
174 int c_memalign; /* from xfsctl(XFS_IOC_DIOINFO) */
177 void *c_memaddr; /* mmapped address */
178 int c_memlen; /* length of above region */
181 #define FD_ALLOC_INCR 32 /* allocate this many fd_map structs */
185 * Globals for tracking Sds and Core usage
188 char *Memptr; /* ptr to core buffer space */
189 int Memsize; /* # bytes pointed to by Memptr */
190 /* maintained by alloc_mem() */
192 int Sdsptr; /* sds offset (always 0) */
193 int Sdssize; /* # bytes of allocated sds space */
194 /* Maintained by alloc_sds() */
200 * Signal handlers, and related globals
203 void sigint_handler(); /* Catch SIGINT in parent doio, propagate
204 * to children, does not die. */
206 void die_handler(); /* Bad sig in child doios, exit 1. */
207 void cleanup_handler(); /* Normal kill, exit 0. */
209 void sigbus_handler(); /* Handle sigbus--check active_mmap_rw to
210 decide if this should be a normal exit. */
212 void cb_handler(); /* Posix aio callback handler. */
213 void noop_handler(); /* Delayop alarm, does nothing. */
217 char *format_listio();
218 char *check_file(char *file, int offset, int length, char *pattern,
219 int pattern_length, int patshift, int fsa);
220 int doio_fprintf(FILE *stream, char *format, ...);
221 void doio_upanic(int mask);
223 void help(FILE *stream);
225 int alloc_fd( char *, int );
226 int alloc_mem( int );
227 int do_read( struct io_req * );
228 int do_write( struct io_req * );
229 int do_rw( struct io_req * );
230 int do_sync( struct io_req * );
232 int aio_unregister( int );
233 int parse_cmdline( int, char **, char * );
234 int lock_file_region( char *, int, int, int, int );
235 struct fd_cache *alloc_fdcache(char *, int);
236 int aio_register( int, int, int );
242 * Upanic conditions, and a map from symbolics to values
245 #define U_CORRUPTION 0001 /* upanic on data corruption */
246 #define U_IOSW 0002 /* upanic on bad iosw */
247 #define U_RVAL 0004 /* upanic on bad rval */
249 #define U_ALL (U_CORRUPTION | U_IOSW | U_RVAL)
253 * Used to map cmdline arguments to values
260 struct smap Upanic_Args[] = {
261 { "corruption", U_CORRUPTION },
276 struct sigaction osa;
279 struct aio_info Aio_Info[MAX_AIO];
281 struct aio_info *aio_slot();
282 int aio_done( struct aio_info * );
284 /* -C data-fill/check type */
286 struct smap checkmap[] = {
287 { "default", C_DEFAULT },
291 /* -d option delay types */
292 #define DELAY_SELECT 1
293 #define DELAY_SLEEP 2
294 #define DELAY_SGINAP 3
295 #define DELAY_ALARM 4
296 #define DELAY_ITIMER 5 /* POSIX timer */
298 struct smap delaymap[] = {
299 { "select", DELAY_SELECT },
300 { "sleep", DELAY_SLEEP },
301 { "alarm", DELAY_ALARM },
307 * strerror() does similar actions.
312 static char sys_errno[10];
313 sprintf(sys_errno, "%d", errno);
324 int i, pid, stat, ex_stat;
326 sigset_t block_mask, old_mask;
327 umask(0); /* force new file modes to known values */
330 parse_cmdline(argc, argv, OPTS);
332 random_range_seed(getpid()); /* initialize random number generator */
335 * If this is a re-exec of doio, jump directly into the doio function.
344 * Stop on all but a few signals...
346 sigemptyset(&sa.sa_mask);
347 sa.sa_handler = sigint_handler;
348 sa.sa_flags = SA_RESETHAND; /* sigint is ignored after the */
350 for (i = 1; i <= NSIG; i++) {
371 sigaction(i, &sa, NULL);
376 * If we're logging write operations, make a dummy call to wlog_open
377 * to initialize the write history file. This call must be done in
378 * the parent, to ensure that the history file exists and/or has
379 * been truncated before any children attempt to open it, as the doio
380 * children are not allowed to truncate the file.
384 strcpy(Wlog.w_file, Write_Log);
386 if (wlog_open(&Wlog, 1, 0666) < 0) {
388 "Could not create/truncate write log %s\n",
397 * Malloc space for the children pid array. Initialize all entries
401 Children = (int *)malloc(sizeof(int) * Nprocs);
402 for (i = 0; i < Nprocs; i++) {
406 sigemptyset(&block_mask);
407 sigaddset(&block_mask, SIGCHLD);
408 sigprocmask(SIG_BLOCK, &block_mask, &old_mask);
411 * Fork Nprocs. This [parent] process is a watchdog, to notify the
412 * invoker of procs which exit abnormally, and to make sure that all
413 * child procs get cleaned up. If the -e option was used, we will also
414 * re-exec. This is mostly for unicos/mk on mpp's, to ensure that not
415 * all of the doio's don't end up in the same pe.
417 * Note - if Nprocs is 1, or this doio is a multi-pe app (Npes > 1),
418 * jump directly to doio(). multi-pe apps can't fork(), and there is
419 * no reason to fork() for 1 proc.
422 if (Nprocs == 1 || Npes > 1) {
426 for (i = 0; i < Nprocs; i++) {
427 if ((pid = fork()) == -1) {
429 "(parent) Could not fork %d children: %s (%d)\n",
434 Children[Nchildren] = pid;
442 argv[0] = (char *)malloc(strlen(exec_path + 1));
443 sprintf(argv[0], "-%s", exec_path);
445 execvp(exec_path, argv);
447 "(parent) Could not execvp %s: %s (%d)\n",
448 exec_path, SYSERR, errno);
458 * Parent spins on wait(), until all children exit.
464 if ((pid = wait(&stat)) == -1) {
469 for (i = 0; i < Nchildren; i++)
470 if (Children[i] == pid)
475 if (WIFEXITED(stat)) {
476 switch (WEXITSTATUS(stat)) {
483 "(parent) pid %d exited because of an internal error\n",
485 ex_stat |= E_INTERNAL;
490 "(parent) pid %d exited because of a setup error\n",
497 "(parent) pid %d exited because of data compare errors\n",
500 ex_stat |= E_COMPARE;
509 "(parent) pid %d exited because of a usage error\n",
517 "(parent) pid %d exited with unknown status %d\n",
518 pid, WEXITSTATUS(stat));
519 ex_stat |= E_INTERNAL;
522 } else if (WIFSIGNALED(stat) && WTERMSIG(stat) != SIGINT) {
524 "(parent) pid %d terminated by signal %d\n",
525 pid, WTERMSIG(stat));
539 * main doio function. Each doio child starts here, and never returns.
545 int rval, i, infd, nbytes;
548 struct sigaction sa, def_action, ignore_action, exit_action;
549 struct sigaction sigbus_action;
551 Memsize = Sdssize = 0;
554 * Initialize the Pattern - write-type syscalls will replace Pattern[1]
555 * with the pattern passed in the request. Make sure that
556 * strlen(Pattern) is not mod 16 so that out of order words will be
560 gethostname(Host, sizeof(Host));
561 if ((cp = strchr(Host, '.')) != NULL)
564 Pattern_Length = sprintf(Pattern, "-:%d:%s:%s*", (int)getpid(), Host, Prog);
566 if (!(Pattern_Length % 16)) {
567 Pattern_Length = sprintf(Pattern, "-:%d:%s:%s**",
568 (int)getpid(), Host, Prog);
572 * Open a couple of descriptors for the write-log file. One descriptor
573 * is for appending, one for random access. Write logging is done for
574 * file corruption detection. The program doio_check is capable of
575 * doing corruption detection based on a doio write-log.
580 strcpy(Wlog.w_file, Write_Log);
582 if (wlog_open(&Wlog, 0, 0666) == -1) {
584 "Could not open write log file (%s): wlog_open() failed\n",
591 * Open the input stream - either a file or stdin
594 if (Infile == NULL) {
597 if ((infd = open(Infile, O_RDWR)) == -1) {
599 "Could not open input file (%s): %s (%d)\n",
600 Infile, SYSERR, errno);
606 * Define a set of signals that should never be masked. Receipt of
607 * these signals generally indicates a programming error, and we want
608 * a corefile at the point of error. We put SIGQUIT in this list so
609 * that ^\ will force a user core dump.
611 * Note: the handler for these should be SIG_DFL, all of them
612 * produce a corefile as the default action.
615 ignore_action.sa_handler = SIG_IGN;
616 ignore_action.sa_flags = 0;
617 sigemptyset(&ignore_action.sa_mask);
619 def_action.sa_handler = SIG_DFL;
620 def_action.sa_flags = 0;
621 sigemptyset(&def_action.sa_mask);
623 exit_action.sa_handler = cleanup_handler;
624 exit_action.sa_flags = 0;
625 sigemptyset(&exit_action.sa_mask);
627 sa.sa_handler = die_handler;
629 sigemptyset(&sa.sa_mask);
631 sigbus_action.sa_handler = sigbus_handler;
632 sigbus_action.sa_flags = 0;
633 sigemptyset(&sigbus_action.sa_mask);
635 for (i = 1; i <= NSIG; i++) {
637 /* Signals to terminate program on */
639 sigaction(i, &exit_action, NULL);
642 /* This depends on active_mmap_rw */
644 sigaction(i, &sigbus_action, NULL);
647 /* Signals to Ignore... */
653 sigaction(i, &ignore_action, NULL);
656 /* Signals to trap & report & die */
659 #ifdef SIGERR /* cray only signals */
672 sigaction(i, &sa, NULL);
676 /* Default Action for all other signals */
678 sigaction(i, &def_action, NULL);
684 * Main loop - each doio proc does this until the read returns eof (0).
685 * Call the appropriate io function based on the request type.
688 while ((nbytes = read(infd, (char *)&ioreq, sizeof(ioreq)))) {
691 * Periodically check our ppid. If it is 1, the child exits to
692 * help clean up in the case that the main doio process was
696 if (Reqno && ((Reqno % PPID_CHECK_INTERVAL) == 0)) {
697 if (getppid() == 1) {
699 "Parent doio process has exited\n");
707 "read of %d bytes from input failed: %s (%d)\n",
708 sizeof(ioreq), SYSERR, errno);
713 if (nbytes != sizeof(ioreq)) {
715 "read wrong # bytes from input stream, expected %d, got %d\n",
716 sizeof(ioreq), nbytes);
721 if (ioreq.r_magic != DOIO_MAGIC) {
723 "got a bad magic # from input stream. Expected 0%o, got 0%o\n",
724 DOIO_MAGIC, ioreq.r_magic);
730 * If we're on a Release_Interval multiple, relase all ssd and
731 * core space, and close all fd's in Fd_Map[].
734 if (Reqno && Release_Interval && ! (Reqno%Release_Interval)) {
745 switch (ioreq.r_type) {
748 rval = do_read(&ioreq);
753 rval = do_write(&ioreq);
776 rval = do_rw(&ioreq);
780 rval = do_xfsctl(&ioreq);
784 rval = do_sync(&ioreq);
788 "Don't know how to handle io request type %d\n",
794 if (rval == SKIP_REQ){
797 else if (rval != 0) {
800 "doio(): operation %d returned != 0\n",
805 if (Message_Interval && Reqno % Message_Interval == 0) {
806 doio_fprintf(stderr, "Info: %d requests done (%d skipped) by this process\n", Reqno, Reqskipcnt);
816 * Child exits normally
826 struct timeval tv_delay;
827 struct sigaction sa_al, sa_old;
832 tv_delay.tv_sec = delaytime / 1000000;
833 tv_delay.tv_usec = delaytime % 1000000;
834 /*doio_fprintf(stdout, "delay_select: %d %d\n",
835 tv_delay.tv_sec, tv_delay.tv_usec);*/
836 select(0, NULL, NULL, NULL, &tv_delay);
845 sa_al.sa_handler = noop_handler;
846 sigemptyset(&sa_al.sa_mask);
847 sigaction(SIGALRM, &sa_al, &sa_old);
848 sigemptyset(&al_mask);
850 sigsuspend(&al_mask);
851 sigaction(SIGALRM, &sa_old, 0);
858 * Format IO requests, returning a pointer to the formatted text.
860 * format_strat - formats the async i/o completion strategy
861 * format_rw - formats a read[a]/write[a] request
862 * format_sds - formats a ssread/sswrite request
863 * format_listio- formats a listio request
865 * ioreq is the doio io request structure.
868 struct smap sysnames[] = {
872 { "WRITEA", WRITEA },
873 { "SSREAD", SSREAD },
874 { "SSWRITE", SSWRITE },
875 { "LISTIO", LISTIO },
877 { "LREADA", LREADA },
878 { "LWRITE", LWRITE },
879 { "LWRITEA", LWRITEA },
880 { "LSREAD", LSREAD },
881 { "LSREADA", LSREADA },
882 { "LSWRITE", LSWRITE },
883 { "LSWRITEA", LSWRITEA },
885 /* Irix System Calls */
887 { "PWRITE", PWRITE },
889 { "AWRITE", AWRITE },
890 { "LLREAD", LLREAD },
891 { "LLAREAD", LLAREAD },
892 { "LLWRITE", LLWRITE },
893 { "LLAWRITE", LLAWRITE },
894 { "RESVSP", RESVSP },
895 { "UNRESVSP", UNRESVSP },
897 /* Irix and Linux System Calls */
899 { "WRITEV", WRITEV },
902 { "FSYNC2", FSYNC2 },
903 { "FDATASYNC", FDATASYNC },
908 struct smap aionames[] = {
910 { "signal", A_SIGNAL },
911 { "recall", A_RECALL },
912 { "recalla", A_RECALLA },
913 { "recalls", A_RECALLS },
914 { "suspend", A_SUSPEND },
915 { "callback", A_CALLBACK },
921 format_oflags(int oflags)
927 switch(oflags & 03) {
928 case O_RDONLY: strcat(flags,"O_RDONLY,"); break;
929 case O_WRONLY: strcat(flags,"O_WRONLY,"); break;
930 case O_RDWR: strcat(flags,"O_RDWR,"); break;
931 default: strcat(flags,"O_weird"); break;
935 strcat(flags,"O_EXCL,");
938 strcat(flags,"O_SYNC,");
940 if(oflags & O_DIRECT)
941 strcat(flags,"O_DIRECT,");
943 return(strdup(flags));
947 format_strat(int strategy)
953 case A_POLL: aio_strat = "POLL"; break;
954 case A_SIGNAL: aio_strat = "SIGNAL"; break;
955 case A_RECALL: aio_strat = "RECALL"; break;
956 case A_RECALLA: aio_strat = "RECALLA"; break;
957 case A_RECALLS: aio_strat = "RECALLS"; break;
958 case A_SUSPEND: aio_strat = "SUSPEND"; break;
959 case A_CALLBACK: aio_strat = "CALLBACK"; break;
960 case 0: aio_strat = "<zero>"; break;
962 sprintf(msg, "<error:%#o>", strategy);
963 aio_strat = strdup(msg);
972 struct io_req *ioreq,
980 static char *errbuf=NULL;
981 char *aio_strat, *cp;
982 struct read_req *readp = &ioreq->r_data.read;
983 struct write_req *writep = &ioreq->r_data.write;
984 struct read_req *readap = &ioreq->r_data.read;
985 struct write_req *writeap = &ioreq->r_data.write;
988 errbuf = (char *)malloc(32768);
991 cp += sprintf(cp, "Request number %d\n", Reqno);
993 switch (ioreq->r_type) {
995 cp += sprintf(cp, "syscall: read(%d, %#lo, %d)\n",
996 fd, (unsigned long) buffer, readp->r_nbytes);
997 cp += sprintf(cp, " fd %d is file %s - open flags are %#o\n",
998 fd, readp->r_file, readp->r_oflags);
999 cp += sprintf(cp, " read done at file offset %d\n",
1004 cp += sprintf(cp, "syscall: write(%d, %#lo, %d)\n",
1005 fd, (unsigned long) buffer, writep->r_nbytes);
1006 cp += sprintf(cp, " fd %d is file %s - open flags are %#o\n",
1007 fd, writep->r_file, writep->r_oflags);
1008 cp += sprintf(cp, " write done at file offset %d - pattern is %s\n",
1009 writep->r_offset, pattern);
1013 aio_strat = format_strat(readap->r_aio_strat);
1015 cp += sprintf(cp, "syscall: reada(%d, %#lo, %d, %#lo, %d)\n",
1016 fd, (unsigned long) buffer, readap->r_nbytes,
1017 (unsigned long) iosw, signo);
1018 cp += sprintf(cp, " fd %d is file %s - open flags are %#o\n",
1019 fd, readap->r_file, readp->r_oflags);
1020 cp += sprintf(cp, " reada done at file offset %d\n",
1022 cp += sprintf(cp, " async io completion strategy is %s\n",
1027 aio_strat = format_strat(writeap->r_aio_strat);
1029 cp += sprintf(cp, "syscall: writea(%d, %#lo, %d, %#lo, %d)\n",
1030 fd, (unsigned long) buffer, writeap->r_nbytes,
1031 (unsigned long) iosw, signo);
1032 cp += sprintf(cp, " fd %d is file %s - open flags are %#o\n",
1033 fd, writeap->r_file, writeap->r_oflags);
1034 cp += sprintf(cp, " writea done at file offset %d - pattern is %s\n",
1035 writeap->r_offset, pattern);
1036 cp += sprintf(cp, " async io completion strategy is %s\n",
1046 * Perform the various sorts of disk reads
1053 int fd, offset, nbytes, oflags, rval;
1055 struct fd_cache *fdc;
1058 * Initialize common fields - assumes r_oflags, r_file, r_offset, and
1059 * r_nbytes are at the same offset in the read_req and reada_req
1063 file = req->r_data.read.r_file;
1064 oflags = req->r_data.read.r_oflags;
1065 offset = req->r_data.read.r_offset;
1066 nbytes = req->r_data.read.r_nbytes;
1068 /*printf("read: %s, %#o, %d %d\n", file, oflags, offset, nbytes);*/
1071 * Grab an open file descriptor
1072 * Note: must be done before memory allocation so that the direct i/o
1073 * information is available in mem. allocate
1076 if ((fd = alloc_fd(file, oflags)) == -1)
1080 * Allocate core or sds - based on the O_SSD flag
1084 #define wtob(x) (x * sizeof(UINT64_T))
1087 /* get memory alignment for using DIRECT I/O */
1088 fdc = alloc_fdcache(file, oflags);
1090 if ((rval = alloc_mem(nbytes + wtob(1) * 2 + fdc->c_memalign)) < 0) {
1097 if( (req->r_data.read.r_uflags & F_WORD_ALIGNED) ) {
1099 * Force memory alignment for Direct I/O
1101 if( (oflags & O_DIRECT) && ((long)addr % fdc->c_memalign != 0) ) {
1102 addr += fdc->c_memalign - ((long)addr % fdc->c_memalign);
1105 addr += random_range(0, wtob(1) - 1, 1, NULL);
1108 switch (req->r_type) {
1110 /* move to the desired file position. */
1111 if (lseek(fd, offset, SEEK_SET) == -1) {
1112 doio_fprintf(stderr,
1113 "lseek(%d, %d, SEEK_SET) failed: %s (%d)\n",
1114 fd, offset, SYSERR, errno);
1118 if ((rval = read(fd, addr, nbytes)) == -1) {
1119 doio_fprintf(stderr,
1120 "read() request failed: %s (%d)\n%s\n",
1122 format_rw(req, fd, addr, -1, NULL, NULL));
1123 doio_upanic(U_RVAL);
1125 } else if (rval != nbytes) {
1126 doio_fprintf(stderr,
1127 "read() request returned wrong # of bytes - expected %d, got %d\n%s\n",
1129 format_rw(req, fd, addr, -1, NULL, NULL));
1130 doio_upanic(U_RVAL);
1136 return 0; /* if we get here, everything went ok */
1140 * Perform the verious types of disk writes.
1147 static int pid = -1;
1148 int fd, nbytes, oflags;
1150 int logged_write, rval, got_lock;
1151 long offset, woffset = 0;
1152 char *addr, pattern, *file, *msg;
1153 struct wlog_rec wrec;
1154 struct fd_cache *fdc;
1157 * Misc variable setup
1160 nbytes = req->r_data.write.r_nbytes;
1161 offset = req->r_data.write.r_offset;
1162 pattern = req->r_data.write.r_pattern;
1163 file = req->r_data.write.r_file;
1164 oflags = req->r_data.write.r_oflags;
1166 /*printf("pwrite: %s, %#o, %d %d\n", file, oflags, offset, nbytes);*/
1169 * Allocate core memory and possibly sds space. Initialize the data
1173 Pattern[0] = pattern;
1177 * Get a descriptor to do the io on
1180 if ((fd = alloc_fd(file, oflags)) == -1)
1183 /*printf("write: %d, %s, %#o, %d %d\n",
1184 fd, file, oflags, offset, nbytes);*/
1187 * Allocate SDS space for backdoor write if desired
1190 /* get memory alignment for using DIRECT I/O */
1191 fdc = alloc_fdcache(file, oflags);
1193 if ((rval = alloc_mem(nbytes + wtob(1) * 2 + fdc->c_memalign)) < 0) {
1199 if( (req->r_data.write.r_uflags & F_WORD_ALIGNED) ) {
1201 * Force memory alignment for Direct I/O
1203 if( (oflags & O_DIRECT) && ((long)addr % fdc->c_memalign != 0) ) {
1204 addr += fdc->c_memalign - ((long)addr % fdc->c_memalign);
1207 addr += random_range(0, wtob(1) - 1, 1, NULL);
1210 (*Data_Fill)(Memptr, nbytes, Pattern, Pattern_Length, 0);
1211 if( addr != Memptr )
1212 memmove( addr, Memptr, nbytes);
1219 if (lock_file_region(file, fd, F_WRLCK, offset, nbytes) < 0) {
1228 * Write a preliminary write-log entry. This is done so that
1229 * doio_check can do corruption detection across an interrupt/crash.
1230 * Note that w_done is set to 0. If doio_check sees this, it
1231 * re-creates the file extents as if the write completed, but does not
1232 * do any checking - see comments in doio_check for more details.
1239 wrec.w_async = (req->r_type == WRITEA) ? 1 : 0;
1240 wrec.w_oflags = oflags;
1242 wrec.w_offset = offset;
1243 wrec.w_nbytes = nbytes;
1245 wrec.w_pathlen = strlen(file);
1246 memcpy(wrec.w_path, file, wrec.w_pathlen);
1247 wrec.w_hostlen = strlen(Host);
1248 memcpy(wrec.w_host, Host, wrec.w_hostlen);
1249 wrec.w_patternlen = Pattern_Length;
1250 memcpy(wrec.w_pattern, Pattern, wrec.w_patternlen);
1254 if ((woffset = wlog_record_write(&Wlog, &wrec, -1)) == -1) {
1255 doio_fprintf(stderr,
1256 "Could not append to write-log: %s (%d)\n",
1263 switch (req->r_type ) {
1269 if (lseek(fd, offset, SEEK_SET) == -1) {
1270 doio_fprintf(stderr,
1271 "lseek(%d, %d, SEEK_SET) failed: %s (%d)\n",
1272 fd, offset, SYSERR, errno);
1276 rval = write(fd, addr, nbytes);
1279 doio_fprintf(stderr,
1280 "write() failed: %s (%d)\n%s\n",
1282 format_rw(req, fd, addr, -1, Pattern, NULL));
1283 doio_fprintf(stderr,
1284 "write() failed: %s\n\twrite(%d, %#o, %d)\n\toffset %d, nbytes%%miniou(%d)=%d, oflags=%#o memalign=%d, addr%%memalign=%d\n",
1288 fdc->c_miniosz, nbytes%fdc->c_miniosz,
1289 oflags, fdc->c_memalign, (long)addr%fdc->c_memalign);
1290 doio_upanic(U_RVAL);
1291 } else if (rval != nbytes) {
1292 doio_fprintf(stderr,
1293 "write() returned wrong # bytes - expected %d, got %d\n%s\n",
1295 format_rw(req, fd, addr, -1, Pattern, NULL));
1296 doio_upanic(U_RVAL);
1304 * Verify that the data was written correctly - check_file() returns
1305 * a non-null pointer which contains an error message if there are
1310 msg = check_file(file, offset, nbytes, Pattern, Pattern_Length,
1311 0, oflags & O_PARALLEL);
1313 doio_fprintf(stderr, "%s%s\n",
1315 format_rw(req, fd, addr, -1, Pattern, NULL)
1317 doio_upanic(U_CORRUPTION);
1324 * General cleanup ...
1326 * Write extent information to the write-log, so that doio_check can do
1327 * corruption detection. Note that w_done is set to 1, indicating that
1328 * the write has been verified as complete. We don't need to write the
1329 * filename on the second logging.
1332 if (w_opt && logged_write) {
1334 wlog_record_write(&Wlog, &wrec, woffset);
1338 * Unlock file region if necessary
1342 if (lock_file_region(file, fd, F_UNLCK, offset, nbytes) < 0) {
1348 return( (rval == -1) ? -1 : 0);
1353 * Simple routine to lock/unlock a file using fcntl()
1357 lock_file_region(fname, fd, type, start, nbytes)
1368 flk.l_start = start;
1371 if (fcntl(fd, F_SETLKW, &flk) < 0) {
1372 doio_fprintf(stderr,
1373 "fcntl(%d, %d, %#o) failed for file %s, lock type %d, offset %d, length %d: %s (%d), open flags: %#o\n",
1374 fd, F_SETLKW, &flk, fname, type,
1375 start, nbytes, SYSERR, errno,
1376 fcntl(fd, F_GETFL, 0));
1390 /* ---------------------------------------------------------------------------
1392 * A new paradigm of doing the r/w system call where there is a "stub"
1393 * function that builds the info for the system call, then does the system
1394 * call; this is called by code that is common to all system calls and does
1395 * the syscall return checking, async I/O wait, iosw check, etc.
1398 * WRITE, ASYNC, SSD/SDS,
1399 * FILE_LOCK, WRITE_LOG, VERIFY_DATA,
1403 int rval; /* syscall return */
1404 int err; /* errno */
1405 int *aioid; /* list of async I/O structures */
1408 struct syscall_info {
1411 struct status *(*sy_syscall)();
1413 char *(*sy_format)();
1418 #define SY_WRITE 00001
1419 #define SY_ASYNC 00010
1420 #define SY_IOSW 00020
1421 #define SY_SDS 00100
1424 fmt_ioreq(struct io_req *ioreq, struct syscall_info *sy, int fd)
1426 static char *errbuf=NULL;
1432 errbuf = (char *)malloc(32768);
1434 io = &ioreq->r_data.io;
1437 * Look up async I/O completion strategy
1440 aname->value != -1 && aname->value != io->r_aio_strat;
1445 cp += sprintf(cp, "Request number %d\n", Reqno);
1447 cp += sprintf(cp, " fd %d is file %s - open flags are %#o %s\n",
1448 fd, io->r_file, io->r_oflags, format_oflags(io->r_oflags));
1450 if(sy->sy_flags & SY_WRITE) {
1451 cp += sprintf(cp, " write done at file offset %d - pattern is %c (%#o)\n",
1453 (io->r_pattern == '\0') ? '?' : io->r_pattern,
1456 cp += sprintf(cp, " read done at file offset %d\n",
1460 if(sy->sy_flags & SY_ASYNC) {
1461 cp += sprintf(cp, " async io completion strategy is %s\n",
1465 cp += sprintf(cp, " number of requests is %d, strides per request is %d\n",
1466 io->r_nent, io->r_nstrides);
1468 cp += sprintf(cp, " i/o byte count = %d\n",
1471 cp += sprintf(cp, " memory alignment is %s\n",
1472 (io->r_uflags & F_WORD_ALIGNED) ? "aligned" : "unaligned");
1474 if(io->r_oflags & O_DIRECT) {
1476 struct dioattr finfo;
1478 if(xfsctl(io->r_file, fd, XFS_IOC_DIOINFO, &finfo) == -1) {
1479 cp += sprintf(cp, " Error %s (%d) getting direct I/O info\n",
1480 strerror(errno), errno);
1482 finfo.d_miniosz = 1;
1483 finfo.d_maxiosz = 1;
1486 dio_env = getenv("XFS_DIO_MIN");
1488 finfo.d_mem = finfo.d_miniosz = atoi(dio_env);
1490 cp += sprintf(cp, " DIRECT I/O: offset %% %d = %d length %% %d = %d\n",
1492 io->r_offset % finfo.d_miniosz,
1494 io->r_nbytes % finfo.d_miniosz);
1495 cp += sprintf(cp, " mem alignment 0x%x xfer size: small: %d large: %d\n",
1496 finfo.d_mem, finfo.d_miniosz, finfo.d_maxiosz);
1502 sy_pread(req, sysc, fd, addr)
1504 struct syscall_info *sysc;
1509 struct status *status;
1511 rc = pread(fd, addr, req->r_data.io.r_nbytes,
1512 req->r_data.io.r_offset);
1514 status = (struct status *)malloc(sizeof(struct status));
1515 if( status == NULL ){
1516 doio_fprintf(stderr, "malloc failed, %s/%d\n",
1517 __FILE__, __LINE__);
1520 status->aioid = NULL;
1522 status->err = errno;
1528 sy_pwrite(req, sysc, fd, addr)
1530 struct syscall_info *sysc;
1535 struct status *status;
1537 rc = pwrite(fd, addr, req->r_data.io.r_nbytes,
1538 req->r_data.io.r_offset);
1540 status = (struct status *)malloc(sizeof(struct status));
1541 if( status == NULL ){
1542 doio_fprintf(stderr, "malloc failed, %s/%d\n",
1543 __FILE__, __LINE__);
1546 status->aioid = NULL;
1548 status->err = errno;
1554 fmt_pread(struct io_req *req, struct syscall_info *sy, int fd, char *addr)
1556 static char *errbuf = NULL;
1560 errbuf = (char *)malloc(32768);
1561 if( errbuf == NULL ){
1562 doio_fprintf(stderr, "malloc failed, %s/%d\n",
1563 __FILE__, __LINE__);
1569 cp += sprintf(cp, "syscall: %s(%d, 0x%p, %d)\n",
1570 sy->sy_name, fd, addr, req->r_data.io.r_nbytes);
1575 sy_rwv(req, sysc, fd, addr, rw)
1577 struct syscall_info *sysc;
1583 struct status *status;
1584 struct iovec iov[2];
1586 status = (struct status *)malloc(sizeof(struct status));
1587 if( status == NULL ){
1588 doio_fprintf(stderr, "malloc failed, %s/%d\n",
1589 __FILE__, __LINE__);
1592 status->aioid = NULL;
1594 /* move to the desired file position. */
1595 if ((rc=lseek(fd, req->r_data.io.r_offset, SEEK_SET)) == -1) {
1597 status->err = errno;
1601 iov[0].iov_base = addr;
1602 iov[0].iov_len = req->r_data.io.r_nbytes;
1605 rc = writev(fd, iov, 1);
1607 rc = readv(fd, iov, 1);
1608 status->aioid = NULL;
1610 status->err = errno;
1615 sy_readv(req, sysc, fd, addr)
1617 struct syscall_info *sysc;
1621 return sy_rwv(req, sysc, fd, addr, 0);
1625 sy_writev(req, sysc, fd, addr)
1627 struct syscall_info *sysc;
1631 return sy_rwv(req, sysc, fd, addr, 1);
1635 fmt_readv(struct io_req *req, struct syscall_info *sy, int fd, char *addr)
1637 static char errbuf[32768];
1641 cp += sprintf(cp, "syscall: %s(%d, (iov on stack), 1)\n",
1647 sy_mmrw(req, sysc, fd, addr, rw)
1649 struct syscall_info *sysc;
1656 * This version is oriented towards mmaping the file to memory
1657 * ONCE and keeping it mapped.
1659 struct status *status;
1660 void *mrc, *memaddr;
1661 struct fd_cache *fdc;
1664 status = (struct status *)malloc(sizeof(struct status));
1665 if( status == NULL ){
1666 doio_fprintf(stderr, "malloc failed, %s/%d\n",
1667 __FILE__, __LINE__);
1670 status->aioid = NULL;
1673 fdc = alloc_fdcache(req->r_data.io.r_file, req->r_data.io.r_oflags);
1675 if( fdc->c_memaddr == NULL ) {
1676 if( fstat(fd, &sbuf) < 0 ){
1677 doio_fprintf(stderr, "fstat failed, errno=%d\n",
1679 status->err = errno;
1683 fdc->c_memlen = (int)sbuf.st_size;
1684 mrc = mmap(NULL, (int)sbuf.st_size,
1685 rw ? PROT_WRITE|PROT_READ : PROT_READ,
1688 if( mrc == MAP_FAILED ) {
1689 doio_fprintf(stderr, "mmap() failed - 0x%lx %d\n",
1691 status->err = errno;
1695 fdc->c_memaddr = mrc;
1698 memaddr = (void *)((char *)fdc->c_memaddr + req->r_data.io.r_offset);
1702 memcpy(memaddr, addr, req->r_data.io.r_nbytes);
1704 memcpy(addr, memaddr, req->r_data.io.r_nbytes);
1707 status->rval = req->r_data.io.r_nbytes;
1713 sy_mmread(req, sysc, fd, addr)
1715 struct syscall_info *sysc;
1719 return sy_mmrw(req, sysc, fd, addr, 0);
1723 sy_mmwrite(req, sysc, fd, addr)
1725 struct syscall_info *sysc;
1729 return sy_mmrw(req, sysc, fd, addr, 1);
1733 fmt_mmrw(struct io_req *req, struct syscall_info *sy, int fd, char *addr)
1735 static char errbuf[32768];
1737 struct fd_cache *fdc;
1740 fdc = alloc_fdcache(req->r_data.io.r_file, req->r_data.io.r_oflags);
1743 cp += sprintf(cp, "syscall: %s(NULL, %d, %s, MAP_SHARED, %d, 0)\n",
1746 (sy->sy_flags & SY_WRITE) ? "PROT_WRITE" : "PROT_READ",
1749 cp += sprintf(cp, "\tfile is mmaped to: 0x%lx\n",
1750 (unsigned long) fdc->c_memaddr);
1752 memaddr = (void *)((char *)fdc->c_memaddr + req->r_data.io.r_offset);
1754 cp += sprintf(cp, "\tfile-mem=0x%lx, length=%d, buffer=0x%lx\n",
1755 (unsigned long) memaddr, req->r_data.io.r_nbytes,
1756 (unsigned long) addr);
1761 struct syscall_info syscalls[] = {
1763 sy_pread, NULL, fmt_pread,
1767 sy_pwrite, NULL, fmt_pread,
1772 sy_readv, NULL, fmt_readv,
1776 sy_writev, NULL, fmt_readv,
1779 { "mmap-read", MMAPR,
1780 sy_mmread, NULL, fmt_mmrw,
1783 { "mmap-write", MMAPW,
1784 sy_mmwrite, NULL, fmt_mmrw,
1798 static int pid = -1;
1799 int fd, offset, nbytes, nstrides, nents, oflags;
1800 int rval, mem_needed, i;
1801 int logged_write, got_lock, woffset = 0, pattern;
1802 int min_byte, max_byte;
1803 char *addr, *file, *msg;
1805 struct wlog_rec wrec;
1806 struct syscall_info *sy;
1807 struct fd_cache *fdc;
1810 * Initialize common fields - assumes r_oflags, r_file, r_offset, and
1811 * r_nbytes are at the same offset in the read_req and reada_req
1814 file = req->r_data.io.r_file;
1815 oflags = req->r_data.io.r_oflags;
1816 offset = req->r_data.io.r_offset;
1817 nbytes = req->r_data.io.r_nbytes;
1818 nstrides= req->r_data.io.r_nstrides;
1819 nents = req->r_data.io.r_nent;
1820 pattern = req->r_data.io.r_pattern;
1822 if( nents >= MAX_AIO ) {
1823 doio_fprintf(stderr, "do_rw: too many list requests, %d. Maximum is %d\n",
1829 * look up system call info
1831 for(sy=syscalls; sy->sy_name != NULL && sy->sy_type != req->r_type; sy++)
1834 if(sy->sy_name == NULL) {
1835 doio_fprintf(stderr, "do_rw: unknown r_type %d.\n",
1841 * Get an open file descriptor
1842 * Note: must be done before memory allocation so that the direct i/o
1843 * information is available in mem. allocate
1846 if ((fd = alloc_fd(file, oflags)) == -1)
1850 * Allocate core memory and possibly sds space. Initialize the
1851 * data to be written. Make sure we get enough, based on the
1855 * 1 extra word for possible partial-word address "bump"
1856 * 1 extra word for dynamic pattern overrun
1857 * MPP_BUMP extra words for T3E non-hw-aligned memory address.
1860 if( sy->sy_buffer != NULL ) {
1861 mem_needed = (*sy->sy_buffer)(req, 0, 0, NULL, NULL);
1863 mem_needed = nbytes;
1866 /* get memory alignment for using DIRECT I/O */
1867 fdc = alloc_fdcache(file, oflags);
1869 if ((rval = alloc_mem(mem_needed + wtob(1) * 2 + fdc->c_memalign)) < 0) {
1873 Pattern[0] = pattern;
1876 * Allocate SDS space for backdoor write if desired
1879 if (oflags & O_SSD) {
1880 doio_fprintf(stderr, "Invalid O_SSD flag was generated for non-Cray system\n");
1887 * if io is not raw, bump the offset by a random amount
1888 * to generate non-word-aligned io.
1890 * On MPP systems, raw I/O must start on an 0x80 byte boundary.
1891 * For non-aligned I/O, bump the address from 1 to 8 words.
1894 if (! (req->r_data.io.r_uflags & F_WORD_ALIGNED)) {
1895 addr += random_range(0, wtob(1) - 1, 1, NULL);
1899 * Force memory alignment for Direct I/O
1901 if( (oflags & O_DIRECT) && ((long)addr % fdc->c_memalign != 0) ) {
1902 addr += fdc->c_memalign - ((long)addr % fdc->c_memalign);
1906 * FILL must be done on a word-aligned buffer.
1907 * Call the fill function with Memptr which is aligned,
1908 * then memmove it to the right place.
1910 if (sy->sy_flags & SY_WRITE) {
1911 (*Data_Fill)(Memptr, mem_needed, Pattern, Pattern_Length, 0);
1912 if( addr != Memptr )
1913 memmove( addr, Memptr, mem_needed);
1922 * Lock data if this is a write and locking option is set
1924 if (sy->sy_flags & SY_WRITE && k_opt) {
1925 if( sy->sy_buffer != NULL ) {
1926 (*sy->sy_buffer)(req, offset, 0, &min_byte, &max_byte);
1929 max_byte = offset + (nbytes * nstrides * nents);
1932 if (lock_file_region(file, fd, F_WRLCK,
1933 min_byte, (max_byte-min_byte+1)) < 0) {
1934 doio_fprintf(stderr,
1935 "file lock failed:\n%s\n",
1936 fmt_ioreq(req, sy, fd));
1937 doio_fprintf(stderr,
1938 " buffer(req, %d, 0, 0x%x, 0x%x)\n",
1939 offset, min_byte, max_byte);
1948 * Write a preliminary write-log entry. This is done so that
1949 * doio_check can do corruption detection across an interrupt/crash.
1950 * Note that w_done is set to 0. If doio_check sees this, it
1951 * re-creates the file extents as if the write completed, but does not
1952 * do any checking - see comments in doio_check for more details.
1955 if (sy->sy_flags & SY_WRITE && w_opt) {
1960 wrec.w_async = (sy->sy_flags & SY_ASYNC) ? 1 : 0;
1961 wrec.w_oflags = oflags;
1963 wrec.w_offset = offset;
1964 wrec.w_nbytes = nbytes; /* mem_needed -- total length */
1966 wrec.w_pathlen = strlen(file);
1967 memcpy(wrec.w_path, file, wrec.w_pathlen);
1968 wrec.w_hostlen = strlen(Host);
1969 memcpy(wrec.w_host, Host, wrec.w_hostlen);
1970 wrec.w_patternlen = Pattern_Length;
1971 memcpy(wrec.w_pattern, Pattern, wrec.w_patternlen);
1975 if ((woffset = wlog_record_write(&Wlog, &wrec, -1)) == -1) {
1976 doio_fprintf(stderr,
1977 "Could not append to write-log: %s (%d)\n",
1984 s = (*sy->sy_syscall)(req, sy, fd, addr);
1986 if( s->rval == -1 ) {
1987 doio_fprintf(stderr,
1988 "%s() request failed: %s (%d)\n%s\n%s\n",
1989 sy->sy_name, SYSERR, errno,
1990 fmt_ioreq(req, sy, fd),
1991 (*sy->sy_format)(req, sy, fd, addr));
1993 doio_upanic(U_RVAL);
1995 for(i=0; i < nents; i++) {
1996 if(s->aioid == NULL)
1998 aio_unregister(s->aioid[i]);
2003 * If the syscall was async, wait for I/O to complete
2006 if(sy->sy_flags & SY_ASYNC) {
2007 for(i=0; i < nents; i++) {
2008 aio_wait(s->aioid[i]);
2014 * Check the syscall how-much-data-written return. Look
2015 * for this in either the return value or the 'iosw'
2019 if( !(sy->sy_flags & SY_IOSW) ) {
2021 if(s->rval != mem_needed) {
2022 doio_fprintf(stderr,
2023 "%s() request returned wrong # of bytes - expected %d, got %d\n%s\n%s\n",
2024 sy->sy_name, nbytes, s->rval,
2025 fmt_ioreq(req, sy, fd),
2026 (*sy->sy_format)(req, sy, fd, addr));
2028 doio_upanic(U_RVAL);
2035 * Verify that the data was written correctly - check_file() returns
2036 * a non-null pointer which contains an error message if there are
2040 if ( rval == 0 && sy->sy_flags & SY_WRITE && v_opt) {
2041 msg = check_file(file, offset, nbytes*nstrides*nents,
2042 Pattern, Pattern_Length, 0,
2043 oflags & O_PARALLEL);
2045 doio_fprintf(stderr, "%s\n%s\n%s\n",
2047 fmt_ioreq(req, sy, fd),
2048 (*sy->sy_format)(req, sy, fd, addr));
2049 doio_upanic(U_CORRUPTION);
2055 * General cleanup ...
2057 * Write extent information to the write-log, so that doio_check can do
2058 * corruption detection. Note that w_done is set to 1, indicating that
2059 * the write has been verified as complete. We don't need to write the
2060 * filename on the second logging.
2063 if (w_opt && logged_write) {
2065 wlog_record_write(&Wlog, &wrec, woffset);
2069 * Unlock file region if necessary
2073 if (lock_file_region(file, fd, F_UNLCK,
2074 min_byte, (max_byte-min_byte+1)) < 0) {
2080 if(s->aioid != NULL)
2083 return (rval == -1) ? -1 : 0;
2088 * xfsctl-based requests
2090 * - XFS_IOC_UNRESVSP
2096 int fd, oflags, offset, nbytes;
2099 int min_byte = 0, max_byte = 0;
2100 char *file, *msg = NULL;
2101 struct xfs_flock64 flk;
2104 * Initialize common fields - assumes r_oflags, r_file, r_offset, and
2105 * r_nbytes are at the same offset in the read_req and reada_req
2108 file = req->r_data.io.r_file;
2109 oflags = req->r_data.io.r_oflags;
2110 offset = req->r_data.io.r_offset;
2111 nbytes = req->r_data.io.r_nbytes;
2114 flk.l_whence=SEEK_SET;
2119 * Get an open file descriptor
2122 if ((fd = alloc_fd(file, oflags)) == -1)
2129 * Lock data if this is locking option is set
2133 max_byte = offset + nbytes;
2135 if (lock_file_region(file, fd, F_WRLCK,
2136 min_byte, (nbytes+1)) < 0) {
2137 doio_fprintf(stderr,
2138 "file lock failed:\n");
2139 doio_fprintf(stderr,
2140 " buffer(req, %d, 0, 0x%x, 0x%x)\n",
2141 offset, min_byte, max_byte);
2149 switch (req->r_type) {
2150 case RESVSP: op=XFS_IOC_RESVSP; msg="resvsp"; break;
2151 case UNRESVSP: op=XFS_IOC_UNRESVSP; msg="unresvsp"; break;
2154 rval = xfsctl(file, fd, op, &flk);
2157 doio_fprintf(stderr,
2158 "xfsctl %s request failed: %s (%d)\n\txfsctl(%d, %s %d, {%d %lld ==> %lld}\n",
2160 fd, msg, op, flk.l_whence,
2161 (long long)flk.l_start,
2162 (long long)flk.l_len);
2164 doio_upanic(U_RVAL);
2169 * Unlock file region if necessary
2173 if (lock_file_region(file, fd, F_UNLCK,
2174 min_byte, (max_byte-min_byte+1)) < 0) {
2180 return (rval == -1) ? -1 : 0;
2184 * fsync(2) and fdatasync(2)
2195 * Initialize common fields - assumes r_oflags, r_file, r_offset, and
2196 * r_nbytes are at the same offset in the read_req and reada_req
2199 file = req->r_data.io.r_file;
2200 oflags = req->r_data.io.r_oflags;
2203 * Get an open file descriptor
2206 if ((fd = alloc_fd(file, oflags)) == -1)
2210 switch(req->r_type) {
2215 rval = fdatasync(fd);
2220 return (rval == -1) ? -1 : 0;
2224 doio_pat_fill(char *addr, int mem_needed, char *Pattern, int Pattern_Length,
2227 return pattern_fill(addr, mem_needed, Pattern, Pattern_Length, 0);
2231 doio_pat_check(buf, offset, length, pattern, pattern_length, patshift)
2239 static char errbuf[4096];
2240 int nb, i, pattern_index;
2241 char *cp, *bufend, *ep;
2242 char actual[33], expected[33];
2244 if (pattern_check(buf, length, pattern, pattern_length, patshift) != 0) {
2246 ep += sprintf(ep, "Corrupt regions follow - unprintable chars are represented as '.'\n");
2247 ep += sprintf(ep, "-----------------------------------------------------------------\n");
2249 pattern_index = patshift % pattern_length;;
2251 bufend = buf + length;
2253 while (cp < bufend) {
2254 if (*cp != pattern[pattern_index]) {
2256 if (nb > sizeof(expected)-1) {
2257 nb = sizeof(expected)-1;
2260 ep += sprintf(ep, "corrupt bytes starting at file offset %d\n", offset + (int)(cp-buf));
2263 * Fill in the expected and actual patterns
2265 bzero(expected, sizeof(expected));
2266 bzero(actual, sizeof(actual));
2268 for (i = 0; i < nb; i++) {
2269 expected[i] = pattern[(pattern_index + i) % pattern_length];
2270 if (! isprint((int)expected[i])) {
2275 if (! isprint((int)actual[i])) {
2280 ep += sprintf(ep, " 1st %2d expected bytes: %s\n", nb, expected);
2281 ep += sprintf(ep, " 1st %2d actual bytes: %s\n", nb, actual);
2288 if (pattern_index == pattern_length) {
2301 * Check the contents of a file beginning at offset, for length bytes. It
2302 * is assumed that there is a string of pattern bytes in this area of the
2303 * file. Use normal buffered reads to do the verification.
2305 * If there is a data mismatch, write a detailed message into a static buffer
2306 * suitable for the caller to print. Otherwise print NULL.
2308 * The fsa flag is set to non-zero if the buffer should be read back through
2309 * the FSA (unicos/mk). This implies the file will be opened
2310 * O_PARALLEL|O_RAW|O_WELLFORMED to do the validation. We must do this because
2311 * FSA will not allow the file to be opened for buffered io if it was
2312 * previously opened for O_PARALLEL io.
2316 check_file(file, offset, length, pattern, pattern_length, patshift, fsa)
2325 static char errbuf[4096];
2327 char *buf, *em, *ep;
2328 struct fd_cache *fdc;
2333 flags = Validation_Flags | O_RDONLY;
2338 if ((fd = alloc_fd(file, flags)) == -1) {
2340 "Could not open file %s with flags %#o (%s) for data comparison: %s (%d)\n",
2341 file, flags, format_oflags(flags),
2346 if (lseek(fd, offset, SEEK_SET) == -1) {
2348 "Could not lseek to offset %d in %s for verification: %s (%d)\n",
2349 offset, file, SYSERR, errno);
2353 /* Guarantee a properly aligned address on Direct I/O */
2354 fdc = alloc_fdcache(file, flags);
2355 if( (flags & O_DIRECT) && ((long)buf % fdc->c_memalign != 0) ) {
2356 buf += fdc->c_memalign - ((long)buf % fdc->c_memalign);
2359 if ((nb = read(fd, buf, length)) == -1) {
2361 "Could not read %d bytes from %s for verification: %s (%d)\n\tread(%d, 0x%p, %d)\n\tbuf %% alignment(%d) = %ld\n",
2362 length, file, SYSERR, errno,
2364 fdc->c_memalign, (long)buf % fdc->c_memalign);
2370 "Read wrong # bytes from %s. Expected %d, got %d\n",
2375 if( (em = (*Data_Check)(buf, offset, length, pattern, pattern_length, patshift)) != NULL ) {
2377 ep += sprintf(ep, "*** DATA COMPARISON ERROR ***\n");
2378 ep += sprintf(ep, "check_file(%s, %d, %d, %s, %d, %d) failed\n\n",
2379 file, offset, length, pattern, pattern_length, patshift);
2380 ep += sprintf(ep, "Comparison fd is %d, with open flags %#o\n",
2389 * Function to single-thread stdio output.
2393 doio_fprintf(FILE *stream, char *format, ...)
2395 static int pid = -1;
2401 date = hms(time(0));
2407 flk.l_whence = flk.l_start = flk.l_len = 0;
2408 flk.l_type = F_WRLCK;
2409 fcntl(fileno(stream), F_SETLKW, &flk);
2411 va_start(arglist, format);
2412 rval = fprintf(stream, "\n%s%s (%5d) %s\n", Prog, TagName, pid, date);
2413 rval += fprintf(stream, "---------------------\n");
2414 vfprintf(stream, format, arglist);
2419 flk.l_type = F_UNLCK;
2420 fcntl(fileno(stream), F_SETLKW, &flk);
2426 * Simple function for allocating core memory. Uses Memsize and Memptr to
2427 * keep track of the current amount allocated.
2436 int me = 0, flags, key, shmid;
2437 static int mturn = 0; /* which memory type to use */
2441 struct shmid_ds shm_ds;
2442 bzero( &shm_ds, sizeof(struct shmid_ds) );
2445 /* nbytes = -1 means "free all allocated memory" */
2446 if( nbytes == -1 ) {
2448 for(me=0; me < Nmemalloc; me++) {
2449 if(Memalloc[me].space == NULL)
2452 switch(Memalloc[me].memtype) {
2454 free(Memalloc[me].space);
2455 Memalloc[me].space = NULL;
2460 shmdt(Memalloc[me].space);
2461 Memalloc[me].space = NULL;
2462 shmctl(Memalloc[me].fd, IPC_RMID, &shm_ds);
2465 munmap(Memalloc[me].space,
2467 close(Memalloc[me].fd);
2468 if(Memalloc[me].flags & MEMF_FILE) {
2469 unlink(Memalloc[me].name);
2471 Memalloc[me].space = NULL;
2474 doio_fprintf(stderr, "alloc_mem: HELP! Unknown memory space type %d index %d\n",
2475 Memalloc[me].memtype, me);
2483 * Select a memory area (currently round-robbin)
2486 if(mturn >= Nmemalloc)
2489 M = &Memalloc[mturn];
2491 switch(M->memtype) {
2493 if( nbytes > M->size ) {
2494 if( M->space != NULL ){
2501 if( M->space == NULL ) {
2502 if( (cp = malloc( nbytes )) == NULL ) {
2503 doio_fprintf(stderr, "malloc(%d) failed: %s (%d)\n",
2504 nbytes, SYSERR, errno);
2507 M->space = (void *)cp;
2513 if( nbytes > M->size ) {
2514 if( M->space != NULL ) {
2515 munmap(M->space, M->size);
2517 if( M->flags & MEMF_FILE )
2524 if( M->space == NULL ) {
2525 if(strchr(M->name, '%')) {
2526 sprintf(filename, M->name, getpid());
2527 M->name = strdup(filename);
2530 if( (M->fd = open(M->name, O_CREAT|O_RDWR, 0666)) == -1) {
2531 doio_fprintf(stderr, "alloc_mmap: error %d (%s) opening '%s'\n",
2539 M->size = nbytes * 4;
2541 /* bias addr if MEMF_ADDR | MEMF_FIXADDR */
2542 /* >>> how to pick a memory address? */
2544 /* bias flags on MEMF_PRIVATE etc */
2545 if(M->flags & MEMF_PRIVATE)
2546 flags |= MAP_PRIVATE;
2547 if(M->flags & MEMF_SHARED)
2548 flags |= MAP_SHARED;
2550 /*printf("alloc_mem, about to mmap, fd=%d, name=(%s)\n", M->fd, M->name);*/
2551 if( (M->space = mmap(addr, M->size,
2552 PROT_READ|PROT_WRITE,
2555 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",
2558 PROT_READ|PROT_WRITE,
2559 flags, M->flags, M->fd,
2561 doio_fprintf(stderr, "\t%s%s%s%s%s",
2562 (flags & MAP_PRIVATE) ? "private " : "",
2563 (flags & MAP_SHARED) ? "shared" : "");
2570 if( nbytes > M->size ) {
2571 if( M->space != NULL ) {
2572 shmctl( M->fd, IPC_RMID, &shm_ds );
2578 if(M->space == NULL) {
2579 if(!strcmp(M->name, "private")) {
2582 sscanf(M->name, "%i", &key);
2585 M->size = M->nblks ? M->nblks * 512 : nbytes;
2587 if( nbytes > M->size ){
2589 doio_fprintf(stderr, "MEM_SHMEM: nblks(%d) too small: nbytes=%d Msize=%d, skipping this req.\n",
2590 M->nblks, nbytes, M->size );
2595 shmid = shmget(key, M->size, IPC_CREAT|0666);
2597 doio_fprintf(stderr, "shmget(0x%x, %d, CREAT) failed: %s (%d)\n",
2598 key, M->size, SYSERR, errno);
2602 M->space = shmat(shmid, NULL, SHM_RND);
2603 if( M->space == (void *)-1 ) {
2604 doio_fprintf(stderr, "shmat(0x%x, NULL, SHM_RND) failed: %s (%d)\n",
2605 shmid, SYSERR, errno);
2612 doio_fprintf(stderr, "alloc_mem: HELP! Unknown memory space type %d index %d\n",
2613 Memalloc[me].memtype, mturn);
2625 * Function to maintain a file descriptor cache, so that doio does not have
2626 * to do so many open() and close() calls. Descriptors are stored in the
2627 * cache by file name, and open flags. Each entry also has a _rtc value
2628 * associated with it which is used in aging. If doio cannot open a file
2629 * because it already has too many open (ie. system limit hit) it will close
2630 * the one in the cache that has the oldest _rtc value.
2632 * If alloc_fd() is called with a file of NULL, it will close all descriptors
2633 * in the cache, and free the memory in the cache.
2637 alloc_fd(file, oflags)
2641 struct fd_cache *fdc;
2642 struct fd_cache *alloc_fdcache(char *file, int oflags);
2644 fdc = alloc_fdcache(file, oflags);
2652 alloc_fdcache(file, oflags)
2657 struct fd_cache *free_slot, *oldest_slot, *cp;
2658 static int cache_size = 0;
2659 static struct fd_cache *cache = NULL;
2660 struct dioattr finfo;
2663 * If file is NULL, it means to free up the fd cache.
2666 if (file == NULL && cache != NULL) {
2667 for (cp = cache; cp < &cache[cache_size]; cp++) {
2668 if (cp->c_fd != -1) {
2671 if (cp->c_memaddr != NULL) {
2672 munmap(cp->c_memaddr, cp->c_memlen);
2686 * Look for a fd in the cache. If one is found, return it directly.
2687 * Otherwise, when this loop exits, oldest_slot will point to the
2688 * oldest fd slot in the cache, and free_slot will point to an
2689 * unoccupied slot if there are any.
2692 for (cp = cache; cp != NULL && cp < &cache[cache_size]; cp++) {
2693 if (cp->c_fd != -1 &&
2694 cp->c_oflags == oflags &&
2695 strcmp(cp->c_file, file) == 0) {
2700 if (cp->c_fd == -1) {
2701 if (free_slot == NULL) {
2705 if (oldest_slot == NULL ||
2706 cp->c_rtc < oldest_slot->c_rtc) {
2713 * No matching file/oflags pair was found in the cache. Attempt to
2717 if ((fd = open(file, oflags, 0666)) < 0) {
2718 if (errno != EMFILE) {
2719 doio_fprintf(stderr,
2720 "Could not open file %s with flags %#o (%s): %s (%d)\n",
2721 file, oflags, format_oflags(oflags),
2728 * If we get here, we have as many open fd's as we can have.
2729 * Close the oldest one in the cache (pointed to by
2730 * oldest_slot), and attempt to re-open.
2733 close(oldest_slot->c_fd);
2734 oldest_slot->c_fd = -1;
2735 free_slot = oldest_slot;
2737 if ((fd = open(file, oflags, 0666)) < 0) {
2738 doio_fprintf(stderr,
2739 "Could not open file %s with flags %#o (%s): %s (%d)\n",
2740 file, oflags, format_oflags(oflags),
2747 /*printf("alloc_fd: new file %s flags %#o fd %d\n", file, oflags, fd);*/
2750 * If we get here, fd is our open descriptor. If free_slot is NULL,
2751 * we need to grow the cache, otherwise free_slot is the slot that
2752 * should hold the fd info.
2755 if (free_slot == NULL) {
2756 cache = (struct fd_cache *)realloc(cache, sizeof(struct fd_cache) * (FD_ALLOC_INCR + cache_size));
2757 if (cache == NULL) {
2758 doio_fprintf(stderr, "Could not malloc() space for fd chace");
2763 cache_size += FD_ALLOC_INCR;
2765 for (cp = &cache[cache_size-FD_ALLOC_INCR];
2766 cp < &cache[cache_size]; cp++) {
2770 free_slot = &cache[cache_size - FD_ALLOC_INCR];
2774 * finally, fill in the cache slot info
2777 free_slot->c_fd = fd;
2778 free_slot->c_oflags = oflags;
2779 strcpy(free_slot->c_file, file);
2780 free_slot->c_rtc = Reqno;
2782 if (oflags & O_DIRECT) {
2785 if (xfsctl(file, fd, XFS_IOC_DIOINFO, &finfo) == -1) {
2787 finfo.d_miniosz = 1;
2788 finfo.d_maxiosz = 1;
2791 dio_env = getenv("XFS_DIO_MIN");
2793 finfo.d_mem = finfo.d_miniosz = atoi(dio_env);
2797 finfo.d_miniosz = 1;
2798 finfo.d_maxiosz = 1;
2801 free_slot->c_memalign = finfo.d_mem;
2802 free_slot->c_miniosz = finfo.d_miniosz;
2803 free_slot->c_maxiosz = finfo.d_maxiosz;
2804 free_slot->c_memaddr = NULL;
2805 free_slot->c_memlen = 0;
2812 * Signal Handling Section
2820 havesigint=1; /* in case there's a followup signal */
2829 doio_fprintf(stderr, "terminating on signal %d\n", sig);
2838 /* See sigbus_handler() in the 'ifdef sgi' case for details. Here,
2839 we don't have the siginfo stuff so the guess is weaker but we'll
2843 if( active_mmap_rw && havesigint )
2858 * SIGINT handler for the parent (original doio) process. It simply sends
2859 * a SIGINT to all of the doio children. Since they're all in the same
2860 * pgrp, this can be done with a single kill().
2868 for (i = 0; i < Nchildren; i++) {
2869 if (Children[i] != -1) {
2870 kill(Children[i], SIGINT);
2876 * Signal handler used to inform a process when async io completes. Referenced
2877 * in do_read() and do_write(). Note that the signal handler is not
2886 struct aio_info *aiop;
2888 for (i = 0; i < sizeof(Aio_Info) / sizeof(Aio_Info[0]); i++) {
2889 aiop = &Aio_Info[i];
2891 if (aiop->strategy == A_SIGNAL && aiop->sig == sig) {
2894 if (aio_done(aiop)) {
2902 * dump info on all open aio slots
2910 for (i = 0; i < sizeof(Aio_Info) / sizeof(Aio_Info[0]); i++) {
2911 if (Aio_Info[i].busy) {
2914 "Aio_Info[%03d] id=%d fd=%d signal=%d signaled=%d\n",
2918 Aio_Info[i].signalled);
2919 fprintf(stderr, "\tstrategy=%s\n",
2920 format_strat(Aio_Info[i].strategy));
2923 fprintf(stderr, "%d active async i/os\n", count);
2932 struct aio_info *aiop;
2936 for (i = 0; i < sizeof(Aio_Info) / sizeof(Aio_Info[0]); i++) {
2938 if (! Aio_Info[i].busy) {
2939 aiop = &Aio_Info[i];
2945 if (Aio_Info[i].busy && Aio_Info[i].id == aio_id) {
2946 aiop = &Aio_Info[i];
2953 doio_fprintf(stderr,"aio_slot(%d) not found. Request %d\n",
2964 aio_register(fd, strategy, sig)
2969 struct aio_info *aiop;
2971 struct sigaction sa;
2973 aiop = aio_slot(-1);
2976 aiop->strategy = strategy;
2979 if (strategy == A_SIGNAL) {
2981 aiop->signalled = 0;
2983 sa.sa_handler = aio_handler;
2985 sigemptyset(&sa.sa_mask);
2987 sigaction(sig, &sa, &aiop->osa);
2990 aiop->signalled = 0;
2997 aio_unregister(aio_id)
3000 struct aio_info *aiop;
3002 aiop = aio_slot(aio_id);
3004 if (aiop->strategy == A_SIGNAL) {
3005 sigaction(aiop->sig, &aiop->osa, NULL);
3017 #ifdef RECALL_SIZEOF
3018 long mask[RECALL_SIZEOF];
3021 struct aio_info *aiop;
3023 /*printf("aio_wait: errno %d return %d\n", aiop->aio_errno, aiop->aio_ret);*/
3030 * Format specified time into HH:MM:SS format. t is the time to format
3031 * in seconds (as returned from time(2)).
3038 static char ascii_time[9];
3041 ltime = localtime(&t);
3042 strftime(ascii_time, sizeof(ascii_time), "%H:%M:%S", ltime);
3048 * Simple routine to check if an async io request has completed.
3052 aio_done(struct aio_info *ainfo)
3054 return -1; /* invalid */
3058 * Routine to handle upanic() - it first attempts to set the panic flag. If
3059 * the flag cannot be set, an error message is issued. A call to upanic
3060 * with PA_PANIC is then done unconditionally, in case the panic flag was set
3061 * from outside the program (as with the panic(8) program).
3063 * Note - we only execute the upanic code if -U was used, and the passed in
3064 * mask is set in the Upanic_Conditions bitmask.
3071 if (U_opt == 0 || (mask & Upanic_Conditions) == 0) {
3074 doio_fprintf(stderr, "WARNING - upanic() failed\n");
3078 * Parse cmdline options/arguments and set appropriate global variables.
3079 * If the cmdline is valid, return 0 to caller. Otherwise exit with a status
3084 parse_cmdline(argc, argv, opts)
3090 char cc, *cp, *tok = NULL;
3093 extern char *optarg;
3095 char *memargs[NMEMALLOC];
3097 void parse_memalloc(char *arg);
3098 void parse_delay(char *arg);
3099 void dump_memalloc();
3101 if (*argv[0] == '-') {
3106 if ((Prog = strrchr(argv[0], '/')) == NULL) {
3113 while ((c = getopt(argc, argv, opts)) != EOF) {
3121 for(s=checkmap; s->string != NULL; s++)
3122 if(!strcmp(s->string, optarg))
3124 if (s->string == NULL) {
3126 "%s%s: Illegal -C arg (%s). Must be one of: ",
3127 Prog, TagName, tok);
3129 for (s = checkmap; s->string != NULL; s++)
3130 fprintf(stderr, "%s ", s->string);
3131 fprintf(stderr, "\n");
3137 Data_Fill = doio_pat_fill;
3138 Data_Check = doio_pat_check;
3142 "%s%s: Unrecognised -C arg '%s' %d",
3143 Prog, TagName, s->string, s->value);
3148 case 'd': /* delay between i/o ops */
3149 parse_delay(optarg);
3153 if (Npes > 1 && Nprocs > 1) {
3154 fprintf(stderr, "%s%s: Warning - Program is a multi-pe application - exec option is ignored.\n", Prog, TagName);
3169 Message_Interval = strtol(optarg, &cp, 10);
3170 if (*cp != '\0' || Message_Interval < 0) {
3171 fprintf(stderr, "%s%s: Illegal -m arg (%s): Must be an integer >= 0\n", Prog, TagName, optarg);
3177 case 'M': /* memory allocation types */
3178 nmemargs = string_to_tokens(optarg, memargs, 32, ",");
3179 for(ma=0; ma < nmemargs; ma++) {
3180 parse_memalloc(memargs[ma]);
3182 /*dump_memalloc();*/
3187 sprintf( TagName, "(%.37s)", optarg );
3191 Nprocs = strtol(optarg, &cp, 10);
3192 if (*cp != '\0' || Nprocs < 1) {
3194 "%s%s: Illegal -n arg (%s): Must be integer > 0\n",
3195 Prog, TagName, optarg);
3199 if (Npes > 1 && Nprocs > 1) {
3200 fprintf(stderr, "%s%s: Program has been built as a multi-pe app. -n1 is the only nprocs value allowed\n", Prog, TagName);
3207 Release_Interval = strtol(optarg, &cp, 10);
3208 if (*cp != '\0' || Release_Interval < 0) {
3210 "%s%s: Illegal -r arg (%s): Must be integer >= 0\n",
3211 Prog, TagName, optarg);
3228 if (strcasecmp(optarg, "sync") == 0) {
3229 Validation_Flags = O_SYNC;
3230 } else if (strcasecmp(optarg, "buffered") == 0) {
3231 Validation_Flags = 0;
3232 } else if (strcasecmp(optarg, "direct") == 0) {
3233 Validation_Flags = O_DIRECT;
3235 if (sscanf(optarg, "%i%c", &Validation_Flags, &cc) != 1) {
3236 fprintf(stderr, "%s: Invalid -V argument (%s) - must be a decimal, hex, or octal\n", Prog, optarg);
3237 fprintf(stderr, " number, or one of the following strings: 'sync',\n");
3238 fprintf(stderr, " 'buffered', 'parallel', 'ldraw', or 'raw'\n");
3245 tok = strtok(optarg, ",");
3246 while (tok != NULL) {
3247 for (s = Upanic_Args; s->string != NULL; s++)
3248 if (strcmp(s->string, tok) == 0)
3251 if (s->string == NULL) {
3253 "%s%s: Illegal -U arg (%s). Must be one of: ",
3254 Prog, TagName, tok);
3256 for (s = Upanic_Args; s->string != NULL; s++)
3257 fprintf(stderr, "%s ", s->string);
3259 fprintf(stderr, "\n");
3264 Upanic_Conditions |= s->value;
3265 tok = strtok(NULL, ",");
3283 Data_Fill = doio_pat_fill;
3284 Data_Check = doio_pat_check;
3288 Upanic_Conditions = 0;
3294 Release_Interval = DEF_RELEASE_INTERVAL;
3297 Memalloc[Nmemalloc].memtype = MEM_DATA;
3298 Memalloc[Nmemalloc].flags = 0;
3299 Memalloc[Nmemalloc].name = NULL;
3300 Memalloc[Nmemalloc].space = NULL;
3305 * Initialize input stream
3308 if (argc == optind) {
3311 Infile = argv[optind++];
3314 if (argc != optind) {
3325 * Parse memory allocation types
3329 * T3E-shmem:blksize[:nblks]
3330 * SysV-shmem:shmid:blksize:nblks
3331 * if shmid is "private", use IPC_PRIVATE
3332 * and nblks is not required
3334 * mmap:flags:filename:blksize[:nblks]
3336 * p - private (MAP_PRIVATE)
3337 * a - private, MAP_AUTORESRV
3338 * l - local (MAP_LOCAL)
3339 * s - shared (nblks required)
3342 * f - fixed address (MAP_FIXED)
3343 * A - use an address without MAP_FIXED
3344 * a - autogrow (map once at startup)
3346 * mmap:flags:devzero
3347 * mmap /dev/zero (shared not allowd)
3348 * maps the first 4096 bytes of /dev/zero
3350 * - put a directory at the beginning of the shared
3351 * regions saying what pid has what region.
3355 * nblks worth of directories - 1 int pids
3358 parse_memalloc(char *arg)
3360 char *allocargs[NMEMALLOC];
3364 if(Nmemalloc >= NMEMALLOC) {
3365 doio_fprintf(stderr, "Error - too many memory types (%d).\n",
3370 M = &Memalloc[Nmemalloc];
3372 nalloc = string_to_tokens(arg, allocargs, 32, ":");
3373 if(!strcmp(allocargs[0], "data")) {
3374 M->memtype = MEM_DATA;
3380 if(strchr(allocargs[1], 'p'))
3381 M->flags |= MEMF_MPIN;
3383 } else if(!strcmp(allocargs[0], "mmap")) {
3384 /* mmap:flags:filename[:size] */
3385 M->memtype = MEM_MMAP;
3389 if(strchr(allocargs[1], 'p'))
3390 M->flags |= MEMF_PRIVATE;
3391 if(strchr(allocargs[1], 'a'))
3392 M->flags |= MEMF_AUTORESRV;
3393 if(strchr(allocargs[1], 'l'))
3394 M->flags |= MEMF_LOCAL;
3395 if(strchr(allocargs[1], 's'))
3396 M->flags |= MEMF_SHARED;
3398 if(strchr(allocargs[1], 'f'))
3399 M->flags |= MEMF_FIXADDR;
3400 if(strchr(allocargs[1], 'A'))
3401 M->flags |= MEMF_ADDR;
3402 if(strchr(allocargs[1], 'G'))
3403 M->flags |= MEMF_AUTOGROW;
3405 if(strchr(allocargs[1], 'U'))
3406 M->flags |= MEMF_FILE;
3408 M->flags |= MEMF_PRIVATE;
3412 if(!strcmp(allocargs[2], "devzero")) {
3413 M->name = "/dev/zero";
3415 ((MEMF_PRIVATE|MEMF_LOCAL) == 0))
3416 M->flags |= MEMF_PRIVATE;
3418 M->name = allocargs[2];
3421 M->name = "/dev/zero";
3423 ((MEMF_PRIVATE|MEMF_LOCAL) == 0))
3424 M->flags |= MEMF_PRIVATE;
3428 } else if(!strcmp(allocargs[0], "shmem")) {
3429 /* shmem:shmid:size */
3430 M->memtype = MEM_SHMEM;
3434 M->name = allocargs[1];
3439 sscanf(allocargs[2], "%i", &M->nblks);
3444 if(strchr(allocargs[3], 'p'))
3445 M->flags |= MEMF_MPIN;
3450 doio_fprintf(stderr, "Error - unknown memory type '%s'.\n",
3462 if(Nmemalloc == 0) {
3463 printf("No memory allocation strategies devined\n");
3467 for(ma=0; ma < Nmemalloc; ma++) {
3468 switch(Memalloc[ma].memtype) {
3469 case MEM_DATA: mt = "data"; break;
3470 case MEM_SHMEM: mt = "shmem"; break;
3471 case MEM_MMAP: mt = "mmap"; break;
3472 default: mt = "unknown"; break;
3474 printf("mstrat[%d] = %d %s\n", ma, Memalloc[ma].memtype, mt);
3475 printf("\tflags=%#o name='%s' nblks=%d\n",
3478 Memalloc[ma].nblks);
3483 * -d <op>:<time> - doio inter-operation delay
3484 * currently this permits ONE type of delay between operations.
3488 parse_delay(char *arg)
3490 char *delayargs[NMEMALLOC];
3494 ndelay = string_to_tokens(arg, delayargs, 32, ":");
3496 doio_fprintf(stderr,
3497 "Illegal delay arg (%s). Must be operation:time\n", arg);
3500 for(s=delaymap; s->string != NULL; s++)
3501 if(!strcmp(s->string, delayargs[0]))
3503 if (s->string == NULL) {
3505 "Illegal Delay arg (%s). Must be one of: ", arg);
3507 for (s = delaymap; s->string != NULL; s++)
3508 fprintf(stderr, "%s ", s->string);
3509 fprintf(stderr, "\n");
3515 sscanf(delayargs[1], "%i", &delaytime);
3519 "Warning: extra delay arguments ignored.\n");
3525 * Usage clause - obvious
3533 * Only do this if we are on vpe 0, to avoid seeing it from every
3534 * process in the application.
3537 if (Npes > 1 && Vpe != 0) {
3541 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);
3550 * Only the app running on vpe 0 gets to issue help - this prevents
3551 * everybody in the application from doing this.
3554 if (Npes > 1 && Vpe != 0) {
3559 fprintf(stream, "\n");
3560 fprintf(stream, "\t-a abort - kill all doio processes on data compare\n");
3561 fprintf(stream, "\t errors. Normally only the erroring process exits\n");
3562 fprintf(stream, "\t-C data-pattern-type \n");
3563 fprintf(stream, "\t Available data patterns are:\n");
3564 fprintf(stream, "\t default - repeating pattern\n");
3565 fprintf(stream, "\t-d Operation:Time Inter-operation delay.\n");
3566 fprintf(stream, "\t Operations are:\n");
3567 fprintf(stream, "\t select:time (1 second=1000000)\n");
3568 fprintf(stream, "\t sleep:time (1 second=1)\n");
3569 fprintf(stream, "\t alarm:time (1 second=1)\n");
3570 fprintf(stream, "\t-e Re-exec children before entering the main\n");
3571 fprintf(stream, "\t loop. This is useful for spreading\n");
3572 fprintf(stream, "\t procs around on multi-pe systems.\n");
3573 fprintf(stream, "\t-k Lock file regions during writes using fcntl()\n");
3574 fprintf(stream, "\t-v Verify writes - this is done by doing a buffered\n");
3575 fprintf(stream, "\t read() of the data if file io was done, or\n");
3576 fprintf(stream, "\t an ssread()of the data if sds io was done\n");
3577 fprintf(stream, "\t-M Data buffer allocation method\n");
3578 fprintf(stream, "\t alloc-type[,type]\n");
3579 fprintf(stream, "\t data\n");
3580 fprintf(stream, "\t shmem:shmid:size\n");
3581 fprintf(stream, "\t mmap:flags:filename\n");
3582 fprintf(stream, "\t p - private\n");
3583 fprintf(stream, "\t s - shared (shared file must exist\n"),
3584 fprintf(stream, "\t and have needed length)\n");
3585 fprintf(stream, "\t f - fixed address (not used)\n");
3586 fprintf(stream, "\t a - specify address (not used)\n");
3587 fprintf(stream, "\t U - Unlink file when done\n");
3588 fprintf(stream, "\t The default flag is private\n");
3589 fprintf(stream, "\n");
3590 fprintf(stream, "\t-m message_interval Generate a message every 'message_interval'\n");
3591 fprintf(stream, "\t requests. An interval of 0 suppresses\n");
3592 fprintf(stream, "\t messages. The default is 0.\n");
3593 fprintf(stream, "\t-N tagname Tag name, for Monster.\n");
3594 fprintf(stream, "\t-n nprocs # of processes to start up\n");
3595 fprintf(stream, "\t-r release_interval Release all memory and close\n");
3596 fprintf(stream, "\t files every release_interval operations.\n");
3597 fprintf(stream, "\t By default procs never release memory\n");
3598 fprintf(stream, "\t or close fds unless they have to.\n");
3599 fprintf(stream, "\t-V validation_ftype The type of file descriptor to use for doing data\n");
3600 fprintf(stream, "\t validation. validation_ftype may be an octal,\n");
3601 fprintf(stream, "\t hex, or decimal number representing the open()\n");
3602 fprintf(stream, "\t flags, or may be one of the following strings:\n");
3603 fprintf(stream, "\t 'buffered' - validate using bufferd read\n");
3604 fprintf(stream, "\t 'sync' - validate using O_SYNC read\n");
3605 fprintf(stream, "\t 'direct - validate using O_DIRECT read'\n");
3606 fprintf(stream, "\t By default, 'parallel'\n");
3607 fprintf(stream, "\t is used if the write was done with O_PARALLEL\n");
3608 fprintf(stream, "\t or 'buffered' for all other writes.\n");
3609 fprintf(stream, "\t-w write_log File to log file writes to. The doio_check\n");
3610 fprintf(stream, "\t program can reconstruct datafiles using the\n");
3611 fprintf(stream, "\t write_log, and detect if a file is corrupt\n");
3612 fprintf(stream, "\t after all procs have exited.\n");
3613 fprintf(stream, "\t-U upanic_cond Comma separated list of conditions that will\n");
3614 fprintf(stream, "\t cause a call to upanic(PA_PANIC).\n");
3615 fprintf(stream, "\t 'corruption' -> upanic on bad data comparisons\n");
3616 fprintf(stream, "\t 'iosw' ---> upanic on unexpected async iosw\n");
3617 fprintf(stream, "\t 'rval' ---> upanic on unexpected syscall rvals\n");
3618 fprintf(stream, "\t 'all' ---> all of the above\n");
3619 fprintf(stream, "\n");
3620 fprintf(stream, "\tinfile Input stream - default is stdin - must be a list\n");
3621 fprintf(stream, "\t of io_req structures (see doio.h). Currently\n");
3622 fprintf(stream, "\t only the iogen program generates the proper\n");
3623 fprintf(stream, "\t format\n");