update read10 and implement readcapacity10
[tridge/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
19 #include "config.h"
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <stddef.h>
23 #include <signal.h>
24 #include <unistd.h>
25 #include <string.h>
26 #include <ctype.h>
27 #include <dirent.h>
28 #include <sys/stat.h>
29 #include <sys/time.h>
30 #include <sys/wait.h>
31 #include <sys/types.h>
32 #include <sys/socket.h>
33 #include <fcntl.h>
34 #include <time.h>
35 #include <sys/ipc.h>
36 #include <sys/shm.h>
37 #include <sys/mman.h>
38
39 #ifdef HAVE_SYS_VFS_H
40 #include <sys/vfs.h>
41 #endif
42
43 #ifdef HAVE_SYS_STATVFS_H
44 #include <sys/statvfs.h>
45 #endif
46
47 #include <sys/param.h>
48 #ifdef HAVE_SYS_MOUNT_H
49 #include <sys/mount.h>
50 #endif
51 #include <utime.h>
52 #include <errno.h>
53 #include <strings.h>
54 #ifdef HAVE_STDINT_H
55 #include <stdint.h>
56 #endif
57 #include <netinet/in.h>
58 #include <netinet/tcp.h>
59 #include <netdb.h>
60
61 #if HAVE_ATTR_XATTR_H
62 #include <attr/xattr.h>
63 #elif HAVE_SYS_XATTR_H
64 #include <sys/xattr.h>
65 #elif HAVE_SYS_ATTRIBUTES_H
66 #include <sys/attributes.h>
67 #endif
68
69 #ifdef HAVE_SYS_EXTATTR_H
70 #include <sys/extattr.h>
71 #endif
72
73 #ifdef HAVE_SYS_UIO_H
74 #include <sys/uio.h>
75 #endif
76
77 #ifndef MSG_WAITALL
78 #define MSG_WAITALL 0x100
79 #endif
80
81 #define PRINT_FREQ 1
82
83 #ifndef MIN
84 #define MIN(x,y) ((x)<(y)?(x):(y))
85 #endif
86
87 #define TCP_PORT 7003
88 #define TCP_OPTIONS "TCP_NODELAY SO_REUSEADDR"
89
90 #define BOOL int
91 #define True 1
92 #define False 0
93 #define uint32 unsigned
94
95 struct op {
96         unsigned count;
97         double total_time;
98         double max_latency;
99 };
100
101 #define ZERO_STRUCT(x) memset(&(x), 0, sizeof(x))
102
103 #define MAX_OPS 100
104
105 struct child_struct {
106         int id;
107         int failed;
108         int line;
109         int done;
110         int cleanup;
111         int cleanup_finished;
112         const char *directory;
113         double bytes;
114         double bytes_done_warmup;
115         double max_latency;
116         double worst_latency;
117         struct timeval starttime;
118         struct timeval lasttime;
119         off_t bytes_since_fsync;
120         char *cname;
121         struct {
122                 double last_bytes;
123                 struct timeval last_time;
124         } rate;
125         struct op ops[MAX_OPS];
126         void *private;
127 };
128
129 struct options {
130         const char *backend;
131         int nprocs;
132         int sync_open;
133         int sync_dirs;
134         int do_fsync;
135         int no_resolve;
136         int fsync_frequency;
137         char *tcp_options;
138         int timelimit;
139         int warmup;
140         const char *directory;
141         char *loadfile;
142         double targetrate;
143         int ea_enable;
144         const char *server;
145         int clients_per_process;
146         int one_byte_write_fix;
147         int stat_check;
148         int fake_io;
149         int skip_cleanup;
150         int per_client_results;
151         const char *export;
152         const char *protocol;
153         int run_once;
154         int trunc_io;
155         const char *scsi_dev;
156 };
157
158
159 struct dbench_op {
160         struct child_struct *child;
161         const char *op;
162         const char *fname;
163         const char *fname2;
164         const char *status;
165         int params[10];
166 };
167
168 struct backend_op {
169         const char *name;
170         void (*fn)(struct dbench_op *);
171 };
172
173 struct nb_operations {
174         const char *backend_name;       
175         struct backend_op *ops;
176         void (*setup)(struct child_struct *child);
177         void (*cleanup)(struct child_struct *child);
178 };
179 extern struct nb_operations *nb_ops;
180
181 /* CreateDisposition field. */
182 #define FILE_SUPERSEDE 0
183 #define FILE_OPEN 1
184 #define FILE_CREATE 2
185 #define FILE_OPEN_IF 3
186 #define FILE_OVERWRITE 4
187 #define FILE_OVERWRITE_IF 5
188
189 /* CreateOptions field. */
190 #define FILE_DIRECTORY_FILE       0x0001
191 #define FILE_WRITE_THROUGH        0x0002
192 #define FILE_SEQUENTIAL_ONLY      0x0004
193 #define FILE_NON_DIRECTORY_FILE   0x0040
194 #define FILE_NO_EA_KNOWLEDGE      0x0200
195 #define FILE_EIGHT_DOT_THREE_ONLY 0x0400
196 #define FILE_RANDOM_ACCESS        0x0800
197 #define FILE_DELETE_ON_CLOSE      0x1000
198
199 #ifndef O_DIRECTORY
200 #define O_DIRECTORY    0200000
201 #endif
202
203 struct nfsio;
204
205 #include "proto.h"
206
207 extern struct options options;