1 /*
2  * linux_kaio.h
3  *
4  * This source file is part of the FoundationDB open source project
5  *
6  * Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 // AIO system calls
22 
23 typedef struct io_context *io_context_t;
24 
25 enum {
26 	IO_CMD_PREAD = 0,
27 	IO_CMD_PWRITE = 1,
28 	IO_CMD_FSYNC = 2,
29 	IO_CMD_FDSYNC = 3
30 };
31 
32 struct linux_iocb {
33 	void* data;
34 	uint32_t key, unused;
35 
36 	uint16_t aio_lio_opcode;
37 	uint16_t aio_reqprio;
38 	uint32_t aio_fildes;
39 
40 	void* buf;
41 	uint64_t nbytes;
42 	int64_t offset;
43 	uint64_t unused2;
44 	uint32_t flags;
45 	uint32_t eventfd;
46 };
47 
48 struct linux_ioresult {
49 	void* data;
50 	linux_iocb* iocb;
51 	unsigned long result;
52 	unsigned long result2;
53 };
54 
io_setup(unsigned nr_events,io_context_t * ctxp)55 static int io_setup(unsigned nr_events, io_context_t *ctxp) { return syscall( __NR_io_setup, nr_events, ctxp ); }
io_submit(io_context_t ctx_id,long nrstruct,linux_iocb ** iocbpp)56 static int io_submit(io_context_t ctx_id, long nrstruct, linux_iocb ** iocbpp ) { return syscall( __NR_io_submit, ctx_id, nrstruct, iocbpp ); }
io_getevents(io_context_t ctx_id,long min_nr,long nr,linux_ioresult * events,struct timespec * timeout)57 static int io_getevents(io_context_t ctx_id, long min_nr, long nr, linux_ioresult *events, struct timespec * timeout ) { return syscall( __NR_io_getevents, ctx_id, min_nr, nr, events, timeout ); }
58