Skip to contentSkip to conversation

net: fix some problems with dump backend

PATCH Applied Hervé Poussineau 3 participants 5 messages Nov 30, 2011 – Dec 20, 2011 Networking

lore
Share & tools
lore
#0 lore raw

v2 cover net: fix some problems with dump backend

This small patchset fixes some problems I've found while using the dump backend.
At least first patch may be considered for 1.0.

Changes v1->v2:
- Update patches descriptions

Hervé Poussineau (2):
net: truncate output file when using dump backend
net: store guest timestamp in dump file instead of time since guest
startup

 net/dump.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
Signature · 1 line
1.7.6.3
#1 lore raw

PATCH v2 1/2 net: truncate output file when using dump backend

This prevents data of a previous run to be seen in the new dump file.

---
 net/dump.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
net/dump.c +1 -1
index 0d0cbb2..8132411 100644
@@ -106,7 +106,7 @@ static int net_dump_init(VLANState *vlan, const char *device,
     DumpState *s;
     int fd;
 
-    fd = open(filename, O_CREAT | O_WRONLY | O_BINARY, 0644);
+    fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, 0644);
     if (fd < 0) {
         error_report("-net dump: can't open %s", filename);
         return -1;
Signature · 1 line
1.7.6.3
#2 lore raw

PATCH v2 2/2 net: store guest timestamp in dump file instead of time since guest startup

In reply to Hervé Poussineau

Stored dates are no more 1970-01-01 (+ run time), but have a real meaning. If someone wants to have comparable timestamps accross boots, it is possible to start qemu with -rtc to give the startup date.

---
 net/dump.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
net/dump.c +6 -1
index 8132411..4b48d48 100644
@@ -30,6 +30,7 @@
 
 typedef struct DumpState {
     VLANClientState nc;
+    int64_t start_ts;
     int fd;
     int pcap_caplen;
 } DumpState;
@@ -70,7 +71,7 @@ static ssize_t dump_receive(VLANClientState *nc, const uint8_t *buf, size_t size
     ts = muldiv64(qemu_get_clock_ns(vm_clock), 1000000, get_ticks_per_sec());
     caplen = size > s->pcap_caplen ? s->pcap_caplen : size;
 
-    hdr.ts.tv_sec = ts / 1000000;
+    hdr.ts.tv_sec = ts / 1000000 + s->start_ts;
     hdr.ts.tv_usec = ts % 1000000;
     hdr.caplen = caplen;
     hdr.len = size;
@@ -104,6 +105,7 @@ static int net_dump_init(VLANState *vlan, const char *device,
     struct pcap_file_hdr hdr;
     VLANClientState *nc;
     DumpState *s;
+    struct tm tm;
     int fd;
 
     fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, 0644);
@@ -136,6 +138,9 @@ static int net_dump_init(VLANState *vlan, const char *device,
     s->fd = fd;
     s->pcap_caplen = len;
 
+    qemu_get_timedate(&tm, 0);
+    s->start_ts = mktime(&tm);
+
     return 0;
 }
 
Signature · 1 line
1.7.6.3
#4 lore raw
In reply to Hervé Poussineau
Quoted 3 lines · Hervé Poussineau

This small patchset fixes some problems I've found while using the dump backend.
At least first patch may be considered for 1.0.

Applied all. Thanks.

Regards,

Anthony Liguori

Quoted 12 lines

Changes v1->v2:
- Update patches descriptions

Hervé Poussineau (2):
net: truncate output file when using dump backend
net: store guest timestamp in dump file instead of time since guest
startup

  net/dump.c |    9 +++++++--
  1 files changed, 7 insertions(+), 2 deletions(-)