Change how we delete the semaphores to be more FreeBSD friendly.
[sahlberg/dbench.git] / dbench.h
1 /* 
2    dbench version 2
3    Copyright (C) Andrew Tridgell 1999
4    
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9    
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14    
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */
18 #define _FILE_OFFSET_BITS 64
19
20 #include "config.h"
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <stddef.h>
24 #include <signal.h>
25 #include <unistd.h>
26 #include <string.h>
27 #include <ctype.h>
28 #include <dirent.h>
29 #include <sys/stat.h>
30 #include <sys/time.h>
31 #include <sys/wait.h>
32 #include <sys/types.h>
33 #include <sys/socket.h>
34 #include <fcntl.h>
35 #include <time.h>
36 #include <sys/ipc.h>
37 #include <sys/shm.h>
38 #include <sys/mman.h>
39
40 #ifdef HAVE_SYS_VFS_H
41 #include <sys/vfs.h>
42 #endif
43
44 #ifdef HAVE_SYS_STATVFS_H
45 #include <sys/statvfs.h>
46 #endif
47
48 #include <sys/param.h>
49 #ifdef HAVE_SYS_MOUNT_H
50 #include <sys/mount.h>
51 #endif
52 #include <utime.h>
53 #include <errno.h>
54 #include <strings.h>
55 #ifdef HAVE_STDINT_H
56 #include <stdint.h>
57 #endif
58 #include <netinet/in.h>
59 #include <netinet/tcp.h>
60 #include <netdb.h>
61
62 #if HAVE_ATTR_XATTR_H
63 #include <attr/xattr.h>
64 #elif HAVE_SYS_XATTR_H
65 #include <sys/xattr.h>
66 #elif HAVE_SYS_ATTRIBUTES_H
67 #include <sys/attributes.h>
68 #endif
69
70 #ifdef HAVE_SYS_EXTATTR_H
71 #include <sys/extattr.h>
72 #endif
73
74 #ifdef HAVE_SYS_UIO_H
75 #include <sys/uio.h>
76 #endif
77
78 #ifndef MSG_WAITALL
79 #define MSG_WAITALL 0x100
80 #endif
81
82 #define PRINT_FREQ 1
83
84 #ifndef MIN
85 #define MIN(x,y) ((x)<(y)?(x):(y))
86 #endif
87
88 #define TCP_PORT 7003
89 #define TCP_OPTIONS "TCP_NODELAY SO_REUSEADDR"
90
91 #define BOOL int
92 #define True 1
93 #define False 0
94 #define uint32 unsigned
95
96 struct op {
97         unsigned count;
98         double total_time;
99         double max_latency;
100 };
101
102 #define ZERO_STRUCT(x) memset(&(x), 0, sizeof(x))
103
104 #define MAX_OPS 100
105
106 struct child_struct {
107         int id;
108         int num_clients;
109         int failed;
110         int line;
111         int done;
112         int cleanup;
113         int cleanup_finished;
114         const char *directory;
115         double bytes;
116         double bytes_done_warmup;
117         double max_latency;
118         double worst_latency;
119         struct timeval starttime;
120         struct timeval lasttime;
121         off_t bytes_since_fsync;
122         char *cname;
123         struct {
124                 double last_bytes;
125                 struct timeval last_time;
126         } rate;
127         struct op ops[MAX_OPS];
128         void *private;
129 };
130
131 struct options {
132         const char *backend;
133         int nprocs;
134         int sync_open;
135         int sync_dirs;
136         int do_fsync;
137         int no_resolve;
138         int fsync_frequency;
139         char *tcp_options;
140         int timelimit;
141         int warmup;
142         const char *directory;
143         char *loadfile;
144         double targetrate;
145         int ea_enable;
146         const char *server;
147         int clients_per_process;
148         int one_byte_write_fix;
149         int stat_check;
150         int fake_io;
151         int skip_cleanup;
152         int per_client_results;
153         const char *export;
154         const char *protocol;
155         int run_once;
156         int allow_scsi_writes;
157         int trunc_io;
158         const char *scsi_dev;
159         const char *iscsi_device;
160         const char *iscsi_initiatorname;
161         int machine_readable;
162         const char *smb_share;
163         const char *smb_user;
164 };
165
166
167 struct dbench_op {
168         struct child_struct *child;
169         const char *op;
170         const char *fname;
171         const char *fname2;
172         const char *status;
173         int64_t params[10];
174 };
175
176 struct backend_op {
177         const char *name;
178         void (*fn)(struct dbench_op *);
179 };
180
181 struct nb_operations {
182         const char *backend_name;       
183         struct backend_op *ops;
184         int (*init)(void);
185         void (*setup)(struct child_struct *child);
186         void (*cleanup)(struct child_struct *child);
187 };
188 extern struct nb_operations *nb_ops;
189
190 /* CreateDisposition field. */
191 #define FILE_SUPERSEDE 0
192 #define FILE_OPEN 1
193 #define FILE_CREATE 2
194 #define FILE_OPEN_IF 3
195 #define FILE_OVERWRITE 4
196 #define FILE_OVERWRITE_IF 5
197
198 /* CreateOptions field. */
199 #define FILE_DIRECTORY_FILE       0x0001
200 #define FILE_WRITE_THROUGH        0x0002
201 #define FILE_SEQUENTIAL_ONLY      0x0004
202 #define FILE_NON_DIRECTORY_FILE   0x0040
203 #define FILE_NO_EA_KNOWLEDGE      0x0200
204 #define FILE_EIGHT_DOT_THREE_ONLY 0x0400
205 #define FILE_RANDOM_ACCESS        0x0800
206 #define FILE_DELETE_ON_CLOSE      0x1000
207
208 #ifndef O_DIRECTORY
209 #define O_DIRECTORY    0200000
210 #endif
211
212 struct nfsio;
213
214 #include "proto.h"
215
216 extern struct options options;
217 extern int global_random;
218 extern char rw_buf[];