forked from kdave/xfstests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoio.c
3613 lines (3060 loc) · 82.4 KB
/
doio.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2000 Silicon Graphics, Inc.
* All Rights Reserved.
*/
/*
* doio - a general purpose io initiator with system call and
* write logging. See doio.h for the structure which defines
* what doio requests should look like.
*
* programming
* notes:
* -----------
* messages should generally be printed using doio_fprintf().
*
*/
#include "global.h"
#include <stdarg.h>
#include <sys/uio.h> /* for struct iovec (readv)*/
#include <sys/mman.h> /* for mmap(2) */
#include <sys/ipc.h> /* for i/o buffer in shared memory */
#include <sys/shm.h> /* for i/o buffer in shared memory */
#include <sys/wait.h>
#include <sys/time.h> /* for delays */
#include <ctype.h>
struct io_req;
int do_xfsctl(struct io_req *);
#include "doio.h"
#include "pattern.h"
#include "write_log.h"
#include "random_range.h"
#include "string_to_tokens.h"
#ifndef O_SSD
#define O_SSD 0 /* so code compiles on a CRAY2 */
#endif
#define UINT64_T unsigned long long
#ifndef O_PARALLEL
#define O_PARALLEL 0 /* so O_PARALLEL may be used in expressions */
#endif
#define PPID_CHECK_INTERVAL 5 /* check ppid every <-- iterations */
#define MAX_AIO 256 /* maximum number of async I/O ops */
#define MPP_BUMP 0
#define SYSERR strerror(errno)
/*
* getopt() string of supported cmdline arguments.
*/
#define OPTS "aC:d:ehm:n:kr:w:vU:V:M:N:"
#define DEF_RELEASE_INTERVAL 0
/*
* Flags set in parse_cmdline() to indicate which options were selected
* on the cmdline.
*/
int a_opt = 0; /* abort on data compare errors */
int e_opt = 0; /* exec() after fork()'ing */
int C_opt = 0; /* Data Check Type */
int d_opt = 0; /* delay between operations */
int k_opt = 0; /* lock file regions during writes */
int m_opt = 0; /* generate periodic messages */
int n_opt = 0; /* nprocs */
int r_opt = 0; /* resource release interval */
int w_opt = 0; /* file write log file */
int v_opt = 0; /* verify writes if set */
int U_opt = 0; /* upanic() on varios conditions */
int V_opt = 0; /* over-ride default validation fd type */
int M_opt = 0; /* data buffer allocation types */
char TagName[40]; /* name of this doio (see Monster) */
/*
* Misc globals initialized in parse_cmdline()
*/
char *Prog = NULL; /* set up in parse_cmdline() */
int Upanic_Conditions; /* set by args to -U */
int Release_Interval; /* arg to -r */
int Nprocs; /* arg to -n */
char *Write_Log; /* arg to -w */
char *Infile; /* input file (defaults to stdin) */
int *Children; /* pids of child procs */
int Nchildren = 0;
int Nsiblings = 0; /* tfork'ed siblings */
int Execd = 0;
int Message_Interval = 0;
int Npes = 0; /* non-zero if built as an mpp multi-pe app */
int Vpe = -1; /* Virtual pe number if Npes >= 0 */
int Reqno = 1; /* request # - used in some error messages */
int Reqskipcnt = 0; /* count of I/O requests that are skipped */
int Validation_Flags;
char *(*Data_Check)(); /* function to call for data checking */
int (*Data_Fill)(); /* function to call for data filling */
int Nmemalloc = 0; /* number of memory allocation strategies */
int delayop = 0; /* delay between operations - type of delay */
int delaytime = 0; /* delay between operations - how long */
struct wlog_file Wlog;
int active_mmap_rw = 0; /* Indicates that mmapped I/O is occurring. */
/* Used by sigbus_action() in the child doio. */
int havesigint = 0;
#define SKIP_REQ -2 /* skip I/O request */
#define NMEMALLOC 32
#define MEM_DATA 1 /* data space */
#define MEM_SHMEM 2 /* System V shared memory */
#define MEM_T3ESHMEM 3 /* T3E Shared Memory */
#define MEM_MMAP 4 /* mmap(2) */
#define MEMF_PRIVATE 0001
#define MEMF_AUTORESRV 0002
#define MEMF_LOCAL 0004
#define MEMF_SHARED 0010
#define MEMF_FIXADDR 0100
#define MEMF_ADDR 0200
#define MEMF_AUTOGROW 0400
#define MEMF_FILE 01000 /* regular file -- unlink on close */
#define MEMF_MPIN 010000 /* use mpin(2) to lock pages in memory */
struct memalloc {
int memtype;
int flags;
int nblks;
char *name;
void *space; /* memory address of allocated space */
int fd; /* FD open for mmaping */
int size;
} Memalloc[NMEMALLOC];
/*
* Global file descriptors
*/
int Wfd_Append; /* for appending to the write-log */
int Wfd_Random; /* for overlaying write-log entries */
/*
* Structure for maintaining open file test descriptors. Used by
* alloc_fd().
*/
struct fd_cache {
char c_file[MAX_FNAME_LENGTH+1];
int c_oflags;
int c_fd;
long c_rtc;
int c_memalign; /* from xfsctl(XFS_IOC_DIOINFO) */
int c_miniosz;
int c_maxiosz;
void *c_memaddr; /* mmapped address */
int c_memlen; /* length of above region */
};
#define FD_ALLOC_INCR 32 /* allocate this many fd_map structs */
/* at a time */
/*
* Globals for tracking Sds and Core usage
*/
char *Memptr; /* ptr to core buffer space */
int Memsize; /* # bytes pointed to by Memptr */
/* maintained by alloc_mem() */
int Sdsptr; /* sds offset (always 0) */
int Sdssize; /* # bytes of allocated sds space */
/* Maintained by alloc_sds() */
char Host[16];
char Pattern[128];
int Pattern_Length;
/*
* Signal handlers, and related globals
*/
void sigint_handler(); /* Catch SIGINT in parent doio, propagate
* to children, does not die. */
void die_handler(); /* Bad sig in child doios, exit 1. */
void cleanup_handler(); /* Normal kill, exit 0. */
void sigbus_handler(); /* Handle sigbus--check active_mmap_rw to
decide if this should be a normal exit. */
void cb_handler(); /* Posix aio callback handler. */
void noop_handler(); /* Delayop alarm, does nothing. */
char *hms(time_t t);
char *format_rw();
char *format_sds();
char *format_listio();
char *check_file(char *file, int offset, int length, char *pattern,
int pattern_length, int patshift, int fsa);
int doio_fprintf(FILE *stream, char *format, ...);
void doio_upanic(int mask);
void doio();
void help(FILE *stream);
void doio_delay();
int alloc_fd( char *, int );
int alloc_mem( int );
int do_read( struct io_req * );
int do_write( struct io_req * );
int do_rw( struct io_req * );
int do_sync( struct io_req * );
int usage( FILE * );
int aio_unregister( int );
int parse_cmdline( int, char **, char * );
int lock_file_region( char *, int, int, int, int );
struct fd_cache *alloc_fdcache(char *, int);
int aio_register( int, int, int );
#ifndef linux
int aio_wait(int);
#endif
/*
* Upanic conditions, and a map from symbolics to values
*/
#define U_CORRUPTION 0001 /* upanic on data corruption */
#define U_IOSW 0002 /* upanic on bad iosw */
#define U_RVAL 0004 /* upanic on bad rval */
#define U_ALL (U_CORRUPTION | U_IOSW | U_RVAL)
/*
* Name-To-Value map
* Used to map cmdline arguments to values
*/
struct smap {
char *string;
int value;
};
struct smap Upanic_Args[] = {
{ "corruption", U_CORRUPTION },
{ "iosw", U_IOSW },
{ "rval", U_RVAL },
{ "all", U_ALL },
{ NULL, 0 }
};
struct aio_info {
int busy;
int id;
int fd;
int strategy;
volatile int done;
int sig;
int signalled;
struct sigaction osa;
};
struct aio_info Aio_Info[MAX_AIO];
struct aio_info *aio_slot();
int aio_done( struct aio_info * );
/* -C data-fill/check type */
#define C_DEFAULT 1
struct smap checkmap[] = {
{ "default", C_DEFAULT },
{ NULL, 0 },
};
/* -d option delay types */
#define DELAY_SELECT 1
#define DELAY_SLEEP 2
#define DELAY_SGINAP 3
#define DELAY_ALARM 4
#define DELAY_ITIMER 5 /* POSIX timer */
struct smap delaymap[] = {
{ "select", DELAY_SELECT },
{ "sleep", DELAY_SLEEP },
{ "alarm", DELAY_ALARM },
{ NULL, 0 },
};
/******
*
* strerror() does similar actions.
char *
syserrno(int err)
{
static char sys_errno[10];
sprintf(sys_errno, "%d", errno);
return(sys_errno);
}
******/
int
main(argc, argv)
int argc;
char **argv;
{
int i, pid, stat, ex_stat;
struct sigaction sa;
sigset_t block_mask, old_mask;
umask(0); /* force new file modes to known values */
TagName[0] = '\0';
parse_cmdline(argc, argv, OPTS);
random_range_seed(getpid()); /* initialize random number generator */
/*
* If this is a re-exec of doio, jump directly into the doio function.
*/
if (Execd) {
doio();
exit(E_SETUP);
}
/*
* Stop on all but a few signals...
*/
sigemptyset(&sa.sa_mask);
sa.sa_handler = sigint_handler;
sa.sa_flags = SA_RESETHAND; /* sigint is ignored after the */
/* first time */
for (i = 1; i <= NSIG; i++) {
switch(i) {
#ifdef SIGRECOVERY
case SIGRECOVERY:
break;
#endif
#ifdef SIGCKPT
case SIGCKPT:
#endif
#ifdef SIGRESTART
case SIGRESTART:
#endif
case SIGTSTP:
case SIGSTOP:
case SIGCONT:
case SIGCHLD:
case SIGBUS:
case SIGSEGV:
case SIGQUIT:
break;
default:
sigaction(i, &sa, NULL);
}
}
/*
* If we're logging write operations, make a dummy call to wlog_open
* to initialize the write history file. This call must be done in
* the parent, to ensure that the history file exists and/or has
* been truncated before any children attempt to open it, as the doio
* children are not allowed to truncate the file.
*/
if (w_opt) {
strcpy(Wlog.w_file, Write_Log);
if (wlog_open(&Wlog, 1, 0666) < 0) {
doio_fprintf(stderr,
"Could not create/truncate write log %s\n",
Write_Log);
exit(2);
}
wlog_close(&Wlog);
}
/*
* Malloc space for the children pid array. Initialize all entries
* to -1.
*/
Children = (int *)malloc(sizeof(int) * Nprocs);
for (i = 0; i < Nprocs; i++) {
Children[i] = -1;
}
sigemptyset(&block_mask);
sigaddset(&block_mask, SIGCHLD);
sigprocmask(SIG_BLOCK, &block_mask, &old_mask);
/*
* Fork Nprocs. This [parent] process is a watchdog, to notify the
* invoker of procs which exit abnormally, and to make sure that all
* child procs get cleaned up. If the -e option was used, we will also
* re-exec. This is mostly for unicos/mk on mpp's, to ensure that not
* all of the doio's don't end up in the same pe.
*
* Note - if Nprocs is 1, or this doio is a multi-pe app (Npes > 1),
* jump directly to doio(). multi-pe apps can't fork(), and there is
* no reason to fork() for 1 proc.
*/
if (Nprocs == 1 || Npes > 1) {
doio();
exit(0);
} else {
for (i = 0; i < Nprocs; i++) {
if ((pid = fork()) == -1) {
doio_fprintf(stderr,
"(parent) Could not fork %d children: %s (%d)\n",
i+1, SYSERR, errno);
exit(E_SETUP);
}
Children[Nchildren] = pid;
Nchildren++;
if (pid == 0) {
if (e_opt) {
char *exec_path;
exec_path = argv[0];
argv[0] = (char *)malloc(strlen(exec_path + 1));
sprintf(argv[0], "-%s", exec_path);
execvp(exec_path, argv);
doio_fprintf(stderr,
"(parent) Could not execvp %s: %s (%d)\n",
exec_path, SYSERR, errno);
exit(E_SETUP);
} else {
doio();
exit(E_SETUP);
}
}
}
/*
* Parent spins on wait(), until all children exit.
*/
ex_stat = E_NORMAL;
while (Nprocs) {
if ((pid = wait(&stat)) == -1) {
if (errno == EINTR)
continue;
}
for (i = 0; i < Nchildren; i++)
if (Children[i] == pid)
Children[i] = -1;
Nprocs--;
if (WIFEXITED(stat)) {
switch (WEXITSTATUS(stat)) {
case E_NORMAL:
/* noop */
break;
case E_INTERNAL:
doio_fprintf(stderr,
"(parent) pid %d exited because of an internal error\n",
pid);
ex_stat |= E_INTERNAL;
break;
case E_SETUP:
doio_fprintf(stderr,
"(parent) pid %d exited because of a setup error\n",
pid);
ex_stat |= E_SETUP;
break;
case E_COMPARE:
doio_fprintf(stderr,
"(parent) pid %d exited because of data compare errors\n",
pid);
ex_stat |= E_COMPARE;
if (a_opt)
kill(0, SIGINT);
break;
case E_USAGE:
doio_fprintf(stderr,
"(parent) pid %d exited because of a usage error\n",
pid);
ex_stat |= E_USAGE;
break;
default:
doio_fprintf(stderr,
"(parent) pid %d exited with unknown status %d\n",
pid, WEXITSTATUS(stat));
ex_stat |= E_INTERNAL;
break;
}
} else if (WIFSIGNALED(stat) && WTERMSIG(stat) != SIGINT) {
doio_fprintf(stderr,
"(parent) pid %d terminated by signal %d\n",
pid, WTERMSIG(stat));
ex_stat |= E_SIGNAL;
}
fflush(NULL);
}
}
exit(ex_stat);
} /* main */
/*
* main doio function. Each doio child starts here, and never returns.
*/
void
doio()
{
int rval, i, infd, nbytes;
char *cp;
struct io_req ioreq;
struct sigaction sa, def_action, ignore_action, exit_action;
struct sigaction sigbus_action;
Memsize = Sdssize = 0;
/*
* Initialize the Pattern - write-type syscalls will replace Pattern[1]
* with the pattern passed in the request. Make sure that
* strlen(Pattern) is not mod 16 so that out of order words will be
* detected.
*/
gethostname(Host, sizeof(Host));
if ((cp = strchr(Host, '.')) != NULL)
*cp = '\0';
Pattern_Length = sprintf(Pattern, "-:%d:%s:%s*", (int)getpid(), Host, Prog);
if (!(Pattern_Length % 16)) {
Pattern_Length = sprintf(Pattern, "-:%d:%s:%s**",
(int)getpid(), Host, Prog);
}
/*
* Open a couple of descriptors for the write-log file. One descriptor
* is for appending, one for random access. Write logging is done for
* file corruption detection. The program doio_check is capable of
* doing corruption detection based on a doio write-log.
*/
if (w_opt) {
strcpy(Wlog.w_file, Write_Log);
if (wlog_open(&Wlog, 0, 0666) == -1) {
doio_fprintf(stderr,
"Could not open write log file (%s): wlog_open() failed\n",
Write_Log);
exit(E_SETUP);
}
}
/*
* Open the input stream - either a file or stdin
*/
if (Infile == NULL) {
infd = 0;
} else {
if ((infd = open(Infile, O_RDWR)) == -1) {
doio_fprintf(stderr,
"Could not open input file (%s): %s (%d)\n",
Infile, SYSERR, errno);
exit(E_SETUP);
}
}
/*
* Define a set of signals that should never be masked. Receipt of
* these signals generally indicates a programming error, and we want
* a corefile at the point of error. We put SIGQUIT in this list so
* that ^\ will force a user core dump.
*
* Note: the handler for these should be SIG_DFL, all of them
* produce a corefile as the default action.
*/
ignore_action.sa_handler = SIG_IGN;
ignore_action.sa_flags = 0;
sigemptyset(&ignore_action.sa_mask);
def_action.sa_handler = SIG_DFL;
def_action.sa_flags = 0;
sigemptyset(&def_action.sa_mask);
exit_action.sa_handler = cleanup_handler;
exit_action.sa_flags = 0;
sigemptyset(&exit_action.sa_mask);
sa.sa_handler = die_handler;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
sigbus_action.sa_handler = sigbus_handler;
sigbus_action.sa_flags = 0;
sigemptyset(&sigbus_action.sa_mask);
for (i = 1; i <= NSIG; i++) {
switch(i) {
/* Signals to terminate program on */
case SIGINT:
sigaction(i, &exit_action, NULL);
break;
/* This depends on active_mmap_rw */
case SIGBUS:
sigaction(i, &sigbus_action, NULL);
break;
/* Signals to Ignore... */
case SIGSTOP:
case SIGCONT:
#ifdef SIGRECOVERY
case SIGRECOVERY:
#endif
sigaction(i, &ignore_action, NULL);
break;
/* Signals to trap & report & die */
/*case SIGTRAP:*/
/*case SIGABRT:*/
#ifdef SIGERR /* cray only signals */
case SIGERR:
case SIGBUFIO:
case SIGINFO:
#endif
/*case SIGFPE:*/
case SIGURG:
case SIGHUP:
case SIGTERM:
case SIGPIPE:
case SIGIO:
case SIGUSR1:
case SIGUSR2:
sigaction(i, &sa, NULL);
break;
/* Default Action for all other signals */
default:
sigaction(i, &def_action, NULL);
break;
}
}
/*
* Main loop - each doio proc does this until the read returns eof (0).
* Call the appropriate io function based on the request type.
*/
while ((nbytes = read(infd, (char *)&ioreq, sizeof(ioreq)))) {
/*
* Periodically check our ppid. If it is 1, the child exits to
* help clean up in the case that the main doio process was
* killed.
*/
if (Reqno && ((Reqno % PPID_CHECK_INTERVAL) == 0)) {
if (getppid() == 1) {
doio_fprintf(stderr,
"Parent doio process has exited\n");
alloc_mem(-1);
exit(E_SETUP);
}
}
if (nbytes == -1) {
doio_fprintf(stderr,
"read of %d bytes from input failed: %s (%d)\n",
sizeof(ioreq), SYSERR, errno);
alloc_mem(-1);
exit(E_SETUP);
}
if (nbytes != sizeof(ioreq)) {
doio_fprintf(stderr,
"read wrong # bytes from input stream, expected %d, got %d\n",
sizeof(ioreq), nbytes);
alloc_mem(-1);
exit(E_SETUP);
}
if (ioreq.r_magic != DOIO_MAGIC) {
doio_fprintf(stderr,
"got a bad magic # from input stream. Expected 0%o, got 0%o\n",
DOIO_MAGIC, ioreq.r_magic);
alloc_mem(-1);
exit(E_SETUP);
}
/*
* If we're on a Release_Interval multiple, relase all ssd and
* core space, and close all fd's in Fd_Map[].
*/
if (Reqno && Release_Interval && ! (Reqno%Release_Interval)) {
if (Memsize) {
#ifdef NOTDEF
sbrk(-1 * Memsize);
#else
alloc_mem(-1);
#endif
}
alloc_fd(NULL, 0);
}
switch (ioreq.r_type) {
case READ:
case READA:
rval = do_read(&ioreq);
break;
case WRITE:
case WRITEA:
rval = do_write(&ioreq);
break;
case READV:
case AREAD:
case PREAD:
case LREAD:
case LREADA:
case LSREAD:
case LSREADA:
case WRITEV:
case AWRITE:
case PWRITE:
case MMAPR:
case MMAPW:
case LWRITE:
case LWRITEA:
case LSWRITE:
case LSWRITEA:
case LEREAD:
case LEREADA:
case LEWRITE:
case LEWRITEA:
rval = do_rw(&ioreq);
break;
case RESVSP:
case UNRESVSP:
rval = do_xfsctl(&ioreq);
break;
case FSYNC2:
case FDATASYNC:
rval = do_sync(&ioreq);
break;
default:
doio_fprintf(stderr,
"Don't know how to handle io request type %d\n",
ioreq.r_type);
alloc_mem(-1);
exit(E_SETUP);
}
if (rval == SKIP_REQ){
Reqskipcnt++;
}
else if (rval != 0) {
alloc_mem(-1);
doio_fprintf(stderr,
"doio(): operation %d returned != 0\n",
ioreq.r_type);
exit(E_SETUP);
}
if (Message_Interval && Reqno % Message_Interval == 0) {
doio_fprintf(stderr, "Info: %d requests done (%d skipped) by this process\n", Reqno, Reqskipcnt);
}
Reqno++;
if(delayop != 0)
doio_delay();
}
/*
* Child exits normally
*/
alloc_mem(-1);
exit(E_NORMAL);
} /* doio */
void
doio_delay()
{
struct timeval tv_delay;
struct sigaction sa_al, sa_old;
sigset_t al_mask;
switch(delayop) {
case DELAY_SELECT:
tv_delay.tv_sec = delaytime / 1000000;
tv_delay.tv_usec = delaytime % 1000000;
/*doio_fprintf(stdout, "delay_select: %d %d\n",
tv_delay.tv_sec, tv_delay.tv_usec);*/
select(0, NULL, NULL, NULL, &tv_delay);
break;
case DELAY_SLEEP:
sleep(delaytime);
break;
case DELAY_ALARM:
sa_al.sa_flags = 0;
sa_al.sa_handler = noop_handler;
sigemptyset(&sa_al.sa_mask);
sigaction(SIGALRM, &sa_al, &sa_old);
sigemptyset(&al_mask);
alarm(delaytime);
sigsuspend(&al_mask);
sigaction(SIGALRM, &sa_old, 0);
break;
}
}
/*
* Format IO requests, returning a pointer to the formatted text.
*
* format_strat - formats the async i/o completion strategy
* format_rw - formats a read[a]/write[a] request
* format_sds - formats a ssread/sswrite request
* format_listio- formats a listio request
*
* ioreq is the doio io request structure.
*/
struct smap sysnames[] = {
{ "READ", READ },
{ "WRITE", WRITE },
{ "READA", READA },
{ "WRITEA", WRITEA },
{ "SSREAD", SSREAD },
{ "SSWRITE", SSWRITE },
{ "LISTIO", LISTIO },
{ "LREAD", LREAD },
{ "LREADA", LREADA },
{ "LWRITE", LWRITE },
{ "LWRITEA", LWRITEA },
{ "LSREAD", LSREAD },
{ "LSREADA", LSREADA },
{ "LSWRITE", LSWRITE },
{ "LSWRITEA", LSWRITEA },
/* Irix System Calls */
{ "PREAD", PREAD },
{ "PWRITE", PWRITE },
{ "AREAD", AREAD },
{ "AWRITE", AWRITE },
{ "LLREAD", LLREAD },
{ "LLAREAD", LLAREAD },
{ "LLWRITE", LLWRITE },
{ "LLAWRITE", LLAWRITE },
{ "RESVSP", RESVSP },
{ "UNRESVSP", UNRESVSP },
/* Irix and Linux System Calls */
{ "READV", READV },
{ "WRITEV", WRITEV },
{ "MMAPR", MMAPR },
{ "MMAPW", MMAPW },
{ "FSYNC2", FSYNC2 },
{ "FDATASYNC", FDATASYNC },
{ "unknown", -1 },
};
struct smap aionames[] = {
{ "poll", A_POLL },
{ "signal", A_SIGNAL },
{ "recall", A_RECALL },
{ "recalla", A_RECALLA },
{ "recalls", A_RECALLS },
{ "suspend", A_SUSPEND },
{ "callback", A_CALLBACK },
{ "synch", 0 },
{ "unknown", -1 },
};
char *
format_oflags(int oflags)
{
char flags[255];
flags[0]='\0';
switch(oflags & 03) {
case O_RDONLY: strcat(flags,"O_RDONLY,"); break;
case O_WRONLY: strcat(flags,"O_WRONLY,"); break;
case O_RDWR: strcat(flags,"O_RDWR,"); break;
default: strcat(flags,"O_weird"); break;
}
if(oflags & O_EXCL)
strcat(flags,"O_EXCL,");
if(oflags & O_SYNC)
strcat(flags,"O_SYNC,");
if(oflags & O_DIRECT)
strcat(flags,"O_DIRECT,");
return(strdup(flags));
}
char *
format_strat(int strategy)
{
char msg[64];
char *aio_strat;
switch (strategy) {
case A_POLL: aio_strat = "POLL"; break;
case A_SIGNAL: aio_strat = "SIGNAL"; break;
case A_RECALL: aio_strat = "RECALL"; break;
case A_RECALLA: aio_strat = "RECALLA"; break;
case A_RECALLS: aio_strat = "RECALLS"; break;
case A_SUSPEND: aio_strat = "SUSPEND"; break;
case A_CALLBACK: aio_strat = "CALLBACK"; break;
case 0: aio_strat = "<zero>"; break;
default:
sprintf(msg, "<error:%#o>", strategy);
aio_strat = strdup(msg);
break;
}
return(aio_strat);
}
char *
format_rw(
struct io_req *ioreq,
int fd,
void *buffer,
int signo,
char *pattern,
void *iosw
)
{
static char *errbuf=NULL;
char *aio_strat, *cp;
struct read_req *readp = &ioreq->r_data.read;
struct write_req *writep = &ioreq->r_data.write;
struct read_req *readap = &ioreq->r_data.read;
struct write_req *writeap = &ioreq->r_data.write;
if(errbuf == NULL)
errbuf = (char *)malloc(32768);
cp = errbuf;
cp += sprintf(cp, "Request number %d\n", Reqno);
switch (ioreq->r_type) {
case READ:
cp += sprintf(cp, "syscall: read(%d, %#lo, %d)\n",
fd, (unsigned long) buffer, readp->r_nbytes);
cp += sprintf(cp, " fd %d is file %s - open flags are %#o\n",
fd, readp->r_file, readp->r_oflags);
cp += sprintf(cp, " read done at file offset %d\n",
readp->r_offset);
break;
case WRITE:
cp += sprintf(cp, "syscall: write(%d, %#lo, %d)\n",
fd, (unsigned long) buffer, writep->r_nbytes);
cp += sprintf(cp, " fd %d is file %s - open flags are %#o\n",
fd, writep->r_file, writep->r_oflags);
cp += sprintf(cp, " write done at file offset %d - pattern is %s\n",
writep->r_offset, pattern);
break;
case READA: