diff options
author | Thomas Huth <thuth@redhat.com> | 2015-10-13 12:39:58 +0200 |
---|---|---|
committer | Jason Wang <jasowang@redhat.com> | 2015-10-27 10:30:31 +0800 |
commit | 43192fcc1ac0a61cf9e20a9034eae8d1e91f35c8 (patch) | |
tree | 4da6ca17a114348799e02b6b8e0ed3a2e92fea61 | |
parent | afb4c51fad8cf86104803fc17457b96e86172b98 (diff) |
net/dump: Add support for receive_iov function
Adding a proper receive_iov function to the net dump module.
This will make it easier to support the dump filter feature for
the -netdev option in later patches.
Reviewed-by: Yang Hongyang <yanghy@cn.fujitsu.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
-rw-r--r-- | net/dump.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/net/dump.c b/net/dump.c index 08259afcb6..aa0d45ddc0 100644 --- a/net/dump.c +++ b/net/dump.c @@ -25,6 +25,7 @@ #include "clients.h" #include "qemu-common.h" #include "qemu/error-report.h" +#include "qemu/iov.h" #include "qemu/log.h" #include "qemu/timer.h" #include "hub.h" @@ -57,12 +58,15 @@ struct pcap_sf_pkthdr { uint32_t len; }; -static ssize_t dump_receive(NetClientState *nc, const uint8_t *buf, size_t size) +static ssize_t 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; + size_t size = iov_size(iov, cnt); + struct iovec dumpiov[cnt + 1]; /* Early return in case of previous error. */ if (s->fd < 0) { @@ -76,8 +80,12 @@ static ssize_t dump_receive(NetClientState *nc, const uint8_t *buf, size_t size) hdr.ts.tv_usec = ts % 1000000; hdr.caplen = caplen; hdr.len = size; - if (write(s->fd, &hdr, sizeof(hdr)) != sizeof(hdr) || - write(s->fd, buf, caplen) != caplen) { + + dumpiov[0].iov_base = &hdr; + dumpiov[0].iov_len = sizeof(hdr); + cnt = iov_copy(&dumpiov[1], cnt, iov, cnt, 0, caplen); + + if (writev(s->fd, dumpiov, cnt + 1) != sizeof(hdr) + caplen) { qemu_log("-net dump write error - stop dump\n"); close(s->fd); s->fd = -1; @@ -86,6 +94,15 @@ static ssize_t dump_receive(NetClientState *nc, const uint8_t *buf, size_t size) return size; } +static ssize_t dump_receive(NetClientState *nc, const uint8_t *buf, size_t size) +{ + struct iovec iov = { + .iov_base = (void *)buf, + .iov_len = size + }; + return dump_receive_iov(nc, &iov, 1); +} + static void dump_cleanup(NetClientState *nc) { DumpState *s = DO_UPCAST(DumpState, nc, nc); @@ -97,6 +114,7 @@ static NetClientInfo net_dump_info = { .type = NET_CLIENT_OPTIONS_KIND_DUMP, .size = sizeof(DumpState), .receive = dump_receive, + .receive_iov = dump_receive_iov, .cleanup = dump_cleanup, }; |