[PATCH v2 09/10] kvm tools: Add aio read write functions

Sasha Levin
2011-11-01T16:08:26Z

This patch adds basic native vectored AIO functions.

These functions should be optimized to process multiple io
requests at once.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
tools/kvm/Makefile | 1 +
tools/kvm/include/kvm/read-write.h | 6 ++++++
tools/kvm/read-write.c | 24 ++++++++++++++++++++++++
3 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index d9baa69..6095440 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -124,6 +124,7 @@ OBJS += bios/bios-rom.o
LIBS += -lrt
LIBS += -lpthread
LIBS += -lutil
+LIBS += -laio

# Additional ARCH settings for x86
ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
diff --git a/tools/kvm/include/kvm/read-write.h b/tools/kvm/include/kvm/read-write.h
index 3351103..89c1590 100644
--- a/tools/kvm/include/kvm/read-write.h
+++ b/tools/kvm/include/kvm/read-write.h
@@ -4,6 +4,7 @@
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
+#include <libaio.h>

ssize_t xread(int fd, void *buf, size_t count);
ssize_t xwrite(int fd, const void *buf, size_t count);
@@ -29,4 +30,9 @@ ssize_t xpwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset);
ssize_t preadv_in_full(int fd, const struct iovec *iov, int iovcnt, off_t offset);
ssize_t pwritev_in_full(int fd, const struct iovec *iov, int iovcnt, off_t offset);

+int aio_preadv(io_context_t ctx, struct iocb *iocb, int fd, const struct iovec *iov, int iovcnt,
+ off_t offset, int ev, void *param);
+int aio_pwritev(io_context_t ctx, struct iocb *iocb, int fd, const struct iovec *iov, int iovcnt,
+ off_t offset, int ev, void *param);
+
#endif /* KVM_READ_WRITE_H */
diff --git a/tools/kvm/read-write.c b/tools/kvm/read-write.c
index 737fb26..be5a4fa 100644
--- a/tools/kvm/read-write.c
+++ b/tools/kvm/read-write.c
@@ -316,3 +316,27 @@ ssize_t pwritev_in_full(int fd, const struct iovec *iov, int iovcnt, off_t offse

return total;
}
+
+int aio_pwritev(io_context_t ctx, struct iocb *iocb, int fd, const struct iovec *iov, int iovcnt,
+ off_t offset, int ev, void *param)
+{
+ struct iocb *ios[1] = { iocb };
+
+ io_prep_pwritev(iocb, fd, iov, iovcnt, offset);
+ io_set_eventfd(iocb, ev);
+ iocb->data = param;
+
+ return io_submit(ctx, 1, ios);
+}
+
+int aio_preadv(io_context_t ctx, struct iocb *iocb, int fd, const struct iovec *iov, int iovcnt,
+ off_t offset, int ev, void *param)
+{
+ struct iocb *ios[1] = { iocb };
+
+ io_prep_preadv(iocb, fd, iov, iovcnt, offset);
+ io_set_eventfd(iocb, ev);
+ iocb->data = param;
+
+ return io_submit(ctx, 1, ios);
+}
--
1.7.7.1