2 * Copyright (c) 2000 - 2001 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 #include <sys/types.h>
40 #include <sys/param.h>
43 #include <sys/mount.h>
45 #ifdef HAVE_SYS_IOCCOM_H
46 #include <sys/ioccom.h>
64 static int write_file
= 0;
65 static int num_runs
= 3;
67 static struct agetargs args
[] = {
68 {"num", 'n', aarg_integer
, &num_files
, "number of files"},
69 {"write", 'w', aarg_integer
, &write_file
, "write num kb"},
70 {"runs", 'r', aarg_integer
, &num_runs
, "number of runs"},
71 {"help", 0, aarg_flag
, &help_flag
, NULL
, NULL
},
72 {NULL
, 0, aarg_end
, NULL
, NULL
, NULL
}
77 fhb_fhget(char *filename
, struct fhb_handle
*handle
)
80 #if defined(HAVE_GETFH) && defined(HAVE_FHOPEN)
84 ret
= getfh(filename
, &fh
);
87 memcpy(handle
, &fh
, sizeof(fh
));
91 struct ViceIoctl vice_ioctl
;
94 vice_ioctl
.in_size
= 0;
96 vice_ioctl
.out
= (caddr_t
) handle
;
97 vice_ioctl
.out_size
= sizeof(*handle
);
99 ret
= pioctl(filename
, VIOC_FHGET
, &vice_ioctl
, 0);
107 fhb_fhopen(struct fhb_handle
*handle
, int flags
)
110 #if defined(HAVE_GETFH) && defined(HAVE_FHOPEN)
114 memcpy(&fh
, handle
, sizeof(fh
));
115 ret
= fhopen(&fh
, flags
);
121 #ifdef KERBEROS /* really KAFS */
123 struct ViceIoctl vice_ioctl
;
125 vice_ioctl
.in
= (caddr_t
) handle
;
126 vice_ioctl
.in_size
= sizeof(*handle
);
128 vice_ioctl
.out
= NULL
;
129 vice_ioctl
.out_size
= 0;
131 ret
= k_pioctl(NULL
, VIOC_FHOPEN
, &vice_ioctl
, flags
);
136 errx(1, "fhopen/k_pioctl");
142 #ifdef KERBEROS /* really KAFS */
144 struct ViceIoctl vice_ioctl
;
148 vice_ioctl
.in
= (caddr_t
) & c
;
149 vice_ioctl
.in_size
= sizeof(c
);
151 vice_ioctl
.out
= NULL
;
152 vice_ioctl
.out_size
= 0;
154 ret
= k_pioctl(NULL
, VIOC_XFSDEBUG
, &vice_ioctl
, 0);
162 warnx("can't test this");
170 create_file(int num
, struct fhb_handle
*handle
)
175 snprintf(filename
, sizeof(filename
), "file-%d", num
);
177 fd
= open(filename
, O_CREAT
| O_EXCL
| O_RDWR
, 0666);
183 fhb_fhget(filename
, handle
);
189 write_to_file(int fd
, int num
)
193 ret
= write(fd
, databuf
, sizeof(databuf
));
194 if (ret
!= sizeof(databuf
))
201 fhopen_file(int num
, struct fhb_handle
*handle
)
205 fd
= fhb_fhopen(handle
, O_RDWR
);
210 write_to_file(fd
, write_file
);
220 snprintf(filename
, sizeof(filename
), "file-%d", num
);
222 fd
= open(filename
, O_RDWR
, 0666);
227 write_to_file(fd
, write_file
);
238 snprintf(filename
, sizeof(filename
), "file-%d", num
);
240 ret
= unlink(filename
);
245 struct timeval time1
, time2
;
248 starttesting(char *msg
)
250 printf("testing %s...\n", msg
);
252 gettimeofday(&time1
, NULL
);
258 gettimeofday(&time2
, NULL
);
259 timevalsub(&time2
, &time1
);
260 printf("timing: %ld.%06ld\n", (long)time2
.tv_sec
, (long)time2
.tv_usec
);
266 aarg_printusage(args
, NULL
, "number of files", AARG_GNUSTYLE
);
271 open_bench(int i
, struct fhb_handle
*handles
)
273 printf("====== test run %d\n" "==================\n", i
);
275 starttesting("fhopening files");
276 for (i
= 0; i
< num_files
; i
++)
277 fhopen_file(i
, &handles
[i
]);
280 starttesting("opening files");
281 for (i
= 0; i
< num_files
; i
++)
287 main(int argc
, char **argv
)
291 struct fhb_handle
*handles
;
294 if (agetarg(args
, argc
, argv
, &optind
, AARG_GNUSTYLE
))
309 errx(1, "no afs kernel module");
311 handles
= emalloc(num_files
* sizeof(*handles
));
313 starttesting("creating files");
314 for (i
= 0; i
< num_files
; i
++)
315 create_file(i
, &handles
[i
]);
318 for (i
= 0; i
< num_runs
; i
++)
319 open_bench(i
, handles
);
321 printf("==================\n");
322 starttesting("unlink files");
323 for (i
= 0; i
< num_files
; i
++)
327 printf("==================\n");
328 starttesting("nop call");
329 for (i
= 0; i
< num_files
; i
++)