4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or https://opensource.org/licenses/CDDL-1.0.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2018 Canonical. All rights reserved.
31 #include <sys/types.h>
36 static io_context_t io_ctx
;
39 do_sync_io(struct iocb
*iocb
)
41 struct io_event event
;
42 struct iocb
*iocbs
[] = { iocb
};
43 struct timespec ts
= { 30, 0 };
45 if (io_submit(io_ctx
, 1, iocbs
) != 1)
46 err(1, "io_submit failed");
48 if (io_getevents(io_ctx
, 0, 1, &event
, &ts
) != 1)
49 err(1, "io_getevents failed");
53 main(int argc
, char **argv
)
57 int page_size
= getpagesize();
58 int buf_size
= strtol(argv
[2], NULL
, 0);
62 if (io_queue_init(1024, &io_ctx
))
63 err(1, "io_queue_init failed");
65 rwfd
= open(argv
[1], O_RDWR
| O_CREAT
, S_IRUSR
| S_IWUSR
);
67 err(1, "open failed");
69 if (ftruncate(rwfd
, buf_size
) < 0)
70 err(1, "ftruncate failed");
72 buf
= mmap(0, page_size
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, rwfd
, 0);
73 if (buf
== MAP_FAILED
)
74 err(1, "mmap failed");
76 (void) io_prep_pwrite(&iocb
, rwfd
, buf
, buf_size
, 0);
79 (void) io_prep_pread(&iocb
, rwfd
, buf
, buf_size
, 0);
83 err(1, "close failed");
85 if (io_queue_release(io_ctx
) != 0)
86 err(1, "io_queue_release failed");