]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Add aio read write functions
authorSasha Levin <levinsasha928@gmail.com>
Wed, 2 Nov 2011 05:41:13 +0000 (07:41 +0200)
committerPekka Enberg <penberg@kernel.org>
Wed, 2 Nov 2011 06:21:31 +0000 (08:21 +0200)
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>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/Makefile
tools/kvm/config/feature-tests.mak
tools/kvm/include/kvm/read-write.h
tools/kvm/read-write.c

index d9baa69d86f2eb641daff4ae99ce7e85b9170659..d4598caa69327b84ac1c81f0ff170e5563dcc553 100644 (file)
@@ -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.
index a75c31d79c1a143c94f1dbfe5602ac70614ede39..be9ebc0c052ae17bd36f339b3a53878bba71e5fc 100644 (file)
@@ -156,3 +156,13 @@ int main(void)
        return 0;
 }
 endef
+
+define SOURCE_AIO
+#include <libaio.h>
+
+int main(void)
+{
+       io_setup(0, NULL);
+       return 0;
+}
+endef
index 3351103edeabd9a2cf0554ae166c610babe5c802..67571f9671c7e7c68722870adb1b3684078013ec 100644 (file)
@@ -5,6 +5,10 @@
 #include <sys/uio.h>
 #include <unistd.h>
 
+#ifdef CONFIG_HAS_AIO
+#include <libaio.h>
+#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 */
index 737fb26ddfbe014b74af154a851300c75b448843..55473ba30dc91db4b14db7b39188fe7cac6d3579 100644 (file)
@@ -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