[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 13/15] iov: don't touch iov in iov_send_recv()
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PULL 13/15] iov: don't touch iov in iov_send_recv() |
Date: |
Wed, 24 Jun 2015 16:28:04 +0100 |
From: Wen Congyang <address@hidden>
Signed-off-by: Wen Congyang <address@hidden>
Message-id: address@hidden
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
include/qemu/iov.h | 2 +-
util/iov.c | 14 +++++++++++++-
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/include/qemu/iov.h b/include/qemu/iov.h
index 68d25f2..569b2c2 100644
--- a/include/qemu/iov.h
+++ b/include/qemu/iov.h
@@ -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)
diff --git a/util/iov.c b/util/iov.c
index 2fb18e6..a0d5934 100644
--- a/util/iov.c
+++ b/util/iov.c
@@ -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;
}
--
2.4.3
- [Qemu-devel] [PULL 01/15] block: Let bdrv_drain_all() to call aio_poll() for each AioContext, (continued)
- [Qemu-devel] [PULL 01/15] block: Let bdrv_drain_all() to call aio_poll() for each AioContext, Stefan Hajnoczi, 2015/06/24
- [Qemu-devel] [PULL 03/15] block-backend: Introduce blk_drain(), Stefan Hajnoczi, 2015/06/24
- [Qemu-devel] [PULL 04/15] virtio-blk: Use blk_drain() to drain IO requests, Stefan Hajnoczi, 2015/06/24
- [Qemu-devel] [PULL 05/15] util/hbitmap: Add an API to reset all set bits in hbitmap, Stefan Hajnoczi, 2015/06/24
- [Qemu-devel] [PULL 07/15] nvme: Fix memleak in nvme_dma_read_prp, Stefan Hajnoczi, 2015/06/24
- [Qemu-devel] [PULL 06/15] vvfat: add a label option, Stefan Hajnoczi, 2015/06/24
- [Qemu-devel] [PULL 08/15] block: Use bdrv_is_sg() everywhere, Stefan Hajnoczi, 2015/06/24
- [Qemu-devel] [PULL 09/15] Fix migration in case of scsi-generic, Stefan Hajnoczi, 2015/06/24
- [Qemu-devel] [PULL 10/15] raw-posix: DPRINTF instead of DEBUG_BLOCK_PRINT, Stefan Hajnoczi, 2015/06/24
- [Qemu-devel] [PULL 11/15] raw-posix: Use DPRINTF for DEBUG_FLOPPY, Stefan Hajnoczi, 2015/06/24
- [Qemu-devel] [PULL 13/15] iov: don't touch iov in iov_send_recv(),
Stefan Hajnoczi <=
- [Qemu-devel] [PULL 12/15] raw-posix: Introduce hdev_is_sg(), Stefan Hajnoczi, 2015/06/24
- [Qemu-devel] [PULL 14/15] qemu-iotests: fix 051.out after qdev error message change, Stefan Hajnoczi, 2015/06/24
- [Qemu-devel] [PULL 15/15] virito-blk: drop duplicate check, Stefan Hajnoczi, 2015/06/24
- Re: [Qemu-devel] [PULL 00/15] Block patches, Peter Maydell, 2015/06/25