*/
#include "qemu-common.h"
#include "qemu-aio.h"
-#include "block_int.h"
#include "block/raw-posix-aio.h"
#include <sys/eventfd.h>
struct iocb iocb;
ssize_t ret;
size_t nbytes;
+ QEMUIOVector *qiov;
+ bool is_read;
QLIST_ENTRY(qemu_laiocb) node;
};
ret = laiocb->ret;
if (ret != -ECANCELED) {
- if (ret == laiocb->nbytes)
+ if (ret == laiocb->nbytes) {
ret = 0;
- else if (ret >= 0)
- ret = -EINVAL;
+ } else if (ret >= 0) {
+ /* Short reads mean EOF, pad with zeros. */
+ if (laiocb->is_read) {
+ qemu_iovec_memset_skip(laiocb->qiov, 0,
+ laiocb->qiov->size - ret, ret);
+ } else {
+ ret = -EINVAL;
+ }
+ }
laiocb->common.cb(laiocb->common.opaque, ret);
}
qemu_aio_release(laiocb);
}
-/*
- * All requests are directly processed when they complete, so there's nothing
- * left to do during qemu_aio_wait().
- */
-static int qemu_laio_process_requests(void *opaque)
-{
- return 0;
-}
-
static void qemu_laio_completion_cb(void *opaque)
{
struct qemu_laio_state *s = opaque;
off_t offset = sector_num * 512;
laiocb = qemu_aio_get(&laio_pool, bs, cb, opaque);
- if (!laiocb)
- return NULL;
laiocb->nbytes = nb_sectors * 512;
laiocb->ctx = s;
laiocb->ret = -EINPROGRESS;
+ laiocb->is_read = (type == QEMU_AIO_READ);
+ laiocb->qiov = qiov;
iocbs = &laiocb->iocb;
case QEMU_AIO_READ:
io_prep_preadv(iocbs, fd, qiov->iov, qiov->niov, offset);
break;
+ /* Currently Linux kernel does not support other operations */
default:
fprintf(stderr, "%s: invalid AIO request type 0x%x.\n",
__func__, type);
goto out_dec_count;
return &laiocb->common;
-out_free_aiocb:
- qemu_aio_release(laiocb);
out_dec_count:
s->count--;
+out_free_aiocb:
+ qemu_aio_release(laiocb);
return NULL;
}
goto out_close_efd;
qemu_aio_set_fd_handler(s->efd, qemu_laio_completion_cb, NULL,
- qemu_laio_flush_cb, qemu_laio_process_requests, s);
+ qemu_laio_flush_cb, NULL, s);
return s;