iov: don't touch iov in iov_send_recv()
PATCH 1/1 iov: don't touch iov in iov_send_recv()
Signed-off-by Wen Congyang <[email protected]>
--- include/qemu/iov.h | 2 +- util/iov.c | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-)
include/qemu/iov.h +1 -1
@@ -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)
util/iov.c +13 -1
@@ -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; }
Signature · 1 line
2.1.0
Ping...
Quoted 66 lines · Wen Congyang
Signed-off-by Wen Congyang <[email protected]>--- include/qemu/iov.h | 2 +- util/iov.c | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-)include/qemu/iov.h +1
-1@@ -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)util/iov.c +13
-1@@ -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; }
Quoted 1 line · * Wen Congyang ([email protected]) wrote:
Ping...
Hi Wen,
I don't know the block side of stuff to review this stuff, so
I'll leave it to Kevin and Paolo.
Dave
Quoted 63 lines · Wen Congyang
Quoted 61 lines
Signed-off-by Wen Congyang <[email protected]>--- include/qemu/iov.h | 2 +- util/iov.c | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-)include/qemu/iov.h +1
-1@@ -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)util/iov.c +12
-1@@ -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; }
Quoted 6 lines
util/iov.c ssize_t iov_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt, · line 222
Quoted 5 lines
util/iov.c +1
-0+g_free (local_iov);return total; }
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Ping again.
This patch is bugfix. The old discussion is here:
http://lists.nongnu.org/archive/html/qemu-devel/2015-02/msg00245.html
Quoted 66 lines · Wen Congyang
Signed-off-by Wen Congyang <[email protected]>--- include/qemu/iov.h | 2 +- util/iov.c | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-)include/qemu/iov.h +1
-1@@ -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)util/iov.c +13
-1@@ -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; }
Stefan Hajnoczi
AppliedQuoted 5 lines · Wen Congyang
Signed-off-by Wen Congyang <[email protected]>--- include/qemu/iov.h | 2 +- util/iov.c | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-)
Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block
Stefan