diff mbox

[RFC/PATCH] kvm tools: Use preadv/pwritev syscalls directly

Message ID 1305745086-7868-1-git-send-email-penberg@kernel.org (mailing list archive)
State New, archived
Headers show

Commit Message

Pekka Enberg May 18, 2011, 6:58 p.m. UTC
"bornto befrag <born2befrag@gmail.com>" reported the following compilation
error:

  > When i compile i kvm native tool tools/kvm && make i get this
  >
  >  CC       read-write.o
  > cc1: warnings being treated as errors
  > read-write.c: In function ‘xpreadv’:
  > read-write.c:255: error: implicit declaration of function ‘preadv’
  > read-write.c:255: error: nested extern declaration of ‘preadv’
  > read-write.c: In function ‘xpwritev’:
  > read-write.c:268: error: implicit declaration of function ‘pwritev’
  > read-write.c:268: error: nested extern declaration of ‘pwritev’
  > make: *** [read-write.o] Error 1

Commit 28f95a5 ("kvm tools: Fix includes for preadv/pwritev") attempted to fix
the issue by adding a missing include. However, as it turns out, the problem
is that glibc 2.7 doesn't have preadv()/pwritev() definitions.

Therefore, use the system calls directly to fix the issue.

Cc: Asias He <asias.hejun@gmail.com>
Cc: Avi Kivity <avi@redhat.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Prasad Joshi <prasadjoshi124@gmail.com>
Cc: Sasha Levin <levinsasha928@gmail.com>
Reported-by: <born2befrag@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
---
 tools/kvm/read-write.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/tools/kvm/read-write.c b/tools/kvm/read-write.c
index 7e233b5..dc8c076 100644
--- a/tools/kvm/read-write.c
+++ b/tools/kvm/read-write.c
@@ -1,11 +1,13 @@ 
 #include "kvm/read-write.h"
 
+#include <sys/syscall.h>
 #include <sys/types.h>
-#include <sys/uio.h>
 #include <unistd.h>
 #include <string.h>
 #include <errno.h>
 
+#include <asm/unistd.h>
+
 /* Same as read(2) except that this function never returns EAGAIN or EINTR. */
 ssize_t xread(int fd, void *buf, size_t count)
 {
@@ -247,26 +249,36 @@  ssize_t writev_in_full(int fd, const struct iovec *iov, int iovcnt)
 	return total;
 }
 
+static inline ssize_t sys_preadv(int fd, const struct iovec *iovec, int count, off_t offset)
+{
+	return syscall(__NR_preadv, fd, iovec, count, offset);
+}
+
 /* Same as preadv(2) except that this function never returns EAGAIN or EINTR. */
 ssize_t xpreadv(int fd, const struct iovec *iov, int iovcnt, off_t offset)
 {
 	ssize_t nr;
 
 restart:
-	nr = preadv(fd, iov, iovcnt, offset);
+	nr = sys_preadv(fd, iov, iovcnt, offset);
 	if ((nr < 0) && ((errno == EAGAIN) || (errno == EINTR)))
 		goto restart;
 
 	return nr;
 }
 
+static inline ssize_t sys_pwritev(int fd, const struct iovec *iovec, int count, off_t offset)
+{
+	return syscall(__NR_pwritev, fd, iovec, count, offset);
+}
+
 /* Same as pwritev(2) except that this function never returns EAGAIN or EINTR. */
 ssize_t xpwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset)
 {
 	ssize_t nr;
 
 restart:
-	nr = pwritev(fd, iov, iovcnt, offset);
+	nr = sys_pwritev(fd, iov, iovcnt, offset);
 	if ((nr < 0) && ((errno == EAGAIN) || (errno == EINTR)))
 		goto restart;