1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  *
25  * Portions Copyright 2008 Denis Cheng
26  */
27 
28 #ifndef _FB_FILEBENCH_H
29 #define	_FB_FILEBENCH_H
30 
31 #include "config.h"
32 
33 #include <stdlib.h>
34 #include <unistd.h>
35 #include <sys/stat.h>
36 #include <sys/types.h>
37 #include <sys/param.h>
38 #include <sys/resource.h>
39 #include <pthread.h>
40 #include <signal.h>
41 #ifndef HAVE_SYSV_SEM
42 #include <semaphore.h>
43 #endif
44 #include <stdio.h>
45 #include <string.h>
46 #include <errno.h>
47 #include <sys/times.h>
48 #ifdef HAVE_STDINT_H
49 #include <stdint.h>
50 #endif
51 /* We use __STDC__ to determine
52 how to handle functions with variable
53 number of arguments in filbench_log
54 function */
55 #ifdef __STDC__
56 #include <stdarg.h>
57 #define	__V(x)  x
58 #ifndef __P
59 #define	__P(x)  x
60 #endif
61 #else
62 #include <varargs.h>
63 #define	__V(x)  (va_alist) va_dcl
64 #define	__P(x)  ()
65 #define	const
66 #endif
67 #ifdef HAVE_AIO
68 #include <aio.h>
69 #endif
70 #include <dirent.h>
71 
72 /* Defining our internal types */
73 typedef uint64_t fbint_t;
74 #ifndef HAVE_BOOLEAN_T
75 typedef enum { B_FALSE, B_TRUE } boolean_t;
76 #endif
77 #define	TRUE 1
78 #define	FALSE 0
79 #ifndef HAVE_U_LONGLONG_T
80 typedef unsigned long long u_longlong_t;
81 #endif
82 #ifndef HAVE_UINT_T
83 typedef unsigned int uint_t;
84 #endif
85 #ifndef MIN
86 /* not defined on OpenSolaris */
87 #define MIN(a,b) (((a)<(b))?(a):(b))
88 #endif
89 /* change 64-postfixed defininition to the regular: on FreeBSD
90    all these function are already 64bit  */
91 #ifndef HAVE_OFF64_T
92 	#define off64_t off_t
93 #endif
94 #ifndef HAVE_STAT64
95 	/* this will replace both: struct stat64 and function stat64 */
96 	#define stat64 stat
97 #endif
98 #ifndef HAVE_AIO_ERROR64
99 	#define aio_error64 aio_error
100 #endif
101 #ifndef HAVE_AIO_WRITE64
102 	#define aio_write64 aio_write
103 	#define aiocb64 aiocb
104 #endif
105 #ifndef HAVE_AIO_RETURN64
106 	#define aio_return64 aio_return
107 #endif
108 #ifndef HAVE_OPEN64
109 	#define open64 open
110 #endif
111 #ifndef HAVE_MMAP64
112 	#define mmap64 mmap
113 #endif
114 #ifndef HAVE_FSTAT64
115 	#define fstat64 fstat
116 #endif
117 #ifndef HAVE_LSEEK64
118 	#define lseek64 lseek
119 #endif
120 #ifndef HAVE_PWRITE64
121 	#define pwrite64 pwrite
122 #endif
123 #ifndef HAVE_PREAD64
124 	#define pread64 pread
125 #endif
126 
127 #include "flag.h"
128 #include "vars.h"
129 #include "fb_cvar.h"
130 #include "fb_avl.h"
131 #include "stats.h"
132 #include "procflow.h"
133 #include "misc.h"
134 #include "fsplug.h"
135 #include "fileset.h"
136 #include "threadflow.h"
137 #include "flowop.h"
138 #include "fb_random.h"
139 #include "ipc.h"
140 
141 extern pid_t my_pid;		/* this process' process id */
142 extern procflow_t *my_procflow;	/* if slave process, procflow pointer */
143 extern int errno;
144 extern char *execname;
145 
146 void filebench_log __V((int level, const char *fmt, ...));
147 void filebench_shutdown(int error);
148 void filebench_plugin_funcvecinit(void);
149 
150 #define	FILEBENCH_RANDMAX64 UINT64_MAX
151 #define	FILEBENCH_RANDMAX32 UINT32_MAX
152 
153 #if defined(_LP64) || (__WORDSIZE == 64)
154 #define	fb_random fb_random64
155 #define	FILEBENCH_RANDMAX FILEBENCH_RANDMAX64
156 #else
157 #define	fb_random fb_random32
158 #define	FILEBENCH_RANDMAX FILEBENCH_RANDMAX32
159 #endif
160 
161 #ifndef HAVE_SIGIGNORE
162 /* No sigignore on FreeBSD */
sigignore(int sig)163 static inline int sigignore(int sig) {
164         struct sigaction sa;
165         bzero(&sa, sizeof(sa));
166         sa.sa_handler = SIG_IGN;
167         return (sigaction(sig, &sa, NULL));
168 }
169 #endif
170 
171 #define	KB (1024LL)
172 #define	MB (KB * KB)
173 #define	GB (KB * MB)
174 
175 #define	KB_FLOAT ((double)1024.0)
176 #define	MB_FLOAT (KB_FLOAT * KB_FLOAT)
177 #define	GB_FLOAT (KB_FLOAT * MB_FLOAT)
178 
179 #define	MMAP_SIZE	(1024UL * 1024UL * 1024UL)
180 
181 #define	FILEBENCH_VERSION	VERSION
182 #define	FILEBENCH_PROMPT	"filebench> "
183 #define	MAX_LINE_LEN	1024
184 #define	MAX_CMD_HIST	128
185 #define	SHUTDOWN_WAIT_SECONDS	3 /* time to wait for proc / thrd to quit */
186 
187 #define	FILEBENCH_DONE	 1
188 #define	FILEBENCH_OK	 0
189 #define	FILEBENCH_ERROR -1
190 #define	FILEBENCH_NORSC -2
191 
192 #endif	/* _FB_FILEBENCH_H */
193