]>
Commit | Line | Data |
---|---|---|
3e9ec521 SH |
1 | /* |
2 | * Linux AIO request queue | |
3 | * | |
4 | * Copyright 2012 IBM, Corp. | |
5 | * Copyright 2012 Red Hat, Inc. and/or its affiliates | |
6 | * | |
7 | * Authors: | |
8 | * Stefan Hajnoczi <[email protected]> | |
9 | * | |
10 | * This work is licensed under the terms of the GNU GPL, version 2 or later. | |
11 | * See the COPYING file in the top-level directory. | |
12 | * | |
13 | */ | |
14 | ||
15 | #ifndef IOQ_H | |
16 | #define IOQ_H | |
17 | ||
18 | #include <libaio.h> | |
19 | #include "qemu/event_notifier.h" | |
20 | ||
21 | typedef struct { | |
22 | int fd; /* file descriptor */ | |
23 | unsigned int max_reqs; /* max length of freelist and queue */ | |
24 | ||
25 | io_context_t io_ctx; /* Linux AIO context */ | |
26 | EventNotifier io_notifier; /* Linux AIO eventfd */ | |
27 | ||
28 | /* Requests can complete in any order so a free list is necessary to manage | |
29 | * available iocbs. | |
30 | */ | |
31 | struct iocb **freelist; /* free iocbs */ | |
32 | unsigned int freelist_idx; | |
33 | ||
34 | /* Multiple requests are queued up before submitting them all in one go */ | |
35 | struct iocb **queue; /* queued iocbs */ | |
36 | unsigned int queue_idx; | |
37 | } IOQueue; | |
38 | ||
39 | void ioq_init(IOQueue *ioq, int fd, unsigned int max_reqs); | |
40 | void ioq_cleanup(IOQueue *ioq); | |
41 | EventNotifier *ioq_get_notifier(IOQueue *ioq); | |
42 | struct iocb *ioq_get_iocb(IOQueue *ioq); | |
43 | void ioq_put_iocb(IOQueue *ioq, struct iocb *iocb); | |
44 | struct iocb *ioq_rdwr(IOQueue *ioq, bool read, struct iovec *iov, | |
45 | unsigned int count, long long offset); | |
46 | int ioq_submit(IOQueue *ioq); | |
47 | ||
48 | static inline unsigned int ioq_num_queued(IOQueue *ioq) | |
49 | { | |
50 | return ioq->queue_idx; | |
51 | } | |
52 | ||
53 | typedef void IOQueueCompletion(struct iocb *iocb, ssize_t ret, void *opaque); | |
54 | int ioq_run_completion(IOQueue *ioq, IOQueueCompletion *completion, | |
55 | void *opaque); | |
56 | ||
57 | #endif /* IOQ_H */ |