From: Thomas Huth <thuth@redhat.com>
To: Jason Wang <jasowang@redhat.com>
Cc: qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>,
Markus Armbruster <armbru@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 1/5] net/dump: Add support for receive_iov function
Date: Fri, 26 Jun 2015 09:06:34 +0200 [thread overview]
Message-ID: <20150626090634.5227fc7b@thh440s> (raw)
In-Reply-To: <558CF372.9010500@redhat.com>
On Fri, 26 Jun 2015 14:38:42 +0800
Jason Wang <jasowang@redhat.com> 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 <thuth@redhat.com>
> > ---
> > 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
next prev parent reply other threads:[~2015-06-26 7:06 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-24 15:56 [Qemu-devel] [PATCH 0/5] Network traffic dumping for -netdev, second try Thomas Huth
2015-06-24 15:56 ` [Qemu-devel] [PATCH 1/5] net/dump: Add support for receive_iov function Thomas Huth
2015-06-26 6:38 ` Jason Wang
2015-06-26 7:06 ` Thomas Huth [this message]
2015-07-03 11:06 ` Markus Armbruster
2015-07-10 18:09 ` Thomas Huth
2015-06-24 15:56 ` [Qemu-devel] [PATCH 2/5] net/dump: Move DumpState into NetClientState Thomas Huth
2015-06-24 15:56 ` [Qemu-devel] [PATCH 3/5] net/dump: Rework net-dump init functions Thomas Huth
2015-07-03 11:19 ` Markus Armbruster
2015-06-24 15:56 ` [Qemu-devel] [PATCH 4/5] net/dump: Add dump option for netdev devices Thomas Huth
2015-06-26 6:50 ` Jason Wang
2015-06-26 9:44 ` Stefan Hajnoczi
2015-06-29 9:57 ` Thomas Huth
2015-06-30 15:12 ` Stefan Hajnoczi
2015-06-30 10:37 ` Thomas Huth
2015-07-01 8:36 ` Stefan Hajnoczi
2015-07-03 11:28 ` Markus Armbruster
2015-07-10 18:27 ` Thomas Huth
2015-06-24 15:56 ` [Qemu-devel] [PATCH 5/5] qemu options: Add information about dumpfile to help text Thomas Huth
2015-07-03 11:30 ` Markus Armbruster
2015-06-26 9:41 ` [Qemu-devel] [PATCH 0/5] Network traffic dumping for -netdev, second try Stefan Hajnoczi
2015-07-03 11:30 ` Markus Armbruster
-- strict thread matches above, loose matches on Subject: below --
2015-09-24 7:22 [Qemu-devel] [PATCH 0/5] Network traffic dumping via netfilter Thomas Huth
2015-09-24 7:22 ` [Qemu-devel] [PATCH 1/5] net/dump: Add support for receive_iov function Thomas Huth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150626090634.5227fc7b@thh440s \
--to=thuth@redhat.com \
--cc=armbru@redhat.com \
--cc=jasowang@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.