• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Disktest
3 * Copyright (c) International Business Machines Corp., 2001
4 *
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 *
20 *  Please send e-mail to yardleyb@us.ibm.com if you have
21 *  questions or comments.
22 *
23 *  Project Website:  TBD
24 *
25 * $Id: main.h,v 1.5 2008/02/14 08:22:23 subrata_modak Exp $
26 *
27 */
28 
29 #ifndef _DISKTEST_H
30 #define _DISKTEST_H
31 
32 #ifdef WINDOWS
33 #include <windows.h>
34 #include <winioctl.h>
35 #include <io.h>
36 #include <process.h>
37 #include <sys/stat.h>
38 #else
39 #include <pthread.h>
40 #include <sys/types.h>
41 #include <sys/ioctl.h>
42 #include <unistd.h>
43 #endif
44 
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <stdarg.h>
48 #include <signal.h>
49 #include <time.h>
50 #include <errno.h>
51 #include "defs.h"
52 #include "lapi/abisize.h"
53 
54 #define VER_STR "v1.4.2"
55 #define BLKGETSIZE _IO(0x12,96)		/* IOCTL for getting the device size */
56 #define BLKSSZGET  _IO(0x12,104)	/* ALT IOCTL for getting the device size */
57 
58 #define DEV_NAME_LEN		80		/* max character for target name */
59 #define MAX_ARG_LEN			160		/* max length of command line arguments for startarg display */
60 #define HOSTNAME_SIZE		16		/* number of hostname characters used in mark header */
61 #define BLK_SIZE			512		/* default size of an LBA in bytes */
62 #define ALIGNSIZE			4096	/* memory alignment size in bytes */
63 #define DEFAULT_IO_TIMEOUT	120		/* the default number of seconds before IO timeout */
64 
65 /* the new way we align */
66 #define ALIGN(x, y) (((long long unsigned)x/(long long unsigned)y)*(long long unsigned)y)
67 
68 #ifdef TST_ABI64
69 /* the old way we use to align */
70 /* #define ALIGN(x, bs) (((OFF_T)x + ((OFF_T)bs - 1)) & ~((OFF_T)bs - 1)) */
71 #define BUFALIGN(x) (void *) (((unsigned long)x + (OFF_T)(ALIGNSIZE - 1)) & (OFF_T)~(ALIGNSIZE - 1))
72 #else
73 /* the old way we use to align */
74 /* #define ALIGN(x, bs) ((x + (bs - 1)) & ~(bs - 1)) */
75 #define BUFALIGN(x) (void *) (((unsigned long)x + (ALIGNSIZE - 1)) & ~(ALIGNSIZE - 1))
76 #endif
77 
78 #define MASK(x,y) (x & y)
79 
80 /* each is a 64b number.  offsets are in 8B*offset placement */
81 #define OFF_RLBA	0	/* offset in memseg of current read LBA */
82 #define OFF_WLBA	1	/* offset in memseg of current write LBA */
83 
84 #define BMP_OFFSET	2*sizeof(OFF_T)		/* bitmap starts here */
85 
86 #define TST_STS(x)			(x & 0x1)	/* current testing status */
87 #define SET_STS_PASS(x)		(x | 0x01)
88 #define SET_STS_FAIL(x)		(x & ~0x01)
89 #define TST_wFST_TIME(x)	(x & 0x02)	/* first write lba access */
90 #define SET_wFST_TIME(x)	(x | 0x02)
91 #define CLR_wFST_TIME(x)	(x & ~0x02)
92 #define TST_rFST_TIME(x)	(x & 0x04)	/* first read lba access */
93 #define SET_rFST_TIME(x)	(x | 0x04)
94 #define CLR_rFST_TIME(x)	(x & ~0x04)
95 #define TST_DIRCTN(x)	(x & 0x08)		/* lba inc/dec 1 is inc, 0 is dec */
96 #define DIRCT_INC(x)    (x | 0x08)
97 #define DIRCT_DEC(x)    (x & ~0x08)
98 #define DIRCT_CNG(x)    (x & 0x08) ? (x & ~0x08) : (x | 0x08)
99 #define TST_OPER(x) (short) ((x & 0x10) >> 4)	/* last transfer operation (write = 0, read = 1) */
100 #define SET_OPER_R(x)	(x | 0x10)
101 #define SET_OPER_W(x)	(x & ~0x10)
102 #define CNG_OPER(x)		(x & 0x10) ? (x & ~0x10) : (x | 0x10)
103 
104 #define CLD_FLG_CMPR		0x0000000000000001ULL	/* will cause readers to compare data read */
105 #define CLD_FLG_MBLK		0x0000000000000002ULL	/* will add header info to first block, fc lun, lba, etc */
106 #define CLD_FLG_OFFSET		0x0000000000000004ULL	/* specifies that an offset up to 2^31 LBAs has been given */
107 #define CLD_FLG_RTRSIZ		0x0000000000000008ULL	/* Ignore weither a block has been written */
108 
109 /* Perforamnce Flags */
110 #define CLD_FLG_XFERS		0x0000000000000010ULL	/* reports # of transfers */
111 #define CLD_FLG_TPUTS		0x0000000000000020ULL	/* reports calculated throughtput */
112 #define CLD_FLG_RUNT		0x0000000000000040ULL	/* reports run time */
113 #define CLD_FLG_PCYC		0x0000000000000080ULL	/* report cycle data */
114 #define CLD_FLG_PRFTYPS	(CLD_FLG_XFERS|CLD_FLG_TPUTS|CLD_FLG_RUNT|CLD_FLG_PCYC)
115 
116 /* Seek Flags */
117 #define CLD_FLG_RANDOM		0x0000000000000100ULL	/* child seeks are random */
118 #define CLD_FLG_LINEAR		0x0000000000000200ULL	/* child seeks are linear */
119 #define CLD_FLG_NTRLVD		0x0000000000000400ULL	/* reads and writes are interleaved */
120 #define CLD_FLG_SKTYPS	(CLD_FLG_RANDOM|CLD_FLG_LINEAR)
121 
122 #define CLD_FLG_VSIZ		0x0000000000000800ULL	/* Volume size is user specified */
123 
124 /* IO Type Flags */
125 #define CLD_FLG_RAW			0x0000000000001000ULL	/* child IO is to a raw/character device */
126 #define CLD_FLG_BLK			0x0000000000002000ULL	/* child IO is to a block device */
127 #define CLD_FLG_FILE		0x0000000000004000ULL	/* child IO is to a file */
128 #define CLD_FLG_DIRECT		0x0000000000008000ULL	/* child IO has direct disk access */
129 #define CLD_FLG_IOTYPS	(CLD_FLG_RAW|CLD_FLG_BLK|CLD_FLG_FILE|CLD_FLG_DIRECT)
130 
131 /* Pattern Flags */
132 #define CLD_FLG_RPTYPE		0x0000000000010000ULL	/* random pattern */
133 #define CLD_FLG_FPTYPE		0x0000000000020000ULL	/* fixed pattern */
134 #define CLD_FLG_CPTYPE		0x0000000000040000ULL	/* counting pattern */
135 #define CLD_FLG_LPTYPE		0x0000000000080000ULL	/* lba pattern */
136 #define CLD_FLG_PTYPS	(CLD_FLG_RPTYPE|CLD_FLG_FPTYPE|CLD_FLG_CPTYPE|CLD_FLG_LPTYPE)
137 
138 /* Duration Flags */
139 #define CLD_FLG_TMD			0x0000000000100000ULL	/* set if using time */
140 #define CLD_FLG_SKS			0x0000000000200000ULL	/* set if seeks are used */
141 #define CLD_FLG_CYC			0x0000000000400000ULL	/* set if cycles are used */
142 #define CLD_FLG_DUTY		0x0000000000800000ULL	/* set if a duty cycle is used while running */
143 
144 #define CLD_FLG_LBA_RNG		0x0000000001000000ULL	/* write multipule read multipule, must define multiple */
145 #define CLD_FLG_BLK_RNG		0x0000000002000000ULL	/* write once read multiple, must define multiple */
146 #define CLD_FLG_ALLDIE		0x0000000004000000ULL	/* will force all children to die on any error if set */
147 #define CLD_FLG_DUMP		0x0000000008000000ULL	/* will dump formatted data */
148 
149 #define CLD_FLG_LUNU		0x0000000010000000ULL	/* seek start/end and then start/end */
150 #define CLD_FLG_LUND		0x0000000020000000ULL	/* seek start/end and then end/start */
151 #define CLD_FLG_W			0x0000000040000000ULL	/* there are child writers */
152 #define CLD_FLG_R			0x0000000080000000ULL	/* there are child readers */
153 
154 #define CLD_FLG_FSLIST		0x0000000100000000ULL	/* the filespec is a list of targets */
155 #define CLD_FLG_HBEAT		0x0000000200000000ULL	/* if performance heartbeat is being used */
156 #define CLD_FLG_WFSYNC		0x0000000400000000ULL	/* do an fsync on write for file IO */
157 #define FLAG_NOT_DEFINED	0x0000000800000000ULL	/* NOT DEFINED */
158 
159 #define CLD_FLG_WRITE_ONCE	0x0000001000000000ULL	/* only write once to each LBA */
160 #define CLD_FLG_ERR_REREAD	0x0000002000000000ULL	/* On miscompare, reread the miscompare transfer */
161 #define CLD_FLG_LBA_SYNC	0x0000004000000000ULL	/* LBA syncronizion */
162 #define CLD_FLG_IO_SERIAL	0x0000008000000000ULL	/* serialize IO at the IO operation level */
163 
164 #define CLD_FLG_MRK_LBA		0x0000010000000000ULL	/* enable adding LBA to mark data */
165 #define CLD_FLG_MRK_PASS	0x0000020000000000ULL	/* enable adding pass count to mark data */
166 #define CLD_FLG_MRK_TIME	0x0000040000000000ULL	/* enable adding start time to mark data */
167 #define CLD_FLG_MRK_SEED	0x0000080000000000ULL	/* enable adding seed to mark data */
168 #define CLD_FLG_MRK_HOST	0x0000100000000000ULL	/* enable adding hostname to mark data */
169 #define CLD_FLG_MRK_TARGET	0x0000200000000000ULL	/* enable adding target name to mark data */
170 #define CLD_FLG_MRK_ALL	(CLD_FLG_MRK_LBA|CLD_FLG_MRK_PASS|CLD_FLG_MRK_TIME|CLD_FLG_MRK_SEED|CLD_FLG_MRK_HOST|CLD_FLG_MRK_TARGET)
171 
172 #define CLD_FLG_ALT_MARK	0x0000400000000000ULL	/* override time marker, with data in alt_mark, in mark header */
173 #define CLD_FLG_ERR_MARK	0x0000800000000000ULL	/* On error, write a special MARKER to LBA 0 on the target */
174 
175 #define CLD_FLG_TMO_ERROR	0x0001000000000000ULL	/* make an IO TIMEOUT warning, fail the IO test */
176 #define CLD_FLG_UNIQ_WRT	0x0002000000000000ULL	/* garentees that every write is unique */
177 
178 /* startup defaults */
179 #define TRSIZ	1		/* default transfer size in blocks */
180 #define VSIZ	2000	/* default volume capacity in LBAs */
181 #define SEEKS	1000	/* default seeks */
182 #define KIDS	4		/* default number of children */
183 
184 #ifdef WINDOWS
185 typedef HANDLE hThread_t;
186 #else
187 typedef pthread_t hThread_t;
188 #endif
189 
190 typedef struct thread_struct {
191 	hThread_t hThread;
192 	BOOL bCanBeJoined;
193 	struct thread_struct *next; /* pointer to next thread */
194 } thread_struct_t;
195 
196 typedef struct stats {
197 	OFF_T wcount;
198 	OFF_T rcount;
199 	OFF_T wbytes;
200 	OFF_T rbytes;
201 	time_t wtime;
202 	time_t rtime;
203 } stats_t;
204 
205 typedef struct child_args {
206 	char device[DEV_NAME_LEN];	/* device name */
207 	char argstr[MAX_ARG_LEN];	/* human readable argument string /w assumtions */
208 	OFF_T vsiz;					/* volume size in blocks */
209 	unsigned long ltrsiz;		/* low bound of transfer size in blocks */
210 	unsigned long htrsiz;		/* high bound of transfer size in blocks */
211 	long offset;				/* the lba offset to shift IO alignment by */
212 	OFF_T pattern;				/* pattern data */
213 	time_t run_time;			/* run time in seconds */
214 	OFF_T seeks;				/* number of seeks */
215 	unsigned long cycles;		/* number of cycles */
216 	OFF_T start_blk;			/* starting transfer block */
217 	OFF_T stop_blk;				/* ending transfer block */
218 	OFF_T start_lba;			/* starting LBA */
219 	OFF_T stop_lba;				/* ending LBA */
220 	unsigned int retries;		/* number of retries */
221 	time_t hbeat;				/* Statistics will be reported every hbeats seconds */
222 	unsigned long long flags;	/* common flags that a child uses */
223 	unsigned long rcount;		/* number of reads a child should perform, 0 is unbound  */
224 	unsigned long wcount;		/* number of writes a child should perform, 0 is unbound  */
225 	short rperc;				/* percent of IO that should be reads */
226 	short wperc;				/* percent of IO that should be write */
227 	unsigned short t_kids;		/* total children, max is 64k */
228 	unsigned int cmp_lng;		/* how much of the data should be compared */
229 	OFF_T test_state;			/* current test state */
230 	unsigned int seed;			/* test seed */
231 	pid_t pid;					/* the process_id used for this environment */
232 	OFF_T alt_mark;				/* alternate marker the start time */
233 	unsigned long delayTimeMin;	/* the minimum time (msec) to delay on each IO */
234 	unsigned long delayTimeMax;	/* the maximum time (msec) to delay on each IO */
235 	time_t ioTimeout;			/* the time (sec) before failure do to possible hung IO */
236 	unsigned long sync_interval;/* number of write IOs before issuing a sync */
237 	long retry_delay;			/* number of msec to wait before retrying an IO */
238 } child_args_t;
239 
240 typedef struct mutexs {
241 #ifdef WINDOWS
242 	HANDLE MutexACTION;			/* mutex for the entire target device */
243 	HANDLE MutexIO;				/* mutex for the IO to the device */
244 #else
245 	pthread_mutex_t MutexACTION; /* mutex for the entire target device */
246 	pthread_mutex_t MutexIO;	/* mutex for the IO to the device */
247 #endif
248 } mutexs_t;
249 
250 typedef struct test_env {
251 	void *shared_mem;           /* global pointer to shared memory */
252 	unsigned char *data_buffer; /* global data buffer */
253 	size_t bmp_siz;             /* size of bitmask */
254 	BOOL bContinue;             /* global that when set to false will force exit for this environment */
255 	OFF_T pass_count;           /* pass counters */
256 	stats_t hbeat_stats;        /* per heartbeat statistics */
257 	stats_t cycle_stats;        /* per cycle statistics */
258 	stats_t global_stats;       /* per env statistics */
259 	OFF_T rcount;				/* number of read IO operations */
260 	OFF_T wcount;				/* number of write IO operations */
261 	unsigned short kids;		/* number of test child processes */
262 	thread_struct_t *pThreads;  /* List of child test processes */
263 	time_t start_time;			/*	overall start time of test	*/
264 	time_t end_time;			/*	overall end time of test	*/
265 	action_t lastAction;		/* when interleaving tests, tells the threads whcih action was last */
266 	action_t *action_list;		/* pointer to list of actions that are currently in use */
267 	int action_list_entry;		/* where in the action_list we are */
268 	mutexs_t mutexs;
269 } test_env_t;
270 
271 typedef struct test_ll {
272 	test_env_t *env;			/* pointer to the environment structure */
273 	child_args_t *args;			/* pointer to the argument structure */
274 	hThread_t hThread;
275 	struct test_ll *next;		/* pointer to the next test */
276 } test_ll_t;
277 
278 #endif /* _DISKTEST_H */
279