From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57601) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z7F41-0006FW-Pf for qemu-devel@nongnu.org; Mon, 22 Jun 2015 23:40:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z7F3x-0007i9-5H for qemu-devel@nongnu.org; Mon, 22 Jun 2015 23:39:57 -0400 Received: from [59.151.112.132] (port=20144 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z7F3w-0007eE-GT for qemu-devel@nongnu.org; Mon, 22 Jun 2015 23:39:53 -0400 Message-ID: <5588D5EC.9010708@cn.fujitsu.com> Date: Tue, 23 Jun 2015 11:43:40 +0800 From: Wen Congyang MIME-Version: 1.0 References: <555D39D2.4000705@cn.fujitsu.com> In-Reply-To: <555D39D2.4000705@cn.fujitsu.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] iov: don't touch iov in iov_send_recv() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devl , Kevin Wolf , Paolo Bonzini Cc: "Dr. David Alan Gilbert" , Stefan Hajnoczi Ping again. This patch is bugfix. The old discussion is here: http://lists.nongnu.org/archive/html/qemu-devel/2015-02/msg00245.html On 05/21/2015 09:50 AM, Wen Congyang wrote: > Signed-off-by: Wen Congyang > --- > 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; > } > >