1f08c3bdfSopenharmony_ci/*
2f08c3bdfSopenharmony_ci * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
3f08c3bdfSopenharmony_ci *
4f08c3bdfSopenharmony_ci * This program is free software; you can redistribute it and/or modify it
5f08c3bdfSopenharmony_ci * under the terms of version 2 of the GNU General Public License as
6f08c3bdfSopenharmony_ci * published by the Free Software Foundation.
7f08c3bdfSopenharmony_ci *
8f08c3bdfSopenharmony_ci * This program is distributed in the hope that it would be useful, but
9f08c3bdfSopenharmony_ci * WITHOUT ANY WARRANTY; without even the implied warranty of
10f08c3bdfSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11f08c3bdfSopenharmony_ci *
12f08c3bdfSopenharmony_ci * Further, this software is distributed without any warranty that it is
13f08c3bdfSopenharmony_ci * free of the rightful claim of any third person regarding infringement
14f08c3bdfSopenharmony_ci * or the like.  Any license provided herein, whether implied or
15f08c3bdfSopenharmony_ci * otherwise, applies only to this software file.  Patent licenses, if
16f08c3bdfSopenharmony_ci * any, provided herein do not apply to combinations of this program with
17f08c3bdfSopenharmony_ci * other software, or any other product whatsoever.
18f08c3bdfSopenharmony_ci *
19f08c3bdfSopenharmony_ci * You should have received a copy of the GNU General Public License along
20f08c3bdfSopenharmony_ci * with this program; if not, write the Free Software Foundation, Inc.,
21f08c3bdfSopenharmony_ci * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22f08c3bdfSopenharmony_ci *
23f08c3bdfSopenharmony_ci * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24f08c3bdfSopenharmony_ci * Mountain View, CA  94043, or:
25f08c3bdfSopenharmony_ci *
26f08c3bdfSopenharmony_ci * http://www.sgi.com
27f08c3bdfSopenharmony_ci *
28f08c3bdfSopenharmony_ci * For further information regarding this notice, see:
29f08c3bdfSopenharmony_ci *
30f08c3bdfSopenharmony_ci * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
31f08c3bdfSopenharmony_ci */
32f08c3bdfSopenharmony_ci/*
33f08c3bdfSopenharmony_ci * iogen - a tool for generating file/sds io for a doio process
34f08c3bdfSopenharmony_ci */
35f08c3bdfSopenharmony_ci
36f08c3bdfSopenharmony_ci#include <stdio.h>
37f08c3bdfSopenharmony_ci#include <stdlib.h>
38f08c3bdfSopenharmony_ci#include <unistd.h>
39f08c3bdfSopenharmony_ci#include <signal.h>
40f08c3bdfSopenharmony_ci#include <fcntl.h>
41f08c3bdfSopenharmony_ci#include <errno.h>
42f08c3bdfSopenharmony_ci#include <string.h>
43f08c3bdfSopenharmony_ci#include <signal.h>
44f08c3bdfSopenharmony_ci#include <time.h>
45f08c3bdfSopenharmony_ci#include <sys/param.h>
46f08c3bdfSopenharmony_ci#include <sys/types.h>
47f08c3bdfSopenharmony_ci#include <sys/time.h>
48f08c3bdfSopenharmony_ci#include <sys/stat.h>
49f08c3bdfSopenharmony_ci#include <sys/sysmacros.h>
50f08c3bdfSopenharmony_ci#ifdef CRAY
51f08c3bdfSopenharmony_ci#include <sys/file.h>
52f08c3bdfSopenharmony_ci#include <sys/iosw.h>
53f08c3bdfSopenharmony_ci#include <sys/listio.h>
54f08c3bdfSopenharmony_ci#endif
55f08c3bdfSopenharmony_ci#ifdef sgi
56f08c3bdfSopenharmony_ci#include <sys/statvfs.h>
57f08c3bdfSopenharmony_ci#include <sys/fs/xfs_itable.h>
58f08c3bdfSopenharmony_ci#endif
59f08c3bdfSopenharmony_ci
60f08c3bdfSopenharmony_ci#ifdef CRAY
61f08c3bdfSopenharmony_ci#include "libkern.h"
62f08c3bdfSopenharmony_ci#endif
63f08c3bdfSopenharmony_ci#include "doio.h"
64f08c3bdfSopenharmony_ci#include "bytes_by_prefix.h"
65f08c3bdfSopenharmony_ci#include "string_to_tokens.h"
66f08c3bdfSopenharmony_ci#include "open_flags.h"
67f08c3bdfSopenharmony_ci#include "random_range.h"
68f08c3bdfSopenharmony_ci
69f08c3bdfSopenharmony_ci#ifndef PATH_MAX
70f08c3bdfSopenharmony_ci#define	PATH_MAX 512		/* ??? */
71f08c3bdfSopenharmony_ci#endif
72f08c3bdfSopenharmony_ci
73f08c3bdfSopenharmony_ci#ifndef BSIZE
74f08c3bdfSopenharmony_ci#ifdef linux
75f08c3bdfSopenharmony_ci#define BSIZE DEV_BSIZE
76f08c3bdfSopenharmony_ci#else
77f08c3bdfSopenharmony_ci#define BSIZE 512
78f08c3bdfSopenharmony_ci#endif
79f08c3bdfSopenharmony_ci#endif
80f08c3bdfSopenharmony_ci
81f08c3bdfSopenharmony_ci#define RAW_IO(_flags_)	((_flags_) & (O_RAW | O_SSD))
82f08c3bdfSopenharmony_ci
83f08c3bdfSopenharmony_ci#ifndef __linux__
84f08c3bdfSopenharmony_ciextern char *sys_errlist[];
85f08c3bdfSopenharmony_ci#endif
86f08c3bdfSopenharmony_ci#define SYSERR	strerror(errno)
87f08c3bdfSopenharmony_ci
88f08c3bdfSopenharmony_ci/*
89f08c3bdfSopenharmony_ci * Structure for retaining test file information
90f08c3bdfSopenharmony_ci */
91f08c3bdfSopenharmony_ci
92f08c3bdfSopenharmony_cistruct file_info {
93f08c3bdfSopenharmony_ci	char f_path[MAX_FNAME_LENGTH + 1];	/* file name (full path)    */
94f08c3bdfSopenharmony_ci	int f_length;		/* length in bytes                      */
95f08c3bdfSopenharmony_ci	int f_iou;		/* file iounit                          */
96f08c3bdfSopenharmony_ci	int f_riou;		/* file raw iounit (for O_RAW/O_SSD)    */
97f08c3bdfSopenharmony_ci	int f_dalign;		/* direct I/O alignment                 */
98f08c3bdfSopenharmony_ci	int f_nextoff;		/* offset of end of last io operation   */
99f08c3bdfSopenharmony_ci	int f_type;		/* file type S_IFREG, etc...            */
100f08c3bdfSopenharmony_ci	int f_lastoffset;	/* offset of last io operation          */
101f08c3bdfSopenharmony_ci	int f_lastlength;	/* length of last io operation          */
102f08c3bdfSopenharmony_ci};
103f08c3bdfSopenharmony_ci
104f08c3bdfSopenharmony_ci/*
105f08c3bdfSopenharmony_ci * Simple structure for associating strings with values - useful for converting
106f08c3bdfSopenharmony_ci * cmdline args to internal values, as well as printing internal values in
107f08c3bdfSopenharmony_ci * a human readable form.
108f08c3bdfSopenharmony_ci */
109f08c3bdfSopenharmony_ci
110f08c3bdfSopenharmony_cistruct strmap {
111f08c3bdfSopenharmony_ci	char *m_string;
112f08c3bdfSopenharmony_ci	int m_value;
113f08c3bdfSopenharmony_ci	int m_flags;
114f08c3bdfSopenharmony_ci};
115f08c3bdfSopenharmony_ci
116f08c3bdfSopenharmony_civoid startup_info(FILE * stream, int seed);
117f08c3bdfSopenharmony_ciint init_output(void);
118f08c3bdfSopenharmony_ciint form_iorequest(struct io_req *req);
119f08c3bdfSopenharmony_ciint get_file_info(struct file_info *rec);
120f08c3bdfSopenharmony_ciint create_file(char *path, int nbytes);
121f08c3bdfSopenharmony_ciint str_to_value(struct strmap *map, char *str);
122f08c3bdfSopenharmony_cistruct strmap *str_lookup(struct strmap *map, char *str);
123f08c3bdfSopenharmony_cichar *value_to_string(struct strmap *map, int val);
124f08c3bdfSopenharmony_ciint parse_cmdline(int argc, char **argv, char *opts);
125f08c3bdfSopenharmony_ciint help(FILE * stream);
126f08c3bdfSopenharmony_ciint usage(FILE * stream);
127f08c3bdfSopenharmony_ci
128f08c3bdfSopenharmony_ci/*
129f08c3bdfSopenharmony_ci * Declare cmdline option flags/variables initialized in parse_cmdline()
130f08c3bdfSopenharmony_ci */
131f08c3bdfSopenharmony_ci
132f08c3bdfSopenharmony_ci#define OPTS	"a:dhf:i:L:m:op:qr:s:t:T:O:N:"
133f08c3bdfSopenharmony_ci
134f08c3bdfSopenharmony_ciint a_opt = 0;			/* async io comp. types supplied            */
135f08c3bdfSopenharmony_ciint o_opt = 0;			/* form overlapping requests                */
136f08c3bdfSopenharmony_ciint f_opt = 0;			/* test flags                               */
137f08c3bdfSopenharmony_ciint i_opt = 0;			/* iterations - 0 implies infinite          */
138f08c3bdfSopenharmony_ciint L_opt = 0;			/* listio min-max nstrides & nents          */
139f08c3bdfSopenharmony_ciint m_opt = 0;			/* offset mode                              */
140f08c3bdfSopenharmony_ciint O_opt = 0;			/* file creation Open flags                 */
141f08c3bdfSopenharmony_ciint p_opt = 0;			/* output pipe - default is stdout          */
142f08c3bdfSopenharmony_ciint r_opt = 0;			/* specify raw io multiple instead of       */
143f08c3bdfSopenharmony_ci				/* getting it from the mounted on device.   */
144f08c3bdfSopenharmony_ci				/* Only applies to regular files.           */
145f08c3bdfSopenharmony_ciint s_opt = 0;			/* syscalls                                 */
146f08c3bdfSopenharmony_ciint t_opt = 0;			/* min transfer size (bytes)                */
147f08c3bdfSopenharmony_ciint T_opt = 0;			/* max transfer size (bytes)                */
148f08c3bdfSopenharmony_ciint q_opt = 0;			/* quiet operation on startup               */
149f08c3bdfSopenharmony_cichar TagName[40];		/* name of this iogen (see Monster)         */
150f08c3bdfSopenharmony_cistruct strmap *Offset_Mode;	/* M_SEQUENTIAL, M_RANDOM, etc.             */
151f08c3bdfSopenharmony_ciint Iterations;			/* # requests to generate (0 --> infinite)  */
152f08c3bdfSopenharmony_ciint Time_Mode = 0;		/* non-zero if Iterations is in seconds     */
153f08c3bdfSopenharmony_ci				/* (ie. -i arg was suffixed with 's')       */
154f08c3bdfSopenharmony_cichar *Outpipe;			/* Pipe to write output to if p_opt         */
155f08c3bdfSopenharmony_ciint Mintrans;			/* min io transfer size                     */
156f08c3bdfSopenharmony_ciint Maxtrans;			/* max io transfer size                     */
157f08c3bdfSopenharmony_ciint Rawmult;			/* raw/ssd io multiple (from -r)            */
158f08c3bdfSopenharmony_ciint Minstrides;			/* min # of listio strides per request      */
159f08c3bdfSopenharmony_ciint Maxstrides;			/* max # of listio strides per request      */
160f08c3bdfSopenharmony_ciint Oflags;			/* open(2) flags for creating files         */
161f08c3bdfSopenharmony_ciint Ocbits;			/* open(2) cbits for creating files         */
162f08c3bdfSopenharmony_ciint Ocblks;			/* open(2) cblks for creating files         */
163f08c3bdfSopenharmony_ciint Orealtime = 0;		/* flag set for -O REALTIME                 */
164f08c3bdfSopenharmony_ciint Oextsize = 0;		/* real-time extent size                    */
165f08c3bdfSopenharmony_ciint Oreserve = 1;		/* flag for -O [no]reserve                  */
166f08c3bdfSopenharmony_ciint Oallocate = 0;		/* flag for -O allocate                     */
167f08c3bdfSopenharmony_ciint Owrite = 1;			/* flag for -O nowrite                      */
168f08c3bdfSopenharmony_ci
169f08c3bdfSopenharmony_ciint Nfiles = 0;			/* # files on cmdline                       */
170f08c3bdfSopenharmony_cistruct file_info *File_List;	/* info about each file                     */
171f08c3bdfSopenharmony_ciint Nflags = 0;			/* # flags on cmdline                       */
172f08c3bdfSopenharmony_cistruct strmap *Flag_List[128];	/* flags selected from cmdline              */
173f08c3bdfSopenharmony_ciint Nsyscalls = 0;		/* # syscalls on cmdline                    */
174f08c3bdfSopenharmony_cistruct strmap *Syscall_List[128];	/* syscalls selected on cmdline          */
175f08c3bdfSopenharmony_ciint Fileio = 0;			/* flag indicating that a file              */
176f08c3bdfSopenharmony_ci				/* io syscall has been chosen.              */
177f08c3bdfSopenharmony_ciint Naio_Strat_Types = 0;	/* # async io completion types              */
178f08c3bdfSopenharmony_cistruct strmap *Aio_Strat_List[128];	/* Async io completion types           */
179f08c3bdfSopenharmony_ci
180f08c3bdfSopenharmony_ci/*
181f08c3bdfSopenharmony_ci * Map async io completion modes (-a args) names to values.  Macros are
182f08c3bdfSopenharmony_ci * defined in doio.h.
183f08c3bdfSopenharmony_ci */
184f08c3bdfSopenharmony_ci
185f08c3bdfSopenharmony_cistruct strmap Aio_Strat_Map[] = {
186f08c3bdfSopenharmony_ci#ifndef linux
187f08c3bdfSopenharmony_ci	{"poll", A_POLL},
188f08c3bdfSopenharmony_ci	{"signal", A_SIGNAL},
189f08c3bdfSopenharmony_ci#else
190f08c3bdfSopenharmony_ci	{"none", 0},
191f08c3bdfSopenharmony_ci#endif /* !linux */
192f08c3bdfSopenharmony_ci#ifdef CRAY
193f08c3bdfSopenharmony_ci#if _UMK || RELEASE_LEVEL >= 8000
194f08c3bdfSopenharmony_ci	{"recall", A_RECALL},
195f08c3bdfSopenharmony_ci#endif
196f08c3bdfSopenharmony_ci
197f08c3bdfSopenharmony_ci#ifdef RECALL_SIZEOF
198f08c3bdfSopenharmony_ci	{"recalla", A_RECALLA},
199f08c3bdfSopenharmony_ci#endif
200f08c3bdfSopenharmony_ci	{"recalls", A_RECALLS},
201f08c3bdfSopenharmony_ci#endif /* CRAY */
202f08c3bdfSopenharmony_ci
203f08c3bdfSopenharmony_ci#ifdef sgi
204f08c3bdfSopenharmony_ci	{"suspend", A_SUSPEND},
205f08c3bdfSopenharmony_ci	{"callback", A_CALLBACK},
206f08c3bdfSopenharmony_ci#endif
207f08c3bdfSopenharmony_ci	{NULL, -1}
208f08c3bdfSopenharmony_ci};
209f08c3bdfSopenharmony_ci
210f08c3bdfSopenharmony_ci/*
211f08c3bdfSopenharmony_ci * Offset_Mode #defines
212f08c3bdfSopenharmony_ci */
213f08c3bdfSopenharmony_ci
214f08c3bdfSopenharmony_ci#define M_RANDOM    	1
215f08c3bdfSopenharmony_ci#define M_SEQUENTIAL	2
216f08c3bdfSopenharmony_ci#define M_REVERSE   	3
217f08c3bdfSopenharmony_ci
218f08c3bdfSopenharmony_ci/*
219f08c3bdfSopenharmony_ci * Map offset mode (-m args) names to values
220f08c3bdfSopenharmony_ci */
221f08c3bdfSopenharmony_ci
222f08c3bdfSopenharmony_cistruct strmap Omode_Map[] = {
223f08c3bdfSopenharmony_ci	{"random", M_RANDOM},
224f08c3bdfSopenharmony_ci	{"sequential", M_SEQUENTIAL},
225f08c3bdfSopenharmony_ci	{"reverse", M_REVERSE},
226f08c3bdfSopenharmony_ci	{NULL, -1}
227f08c3bdfSopenharmony_ci};
228f08c3bdfSopenharmony_ci
229f08c3bdfSopenharmony_ci/*
230f08c3bdfSopenharmony_ci * Map syscall names (-s args) to values - macros are defined in doio.h.
231f08c3bdfSopenharmony_ci */
232f08c3bdfSopenharmony_ci#define	SY_ASYNC	00001
233f08c3bdfSopenharmony_ci#define	SY_WRITE	00002
234f08c3bdfSopenharmony_ci#define	SY_SDS		00010
235f08c3bdfSopenharmony_ci#define	SY_LISTIO	00020
236f08c3bdfSopenharmony_ci#define	SY_NENT		00100	/* multi entry vs multi stride >>> */
237f08c3bdfSopenharmony_ci
238f08c3bdfSopenharmony_cistruct strmap Syscall_Map[] = {
239f08c3bdfSopenharmony_ci	{"read", READ, 0},
240f08c3bdfSopenharmony_ci	{"write", WRITE, SY_WRITE},
241f08c3bdfSopenharmony_ci#ifdef CRAY
242f08c3bdfSopenharmony_ci	{"reada", READA, SY_ASYNC},
243f08c3bdfSopenharmony_ci	{"writea", WRITEA, SY_WRITE | SY_ASYNC},
244f08c3bdfSopenharmony_ci#ifndef _CRAYMPP
245f08c3bdfSopenharmony_ci	{"ssread", SSREAD, SY_SDS},
246f08c3bdfSopenharmony_ci	{"sswrite", SSWRITE, SY_WRITE | SY_SDS},
247f08c3bdfSopenharmony_ci#endif
248f08c3bdfSopenharmony_ci	{"listio", LISTIO, SY_ASYNC},
249f08c3bdfSopenharmony_ci
250f08c3bdfSopenharmony_ci	/* listio as 4 system calls */
251f08c3bdfSopenharmony_ci	{"lread", LREAD, 0},
252f08c3bdfSopenharmony_ci	{"lreada", LREADA, SY_ASYNC},
253f08c3bdfSopenharmony_ci	{"lwrite", LWRITE, SY_WRITE},
254f08c3bdfSopenharmony_ci	{"lwritea", LWRITEA, SY_WRITE | SY_ASYNC},
255f08c3bdfSopenharmony_ci
256f08c3bdfSopenharmony_ci	/* listio with nstrides > 1 */
257f08c3bdfSopenharmony_ci	{"lsread", LSREAD, 0},
258f08c3bdfSopenharmony_ci	{"lsreada", LSREADA, SY_ASYNC},
259f08c3bdfSopenharmony_ci	{"lswrite", LSWRITE, SY_WRITE},
260f08c3bdfSopenharmony_ci	{"lswritea", LSWRITEA, SY_WRITE | SY_ASYNC},
261f08c3bdfSopenharmony_ci
262f08c3bdfSopenharmony_ci	/* listio with nents > 1 */
263f08c3bdfSopenharmony_ci	{"leread", LEREAD, 0 | SY_NENT},
264f08c3bdfSopenharmony_ci	{"lereada", LEREADA, SY_ASYNC | SY_NENT},
265f08c3bdfSopenharmony_ci	{"lewrite", LEWRITE, SY_WRITE | SY_NENT},
266f08c3bdfSopenharmony_ci	{"lewritea", LEWRITEA, SY_WRITE | SY_ASYNC | SY_NENT},
267f08c3bdfSopenharmony_ci
268f08c3bdfSopenharmony_ci	/* listio with nents > 1 & nstrides > 1 */
269f08c3bdfSopenharmony_ci
270f08c3bdfSopenharmony_ci	/* all listio system calls under one name */
271f08c3bdfSopenharmony_ci	{"listio+", LREAD, 0},
272f08c3bdfSopenharmony_ci	{"listio+", LREADA, SY_ASYNC},
273f08c3bdfSopenharmony_ci	{"listio+", LWRITE, SY_WRITE},
274f08c3bdfSopenharmony_ci	{"listio+", LWRITEA, SY_WRITE | SY_ASYNC},
275f08c3bdfSopenharmony_ci	{"listio+", LSREAD, 0},
276f08c3bdfSopenharmony_ci	{"listio+", LSREADA, SY_ASYNC},
277f08c3bdfSopenharmony_ci	{"listio+", LSWRITE, SY_WRITE},
278f08c3bdfSopenharmony_ci	{"listio+", LSWRITEA, SY_WRITE | SY_ASYNC},
279f08c3bdfSopenharmony_ci	{"listio+", LEREAD, 0 | SY_NENT},
280f08c3bdfSopenharmony_ci	{"listio+", LEREADA, SY_ASYNC | SY_NENT},
281f08c3bdfSopenharmony_ci	{"listio+", LEWRITE, SY_WRITE | SY_NENT},
282f08c3bdfSopenharmony_ci	{"listio+", LEWRITEA, SY_WRITE | SY_ASYNC | SY_NENT},
283f08c3bdfSopenharmony_ci#endif
284f08c3bdfSopenharmony_ci
285f08c3bdfSopenharmony_ci#ifdef sgi
286f08c3bdfSopenharmony_ci	{"pread", PREAD},
287f08c3bdfSopenharmony_ci	{"pwrite", PWRITE, SY_WRITE},
288f08c3bdfSopenharmony_ci	{"aread", AREAD, SY_ASYNC},
289f08c3bdfSopenharmony_ci	{"awrite", AWRITE, SY_WRITE | SY_ASYNC},
290f08c3bdfSopenharmony_ci#if 0
291f08c3bdfSopenharmony_ci	/* not written yet */
292f08c3bdfSopenharmony_ci	{"llread", LLREAD, 0},
293f08c3bdfSopenharmony_ci	{"llaread", LLAREAD, SY_ASYNC},
294f08c3bdfSopenharmony_ci	{"llwrite", LLWRITE, 0},
295f08c3bdfSopenharmony_ci	{"llawrite", LLAWRITE, SY_ASYNC},
296f08c3bdfSopenharmony_ci#endif
297f08c3bdfSopenharmony_ci	{"resvsp", RESVSP, SY_WRITE},
298f08c3bdfSopenharmony_ci	{"unresvsp", UNRESVSP, SY_WRITE},
299f08c3bdfSopenharmony_ci	{"reserve", RESVSP, SY_WRITE},
300f08c3bdfSopenharmony_ci	{"unreserve", UNRESVSP, SY_WRITE},
301f08c3bdfSopenharmony_ci	{"ffsync", DFFSYNC, SY_WRITE},
302f08c3bdfSopenharmony_ci#endif /* SGI */
303f08c3bdfSopenharmony_ci
304f08c3bdfSopenharmony_ci#ifndef CRAY
305f08c3bdfSopenharmony_ci	{"readv", READV},
306f08c3bdfSopenharmony_ci	{"writev", WRITEV, SY_WRITE},
307f08c3bdfSopenharmony_ci	{"mmread", MMAPR},
308f08c3bdfSopenharmony_ci	{"mmwrite", MMAPW, SY_WRITE},
309f08c3bdfSopenharmony_ci	{"fsync2", FSYNC2, SY_WRITE},
310f08c3bdfSopenharmony_ci	{"fdatasync", FDATASYNC, SY_WRITE},
311f08c3bdfSopenharmony_ci#endif
312f08c3bdfSopenharmony_ci
313f08c3bdfSopenharmony_ci	{NULL, -1}
314f08c3bdfSopenharmony_ci};
315f08c3bdfSopenharmony_ci
316f08c3bdfSopenharmony_ci/*
317f08c3bdfSopenharmony_ci * Map open flags (-f args) to values
318f08c3bdfSopenharmony_ci */
319f08c3bdfSopenharmony_ci#define	FLG_RAW		00001
320f08c3bdfSopenharmony_ci
321f08c3bdfSopenharmony_cistruct strmap Flag_Map[] = {
322f08c3bdfSopenharmony_ci	{"buffered", 0, 0},
323f08c3bdfSopenharmony_ci	{"sync", O_SYNC, 0},
324f08c3bdfSopenharmony_ci#ifdef CRAY
325f08c3bdfSopenharmony_ci	{"raw", O_RAW, FLG_RAW},
326f08c3bdfSopenharmony_ci	{"raw+wf", O_RAW | O_WELLFORMED, FLG_RAW},
327f08c3bdfSopenharmony_ci	{"raw+wf+ldraw", O_RAW | O_WELLFORMED | O_LDRAW, FLG_RAW},
328f08c3bdfSopenharmony_ci	{"raw+wf+ldraw+sync", O_RAW | O_WELLFORMED | O_LDRAW | O_SYNC, FLG_RAW},
329f08c3bdfSopenharmony_ci#ifdef O_SSD
330f08c3bdfSopenharmony_ci	{"ssd", O_SSD, FLG_RAW},
331f08c3bdfSopenharmony_ci#endif
332f08c3bdfSopenharmony_ci#ifdef O_LDRAW
333f08c3bdfSopenharmony_ci	{"ldraw", O_LDRAW, 0},
334f08c3bdfSopenharmony_ci#endif
335f08c3bdfSopenharmony_ci#ifdef O_PARALLEL
336f08c3bdfSopenharmony_ci	{"parallel", O_PARALLEL | O_RAW | O_WELLFORMED,
337f08c3bdfSopenharmony_ci	 FLG_RAW},
338f08c3bdfSopenharmony_ci	{"parallel+sync", O_PARALLEL | O_RAW | O_WELLFORMED | O_SYNC,
339f08c3bdfSopenharmony_ci	 FLG_RAW},
340f08c3bdfSopenharmony_ci	{"parallel+ldraw", O_PARALLEL | O_RAW | O_WELLFORMED | O_LDRAW,
341f08c3bdfSopenharmony_ci	 FLG_RAW},
342f08c3bdfSopenharmony_ci	{"parallel+ldraw+sync",
343f08c3bdfSopenharmony_ci	 O_PARALLEL | O_RAW | O_WELLFORMED | O_LDRAW | O_SYNC,
344f08c3bdfSopenharmony_ci	 FLG_RAW},
345f08c3bdfSopenharmony_ci#endif
346f08c3bdfSopenharmony_ci#endif /* CRAY */
347f08c3bdfSopenharmony_ci
348f08c3bdfSopenharmony_ci#ifdef sgi
349f08c3bdfSopenharmony_ci	{"direct", O_DIRECT, FLG_RAW},
350f08c3bdfSopenharmony_ci	{"dsync", O_DSYNC},	/* affects writes */
351f08c3bdfSopenharmony_ci	{"rsync", O_RSYNC},	/* affects reads */
352f08c3bdfSopenharmony_ci	{"rsync+dsync", O_RSYNC | O_DSYNC},
353f08c3bdfSopenharmony_ci#endif
354f08c3bdfSopenharmony_ci	{NULL, -1}
355f08c3bdfSopenharmony_ci};
356f08c3bdfSopenharmony_ci
357f08c3bdfSopenharmony_ci/*
358f08c3bdfSopenharmony_ci * Map file types to strings
359f08c3bdfSopenharmony_ci */
360f08c3bdfSopenharmony_ci
361f08c3bdfSopenharmony_cistruct strmap Ftype_Map[] = {
362f08c3bdfSopenharmony_ci	{"regular", S_IFREG},
363f08c3bdfSopenharmony_ci	{"blk-spec", S_IFBLK},
364f08c3bdfSopenharmony_ci	{"chr-spec", S_IFCHR},
365f08c3bdfSopenharmony_ci	{NULL, 0}
366f08c3bdfSopenharmony_ci};
367f08c3bdfSopenharmony_ci
368f08c3bdfSopenharmony_ci/*
369f08c3bdfSopenharmony_ci * Misc declarations
370f08c3bdfSopenharmony_ci */
371f08c3bdfSopenharmony_ci
372f08c3bdfSopenharmony_ciint Sds_Avail;
373f08c3bdfSopenharmony_ci
374f08c3bdfSopenharmony_cichar Byte_Patterns[26] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
375f08c3bdfSopenharmony_ci	'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
376f08c3bdfSopenharmony_ci	'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
377f08c3bdfSopenharmony_ci	'Y', 'Z'
378f08c3bdfSopenharmony_ci};
379f08c3bdfSopenharmony_ci
380f08c3bdfSopenharmony_ciint main(int argc, char **argv)
381f08c3bdfSopenharmony_ci{
382f08c3bdfSopenharmony_ci	int rseed, outfd, infinite;
383f08c3bdfSopenharmony_ci	time_t start_time;
384f08c3bdfSopenharmony_ci	struct io_req req;
385f08c3bdfSopenharmony_ci
386f08c3bdfSopenharmony_ci	umask(0);
387f08c3bdfSopenharmony_ci
388f08c3bdfSopenharmony_ci#ifdef CRAY
389f08c3bdfSopenharmony_ci	Sds_Avail = sysconf(_SC_CRAY_SDS);
390f08c3bdfSopenharmony_ci#else
391f08c3bdfSopenharmony_ci	Sds_Avail = 0;
392f08c3bdfSopenharmony_ci#endif
393f08c3bdfSopenharmony_ci
394f08c3bdfSopenharmony_ci	TagName[0] = '\0';
395f08c3bdfSopenharmony_ci	parse_cmdline(argc, argv, OPTS);
396f08c3bdfSopenharmony_ci
397f08c3bdfSopenharmony_ci	/*
398f08c3bdfSopenharmony_ci	 * Initialize output descriptor.
399f08c3bdfSopenharmony_ci	 */
400f08c3bdfSopenharmony_ci	if (!p_opt) {
401f08c3bdfSopenharmony_ci		outfd = 1;
402f08c3bdfSopenharmony_ci	} else {
403f08c3bdfSopenharmony_ci		outfd = init_output();
404f08c3bdfSopenharmony_ci	}
405f08c3bdfSopenharmony_ci
406f08c3bdfSopenharmony_ci	rseed = getpid();
407f08c3bdfSopenharmony_ci	random_range_seed(rseed);	/* initialize random number generator */
408f08c3bdfSopenharmony_ci
409f08c3bdfSopenharmony_ci	/*
410f08c3bdfSopenharmony_ci	 * Print out startup information, unless we're running in quiet mode
411f08c3bdfSopenharmony_ci	 */
412f08c3bdfSopenharmony_ci	if (!q_opt)
413f08c3bdfSopenharmony_ci		startup_info(stderr, rseed);
414f08c3bdfSopenharmony_ci	{
415f08c3bdfSopenharmony_ci		struct timeval ts;
416f08c3bdfSopenharmony_ci		gettimeofday(&ts, NULL);
417f08c3bdfSopenharmony_ci		start_time = ts.tv_sec;
418f08c3bdfSopenharmony_ci	}
419f08c3bdfSopenharmony_ci	/*
420f08c3bdfSopenharmony_ci	 * While iterations (or forever if Iterations == 0) - compute an
421f08c3bdfSopenharmony_ci	 * io request, and write the structure to the output descriptor
422f08c3bdfSopenharmony_ci	 */
423f08c3bdfSopenharmony_ci
424f08c3bdfSopenharmony_ci	infinite = !Iterations;
425f08c3bdfSopenharmony_ci	struct timeval ts;
426f08c3bdfSopenharmony_ci	gettimeofday(&ts, NULL);
427f08c3bdfSopenharmony_ci	while (infinite ||
428f08c3bdfSopenharmony_ci	       (!Time_Mode && Iterations--) ||
429f08c3bdfSopenharmony_ci	       (Time_Mode && (ts.tv_sec - start_time <= Iterations))) {
430f08c3bdfSopenharmony_ci		gettimeofday(&ts, NULL);
431f08c3bdfSopenharmony_ci		memset(&req, 0, sizeof(struct io_req));
432f08c3bdfSopenharmony_ci		if (form_iorequest(&req) == -1) {
433f08c3bdfSopenharmony_ci			fprintf(stderr, "iogen%s:  form_iorequest() failed\n",
434f08c3bdfSopenharmony_ci				TagName);
435f08c3bdfSopenharmony_ci			continue;
436f08c3bdfSopenharmony_ci		}
437f08c3bdfSopenharmony_ci
438f08c3bdfSopenharmony_ci		req.r_magic = DOIO_MAGIC;
439f08c3bdfSopenharmony_ci		if (write(outfd, (char *)&req, sizeof(req)) == -1)
440f08c3bdfSopenharmony_ci			perror("Warning: Could not write");
441f08c3bdfSopenharmony_ci	}
442f08c3bdfSopenharmony_ci
443f08c3bdfSopenharmony_ci	exit(0);
444f08c3bdfSopenharmony_ci
445f08c3bdfSopenharmony_ci}				/* main */
446f08c3bdfSopenharmony_ci
447f08c3bdfSopenharmony_civoid startup_info(FILE * stream, int seed)
448f08c3bdfSopenharmony_ci{
449f08c3bdfSopenharmony_ci	char *value_to_string(), *type;
450f08c3bdfSopenharmony_ci	int i;
451f08c3bdfSopenharmony_ci
452f08c3bdfSopenharmony_ci	fprintf(stream, "\n");
453f08c3bdfSopenharmony_ci	fprintf(stream, "iogen%s starting up with the following:\n", TagName);
454f08c3bdfSopenharmony_ci	fprintf(stream, "\n");
455f08c3bdfSopenharmony_ci
456f08c3bdfSopenharmony_ci	fprintf(stream, "Out-pipe:              %s\n",
457f08c3bdfSopenharmony_ci		p_opt ? Outpipe : "stdout");
458f08c3bdfSopenharmony_ci
459f08c3bdfSopenharmony_ci	if (Iterations) {
460f08c3bdfSopenharmony_ci		fprintf(stream, "Iterations:            %d", Iterations);
461f08c3bdfSopenharmony_ci		if (Time_Mode)
462f08c3bdfSopenharmony_ci			fprintf(stream, " seconds");
463f08c3bdfSopenharmony_ci
464f08c3bdfSopenharmony_ci		fprintf(stream, "\n");
465f08c3bdfSopenharmony_ci	} else {
466f08c3bdfSopenharmony_ci		fprintf(stream, "Iterations:            Infinite\n");
467f08c3bdfSopenharmony_ci	}
468f08c3bdfSopenharmony_ci
469f08c3bdfSopenharmony_ci	fprintf(stream, "Seed:                  %d\n", seed);
470f08c3bdfSopenharmony_ci
471f08c3bdfSopenharmony_ci	fprintf(stream, "Offset-Mode:           %s\n", Offset_Mode->m_string);
472f08c3bdfSopenharmony_ci
473f08c3bdfSopenharmony_ci	fprintf(stream, "Overlap Flag:          %s\n", o_opt ? "on" : "off");
474f08c3bdfSopenharmony_ci
475f08c3bdfSopenharmony_ci	fprintf(stream,
476f08c3bdfSopenharmony_ci		"Mintrans:              %-11d (%d blocks)\n",
477f08c3bdfSopenharmony_ci		Mintrans, (Mintrans + BSIZE - 1) / BSIZE);
478f08c3bdfSopenharmony_ci
479f08c3bdfSopenharmony_ci	fprintf(stream,
480f08c3bdfSopenharmony_ci		"Maxtrans:              %-11d (%d blocks)\n",
481f08c3bdfSopenharmony_ci		Maxtrans, (Maxtrans + BSIZE - 1) / BSIZE);
482f08c3bdfSopenharmony_ci
483f08c3bdfSopenharmony_ci	if (!r_opt)
484f08c3bdfSopenharmony_ci		fprintf(stream,
485f08c3bdfSopenharmony_ci			"O_RAW/O_SSD Multiple:  (Determined by device)\n");
486f08c3bdfSopenharmony_ci	else
487f08c3bdfSopenharmony_ci		fprintf(stream,
488f08c3bdfSopenharmony_ci			"O_RAW/O_SSD Multiple:  %-11d (%d blocks)\n",
489f08c3bdfSopenharmony_ci			Rawmult, (Rawmult + BSIZE - 1) / BSIZE);
490f08c3bdfSopenharmony_ci
491f08c3bdfSopenharmony_ci	fprintf(stream, "Syscalls:              ");
492f08c3bdfSopenharmony_ci	for (i = 0; i < Nsyscalls; i++)
493f08c3bdfSopenharmony_ci		fprintf(stream, "%s ", Syscall_List[i]->m_string);
494f08c3bdfSopenharmony_ci	fprintf(stream, "\n");
495f08c3bdfSopenharmony_ci
496f08c3bdfSopenharmony_ci	fprintf(stream, "Aio completion types:  ");
497f08c3bdfSopenharmony_ci	for (i = 0; i < Naio_Strat_Types; i++)
498f08c3bdfSopenharmony_ci		fprintf(stream, "%s ", Aio_Strat_List[i]->m_string);
499f08c3bdfSopenharmony_ci	fprintf(stream, "\n");
500f08c3bdfSopenharmony_ci
501f08c3bdfSopenharmony_ci	if (Fileio) {
502f08c3bdfSopenharmony_ci		fprintf(stream, "Flags:                 ");
503f08c3bdfSopenharmony_ci		for (i = 0; i < Nflags; i++)
504f08c3bdfSopenharmony_ci			fprintf(stream, "%s ", Flag_List[i]->m_string);
505f08c3bdfSopenharmony_ci
506f08c3bdfSopenharmony_ci		fprintf(stream, "\n");
507f08c3bdfSopenharmony_ci		fprintf(stream, "\n");
508f08c3bdfSopenharmony_ci		fprintf(stream, "Test Files:  \n");
509f08c3bdfSopenharmony_ci		fprintf(stream, "\n");
510f08c3bdfSopenharmony_ci		fprintf(stream,
511f08c3bdfSopenharmony_ci			"Path                                          Length    iou   raw iou file\n");
512f08c3bdfSopenharmony_ci		fprintf(stream,
513f08c3bdfSopenharmony_ci			"                                              (bytes) (bytes) (bytes) type\n");
514f08c3bdfSopenharmony_ci		fprintf(stream,
515f08c3bdfSopenharmony_ci			"-----------------------------------------------------------------------------\n");
516f08c3bdfSopenharmony_ci
517f08c3bdfSopenharmony_ci		for (i = 0; i < Nfiles; i++) {
518f08c3bdfSopenharmony_ci			type = value_to_string(Ftype_Map, File_List[i].f_type);
519f08c3bdfSopenharmony_ci			fprintf(stream, "%-40s %12d %7d %7d %s\n",
520f08c3bdfSopenharmony_ci				File_List[i].f_path, File_List[i].f_length,
521f08c3bdfSopenharmony_ci				File_List[i].f_iou, File_List[i].f_riou, type);
522f08c3bdfSopenharmony_ci		}
523f08c3bdfSopenharmony_ci	}
524f08c3bdfSopenharmony_ci}
525f08c3bdfSopenharmony_ci
526f08c3bdfSopenharmony_ci/*
527f08c3bdfSopenharmony_ci * Initialize output descriptor.  If going to stdout, its easy,
528f08c3bdfSopenharmony_ci * otherwise, attempt to create a FIFO on path Outpipe.  Exit with an
529f08c3bdfSopenharmony_ci * error code if this cannot be done.
530f08c3bdfSopenharmony_ci */
531f08c3bdfSopenharmony_ciint init_output(void)
532f08c3bdfSopenharmony_ci{
533f08c3bdfSopenharmony_ci	int outfd;
534f08c3bdfSopenharmony_ci	struct stat sbuf;
535f08c3bdfSopenharmony_ci
536f08c3bdfSopenharmony_ci	if (stat(Outpipe, &sbuf) == -1) {
537f08c3bdfSopenharmony_ci		if (errno == ENOENT) {
538f08c3bdfSopenharmony_ci			if (mkfifo(Outpipe, 0666) == -1) {
539f08c3bdfSopenharmony_ci				fprintf(stderr,
540f08c3bdfSopenharmony_ci					"iogen%s:  Could not mkfifo %s:  %s\n",
541f08c3bdfSopenharmony_ci					TagName, Outpipe, SYSERR);
542f08c3bdfSopenharmony_ci				exit(2);
543f08c3bdfSopenharmony_ci			}
544f08c3bdfSopenharmony_ci		} else {
545f08c3bdfSopenharmony_ci			fprintf(stderr,
546f08c3bdfSopenharmony_ci				"iogen%s:  Could not stat outpipe %s:  %s\n",
547f08c3bdfSopenharmony_ci				TagName, Outpipe, SYSERR);
548f08c3bdfSopenharmony_ci			exit(2);
549f08c3bdfSopenharmony_ci		}
550f08c3bdfSopenharmony_ci	} else {
551f08c3bdfSopenharmony_ci		if (!S_ISFIFO(sbuf.st_mode)) {
552f08c3bdfSopenharmony_ci			fprintf(stderr,
553f08c3bdfSopenharmony_ci				"iogen%s:  Output file %s exists, but is not a FIFO\n",
554f08c3bdfSopenharmony_ci				TagName, Outpipe);
555f08c3bdfSopenharmony_ci			exit(2);
556f08c3bdfSopenharmony_ci		}
557f08c3bdfSopenharmony_ci	}
558f08c3bdfSopenharmony_ci
559f08c3bdfSopenharmony_ci	if ((outfd = open(Outpipe, O_RDWR)) == -1) {
560f08c3bdfSopenharmony_ci		fprintf(stderr,
561f08c3bdfSopenharmony_ci			"iogen%s:  Couldn't open outpipe %s with flags O_RDWR: %s\n",
562f08c3bdfSopenharmony_ci			TagName, Outpipe, SYSERR);
563f08c3bdfSopenharmony_ci		exit(2);
564f08c3bdfSopenharmony_ci	}
565f08c3bdfSopenharmony_ci
566f08c3bdfSopenharmony_ci	return (outfd);
567f08c3bdfSopenharmony_ci}
568f08c3bdfSopenharmony_ci
569f08c3bdfSopenharmony_ci/*
570f08c3bdfSopenharmony_ci * Main io generation function.  form_iorequest() selects a system call to
571f08c3bdfSopenharmony_ci * do based on cmdline arguments, and proceeds to select parameters for that
572f08c3bdfSopenharmony_ci * system call.
573f08c3bdfSopenharmony_ci *
574f08c3bdfSopenharmony_ci * Returns 0 if req is filled in with a complete doio request, otherwise
575f08c3bdfSopenharmony_ci * returns -1.
576f08c3bdfSopenharmony_ci */
577f08c3bdfSopenharmony_ci
578f08c3bdfSopenharmony_ciint form_iorequest(struct io_req *req)
579f08c3bdfSopenharmony_ci{
580f08c3bdfSopenharmony_ci	int mult, offset = 0, length = 0, slength;
581f08c3bdfSopenharmony_ci	int minlength, maxlength, laststart, lastend;
582f08c3bdfSopenharmony_ci	int minoffset, maxoffset;
583f08c3bdfSopenharmony_ci	int maxstride, nstrides;
584f08c3bdfSopenharmony_ci	char pattern, *errp;
585f08c3bdfSopenharmony_ci	struct strmap *flags, *sc, *aio_strat;
586f08c3bdfSopenharmony_ci	struct file_info *fptr;
587f08c3bdfSopenharmony_ci#ifdef CRAY
588f08c3bdfSopenharmony_ci	int opcode, cmd;
589f08c3bdfSopenharmony_ci#endif
590f08c3bdfSopenharmony_ci
591f08c3bdfSopenharmony_ci	/*
592f08c3bdfSopenharmony_ci	 * Choose system call, flags, and file
593f08c3bdfSopenharmony_ci	 */
594f08c3bdfSopenharmony_ci
595f08c3bdfSopenharmony_ci	sc = Syscall_List[random_range(0, Nsyscalls - 1, 1, NULL)];
596f08c3bdfSopenharmony_ci	req->r_type = sc->m_value;
597f08c3bdfSopenharmony_ci
598f08c3bdfSopenharmony_ci#ifdef CRAY
599f08c3bdfSopenharmony_ci	if (sc->m_value == LISTIO) {
600f08c3bdfSopenharmony_ci		opcode = random_range(0, 1, 1, NULL) ? LO_READ : LO_WRITE;
601f08c3bdfSopenharmony_ci		cmd = random_range(0, 1, 1, NULL) ? LC_START : LC_WAIT;
602f08c3bdfSopenharmony_ci	}
603f08c3bdfSopenharmony_ci#endif
604f08c3bdfSopenharmony_ci
605f08c3bdfSopenharmony_ci	if (sc->m_flags & SY_WRITE)
606f08c3bdfSopenharmony_ci		pattern =
607f08c3bdfSopenharmony_ci		    Byte_Patterns[random_range
608f08c3bdfSopenharmony_ci				  (0, sizeof(Byte_Patterns) - 1, 1, NULL)];
609f08c3bdfSopenharmony_ci	else
610f08c3bdfSopenharmony_ci		pattern = 0;
611f08c3bdfSopenharmony_ci
612f08c3bdfSopenharmony_ci#if CRAY
613f08c3bdfSopenharmony_ci	/*
614f08c3bdfSopenharmony_ci	 * If sds io, simply choose a length (possibly pattern) and return
615f08c3bdfSopenharmony_ci	 */
616f08c3bdfSopenharmony_ci
617f08c3bdfSopenharmony_ci	if (sc->m_flags & SY_SDS) {
618f08c3bdfSopenharmony_ci		req->r_data.ssread.r_nbytes =
619f08c3bdfSopenharmony_ci		    random_range(Mintrans, Maxtrans, BSIZE, NULL);
620f08c3bdfSopenharmony_ci		if (sc->m_flags & SY_WRITE)
621f08c3bdfSopenharmony_ci			req->r_data.sswrite.r_pattern = pattern;
622f08c3bdfSopenharmony_ci
623f08c3bdfSopenharmony_ci		return 0;
624f08c3bdfSopenharmony_ci	}
625f08c3bdfSopenharmony_ci#endif
626f08c3bdfSopenharmony_ci
627f08c3bdfSopenharmony_ci	/*
628f08c3bdfSopenharmony_ci	 * otherwise, we're doing file io.  Choose starting offset, length,
629f08c3bdfSopenharmony_ci	 * open flags, and possibly a pattern (for write/writea).
630f08c3bdfSopenharmony_ci	 */
631f08c3bdfSopenharmony_ci
632f08c3bdfSopenharmony_ci	fptr = &File_List[random_range(0, Nfiles - 1, 1, NULL)];
633f08c3bdfSopenharmony_ci	flags = Flag_List[random_range(0, Nflags - 1, 1, NULL)];
634f08c3bdfSopenharmony_ci
635f08c3bdfSopenharmony_ci	/*
636f08c3bdfSopenharmony_ci	 * Choose offset/length multiple.  IO going to a device, or regular
637f08c3bdfSopenharmony_ci	 * IO that is O_RAW or O_SSD must be aligned on the file r_iou.  Otherwise
638f08c3bdfSopenharmony_ci	 * it must be aligned on the regular iou (normally 1).
639f08c3bdfSopenharmony_ci	 */
640f08c3bdfSopenharmony_ci
641f08c3bdfSopenharmony_ci	if (fptr->f_type == S_IFREG && (flags->m_flags & FLG_RAW))
642f08c3bdfSopenharmony_ci		mult = fptr->f_riou;
643f08c3bdfSopenharmony_ci	else
644f08c3bdfSopenharmony_ci		mult = fptr->f_iou;
645f08c3bdfSopenharmony_ci
646f08c3bdfSopenharmony_ci	/*
647f08c3bdfSopenharmony_ci	 * Choose offset and length.  Both must be a multiple of mult
648f08c3bdfSopenharmony_ci	 */
649f08c3bdfSopenharmony_ci
650f08c3bdfSopenharmony_ci	/*
651f08c3bdfSopenharmony_ci	 * Choose length first - it must be a multiple of mult
652f08c3bdfSopenharmony_ci	 */
653f08c3bdfSopenharmony_ci
654f08c3bdfSopenharmony_ci	laststart = fptr->f_lastoffset;
655f08c3bdfSopenharmony_ci	lastend = fptr->f_lastoffset + fptr->f_lastlength - 1;
656f08c3bdfSopenharmony_ci
657f08c3bdfSopenharmony_ci	minlength = (Mintrans > mult) ? Mintrans : mult;
658f08c3bdfSopenharmony_ci
659f08c3bdfSopenharmony_ci	switch (Offset_Mode->m_value) {
660f08c3bdfSopenharmony_ci	case M_SEQUENTIAL:
661f08c3bdfSopenharmony_ci		if (o_opt && lastend > laststart)
662f08c3bdfSopenharmony_ci			offset = random_range(laststart, lastend, 1, NULL);
663f08c3bdfSopenharmony_ci		else
664f08c3bdfSopenharmony_ci			offset = lastend + 1;
665f08c3bdfSopenharmony_ci		if (offset && (offset % mult))
666f08c3bdfSopenharmony_ci			offset += mult - (offset % mult);
667f08c3bdfSopenharmony_ci
668f08c3bdfSopenharmony_ci		if (minlength > fptr->f_length - offset)
669f08c3bdfSopenharmony_ci			offset = 0;
670f08c3bdfSopenharmony_ci
671f08c3bdfSopenharmony_ci		maxlength = fptr->f_length - offset;
672f08c3bdfSopenharmony_ci		if (maxlength > Maxtrans)
673f08c3bdfSopenharmony_ci			maxlength = Maxtrans;
674f08c3bdfSopenharmony_ci
675f08c3bdfSopenharmony_ci		length = random_range(minlength, maxlength, mult, &errp);
676f08c3bdfSopenharmony_ci		if (errp != NULL) {
677f08c3bdfSopenharmony_ci			fprintf(stderr,
678f08c3bdfSopenharmony_ci				"iogen%s:  random_range(%d, %d, %d) failed\n",
679f08c3bdfSopenharmony_ci				TagName, minlength, maxlength, mult);
680f08c3bdfSopenharmony_ci			return -1;
681f08c3bdfSopenharmony_ci		}
682f08c3bdfSopenharmony_ci
683f08c3bdfSopenharmony_ci		break;
684f08c3bdfSopenharmony_ci
685f08c3bdfSopenharmony_ci	case M_REVERSE:
686f08c3bdfSopenharmony_ci		maxlength = laststart;
687f08c3bdfSopenharmony_ci
688f08c3bdfSopenharmony_ci		if (maxlength > Maxtrans)
689f08c3bdfSopenharmony_ci			maxlength = Maxtrans;
690f08c3bdfSopenharmony_ci
691f08c3bdfSopenharmony_ci		if (minlength > maxlength) {
692f08c3bdfSopenharmony_ci			laststart = fptr->f_length;
693f08c3bdfSopenharmony_ci			lastend = fptr->f_length;
694f08c3bdfSopenharmony_ci			maxlength = Maxtrans;
695f08c3bdfSopenharmony_ci		}
696f08c3bdfSopenharmony_ci
697f08c3bdfSopenharmony_ci		length = random_range(minlength, maxlength, mult, &errp);
698f08c3bdfSopenharmony_ci		if (errp != NULL) {
699f08c3bdfSopenharmony_ci			fprintf(stderr,
700f08c3bdfSopenharmony_ci				"iogen%s:  random_range(%d, %d, %d) failed\n",
701f08c3bdfSopenharmony_ci				TagName, minlength, maxlength, mult);
702f08c3bdfSopenharmony_ci			return -1;
703f08c3bdfSopenharmony_ci		}
704f08c3bdfSopenharmony_ci
705f08c3bdfSopenharmony_ci		offset = laststart - length;
706f08c3bdfSopenharmony_ci
707f08c3bdfSopenharmony_ci		if (o_opt && lastend > laststart)
708f08c3bdfSopenharmony_ci			offset += random_range(1, lastend - laststart, 1, NULL);
709f08c3bdfSopenharmony_ci
710f08c3bdfSopenharmony_ci		if (offset && (offset % mult))
711f08c3bdfSopenharmony_ci			offset -= offset % mult;
712f08c3bdfSopenharmony_ci
713f08c3bdfSopenharmony_ci		break;
714f08c3bdfSopenharmony_ci
715f08c3bdfSopenharmony_ci	case M_RANDOM:
716f08c3bdfSopenharmony_ci		length = random_range(Mintrans, Maxtrans, mult, NULL);
717f08c3bdfSopenharmony_ci
718f08c3bdfSopenharmony_ci		if (o_opt && lastend > laststart) {
719f08c3bdfSopenharmony_ci			minoffset = laststart - length + 1;
720f08c3bdfSopenharmony_ci			if (minoffset < 0) {
721f08c3bdfSopenharmony_ci				minoffset = 0;
722f08c3bdfSopenharmony_ci			}
723f08c3bdfSopenharmony_ci
724f08c3bdfSopenharmony_ci			if (lastend + length > fptr->f_length) {
725f08c3bdfSopenharmony_ci				maxoffset = fptr->f_length - length;
726f08c3bdfSopenharmony_ci			} else {
727f08c3bdfSopenharmony_ci				maxoffset = lastend;
728f08c3bdfSopenharmony_ci			}
729f08c3bdfSopenharmony_ci		} else {
730f08c3bdfSopenharmony_ci			minoffset = 0;
731f08c3bdfSopenharmony_ci			maxoffset = fptr->f_length - length;
732f08c3bdfSopenharmony_ci		}
733f08c3bdfSopenharmony_ci
734f08c3bdfSopenharmony_ci		if (minoffset < 0)
735f08c3bdfSopenharmony_ci			minoffset = 0;
736f08c3bdfSopenharmony_ci
737f08c3bdfSopenharmony_ci		offset = random_range(minoffset, maxoffset, mult, &errp);
738f08c3bdfSopenharmony_ci		if (errp != NULL) {
739f08c3bdfSopenharmony_ci			fprintf(stderr,
740f08c3bdfSopenharmony_ci				"iogen%s:  random_range(%d, %d, %d) failed\n",
741f08c3bdfSopenharmony_ci				TagName, minoffset, maxoffset, mult);
742f08c3bdfSopenharmony_ci			return -1;
743f08c3bdfSopenharmony_ci		}
744f08c3bdfSopenharmony_ci	}
745f08c3bdfSopenharmony_ci
746f08c3bdfSopenharmony_ci	fptr->f_lastoffset = offset;
747f08c3bdfSopenharmony_ci	fptr->f_lastlength = length;
748f08c3bdfSopenharmony_ci
749f08c3bdfSopenharmony_ci	/*
750f08c3bdfSopenharmony_ci	 * Choose an async io completion strategy if necessary
751f08c3bdfSopenharmony_ci	 */
752f08c3bdfSopenharmony_ci	if (sc->m_flags & SY_ASYNC)
753f08c3bdfSopenharmony_ci		aio_strat = Aio_Strat_List[random_range(0, Naio_Strat_Types - 1,
754f08c3bdfSopenharmony_ci							1, NULL)];
755f08c3bdfSopenharmony_ci	else
756f08c3bdfSopenharmony_ci		aio_strat = NULL;
757f08c3bdfSopenharmony_ci
758f08c3bdfSopenharmony_ci	/*
759f08c3bdfSopenharmony_ci	 * fill in specific syscall record data
760f08c3bdfSopenharmony_ci	 */
761f08c3bdfSopenharmony_ci	switch (sc->m_value) {
762f08c3bdfSopenharmony_ci	case READ:
763f08c3bdfSopenharmony_ci	case READA:
764f08c3bdfSopenharmony_ci		strcpy(req->r_data.read.r_file, fptr->f_path);
765f08c3bdfSopenharmony_ci		req->r_data.read.r_oflags = O_RDONLY | flags->m_value;
766f08c3bdfSopenharmony_ci		req->r_data.read.r_offset = offset;
767f08c3bdfSopenharmony_ci		req->r_data.read.r_nbytes = length;
768f08c3bdfSopenharmony_ci		req->r_data.read.r_uflags =
769f08c3bdfSopenharmony_ci		    (flags->m_flags & FLG_RAW) ? F_WORD_ALIGNED : 0;
770f08c3bdfSopenharmony_ci		req->r_data.read.r_aio_strat =
771f08c3bdfSopenharmony_ci		    (aio_strat == NULL) ? 0 : aio_strat->m_value;
772f08c3bdfSopenharmony_ci		req->r_data.read.r_nstrides = 1;
773f08c3bdfSopenharmony_ci		req->r_data.read.r_nent = 1;
774f08c3bdfSopenharmony_ci		break;
775f08c3bdfSopenharmony_ci
776f08c3bdfSopenharmony_ci	case WRITE:
777f08c3bdfSopenharmony_ci	case WRITEA:
778f08c3bdfSopenharmony_ci		strcpy(req->r_data.write.r_file, fptr->f_path);
779f08c3bdfSopenharmony_ci		req->r_data.write.r_oflags = O_WRONLY | flags->m_value;
780f08c3bdfSopenharmony_ci		req->r_data.write.r_offset = offset;
781f08c3bdfSopenharmony_ci		req->r_data.write.r_nbytes = length;
782f08c3bdfSopenharmony_ci		req->r_data.write.r_pattern = pattern;
783f08c3bdfSopenharmony_ci		req->r_data.write.r_uflags =
784f08c3bdfSopenharmony_ci		    (flags->m_flags & FLG_RAW) ? F_WORD_ALIGNED : 0;
785f08c3bdfSopenharmony_ci		req->r_data.write.r_aio_strat =
786f08c3bdfSopenharmony_ci		    (aio_strat == NULL) ? 0 : aio_strat->m_value;
787f08c3bdfSopenharmony_ci		req->r_data.write.r_nstrides = 1;
788f08c3bdfSopenharmony_ci		req->r_data.write.r_nent = 1;
789f08c3bdfSopenharmony_ci		break;
790f08c3bdfSopenharmony_ci
791f08c3bdfSopenharmony_ci	case READV:
792f08c3bdfSopenharmony_ci	case AREAD:
793f08c3bdfSopenharmony_ci	case PREAD:
794f08c3bdfSopenharmony_ci	case WRITEV:
795f08c3bdfSopenharmony_ci	case AWRITE:
796f08c3bdfSopenharmony_ci	case PWRITE:
797f08c3bdfSopenharmony_ci
798f08c3bdfSopenharmony_ci	case LREAD:
799f08c3bdfSopenharmony_ci	case LREADA:
800f08c3bdfSopenharmony_ci	case LWRITE:
801f08c3bdfSopenharmony_ci	case LWRITEA:
802f08c3bdfSopenharmony_ci
803f08c3bdfSopenharmony_ci	case RESVSP:
804f08c3bdfSopenharmony_ci	case UNRESVSP:
805f08c3bdfSopenharmony_ci	case DFFSYNC:
806f08c3bdfSopenharmony_ci	case FSYNC2:
807f08c3bdfSopenharmony_ci	case FDATASYNC:
808f08c3bdfSopenharmony_ci
809f08c3bdfSopenharmony_ci		strcpy(req->r_data.io.r_file, fptr->f_path);
810f08c3bdfSopenharmony_ci		req->r_data.io.r_oflags =
811f08c3bdfSopenharmony_ci		    ((sc->m_flags & SY_WRITE) ? O_WRONLY : O_RDONLY) | flags->
812f08c3bdfSopenharmony_ci		    m_value;
813f08c3bdfSopenharmony_ci		req->r_data.io.r_offset = offset;
814f08c3bdfSopenharmony_ci		req->r_data.io.r_nbytes = length;
815f08c3bdfSopenharmony_ci		req->r_data.io.r_pattern = pattern;
816f08c3bdfSopenharmony_ci		req->r_data.io.r_uflags =
817f08c3bdfSopenharmony_ci		    (flags->m_flags & FLG_RAW) ? F_WORD_ALIGNED : 0;
818f08c3bdfSopenharmony_ci		req->r_data.io.r_aio_strat =
819f08c3bdfSopenharmony_ci		    (aio_strat == NULL) ? 0 : aio_strat->m_value;
820f08c3bdfSopenharmony_ci		req->r_data.io.r_nstrides = 1;
821f08c3bdfSopenharmony_ci		req->r_data.io.r_nent = 1;
822f08c3bdfSopenharmony_ci		break;
823f08c3bdfSopenharmony_ci
824f08c3bdfSopenharmony_ci	case MMAPR:
825f08c3bdfSopenharmony_ci	case MMAPW:
826f08c3bdfSopenharmony_ci		strcpy(req->r_data.io.r_file, fptr->f_path);
827f08c3bdfSopenharmony_ci		/* a subtle "feature" of mmap: a write-map requires
828f08c3bdfSopenharmony_ci		   the file open read/write */
829f08c3bdfSopenharmony_ci		req->r_data.io.r_oflags =
830f08c3bdfSopenharmony_ci		    ((sc->m_flags & SY_WRITE) ? O_RDWR : O_RDONLY) | flags->
831f08c3bdfSopenharmony_ci		    m_value;
832f08c3bdfSopenharmony_ci		req->r_data.io.r_offset = offset;
833f08c3bdfSopenharmony_ci		req->r_data.io.r_nbytes = length;
834f08c3bdfSopenharmony_ci		req->r_data.io.r_pattern = pattern;
835f08c3bdfSopenharmony_ci		req->r_data.io.r_uflags =
836f08c3bdfSopenharmony_ci		    (flags->m_flags & FLG_RAW) ? F_WORD_ALIGNED : 0;
837f08c3bdfSopenharmony_ci		req->r_data.io.r_aio_strat =
838f08c3bdfSopenharmony_ci		    (aio_strat == NULL) ? 0 : aio_strat->m_value;
839f08c3bdfSopenharmony_ci		req->r_data.io.r_nstrides = 1;
840f08c3bdfSopenharmony_ci		req->r_data.io.r_nent = 1;
841f08c3bdfSopenharmony_ci		break;
842f08c3bdfSopenharmony_ci
843f08c3bdfSopenharmony_ci	case LSREAD:
844f08c3bdfSopenharmony_ci	case LSREADA:
845f08c3bdfSopenharmony_ci	case LEREAD:
846f08c3bdfSopenharmony_ci	case LEREADA:
847f08c3bdfSopenharmony_ci	case LSWRITE:
848f08c3bdfSopenharmony_ci	case LSWRITEA:
849f08c3bdfSopenharmony_ci	case LEWRITE:
850f08c3bdfSopenharmony_ci	case LEWRITEA:
851f08c3bdfSopenharmony_ci		/* multi-strided */
852f08c3bdfSopenharmony_ci		strcpy(req->r_data.io.r_file, fptr->f_path);
853f08c3bdfSopenharmony_ci		req->r_data.io.r_oflags =
854f08c3bdfSopenharmony_ci		    ((sc->m_flags & SY_WRITE) ? O_WRONLY : O_RDONLY) | flags->
855f08c3bdfSopenharmony_ci		    m_value;
856f08c3bdfSopenharmony_ci		req->r_data.io.r_offset = offset;
857f08c3bdfSopenharmony_ci		req->r_data.io.r_uflags =
858f08c3bdfSopenharmony_ci		    (flags->m_flags & FLG_RAW) ? F_WORD_ALIGNED : 0;
859f08c3bdfSopenharmony_ci		req->r_data.io.r_aio_strat =
860f08c3bdfSopenharmony_ci		    (aio_strat == NULL) ? 0 : aio_strat->m_value;
861f08c3bdfSopenharmony_ci		req->r_data.io.r_pattern = pattern;
862f08c3bdfSopenharmony_ci
863f08c3bdfSopenharmony_ci		/* multi-strided request...
864f08c3bdfSopenharmony_ci		 *  random number of strides (1...MaxStrides)
865f08c3bdfSopenharmony_ci		 *  length of stride must be > minlength
866f08c3bdfSopenharmony_ci		 *  length of stride must be % mult
867f08c3bdfSopenharmony_ci		 *
868f08c3bdfSopenharmony_ci		 * maxstrides = min(length / mult, overall.max#strides)
869f08c3bdfSopenharmony_ci		 * nstrides = random #
870f08c3bdfSopenharmony_ci		 * while (length / nstrides < minlength)
871f08c3bdfSopenharmony_ci		 *      nstrides = new random #
872f08c3bdfSopenharmony_ci		 */
873f08c3bdfSopenharmony_ci		maxstride = length / mult;
874f08c3bdfSopenharmony_ci		if (maxstride > Maxstrides)
875f08c3bdfSopenharmony_ci			maxstride = Maxstrides;
876f08c3bdfSopenharmony_ci
877f08c3bdfSopenharmony_ci		if (!Minstrides)
878f08c3bdfSopenharmony_ci			Minstrides = 1;
879f08c3bdfSopenharmony_ci		nstrides = random_range(Minstrides, maxstride, 1, &errp);
880f08c3bdfSopenharmony_ci		if (errp != NULL) {
881f08c3bdfSopenharmony_ci			fprintf(stderr,
882f08c3bdfSopenharmony_ci				"iogen%s:  random_range(%d, %d, %d) failed\n",
883f08c3bdfSopenharmony_ci				TagName, Minstrides, maxstride, 1);
884f08c3bdfSopenharmony_ci			return -1;
885f08c3bdfSopenharmony_ci		}
886f08c3bdfSopenharmony_ci
887f08c3bdfSopenharmony_ci		slength = length / nstrides;
888f08c3bdfSopenharmony_ci		if (slength % mult != 0) {
889f08c3bdfSopenharmony_ci			if (mult > slength) {
890f08c3bdfSopenharmony_ci				slength = mult;
891f08c3bdfSopenharmony_ci			} else {
892f08c3bdfSopenharmony_ci				slength -= slength % mult;
893f08c3bdfSopenharmony_ci			}
894f08c3bdfSopenharmony_ci			nstrides = length / slength;
895f08c3bdfSopenharmony_ci			if (nstrides > Maxstrides)
896f08c3bdfSopenharmony_ci				nstrides = Maxstrides;
897f08c3bdfSopenharmony_ci		}
898f08c3bdfSopenharmony_ci
899f08c3bdfSopenharmony_ci		req->r_data.io.r_nbytes = slength;
900f08c3bdfSopenharmony_ci		if (sc->m_flags & SY_NENT) {
901f08c3bdfSopenharmony_ci			req->r_data.io.r_nstrides = 1;
902f08c3bdfSopenharmony_ci			req->r_data.io.r_nent = nstrides;
903f08c3bdfSopenharmony_ci		} else {
904f08c3bdfSopenharmony_ci			req->r_data.io.r_nstrides = nstrides;
905f08c3bdfSopenharmony_ci			req->r_data.io.r_nent = 1;
906f08c3bdfSopenharmony_ci		}
907f08c3bdfSopenharmony_ci		break;
908f08c3bdfSopenharmony_ci
909f08c3bdfSopenharmony_ci	case LISTIO:
910f08c3bdfSopenharmony_ci#ifdef CRAY
911f08c3bdfSopenharmony_ci		strcpy(req->r_data.listio.r_file, fptr->f_path);
912f08c3bdfSopenharmony_ci		req->r_data.listio.r_offset = offset;
913f08c3bdfSopenharmony_ci		req->r_data.listio.r_cmd = cmd;
914f08c3bdfSopenharmony_ci		req->r_data.listio.r_aio_strat =
915f08c3bdfSopenharmony_ci		    (aio_strat == NULL) ? 0 : aio_strat->m_value;
916f08c3bdfSopenharmony_ci		req->r_data.listio.r_filestride = 0;
917f08c3bdfSopenharmony_ci		req->r_data.listio.r_memstride = 0;
918f08c3bdfSopenharmony_ci		req->r_data.listio.r_opcode = opcode;
919f08c3bdfSopenharmony_ci		req->r_data.listio.r_nstrides = 1;
920f08c3bdfSopenharmony_ci		req->r_data.listio.r_nbytes = length;
921f08c3bdfSopenharmony_ci		req->r_data.listio.r_uflags =
922f08c3bdfSopenharmony_ci		    (flags->m_flags & FLG_RAW) ? F_WORD_ALIGNED : 0;
923f08c3bdfSopenharmony_ci
924f08c3bdfSopenharmony_ci		if (opcode == LO_WRITE) {
925f08c3bdfSopenharmony_ci			req->r_data.listio.r_pattern = pattern;
926f08c3bdfSopenharmony_ci			req->r_data.listio.r_oflags = O_WRONLY | flags->m_value;
927f08c3bdfSopenharmony_ci		} else {
928f08c3bdfSopenharmony_ci			req->r_data.listio.r_oflags = O_RDONLY | flags->m_value;
929f08c3bdfSopenharmony_ci		}
930f08c3bdfSopenharmony_ci#endif
931f08c3bdfSopenharmony_ci		break;
932f08c3bdfSopenharmony_ci	}
933f08c3bdfSopenharmony_ci
934f08c3bdfSopenharmony_ci	return 0;
935f08c3bdfSopenharmony_ci}
936f08c3bdfSopenharmony_ci
937f08c3bdfSopenharmony_ci/*
938f08c3bdfSopenharmony_ci * Get information about a file that iogen uses to choose io length and
939f08c3bdfSopenharmony_ci * offset.  Information gathered is file length, iounit, and raw iounit.
940f08c3bdfSopenharmony_ci * For regurlar files, iounit is 1, and raw iounit is the iounit of the
941f08c3bdfSopenharmony_ci * device on which the file resides.  For block/character special files
942f08c3bdfSopenharmony_ci * the iounit and raw iounit are both the iounit of the device.
943f08c3bdfSopenharmony_ci *
944f08c3bdfSopenharmony_ci * Note:	buffered and osync io must be iounit aligned
945f08c3bdfSopenharmony_ci *		raw and ossd io must be raw iounit aligned
946f08c3bdfSopenharmony_ci */
947f08c3bdfSopenharmony_ci
948f08c3bdfSopenharmony_ciint get_file_info(struct file_info *rec)
949f08c3bdfSopenharmony_ci{
950f08c3bdfSopenharmony_ci	struct stat sbuf;
951f08c3bdfSopenharmony_ci#ifdef CRAY
952f08c3bdfSopenharmony_ci	struct lk_device_info dinfo;
953f08c3bdfSopenharmony_ci#endif
954f08c3bdfSopenharmony_ci#ifdef sgi
955f08c3bdfSopenharmony_ci	int fd;
956f08c3bdfSopenharmony_ci	struct dioattr finfo;
957f08c3bdfSopenharmony_ci#endif
958f08c3bdfSopenharmony_ci
959f08c3bdfSopenharmony_ci	/*
960f08c3bdfSopenharmony_ci	 * Figure out if the files is regular, block or character special.  Any
961f08c3bdfSopenharmony_ci	 * other type is an error.
962f08c3bdfSopenharmony_ci	 */
963f08c3bdfSopenharmony_ci
964f08c3bdfSopenharmony_ci	if (stat(rec->f_path, &sbuf) == -1) {
965f08c3bdfSopenharmony_ci		fprintf(stderr,
966f08c3bdfSopenharmony_ci			"iogen%s: get_file_info():  Could not stat() %s:  %s\n",
967f08c3bdfSopenharmony_ci			TagName, rec->f_path, SYSERR);
968f08c3bdfSopenharmony_ci		return -1;
969f08c3bdfSopenharmony_ci	}
970f08c3bdfSopenharmony_ci#if _CRAY2
971f08c3bdfSopenharmony_ci	if ((!S_ISREG(sbuf.st_mode)) || strncmp(rec->f_path, "/dev/", 5) == 0) {
972f08c3bdfSopenharmony_ci		fprintf(stderr,
973f08c3bdfSopenharmony_ci			"iogen%s:  device level io not supported on cray2\n",
974f08c3bdfSopenharmony_ci			TagName);
975f08c3bdfSopenharmony_ci		return -1;
976f08c3bdfSopenharmony_ci	}
977f08c3bdfSopenharmony_ci#endif
978f08c3bdfSopenharmony_ci
979f08c3bdfSopenharmony_ci	rec->f_type = sbuf.st_mode & S_IFMT;
980f08c3bdfSopenharmony_ci
981f08c3bdfSopenharmony_ci	/*
982f08c3bdfSopenharmony_ci	 * If regular, iou is 1, and we must figure out the device on
983f08c3bdfSopenharmony_ci	 * which the file resides.  riou is the iou (logical sector size) of
984f08c3bdfSopenharmony_ci	 * this device.
985f08c3bdfSopenharmony_ci	 */
986f08c3bdfSopenharmony_ci
987f08c3bdfSopenharmony_ci	if (S_ISREG(sbuf.st_mode)) {
988f08c3bdfSopenharmony_ci		rec->f_iou = 1;
989f08c3bdfSopenharmony_ci		rec->f_length = sbuf.st_size;
990f08c3bdfSopenharmony_ci
991f08c3bdfSopenharmony_ci		/*
992f08c3bdfSopenharmony_ci		 * If -r used, take Rawmult as the raw/ssd io multiple.  Otherwise
993f08c3bdfSopenharmony_ci		 * attempt to determine it by looking at the device the file
994f08c3bdfSopenharmony_ci		 * resides on.
995f08c3bdfSopenharmony_ci		 */
996f08c3bdfSopenharmony_ci
997f08c3bdfSopenharmony_ci		if (r_opt) {
998f08c3bdfSopenharmony_ci			rec->f_riou = Rawmult;
999f08c3bdfSopenharmony_ci			return 0;
1000f08c3bdfSopenharmony_ci		}
1001f08c3bdfSopenharmony_ci#ifdef CRAY
1002f08c3bdfSopenharmony_ci		if (lk_rawdev(rec->f_path, dinfo.path, sizeof(dinfo.path), 0) ==
1003f08c3bdfSopenharmony_ci		    -1)
1004f08c3bdfSopenharmony_ci			return -1;
1005f08c3bdfSopenharmony_ci
1006f08c3bdfSopenharmony_ci		if (lk_devinfo(&dinfo, 0) == -1) {
1007f08c3bdfSopenharmony_ci			/* can't get raw I/O unit -- use stat to fudge it */
1008f08c3bdfSopenharmony_ci			rec->f_riou = sbuf.st_blksize;
1009f08c3bdfSopenharmony_ci		} else {
1010f08c3bdfSopenharmony_ci			rec->f_riou = ctob(dinfo.iou);
1011f08c3bdfSopenharmony_ci		}
1012f08c3bdfSopenharmony_ci#endif
1013f08c3bdfSopenharmony_ci#ifdef linux
1014f08c3bdfSopenharmony_ci		rec->f_riou = BSIZE;
1015f08c3bdfSopenharmony_ci#endif
1016f08c3bdfSopenharmony_ci#ifdef sgi
1017f08c3bdfSopenharmony_ci		if ((fd = open(rec->f_path, O_RDWR | O_DIRECT, 0)) != -1) {
1018f08c3bdfSopenharmony_ci			if (fcntl(fd, F_DIOINFO, &finfo) != -1) {
1019f08c3bdfSopenharmony_ci				rec->f_riou = finfo.d_miniosz;
1020f08c3bdfSopenharmony_ci			} else {
1021f08c3bdfSopenharmony_ci				fprintf(stderr,
1022f08c3bdfSopenharmony_ci					"iogen%s: Error %s (%d) getting direct I/O info of file %s\n",
1023f08c3bdfSopenharmony_ci					TagName, strerror(errno), errno,
1024f08c3bdfSopenharmony_ci					rec->f_path);
1025f08c3bdfSopenharmony_ci			}
1026f08c3bdfSopenharmony_ci			close(fd);
1027f08c3bdfSopenharmony_ci		} else {
1028f08c3bdfSopenharmony_ci			rec->f_riou = BBSIZE;
1029f08c3bdfSopenharmony_ci		}
1030f08c3bdfSopenharmony_ci#endif /* SGI */
1031f08c3bdfSopenharmony_ci
1032f08c3bdfSopenharmony_ci	} else {
1033f08c3bdfSopenharmony_ci
1034f08c3bdfSopenharmony_ci#ifdef CRAY
1035f08c3bdfSopenharmony_ci		/*
1036f08c3bdfSopenharmony_ci		 * Otherwise, file is a device.  Use lk_devinfo() to get its logical
1037f08c3bdfSopenharmony_ci		 * sector size.  This is the iou and riou
1038f08c3bdfSopenharmony_ci		 */
1039f08c3bdfSopenharmony_ci
1040f08c3bdfSopenharmony_ci		strcpy(dinfo.path, rec->f_path);
1041f08c3bdfSopenharmony_ci
1042f08c3bdfSopenharmony_ci		if (lk_devinfo(&dinfo, 0) == -1) {
1043f08c3bdfSopenharmony_ci			fprintf(stderr, "iogen%s: %s:  %s\n", TagName,
1044f08c3bdfSopenharmony_ci				Lk_err_func, Lk_err_mesg);
1045f08c3bdfSopenharmony_ci			return -1;
1046f08c3bdfSopenharmony_ci		}
1047f08c3bdfSopenharmony_ci
1048f08c3bdfSopenharmony_ci		rec->f_iou = ctob(dinfo.iou);
1049f08c3bdfSopenharmony_ci		rec->f_riou = ctob(dinfo.iou);
1050f08c3bdfSopenharmony_ci		rec->f_length = ctob(dinfo.length);
1051f08c3bdfSopenharmony_ci#else
1052f08c3bdfSopenharmony_ci#ifdef sgi
1053f08c3bdfSopenharmony_ci		rec->f_riou = BBSIZE;
1054f08c3bdfSopenharmony_ci		rec->f_length = BBSIZE;
1055f08c3bdfSopenharmony_ci#else
1056f08c3bdfSopenharmony_ci		rec->f_riou = BSIZE;
1057f08c3bdfSopenharmony_ci		rec->f_length = BSIZE;
1058f08c3bdfSopenharmony_ci#endif /* sgi */
1059f08c3bdfSopenharmony_ci#endif /* CRAY */
1060f08c3bdfSopenharmony_ci	}
1061f08c3bdfSopenharmony_ci
1062f08c3bdfSopenharmony_ci	return 0;
1063f08c3bdfSopenharmony_ci}
1064f08c3bdfSopenharmony_ci
1065f08c3bdfSopenharmony_ci/*
1066f08c3bdfSopenharmony_ci * Create file path as nbytes long.  If path exists, the file will either be
1067f08c3bdfSopenharmony_ci * extended or truncated to be nbytes long.  Returns final size of file,
1068f08c3bdfSopenharmony_ci * or -1 if there was a failure.
1069f08c3bdfSopenharmony_ci */
1070f08c3bdfSopenharmony_ci
1071f08c3bdfSopenharmony_ciint create_file(char *path, int nbytes)
1072f08c3bdfSopenharmony_ci{
1073f08c3bdfSopenharmony_ci	int fd, rval;
1074f08c3bdfSopenharmony_ci	char c;
1075f08c3bdfSopenharmony_ci	struct stat sbuf;
1076f08c3bdfSopenharmony_ci#ifdef sgi
1077f08c3bdfSopenharmony_ci	int nb;
1078f08c3bdfSopenharmony_ci	struct flock f;
1079f08c3bdfSopenharmony_ci	struct fsxattr xattr;
1080f08c3bdfSopenharmony_ci	struct dioattr finfo;
1081f08c3bdfSopenharmony_ci	char *b, *buf;
1082f08c3bdfSopenharmony_ci#endif
1083f08c3bdfSopenharmony_ci
1084f08c3bdfSopenharmony_ci	errno = 0;
1085f08c3bdfSopenharmony_ci	rval = stat(path, &sbuf);
1086f08c3bdfSopenharmony_ci
1087f08c3bdfSopenharmony_ci	if (rval == -1) {
1088f08c3bdfSopenharmony_ci		if (errno == ENOENT) {
1089f08c3bdfSopenharmony_ci			sbuf.st_size = 0;
1090f08c3bdfSopenharmony_ci		} else {
1091f08c3bdfSopenharmony_ci			fprintf(stderr,
1092f08c3bdfSopenharmony_ci				"iogen%s:  Could not stat file %s:  %s (%d)\n",
1093f08c3bdfSopenharmony_ci				TagName, path, SYSERR, errno);
1094f08c3bdfSopenharmony_ci			return -1;
1095f08c3bdfSopenharmony_ci		}
1096f08c3bdfSopenharmony_ci	} else {
1097f08c3bdfSopenharmony_ci		if (!S_ISREG(sbuf.st_mode)) {
1098f08c3bdfSopenharmony_ci			fprintf(stderr,
1099f08c3bdfSopenharmony_ci				"iogen%s:  file %s exists, but is not a regular file - cannot modify length\n",
1100f08c3bdfSopenharmony_ci				TagName, path);
1101f08c3bdfSopenharmony_ci			return -1;
1102f08c3bdfSopenharmony_ci		}
1103f08c3bdfSopenharmony_ci	}
1104f08c3bdfSopenharmony_ci
1105f08c3bdfSopenharmony_ci	if (sbuf.st_size == nbytes)
1106f08c3bdfSopenharmony_ci		return nbytes;
1107f08c3bdfSopenharmony_ci
1108f08c3bdfSopenharmony_ci	Oflags |= O_CREAT | O_WRONLY;
1109f08c3bdfSopenharmony_ci
1110f08c3bdfSopenharmony_ci	if ((fd = open(path, Oflags, 0666)) == -1) {
1111f08c3bdfSopenharmony_ci		fprintf(stderr,
1112f08c3bdfSopenharmony_ci			"iogen%s:  Could not create/open file %s: %s (%d)\n",
1113f08c3bdfSopenharmony_ci			TagName, path, SYSERR, errno);
1114f08c3bdfSopenharmony_ci		return -1;
1115f08c3bdfSopenharmony_ci	}
1116f08c3bdfSopenharmony_ci
1117f08c3bdfSopenharmony_ci	/*
1118f08c3bdfSopenharmony_ci	 * Truncate file if it is longer than nbytes, otherwise attempt to
1119f08c3bdfSopenharmony_ci	 * pre-allocate file blocks.
1120f08c3bdfSopenharmony_ci	 */
1121f08c3bdfSopenharmony_ci
1122f08c3bdfSopenharmony_ci	if (sbuf.st_size > nbytes) {
1123f08c3bdfSopenharmony_ci		if (ftruncate(fd, nbytes) == -1) {
1124f08c3bdfSopenharmony_ci			fprintf(stderr,
1125f08c3bdfSopenharmony_ci				"iogen%s:  Could not ftruncate() %s to %d bytes:  %s (%d)\n",
1126f08c3bdfSopenharmony_ci				TagName, path, nbytes, SYSERR, errno);
1127f08c3bdfSopenharmony_ci			close(fd);
1128f08c3bdfSopenharmony_ci			return -1;
1129f08c3bdfSopenharmony_ci		}
1130f08c3bdfSopenharmony_ci	} else {
1131f08c3bdfSopenharmony_ci
1132f08c3bdfSopenharmony_ci#ifdef sgi
1133f08c3bdfSopenharmony_ci		/*
1134f08c3bdfSopenharmony_ci		 *  The file must be designated as Real-Time before any data
1135f08c3bdfSopenharmony_ci		 *  is allocated to it.
1136f08c3bdfSopenharmony_ci		 *
1137f08c3bdfSopenharmony_ci		 */
1138f08c3bdfSopenharmony_ci		if (Orealtime != 0) {
1139f08c3bdfSopenharmony_ci			memset(&xattr, 0x00, sizeof(xattr));
1140f08c3bdfSopenharmony_ci			xattr.fsx_xflags = XFS_XFLAG_REALTIME;
1141f08c3bdfSopenharmony_ci			/*fprintf(stderr, "set: fsx_xflags = 0x%x\n", xattr.fsx_xflags); */
1142f08c3bdfSopenharmony_ci			if (fcntl(fd, F_FSSETXATTR, &xattr) == -1) {
1143f08c3bdfSopenharmony_ci				fprintf(stderr,
1144f08c3bdfSopenharmony_ci					"iogen%s: Error %s (%d) setting XFS XATTR->Realtime on file %s\n",
1145f08c3bdfSopenharmony_ci					TagName, SYSERR, errno, path);
1146f08c3bdfSopenharmony_ci				close(fd);
1147f08c3bdfSopenharmony_ci				return -1;
1148f08c3bdfSopenharmony_ci			}
1149f08c3bdfSopenharmony_ci#ifdef DEBUG
1150f08c3bdfSopenharmony_ci			if (fcntl(fd, F_FSGETXATTR, &xattr) == -1) {
1151f08c3bdfSopenharmony_ci				fprintf(stderr,
1152f08c3bdfSopenharmony_ci					"iogen%s: Error getting realtime flag %s (%d)\n",
1153f08c3bdfSopenharmony_ci					TagName, SYSERR, errno);
1154f08c3bdfSopenharmony_ci				close(fd);
1155f08c3bdfSopenharmony_ci				return -1;
1156f08c3bdfSopenharmony_ci			} else {
1157f08c3bdfSopenharmony_ci				fprintf(stderr, "get: fsx_xflags = 0x%x\n",
1158f08c3bdfSopenharmony_ci					xattr.fsx_xflags);
1159f08c3bdfSopenharmony_ci			}
1160f08c3bdfSopenharmony_ci#endif
1161f08c3bdfSopenharmony_ci		}
1162f08c3bdfSopenharmony_ci
1163f08c3bdfSopenharmony_ci		/*
1164f08c3bdfSopenharmony_ci		 * Reserve space with F_RESVSP
1165f08c3bdfSopenharmony_ci		 *
1166f08c3bdfSopenharmony_ci		 * Failure is ignored since F_RESVSP only works on XFS and the
1167f08c3bdfSopenharmony_ci		 * filesystem could be on EFS or NFS
1168f08c3bdfSopenharmony_ci		 */
1169f08c3bdfSopenharmony_ci		if (Oreserve) {
1170f08c3bdfSopenharmony_ci			f.l_whence = SEEK_SET;
1171f08c3bdfSopenharmony_ci			f.l_start = 0;
1172f08c3bdfSopenharmony_ci			f.l_len = nbytes;
1173f08c3bdfSopenharmony_ci
1174f08c3bdfSopenharmony_ci			/*fprintf(stderr,
1175f08c3bdfSopenharmony_ci			   "create_file: fcntl(%d, F_RESVSP, { %d, %lld, %lld })\n",
1176f08c3bdfSopenharmony_ci			   fd, f.l_whence, (long long)f.l_start, (long long)f.l_len); */
1177f08c3bdfSopenharmony_ci
1178f08c3bdfSopenharmony_ci			/* non-zeroing reservation */
1179f08c3bdfSopenharmony_ci			if (fcntl(fd, F_RESVSP, &f) == -1) {
1180f08c3bdfSopenharmony_ci				fprintf(stderr,
1181f08c3bdfSopenharmony_ci					"iogen%s:  Could not fcntl(F_RESVSP) %d bytes in file %s: %s (%d)\n",
1182f08c3bdfSopenharmony_ci					TagName, nbytes, path, SYSERR, errno);
1183f08c3bdfSopenharmony_ci				close(fd);
1184f08c3bdfSopenharmony_ci				return -1;
1185f08c3bdfSopenharmony_ci			}
1186f08c3bdfSopenharmony_ci		}
1187f08c3bdfSopenharmony_ci
1188f08c3bdfSopenharmony_ci		if (Oallocate) {
1189f08c3bdfSopenharmony_ci			/* F_ALLOCSP allocates from the start of the file to l_start */
1190f08c3bdfSopenharmony_ci			f.l_whence = SEEK_SET;
1191f08c3bdfSopenharmony_ci			f.l_start = nbytes;
1192f08c3bdfSopenharmony_ci			f.l_len = 0;
1193f08c3bdfSopenharmony_ci			/*fprintf(stderr,
1194f08c3bdfSopenharmony_ci			   "create_file: fcntl(%d, F_ALLOCSP, { %d, %lld, %lld })\n",
1195f08c3bdfSopenharmony_ci			   fd, f.l_whence, (long long)f.l_start,
1196f08c3bdfSopenharmony_ci			   (long long)f.l_len); */
1197f08c3bdfSopenharmony_ci
1198f08c3bdfSopenharmony_ci			/* zeroing reservation */
1199f08c3bdfSopenharmony_ci			if (fcntl(fd, F_ALLOCSP, &f) == -1) {
1200f08c3bdfSopenharmony_ci				fprintf(stderr,
1201f08c3bdfSopenharmony_ci					"iogen%s:  Could not fcntl(F_ALLOCSP) %d bytes in file %s: %s (%d)\n",
1202f08c3bdfSopenharmony_ci					TagName, nbytes, path, SYSERR, errno);
1203f08c3bdfSopenharmony_ci				close(fd);
1204f08c3bdfSopenharmony_ci				return -1;
1205f08c3bdfSopenharmony_ci			}
1206f08c3bdfSopenharmony_ci		}
1207f08c3bdfSopenharmony_ci#endif /* sgi */
1208f08c3bdfSopenharmony_ci
1209f08c3bdfSopenharmony_ci		/*
1210f08c3bdfSopenharmony_ci		 * Write a byte at the end of file so that stat() sets the right
1211f08c3bdfSopenharmony_ci		 * file size.
1212f08c3bdfSopenharmony_ci		 */
1213f08c3bdfSopenharmony_ci
1214f08c3bdfSopenharmony_ci#ifdef sgi
1215f08c3bdfSopenharmony_ci		if (Owrite == 2) {
1216f08c3bdfSopenharmony_ci			close(fd);
1217f08c3bdfSopenharmony_ci			if ((fd =
1218f08c3bdfSopenharmony_ci			     open(path, O_CREAT | O_RDWR | O_DIRECT,
1219f08c3bdfSopenharmony_ci				  0)) != -1) {
1220f08c3bdfSopenharmony_ci				if (fcntl(fd, F_DIOINFO, &finfo) == -1) {
1221f08c3bdfSopenharmony_ci					fprintf(stderr,
1222f08c3bdfSopenharmony_ci						"iogen%s: Error %s (%d) getting direct I/O info for file %s\n",
1223f08c3bdfSopenharmony_ci						TagName, SYSERR, errno, path);
1224f08c3bdfSopenharmony_ci					return -1;
1225f08c3bdfSopenharmony_ci				} else {
1226f08c3bdfSopenharmony_ci					/*fprintf(stderr, "%s: miniosz=%d\n",
1227f08c3bdfSopenharmony_ci					   path, finfo.d_miniosz); */
1228f08c3bdfSopenharmony_ci				}
1229f08c3bdfSopenharmony_ci			} else {
1230f08c3bdfSopenharmony_ci				fprintf(stderr,
1231f08c3bdfSopenharmony_ci					"iogen%s: Error %s (%d) opening file %s with flags O_CREAT|O_RDWR|O_DIRECT\n",
1232f08c3bdfSopenharmony_ci					TagName, SYSERR, errno, path);
1233f08c3bdfSopenharmony_ci				return -1;
1234f08c3bdfSopenharmony_ci			}
1235f08c3bdfSopenharmony_ci
1236f08c3bdfSopenharmony_ci			/*
1237f08c3bdfSopenharmony_ci			 * nb is nbytes adjusted down by an even d_miniosz block
1238f08c3bdfSopenharmony_ci			 *
1239f08c3bdfSopenharmony_ci			 * Note: the first adjustment can cause iogen to print a warning
1240f08c3bdfSopenharmony_ci			 *  about not being able to create a file of <nbytes> length,
1241f08c3bdfSopenharmony_ci			 *  since the file will be shorter.
1242f08c3bdfSopenharmony_ci			 */
1243f08c3bdfSopenharmony_ci			nb = nbytes - finfo.d_miniosz;
1244f08c3bdfSopenharmony_ci			nb = nb - nb % finfo.d_miniosz;
1245f08c3bdfSopenharmony_ci
1246f08c3bdfSopenharmony_ci			/*fprintf(stderr,
1247f08c3bdfSopenharmony_ci			   "create_file_ow2: lseek(%d, %d {%d %d}, SEEK_SET)\n",
1248f08c3bdfSopenharmony_ci			   fd, nb, nbytes, finfo.d_miniosz); */
1249f08c3bdfSopenharmony_ci
1250f08c3bdfSopenharmony_ci			if (lseek(fd, nb, SEEK_SET) == -1) {
1251f08c3bdfSopenharmony_ci				fprintf(stderr,
1252f08c3bdfSopenharmony_ci					"iogen%s:  Could not lseek() to EOF of file %s: %s (%d)\n\tactual offset %d file size goal %d miniosz %lld\n",
1253f08c3bdfSopenharmony_ci					TagName, path, SYSERR, errno,
1254f08c3bdfSopenharmony_ci					nb, nbytes, (long long)finfo.d_miniosz);
1255f08c3bdfSopenharmony_ci				close(fd);
1256f08c3bdfSopenharmony_ci				return -1;
1257f08c3bdfSopenharmony_ci			}
1258f08c3bdfSopenharmony_ci
1259f08c3bdfSopenharmony_ci			b = buf = malloc(finfo.d_miniosz + finfo.d_mem);
1260f08c3bdfSopenharmony_ci
1261f08c3bdfSopenharmony_ci			if (((long)buf % finfo.d_mem != 0)) {
1262f08c3bdfSopenharmony_ci				buf += finfo.d_mem - ((long)buf % finfo.d_mem);
1263f08c3bdfSopenharmony_ci			}
1264f08c3bdfSopenharmony_ci
1265f08c3bdfSopenharmony_ci			memset(buf, 0, finfo.d_miniosz);
1266f08c3bdfSopenharmony_ci
1267f08c3bdfSopenharmony_ci			if ((rval =
1268f08c3bdfSopenharmony_ci			     write(fd, buf,
1269f08c3bdfSopenharmony_ci				   finfo.d_miniosz)) != finfo.d_miniosz) {
1270f08c3bdfSopenharmony_ci				fprintf(stderr,
1271f08c3bdfSopenharmony_ci					"iogen%s:  Could not write %d byte length file %s: %s (%d)\n",
1272f08c3bdfSopenharmony_ci					TagName, nb, path, SYSERR, errno);
1273f08c3bdfSopenharmony_ci				fprintf(stderr, "\twrite(%d, 0x%lx, %d) = %d\n",
1274f08c3bdfSopenharmony_ci					fd, (long)buf, finfo.d_miniosz, rval);
1275f08c3bdfSopenharmony_ci				fprintf(stderr,
1276f08c3bdfSopenharmony_ci					"\toffset %d file size goal %d, miniosz=%d\n",
1277f08c3bdfSopenharmony_ci					nb, nbytes, finfo.d_miniosz);
1278f08c3bdfSopenharmony_ci				close(fd);
1279f08c3bdfSopenharmony_ci				return -1;
1280f08c3bdfSopenharmony_ci			}
1281f08c3bdfSopenharmony_ci			free(b);
1282f08c3bdfSopenharmony_ci		} else
1283f08c3bdfSopenharmony_ci#endif /* sgi */
1284f08c3bdfSopenharmony_ci		if (Owrite) {
1285f08c3bdfSopenharmony_ci			/*fprintf(stderr,
1286f08c3bdfSopenharmony_ci			   "create_file_Owrite: lseek(%d, %d {%d}, SEEK_SET)\n",
1287f08c3bdfSopenharmony_ci			   fd, nbytes-1, nbytes); */
1288f08c3bdfSopenharmony_ci
1289f08c3bdfSopenharmony_ci			if (lseek(fd, nbytes - 1, SEEK_SET) == -1) {
1290f08c3bdfSopenharmony_ci				fprintf(stderr,
1291f08c3bdfSopenharmony_ci					"iogen%s:  Could not lseek() to EOF in file %s:  %s (%d)\n\toffset goal %d\n",
1292f08c3bdfSopenharmony_ci					TagName, path, SYSERR, errno,
1293f08c3bdfSopenharmony_ci					nbytes - 1);
1294f08c3bdfSopenharmony_ci				close(fd);
1295f08c3bdfSopenharmony_ci				return -1;
1296f08c3bdfSopenharmony_ci			}
1297f08c3bdfSopenharmony_ci
1298f08c3bdfSopenharmony_ci			if ((rval = write(fd, &c, 1)) != 1) {
1299f08c3bdfSopenharmony_ci				fprintf(stderr,
1300f08c3bdfSopenharmony_ci					"iogen%s:  Could not create a %d byte length file %s: %s (%d)\n",
1301f08c3bdfSopenharmony_ci					TagName, nbytes, path, SYSERR, errno);
1302f08c3bdfSopenharmony_ci				fprintf(stderr,
1303f08c3bdfSopenharmony_ci					"\twrite(%d, 0x%lx, %d) = %d\n",
1304f08c3bdfSopenharmony_ci					fd, (long)&c, 1, rval);
1305f08c3bdfSopenharmony_ci				fprintf(stderr,
1306f08c3bdfSopenharmony_ci					"\toffset %d file size goal %d\n",
1307f08c3bdfSopenharmony_ci					nbytes - 1, nbytes);
1308f08c3bdfSopenharmony_ci				close(fd);
1309f08c3bdfSopenharmony_ci				return -1;
1310f08c3bdfSopenharmony_ci			}
1311f08c3bdfSopenharmony_ci		}
1312f08c3bdfSopenharmony_ci	}
1313f08c3bdfSopenharmony_ci
1314f08c3bdfSopenharmony_ci	fstat(fd, &sbuf);
1315f08c3bdfSopenharmony_ci	close(fd);
1316f08c3bdfSopenharmony_ci
1317f08c3bdfSopenharmony_ci	return sbuf.st_size;
1318f08c3bdfSopenharmony_ci}
1319f08c3bdfSopenharmony_ci
1320f08c3bdfSopenharmony_ci/*
1321f08c3bdfSopenharmony_ci * Function to convert a string to its corresponding value in a strmap array.
1322f08c3bdfSopenharmony_ci * If the string is not found in the array, the value corresponding to the
1323f08c3bdfSopenharmony_ci * NULL string (the last element in the array) is returned.
1324f08c3bdfSopenharmony_ci */
1325f08c3bdfSopenharmony_ci
1326f08c3bdfSopenharmony_ciint str_to_value(struct strmap *map, char *str)
1327f08c3bdfSopenharmony_ci{
1328f08c3bdfSopenharmony_ci	struct strmap *mp;
1329f08c3bdfSopenharmony_ci
1330f08c3bdfSopenharmony_ci	for (mp = map; mp->m_string != NULL; mp++)
1331f08c3bdfSopenharmony_ci		if (strcmp(mp->m_string, str) == 0)
1332f08c3bdfSopenharmony_ci			break;
1333f08c3bdfSopenharmony_ci
1334f08c3bdfSopenharmony_ci	return mp->m_value;
1335f08c3bdfSopenharmony_ci}
1336f08c3bdfSopenharmony_ci
1337f08c3bdfSopenharmony_ci/*
1338f08c3bdfSopenharmony_ci * Function to convert a string to its corresponding entry in a strmap array.
1339f08c3bdfSopenharmony_ci * If the string is not found in the array, a NULL is returned.
1340f08c3bdfSopenharmony_ci */
1341f08c3bdfSopenharmony_ci
1342f08c3bdfSopenharmony_cistruct strmap *str_lookup(struct strmap *map, char *str)
1343f08c3bdfSopenharmony_ci{
1344f08c3bdfSopenharmony_ci	struct strmap *mp;
1345f08c3bdfSopenharmony_ci
1346f08c3bdfSopenharmony_ci	for (mp = map; mp->m_string != NULL; mp++)
1347f08c3bdfSopenharmony_ci		if (strcmp(mp->m_string, str) == 0)
1348f08c3bdfSopenharmony_ci			break;
1349f08c3bdfSopenharmony_ci
1350f08c3bdfSopenharmony_ci	return ((mp->m_string == NULL) ? NULL : mp);
1351f08c3bdfSopenharmony_ci}
1352f08c3bdfSopenharmony_ci
1353f08c3bdfSopenharmony_ci/*
1354f08c3bdfSopenharmony_ci * Function to convert a value to its corresponding string in a strmap array.
1355f08c3bdfSopenharmony_ci * If the value is not found in the array, NULL is returned.
1356f08c3bdfSopenharmony_ci */
1357f08c3bdfSopenharmony_ci
1358f08c3bdfSopenharmony_cichar *value_to_string(struct strmap *map, int val)
1359f08c3bdfSopenharmony_ci{
1360f08c3bdfSopenharmony_ci	struct strmap *mp;
1361f08c3bdfSopenharmony_ci
1362f08c3bdfSopenharmony_ci	for (mp = map; mp->m_string != NULL; mp++)
1363f08c3bdfSopenharmony_ci		if (mp->m_value == val)
1364f08c3bdfSopenharmony_ci			break;
1365f08c3bdfSopenharmony_ci
1366f08c3bdfSopenharmony_ci	return mp->m_string;
1367f08c3bdfSopenharmony_ci}
1368f08c3bdfSopenharmony_ci
1369f08c3bdfSopenharmony_ci/*
1370f08c3bdfSopenharmony_ci * Interpret cmdline options/arguments.  Exit with 1 if something on the
1371f08c3bdfSopenharmony_ci * cmdline isn't kosher.
1372f08c3bdfSopenharmony_ci */
1373f08c3bdfSopenharmony_ci
1374f08c3bdfSopenharmony_ciint parse_cmdline(int argc, char **argv, char *opts)
1375f08c3bdfSopenharmony_ci{
1376f08c3bdfSopenharmony_ci	int o, len, nb, format_error;
1377f08c3bdfSopenharmony_ci	struct strmap *flgs, *sc;
1378f08c3bdfSopenharmony_ci	char *file, *cp, ch;
1379f08c3bdfSopenharmony_ci	extern int opterr;
1380f08c3bdfSopenharmony_ci	extern int optind;
1381f08c3bdfSopenharmony_ci	extern char *optarg;
1382f08c3bdfSopenharmony_ci	struct strmap *mp;
1383f08c3bdfSopenharmony_ci	struct file_info *fptr;
1384f08c3bdfSopenharmony_ci	int nopenargs;
1385f08c3bdfSopenharmony_ci	char *openargs[5];	/* Flags, cbits, cblks */
1386f08c3bdfSopenharmony_ci	char *errmsg;
1387f08c3bdfSopenharmony_ci	int str_to_int();
1388f08c3bdfSopenharmony_ci	opterr = 0;
1389f08c3bdfSopenharmony_ci#ifndef linux
1390f08c3bdfSopenharmony_ci	char *ranges;
1391f08c3bdfSopenharmony_ci	struct strmap *type;
1392f08c3bdfSopenharmony_ci#endif
1393f08c3bdfSopenharmony_ci
1394f08c3bdfSopenharmony_ci	while ((o = getopt(argc, argv, opts)) != EOF) {
1395f08c3bdfSopenharmony_ci		switch ((char)o) {
1396f08c3bdfSopenharmony_ci
1397f08c3bdfSopenharmony_ci		case 'a':
1398f08c3bdfSopenharmony_ci#ifdef linux
1399f08c3bdfSopenharmony_ci			fprintf(stderr,
1400f08c3bdfSopenharmony_ci				"iogen%s:  Unrecognized option -a on this platform\n",
1401f08c3bdfSopenharmony_ci				TagName);
1402f08c3bdfSopenharmony_ci			exit(2);
1403f08c3bdfSopenharmony_ci#else
1404f08c3bdfSopenharmony_ci			cp = strtok(optarg, ",");
1405f08c3bdfSopenharmony_ci			while (cp != NULL) {
1406f08c3bdfSopenharmony_ci				if ((type =
1407f08c3bdfSopenharmony_ci				     str_lookup(Aio_Strat_Map, cp)) == NULL) {
1408f08c3bdfSopenharmony_ci					fprintf(stderr,
1409f08c3bdfSopenharmony_ci						"iogen%s:  Unrecognized aio completion strategy:  %s\n",
1410f08c3bdfSopenharmony_ci						TagName, cp);
1411f08c3bdfSopenharmony_ci					exit(2);
1412f08c3bdfSopenharmony_ci				}
1413f08c3bdfSopenharmony_ci
1414f08c3bdfSopenharmony_ci				Aio_Strat_List[Naio_Strat_Types++] = type;
1415f08c3bdfSopenharmony_ci				cp = strtok(NULL, ",");
1416f08c3bdfSopenharmony_ci			}
1417f08c3bdfSopenharmony_ci			a_opt++;
1418f08c3bdfSopenharmony_ci#endif
1419f08c3bdfSopenharmony_ci			break;
1420f08c3bdfSopenharmony_ci
1421f08c3bdfSopenharmony_ci		case 'f':
1422f08c3bdfSopenharmony_ci			cp = strtok(optarg, ",");
1423f08c3bdfSopenharmony_ci			while (cp != NULL) {
1424f08c3bdfSopenharmony_ci				if ((flgs = str_lookup(Flag_Map, cp)) == NULL) {
1425f08c3bdfSopenharmony_ci					fprintf(stderr,
1426f08c3bdfSopenharmony_ci						"iogen%s:  Unrecognized flags:  %s\n",
1427f08c3bdfSopenharmony_ci						TagName, cp);
1428f08c3bdfSopenharmony_ci					exit(2);
1429f08c3bdfSopenharmony_ci				}
1430f08c3bdfSopenharmony_ci
1431f08c3bdfSopenharmony_ci				cp = strtok(NULL, ",");
1432f08c3bdfSopenharmony_ci
1433f08c3bdfSopenharmony_ci#ifdef O_SSD
1434f08c3bdfSopenharmony_ci				if (flgs->m_value & O_SSD && !Sds_Avail) {
1435f08c3bdfSopenharmony_ci					fprintf(stderr,
1436f08c3bdfSopenharmony_ci						"iogen%s:  Warning - no sds available, ignoring ssd flag\n",
1437f08c3bdfSopenharmony_ci						TagName);
1438f08c3bdfSopenharmony_ci					continue;
1439f08c3bdfSopenharmony_ci				}
1440f08c3bdfSopenharmony_ci#endif
1441f08c3bdfSopenharmony_ci
1442f08c3bdfSopenharmony_ci				Flag_List[Nflags++] = flgs;
1443f08c3bdfSopenharmony_ci			}
1444f08c3bdfSopenharmony_ci			f_opt++;
1445f08c3bdfSopenharmony_ci			break;
1446f08c3bdfSopenharmony_ci
1447f08c3bdfSopenharmony_ci		case 'h':
1448f08c3bdfSopenharmony_ci			help(stdout);
1449f08c3bdfSopenharmony_ci			exit(0);
1450f08c3bdfSopenharmony_ci			break;
1451f08c3bdfSopenharmony_ci
1452f08c3bdfSopenharmony_ci		case 'i':
1453f08c3bdfSopenharmony_ci			format_error = 0;
1454f08c3bdfSopenharmony_ci
1455f08c3bdfSopenharmony_ci			switch (sscanf(optarg, "%i%c", &Iterations, &ch)) {
1456f08c3bdfSopenharmony_ci			case 1:
1457f08c3bdfSopenharmony_ci				Time_Mode = 0;
1458f08c3bdfSopenharmony_ci				break;
1459f08c3bdfSopenharmony_ci
1460f08c3bdfSopenharmony_ci			case 2:
1461f08c3bdfSopenharmony_ci				if (ch == 's')
1462f08c3bdfSopenharmony_ci					Time_Mode = 1;
1463f08c3bdfSopenharmony_ci				else
1464f08c3bdfSopenharmony_ci					format_error = 1;
1465f08c3bdfSopenharmony_ci				break;
1466f08c3bdfSopenharmony_ci
1467f08c3bdfSopenharmony_ci			default:
1468f08c3bdfSopenharmony_ci				format_error = 1;
1469f08c3bdfSopenharmony_ci			}
1470f08c3bdfSopenharmony_ci
1471f08c3bdfSopenharmony_ci			if (Iterations < 0)
1472f08c3bdfSopenharmony_ci				format_error = 1;
1473f08c3bdfSopenharmony_ci
1474f08c3bdfSopenharmony_ci			if (format_error) {
1475f08c3bdfSopenharmony_ci				fprintf(stderr,
1476f08c3bdfSopenharmony_ci					"iogen%s:  Illegal -i arg (%s):  Must be of the format:  number[s]\n",
1477f08c3bdfSopenharmony_ci					TagName, optarg);
1478f08c3bdfSopenharmony_ci				fprintf(stderr,
1479f08c3bdfSopenharmony_ci					"        where 'number' is >= 0\n");
1480f08c3bdfSopenharmony_ci				exit(1);
1481f08c3bdfSopenharmony_ci			}
1482f08c3bdfSopenharmony_ci
1483f08c3bdfSopenharmony_ci			i_opt++;
1484f08c3bdfSopenharmony_ci			break;
1485f08c3bdfSopenharmony_ci
1486f08c3bdfSopenharmony_ci		case 'L':
1487f08c3bdfSopenharmony_ci#ifdef linux
1488f08c3bdfSopenharmony_ci			fprintf(stderr,
1489f08c3bdfSopenharmony_ci				"iogen%s:  Unrecognized option -L on this platform\n",
1490f08c3bdfSopenharmony_ci				TagName);
1491f08c3bdfSopenharmony_ci			exit(2);
1492f08c3bdfSopenharmony_ci#else
1493f08c3bdfSopenharmony_ci			if (parse_ranges(optarg, 1, 255, 1, NULL, &ranges,
1494f08c3bdfSopenharmony_ci					 &errmsg) == -1) {
1495f08c3bdfSopenharmony_ci				fprintf(stderr,
1496f08c3bdfSopenharmony_ci					"iogen%s: error parsing listio range '%s': %s\n",
1497f08c3bdfSopenharmony_ci					TagName, optarg, errmsg);
1498f08c3bdfSopenharmony_ci				exit(1);
1499f08c3bdfSopenharmony_ci			}
1500f08c3bdfSopenharmony_ci
1501f08c3bdfSopenharmony_ci			Minstrides = range_min(ranges, 0);
1502f08c3bdfSopenharmony_ci			Maxstrides = range_max(ranges, 0);
1503f08c3bdfSopenharmony_ci
1504f08c3bdfSopenharmony_ci			free(ranges);
1505f08c3bdfSopenharmony_ci			L_opt++;
1506f08c3bdfSopenharmony_ci#endif
1507f08c3bdfSopenharmony_ci			break;
1508f08c3bdfSopenharmony_ci
1509f08c3bdfSopenharmony_ci		case 'm':
1510f08c3bdfSopenharmony_ci			if ((Offset_Mode =
1511f08c3bdfSopenharmony_ci			     str_lookup(Omode_Map, optarg)) == NULL) {
1512f08c3bdfSopenharmony_ci				fprintf(stderr,
1513f08c3bdfSopenharmony_ci					"iogen%s:  Illegal -m arg (%s)\n",
1514f08c3bdfSopenharmony_ci					TagName, optarg);
1515f08c3bdfSopenharmony_ci				exit(1);
1516f08c3bdfSopenharmony_ci			}
1517f08c3bdfSopenharmony_ci
1518f08c3bdfSopenharmony_ci			m_opt++;
1519f08c3bdfSopenharmony_ci			break;
1520f08c3bdfSopenharmony_ci
1521f08c3bdfSopenharmony_ci		case 'N':
1522f08c3bdfSopenharmony_ci			sprintf(TagName, "(%.39s)", optarg);
1523f08c3bdfSopenharmony_ci			break;
1524f08c3bdfSopenharmony_ci
1525f08c3bdfSopenharmony_ci		case 'o':
1526f08c3bdfSopenharmony_ci			o_opt++;
1527f08c3bdfSopenharmony_ci			break;
1528f08c3bdfSopenharmony_ci
1529f08c3bdfSopenharmony_ci		case 'O':
1530f08c3bdfSopenharmony_ci
1531f08c3bdfSopenharmony_ci			nopenargs = string_to_tokens(optarg, openargs, 4, ":/");
1532f08c3bdfSopenharmony_ci
1533f08c3bdfSopenharmony_ci#ifdef CRAY
1534f08c3bdfSopenharmony_ci			if (nopenargs)
1535f08c3bdfSopenharmony_ci				sscanf(openargs[1], "%i", &Ocbits);
1536f08c3bdfSopenharmony_ci			if (nopenargs > 1)
1537f08c3bdfSopenharmony_ci				sscanf(openargs[2], "%i", &Ocblks);
1538f08c3bdfSopenharmony_ci
1539f08c3bdfSopenharmony_ci			Oflags = parse_open_flags(openargs[0], &errmsg);
1540f08c3bdfSopenharmony_ci			if (Oflags == -1) {
1541f08c3bdfSopenharmony_ci				fprintf(stderr, "iogen%s: -O %s error: %s\n",
1542f08c3bdfSopenharmony_ci					TagName, optarg, errmsg);
1543f08c3bdfSopenharmony_ci				exit(1);
1544f08c3bdfSopenharmony_ci			}
1545f08c3bdfSopenharmony_ci#endif
1546f08c3bdfSopenharmony_ci#ifdef linux
1547f08c3bdfSopenharmony_ci			Oflags = parse_open_flags(openargs[0], &errmsg);
1548f08c3bdfSopenharmony_ci			if (Oflags == -1) {
1549f08c3bdfSopenharmony_ci				fprintf(stderr, "iogen%s: -O %s error: %s\n",
1550f08c3bdfSopenharmony_ci					TagName, optarg, errmsg);
1551f08c3bdfSopenharmony_ci				exit(1);
1552f08c3bdfSopenharmony_ci			}
1553f08c3bdfSopenharmony_ci#endif
1554f08c3bdfSopenharmony_ci#ifdef sgi
1555f08c3bdfSopenharmony_ci			if (!strcmp(openargs[0], "realtime")) {
1556f08c3bdfSopenharmony_ci				/*
1557f08c3bdfSopenharmony_ci				 * -O realtime:extsize
1558f08c3bdfSopenharmony_ci				 */
1559f08c3bdfSopenharmony_ci				Orealtime = 1;
1560f08c3bdfSopenharmony_ci				if (nopenargs > 1)
1561f08c3bdfSopenharmony_ci					sscanf(openargs[1], "%i", &Oextsize);
1562f08c3bdfSopenharmony_ci				else
1563f08c3bdfSopenharmony_ci					Oextsize = 0;
1564f08c3bdfSopenharmony_ci			} else if (!strcmp(openargs[0], "allocate") ||
1565f08c3bdfSopenharmony_ci				   !strcmp(openargs[0], "allocsp")) {
1566f08c3bdfSopenharmony_ci				/*
1567f08c3bdfSopenharmony_ci				 * -O allocate
1568f08c3bdfSopenharmony_ci				 */
1569f08c3bdfSopenharmony_ci				Oreserve = 0;
1570f08c3bdfSopenharmony_ci				Oallocate = 1;
1571f08c3bdfSopenharmony_ci			} else if (!strcmp(openargs[0], "reserve")) {
1572f08c3bdfSopenharmony_ci				/*
1573f08c3bdfSopenharmony_ci				 * -O [no]reserve
1574f08c3bdfSopenharmony_ci				 */
1575f08c3bdfSopenharmony_ci				Oallocate = 0;
1576f08c3bdfSopenharmony_ci				Oreserve = 1;
1577f08c3bdfSopenharmony_ci			} else if (!strcmp(openargs[0], "noreserve")) {
1578f08c3bdfSopenharmony_ci				/* Oreserve=1 by default; this clears that default */
1579f08c3bdfSopenharmony_ci				Oreserve = 0;
1580f08c3bdfSopenharmony_ci			} else if (!strcmp(openargs[0], "nowrite")) {
1581f08c3bdfSopenharmony_ci				/* Owrite=1 by default; this clears that default */
1582f08c3bdfSopenharmony_ci				Owrite = 0;
1583f08c3bdfSopenharmony_ci			} else if (!strcmp(openargs[0], "direct")) {
1584f08c3bdfSopenharmony_ci				/* this means "use direct i/o to preallocate file" */
1585f08c3bdfSopenharmony_ci				Owrite = 2;
1586f08c3bdfSopenharmony_ci			} else {
1587f08c3bdfSopenharmony_ci				fprintf(stderr,
1588f08c3bdfSopenharmony_ci					"iogen%s: Error: -O %s error: unrecognized option\n",
1589f08c3bdfSopenharmony_ci					TagName, openargs[0]);
1590f08c3bdfSopenharmony_ci				exit(1);
1591f08c3bdfSopenharmony_ci			}
1592f08c3bdfSopenharmony_ci#endif
1593f08c3bdfSopenharmony_ci
1594f08c3bdfSopenharmony_ci			O_opt++;
1595f08c3bdfSopenharmony_ci			break;
1596f08c3bdfSopenharmony_ci
1597f08c3bdfSopenharmony_ci		case 'p':
1598f08c3bdfSopenharmony_ci			Outpipe = optarg;
1599f08c3bdfSopenharmony_ci			p_opt++;
1600f08c3bdfSopenharmony_ci			break;
1601f08c3bdfSopenharmony_ci
1602f08c3bdfSopenharmony_ci		case 'r':
1603f08c3bdfSopenharmony_ci			if ((Rawmult = bytes_by_prefix(optarg)) == -1 ||
1604f08c3bdfSopenharmony_ci			    Rawmult < 11 || Rawmult % BSIZE) {
1605f08c3bdfSopenharmony_ci				fprintf(stderr,
1606f08c3bdfSopenharmony_ci					"iogen%s:  Illegal -r arg (%s).  Must be > 0 and multipe of BSIZE (%d)\n",
1607f08c3bdfSopenharmony_ci					TagName, optarg, BSIZE);
1608f08c3bdfSopenharmony_ci				exit(1);
1609f08c3bdfSopenharmony_ci			}
1610f08c3bdfSopenharmony_ci
1611f08c3bdfSopenharmony_ci			r_opt++;
1612f08c3bdfSopenharmony_ci			break;
1613f08c3bdfSopenharmony_ci
1614f08c3bdfSopenharmony_ci		case 's':
1615f08c3bdfSopenharmony_ci			cp = strtok(optarg, ",");
1616f08c3bdfSopenharmony_ci			while (cp != NULL) {
1617f08c3bdfSopenharmony_ci				if ((sc = str_lookup(Syscall_Map, cp)) == NULL) {
1618f08c3bdfSopenharmony_ci					fprintf(stderr,
1619f08c3bdfSopenharmony_ci						"iogen%s:  Unrecognized syscall:  %s\n",
1620f08c3bdfSopenharmony_ci						TagName, cp);
1621f08c3bdfSopenharmony_ci					exit(2);
1622f08c3bdfSopenharmony_ci				}
1623f08c3bdfSopenharmony_ci
1624f08c3bdfSopenharmony_ci				do {
1625f08c3bdfSopenharmony_ci					/* >>> sc->m_flags & FLG_SDS */
1626f08c3bdfSopenharmony_ci					if (sc->m_value != SSREAD
1627f08c3bdfSopenharmony_ci					    && sc->m_value != SSWRITE)
1628f08c3bdfSopenharmony_ci						Fileio++;
1629f08c3bdfSopenharmony_ci
1630f08c3bdfSopenharmony_ci					Syscall_List[Nsyscalls++] = sc;
1631f08c3bdfSopenharmony_ci				} while ((sc = str_lookup(++sc, cp)) != NULL);
1632f08c3bdfSopenharmony_ci
1633f08c3bdfSopenharmony_ci				cp = strtok(NULL, ",");
1634f08c3bdfSopenharmony_ci			}
1635f08c3bdfSopenharmony_ci			s_opt++;
1636f08c3bdfSopenharmony_ci			break;
1637f08c3bdfSopenharmony_ci
1638f08c3bdfSopenharmony_ci		case 't':
1639f08c3bdfSopenharmony_ci			if ((Mintrans = bytes_by_prefix(optarg)) == -1) {
1640f08c3bdfSopenharmony_ci				fprintf(stderr,
1641f08c3bdfSopenharmony_ci					"iogen%s:  Illegal -t arg (%s):  Must have the form num[bkm]\n",
1642f08c3bdfSopenharmony_ci					TagName, optarg);
1643f08c3bdfSopenharmony_ci				exit(1);
1644f08c3bdfSopenharmony_ci			}
1645f08c3bdfSopenharmony_ci			t_opt++;
1646f08c3bdfSopenharmony_ci			break;
1647f08c3bdfSopenharmony_ci
1648f08c3bdfSopenharmony_ci		case 'T':
1649f08c3bdfSopenharmony_ci			if ((Maxtrans = bytes_by_prefix(optarg)) == -1) {
1650f08c3bdfSopenharmony_ci				fprintf(stderr,
1651f08c3bdfSopenharmony_ci					"iogen%s:  Illegal -T arg (%s):  Must have the form num[bkm]\n",
1652f08c3bdfSopenharmony_ci					TagName, optarg);
1653f08c3bdfSopenharmony_ci				exit(1);
1654f08c3bdfSopenharmony_ci			}
1655f08c3bdfSopenharmony_ci			T_opt++;
1656f08c3bdfSopenharmony_ci			break;
1657f08c3bdfSopenharmony_ci
1658f08c3bdfSopenharmony_ci		case 'q':
1659f08c3bdfSopenharmony_ci			q_opt++;
1660f08c3bdfSopenharmony_ci			break;
1661f08c3bdfSopenharmony_ci
1662f08c3bdfSopenharmony_ci		case '?':
1663f08c3bdfSopenharmony_ci			usage(stderr);
1664f08c3bdfSopenharmony_ci			exit(1);
1665f08c3bdfSopenharmony_ci		}
1666f08c3bdfSopenharmony_ci	}
1667f08c3bdfSopenharmony_ci
1668f08c3bdfSopenharmony_ci	/*
1669f08c3bdfSopenharmony_ci	 * Supply defaults
1670f08c3bdfSopenharmony_ci	 */
1671f08c3bdfSopenharmony_ci
1672f08c3bdfSopenharmony_ci	if (!L_opt) {
1673f08c3bdfSopenharmony_ci		Minstrides = 1;
1674f08c3bdfSopenharmony_ci		Maxstrides = 255;
1675f08c3bdfSopenharmony_ci	}
1676f08c3bdfSopenharmony_ci
1677f08c3bdfSopenharmony_ci	if (!m_opt)
1678f08c3bdfSopenharmony_ci		Offset_Mode = str_lookup(Omode_Map, "sequential");
1679f08c3bdfSopenharmony_ci
1680f08c3bdfSopenharmony_ci	if (!i_opt)
1681f08c3bdfSopenharmony_ci		Iterations = 0;
1682f08c3bdfSopenharmony_ci
1683f08c3bdfSopenharmony_ci	if (!t_opt)
1684f08c3bdfSopenharmony_ci		Mintrans = 1;
1685f08c3bdfSopenharmony_ci
1686f08c3bdfSopenharmony_ci	if (!T_opt)
1687f08c3bdfSopenharmony_ci		Maxtrans = 256 * BSIZE;
1688f08c3bdfSopenharmony_ci
1689f08c3bdfSopenharmony_ci	if (!O_opt)
1690f08c3bdfSopenharmony_ci		Oflags = Ocbits = Ocblks = 0;
1691f08c3bdfSopenharmony_ci
1692f08c3bdfSopenharmony_ci	/*
1693f08c3bdfSopenharmony_ci	 * Supply default async io completion strategy types.
1694f08c3bdfSopenharmony_ci	 */
1695f08c3bdfSopenharmony_ci
1696f08c3bdfSopenharmony_ci	if (!a_opt) {
1697f08c3bdfSopenharmony_ci		for (mp = Aio_Strat_Map; mp->m_string != NULL; mp++) {
1698f08c3bdfSopenharmony_ci			Aio_Strat_List[Naio_Strat_Types++] = mp;
1699f08c3bdfSopenharmony_ci		}
1700f08c3bdfSopenharmony_ci	}
1701f08c3bdfSopenharmony_ci
1702f08c3bdfSopenharmony_ci	/*
1703f08c3bdfSopenharmony_ci	 * Supply default syscalls.  Default is read,write,reada,writea,listio.
1704f08c3bdfSopenharmony_ci	 */
1705f08c3bdfSopenharmony_ci
1706f08c3bdfSopenharmony_ci	if (!s_opt) {
1707f08c3bdfSopenharmony_ci		Nsyscalls = 0;
1708f08c3bdfSopenharmony_ci		Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "read");
1709f08c3bdfSopenharmony_ci		Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "write");
1710f08c3bdfSopenharmony_ci#ifdef CRAY
1711f08c3bdfSopenharmony_ci		Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "reada");
1712f08c3bdfSopenharmony_ci		Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "writea");
1713f08c3bdfSopenharmony_ci		Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "lread");
1714f08c3bdfSopenharmony_ci		Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "lreada");
1715f08c3bdfSopenharmony_ci		Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "lwrite");
1716f08c3bdfSopenharmony_ci		Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "lwritea");
1717f08c3bdfSopenharmony_ci#endif
1718f08c3bdfSopenharmony_ci
1719f08c3bdfSopenharmony_ci#ifdef sgi
1720f08c3bdfSopenharmony_ci		Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "pread");
1721f08c3bdfSopenharmony_ci		Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "pwrite");
1722f08c3bdfSopenharmony_ci		/*Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "aread"); */
1723f08c3bdfSopenharmony_ci		/*Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "awrite"); */
1724f08c3bdfSopenharmony_ci#endif
1725f08c3bdfSopenharmony_ci
1726f08c3bdfSopenharmony_ci#ifndef CRAY
1727f08c3bdfSopenharmony_ci		Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "readv");
1728f08c3bdfSopenharmony_ci		Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "writev");
1729f08c3bdfSopenharmony_ci		Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "mmread");
1730f08c3bdfSopenharmony_ci		Syscall_List[Nsyscalls++] = str_lookup(Syscall_Map, "mmwrite");
1731f08c3bdfSopenharmony_ci#endif
1732f08c3bdfSopenharmony_ci
1733f08c3bdfSopenharmony_ci		Fileio = 1;
1734f08c3bdfSopenharmony_ci	}
1735f08c3bdfSopenharmony_ci
1736f08c3bdfSopenharmony_ci	if (Fileio && (argc - optind < 1)) {
1737f08c3bdfSopenharmony_ci		fprintf(stderr, "iogen%s:  No files specified on the cmdline\n",
1738f08c3bdfSopenharmony_ci			TagName);
1739f08c3bdfSopenharmony_ci		exit(1);
1740f08c3bdfSopenharmony_ci	}
1741f08c3bdfSopenharmony_ci
1742f08c3bdfSopenharmony_ci	/*
1743f08c3bdfSopenharmony_ci	 * Supply default file io flags - defaut is 'buffered,raw,sync,ldraw'.
1744f08c3bdfSopenharmony_ci	 */
1745f08c3bdfSopenharmony_ci
1746f08c3bdfSopenharmony_ci	if (!f_opt && Fileio) {
1747f08c3bdfSopenharmony_ci		Nflags = 0;
1748f08c3bdfSopenharmony_ci		Flag_List[Nflags++] = str_lookup(Flag_Map, "buffered");
1749f08c3bdfSopenharmony_ci		Flag_List[Nflags++] = str_lookup(Flag_Map, "sync");
1750f08c3bdfSopenharmony_ci#ifdef CRAY
1751f08c3bdfSopenharmony_ci		Flag_List[Nflags++] = str_lookup(Flag_Map, "raw+wf");
1752f08c3bdfSopenharmony_ci		Flag_List[Nflags++] = str_lookup(Flag_Map, "ldraw");
1753f08c3bdfSopenharmony_ci#endif
1754f08c3bdfSopenharmony_ci
1755f08c3bdfSopenharmony_ci#ifdef sgi
1756f08c3bdfSopenharmony_ci		/* Warning: cannot mix direct i/o with others! */
1757f08c3bdfSopenharmony_ci		Flag_List[Nflags++] = str_lookup(Flag_Map, "dsync");
1758f08c3bdfSopenharmony_ci		Flag_List[Nflags++] = str_lookup(Flag_Map, "rsync");
1759f08c3bdfSopenharmony_ci		/* Flag_List[Nflags++] = str_lookup(Flag_Map, "rsync+sync"); */
1760f08c3bdfSopenharmony_ci		/* Flag_List[Nflags++] = str_lookup(Flag_Map, "rsync+dsync"); */
1761f08c3bdfSopenharmony_ci#endif
1762f08c3bdfSopenharmony_ci	}
1763f08c3bdfSopenharmony_ci
1764f08c3bdfSopenharmony_ci	if (Fileio) {
1765f08c3bdfSopenharmony_ci		if (optind >= argc) {
1766f08c3bdfSopenharmony_ci			fprintf(stderr,
1767f08c3bdfSopenharmony_ci				"iogen%s:  No files listed on the cmdline\n",
1768f08c3bdfSopenharmony_ci				TagName);
1769f08c3bdfSopenharmony_ci			exit(1);
1770f08c3bdfSopenharmony_ci		}
1771f08c3bdfSopenharmony_ci
1772f08c3bdfSopenharmony_ci		/*
1773f08c3bdfSopenharmony_ci		 * Initialize File_List[] - only necessary if doing file io.  First
1774f08c3bdfSopenharmony_ci		 * space for the File_List array, then fill it in.
1775f08c3bdfSopenharmony_ci		 */
1776f08c3bdfSopenharmony_ci
1777f08c3bdfSopenharmony_ci		File_List = malloc((argc - optind) * sizeof(struct file_info));
1778f08c3bdfSopenharmony_ci
1779f08c3bdfSopenharmony_ci		if (File_List == NULL) {
1780f08c3bdfSopenharmony_ci			fprintf(stderr,
1781f08c3bdfSopenharmony_ci				"iogen%s:  Could not malloc space for %d file_info structures\n",
1782f08c3bdfSopenharmony_ci				TagName, argc - optind);
1783f08c3bdfSopenharmony_ci			exit(2);
1784f08c3bdfSopenharmony_ci		}
1785f08c3bdfSopenharmony_ci
1786f08c3bdfSopenharmony_ci		memset(File_List, 0,
1787f08c3bdfSopenharmony_ci		       (argc - optind) * sizeof(struct file_info));
1788f08c3bdfSopenharmony_ci
1789f08c3bdfSopenharmony_ci		Nfiles = 0;
1790f08c3bdfSopenharmony_ci		while (optind < argc) {
1791f08c3bdfSopenharmony_ci			len = -1;
1792f08c3bdfSopenharmony_ci
1793f08c3bdfSopenharmony_ci			/*
1794f08c3bdfSopenharmony_ci			 * Pick off leading len: if it's there and create/extend/trunc
1795f08c3bdfSopenharmony_ci			 * the file to the desired length.  Otherwise, just make sure
1796f08c3bdfSopenharmony_ci			 * the file is accessable.
1797f08c3bdfSopenharmony_ci			 */
1798f08c3bdfSopenharmony_ci
1799f08c3bdfSopenharmony_ci			if ((cp = strchr(argv[optind], ':')) != NULL) {
1800f08c3bdfSopenharmony_ci				*cp = '\0';
1801f08c3bdfSopenharmony_ci				if ((len = bytes_by_prefix(argv[optind])) == -1) {
1802f08c3bdfSopenharmony_ci					fprintf(stderr,
1803f08c3bdfSopenharmony_ci						"iogen%s:  illegal file length (%s) for file %s\n",
1804f08c3bdfSopenharmony_ci						TagName, argv[optind], cp + 1);
1805f08c3bdfSopenharmony_ci					exit(2);
1806f08c3bdfSopenharmony_ci				}
1807f08c3bdfSopenharmony_ci				*cp = ':';
1808f08c3bdfSopenharmony_ci				file = cp + 1;
1809f08c3bdfSopenharmony_ci
1810f08c3bdfSopenharmony_ci				if (strlen(file) > MAX_FNAME_LENGTH) {
1811f08c3bdfSopenharmony_ci					fprintf(stderr,
1812f08c3bdfSopenharmony_ci						"iogen%s:  Max fname length is %d chars - ignoring file %s\n",
1813f08c3bdfSopenharmony_ci						TagName, MAX_FNAME_LENGTH,
1814f08c3bdfSopenharmony_ci						file);
1815f08c3bdfSopenharmony_ci					optind++;
1816f08c3bdfSopenharmony_ci					continue;
1817f08c3bdfSopenharmony_ci				}
1818f08c3bdfSopenharmony_ci
1819f08c3bdfSopenharmony_ci				nb = create_file(file, len);
1820f08c3bdfSopenharmony_ci
1821f08c3bdfSopenharmony_ci				if (nb < len) {
1822f08c3bdfSopenharmony_ci					fprintf(stderr,
1823f08c3bdfSopenharmony_ci						"iogen%s warning:  Couldn't create file %s of %d bytes\n",
1824f08c3bdfSopenharmony_ci						TagName, file, len);
1825f08c3bdfSopenharmony_ci
1826f08c3bdfSopenharmony_ci					if (nb <= 0) {
1827f08c3bdfSopenharmony_ci						optind++;
1828f08c3bdfSopenharmony_ci						continue;
1829f08c3bdfSopenharmony_ci					}
1830f08c3bdfSopenharmony_ci				}
1831f08c3bdfSopenharmony_ci			} else {
1832f08c3bdfSopenharmony_ci				file = argv[optind];
1833f08c3bdfSopenharmony_ci				if (access(file, R_OK | W_OK) == -1) {
1834f08c3bdfSopenharmony_ci					fprintf(stderr,
1835f08c3bdfSopenharmony_ci						"iogen%s:  file %s cannot be accessed for reading and/or writing:  %s (%d)\n",
1836f08c3bdfSopenharmony_ci						TagName, file, SYSERR, errno);
1837f08c3bdfSopenharmony_ci					exit(2);
1838f08c3bdfSopenharmony_ci				}
1839f08c3bdfSopenharmony_ci			}
1840f08c3bdfSopenharmony_ci
1841f08c3bdfSopenharmony_ci			/*
1842f08c3bdfSopenharmony_ci			 * get per-file information
1843f08c3bdfSopenharmony_ci			 */
1844f08c3bdfSopenharmony_ci
1845f08c3bdfSopenharmony_ci			fptr = &File_List[Nfiles];
1846f08c3bdfSopenharmony_ci
1847f08c3bdfSopenharmony_ci			if (file[0] == '/') {
1848f08c3bdfSopenharmony_ci				strcpy(fptr->f_path, file);
1849f08c3bdfSopenharmony_ci			} else {
1850f08c3bdfSopenharmony_ci				if (getcwd
1851f08c3bdfSopenharmony_ci				    (fptr->f_path,
1852f08c3bdfSopenharmony_ci				     sizeof(fptr->f_path) - 1) == NULL)
1853f08c3bdfSopenharmony_ci					perror
1854f08c3bdfSopenharmony_ci					    ("Could not get current working directory");
1855f08c3bdfSopenharmony_ci				strcat(fptr->f_path, "/");
1856f08c3bdfSopenharmony_ci				strcat(fptr->f_path, file);
1857f08c3bdfSopenharmony_ci			}
1858f08c3bdfSopenharmony_ci
1859f08c3bdfSopenharmony_ci			if (get_file_info(fptr) == -1) {
1860f08c3bdfSopenharmony_ci				fprintf(stderr,
1861f08c3bdfSopenharmony_ci					"iogen%s warning:  Error getting file info for %s\n",
1862f08c3bdfSopenharmony_ci					TagName, file);
1863f08c3bdfSopenharmony_ci			} else {
1864f08c3bdfSopenharmony_ci
1865f08c3bdfSopenharmony_ci				/*
1866f08c3bdfSopenharmony_ci				 * If the file length is smaller than our min transfer size,
1867f08c3bdfSopenharmony_ci				 * ignore it.
1868f08c3bdfSopenharmony_ci				 */
1869f08c3bdfSopenharmony_ci
1870f08c3bdfSopenharmony_ci				if (fptr->f_length < Mintrans) {
1871f08c3bdfSopenharmony_ci					fprintf(stderr,
1872f08c3bdfSopenharmony_ci						"iogen%s warning:  Ignoring file %s\n",
1873f08c3bdfSopenharmony_ci						TagName, fptr->f_path);
1874f08c3bdfSopenharmony_ci					fprintf(stderr,
1875f08c3bdfSopenharmony_ci						"                length (%d) is < min transfer size (%d)\n",
1876f08c3bdfSopenharmony_ci						fptr->f_length, Mintrans);
1877f08c3bdfSopenharmony_ci					optind++;
1878f08c3bdfSopenharmony_ci					continue;
1879f08c3bdfSopenharmony_ci				}
1880f08c3bdfSopenharmony_ci
1881f08c3bdfSopenharmony_ci				/*
1882f08c3bdfSopenharmony_ci				 * If the file length is smaller than our max transfer size,
1883f08c3bdfSopenharmony_ci				 * ignore it.
1884f08c3bdfSopenharmony_ci				 */
1885f08c3bdfSopenharmony_ci
1886f08c3bdfSopenharmony_ci				if (fptr->f_length < Maxtrans) {
1887f08c3bdfSopenharmony_ci					fprintf(stderr,
1888f08c3bdfSopenharmony_ci						"iogen%s warning:  Ignoring file %s\n",
1889f08c3bdfSopenharmony_ci						TagName, fptr->f_path);
1890f08c3bdfSopenharmony_ci					fprintf(stderr,
1891f08c3bdfSopenharmony_ci						"                length (%d) is < max transfer size (%d)\n",
1892f08c3bdfSopenharmony_ci						fptr->f_length, Maxtrans);
1893f08c3bdfSopenharmony_ci					optind++;
1894f08c3bdfSopenharmony_ci					continue;
1895f08c3bdfSopenharmony_ci				}
1896f08c3bdfSopenharmony_ci
1897f08c3bdfSopenharmony_ci				if (fptr->f_length > 0) {
1898f08c3bdfSopenharmony_ci					switch (Offset_Mode->m_value) {
1899f08c3bdfSopenharmony_ci					case M_SEQUENTIAL:
1900f08c3bdfSopenharmony_ci						fptr->f_lastoffset = 0;
1901f08c3bdfSopenharmony_ci						fptr->f_lastlength = 0;
1902f08c3bdfSopenharmony_ci						break;
1903f08c3bdfSopenharmony_ci
1904f08c3bdfSopenharmony_ci					case M_REVERSE:
1905f08c3bdfSopenharmony_ci						fptr->f_lastoffset =
1906f08c3bdfSopenharmony_ci						    fptr->f_length;
1907f08c3bdfSopenharmony_ci						fptr->f_lastlength = 0;
1908f08c3bdfSopenharmony_ci						break;
1909f08c3bdfSopenharmony_ci
1910f08c3bdfSopenharmony_ci					case M_RANDOM:
1911f08c3bdfSopenharmony_ci						fptr->f_lastoffset =
1912f08c3bdfSopenharmony_ci						    fptr->f_length / 2;
1913f08c3bdfSopenharmony_ci						fptr->f_lastlength = 0;
1914f08c3bdfSopenharmony_ci						break;
1915f08c3bdfSopenharmony_ci					}
1916f08c3bdfSopenharmony_ci
1917f08c3bdfSopenharmony_ci					Nfiles++;
1918f08c3bdfSopenharmony_ci				}
1919f08c3bdfSopenharmony_ci			}
1920f08c3bdfSopenharmony_ci
1921f08c3bdfSopenharmony_ci			optind++;
1922f08c3bdfSopenharmony_ci		}
1923f08c3bdfSopenharmony_ci
1924f08c3bdfSopenharmony_ci		if (Nfiles == 0) {
1925f08c3bdfSopenharmony_ci			fprintf(stderr,
1926f08c3bdfSopenharmony_ci				"iogen%s:  Could not create, or gather info for any test files\n",
1927f08c3bdfSopenharmony_ci				TagName);
1928f08c3bdfSopenharmony_ci			exit(2);
1929f08c3bdfSopenharmony_ci		}
1930f08c3bdfSopenharmony_ci	}
1931f08c3bdfSopenharmony_ci
1932f08c3bdfSopenharmony_ci	return 0;
1933f08c3bdfSopenharmony_ci}
1934f08c3bdfSopenharmony_ci
1935f08c3bdfSopenharmony_ciint help(FILE * stream)
1936f08c3bdfSopenharmony_ci{
1937f08c3bdfSopenharmony_ci	usage(stream);
1938f08c3bdfSopenharmony_ci	fprintf(stream, "\n");
1939f08c3bdfSopenharmony_ci#ifndef linux
1940f08c3bdfSopenharmony_ci	fprintf(stream,
1941f08c3bdfSopenharmony_ci		"\t-a aio_type,...  Async io completion types to choose.  Supported types\n");
1942f08c3bdfSopenharmony_ci#ifdef CRAY
1943f08c3bdfSopenharmony_ci#if _UMK || RELEASE_LEVEL >= 8000
1944f08c3bdfSopenharmony_ci	fprintf(stream,
1945f08c3bdfSopenharmony_ci		"\t                 are:  poll, signal, recall, recalla, and recalls.\n");
1946f08c3bdfSopenharmony_ci#else
1947f08c3bdfSopenharmony_ci	fprintf(stream,
1948f08c3bdfSopenharmony_ci		"\t                 are:  poll, signal, recalla, and recalls.\n");
1949f08c3bdfSopenharmony_ci#endif
1950f08c3bdfSopenharmony_ci#else
1951f08c3bdfSopenharmony_ci	fprintf(stream,
1952f08c3bdfSopenharmony_ci		"\t                 are:  poll, signal, suspend, and callback.\n");
1953f08c3bdfSopenharmony_ci#endif
1954f08c3bdfSopenharmony_ci	fprintf(stream, "\t                 Default is all of the above.\n");
1955f08c3bdfSopenharmony_ci#else /* !linux */
1956f08c3bdfSopenharmony_ci	fprintf(stream, "\t-a               (Not used on Linux).\n");
1957f08c3bdfSopenharmony_ci#endif /* !linux */
1958f08c3bdfSopenharmony_ci	fprintf(stream,
1959f08c3bdfSopenharmony_ci		"\t-f flag,...      Flags to use for file IO.  Supported flags are\n");
1960f08c3bdfSopenharmony_ci#ifdef CRAY
1961f08c3bdfSopenharmony_ci	fprintf(stream,
1962f08c3bdfSopenharmony_ci		"\t                 raw, ssd, buffered, ldraw, sync,\n");
1963f08c3bdfSopenharmony_ci	fprintf(stream,
1964f08c3bdfSopenharmony_ci		"\t                 raw+wf, raw+wf+ldraw, raw+wf+ldraw+sync,\n");
1965f08c3bdfSopenharmony_ci	fprintf(stream,
1966f08c3bdfSopenharmony_ci		"\t                 and parallel (unicos/mk on MPP only).\n");
1967f08c3bdfSopenharmony_ci	fprintf(stream,
1968f08c3bdfSopenharmony_ci		"\t                 Default is 'raw,ldraw,sync,buffered'.\n");
1969f08c3bdfSopenharmony_ci#else
1970f08c3bdfSopenharmony_ci#ifdef sgi
1971f08c3bdfSopenharmony_ci	fprintf(stream,
1972f08c3bdfSopenharmony_ci		"\t                 buffered, direct, sync, dsync, rsync,\n");
1973f08c3bdfSopenharmony_ci	fprintf(stream, "\t                 rsync+dsync.\n");
1974f08c3bdfSopenharmony_ci	fprintf(stream,
1975f08c3bdfSopenharmony_ci		"\t                 Default is 'buffered,sync,dsync,rsync'.\n");
1976f08c3bdfSopenharmony_ci#else
1977f08c3bdfSopenharmony_ci	fprintf(stream, "\t                 buffered, sync.\n");
1978f08c3bdfSopenharmony_ci	fprintf(stream, "\t                 Default is 'buffered,sync'.\n");
1979f08c3bdfSopenharmony_ci#endif /* sgi */
1980f08c3bdfSopenharmony_ci#endif /* CRAY */
1981f08c3bdfSopenharmony_ci	fprintf(stream, "\t-h               This help.\n");
1982f08c3bdfSopenharmony_ci	fprintf(stream,
1983f08c3bdfSopenharmony_ci		"\t-i iterations[s] # of requests to generate.  0 means causes iogen\n");
1984f08c3bdfSopenharmony_ci	fprintf(stream,
1985f08c3bdfSopenharmony_ci		"\t                 to run until it's killed.  If iterations is suffixed\n");
1986f08c3bdfSopenharmony_ci	fprintf(stream,
1987f08c3bdfSopenharmony_ci		"\t                 with 's', then iterations is the number of seconds\n");
1988f08c3bdfSopenharmony_ci	fprintf(stream,
1989f08c3bdfSopenharmony_ci		"\t                 that iogen should run for.  Default is '0'.\n");
1990f08c3bdfSopenharmony_ci#ifndef linux
1991f08c3bdfSopenharmony_ci	fprintf(stream,
1992f08c3bdfSopenharmony_ci		"\t-L min:max       listio nstrides / nrequests range\n");
1993f08c3bdfSopenharmony_ci#else
1994f08c3bdfSopenharmony_ci	fprintf(stream, "\t-L               (Not used on Linux).\n");
1995f08c3bdfSopenharmony_ci#endif /* !linux */
1996f08c3bdfSopenharmony_ci	fprintf(stream,
1997f08c3bdfSopenharmony_ci		"\t-m offset-mode   The mode by which iogen chooses the offset for\n");
1998f08c3bdfSopenharmony_ci	fprintf(stream,
1999f08c3bdfSopenharmony_ci		"\t                 consectutive transfers within a given file.\n");
2000f08c3bdfSopenharmony_ci	fprintf(stream,
2001f08c3bdfSopenharmony_ci		"\t                 Allowed values are 'random', 'sequential',\n");
2002f08c3bdfSopenharmony_ci	fprintf(stream, "\t                 and 'reverse'.\n");
2003f08c3bdfSopenharmony_ci	fprintf(stream, "\t                 sequential is the default.\n");
2004f08c3bdfSopenharmony_ci	fprintf(stream, "\t-N tagname       Tag name, for Monster.\n");
2005f08c3bdfSopenharmony_ci	fprintf(stream,
2006f08c3bdfSopenharmony_ci		"\t-o               Form overlapping consecutive requests.\n");
2007f08c3bdfSopenharmony_ci	fprintf(stream, "\t-O               Open flags for creating files\n");
2008f08c3bdfSopenharmony_ci#ifdef CRAY
2009f08c3bdfSopenharmony_ci	fprintf(stream,
2010f08c3bdfSopenharmony_ci		"\t                 {O_PLACE,O_BIG,etc}[:CBITS[:CBLKS]]\n");
2011f08c3bdfSopenharmony_ci#endif
2012f08c3bdfSopenharmony_ci#ifdef sgi
2013f08c3bdfSopenharmony_ci	fprintf(stream,
2014f08c3bdfSopenharmony_ci		"\t                 realtime:extsize - put file on real-time volume\n");
2015f08c3bdfSopenharmony_ci	fprintf(stream,
2016f08c3bdfSopenharmony_ci		"\t                 allocate - allocate space with F_ALLOCSP\n");
2017f08c3bdfSopenharmony_ci	fprintf(stream,
2018f08c3bdfSopenharmony_ci		"\t                 reserve - reserve space with F_RESVSP (default)\n");
2019f08c3bdfSopenharmony_ci	fprintf(stream,
2020f08c3bdfSopenharmony_ci		"\t                 noreserve - do not reserve with F_RESVSP\n");
2021f08c3bdfSopenharmony_ci	fprintf(stream,
2022f08c3bdfSopenharmony_ci		"\t                 direct - use O_DIRECT I/O to write to the file\n");
2023f08c3bdfSopenharmony_ci#endif
2024f08c3bdfSopenharmony_ci#ifdef linux
2025f08c3bdfSopenharmony_ci	fprintf(stream, "\t                 {O_SYNC,etc}\n");
2026f08c3bdfSopenharmony_ci#endif
2027f08c3bdfSopenharmony_ci	fprintf(stream,
2028f08c3bdfSopenharmony_ci		"\t-p               Output pipe.  Default is stdout.\n");
2029f08c3bdfSopenharmony_ci	fprintf(stream,
2030f08c3bdfSopenharmony_ci		"\t-q               Quiet mode.  Normally iogen spits out info\n");
2031f08c3bdfSopenharmony_ci	fprintf(stream,
2032f08c3bdfSopenharmony_ci		"\t                 about test files, options, etc. before starting.\n");
2033f08c3bdfSopenharmony_ci	fprintf(stream,
2034f08c3bdfSopenharmony_ci		"\t-s syscall,...   Syscalls to do.  Supported syscalls are\n");
2035f08c3bdfSopenharmony_ci#ifdef sgi
2036f08c3bdfSopenharmony_ci	fprintf(stream,
2037f08c3bdfSopenharmony_ci		"\t                 read, write, pread, pwrite, readv, writev\n");
2038f08c3bdfSopenharmony_ci	fprintf(stream,
2039f08c3bdfSopenharmony_ci		"\t                 aread, awrite, resvsp, unresvsp, ffsync,\n");
2040f08c3bdfSopenharmony_ci	fprintf(stream,
2041f08c3bdfSopenharmony_ci		"\t                 mmread, mmwrite, fsync2, fdatasync,\n");
2042f08c3bdfSopenharmony_ci	fprintf(stream,
2043f08c3bdfSopenharmony_ci		"\t                 Default is 'read,write,pread,pwrite,readv,writev,mmread,mmwrite'.\n");
2044f08c3bdfSopenharmony_ci#endif
2045f08c3bdfSopenharmony_ci#ifdef CRAY
2046f08c3bdfSopenharmony_ci	fprintf(stream,
2047f08c3bdfSopenharmony_ci		"\t                 read, write, reada, writea, listio,\n");
2048f08c3bdfSopenharmony_ci	fprintf(stream,
2049f08c3bdfSopenharmony_ci		"\t                 ssread (PVP only), and sswrite (PVP only).\n");
2050f08c3bdfSopenharmony_ci	fprintf(stream,
2051f08c3bdfSopenharmony_ci		"\t                 Default is 'read,write,reada,writea,listio'.\n");
2052f08c3bdfSopenharmony_ci#endif
2053f08c3bdfSopenharmony_ci#ifdef linux
2054f08c3bdfSopenharmony_ci	fprintf(stream, "\t                 read, write, readv, writev,\n");
2055f08c3bdfSopenharmony_ci	fprintf(stream,
2056f08c3bdfSopenharmony_ci		"\t                 mmread, mmwrite, fsync2, fdatasync,\n");
2057f08c3bdfSopenharmony_ci	fprintf(stream,
2058f08c3bdfSopenharmony_ci		"\t                 Default is 'read,write,readv,writev,mmread,mmwrite'.\n");
2059f08c3bdfSopenharmony_ci#endif
2060f08c3bdfSopenharmony_ci	fprintf(stream, "\t-t mintrans      Min transfer length\n");
2061f08c3bdfSopenharmony_ci	fprintf(stream, "\t-T maxtrans      Max transfer length\n");
2062f08c3bdfSopenharmony_ci	fprintf(stream, "\n");
2063f08c3bdfSopenharmony_ci	fprintf(stream,
2064f08c3bdfSopenharmony_ci		"\t[len:]file,...   Test files to do IO against (note ssread/sswrite\n");
2065f08c3bdfSopenharmony_ci	fprintf(stream,
2066f08c3bdfSopenharmony_ci		"\t                 don't need a test file).  The len: syntax\n");
2067f08c3bdfSopenharmony_ci	fprintf(stream,
2068f08c3bdfSopenharmony_ci		"\t                 informs iogen to first create/expand/truncate the\n");
2069f08c3bdfSopenharmony_ci	fprintf(stream, "\t                 to the desired length.\n");
2070f08c3bdfSopenharmony_ci	fprintf(stream, "\n");
2071f08c3bdfSopenharmony_ci	fprintf(stream,
2072f08c3bdfSopenharmony_ci		"\tNote:  The ssd flag causes sds transfers to also be done.\n");
2073f08c3bdfSopenharmony_ci	fprintf(stream,
2074f08c3bdfSopenharmony_ci		"\t       To totally eliminate sds transfers, you must eleminate sds\n");
2075f08c3bdfSopenharmony_ci	fprintf(stream,
2076f08c3bdfSopenharmony_ci		"\t       from the flags (-f) and ssread,ssrite from the syscalls (-s)\n");
2077f08c3bdfSopenharmony_ci	fprintf(stream,
2078f08c3bdfSopenharmony_ci		"\tThe mintrans, maxtrans, and len: parameters are numbers of the\n");
2079f08c3bdfSopenharmony_ci	fprintf(stream,
2080f08c3bdfSopenharmony_ci		"\tform [0-9]+[bkm].  The optional trailing b, k, or m multiplies\n");
2081f08c3bdfSopenharmony_ci	fprintf(stream,
2082f08c3bdfSopenharmony_ci		"\tthe number by blocks, kilobytes, or megabytes.  If no trailing\n");
2083f08c3bdfSopenharmony_ci	fprintf(stream,
2084f08c3bdfSopenharmony_ci		"\tmultiplier is present, the number is interpreted as bytes\n");
2085f08c3bdfSopenharmony_ci
2086f08c3bdfSopenharmony_ci	return 0;
2087f08c3bdfSopenharmony_ci}
2088f08c3bdfSopenharmony_ci
2089f08c3bdfSopenharmony_ci/*
2090f08c3bdfSopenharmony_ci * Obvious - usage clause
2091f08c3bdfSopenharmony_ci */
2092f08c3bdfSopenharmony_ci
2093f08c3bdfSopenharmony_ciint usage(FILE * stream)
2094f08c3bdfSopenharmony_ci{
2095f08c3bdfSopenharmony_ci	fprintf(stream,
2096f08c3bdfSopenharmony_ci		"usage%s:  iogen [-hoq] [-a aio_type,...] [-f flag[,flag...]] [-i iterations] [-p outpipe] [-m offset-mode] [-s syscall[,syscall...]] [-t mintrans] [-T maxtrans] [ -O file-create-flags ] [[len:]file ...]\n",
2097f08c3bdfSopenharmony_ci		TagName);
2098f08c3bdfSopenharmony_ci	return 0;
2099f08c3bdfSopenharmony_ci}
2100