net: truncate output file when using dump backend
PATCH 1/2 net: truncate output file when using dump backend
--- net/dump.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
net/dump.c +1 -1
@@ -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
PATCH 2/2 net: store correct timestamp in dump file
--- net/dump.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
net/dump.c +6 -1
@@ -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
Re: [Qemu-devel] [PATCH 2/2] net: store correct timestamp in dump file
Quoted 18 lines · Hervé Poussineau
Signed-off-by Hervé Poussineau<[email protected]>--- net/dump.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)net/dump.c +1
-0@@ -30,6 +30,7 @@typedef struct DumpState {VLANClientState nc; +int64_t start_ts;int fd;int pcap_caplen; }DumpState ;
net/dump.c static ssize_t dump_receive(VLANClientState *nc, const uint8_t *buf, size_t size · line 71
Quoted 1 line
net/dump.c +0
-0@@ -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 ());
I agree that using host time as timestamp is more reasonable than the virtual clock because in most cases rtc for guest is based on host time not virtual clock.
I think we can simply use "host_clock" instead of "vm_clock" to achieve that. It will use the same time as host no matter what option is specified for guest's rtc. With your patch, the time stamp will keep the same as the choice of guest rtc, which is utc default.
- ts = muldiv64(qemu_get_clock_ns(vm_clock), 1000000,get_ticks_per_sec());
+ ts = muldiv64(qemu_get_clock_ns(host_clock), 1000000, get_ticks_per_sec());
caplen = size > s->pcap_caplen ? s->pcap_caplen : size;Quoted 5 lines · Hervé Poussineau
Signed-off-by Hervé Poussineau <[email protected]>--- net/dump.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)