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>
57 #include <arla-pioctl.h>
70 static int write_file
= 0;
71 static int num_runs
= 3;
73 static struct agetargs args
[] = {
74 {"num", 'n', aarg_integer
, &num_files
, "number of files"},
75 {"write", 'w', aarg_integer
, &write_file
, "write num kb"},
76 {"runs", 'r', aarg_integer
, &num_runs
, "number of runs"},
77 {"help", 0, aarg_flag
, &help_flag
, NULL
, NULL
},
78 {NULL
, 0, aarg_end
, NULL
, NULL
, NULL
}
83 fhb_fhget (char *filename
, struct fhb_handle
*handle
)
86 #if defined(HAVE_GETFH) && defined(HAVE_FHOPEN)
90 ret
= getfh (filename
, &fh
);
93 memcpy (handle
, &fh
, sizeof(fh
));
98 struct arlaViceIoctl vice_ioctl
;
100 vice_ioctl
.in
= NULL
;
101 vice_ioctl
.in_size
= 0;
103 vice_ioctl
.out
= (caddr_t
)handle
;
104 vice_ioctl
.out_size
= sizeof(*handle
);
106 ret
= k_pioctl (filename
, ARLA_VIOC_FHGET
, (void*)&vice_ioctl
, 0);
108 errx (1, "k_pioctl");
115 fhb_fhopen (struct fhb_handle
*handle
, int flags
)
118 #if defined(HAVE_GETFH) && defined(HAVE_FHOPEN)
122 memcpy (&fh
, handle
, sizeof(fh
));
123 ret
= fhopen (&fh
, flags
);
129 #ifdef KERBEROS /* really KAFS */
131 struct arlaViceIoctl vice_ioctl
;
133 vice_ioctl
.in
= (caddr_t
)handle
;
134 vice_ioctl
.in_size
= sizeof(*handle
);
136 vice_ioctl
.out
= NULL
;
137 vice_ioctl
.out_size
= 0;
139 ret
= k_pioctl (NULL
, ARLA_VIOC_FHOPEN
, (void*)&vice_ioctl
, flags
);
144 errx (1, "fhopen/k_pioctl");
150 #ifdef KERBEROS /* really KAFS */
152 struct arlaViceIoctl vice_ioctl
;
156 vice_ioctl
.in
= (caddr_t
)&c
;
157 vice_ioctl
.in_size
= sizeof(c
);
159 vice_ioctl
.out
= NULL
;
160 vice_ioctl
.out_size
= 0;
162 ret
= k_pioctl (NULL
, ARLA_VIOC_NNPFSDEBUG
, (void*)&vice_ioctl
, 0);
170 warnx ("can't test this");
178 create_file (int num
, struct fhb_handle
*handle
)
183 snprintf (filename
, sizeof(filename
), "file-%d", num
);
185 fd
= open (filename
, O_CREAT
|O_EXCL
|O_RDWR
, 0666);
191 fhb_fhget(filename
, handle
);
197 write_to_file (int fd
, int num
)
201 ret
= write (fd
, databuf
, sizeof(databuf
));
202 if (ret
!= sizeof(databuf
))
209 fhopen_file (int num
, struct fhb_handle
*handle
)
213 fd
= fhb_fhopen(handle
, O_RDWR
);
218 write_to_file(fd
, write_file
);
228 snprintf (filename
, sizeof(filename
), "file-%d", num
);
230 fd
= open (filename
, O_RDWR
, 0666);
235 write_to_file(fd
, write_file
);
241 unlink_file (int num
)
246 snprintf (filename
, sizeof(filename
), "file-%d", num
);
248 ret
= unlink(filename
);
254 * Make `t1' consistent.
258 tvfix(struct timeval
*t1
)
260 if (t1
->tv_usec
< 0) {
262 t1
->tv_usec
+= 1000000;
264 if (t1
->tv_usec
>= 1000000) {
266 t1
->tv_usec
-= 1000000;
275 tvsub(struct timeval
*t1
, const struct timeval
*t2
)
277 t1
->tv_sec
-= t2
->tv_sec
;
278 t1
->tv_usec
-= t2
->tv_usec
;
283 struct timeval time1
, time2
;
286 starttesting(char *msg
)
288 printf("testing %s...\n", msg
);
290 gettimeofday(&time1
, NULL
);
296 gettimeofday(&time2
, NULL
);
297 tvsub(&time2
, &time1
);
298 printf("timing: %ld.%06ld\n", (long)time2
.tv_sec
, (long)time2
.tv_usec
);
304 aarg_printusage (args
, NULL
, "number of files", AARG_GNUSTYLE
);
309 open_bench (int i
, struct fhb_handle
*handles
)
311 printf ("====== test run %d\n"
312 "==================\n",
315 starttesting ("fhopening files");
316 for (i
= 0; i
< num_files
; i
++)
317 fhopen_file (i
, &handles
[i
]);
320 starttesting ("opening files");
321 for (i
= 0; i
< num_files
; i
++)
327 main (int argc
, char **argv
)
331 struct fhb_handle
*handles
;
333 setprogname (argv
[0]);
335 if (agetarg (args
, argc
, argv
, &optind
, AARG_GNUSTYLE
))
350 errx (1, "no afs kernel module");
352 handles
= emalloc (num_files
* sizeof(*handles
));
354 starttesting ("creating files");
355 for (i
= 0; i
< num_files
; i
++)
356 create_file (i
, &handles
[i
]);
359 for (i
= 0 ; i
< num_runs
; i
++)
360 open_bench (i
, handles
);
362 printf ( "==================\n");
363 starttesting ("unlink files");
364 for (i
= 0; i
< num_files
; i
++)
368 printf ( "==================\n");
369 starttesting ("nop call");
370 for (i
= 0; i
< num_files
; i
++)