From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53087) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z8Nim-0003HF-9m for qemu-devel@nongnu.org; Fri, 26 Jun 2015 03:06:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z8Nij-0002Ce-3P for qemu-devel@nongnu.org; Fri, 26 Jun 2015 03:06:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34806) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z8Nii-0002CN-So for qemu-devel@nongnu.org; Fri, 26 Jun 2015 03:06:41 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 253B7C4657 for ; Fri, 26 Jun 2015 07:06:40 +0000 (UTC) Date: Fri, 26 Jun 2015 09:06:34 +0200 From: Thomas Huth Message-ID: <20150626090634.5227fc7b@thh440s> In-Reply-To: <558CF372.9010500@redhat.com> References: <1435161381-31521-1-git-send-email-thuth@redhat.com> <1435161381-31521-2-git-send-email-thuth@redhat.com> <558CF372.9010500@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 1/5] net/dump: Add support for receive_iov function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jason Wang Cc: qemu-devel@nongnu.org, Stefan Hajnoczi , Markus Armbruster On Fri, 26 Jun 2015 14:38:42 +0800 Jason Wang wrote: > > > On 06/24/2015 11:56 PM, Thomas Huth wrote: > > Adding a proper receive_iov function to the net dump module. This > > will make it easier to support the dump feature for the -netdev > > option in later patches. > > Also make the receive functions available to the other parts of the > > source code so we can later use them for dumping from net.c, too. > > > > Signed-off-by: Thomas Huth > > --- > > net/clients.h | 3 +++ > > net/dump.c | 48 ++++++++++++++++++++++++++++++++++++++++-------- > > 2 files changed, 43 insertions(+), 8 deletions(-) > > > > diff --git a/net/clients.h b/net/clients.h > > index d47530e..5092f3d 100644 > > --- a/net/clients.h > > +++ b/net/clients.h > > @@ -29,6 +29,9 @@ > > > > int net_init_dump(const NetClientOptions *opts, const char *name, > > NetClientState *peer, Error **errp); > > +ssize_t net_dump_receive(NetClientState *nc, const uint8_t *buf, size_t size); > > +ssize_t net_dump_receive_iov(NetClientState *nc, const struct iovec *iov, > > + int cnt); > > > > #ifdef CONFIG_SLIRP > > int net_init_slirp(const NetClientOptions *opts, const char *name, > > diff --git a/net/dump.c b/net/dump.c > > index 02c8064..383718a 100644 > > --- a/net/dump.c > > +++ b/net/dump.c > > @@ -57,27 +57,49 @@ struct pcap_sf_pkthdr { > > uint32_t len; > > }; > > > > -static ssize_t dump_receive(NetClientState *nc, const uint8_t *buf, size_t size) > > +ssize_t net_dump_receive_iov(NetClientState *nc, const struct iovec *iov, > > + int cnt) > > { > > DumpState *s = DO_UPCAST(DumpState, nc, nc); > > struct pcap_sf_pkthdr hdr; > > int64_t ts; > > - int caplen; > > + int caplen, i; > > + size_t size = 0; > > + struct iovec dumpiov[cnt + 1]; > > > > /* Early return in case of previous error. */ > > if (s->fd < 0) { > > return size; > > } > > > > + dumpiov[0].iov_base = &hdr; > > + dumpiov[0].iov_len = sizeof(hdr); > > + caplen = s->pcap_caplen; > > + > > + /* Copy iov, limit maximum size to caplen, and count total input size */ > > + for (i = 0; i < cnt; i++) { > > + dumpiov[i + 1].iov_base = iov[i].iov_base; > > + if (size + iov[i].iov_len <= caplen) { > > + dumpiov[i + 1].iov_len = iov[i].iov_len; > > + } else if (size < caplen) { > > + dumpiov[i + 1].iov_len = caplen - size; > > + } else { > > + dumpiov[i + 1].iov_len = 0; > > + } > > + size += iov[i].iov_len; > > + } > > I believe we could use iov_copy() here. Looks like that could do the job, too, thanks for the hint! However, I also need the total size of bytes in the source iov, so I'd then need to call iov_size() here, too - but I guess it's ok to loop through the iov twice since dumping is not really time critical. Thomas