2 * Copyright (C) 2005 IronPort Systems, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * Note: it is a good idea to run this against a physical drive to
30 * exercise the physio fast path (ie. lio_kqueue /dev/<something safe>)
31 * This will ensure op's counting is correct. It is currently broken.
33 * Also note that LIO & kqueue is not implemented in FreeBSD yet, LIO
34 * is also broken with respect to op's and some paths.
36 * A patch to make this work is at:
37 * http://www.ambrisko.com/doug/listio_kqueue/listio_kqueue.patch
40 #include <sys/types.h>
41 #include <sys/event.h>
52 #include "freebsd_test_suite/macros.h"
55 #define PATH_TEMPLATE "aio.XXXXXXXXXX"
58 #define MAX_IOCBS LIO_MAX * 16
62 main(int argc, char *argv[])
65 struct aiocb *iocb[MAX_IOCBS];
66 struct aiocb **lio[LIO_MAX], **kq_lio;
67 int i, result, run, error, j, k;
70 struct kevent ke, kq_returned;
74 char *file, pathname[sizeof(PATH_TEMPLATE)];
75 int tmp_file = 0, failed = 0;
77 PLAIN_REQUIRE_KERNEL_MODULE("aio", 0);
78 PLAIN_REQUIRE_UNSAFE_AIO(0);
82 err(1, "kqeueue(2) failed");
85 strcpy(pathname, PATH_TEMPLATE);
86 fd = mkstemp(pathname);
91 fd = open(file, O_RDWR|O_CREAT, 0666);
94 err(1, "can't open %s", argv[1]);
97 printf("Hello kq %d fd %d\n", kq, fd);
100 for (run = 0; run < MAX_RUNS; run++) {
102 printf("Run %d\n", run);
104 for (j = 0; j < LIO_MAX; j++) {
106 malloc(sizeof(struct aiocb *) * MAX_IOCBS/LIO_MAX);
107 for (i = 0; i < MAX_IOCBS / LIO_MAX; i++) {
108 k = (MAX_IOCBS / LIO_MAX * j) + i;
109 lio[j][i] = iocb[k] =
110 calloc(1, sizeof(struct aiocb));
111 iocb[k]->aio_nbytes = sizeof(buffer);
112 iocb[k]->aio_buf = buffer;
113 iocb[k]->aio_fildes = fd;
115 = iocb[k]->aio_nbytes * k * (run + 1);
118 printf("hello iocb[k] %d\n",
119 iocb[k]->aio_offset);
121 iocb[k]->aio_lio_opcode = LIO_WRITE;
123 sig.sigev_notify_kqueue = kq;
124 sig.sigev_value.sival_ptr = lio[j];
125 sig.sigev_notify = SIGEV_KEVENT;
127 result = lio_listio(LIO_NOWAIT, lio[j],
128 MAX_IOCBS / LIO_MAX, &sig);
132 printf("Time %d %d %d result -> %d\n",
133 time1, time2, time2-time1, result);
137 err(1, "FAIL: Result %d iteration %d\n",
141 printf("write %d is at %p\n", j, lio[j]);
145 for (i = 0; i < LIO_MAX; i++) {
146 for (j = LIO_MAX - 1; j >=0; j--) {
152 bzero(&ke, sizeof(ke));
153 bzero(&kq_returned, sizeof(ke));
157 printf("FOO lio %d -> %p\n", j, lio[j]);
159 EV_SET(&ke, (uintptr_t)lio[j],
160 EVFILT_LIO, EV_ONESHOT, 0, 0, iocb[j]);
161 result = kevent(kq, NULL, 0,
162 &kq_returned, 1, &ts);
165 perror("kevent error: ");
167 kq_lio = kq_returned.udata;
169 printf("kevent %d %d errno %d return.ident %p "
170 "return.data %p return.udata %p %p\n",
172 kq_returned.ident, kq_returned.data,
180 printf("Try again\n");
185 printf("lio %p\n", lio);
188 for (j = 0; j < LIO_MAX; j++) {
189 if (lio[j] == kq_lio)
196 printf("Error Result for %d is %d\n", j, result);
199 printf("FAIL: run %d, operation %d result %d \n", run, LIO_MAX - i -1, result);
202 printf("PASS: run %d, operation %d result %d \n", run, LIO_MAX - i -1, result);
203 for (k = 0; k < MAX_IOCBS / LIO_MAX; k++) {
204 result = aio_return(kq_lio[k]);
206 printf("Return Resulto for %d %d is %d\n", j, k, result);
208 if (result != sizeof(buffer)) {
209 printf("FAIL: run %d, operation %d sub-opt %d result %d (errno=%d) should be %zu\n",
210 run, LIO_MAX - i -1, k, result, errno, sizeof(buffer));
212 printf("PASS: run %d, operation %d sub-opt %d result %d\n",
213 run, LIO_MAX - i -1, k, result);
220 for (k = 0; k < MAX_IOCBS / LIO_MAX; k++)
234 errx(1, "FAIL: %d testcases failed", failed);
236 errx(0, "PASS: All\n");