]> git.proxmox.com Git - mirror_qemu.git/commitdiff
iov: don't touch iov in iov_send_recv()
authorWen Congyang <wency@cn.fujitsu.com>
Thu, 21 May 2015 01:50:10 +0000 (09:50 +0800)
committerStefan Hajnoczi <stefanha@redhat.com>
Tue, 23 Jun 2015 15:05:34 +0000 (16:05 +0100)
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
Message-id: 555D39D2.4000705@cn.fujitsu.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
include/qemu/iov.h
util/iov.c

index 68d25f29b76c6deb09e1ef99e7457ebd75a9cb8b..569b2c2a23f24de82d74cf33e0fb35ef319b958f 100644 (file)
@@ -75,7 +75,7 @@ size_t iov_memset(const struct iovec *iov, const unsigned int iov_cnt,
  * For iov_send_recv() _whole_ area being sent or received
  * should be within the iovec, not only beginning of it.
  */
-ssize_t iov_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt,
+ssize_t iov_send_recv(int sockfd, const struct iovec *iov, unsigned iov_cnt,
                       size_t offset, size_t bytes, bool do_send);
 #define iov_recv(sockfd, iov, iov_cnt, offset, bytes) \
   iov_send_recv(sockfd, iov, iov_cnt, offset, bytes, false)
index 2fb18e665426ae8064b0e56ca04061772406487a..a0d5934e8eecb011089390df92cbd1f7cd532e6f 100644 (file)
@@ -133,7 +133,7 @@ do_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt, bool do_send)
 #endif
 }
 
-ssize_t iov_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt,
+ssize_t iov_send_recv(int sockfd, const struct iovec *_iov, unsigned iov_cnt,
                       size_t offset, size_t bytes,
                       bool do_send)
 {
@@ -141,6 +141,16 @@ ssize_t iov_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt,
     ssize_t ret;
     size_t orig_len, tail;
     unsigned niov;
+    struct iovec *local_iov, *iov;
+
+    if (bytes <= 0) {
+        return 0;
+    }
+
+    local_iov = g_new0(struct iovec, iov_cnt);
+    iov_copy(local_iov, iov_cnt, _iov, iov_cnt, offset, bytes);
+    offset = 0;
+    iov = local_iov;
 
     while (bytes > 0) {
         /* Find the start position, skipping `offset' bytes:
@@ -187,6 +197,7 @@ ssize_t iov_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt,
 
         if (ret < 0) {
             assert(errno != EINTR);
+            g_free(local_iov);
             if (errno == EAGAIN && total > 0) {
                 return total;
             }
@@ -205,6 +216,7 @@ ssize_t iov_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt,
         bytes -= ret;
     }
 
+    g_free(local_iov);
     return total;
 }