aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 1 | /* |
| 2 | * QEMU posix-aio emulation |
| 3 | * |
| 4 | * Copyright IBM, Corp. 2008 |
| 5 | * |
| 6 | * Authors: |
| 7 | * Anthony Liguori <aliguori@us.ibm.com> |
| 8 | * |
| 9 | * This work is licensed under the terms of the GNU GPL, version 2. See |
| 10 | * the COPYING file in the top-level directory. |
| 11 | * |
| 12 | */ |
| 13 | |
aliguori | 221f715 | 2009-03-28 17:28:41 +0000 | [diff] [blame] | 14 | #include <sys/ioctl.h> |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 15 | #include <sys/types.h> |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 16 | #include <pthread.h> |
| 17 | #include <unistd.h> |
| 18 | #include <errno.h> |
malc | 30525af | 2009-02-21 05:48:13 +0000 | [diff] [blame] | 19 | #include <time.h> |
malc | 8653c01 | 2009-02-21 05:48:11 +0000 | [diff] [blame] | 20 | #include <string.h> |
| 21 | #include <stdlib.h> |
| 22 | #include <stdio.h> |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 23 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 24 | #include "qemu-queue.h" |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 25 | #include "osdep.h" |
Jes Sorensen | dc786bc | 2010-10-26 10:39:23 +0200 | [diff] [blame] | 26 | #include "sysemu.h" |
aliguori | f141eaf | 2009-04-07 18:43:24 +0000 | [diff] [blame] | 27 | #include "qemu-common.h" |
Stefan Hajnoczi | 6d519a5 | 2010-05-22 18:15:08 +0100 | [diff] [blame] | 28 | #include "trace.h" |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 29 | #include "block_int.h" |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 30 | |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 31 | #include "block/raw-posix-aio.h" |
| 32 | |
Avi Kivity | e4ea78e | 2011-08-14 07:04:49 +0300 | [diff] [blame] | 33 | static void do_spawn_thread(void); |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 34 | |
| 35 | struct qemu_paiocb { |
| 36 | BlockDriverAIOCB common; |
| 37 | int aio_fildes; |
| 38 | union { |
| 39 | struct iovec *aio_iov; |
Stefan Hajnoczi | b587a52 | 2010-05-27 12:52:08 +0100 | [diff] [blame] | 40 | void *aio_ioctl_buf; |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 41 | }; |
| 42 | int aio_niov; |
| 43 | size_t aio_nbytes; |
| 44 | #define aio_ioctl_cmd aio_nbytes /* for QEMU_AIO_IOCTL */ |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 45 | off_t aio_offset; |
| 46 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 47 | QTAILQ_ENTRY(qemu_paiocb) node; |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 48 | int aio_type; |
| 49 | ssize_t ret; |
| 50 | int active; |
| 51 | struct qemu_paiocb *next; |
| 52 | }; |
| 53 | |
| 54 | typedef struct PosixAioState { |
| 55 | int rfd, wfd; |
| 56 | struct qemu_paiocb *first_aio; |
| 57 | } PosixAioState; |
| 58 | |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 59 | |
| 60 | static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; |
| 61 | static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; |
| 62 | static pthread_t thread_id; |
malc | a8227a5 | 2009-02-21 05:48:17 +0000 | [diff] [blame] | 63 | static pthread_attr_t attr; |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 64 | static int max_threads = 64; |
| 65 | static int cur_threads = 0; |
| 66 | static int idle_threads = 0; |
Avi Kivity | e4ea78e | 2011-08-14 07:04:49 +0300 | [diff] [blame] | 67 | static int new_threads = 0; /* backlog of threads we need to create */ |
| 68 | static int pending_threads = 0; /* threads created but not running yet */ |
| 69 | static QEMUBH *new_thread_bh; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 70 | static QTAILQ_HEAD(, qemu_paiocb) request_list; |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 71 | |
Juan Quintela | 2341f9a | 2009-07-27 16:12:58 +0200 | [diff] [blame] | 72 | #ifdef CONFIG_PREADV |
aliguori | ceb42de | 2009-04-07 18:43:28 +0000 | [diff] [blame] | 73 | static int preadv_present = 1; |
| 74 | #else |
| 75 | static int preadv_present = 0; |
| 76 | #endif |
| 77 | |
malc | 8653c01 | 2009-02-21 05:48:11 +0000 | [diff] [blame] | 78 | static void die2(int err, const char *what) |
| 79 | { |
| 80 | fprintf(stderr, "%s failed: %s\n", what, strerror(err)); |
| 81 | abort(); |
| 82 | } |
| 83 | |
| 84 | static void die(const char *what) |
| 85 | { |
| 86 | die2(errno, what); |
| 87 | } |
| 88 | |
| 89 | static void mutex_lock(pthread_mutex_t *mutex) |
| 90 | { |
| 91 | int ret = pthread_mutex_lock(mutex); |
| 92 | if (ret) die2(ret, "pthread_mutex_lock"); |
| 93 | } |
| 94 | |
| 95 | static void mutex_unlock(pthread_mutex_t *mutex) |
| 96 | { |
| 97 | int ret = pthread_mutex_unlock(mutex); |
| 98 | if (ret) die2(ret, "pthread_mutex_unlock"); |
| 99 | } |
| 100 | |
| 101 | static int cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, |
| 102 | struct timespec *ts) |
| 103 | { |
| 104 | int ret = pthread_cond_timedwait(cond, mutex, ts); |
| 105 | if (ret && ret != ETIMEDOUT) die2(ret, "pthread_cond_timedwait"); |
| 106 | return ret; |
| 107 | } |
| 108 | |
malc | 5d47e37 | 2009-02-21 05:48:15 +0000 | [diff] [blame] | 109 | static void cond_signal(pthread_cond_t *cond) |
malc | 8653c01 | 2009-02-21 05:48:11 +0000 | [diff] [blame] | 110 | { |
malc | 5d47e37 | 2009-02-21 05:48:15 +0000 | [diff] [blame] | 111 | int ret = pthread_cond_signal(cond); |
| 112 | if (ret) die2(ret, "pthread_cond_signal"); |
malc | 8653c01 | 2009-02-21 05:48:11 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | static void thread_create(pthread_t *thread, pthread_attr_t *attr, |
| 116 | void *(*start_routine)(void*), void *arg) |
| 117 | { |
| 118 | int ret = pthread_create(thread, attr, start_routine, arg); |
| 119 | if (ret) die2(ret, "pthread_create"); |
| 120 | } |
| 121 | |
Kevin Wolf | 6769da2 | 2009-11-18 12:15:10 +0100 | [diff] [blame] | 122 | static ssize_t handle_aiocb_ioctl(struct qemu_paiocb *aiocb) |
aliguori | f141eaf | 2009-04-07 18:43:24 +0000 | [diff] [blame] | 123 | { |
Stefan Hajnoczi | b587a52 | 2010-05-27 12:52:08 +0100 | [diff] [blame] | 124 | int ret; |
aliguori | f141eaf | 2009-04-07 18:43:24 +0000 | [diff] [blame] | 125 | |
Stefan Hajnoczi | b587a52 | 2010-05-27 12:52:08 +0100 | [diff] [blame] | 126 | ret = ioctl(aiocb->aio_fildes, aiocb->aio_ioctl_cmd, aiocb->aio_ioctl_buf); |
| 127 | if (ret == -1) |
| 128 | return -errno; |
Christoph Hellwig | e7d54ae | 2009-04-28 11:57:02 +0200 | [diff] [blame] | 129 | |
Stefan Hajnoczi | b587a52 | 2010-05-27 12:52:08 +0100 | [diff] [blame] | 130 | /* |
| 131 | * This looks weird, but the aio code only consideres a request |
Stefan Weil | b0cd712 | 2010-08-06 21:53:45 +0200 | [diff] [blame] | 132 | * successful if it has written the number full number of bytes. |
Stefan Hajnoczi | b587a52 | 2010-05-27 12:52:08 +0100 | [diff] [blame] | 133 | * |
| 134 | * Now we overload aio_nbytes as aio_ioctl_cmd for the ioctl command, |
| 135 | * so in fact we return the ioctl command here to make posix_aio_read() |
| 136 | * happy.. |
| 137 | */ |
| 138 | return aiocb->aio_nbytes; |
aliguori | f141eaf | 2009-04-07 18:43:24 +0000 | [diff] [blame] | 139 | } |
| 140 | |
Kevin Wolf | 6769da2 | 2009-11-18 12:15:10 +0100 | [diff] [blame] | 141 | static ssize_t handle_aiocb_flush(struct qemu_paiocb *aiocb) |
Christoph Hellwig | b2e12bc | 2009-09-04 19:01:49 +0200 | [diff] [blame] | 142 | { |
| 143 | int ret; |
| 144 | |
Blue Swirl | 47faadc | 2009-09-12 06:19:14 +0000 | [diff] [blame] | 145 | ret = qemu_fdatasync(aiocb->aio_fildes); |
Christoph Hellwig | b2e12bc | 2009-09-04 19:01:49 +0200 | [diff] [blame] | 146 | if (ret == -1) |
| 147 | return -errno; |
| 148 | return 0; |
| 149 | } |
| 150 | |
Juan Quintela | 2341f9a | 2009-07-27 16:12:58 +0200 | [diff] [blame] | 151 | #ifdef CONFIG_PREADV |
aliguori | ceb42de | 2009-04-07 18:43:28 +0000 | [diff] [blame] | 152 | |
| 153 | static ssize_t |
| 154 | qemu_preadv(int fd, const struct iovec *iov, int nr_iov, off_t offset) |
| 155 | { |
| 156 | return preadv(fd, iov, nr_iov, offset); |
| 157 | } |
| 158 | |
| 159 | static ssize_t |
| 160 | qemu_pwritev(int fd, const struct iovec *iov, int nr_iov, off_t offset) |
| 161 | { |
| 162 | return pwritev(fd, iov, nr_iov, offset); |
| 163 | } |
| 164 | |
| 165 | #else |
| 166 | |
| 167 | static ssize_t |
| 168 | qemu_preadv(int fd, const struct iovec *iov, int nr_iov, off_t offset) |
| 169 | { |
| 170 | return -ENOSYS; |
| 171 | } |
| 172 | |
| 173 | static ssize_t |
| 174 | qemu_pwritev(int fd, const struct iovec *iov, int nr_iov, off_t offset) |
| 175 | { |
| 176 | return -ENOSYS; |
| 177 | } |
| 178 | |
| 179 | #endif |
| 180 | |
Kevin Wolf | 6769da2 | 2009-11-18 12:15:10 +0100 | [diff] [blame] | 181 | static ssize_t handle_aiocb_rw_vector(struct qemu_paiocb *aiocb) |
aliguori | ceb42de | 2009-04-07 18:43:28 +0000 | [diff] [blame] | 182 | { |
aliguori | ceb42de | 2009-04-07 18:43:28 +0000 | [diff] [blame] | 183 | ssize_t len; |
| 184 | |
| 185 | do { |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 186 | if (aiocb->aio_type & QEMU_AIO_WRITE) |
aliguori | ceb42de | 2009-04-07 18:43:28 +0000 | [diff] [blame] | 187 | len = qemu_pwritev(aiocb->aio_fildes, |
| 188 | aiocb->aio_iov, |
| 189 | aiocb->aio_niov, |
Frediano Ziglio | 21cfa41 | 2011-09-16 13:34:46 +0200 | [diff] [blame] | 190 | aiocb->aio_offset); |
aliguori | ceb42de | 2009-04-07 18:43:28 +0000 | [diff] [blame] | 191 | else |
| 192 | len = qemu_preadv(aiocb->aio_fildes, |
| 193 | aiocb->aio_iov, |
| 194 | aiocb->aio_niov, |
Frediano Ziglio | 21cfa41 | 2011-09-16 13:34:46 +0200 | [diff] [blame] | 195 | aiocb->aio_offset); |
aliguori | ceb42de | 2009-04-07 18:43:28 +0000 | [diff] [blame] | 196 | } while (len == -1 && errno == EINTR); |
| 197 | |
| 198 | if (len == -1) |
| 199 | return -errno; |
| 200 | return len; |
| 201 | } |
| 202 | |
Kevin Wolf | ba1d1af | 2011-07-25 19:42:37 +0200 | [diff] [blame] | 203 | /* |
| 204 | * Read/writes the data to/from a given linear buffer. |
| 205 | * |
| 206 | * Returns the number of bytes handles or -errno in case of an error. Short |
| 207 | * reads are only returned if the end of the file is reached. |
| 208 | */ |
Kevin Wolf | 6769da2 | 2009-11-18 12:15:10 +0100 | [diff] [blame] | 209 | static ssize_t handle_aiocb_rw_linear(struct qemu_paiocb *aiocb, char *buf) |
aliguori | 221f715 | 2009-03-28 17:28:41 +0000 | [diff] [blame] | 210 | { |
Kevin Wolf | 6769da2 | 2009-11-18 12:15:10 +0100 | [diff] [blame] | 211 | ssize_t offset = 0; |
| 212 | ssize_t len; |
aliguori | 221f715 | 2009-03-28 17:28:41 +0000 | [diff] [blame] | 213 | |
| 214 | while (offset < aiocb->aio_nbytes) { |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 215 | if (aiocb->aio_type & QEMU_AIO_WRITE) |
aliguori | f141eaf | 2009-04-07 18:43:24 +0000 | [diff] [blame] | 216 | len = pwrite(aiocb->aio_fildes, |
| 217 | (const char *)buf + offset, |
| 218 | aiocb->aio_nbytes - offset, |
| 219 | aiocb->aio_offset + offset); |
| 220 | else |
| 221 | len = pread(aiocb->aio_fildes, |
| 222 | buf + offset, |
aliguori | 221f715 | 2009-03-28 17:28:41 +0000 | [diff] [blame] | 223 | aiocb->aio_nbytes - offset, |
| 224 | aiocb->aio_offset + offset); |
aliguori | 221f715 | 2009-03-28 17:28:41 +0000 | [diff] [blame] | 225 | |
aliguori | f141eaf | 2009-04-07 18:43:24 +0000 | [diff] [blame] | 226 | if (len == -1 && errno == EINTR) |
| 227 | continue; |
| 228 | else if (len == -1) { |
| 229 | offset = -errno; |
| 230 | break; |
| 231 | } else if (len == 0) |
| 232 | break; |
aliguori | 221f715 | 2009-03-28 17:28:41 +0000 | [diff] [blame] | 233 | |
aliguori | f141eaf | 2009-04-07 18:43:24 +0000 | [diff] [blame] | 234 | offset += len; |
aliguori | 221f715 | 2009-03-28 17:28:41 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | return offset; |
| 238 | } |
| 239 | |
Kevin Wolf | 6769da2 | 2009-11-18 12:15:10 +0100 | [diff] [blame] | 240 | static ssize_t handle_aiocb_rw(struct qemu_paiocb *aiocb) |
aliguori | 221f715 | 2009-03-28 17:28:41 +0000 | [diff] [blame] | 241 | { |
Kevin Wolf | 6769da2 | 2009-11-18 12:15:10 +0100 | [diff] [blame] | 242 | ssize_t nbytes; |
aliguori | f141eaf | 2009-04-07 18:43:24 +0000 | [diff] [blame] | 243 | char *buf; |
aliguori | 221f715 | 2009-03-28 17:28:41 +0000 | [diff] [blame] | 244 | |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 245 | if (!(aiocb->aio_type & QEMU_AIO_MISALIGNED)) { |
aliguori | f141eaf | 2009-04-07 18:43:24 +0000 | [diff] [blame] | 246 | /* |
| 247 | * If there is just a single buffer, and it is properly aligned |
| 248 | * we can just use plain pread/pwrite without any problems. |
| 249 | */ |
aliguori | ceb42de | 2009-04-07 18:43:28 +0000 | [diff] [blame] | 250 | if (aiocb->aio_niov == 1) |
| 251 | return handle_aiocb_rw_linear(aiocb, aiocb->aio_iov->iov_base); |
| 252 | |
| 253 | /* |
| 254 | * We have more than one iovec, and all are properly aligned. |
| 255 | * |
| 256 | * Try preadv/pwritev first and fall back to linearizing the |
| 257 | * buffer if it's not supported. |
| 258 | */ |
Stefan Hajnoczi | b587a52 | 2010-05-27 12:52:08 +0100 | [diff] [blame] | 259 | if (preadv_present) { |
aliguori | ceb42de | 2009-04-07 18:43:28 +0000 | [diff] [blame] | 260 | nbytes = handle_aiocb_rw_vector(aiocb); |
| 261 | if (nbytes == aiocb->aio_nbytes) |
Stefan Hajnoczi | b587a52 | 2010-05-27 12:52:08 +0100 | [diff] [blame] | 262 | return nbytes; |
aliguori | ceb42de | 2009-04-07 18:43:28 +0000 | [diff] [blame] | 263 | if (nbytes < 0 && nbytes != -ENOSYS) |
| 264 | return nbytes; |
| 265 | preadv_present = 0; |
| 266 | } |
| 267 | |
| 268 | /* |
| 269 | * XXX(hch): short read/write. no easy way to handle the reminder |
| 270 | * using these interfaces. For now retry using plain |
| 271 | * pread/pwrite? |
| 272 | */ |
aliguori | f141eaf | 2009-04-07 18:43:24 +0000 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | /* |
| 276 | * Ok, we have to do it the hard way, copy all segments into |
| 277 | * a single aligned buffer. |
| 278 | */ |
Christoph Hellwig | 72aef73 | 2010-09-12 23:42:56 +0200 | [diff] [blame] | 279 | buf = qemu_blockalign(aiocb->common.bs, aiocb->aio_nbytes); |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 280 | if (aiocb->aio_type & QEMU_AIO_WRITE) { |
aliguori | f141eaf | 2009-04-07 18:43:24 +0000 | [diff] [blame] | 281 | char *p = buf; |
| 282 | int i; |
| 283 | |
| 284 | for (i = 0; i < aiocb->aio_niov; ++i) { |
| 285 | memcpy(p, aiocb->aio_iov[i].iov_base, aiocb->aio_iov[i].iov_len); |
| 286 | p += aiocb->aio_iov[i].iov_len; |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | nbytes = handle_aiocb_rw_linear(aiocb, buf); |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 291 | if (!(aiocb->aio_type & QEMU_AIO_WRITE)) { |
aliguori | f141eaf | 2009-04-07 18:43:24 +0000 | [diff] [blame] | 292 | char *p = buf; |
| 293 | size_t count = aiocb->aio_nbytes, copy; |
| 294 | int i; |
| 295 | |
| 296 | for (i = 0; i < aiocb->aio_niov && count; ++i) { |
| 297 | copy = count; |
| 298 | if (copy > aiocb->aio_iov[i].iov_len) |
| 299 | copy = aiocb->aio_iov[i].iov_len; |
| 300 | memcpy(aiocb->aio_iov[i].iov_base, p, copy); |
| 301 | p += copy; |
| 302 | count -= copy; |
| 303 | } |
| 304 | } |
| 305 | qemu_vfree(buf); |
| 306 | |
| 307 | return nbytes; |
aliguori | 221f715 | 2009-03-28 17:28:41 +0000 | [diff] [blame] | 308 | } |
| 309 | |
Frediano Ziglio | e1d3b25 | 2011-09-19 16:37:13 +0200 | [diff] [blame] | 310 | static void posix_aio_notify_event(void); |
| 311 | |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 312 | static void *aio_thread(void *unused) |
| 313 | { |
Avi Kivity | e4ea78e | 2011-08-14 07:04:49 +0300 | [diff] [blame] | 314 | mutex_lock(&lock); |
| 315 | pending_threads--; |
| 316 | mutex_unlock(&lock); |
| 317 | do_spawn_thread(); |
| 318 | |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 319 | while (1) { |
| 320 | struct qemu_paiocb *aiocb; |
Kevin Wolf | 6769da2 | 2009-11-18 12:15:10 +0100 | [diff] [blame] | 321 | ssize_t ret = 0; |
malc | 30525af | 2009-02-21 05:48:13 +0000 | [diff] [blame] | 322 | qemu_timeval tv; |
| 323 | struct timespec ts; |
| 324 | |
| 325 | qemu_gettimeofday(&tv); |
| 326 | ts.tv_sec = tv.tv_sec + 10; |
| 327 | ts.tv_nsec = 0; |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 328 | |
malc | 8653c01 | 2009-02-21 05:48:11 +0000 | [diff] [blame] | 329 | mutex_lock(&lock); |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 330 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 331 | while (QTAILQ_EMPTY(&request_list) && |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 332 | !(ret == ETIMEDOUT)) { |
Kevin Wolf | 5be4aab | 2011-05-02 17:32:54 +0200 | [diff] [blame] | 333 | idle_threads++; |
malc | 8653c01 | 2009-02-21 05:48:11 +0000 | [diff] [blame] | 334 | ret = cond_timedwait(&cond, &lock, &ts); |
Kevin Wolf | 5be4aab | 2011-05-02 17:32:54 +0200 | [diff] [blame] | 335 | idle_threads--; |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 336 | } |
| 337 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 338 | if (QTAILQ_EMPTY(&request_list)) |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 339 | break; |
| 340 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 341 | aiocb = QTAILQ_FIRST(&request_list); |
| 342 | QTAILQ_REMOVE(&request_list, aiocb, node); |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 343 | aiocb->active = 1; |
malc | 8653c01 | 2009-02-21 05:48:11 +0000 | [diff] [blame] | 344 | mutex_unlock(&lock); |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 345 | |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 346 | switch (aiocb->aio_type & QEMU_AIO_TYPE_MASK) { |
| 347 | case QEMU_AIO_READ: |
Kevin Wolf | ba1d1af | 2011-07-25 19:42:37 +0200 | [diff] [blame] | 348 | ret = handle_aiocb_rw(aiocb); |
| 349 | if (ret >= 0 && ret < aiocb->aio_nbytes && aiocb->common.bs->growable) { |
| 350 | /* A short read means that we have reached EOF. Pad the buffer |
| 351 | * with zeros for bytes after EOF. */ |
| 352 | QEMUIOVector qiov; |
| 353 | |
| 354 | qemu_iovec_init_external(&qiov, aiocb->aio_iov, |
| 355 | aiocb->aio_niov); |
| 356 | qemu_iovec_memset_skip(&qiov, 0, aiocb->aio_nbytes - ret, ret); |
| 357 | |
| 358 | ret = aiocb->aio_nbytes; |
| 359 | } |
| 360 | break; |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 361 | case QEMU_AIO_WRITE: |
Stefan Hajnoczi | b587a52 | 2010-05-27 12:52:08 +0100 | [diff] [blame] | 362 | ret = handle_aiocb_rw(aiocb); |
| 363 | break; |
Christoph Hellwig | b2e12bc | 2009-09-04 19:01:49 +0200 | [diff] [blame] | 364 | case QEMU_AIO_FLUSH: |
Stefan Hajnoczi | b587a52 | 2010-05-27 12:52:08 +0100 | [diff] [blame] | 365 | ret = handle_aiocb_flush(aiocb); |
| 366 | break; |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 367 | case QEMU_AIO_IOCTL: |
Stefan Hajnoczi | b587a52 | 2010-05-27 12:52:08 +0100 | [diff] [blame] | 368 | ret = handle_aiocb_ioctl(aiocb); |
| 369 | break; |
| 370 | default: |
| 371 | fprintf(stderr, "invalid aio request (0x%x)\n", aiocb->aio_type); |
| 372 | ret = -EINVAL; |
| 373 | break; |
| 374 | } |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 375 | |
malc | 8653c01 | 2009-02-21 05:48:11 +0000 | [diff] [blame] | 376 | mutex_lock(&lock); |
aliguori | 221f715 | 2009-03-28 17:28:41 +0000 | [diff] [blame] | 377 | aiocb->ret = ret; |
malc | 8653c01 | 2009-02-21 05:48:11 +0000 | [diff] [blame] | 378 | mutex_unlock(&lock); |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 379 | |
Frediano Ziglio | e1d3b25 | 2011-09-19 16:37:13 +0200 | [diff] [blame] | 380 | posix_aio_notify_event(); |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 381 | } |
| 382 | |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 383 | cur_threads--; |
malc | 8653c01 | 2009-02-21 05:48:11 +0000 | [diff] [blame] | 384 | mutex_unlock(&lock); |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 385 | |
| 386 | return NULL; |
| 387 | } |
| 388 | |
Avi Kivity | e4ea78e | 2011-08-14 07:04:49 +0300 | [diff] [blame] | 389 | static void do_spawn_thread(void) |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 390 | { |
malc | ee39930 | 2009-09-25 00:20:44 +0400 | [diff] [blame] | 391 | sigset_t set, oldset; |
| 392 | |
Avi Kivity | e4ea78e | 2011-08-14 07:04:49 +0300 | [diff] [blame] | 393 | mutex_lock(&lock); |
| 394 | if (!new_threads) { |
| 395 | mutex_unlock(&lock); |
| 396 | return; |
| 397 | } |
| 398 | |
| 399 | new_threads--; |
| 400 | pending_threads++; |
| 401 | |
| 402 | mutex_unlock(&lock); |
malc | ee39930 | 2009-09-25 00:20:44 +0400 | [diff] [blame] | 403 | |
| 404 | /* block all signals */ |
| 405 | if (sigfillset(&set)) die("sigfillset"); |
| 406 | if (sigprocmask(SIG_SETMASK, &set, &oldset)) die("sigprocmask"); |
| 407 | |
malc | 8653c01 | 2009-02-21 05:48:11 +0000 | [diff] [blame] | 408 | thread_create(&thread_id, &attr, aio_thread, NULL); |
malc | ee39930 | 2009-09-25 00:20:44 +0400 | [diff] [blame] | 409 | |
| 410 | if (sigprocmask(SIG_SETMASK, &oldset, NULL)) die("sigprocmask restore"); |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 411 | } |
| 412 | |
Avi Kivity | e4ea78e | 2011-08-14 07:04:49 +0300 | [diff] [blame] | 413 | static void spawn_thread_bh_fn(void *opaque) |
| 414 | { |
| 415 | do_spawn_thread(); |
| 416 | } |
| 417 | |
| 418 | static void spawn_thread(void) |
| 419 | { |
| 420 | cur_threads++; |
| 421 | new_threads++; |
| 422 | /* If there are threads being created, they will spawn new workers, so |
| 423 | * we don't spend time creating many threads in a loop holding a mutex or |
| 424 | * starving the current vcpu. |
| 425 | * |
| 426 | * If there are no idle threads, ask the main thread to create one, so we |
| 427 | * inherit the correct affinity instead of the vcpu affinity. |
| 428 | */ |
| 429 | if (!pending_threads) { |
| 430 | qemu_bh_schedule(new_thread_bh); |
| 431 | } |
| 432 | } |
| 433 | |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 434 | static void qemu_paio_submit(struct qemu_paiocb *aiocb) |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 435 | { |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 436 | aiocb->ret = -EINPROGRESS; |
| 437 | aiocb->active = 0; |
malc | 8653c01 | 2009-02-21 05:48:11 +0000 | [diff] [blame] | 438 | mutex_lock(&lock); |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 439 | if (idle_threads == 0 && cur_threads < max_threads) |
| 440 | spawn_thread(); |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 441 | QTAILQ_INSERT_TAIL(&request_list, aiocb, node); |
malc | 8653c01 | 2009-02-21 05:48:11 +0000 | [diff] [blame] | 442 | mutex_unlock(&lock); |
malc | 5d47e37 | 2009-02-21 05:48:15 +0000 | [diff] [blame] | 443 | cond_signal(&cond); |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 444 | } |
| 445 | |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 446 | static ssize_t qemu_paio_return(struct qemu_paiocb *aiocb) |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 447 | { |
| 448 | ssize_t ret; |
| 449 | |
malc | 8653c01 | 2009-02-21 05:48:11 +0000 | [diff] [blame] | 450 | mutex_lock(&lock); |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 451 | ret = aiocb->ret; |
malc | 8653c01 | 2009-02-21 05:48:11 +0000 | [diff] [blame] | 452 | mutex_unlock(&lock); |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 453 | |
| 454 | return ret; |
| 455 | } |
| 456 | |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 457 | static int qemu_paio_error(struct qemu_paiocb *aiocb) |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 458 | { |
| 459 | ssize_t ret = qemu_paio_return(aiocb); |
| 460 | |
| 461 | if (ret < 0) |
| 462 | ret = -ret; |
| 463 | else |
| 464 | ret = 0; |
| 465 | |
| 466 | return ret; |
| 467 | } |
| 468 | |
Kevin Wolf | 59c7b15 | 2009-10-22 17:54:35 +0200 | [diff] [blame] | 469 | static int posix_aio_process_queue(void *opaque) |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 470 | { |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 471 | PosixAioState *s = opaque; |
| 472 | struct qemu_paiocb *acb, **pacb; |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 473 | int ret; |
Kevin Wolf | 59c7b15 | 2009-10-22 17:54:35 +0200 | [diff] [blame] | 474 | int result = 0; |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 475 | |
| 476 | for(;;) { |
| 477 | pacb = &s->first_aio; |
| 478 | for(;;) { |
| 479 | acb = *pacb; |
| 480 | if (!acb) |
Kevin Wolf | 59c7b15 | 2009-10-22 17:54:35 +0200 | [diff] [blame] | 481 | return result; |
Kevin Wolf | e5f3764 | 2009-10-22 17:54:40 +0200 | [diff] [blame] | 482 | |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 483 | ret = qemu_paio_error(acb); |
| 484 | if (ret == ECANCELED) { |
| 485 | /* remove the request */ |
| 486 | *pacb = acb->next; |
| 487 | qemu_aio_release(acb); |
Kevin Wolf | 59c7b15 | 2009-10-22 17:54:35 +0200 | [diff] [blame] | 488 | result = 1; |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 489 | } else if (ret != EINPROGRESS) { |
| 490 | /* end of aio */ |
| 491 | if (ret == 0) { |
| 492 | ret = qemu_paio_return(acb); |
| 493 | if (ret == acb->aio_nbytes) |
| 494 | ret = 0; |
| 495 | else |
| 496 | ret = -EINVAL; |
| 497 | } else { |
| 498 | ret = -ret; |
| 499 | } |
Stefan Hajnoczi | ddca9fb | 2011-03-07 08:06:10 +0000 | [diff] [blame] | 500 | |
| 501 | trace_paio_complete(acb, acb->common.opaque, ret); |
| 502 | |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 503 | /* remove the request */ |
| 504 | *pacb = acb->next; |
| 505 | /* call the callback */ |
| 506 | acb->common.cb(acb->common.opaque, ret); |
| 507 | qemu_aio_release(acb); |
Kevin Wolf | 59c7b15 | 2009-10-22 17:54:35 +0200 | [diff] [blame] | 508 | result = 1; |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 509 | break; |
| 510 | } else { |
| 511 | pacb = &acb->next; |
| 512 | } |
| 513 | } |
| 514 | } |
Kevin Wolf | 59c7b15 | 2009-10-22 17:54:35 +0200 | [diff] [blame] | 515 | |
| 516 | return result; |
| 517 | } |
| 518 | |
| 519 | static void posix_aio_read(void *opaque) |
| 520 | { |
| 521 | PosixAioState *s = opaque; |
| 522 | ssize_t len; |
| 523 | |
| 524 | /* read all bytes from signal pipe */ |
| 525 | for (;;) { |
| 526 | char bytes[16]; |
| 527 | |
| 528 | len = read(s->rfd, bytes, sizeof(bytes)); |
| 529 | if (len == -1 && errno == EINTR) |
| 530 | continue; /* try again */ |
| 531 | if (len == sizeof(bytes)) |
| 532 | continue; /* more to read */ |
| 533 | break; |
| 534 | } |
| 535 | |
| 536 | posix_aio_process_queue(s); |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | static int posix_aio_flush(void *opaque) |
| 540 | { |
| 541 | PosixAioState *s = opaque; |
| 542 | return !!s->first_aio; |
| 543 | } |
| 544 | |
| 545 | static PosixAioState *posix_aio_state; |
| 546 | |
Frediano Ziglio | e1d3b25 | 2011-09-19 16:37:13 +0200 | [diff] [blame] | 547 | static void posix_aio_notify_event(void) |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 548 | { |
Frediano Ziglio | e1d3b25 | 2011-09-19 16:37:13 +0200 | [diff] [blame] | 549 | char byte = 0; |
| 550 | ssize_t ret; |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 551 | |
Frediano Ziglio | e1d3b25 | 2011-09-19 16:37:13 +0200 | [diff] [blame] | 552 | ret = write(posix_aio_state->wfd, &byte, sizeof(byte)); |
| 553 | if (ret < 0 && errno != EAGAIN) |
| 554 | die("write()"); |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | static void paio_remove(struct qemu_paiocb *acb) |
| 558 | { |
| 559 | struct qemu_paiocb **pacb; |
| 560 | |
| 561 | /* remove the callback from the queue */ |
| 562 | pacb = &posix_aio_state->first_aio; |
| 563 | for(;;) { |
| 564 | if (*pacb == NULL) { |
| 565 | fprintf(stderr, "paio_remove: aio request not found!\n"); |
| 566 | break; |
| 567 | } else if (*pacb == acb) { |
| 568 | *pacb = acb->next; |
| 569 | qemu_aio_release(acb); |
| 570 | break; |
| 571 | } |
| 572 | pacb = &(*pacb)->next; |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | static void paio_cancel(BlockDriverAIOCB *blockacb) |
| 577 | { |
| 578 | struct qemu_paiocb *acb = (struct qemu_paiocb *)blockacb; |
| 579 | int active = 0; |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 580 | |
Stefan Hajnoczi | ddca9fb | 2011-03-07 08:06:10 +0000 | [diff] [blame] | 581 | trace_paio_cancel(acb, acb->common.opaque); |
| 582 | |
malc | 8653c01 | 2009-02-21 05:48:11 +0000 | [diff] [blame] | 583 | mutex_lock(&lock); |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 584 | if (!acb->active) { |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 585 | QTAILQ_REMOVE(&request_list, acb, node); |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 586 | acb->ret = -ECANCELED; |
| 587 | } else if (acb->ret == -EINPROGRESS) { |
| 588 | active = 1; |
| 589 | } |
malc | 8653c01 | 2009-02-21 05:48:11 +0000 | [diff] [blame] | 590 | mutex_unlock(&lock); |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 591 | |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 592 | if (active) { |
| 593 | /* fail safe: if the aio could not be canceled, we wait for |
| 594 | it */ |
| 595 | while (qemu_paio_error(acb) == EINPROGRESS) |
| 596 | ; |
| 597 | } |
| 598 | |
| 599 | paio_remove(acb); |
| 600 | } |
| 601 | |
| 602 | static AIOPool raw_aio_pool = { |
| 603 | .aiocb_size = sizeof(struct qemu_paiocb), |
| 604 | .cancel = paio_cancel, |
| 605 | }; |
| 606 | |
Kevin Wolf | 1e5b9d2 | 2009-10-26 13:03:08 +0100 | [diff] [blame] | 607 | BlockDriverAIOCB *paio_submit(BlockDriverState *bs, int fd, |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 608 | int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, |
| 609 | BlockDriverCompletionFunc *cb, void *opaque, int type) |
| 610 | { |
| 611 | struct qemu_paiocb *acb; |
| 612 | |
| 613 | acb = qemu_aio_get(&raw_aio_pool, bs, cb, opaque); |
| 614 | if (!acb) |
| 615 | return NULL; |
| 616 | acb->aio_type = type; |
| 617 | acb->aio_fildes = fd; |
Kevin Wolf | e5f3764 | 2009-10-22 17:54:40 +0200 | [diff] [blame] | 618 | |
Christoph Hellwig | b2e12bc | 2009-09-04 19:01:49 +0200 | [diff] [blame] | 619 | if (qiov) { |
| 620 | acb->aio_iov = qiov->iov; |
| 621 | acb->aio_niov = qiov->niov; |
| 622 | } |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 623 | acb->aio_nbytes = nb_sectors * 512; |
| 624 | acb->aio_offset = sector_num * 512; |
| 625 | |
| 626 | acb->next = posix_aio_state->first_aio; |
| 627 | posix_aio_state->first_aio = acb; |
| 628 | |
Stefan Hajnoczi | 6d519a5 | 2010-05-22 18:15:08 +0100 | [diff] [blame] | 629 | trace_paio_submit(acb, opaque, sector_num, nb_sectors, type); |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 630 | qemu_paio_submit(acb); |
| 631 | return &acb->common; |
| 632 | } |
| 633 | |
| 634 | BlockDriverAIOCB *paio_ioctl(BlockDriverState *bs, int fd, |
| 635 | unsigned long int req, void *buf, |
| 636 | BlockDriverCompletionFunc *cb, void *opaque) |
| 637 | { |
| 638 | struct qemu_paiocb *acb; |
| 639 | |
| 640 | acb = qemu_aio_get(&raw_aio_pool, bs, cb, opaque); |
| 641 | if (!acb) |
| 642 | return NULL; |
| 643 | acb->aio_type = QEMU_AIO_IOCTL; |
| 644 | acb->aio_fildes = fd; |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 645 | acb->aio_offset = 0; |
| 646 | acb->aio_ioctl_buf = buf; |
| 647 | acb->aio_ioctl_cmd = req; |
| 648 | |
| 649 | acb->next = posix_aio_state->first_aio; |
| 650 | posix_aio_state->first_aio = acb; |
| 651 | |
| 652 | qemu_paio_submit(acb); |
| 653 | return &acb->common; |
| 654 | } |
| 655 | |
Kevin Wolf | 1e5b9d2 | 2009-10-26 13:03:08 +0100 | [diff] [blame] | 656 | int paio_init(void) |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 657 | { |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 658 | PosixAioState *s; |
| 659 | int fds[2]; |
| 660 | int ret; |
| 661 | |
| 662 | if (posix_aio_state) |
Kevin Wolf | 1e5b9d2 | 2009-10-26 13:03:08 +0100 | [diff] [blame] | 663 | return 0; |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 664 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 665 | s = g_malloc(sizeof(PosixAioState)); |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 666 | |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 667 | s->first_aio = NULL; |
Kevin Wolf | 40ff6d7 | 2009-12-02 12:24:42 +0100 | [diff] [blame] | 668 | if (qemu_pipe(fds) == -1) { |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 669 | fprintf(stderr, "failed to create pipe\n"); |
Kevin Wolf | 1e5b9d2 | 2009-10-26 13:03:08 +0100 | [diff] [blame] | 670 | return -1; |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | s->rfd = fds[0]; |
| 674 | s->wfd = fds[1]; |
| 675 | |
| 676 | fcntl(s->rfd, F_SETFL, O_NONBLOCK); |
| 677 | fcntl(s->wfd, F_SETFL, O_NONBLOCK); |
| 678 | |
Kevin Wolf | 8febfa2 | 2009-10-22 17:54:36 +0200 | [diff] [blame] | 679 | qemu_aio_set_fd_handler(s->rfd, posix_aio_read, NULL, posix_aio_flush, |
| 680 | posix_aio_process_queue, s); |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 681 | |
| 682 | ret = pthread_attr_init(&attr); |
| 683 | if (ret) |
| 684 | die2(ret, "pthread_attr_init"); |
| 685 | |
| 686 | ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); |
| 687 | if (ret) |
| 688 | die2(ret, "pthread_attr_setdetachstate"); |
| 689 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 690 | QTAILQ_INIT(&request_list); |
Avi Kivity | e4ea78e | 2011-08-14 07:04:49 +0300 | [diff] [blame] | 691 | new_thread_bh = qemu_bh_new(spawn_thread_bh_fn, NULL); |
Christoph Hellwig | 9ef91a6 | 2009-08-20 16:58:19 +0200 | [diff] [blame] | 692 | |
| 693 | posix_aio_state = s; |
Kevin Wolf | 1e5b9d2 | 2009-10-26 13:03:08 +0100 | [diff] [blame] | 694 | return 0; |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 695 | } |