From: Sasha Levin Date: Wed, 2 Nov 2011 05:41:13 +0000 (+0200) Subject: kvm tools: Add aio read write functions X-Git-Tag: next-20111103~2^2~2 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=7936faf28ecd1242d8b2d0bec63774d16ac64bac;p=karo-tx-linux.git kvm tools: Add aio read write functions 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 Signed-off-by: Pekka Enberg --- diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile index d9baa69d86f2..d4598caa6932 100644 --- a/tools/kvm/Makefile +++ b/tools/kvm/Makefile @@ -115,6 +115,13 @@ ifeq ($(has_ZLIB),y) LIBS += -lz endif +FLAGS_AIO := $(CFLAGS) -laio +has_AIO := $(call try-cc,$(SOURCE_AIO),$(FLAGS_AIO)) +ifeq ($(has_AIO),y) + CFLAGS += -DCONFIG_HAS_AIO + LIBS += -laio +endif + DEPS := $(patsubst %.o,%.d,$(OBJS)) # Exclude BIOS object files from header dependencies. diff --git a/tools/kvm/config/feature-tests.mak b/tools/kvm/config/feature-tests.mak index a75c31d79c1a..be9ebc0c052a 100644 --- a/tools/kvm/config/feature-tests.mak +++ b/tools/kvm/config/feature-tests.mak @@ -156,3 +156,13 @@ int main(void) return 0; } endef + +define SOURCE_AIO +#include + +int main(void) +{ + io_setup(0, NULL); + return 0; +} +endef diff --git a/tools/kvm/include/kvm/read-write.h b/tools/kvm/include/kvm/read-write.h index 3351103edeab..67571f9671c7 100644 --- a/tools/kvm/include/kvm/read-write.h +++ b/tools/kvm/include/kvm/read-write.h @@ -5,6 +5,10 @@ #include #include +#ifdef CONFIG_HAS_AIO +#include +#endif + ssize_t xread(int fd, void *buf, size_t count); ssize_t xwrite(int fd, const void *buf, size_t count); @@ -29,4 +33,11 @@ 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); +#ifdef CONFIG_HAS_AIO +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 + #endif /* KVM_READ_WRITE_H */ diff --git a/tools/kvm/read-write.c b/tools/kvm/read-write.c index 737fb26ddfbe..55473ba30dc9 100644 --- a/tools/kvm/read-write.c +++ b/tools/kvm/read-write.c @@ -316,3 +316,29 @@ ssize_t pwritev_in_full(int fd, const struct iovec *iov, int iovcnt, off_t offse return total; } + +#ifdef CONFIG_HAS_AIO +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); +} +#endif \ No newline at end of file