do savevm/migration save/load via Visitor interface
cover do savevm/migration save/load via Visitor interface
These patches apply on top of origin/master, and can also be obtained from:git://repo.or.cz/qemu/mdroth.git migration-visitor-v1
OVERVIEW
This patch series implements a QEMUFile Visitor class that's intended to abstract away direct calls to qemu_put_*/qemu_get_* for save/load functions. Currently this is done by always creating a QEMUFileInputVisitor/QEMUFileOutputVisitor pair with each call to qemu_fopen_ops() and maintaining a QEMUFile->I/O Visitor mapping. save/load functions that are to be converted would them simply use lookup routines to get a Visitor based on their QEMUFile arguments. Once these save/load functions are all converted, we can then change the interfaces in bulk and switch over to passing in the Visitor directly.
This series also converts all of vmstate over to using Visitors, leveraging the existing vmstate hierachical structure to handle namespacing and structuring of the fields that are fed to the visitor functions, and introduces trace statements for qemu_put_*/qemu_get_* and visitor API calls to aid in testing.
Migration compatibility is not affected by these changes, as the qemu_put_*/qemu_get_* calls have a trivial 1-to-1 mapping with the visit_type_* calls, and the added field names/structure are not sent out over the wire when using the QEMUFile visitors, but serve simply as placeholders for future functionality.
Test scripts/procedure are documented on the wiki page:
http://wiki.qemu.org/Features/Migration/Visitor#Code.2FTesting
PLANS
With these patches in place non-vmstate save/load functions can be converted over to using Visitors incrementally.
Short term (1.1 timeframe), the goal is to implement a new migration protocol that is self-describing, such that incompatibilities or migration errors can be more easilly detected. Currently, a simple change in data types for a particular device can introduce subtle bugs that won't be detected by the target, since the target interprets the data according to it's own expectation of what those data types are. Currently the plan is to achieve this by using ASN.1 BER in place of QEMUFile via a new BERVisitor.
Also planned is using the visitor interface to aid in things like device introspection (for both vmstate and non-vmstate devices), likely via the existing QMPOutputVisitor, as well as debugging/testing migration via a well structured "PrettyPrintVisitor" type of visitor that also retains ordering, field names, and type information (unlike with QMP/JSON or ASN.1). I've played around with doing this indirectly to test the conversions by doing some post-processing on the visit_* trace statements:
...
PIIX3.PCIDevice.config(256)(1).[255] = (uint8) 0x0 PIIX3.PCIDevice.irq_state(4)(4).[0] = (uint32) 0x0 PIIX3.PCIDevice.irq_state(4)(4).[1] = (uint32) 0x0 PIIX3.PCIDevice.irq_state(4)(4).[2] = (uint32) 0x0 PIIX3.PCIDevice.irq_state(4)(4).[3] = (uint32) 0x0 PIIX3.pci_irq_levels_vmstate(4)(4).[0] = (int32) 0x0 PIIX3.pci_irq_levels_vmstate(4)(4).[1] = (int32) 0x0 PIIX3.pci_irq_levels_vmstate(4)(4).[2] = (int32) 0x0 PIIX3.pci_irq_levels_vmstate(4)(4).[3] = (int32) 0x0 i8259.last_irr = (uint8) 0x1
i8259.irr = (uint8) 0x10
i8259.imr = (uint8) 0xb8
i8259.isr = (uint8) 0x0
i8259.priority_add = (uint8) 0x0
i8259.irq_base = (uint8) 0x8
i8259.read_reg_select = (uint8) 0x0
i8259.poll = (uint8) 0x0
i8259.special_mask = (uint8) 0x0
i8259.init_state = (uint8) 0x0
i8259.auto_eoi = (uint8) 0x0
...
slirp.ip_id = (uint16) 0x2 slirp.bootp.bootp_clients(16)(8).[0].allocated = (uint16) 0x1 slirp.bootp.bootp_clients(16)(8).[0].macaddr(6)(1).[0] = (uint8) 0x1 slirp.bootp.bootp_clients(16)(8).[0].macaddr(6)(1).[1] = (uint8) 0x0 slirp.bootp.bootp_clients(16)(8).[0].macaddr(6)(1).[2] = (uint8) 0x0 slirp.bootp.bootp_clients(16)(8).[0].macaddr(6)(1).[3] = (uint8) 0x0 slirp.bootp.bootp_clients(16)(8).[0].macaddr(6)(1).[4] = (uint8) 0x0 slirp.bootp.bootp_clients(16)(8).[0].macaddr(6)(1).[5] = (uint8) 0x0 slirp.bootp.bootp_clients(16)(8).[1].allocated = (uint16) 0x0 slirp.bootp.bootp_clients(16)(8).[1].macaddr(6)(1).[0] = (uint8) 0x1 slirp.bootp.bootp_clients(16)(8).[1].macaddr(6)(1).[1] = (uint8) 0x0 slirp.bootp.bootp_clients(16)(8).[1].macaddr(6)(1).[2] = (uint8) 0x0 slirp.bootp.bootp_clients(16)(8).[1].macaddr(6)(1).[3] = (uint8) 0x0 slirp.bootp.bootp_clients(16)(8).[1].macaddr(6)(1).[4] = (uint8) 0x0 slirp.bootp.bootp_clients(16)(8).[1].macaddr(6)(1).[5] = (uint8) 0x0 slirp.bootp.bootp_clients(16)(8).[2].allocated = (uint16) 0x0
...
It's not completely clear at this point how the latter will fall into place with other plans such as QOM that would provide similar capabilities, but since device serialization will likely be done via automatically-generated visitor patterns, this conversion should at least serve as an incremental step toward that transition.
Michael Roth (10):
qapi: add Visitor interfaces for uint*_t and int*_t
qapi: add QemuFileOutputVisitor
qapi: add QemuFileInputVisitor
savevm: move QEMUFile interfaces into qemu-file.c
qapi: test cases for QEMUFile input/output visitors
savevm: add QEMUFile->visitor lookup routines
trace: qemu_(put|get)_(byte|buffer) events
trace: add trace statements for visitor interface
qapi: add trace statements to qapi-visit-core.c
vmstate: use visitors
Makefile | 2 +- Makefile.objs | 22 +- hw/eeprom93xx.c | 12 +- hw/fw_cfg.c | 12 +- hw/hw.h | 24 +- hw/pci.c | 38 ++- hw/twl92230.c | 18 +- qapi/qapi-visit-core.c | 119 +++++- qapi/qapi-visit-core.h | 30 ++ qapi/qemu-file-input-visitor.c | 328 ++++++++++++++ qapi/qemu-file-input-visitor.h | 26 + qapi/qemu-file-output-visitor.c | 328 ++++++++++++++ qapi/qemu-file-output-visitor.h | 26 + qemu-file.c | 623 +++++++++++++++++++++++++ qemu-timer.c | 24 +- qemu-timer.h | 5 + savevm.c | 953 ++++++++++++--------------------------- target-alpha/machine.c | 13 +- target-i386/machine.c | 49 ++- test-visitor.c | 404 +++++++++++++++++ trace-events | 43 ++ 21 files changed, 2364 insertions(+), 735 deletions(-) create mode 100644 qapi/qemu-file-input-visitor.c create mode 100644 qapi/qemu-file-input-visitor.h create mode 100644 qapi/qemu-file-output-visitor.c create mode 100644 qapi/qemu-file-output-visitor.h create mode 100644 qemu-file.c
Signature · 1 line
1.7.4.1
PATCH 2/10 qapi: add QemuFileOutputVisitor
Visitor interface to write values to a QEMUFile.
--- Makefile.objs | 19 +-- qapi/qemu-file-output-visitor.c | 328 +++++++++++++++++++++++++++++++++++++++ qapi/qemu-file-output-visitor.h | 26 +++ 3 files changed, 363 insertions(+), 10 deletions(-) create mode 100644 qapi/qemu-file-output-visitor.c create mode 100644 qapi/qemu-file-output-visitor.h
Makefile.objs +9 -10
@@ -20,6 +20,12 @@ coroutine-obj-$(CONFIG_POSIX) += coroutine-gthread.o endif coroutine-obj-$(CONFIG_WIN32) += coroutine-win32.o +###################################################################### +# qapi +qapi-nested-y = qapi-visit-core.o qmp-input-visitor.o qmp-output-visitor.o qapi-dealloc-visitor.o +qapi-nested-y += qmp-registry.o qmp-dispatch.o +qapi-obj-y = $(addprefix qapi/, $(qapi-nested-y)) + ####################################################################### # block-obj-y is code used by both qemu system emulation and qemu-img
@@ -73,6 +79,9 @@ fsdev-obj-$(CONFIG_VIRTFS) += $(addprefix fsdev/, $(fsdev-nested-y)) # CPUs and machines. common-obj-y = $(block-obj-y) blockdev.o +common-obj-y += qmp-marshal.o qapi-visit.o qapi-types.o $(qapi-obj-y) +common-obj-y += qmp.o hmp.o +common-obj-y += qapi/qemu-file-output-visitor.o common-obj-y += $(net-obj-y) common-obj-y += $(qobject-obj-y) common-obj-$(CONFIG_LINUX) += $(fsdev-obj-$(CONFIG_LINUX))
@@ -399,16 +408,6 @@ $(trace-obj-y): $(GENERATED_HEADERS) libcacard-y = cac.o event.o vcard.o vreader.o vcard_emul_nss.o vcard_emul_type.o card_7816.o ###################################################################### -# qapi - -qapi-nested-y = qapi-visit-core.o qmp-input-visitor.o qmp-output-visitor.o qapi-dealloc-visitor.o -qapi-nested-y += qmp-registry.o qmp-dispatch.o -qapi-obj-y = $(addprefix qapi/, $(qapi-nested-y)) - -common-obj-y += qmp-marshal.o qapi-visit.o qapi-types.o $(qapi-obj-y) -common-obj-y += qmp.o hmp.o - -###################################################################### # guest agent qga-nested-y = guest-agent-commands.o guest-agent-command-state.o
qapi/qemu-file-output-visitor.c new file +328 -0
328 lines not on this page · raw message
qapi/qemu-file-output-visitor.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* QEMUFile Visitor +* +* Copyright IBM, Corp. 2011 +* +* Authors: +* Michael Roth <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2.1 or later. +* See the COPYING.LIB file in the top-level directory. +* +*/ + +#ifndef QEMU_FILE_OUTPUT_VISITOR_H +#define QEMU_FILE_OUTPUT_VISITOR_H + +#include "qapi-visit-core.h" + +typedef struct QemuFileOutputVisitor QemuFileOutputVisitor ; + +QemuFileOutputVisitor *qemu_file_output_visitor_new (QEMUFile *f); +void qemu_file_output_visitor_cleanup (QemuFileOutputVisitor *d); + +Visitor *qemu_file_output_get_visitor (QemuFileOutputVisitor *v); + +#endif
Signature · 1 line
1.7.4.1
PATCH 3/10 qapi: add QemuFileInputVisitor
In reply to Michael RothVisitor interfaces to read values from a QEMUFile
--- Makefile.objs | 1 + qapi/qemu-file-input-visitor.c | 328 ++++++++++++++++++++++++++++++++++++++++ qapi/qemu-file-input-visitor.h | 26 +++ 3 files changed, 355 insertions(+), 0 deletions(-) create mode 100644 qapi/qemu-file-input-visitor.c create mode 100644 qapi/qemu-file-input-visitor.h
Makefile.objs +1 -0
@@ -82,6 +82,7 @@ common-obj-y = $(block-obj-y) blockdev.o common-obj-y += qmp-marshal.o qapi-visit.o qapi-types.o $(qapi-obj-y) common-obj-y += qmp.o hmp.o common-obj-y += qapi/qemu-file-output-visitor.o +common-obj-y += qapi/qemu-file-input-visitor.o common-obj-y += $(net-obj-y) common-obj-y += $(qobject-obj-y) common-obj-$(CONFIG_LINUX) += $(fsdev-obj-$(CONFIG_LINUX))
qapi/qemu-file-input-visitor.c new file +328 -0
328 lines not on this page · raw message
qapi/qemu-file-input-visitor.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* QEMUFile Visitor +* +* Copyright IBM, Corp. 2011 +* +* Authors: +* Michael Roth <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2.1 or later. +* See the COPYING.LIB file in the top-level directory. +* +*/ + +#ifndef QEMU_FILE_INPUT_VISITOR_H +#define QEMU_FILE_INPUT_VISITOR_H + +#include "qapi-visit-core.h" + +typedef struct QemuFileInputVisitor QemuFileInputVisitor ; + +QemuFileInputVisitor *qemu_file_input_visitor_new (QEMUFile *f); +void qemu_file_input_visitor_cleanup (QemuFileInputVisitor *d); + +Visitor *qemu_file_input_get_visitor (QemuFileInputVisitor *v); + +#endif
Signature · 1 line
1.7.4.1
PATCH 1/10 qapi: add Visitor interfaces for uint*_t and int*_t
In reply to Michael Roth--- qapi/qapi-visit-core.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++ qapi/qapi-visit-core.h | 30 ++++++++++++++++++ 2 files changed, 108 insertions(+), 0 deletions(-)
qapi/qapi-visit-core.c +78 -0
@@ -66,6 +66,28 @@ void visit_end_list(Visitor *v, Error **errp) } } +void visit_start_array (Visitor *v,void **obj,const char *name,size_t elem_count, +size_t elem_size,Error **errp) +{ +if (!error_is_set (errp)) { + v->start_array (v, obj, name, elem_count, elem_size, errp); + } +} + +void visit_next_array (Visitor *v,Error **errp) +{ +if (!error_is_set (errp)) { + v->next_array (v, errp); + } +} + +void visit_end_array (Visitor *v,Error **errp) +{ +if (!error_is_set (errp)) { + v->end_array (v, errp); + } +} +void visit_start_optional (Visitor *v,bool *present,const char *name,Error **errp) {
@@ -96,6 +118,62 @@ void visit_type_int(Visitor *v, int64_t *obj, const char *name, Error **errp) } } +void visit_type_uint8 (Visitor *v,uint8_t *obj,const char *name,Error **errp) +{ +if (!error_is_set (errp)) { + v->type_uint8 (v, obj, name, errp); + } +} + +void visit_type_uint16 (Visitor *v,uint16_t *obj,const char *name,Error **errp) +{ +if (!error_is_set (errp)) { + v->type_uint16 (v, obj, name, errp); + } +} + +void visit_type_uint32 (Visitor *v,uint32_t *obj,const char *name,Error **errp) +{ +if (!error_is_set (errp)) { + v->type_uint32 (v, obj, name, errp); + } +} + +void visit_type_uint64 (Visitor *v,uint64_t *obj,const char *name,Error **errp) +{ +if (!error_is_set (errp)) { + v->type_uint64 (v, obj, name, errp); + } +} + +void visit_type_int8 (Visitor *v,int8_t *obj,const char *name,Error **errp) +{ +if (!error_is_set (errp)) { + v->type_int8 (v, obj, name, errp); + } +} + +void visit_type_int16 (Visitor *v,int16_t *obj,const char *name,Error **errp) +{ +if (!error_is_set (errp)) { + v->type_int16 (v, obj, name, errp); + } +} + +void visit_type_int32 (Visitor *v,int32_t *obj,const char *name,Error **errp) +{ +if (!error_is_set (errp)) { + v->type_int32 (v, obj, name, errp); + } +} + +void visit_type_int64 (Visitor *v,int64_t *obj,const char *name,Error **errp) +{ +if (!error_is_set (errp)) { + v->type_int64 (v, obj, name, errp); + } +} +void visit_type_bool (Visitor *v,bool *obj,const char *name,Error **errp) {if (!error_is_set (errp)) {
qapi/qapi-visit-core.h +30 -0
@@ -22,6 +22,11 @@ typedef struct GenericListstruct GenericList *next; } GenericList; +typedef struct GenericItem +{ +void *value; +}GenericItem ; +typedef struct Visitor Visitor ;struct Visitor
@@ -35,10 +40,23 @@ struct Visitor GenericList *(*next_list)(Visitor *v, GenericList **list, Error **errp);void (*end_list)(Visitor *v,Error **errp); +void (*start_array)(Visitor *v,void **obj,const char *name, +size_t elem_count,size_t elem_size,Error **errp); +void (*next_array)(Visitor *v,Error **errp); +void (*end_array)(Visitor *v,Error **errp); +void (*type_enum)(Visitor *v,int *obj,const char *strings[],const char *kind,const char *name,Error **errp);void (*type_int)(Visitor *v,int64_t *obj,const char *name,Error **errp); +void (*type_uint8)(Visitor *v,uint8_t *obj,const char *name,Error **errp); +void (*type_uint16)(Visitor *v,uint16_t *obj,const char *name,Error **errp); +void (*type_uint32)(Visitor *v,uint32_t *obj,const char *name,Error **errp); +void (*type_uint64)(Visitor *v,uint64_t *obj,const char *name,Error **errp); +void (*type_int8)(Visitor *v,int8_t *obj,const char *name,Error **errp); +void (*type_int16)(Visitor *v,int16_t *obj,const char *name,Error **errp); +void (*type_int32)(Visitor *v,int32_t *obj,const char *name,Error **errp); +void (*type_int64)(Visitor *v,int64_t *obj,const char *name,Error **errp);void (*type_bool)(Visitor *v,bool *obj,const char *name,Error **errp);void (*type_str)(Visitor *v,char **obj,const char *name,Error **errp); void (*type_number)(Visitor *v, double *obj, const char *name,
@@ -63,12 +81,24 @@ void visit_end_struct(Visitor *v, Error **errp);void visit_start_list (Visitor *v,const char *name,Error **errp);GenericList *visit_next_list (Visitor *v,GenericList **list,Error **errp);void visit_end_list (Visitor *v,Error **errp); +void visit_start_array (Visitor *v,void **obj,const char *name,size_t elem_count, +size_t elem_size,Error **errp); +void visit_next_array (Visitor *v,Error **errp); +void visit_end_array (Visitor *v,Error **errp);void visit_start_optional (Visitor *v,bool *present,const char *name,Error **errp);void visit_end_optional (Visitor *v,Error **errp);void visit_type_enum (Visitor *v,int *obj,const char *strings[],const char *kind,const char *name,Error **errp);void visit_type_int (Visitor *v,int64_t *obj,const char *name,Error **errp); +void visit_type_uint8 (Visitor *v,uint8_t *obj,const char *name,Error **errp); +void visit_type_uint16 (Visitor *v,uint16_t *obj,const char *name,Error **errp); +void visit_type_uint32 (Visitor *v,uint32_t *obj,const char *name,Error **errp); +void visit_type_uint64 (Visitor *v,uint64_t *obj,const char *name,Error **errp); +void visit_type_int8 (Visitor *v,int8_t *obj,const char *name,Error **errp); +void visit_type_int16 (Visitor *v,int16_t *obj,const char *name,Error **errp); +void visit_type_int32 (Visitor *v,int32_t *obj,const char *name,Error **errp); +void visit_type_int64 (Visitor *v,int64_t *obj,const char *name,Error **errp);void visit_type_bool (Visitor *v,bool *obj,const char *name,Error **errp);void visit_type_str (Visitor *v,char **obj,const char *name,Error **errp);void visit_type_number (Visitor *v,double *obj,const char *name,Error **errp);
Signature · 1 line
1.7.4.1
PATCH 4/10 savevm: move QEMUFile interfaces into qemu-file.c
In reply to Michael Roth--- Makefile.objs | 2 +- hw/hw.h | 1 + qemu-file.c | 541 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ savevm.c | 494 ---------------------------------------------------- 4 files changed, 543 insertions(+), 495 deletions(-) create mode 100644 qemu-file.c
Makefile.objs +1 -1
@@ -119,7 +119,7 @@ common-obj-$(CONFIG_SD) += sd.o common-obj-y += bt.o bt-host.o bt-vhci.o bt-l2cap.o bt-sdp.o bt-hci.o bt-hid.o usb-bt.o common-obj-y += bt-hci-csr.o common-obj-y += buffered_file.o migration.o migration-tcp.o -common-obj-y += qemu-char.o savevm.o #aio.o +common-obj-y += qemu-char.o savevm.o qemu-file.o #aio.o common-obj-y += msmouse.o ps2.o common-obj-y += qdev.o qdev-properties.o common-obj-y += block-migration.o iohandler.o
hw/hw.h +1 -0
@@ -58,6 +58,7 @@ void qemu_fflush(QEMUFile *f);int qemu_fclose (QEMUFile *f);void qemu_put_buffer (QEMUFile *f,const uint8_t *buf,int size);void qemu_put_byte (QEMUFile *f,int v); +int qemu_peek_byte (QEMUFile *f);static inline void qemu_put_ubyte (QEMUFile *f,unsigned int v) {
qemu-file.c new file +541 -0
541 lines not on this page · raw message
savevm.c +0 -494
506 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH 6/10 savevm: add QEMUFile->visitor lookup routines
In reply to Michael Roth--- hw/hw.h | 19 +++++++++++++++++ qemu-file.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 0 deletions(-)
hw/hw.h +19 -0
@@ -10,6 +10,25 @@#include "ioport.h" #include "irq.h" +#include "qemu-queue.h" +#include "qapi/qapi-visit-core.h" +#include "qapi/qemu-file-output-visitor.h" +#include "qapi/qemu-file-input-visitor.h" + +/* QEMUFile->Visitor lookup routines to support legacy qemu_put_* calls */ +typedef struct QemuFileVisitorNode { +void *opaque;/* Visitor type */ +QemuFileOutputVisitor *ov; +QemuFileInputVisitor *iv; +QEMUFile *f; +QTAILQ_ENTRY (QemuFileVisitorNode) entry; +}QemuFileVisitorNode ; + +Visitor *qemu_file_get_input_visitor (QEMUFile *f); +Visitor *qemu_file_get_output_visitor (QEMUFile *f); +QemuFileVisitorNode *qemu_file_get_visitor_node (QEMUFile *f); +void qemu_file_put_visitor_node (QemuFileVisitorNode *n); +void qemu_file_remove_visitor_node (QemuFileVisitorNode *n);/* VM Load/Save */
qemu-file.c +64 -0
88 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH 5/10 qapi: test cases for QEMUFile input/output visitors
In reply to Michael Roth--- Makefile | 2 +- test-visitor.c | 404 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 405 insertions(+), 1 deletions(-)
Makefile +1 -1
@@ -204,7 +204,7 @@ qmp-marshal.c: $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py -m -o "." < $<, " GEN $@") test-visitor.o: $(addprefix $(qapi-dir)/, test-qapi-types.c test-qapi-types.h test-qapi-visit.c test-qapi-visit.h) $(qapi-obj-y) -test-visitor: test-visitor.o qfloat.o qint.o qdict.o qstring.o qlist.o qbool.o $(qapi-obj-y) error.o osdep.o $(oslib-obj-y) qjson.o json-streamer.o json-lexer.o json-parser.o qerror.o qemu-error.o qemu-tool.o $(qapi-dir)/test-qapi-visit.o $(qapi-dir)/test-qapi-types.o +test-visitor: test-visitor.o qfloat.o qint.o qdict.o qstring.o qlist.o qbool.o $(qapi-obj-y) error.o osdep.o $(oslib-obj-y) qjson.o json-streamer.o json-lexer.o json-parser.o qerror.o qemu-error.o qemu-tool.o $(qapi-dir)/test-qapi-visit.o $(qapi-dir)/test-qapi-types.o qapi/qemu-file-input-visitor.o qapi/qemu-file-output-visitor.o qemu-file.o test-qmp-commands.o: $(addprefix $(qapi-dir)/, test-qapi-types.c test-qapi-types.h test-qapi-visit.c test-qapi-visit.h test-qmp-marshal.c test-qmp-commands.h) $(qapi-obj-y) test-qmp-commands: test-qmp-commands.o qfloat.o qint.o qdict.o qstring.o qlist.o qbool.o $(qapi-obj-y) error.o osdep.o $(oslib-obj-y) qjson.o json-streamer.o json-lexer.o json-parser.o qerror.o qemu-error.o qemu-tool.o $(qapi-dir)/test-qapi-visit.o $(qapi-dir)/test-qapi-types.o $(qapi-dir)/test-qmp-marshal.o module.o
test-visitor.c +404 -0
422 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH 8/10 trace: add trace statements for visitor interface
In reply to Michael Roth--- trace-events | 25 +++++++++++++++++++++++++ 1 files changed, 25 insertions(+), 0 deletions(-)
trace-events +25 -0
@@ -556,3 +556,28 @@ qemu_put_sbe32(void *f, int v) "file=%p, val=0x%x" qemu_get_sbe32(void *f, int v) "file=%p, val=0x%x" qemu_put_sbe64(void *f, int64_t v) "file=%p, val=0x%"PRIx64 qemu_get_sbe64(void *f, int64_t v) "file=%p, val=0x%"PRIx64 + +# qapi/qapi-visit-core.c +qapi_visit_type_uint8(void *v, const char *field, uint8_t *value_ptr, uint8_t value, void *e) "visitor=%p, field=%s, ptr=%p, val=0x%x, err=%p" +qapi_visit_type_uint16(void *v, const char *field, uint16_t *value_ptr, uint16_t value, void *e) "visitor=%p, field=%s, ptr=%p, val=0x%x, err=%p" +qapi_visit_type_uint32(void *v, const char *field, uint32_t *value_ptr, uint32_t value, void *e) "visitor=%p, field=%s, ptr=%p, val=0x%x, err=%p" +qapi_visit_type_uint64(void *v, const char *field, uint64_t *value_ptr, uint64_t value, void *e) "visitor=%p, field=%s, ptr=%p, val=0x%"PRIx64", err=%p" +qapi_visit_type_int8(void *v, const char *field, int8_t *value_ptr, int8_t value, void *e) "visitor=%p, field=%s, ptr=%p, val=0x%x, err=%p" +qapi_visit_type_int16(void *v, const char *field, int16_t *value_ptr, int16_t value, void *e) "visitor=%p, field=%s, ptr=%p, val=0x%x, err=%p" +qapi_visit_type_int32(void *v, const char *field, int32_t *value_ptr, int32_t value, void *e) "visitor=%p, field=%s, ptr=%p, val=0x%x, err=%p" +qapi_visit_type_int64(void *v, const char *field, int64_t *value_ptr, int64_t value, void *e) "visitor=%p, field=%s, ptr=%p, val=0x%"PRIx64", err=%p" +qapi_visit_type_int(void *v, const char *field, int64_t *value_ptr, int64_t value, void *e) "visitor=%p, field=%s, ptr=%p, val=0x%"PRIx64", err=%p" +qapi_visit_type_bool(void *v, const char *field, bool *value_ptr, bool value, void *e) "visitor=%p, field=%s, ptr=%p, val=0x%x, err=%p" +qapi_visit_type_str(void *v, const char *field, void *value_ptr, char *value, void *e) "visitor=%p, field=%s, ptr=%p, val=%s, err=%p" +qapi_visit_type_double(void *v, const char *field, double *value_ptr, double value, void *e) "visitor=%p, field=%s, ptr=%p, val=%f, err=%p" +qapi_visit_type_enum(void *v, const char *field, int *value_ptr, int value, const void *strings_ptr, void *e) "visitor=%p, field=%s, ptr=%p, val=0x%x, strings_ptr=%p, err=%p" +qapi_start_struct(void *v, const char *field, void *ptr, int size, const char *kind, void *err) "visitor=%p, field=%s, ptr=%p, size=%d, kind=%s, err=%p" +qapi_end_struct(void *v, void *err) "visitor=%p, err=%p" +qapi_start_list(void *v, const char *field, void *e) "visitor=%p, field=%s, err=%p" +qapi_visit_next_list(void *v, void *list_entry, void *e) "visitor=%p, list_entry=%p, err=%p" +qapi_end_list(void *v, void *e) "visitor=%p, err=%p" +qapi_start_array(void *v, const char *field, void *ptr, int elem_count, int elem_size, void *e) "visitor=%p, field=%s, ptr=%p, elem_count=%d, elem_size=%d, err=%p" +qapi_visit_next_array(void *v, void *e) "visitor=%p, err=%p" +qapi_end_array(void *v, void *e) "visitor=%p, err=%p" +qapi_start_optional(void *v, const char *field, bool *value_ptr, bool value, void *e) "visitor=%p, field=%s, value_ptr=%p, val=0x%x, err=%p" +qapi_end_optional(void *v, void *e) "visitor=%p, err=%p"
Signature · 1 line
1.7.4.1
PATCH 7/10 trace: qemu_(put|get)_(byte|buffer) events
In reply to Michael Roth--- qemu-file.c | 22 ++++++++++++++++++++-- trace-events | 18 ++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-)
qemu-file.c +20 -2
@@ -27,6 +27,7 @@#include "hw/hw.h" #include "qapi/qemu-file-output-visitor.h" #include "qapi/qemu-file-input-visitor.h" +#include "trace.h" #define IO_BUF_SIZE 32768
@@ -206,6 +207,8 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size) {int l; +trace_qemu_put_buffer (f, buf, size); +if (!f->has_error && f->is_write ==0 && f->buf_index >0 ) {fprintf (stderr,"Attempted to write to buffer while read buffer is not empty\n" );
@@ -236,6 +239,7 @@ void qemu_put_byte(QEMUFile *f, int v)abort (); } +trace_qemu_put_byte (f, v &0xff ); f->buf[f->buf_index++] = v; f->is_write =1 ;if (f->buf_index >=IO_BUF_SIZE ) {
@@ -247,6 +251,8 @@ int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size1) {int size, l; +trace_qemu_get_buffer (f, buf, size1); +if (f->is_write) {abort (); }
@@ -273,6 +279,8 @@ int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size1)int qemu_get_byte (QEMUFile *f) { +int ret; +if (f->is_write) {abort (); }
@@ -280,10 +288,14 @@ int qemu_get_byte(QEMUFile *f)if (f->buf_index >= f->buf_size) {qemu_fill_buffer (f);if (f->buf_index >= f->buf_size) { -return 0 ; + ret =0 ; + goto out; } } -return f->buf[f->buf_index++]; + ret = f->buf[f->buf_index++]; +out: +trace_qemu_get_byte (f, ret); +return ret; }int64_t qemu_ftell (QEMUFile *f)
@@ -360,6 +372,7 @@ void qemu_put_be16(QEMUFile *f, unsigned int v) {qemu_put_byte (f, v >>8 );qemu_put_byte (f, v); +trace_qemu_put_be16 (f, v); }void qemu_put_be32 (QEMUFile *f,unsigned int v)
@@ -368,12 +381,14 @@ void qemu_put_be32(QEMUFile *f, unsigned int v)qemu_put_byte (f, v >>16 );qemu_put_byte (f, v >>8 );qemu_put_byte (f, v); +trace_qemu_put_be32 (f, v); }void qemu_put_be64 (QEMUFile *f,uint64_t v) {qemu_put_be32 (f, v >>32 );qemu_put_be32 (f, v); +trace_qemu_put_be64 (f, v); }unsigned int qemu_get_be16 (QEMUFile *f)
@@ -381,6 +396,7 @@ unsigned int qemu_get_be16(QEMUFile *f)unsigned int v; v =qemu_get_byte (f) <<8 ; v |=qemu_get_byte (f); +trace_qemu_get_be16 (f, v);return v; }
@@ -391,6 +407,7 @@ unsigned int qemu_get_be32(QEMUFile *f) v |=qemu_get_byte (f) <<16 ; v |=qemu_get_byte (f) <<8 ; v |=qemu_get_byte (f); +trace_qemu_get_be32 (f, v);return v; }
@@ -399,6 +416,7 @@ uint64_t qemu_get_be64(QEMUFile *f)uint64_t v; v = (uint64_t )qemu_get_be32 (f) <<32 ; v |=qemu_get_be32 (f); +trace_qemu_get_be64 (f, v);return v; }
trace-events +18 -0
@@ -538,3 +538,21 @@ esp_mem_writeb_cmd_ensel(uint32_t val) "Enable selection (%2.2x)" # monitor.c handle_qmp_command(void *mon, const char *cmd_name) "mon %p cmd_name \"%s\"" monitor_protocol_emitter(void *mon) "mon %p" + +# qemu-file.c +qemu_put_buffer(void *f, const uint8_t *buf, int size) "file=%p, buf=%p, size=%d" +qemu_get_buffer(void *f, const uint8_t *buf, int size) "file=%p, buf=%p, size=%d" +qemu_put_byte(void *f, int val) "file=%p, val=0x%x" +qemu_get_byte(void *f, int val) "file=%p, val=0x%x" +qemu_put_be16(void *f, unsigned int v) "file=%p, val=0x%x" +qemu_get_be16(void *f, unsigned int v) "file=%p, val=0x%x" +qemu_put_be32(void *f, unsigned int v) "file=%p, val=0x%x" +qemu_get_be32(void *f, unsigned int v) "file=%p, val=0x%x" +qemu_put_be64(void *f, uint64_t v) "file=%p, val=0x%"PRIx64 +qemu_get_be64(void *f, uint64_t v) "file=%p, val=0x%"PRIx64 +qemu_put_sbe16(void *f, int v) "file=%p, val=0x%x" +qemu_get_sbe16(void *f, int v) "file=%p, val=0x%x" +qemu_put_sbe32(void *f, int v) "file=%p, val=0x%x" +qemu_get_sbe32(void *f, int v) "file=%p, val=0x%x" +qemu_put_sbe64(void *f, int64_t v) "file=%p, val=0x%"PRIx64 +qemu_get_sbe64(void *f, int64_t v) "file=%p, val=0x%"PRIx64
Signature · 1 line
1.7.4.1
PATCH 9/10 qapi: add trace statements to qapi-visit-core.c
In reply to Michael Roth--- Makefile.objs | 2 +- qapi/qapi-visit-core.c | 41 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 3 deletions(-)
Makefile.objs +1 -1
@@ -24,7 +24,7 @@ coroutine-obj-$(CONFIG_WIN32) += coroutine-win32.o # qapi qapi-nested-y = qapi-visit-core.o qmp-input-visitor.o qmp-output-visitor.o qapi-dealloc-visitor.o qapi-nested-y += qmp-registry.o qmp-dispatch.o -qapi-obj-y = $(addprefix qapi/, $(qapi-nested-y)) +qapi-obj-y = $(addprefix qapi/, $(qapi-nested-y)) $(trace-obj-y) ####################################################################### # block-obj-y is code used by both qemu system emulation and qemu-img
qapi/qapi-visit-core.c +39 -2
184 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH 10/10 vmstate: use visitors
In reply to Michael Roth--- hw/eeprom93xx.c | 12 +- hw/fw_cfg.c | 12 +- hw/hw.h | 4 +- hw/pci.c | 38 +++-- hw/twl92230.c | 18 ++- qemu-timer.c | 24 ++- qemu-timer.h | 5 + savevm.c | 459 ++++++++++++++++++++++++++++++------------------ target-alpha/machine.c | 13 +- target-i386/machine.c | 49 ++++-- 10 files changed, 407 insertions(+), 227 deletions(-)
hw/eeprom93xx.c +8 -4
@@ -93,14 +93,18 @@ struct _eeprom_t {This is a Big hack, but it is how the old state did it. */ -static int get_uint16_from_uint8 (QEMUFile *f,void *pv,size_t size) +static int get_uint16_from_uint8 (Visitor *v,const char *name,void *pv, +size_t size,Error **err) { -uint16_t *v = pv; - *v =qemu_get_ubyte (f); +uint16_t *v1 = pv; +uint8_t v2; +visit_type_uint8 (v, &v2,NULL , err); + *v1 = v2;return 0 ; } -static void put_unused (QEMUFile *f,void *pv,size_t size) +static void put_unused (Visitor *v,const char *name,void *pv, +size_t size,Error **err) {fprintf (stderr,"uint16_from_uint8 is used only for backwards compatibility.\n" );fprintf (stderr,"Never should be used to write a new state.\n" );
hw/fw_cfg.c +8 -4
@@ -326,14 +326,18 @@ static void fw_cfg_reset(DeviceState *d)Or we broke compatibility in the state, or we can't use struct tm */ -static int get_uint32_as_uint16 (QEMUFile *f,void *pv,size_t size) +static int get_uint32_as_uint16 (Visitor *v,const char *name,void *pv, +size_t size,Error **err) { -uint32_t *v = pv; - *v =qemu_get_be16 (f); +uint32_t *val = pv; +uint16_t val2; +visit_type_uint16 (v, &val2, name, err); + *val = val2;return 0 ; } -static void put_unused (QEMUFile *f,void *pv,size_t size) +static void put_unused (Visitor *v,const char *name,void *pv,size_t size, +Error **err) {fprintf (stderr,"uint32_as_uint16 is only used for backward compatibility.\n" );fprintf (stderr,"This functions shouldn't be called.\n" );
hw/hw.h +2 -2
@@ -303,8 +303,8 @@ typedef struct VMStateDescription VMStateDescription;struct VMStateInfo {const char *name; -int (*get)(QEMUFile *f,void *pv,size_t size); -void (*put)(QEMUFile *f,void *pv,size_t size); +int (*get)(Visitor *v,const char *name,void *pv,size_t size,Error **err); +void (*put)(Visitor *v,const char *name,void *pv,size_t size,Error **err); };enum VMStateFlags {
hw/pci.c +27 -11
@@ -334,23 +334,25 @@ int pci_bus_num(PCIBus *s)return s->parent_dev->config[PCI_SECONDARY_BUS ]; } -static int get_pci_config_device (QEMUFile *f,void *pv,size_t size) +static int get_pci_config_device (Visitor *v,const char *name,void *pv, +size_t size,Error **err) {PCIDevice *s =container_of (pv, PCIDevice, config); -uint8_t *config; +uint8_t *config =NULL ;int i;assert (size ==pci_config_size (s)); - config =g_malloc (size); -qemu_get_buffer (f, config, size); +visit_start_array (v, (void **)&config, name, size,1 , err);for (i =0 ; i < size; ++i) { +visit_type_uint8 (v, &config[i],NULL , err);if ((config[i] ^ s->config[i]) & s->cmask[i] & ~s->wmask[i] & ~s->w1cmask[i]) {g_free (config);return -EINVAL ; } } +visit_end_array (v, err);memcpy (s->config, config, size);pci_update_mappings (s);
@@ -360,11 +362,17 @@ static int get_pci_config_device(QEMUFile *f, void *pv, size_t size) }/* just put buffer */ -static void put_pci_config_device (QEMUFile *f,void *pv,size_t size) +static void put_pci_config_device (Visitor *v,const char *name,void *pv, +size_t size,Error **err) { -const uint8_t **v = pv; +uint8_t *config = *(uint8_t **)pv; +int i;assert (size ==pci_config_size (container_of (pv, PCIDevice, config))); -qemu_put_buffer (f, *v, size); +visit_start_array (v, (void **)&config, name, size,1 , err); +for (i =0 ; i < size; i++) { +visit_type_uint8 (v, &config[i],NULL , err); + } +visit_end_array (v, err); }static VMStateInfo vmstate_info_pci_config = {
@@ -373,19 +381,22 @@ static VMStateInfo vmstate_info_pci_config = { .put = put_pci_config_device, }; -static int get_pci_irq_state (QEMUFile *f,void *pv,size_t size) +static int get_pci_irq_state (Visitor *v,const char *name,void *pv, +size_t size,Error **err) {PCIDevice *s =container_of (pv, PCIDevice, irq_state);uint32_t irq_state[PCI_NUM_PINS ];int i; +visit_start_array (v,NULL , name,PCI_NUM_PINS ,4 , err);for (i =0 ; i <PCI_NUM_PINS ; ++i) { - irq_state[i] =qemu_get_be32 (f); +visit_type_uint32 (v, &irq_state[i],NULL , err);if (irq_state[i] !=0x1 && irq_state[i] !=0 ) {fprintf (stderr,"irq state %d: must be 0 or 1.\n" , irq_state[i]);return -EINVAL ; } } +visit_end_array (v, err);for (i =0 ; i <PCI_NUM_PINS ; ++i) {pci_set_irq_state (s, i, irq_state[i]);
@@ -394,14 +405,19 @@ static int get_pci_irq_state(QEMUFile *f, void *pv, size_t size)return 0 ; } -static void put_pci_irq_state (QEMUFile *f,void *pv,size_t size) +static void put_pci_irq_state (Visitor *v,const char *name,void *pv, +size_t size,Error **err) {int i;PCIDevice *s =container_of (pv, PCIDevice, irq_state); +uint32_t irq_state; +visit_start_array (v,NULL , name,PCI_NUM_PINS ,4 , err);for (i =0 ; i <PCI_NUM_PINS ; ++i) { -qemu_put_be32 (f,pci_irq_state (s, i)); + irq_state =pci_irq_state (s, i); +visit_type_uint32 (v, &irq_state,NULL , err); } +visit_end_array (v, err); }static VMStateInfo vmstate_info_pci_irq_state = {
hw/twl92230.c +12 -6
@@ -742,17 +742,23 @@ static int menelaus_rx(i2c_slave *i2c)Or we broke compatibility in the state, or we can't use struct tm */ -static int get_int32_as_uint16 (QEMUFile *f,void *pv,size_t size) +static int get_int32_as_uint16 (Visitor *v,const char *name,void *pv, +size_t size,Error **err) { -int *v = pv; - *v =qemu_get_be16 (f); +uint32_t *val = pv; +uint16_t val2; +visit_type_uint16 (v, &val2, name, err); + *val = val2;return 0 ; } -static void put_int32_as_uint16 (QEMUFile *f,void *pv,size_t size) +static void put_int32_as_uint16 (Visitor *v,const char *name,void *pv, +size_t size,Error **err) { -int *v = pv; -qemu_put_be16 (f, *v); +uint32_t *val = pv; +uint16_t val2; +visit_type_uint16 (v, &val2, name, err); + *val = val2; }static const VMStateInfo vmstate_hack_int32_as_uint16 = {
qemu-timer.c +20 -4
@@ -629,7 +629,8 @@ void init_clocks(void) }/* save a timer */ -void qemu_put_timer (QEMUFile *f,QEMUTimer *ts) +void qemu_put_timer_visitor (Visitor *v,const char *name,QEMUTimer *ts, +Error **err) {uint64_t expire_time;
@@ -638,14 +639,22 @@ void qemu_put_timer(QEMUFile *f, QEMUTimer *ts) }else { expire_time =-1 ; } -qemu_put_be64 (f, expire_time); +visit_type_uint64 (v, &expire_time, name, err); } -void qemu_get_timer (QEMUFile *f,QEMUTimer *ts) +void qemu_put_timer (QEMUFile *f,QEMUTimer *ts) +{ +Visitor *v =qemu_file_get_output_visitor (f); +assert (v); +qemu_put_timer_visitor (v,"timer" , ts,NULL ); +} + +void qemu_get_timer_visitor (Visitor *v,const char *name,QEMUTimer *ts, +Error **err) {uint64_t expire_time; - expire_time =qemu_get_be64 (f); +visit_type_uint64 (v, &expire_time, name, err);if (expire_time !=-1 ) {qemu_mod_timer_ns (ts, expire_time); }else {
@@ -653,6 +662,13 @@ void qemu_get_timer(QEMUFile *f, QEMUTimer *ts) } } +void qemu_get_timer (QEMUFile *f,QEMUTimer *ts) +{ +Visitor *v =qemu_file_get_input_visitor (f); +assert (v); +qemu_get_timer_visitor (v,"timer" , ts,NULL ); +} +static const VMStateDescription vmstate_timers = { .name ="timer" , .version_id =2 ,
qemu-timer.h +5 -0
@@ -5,6 +5,7 @@#include "notify.h" #include <time.h> #include <sys/time.h> +#include "qapi/qapi-visit-core.h" #ifdef _WIN32#include <windows.h>
@@ -134,7 +135,11 @@ static inline int64_t get_clock(void)#endif void qemu_get_timer (QEMUFile *f,QEMUTimer *ts); +void qemu_get_timer_visitor (Visitor *v,const char *name,QEMUTimer *ts, +Error **err);void qemu_put_timer (QEMUFile *f,QEMUTimer *ts); +void qemu_put_timer_visitor (Visitor *v,const char *name,QEMUTimer *ts, +Error **err);/* ptimer.c */ typedef struct ptimer_state ptimer_state ;
savevm.c +284 -175
751 lines not on this page · raw message
target-alpha/machine.c +9 -4
@@ -1,17 +1,22 @@#include "hw/hw.h" #include "hw/boards.h" -static int get_fpcr (QEMUFile *f,void *opaque,size_t size) +static int get_fpcr (Visitor *v,const char *name,void *opaque, +size_t size,Error **err) {CPUAlphaState *env = opaque; -cpu_alpha_store_fpcr (env,qemu_get_be64 (f)); +uint64_t fpcr; +visit_type_uint64 (v, &fpcr, name, err); +cpu_alpha_store_fpcr (env, fpcr);return 0 ; } -static void put_fpcr (QEMUFile *f,void *opaque,size_t size) +static void put_fpcr (Visitor *v,const char *name,void *opaque, +size_t size,Error **err) {CPUAlphaState *env = opaque; -qemu_put_be64 (f,cpu_alpha_load_fpcr (env)); +uint64_t fpcr =cpu_alpha_load_fpcr (env); +visit_type_uint64 (v, &fpcr, name, err); }static const VMStateInfo vmstate_fpcr = {
target-i386/machine.c +32 -17
107 lines not on this page · raw message
Signature · 1 line
1.7.4.1