do savevm/migration save/load via Visitor interface
v2 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-v2
- rebased on 9f60639b848944200c3d33a89233d808de0b5a43. Juan: had a pretty hard collision with your recent savevm/vmstate cleanups. I think most of the issues were reconciled, but some of your checks such as bailing out of vmstate_subsection_load() if qemu_peek_buffer() doesn't return the length encoded in the stream (for idstr) and peeking and checking subsection tags before progressing through the QEMUFile input buffer were not compatible with the visitorized approach. The net effect of failing migration if these assertions do not hold should still be intact, however.
- reworked QEMUFile<->Visitor lookup routines to support opaque objects and register cleanup routines, mainly to allow cleanup of QEMUFileInputVisitor/QEMUFileOutputVisitor/etc via qemu_fclose() without being aware of the type of Visitor employed.
- fixed coding style issues as part of moving QEMUFile interfaces to qemu-file.c
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
qemu-file: 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 | 18 +- 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 | 688 +++++++++++++++++++++++++ qemu-timer.h | 5 + savevm.c | 1049 ++++++++++++--------------------------- target-alpha/machine.c | 13 +- target-i386/machine.c | 49 ++- test-visitor.c | 404 +++++++++++++++ trace-events | 43 ++ 20 files changed, 2445 insertions(+), 785 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 v2 1/10 qapi: add Visitor interfaces for uint*_t and int*_t
--- 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
Re: [Qemu-devel] [PATCH v2 01/10] qapi: add Visitor interfaces for uint*_t and int*_t
Quoted 8 lines
qapi/qapi-visit-core.h +4
-0+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[],
qapi/qapi-visit-core.h void visit_end_struct(Visitor *v, Error **errp); · line 101
Quoted 10 lines
qapi/qapi-visit-core.h +8
-0const 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);
I think this approach is wrong. We're mashing the design of vmstate with that of visitors and getting something that is not a visitor and not vmstate.
Instead, I think you should have something like this:
struct VMStateInfo {
const char *name;
// takes a QMPOutputVisitor and a QEMUFile open for reading
int (*load)(QEMUFile *f, const char *name, Visitor *v,
size_t size, Error **err);
// takes a QMPInputVisitor and a QEMUFile open for writing
void (*save)(QEMUFile *f, const char *name, Visitor *v,
size_t size, Error **err);
// takes a QMPOutputVisitor and reads from *pv
int (*get)(Visitor *v, const char *name, void *pv,
size_t size, Error **err);
// takes a QMPInputVisitor and writes into *pv
void (*set)(Visitor *v, const char *name, void *pv,
size_t size, Error **err);
};that splits the existing callbacks in two steps.
For saving, you would adapt your visitor-based vmstate "put" routines so that they put things in a dictionary with no regard for integer types (a bit ugly for uint64, but perfectly fine for everything else). You take the dictionary from the output visitor and (with an input visitor) you feed it back to the "save" routines, which convert the dictionary to a QEMUFile. Both steps keep the types internal to vmstate.
For loading, it's the other way round: you interpret the vmstate with the QEMUFile reading routines, and create a dictionary. Then make an input visitor and use the vmstate "set" interpreter to fill in the struct fields.
I'm sorry for noticing this just now, I was waiting for Anthony's QOM plans to be committed so that I could understand better how vmstate and QOM properties would interact. In fact, it would be great and not hard if the struct<->visitor step (get/set) was also exposed as a QOM property.
Paolo
Re: [Qemu-devel] [PATCH v2 01/10] qapi: add Visitor interfaces for uint*_t and int*_t
Quoted 40 lines · Paolo Bonzini
I think this approach is wrong. We're mashing the design of vmstate with that of visitors and getting something that is not a visitor and not vmstate.
Instead, I think you should have something like this:
struct VMStateInfo { const char *name; // takes a QMPOutputVisitor and a QEMUFile open for reading int (*load)(QEMUFile *f, const char *name, Visitor *v, size_t size, Error **err); // takes a QMPInputVisitor and a QEMUFile open for writing void (*save)(QEMUFile *f, const char *name, Visitor *v, size_t size, Error **err); // takes a QMPOutputVisitor and reads from *pv int (*get)(Visitor *v, const char *name, void *pv, size_t size, Error **err); // takes a QMPInputVisitor and writes into *pv void (*set)(Visitor *v, const char *name, void *pv, size_t size, Error **err); };that splits the existing callbacks in two steps.
For saving, you would adapt your visitor-based vmstate "put" routines so that they put things in a dictionary with no regard for integer types (a bit ugly for uint64, but perfectly fine for everything else). You take the dictionary from the output visitor and (with an input visitor) you feed it back to the "save" routines, which convert the dictionary to a QEMUFile. Both steps keep the types internal to vmstate.
For loading, it's the other way round: you interpret the vmstate with the QEMUFile reading routines, and create a dictionary. Then make an input visitor and use the vmstate "set" interpreter to fill in the struct fields.
Quoted 4 lines
I'm sorry for noticing this just now, I was waiting for Anthony's QOM plans to be committed so that I could understand better how vmstate and QOM properties would interact. In fact, it would be great and not hard if the struct<->visitor step (get/set) was also exposed as a QOM property.
Note that this doesn't prevent sharing the code for loading and saving.
1) You can still add a vtable to QEMUFile for "visit_type_int*" and "visit_type_uint*". But this vtable doesn't need start/end callbacks.
2) Similarly, I don't object to adding visit_type_int* and visit_type_uint* to Visitor. However, these should be exclusively a convenience for the callers, so that they do not have to convert between int64 and other types. There should be exactly two implementations of these callbacks, one for input visitors (including e.g. the dealloc visitor) and one for output visitors. I attach a sample patch that does this for int16 only.
Paolo
qapi/qapi-dealloc-visitor.c +1 -0
@@ -154,6 +154,7 @@ QapiDeallocVisitor *qapi_dealloc_visitor_new(void) v =g_malloc0 (sizeof (*v)); +qapi_init_input_visitor (&v->visitor); v->visitor.start_struct = qapi_dealloc_start_struct; v->visitor.end_struct = qapi_dealloc_end_struct; v->visitor.start_list = qapi_dealloc_start_list;
qapi/qapi-visit-core.c +34 -0
@@ -116,3 +116,37 @@ void visit_type_number(Visitor *v, double *obj, const char *name, Error **errp) v->type_number (v, obj, name, errp); } } + +static void visit_type_int16_in (Visitor *v,int16_t *obj,const char *name,Error **errp) +{ +if (!error_is_set (errp)) { +int64_t value; + v->type_int (v, &value, name, errp); + *obj = value; + } +} + +static void visit_type_int16_out (Visitor *v,int16_t *obj,const char *name,Error **errp) +{ +if (!error_is_set (errp)) { +int64_t value = *obj; + v->type_int (v, &value, 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 qapi_init_input_visitor (Visitor *v) +{ + v->type_int16 = visit_type_int16_in; +} + +void qapi_init_output_visitor (Visitor *v) +{ + v->type_int16 = visit_type_int16_out; +}
qapi/qapi-visit-core.h +19 -0
@@ -52,6 +52,9 @@ struct Visitorvoid (*start_handle)(Visitor *v,void **obj,const char *kind,const char *name,Error **errp);void (*end_handle)(Visitor *v,Error **errp); + +/* Internal only. */ +void (*type_int16)(Visitor *v,int16_t *obj,const char *name,Error **errp); }; void visit_start_handle(Visitor *v, void **obj, const char *kind,
@@ -69,8 +72,24 @@ 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_int16 (Visitor *v,int16_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); +static inline void visit_type_uint (Visitor *v,uint64_t *obj, +const char *name,Error **errp) +{ +visit_type_int (v, (int64_t *) obj, name, errp); +} + +static inline void visit_type_uint16 (Visitor *v,uint16_t *obj, +const char *name,Error **errp) +{ +visit_type_int16 (v, (int16_t *) obj, name, errp); +} + +void qapi_init_input_visitor (Visitor *v); +void qapi_init_output_visitor (Visitor *v); +#endif
qapi/qmp-input-visitor.c +1 -0
@@ -283,6 +283,7 @@ QmpInputVisitor *qmp_input_visitor_new(QObject *obj) v =g_malloc0 (sizeof (*v)); +qapi_init_input_visitor (&v->visitor); v->visitor.start_struct = qmp_input_start_struct; v->visitor.end_struct = qmp_input_end_struct; v->visitor.start_list = qmp_input_start_list;
qapi/qmp-output-visitor.c +1 -0
@@ -234,6 +234,7 @@ QmpOutputVisitor *qmp_output_visitor_new(void) v =g_malloc0 (sizeof (*v)); +qapi_init_output_visitor (&v->visitor); v->visitor.start_struct = qmp_output_start_struct; v->visitor.end_struct = qmp_output_end_struct; v->visitor.start_list = qmp_output_start_list;
hw/qdev-properties.c +1 -3
@@ -229,10 +229,8 @@ static void get_int16(DeviceState *dev, Visitor *v, void *opaque, {Property *prop = opaque;int16_t *ptr =qdev_get_prop_ptr (dev, prop); -int64_t value; - value = *ptr; -visit_type_int (v, &value, name, errp); +visit_type_int16 (v, ptr, name, errp); } static void set_int16(DeviceState *dev, Visitor *v, void *opaque,
Re: [Qemu-devel] [PATCH v2 01/10] qapi: add Visitor interfaces for uint*_t and int*_t
Quoted 3 lines · Paolo Bonzini
1) You can still add a vtable to QEMUFile for "visit_type_int*" and "visit_type_uint*". But this vtable doesn't need start/end callbacks.
Here I meant something simple like:
void (*visit_type_int16) (QEMUFile *f, int16_t *x);
that is really the same as qemu_{get,put}_be16s and friends.
It may even be not a vtable, but a function that dispatches based on the existing get_buffer/put_buffer callbacks: note that one of them is always NULL. Which also means that the is_write field is superfluous. So much cleanup to do. :(
Paolo
Re: [Qemu-devel] [PATCH v2 01/10] qapi: add Visitor interfaces for uint*_t and int*_t
In reply to Paolo BonziniQuoted 17 lines · Paolo Bonzini
Quoted 17 lines
+void visit_start_array(Visitor *v, void **obj, const char *name,
size_telem_count,
+size_telem_size, Error **errp);qapi/qapi-visit-core.h +2
-0+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);
voidvisit_end_optional(Visitor *v, Error **errp);
voidvisit_type_enum(Visitor *v, int *obj, const char *strings[], const char *kind, const char *name, Error **errp);
voidvisit_type_int(Visitor *v, int64_t *obj, const char *name, Error **errp);(quoted diff) +2
-0+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);
+voidvisit_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
Quoted 8 lines
qapi/qapi-visit-core.h void visit_end_struct(Visitor *v, Error **errp); · line 101
Quoted 5 lines
**errp);
qapi/qapi-visit-core.h +4
-0+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);I think this approach is wrong. We're mashing the design of vmstate with that of visitors and getting something that is not a visitor and not vmstate.
Thanks for taking a look at this.
Quoted 22 lines
Instead, I think you should have something like this:
struct VMStateInfo {
const char *name;
// takes a QMPOutputVisitor and a QEMUFile open for reading int (*load)(QEMUFile *f, const char *name, Visitor *v,size_tsize, Error **err);// takes a QMPInputVisitor and a QEMUFile open for writing void (*save)(QEMUFile *f, const char *name, Visitor *v,
size_tsize, Error **err);// takes a QMPOutputVisitor and reads from *pv int (*get)(Visitor *v, const char *name, void *pv,
size_tsize, Error **err);// takes a QMPInputVisitor and writes into *pv void (*set)(Visitor *v, const char *name, void *pv,
size_tsize, Error **err);
};
Quoted 5 lines
that splits the existing callbacks in two steps.
For saving, you would adapt your visitor-based vmstate "put" routines so that they put things in a dictionary with no regard for integer types (a bit ugly for uint64, but perfectly fine for everything else).
I don't understand this. The visitor interface should expose the C level primitives so that we can maintain fidelity when visiting something. The fact that it only knows about "ints" today is a short cut.
Quoted 4 lines
You take the dictionary from
the output visitor and (with an input visitor) you feed it back to the "save" routines, which convert the dictionary to a QEMUFile. Both steps keep the types internal to vmstate.
That doesn't make effective use of visitors. Visitors should preserve as much type information as possible. I'm not really sure I understand the whole QEMUFile tie in either. This series:
1) Makes a fully compatible QEMUFile input and output Visitor
2) Makes VMState no longer know about QEMUFile by using (1)
(2) is really the end goal. If we have an interface that still uses QEMUFile, we're doing something wrong IMHO.
Quoted 8 lines
For loading, it's the other way round: you interpret the vmstate with the QEMUFile reading routines, and create a dictionary. Then make an input visitor and use the vmstate "set" interpreter to fill in the struct fields.
I'm sorry for noticing this just now, I was waiting for Anthony's QOM plans to be committed so that I could understand better how vmstate and QOM properties would interact. In fact, it would be great and not hard if the struct<->visitor step (get/set) was also exposed as a QOM property.
That's exactly why I'm so anxious to get this merged :-)
Regards,
Anthony Liguori
Quoted 2 lines
Paolo
Re: [Qemu-devel] [PATCH v2 01/10] qapi: add Visitor interfaces for uint*_t and int*_t
Quoted 9 lines · Anthony Liguori
Quoted 4 lines
For saving, you would adapt your visitor-based vmstate "put" routines so that they put things in a dictionary with no regard for integer types (a bit ugly for uint64, but perfectly fine for everything else).
I don't understand this. The visitor interface should expose the C level primitives so that we can maintain fidelity when visiting something. The fact that it only knows about "ints" today is a short cut.
Why does this need to be in Visitor? You can always embed C knowledge in an adaptor or decorator. Visitors only need to know about names and JSON types (well, they also distinguish int from double).
We already have such an adaptor: QOM static properties know about names, JSON types, C type and struct offset.
VMState fields know about all that plus QEMUFile encoding. QEMUFile encoding can be hidden in the decorator, it does not need to become visible to the concrete visitors.
As always, you can implement that in many ways. However, I think the point of using Visitors is not to remove QEMUFile. It is to provide a backend-independent representation that backends can transform and that secondarily can be exposed by QOM.
This is only half-true in Michael's code, because he relies on primitives that QMPInputVisitor and QMPOutputVisitor do not implement. Fixing this is quite easy, you only need to add a base-class implementation of the int8/int16/... primitives.
On top of this the representation he passes to visitors is somewhat redundant. For example, VMState has "equal" fields; they are fields that are serialized but are really fixed at compile- or realize-time. Such fields should not be part of the backend-independent representation. With Michael's approach they are, and that's quite deep in the implementation.
Quoted 9 lines
Quoted 4 lines
You take the dictionary from the output visitor and (with an input visitor) you feed it back to the "save" routines, which convert the dictionary to a QEMUFile. Both steps keep the types internal to vmstate.
That doesn't make effective use of visitors. Visitors should preserve as much type information as possible. I'm not really sure I understand the whole QEMUFile tie in either. This series:
Quoted 6 lines
1) Makes a fully compatible QEMUFile input and output Visitor
2) Makes VMState no longer know about QEMUFile by using (1)
(2) is really the end goal. If we have an interface that still uses QEMUFile, we're doing something wrong IMHO.
Yes, this is accurate, but I see the goals differently. We should:
(1) First and foremost, provide a backend-independent representation of device state so that we can add other backends later.
(2) Serialize this with QEMUFile, both for backwards-compatibility and to ensure that the whole thing works.
Whether you do (2) directly with QEMUFile or, like Michael does, with QEMUFile*Visitors is secondary. I don't have big objections to either approach. However, the series is missing (1).
Paolo
Re: [Qemu-devel] [PATCH v2 01/10] qapi: add Visitor interfaces for uint*_t and int*_t
Quoted 6 lines · Paolo Bonzini
Quoted 5 lines · Anthony Liguori
Quoted 4 lines
For saving, you would adapt your visitor-based vmstate "put" routines so that they put things in a dictionary with no regard for integer types (a bit ugly for uint64, but perfectly fine for everything else).
Quoted 8 lines
Quoted 4 lines
I don't understand this. The visitor interface should expose the C level primitives so that we can maintain fidelity when visiting something. The fact that it only knows about "ints" today is a short cut.
Why does this need to be in Visitor? You can always embed C knowledge in an adaptor or decorator. Visitors only need to know about names and JSON types (well, they also distinguish int from double).
The main goal is to abstract away data serialization schemes (QObject->JSON, C->QEMUFile, etc). In the case of a JSON-based serialization, the visitor interface for fixed-with types would end up serializing everything as int64_t/double, but QEMUFile requires byte-length affinity to remain backward-compatible, so that information must be passed on to the Visitor interface when we call it.
And beyond QEMUFile, we'd like to eventually move to a serialization scheme that is self-describing in the types of the fields it stores so that we can do stricter checking in the deserialization/input visitor routines, or just plain be able to make sense of the serialized data without any outside information, since those schemes would eventually be used directly in implementing a new migration wire protocol and/or device state introspection.
Quoted 7 lines
We already have such an adaptor: QOM static properties know about names, JSON types, C type and struct offset.
VMState fields know about all that plus QEMUFile encoding. QEMUFile encoding can be hidden in the decorator, it does not need to become visible to the concrete visitors.
And these are both requirements to implementing a robust, flexible serialization/Visitor interface with pluggable back-ends, but if those interface throw away the type/field names then the only way to get them back is to deserialize, which isn't useful for introspection, and volatile for migration (since type errors can be silently missed in a lot of cases)
Quoted 5 lines
As always, you can implement that in many ways. However, I think the point of using Visitors is not to remove QEMUFile. It is to provide a backend-independent representation that backends can transform and that secondarily can be exposed by QOM.
Agreed, it's just a matter of wanting to maintain that information from start to finish.
Quoted 5 lines
This is only half-true in Michael's code, because he relies on primitives that QMPInputVisitor and QMPOutputVisitor do not implement. Fixing this is quite easy, you only need to add a base-class implementation of the int8/int16/... primitives.
Yup, that's the plan. These patches are a bit lazy in that regard. I agree that if we get into the habit of adding interfaces for a specific back-end without mapping these to the base-class implementations in other backends things will get out of hand quickly. Fortunately we haven't yet hit a situation where one backend ends up adding an interface that other backends cant' handle in some form.
Quoted 7 lines
On top of this the representation he passes to visitors is somewhat redundant. For example, VMState has "equal" fields; they are fields that are serialized but are really fixed at compile- or realize-time. Such fields should not be part of the backend-independent representation. With Michael's approach they are, and that's quite deep in the implementation.
You mean, for instance, put_int32()/get_int32_equal()? If so, I'm not sure I follow. In that case we use a Visitor purely to serialize/deserialize an int32, vmstate adds the *_equal() interface as helper function on top of that, but it's not part of the Visitor interfaces.
Quoted 22 lines
Quoted 10 lines
Quoted 5 lines
You take the dictionary from the output visitor and (with an input visitor) you feed it back to the "save" routines, which convert the dictionary to a QEMUFile. Both steps keep the types internal to vmstate.
That doesn't make effective use of visitors. Visitors should preserve as much type information as possible. I'm not really sure I understand the whole QEMUFile tie in either. This series:
Quoted 6 lines
1) Makes a fully compatible QEMUFile input and output Visitor
2) Makes VMState no longer know about QEMUFile by using (1)
(2) is really the end goal. If we have an interface that still uses QEMUFile, we're doing something wrong IMHO.
Yes, this is accurate, but I see the goals differently. We should:
(1) First and foremost, provide a backend-independent representation of device state so that we can add other backends later.
Quoted 6 lines
(2) Serialize this with QEMUFile, both for backwards-compatibility and to ensure that the whole thing works.
Whether you do (2) directly with QEMUFile or, like Michael does, with QEMUFile*Visitors is secondary. I don't have big objections to either approach. However, the series is missing (1).
I'll fix up the existing non-QEMUFile Visitor backends with base-class implementations for all the new interfaces. Beyond that, is there anything else missing to achieve 1)?
Quoted 3 lines
Paolo
Re: [Qemu-devel] [PATCH v2 01/10] qapi: add Visitor interfaces for uint*_t and int*_t
Quoted 2 lines · Michael Roth
The main goal is to abstract away data serialization schemes (
QObject->JSON,C->QEMUFile, etc).
Right. And the simplest way to abstract the scheme is to provide a backend-independent representation of device state.
As a convention, I'll call:
- "device state" the fields in the struct
- "QEMUFile" the serialized output that VMState save produces
- "device state representation" a representation of device state that is independent of the actual serialization backend.
- "device configuration" is the parameters that are used to create the device (coming from compile-time constants or the command-line)
Quoted 5 lines
In the case of a JSON-based serialization, the visitor interface for fixed-with types would end up serializing everything as int64_t/double, but QEMUFile requires byte-length affinity to remain backward-compatible, so that information must be passed on to the Visitor interface when we call it.
When creating the device state representation from either device state or QEMUFile, you need the byte length to fetch fields correctly.
When recreating device state from its representation, or saving to QEMUFile state, you need the byte length to store fields correctly.
However, you do not need the byte length in the device state representation. In all four cases (from/to device state, from/to QEMUFile) the byte length can be fetched from the VMState.
Quoted 7 lines
Quoted 4 lines
As always, you can implement that in many ways. However, I think the point of using Visitors is not to remove QEMUFile. It is to provide a backend-independent representation that backends can transform and that secondarily can be exposed by QOM.
Agreed, it's just a matter of wanting to maintain that information from start to finish.
I don't see the point of maintaining the type hints from start to finish, as long as you can reconstruct it any time you want it.
Quoted 7 lines
Quoted 6 lines
On top of this the representation he passes to visitors is somewhat redundant. For example, VMState has "equal" fields; they are fields that are serialized but are really fixed at compile- or realize-time. Such fields should not be part of the backend-independent representation. With Michael's approach they are, and that's quite deep in the implementation.
Quoted 5 lines
You mean, for instance, put_int32()/get_int32_equal()? If so, I'm not sure I follow. In that case we use a Visitor purely to serialize/deserialize an int32, vmstate adds the
*_equal()interface as helper function on top of that, but it's not part of the Visitor interfaces.
It should be only in QEMUFile, because it's one of its quirks. It is a separate property that is fixed at compile-time or realize-time, so it's part of device configuration; it's not part of device state representation.
Quoted 8 lines
Quoted 8 lines
Yes, this is accurate, but I see the goals differently. We should:
(1) First and foremost, provide a backend-independent representation of device state so that we can add other backends later.
(2) Serialize this with QEMUFile, both for backwards-compatibility and to ensure that the whole thing works.
Quoted 7 lines
Quoted 3 lines
Whether you do (2) directly with QEMUFile or, like Michael does, with QEMUFile*Visitors is secondary. I don't have big objections to either approach. However, the series is missing (1).
I'll fix up the existing non-QEMUFile Visitor backends with base-class implementations for all the new interfaces. Beyond that, is there anything else missing to achieve 1)?
I think almost nothing (you need to integrate into the QOM properties, and to handle a few special cases such as VMSTATE_EQUAL and VMSTATE_UNUSED). That's quite good.
However, once you do this, you will still be serializing QEMUFile directly from device state rather than from device state representation.
This is fine, but not what we should do when working on BER
serialization or similar.
Paolo
Re: [Qemu-devel] [PATCH v2 01/10] qapi: add Visitor interfaces for uint*_t and int*_t
In reply to Paolo BonziniQuoted 6 lines · Paolo Bonzini
Quoted 5 lines · Anthony Liguori
Quoted 4 lines
For saving, you would adapt your visitor-based vmstate "put" routines so that they put things in a dictionary with no regard for integer types (a bit ugly for uint64, but perfectly fine for everything else).
Quoted 8 lines
Quoted 4 lines
I don't understand this. The visitor interface should expose the C level primitives so that we can maintain fidelity when visiting something. The fact that it only knows about "ints" today is a short cut.
Why does this need to be in Visitor? You can always embed C knowledge in an adaptor or decorator. Visitors only need to know about names and JSON types (well, they also distinguish int from double).
You are tying Visitors too closely to JSON. We should be able to write a Visitor that can output a serialization format that has more interesting integer types and maintains better fidelity with standard C types.
Quoted 2 lines
We already have such an adaptor: QOM static properties know about names, JSON types, C type and struct offset.
Yes... But I don't see the relevance here.
Quoted 4 lines
VMState fields know about all that plus QEMUFile encoding. QEMUFile encoding can be hidden in the decorator, it does not need to become visible to the concrete visitors.
This is mixing up too many concepts.
A visit function -> knows only how to walk a C data structure. It's just saying, I have an int, it's name is X, i have a double, it's name is Y.
The Visitor is the thing that plugs into the visit function and decides what to do with this information.
Having a "QEMUFile" decorator just doesn't fit the model. I'm not even sure what it means.
Quoted 2 lines
As always, you can implement that in many ways. However, I think the point of using Visitors is not to remove QEMUFile.
Yes, it is.
Quoted 3 lines
It is to provide a backend-independent
representation that backends can transform and that secondarily can be exposed by QOM.
The point of Visitors is to make up for the fact that C lacks introspection. It's meant to be a standard way to introspect a C data structure (or type).
Quoted 11 lines
This is only half-true in Michael's code, because he relies on primitives that QMPInputVisitor and QMPOutputVisitor do not implement. Fixing this is quite easy, you only need to add a base-class implementation of the int8/int16/... primitives.
On top of this the representation he passes to visitors is somewhat redundant. For example, VMState has "equal" fields; they are fields that are serialized but are really fixed at compile- or realize-time. Such fields should not be part of the backend-independent representation. With Michael's approach they are, and that's quite deep in the implementation.
Yes, but there's no way to do this today without breaking the format. There's just too much magic in VMState right now. We need something like a migration filter capability where we can encapsulate this kind of logic such that we can ween VMState away from these things (and ultimately switch to an IDL compiler).
We can't do a migration filter until we have something like Michael's series.
Quoted 14 lines
Quoted 14 lines
Quoted 5 lines
You take the dictionary from the output visitor and (with an input visitor) you feed it back to the "save" routines, which convert the dictionary to a QEMUFile. Both steps keep the types internal to vmstate.
That doesn't make effective use of visitors. Visitors should preserve as much type information as possible. I'm not really sure I understand the whole QEMUFile tie in either. This series:
1) Makes a fully compatible QEMUFile input and output Visitor
2) Makes VMState no longer know about QEMUFile by using (1)
Quoted 7 lines
Quoted 2 lines
(2) is really the end goal. If we have an interface that still uses QEMUFile, we're doing something wrong IMHO.
Yes, this is accurate, but I see the goals differently. We should:
(1) First and foremost, provide a backend-independent representation of device state so that we can add other backends later.
And Mike's series does this, no?
Quoted 2 lines
(2) Serialize this with QEMUFile, both for backwards-compatibility and to ensure that the whole thing works.
Mike's series also does this, no?
Quoted 3 lines
Whether you do (2) directly with QEMUFile or, like Michael does, with QEMUFile*Visitors is secondary. I don't have big objections to either approach. However, the series is missing (1).
I don't see how.
Regards,
Anthony Liguori
Quoted 3 lines
Paolo
Re: [Qemu-devel] [PATCH v2 01/10] qapi: add Visitor interfaces for uint*_t and int*_t
Quoted 4 lines · Anthony Liguori
Quoted 2 lines
As always, you can implement that in many ways. However, I think the point of using Visitors is not to remove QEMUFile.
Yes, it is.
The point of using Visitors is to provide a standard representation of device state. QEMUFile is but one consumer of that representation, along with any other migration filter.
Quoted 6 lines
We need something like a migration filter capability where we can encapsulate this kind of logic such that we can ween VMState away from these things (and ultimately switch to an IDL compiler).
We can't do a migration filter until we have something like Michael's series.
Agreed. I'm saying that the QEMUFile serialization should be the first example of a migration filter. Mike's patch add a layer of indirection in the code, but not in the data. We can't do a migration filter until we have device state represented as introspectable data.
Quoted 6 lines
Quoted 4 lines
Yes, this is accurate, but I see the goals differently. We should:
(1) First and foremost, provide a backend-independent representation of device state so that we can add other backends later.
And Mike's series does this, no?
No.
Quoted 4 lines
Quoted 2 lines
(2) Serialize this with QEMUFile, both for backwards-compatibility and to ensure that the whole thing works.
Mike's series also does this, no?
It serializes device state directly, without going through a backend-independent representation. It doesn't provide a place in which you can plug a filter.
Paolo
Re: [Qemu-devel] [PATCH v2 01/10] qapi: add Visitor interfaces for uint*_t and int*_t
Quoted 9 lines · Paolo Bonzini
Quoted 4 lines · Anthony Liguori
Quoted 2 lines
As always, you can implement that in many ways. However, I think the point of using Visitors is not to remove QEMUFile.
Yes, it is.
The point of using Visitors is to provide a standard representation of device state. QEMUFile is but one consumer of that representation, along with any other migration filter.
Can you do a quick code mock up of how you'd expect this to work? I'm not sure if I'm just being dense, but I'm having a really hard time understanding what you're suggesting. How I see this evolving with Mike's series is:
struct DeviceStateClass {
ObjectClass parent;
void (*load_state)(DeviceState *obj, Visitor *v, const char *name,
Error **errp);
void (*save_state)(DeviceState *obj, Visitor *v, const char *name,
Error **errp);
};The PCIDevice base class would expose:
/* protected */
void pci_load_state(PCIDevice *obj, Visitor *v, const char *name,
Error **errp)
{
visit_start_struct(v, "PCIDevice", name, errp);
visit_type_int8(v, &obj->reg[0], "reg[0]", errp);
..
visit_end_struct(v, errp);
}Or:
static VMStateDescription pci_device_desc = {
.name = "PCIDevice",
.fields = {
VMSTATE_UINT8(PCIDevice, reg[0]),
... }
};
void pci_load_state(PCIDevice *obj, Visitor *v, const char *name,
Error **errp)
{
visit_with_vmstate(v, obj, &pci_device_desc, name, errp);
}A subclass would do:
static void my_device_load_state(DeviceState *obj, Visitor *v, const char *name,
Error **errp)
{
MyDevice *s = MY_DEVICE(obj);
visit_start_struct(v, "MyDevice", name, errp);
pci_load_state(PCI_DEVICE(obj), v, "super", errp);
visit_end_struct(v, errp);
}static void my_device_class_init(ObjectClass *klass, void *data) {
DeviceClass *dc = DEVICE_CLASS(klass);
dc->load_state = my_device_load_state;
...
}
There's no reference at all to QEMUFile. The load_state/save_state methods can be exposed as a "state" property too.
Once the series 2/4 lands and Mike's series, implementing this should be very straight forward.
Regards,
Anthony Liguori
Re: [Qemu-devel] [PATCH v2 01/10] qapi: add Visitor interfaces for uint*_t and int*_t
Quoted 7 lines · Anthony Liguori
Quoted 6 lines · Paolo Bonzini
Quoted 4 lines · Anthony Liguori
Quoted 2 lines
As always, you can implement that in many ways. However, I think the point of using Visitors is not to remove QEMUFile.
Yes, it is.
Quoted 7 lines
Quoted 5 lines
The point of using Visitors is to provide a standard representation of device
state. QEMUFile is but one consumer of that representation, along with any other
migration filter.Can you do a quick code mock up of how you'd expect this to work?
voidvmstate_get(Device *obj, Visitor *v, void *opaque, const char *name) {
/* Use the VMStateDescription in opaque to add fields to Visitor
from the struct. */
}
voidvmstate_set(Device *obj, Visitor *v, void *opaque, const char *name) {
/* Use the VMStateDescription in opaque to retrieve fields from
Visitor and store them in the struct. */
}
voidvmstate_load_state(Device *obj, Visitor *v, QEMUFile )
{
VMStateDescription *vmsd = ???; /* something from the DeviceClass */
/* Use the VMStateDescription in opaque to retrieve fields from
Visitor and store them in the struct. This is basically the VMState interpreter currently in savevm.c, only fetching fields from v rather than the file. */
}
voidvmstate_save_state(Device *obj, Visitor *v, QEMUFile *out)
{
VMStateDescription *vmsd = ???; /* something from the DeviceClass */
/* Use the VMStateDescription in opaque to fetch fields from
Visitor and store them in the file. This is basically the other VMState interpreter currently in savevm.c, but fetching fields from v rather than the struct. */
}
voidqdev_add_vmstate(Device *obj, VMStateDescription *vmsd)
{
qdev_add_property(obj, "vmstate", vmstate_get, vmstate_set, vmsd);
qdev_add_interface(obj, "QEMUFileSerializable", vmstate_load_state,
vmstate_save_state);
}savevm.c:
Visitor *v = qmp_output_visitor_new(); qdev_property_get(obj, "vmstate", v); QObject *qobj = qmp_visitor_get_obj(v); qmp_visitor_free(v);
Visitor *v = qmp_input_visitor_new(qobj); QEMUFileSerializable *s = QEMU_FILE_SERIALIZABLE(obj); s->save_state(obj, v, outfile); qmp_visitor_free(v);
...
Visitor *v = qmp_output_visitor_new(); QEMUFileSerializable *s = QEMU_FILE_SERIALIZABLE(obj); s->load_state(obj, v, outfile);
QObject *qobj = qmp_visitor_get_obj(v); qmp_visitor_free(v);
Visitor *v = qmp_input_visitor_new(qobj); QEMUFileSerializable *s = QEMU_FILE_SERIALIZABLE(obj); qdev_property_set(obj, "vmstate", v); qmp_visitor_free(v);
---------------------
Yes, this makes QEMUFile serialization special. But that's because it's legacy, and it needs to do strange things and store things beyond the contents of the vmstate.
Take for example "unused" fields. In Mike's implementation, if you try to pass a QMPOutputVisitor to save_state you might get a "unused" entry that is an array of zeros. I have no idea what happens if a single VMStateDescription has more than one VMSTATE_UNUSED field. QEMUFileOutputVisitor completely ignores the field names, so it probably works but would break with QMPOutputVisitor.
Other serialization backends should not need any hooks in the devices beyond save_state and load_state.
Paolo
Re: [Qemu-devel] [PATCH v2 01/10] qapi: add Visitor interfaces for uint*_t and int*_t
Quoted 52 lines · Paolo Bonzini
Quoted 7 lines · Anthony Liguori
Quoted 6 lines · Paolo Bonzini
Quoted 4 lines · Anthony Liguori
Quoted 2 lines
As always, you can implement that in many ways. However, I think the point of using Visitors is not to remove QEMUFile.
Yes, it is.
Quoted 7 lines
Quoted 5 lines
The point of using Visitors is to provide a standard representation of device
state. QEMUFile is but one consumer of that representation, along with any other
migration filter.Can you do a quick code mock up of how you'd expect this to work?
void
vmstate_get(Device *obj, Visitor *v, void *opaque, const char *name){
/* Use the VMStateDescription in opaque to add fields to Visitor from the struct. */
}void
vmstate_set(Device *obj, Visitor *v, void *opaque, const char *name){
/* Use the VMStateDescription in opaque to retrieve fields from Visitor and store them in the struct. */
}void
vmstate_load_state(Device *obj, Visitor *v, QEMUFile )
{
VMStateDescription *vmsd = ???; /* something from the DeviceClass *//* Use the VMStateDescription in opaque to retrieve fields from Visitor and store them in the struct. This is basically the VMState interpreter currently in
savevm.c, only fetching fields from v rather than the file. */
}void
vmstate_save_state(Device *obj, Visitor *v, QEMUFile *out){
VMStateDescription *vmsd = ???; /* something from the DeviceClass *//* Use the VMStateDescription in opaque to fetch fields from Visitor and store them in the file. This is basically the other VMState interpreter currently in
savevm.c, but fetching fields from v rather than the struct. */
}
Quoted 6 lines
void
qdev_add_vmstate(Device *obj, VMStateDescription *vmsd){qdev_add_property(obj, "vmstate", vmstate_get, vmstate_set, vmsd);qdev_add_interface(obj, "QEMUFileSerializable", vmstate_load_state, vmstate_save_state);
Ok, I get what you're suggesting. You would like to continue to keep VMStateDescription describing both the QEMUFile format and the fields.
I'm suggesting something fundamentally different. What I see us doing is breaking VMStateDescription apart into two different things. One would be a pure description of current fields. The other one would be the description of the old protocol.
The later would be fed to a migration filter and the former would live off of DeviceState.
By doing Mike's series, we can do this incrementally by splitting the description up, and invoking the filter post_load/pre_save.
One of the reasons for this split up is because I would like to generate the first table by IDL and make the second table not dependent on structure members (so we don't end up with all the hacks we have with dummy struct fields).
Regards,
Anthony Liguori
Quoted 45 lines
}
savevm.c:Visitor *v =
qmp_output_visitor_new();qdev_property_get(obj, "vmstate", v);
QObject *qobj =qmp_visitor_get_obj(v);qmp_visitor_free(v);Visitor *v =
qmp_input_visitor_new(qobj); QEMUFileSerializable *s =QEMU_FILE_SERIALIZABLE(obj);s->save_state(obj, v, outfile);qmp_visitor_free(v);...
Visitor *v =
qmp_output_visitor_new(); QEMUFileSerializable *s =QEMU_FILE_SERIALIZABLE(obj);s->load_state(obj, v, outfile);
QObject *qobj =qmp_visitor_get_obj(v);qmp_visitor_free(v);Visitor *v =
qmp_input_visitor_new(qobj); QEMUFileSerializable *s =QEMU_FILE_SERIALIZABLE(obj);qdev_property_set(obj, "vmstate", v);qmp_visitor_free(v);---------------------
Yes, this makes QEMUFile serialization special. But that's because it's legacy, and it needs to do strange things and store things beyond the contents of the vmstate.
Take for example "unused" fields. In Mike's implementation, if you try to pass a QMPOutputVisitor to
save_stateyou might get a "unused" entry that is an array of zeros. I have no idea what happens if a single VMStateDescription has more than oneVMSTATE_UNUSEDfield. QEMUFileOutputVisitor completely ignores the field names, so it probably works but would break with QMPOutputVisitor.Other serialization backends should not need any hooks in the devices beyond
save_stateandload_state.Paolo
Re: [Qemu-devel] [PATCH v2 01/10] qapi: add Visitor interfaces for uint*_t and int*_t
Quoted 2 lines · Anthony Liguori
Ok, I get what you're suggesting. You would like to continue to keep VMStateDescription describing both the QEMUFile format and the fields.
I don't "like" to do that, but yes, that's what I'm suggesting. :)
You envision having the front-end (state->introspectable state representation) and back-end (state representation->serialization) completely decoupled in the future, with migration filters in the middle if necessary.
I actually agree this is as the final direction. For this reason, the first step should be to decouple the front-end and backend and actually have this introspectable state representation. Then you can also break VMStateDescription apart into a front-end and backend part.
Mike's patches change the way you write to QEMUFile, so the new code _does_ go in the right direction. However, they fail to provide an introspectable, backend-independent state representation. Let's put it in a few diagrams:
where we are now: struct ---> QEMUFile
^
|
VMStateDescriptionwhat Mike's patches do: struct ---> QEMUFileVisitor ---> QEMUFile
^
|
VMStateDescriptionwhat I proposed: struct ---> QMPOutputVisitor ---> QObject
^
|
VMStateDescription
QObject ---> QEMUFile
^
|
VMStateDescriptionwhere you want to go: struct ---> QMPOutputVisitor ---> QObject
^
|
DeviceStateDescription
QObject ---> QEMUFileOutputVisitor ---> QEMUFile
^
|
VMStateDescriptionAs Mike's patches stand, I'm worried that they would make further steps harder rather than easier. This is because I'm not convinced that the QEMUFileOutputVisitor is actually useful.
However, the new code from Mike's patches is very close to the backend-independent representation from the VMStateDescription. So, Mike's patches could be morphed into this pretty easily:
struct ---> QMPOutputVisitor ---> QObject
^
|
VMStateDescription
struct ---> QEMUFile \
^ \ that's savevm.c,
| / unchanged
VMStateDescription /This is an intermediate state that lets us do the next steps:
- serialize to QEMUFile from a QObject;
- reintroduce Mike's QEMUFileOutputVisitor [I don't really see the benefit of this];
- split the DeviceStateDescription and the VMStateDescription;
None of these three steps are a prerequisite for introducing a new migration format.
Quoted 4 lines
One of the reasons for this split up is because I would like to generate the first table by IDL and make the second table not dependent on structure members (so we don't end up with all the hacks we have with dummy struct fields).
That would be a few years away. Let's reason in incremental steps.
Paolo
PATCH v2 2/10 qapi: add QemuFileOutputVisitor
In reply to Michael RothVisitor 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))
@@ -401,16 +410,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 v2 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 v2 4/10 savevm: move QEMUFile interfaces into qemu-file.c
In reply to Michael Roth--- Makefile.objs | 2 +- hw/hw.h | 3 + qemu-file.c | 573 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ savevm.c | 534 ----------------------------------------------------- 4 files changed, 577 insertions(+), 535 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 +3 -0
@@ -58,6 +58,9 @@ 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,int offset); +int qemu_peek_buffer (QEMUFile *f,uint8_t *buf,int size,size_t offset); +void qemu_file_skip (QEMUFile *f,int size);static inline void qemu_put_ubyte (QEMUFile *f,unsigned int v) {
qemu-file.c new file +573 -0
573 lines not on this page · raw message
savevm.c +0 -534
552 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH v2 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 v2 6/10 qemu-file: add QEMUFile<->visitor lookup routines
In reply to Michael RothThis interface is to allow switching between Visitor-based and direct QEMUFile usage to serialize/de-serialize fields. Once we're passed the transitionary stages and all requisite interfaces are converted to accepting Visitor objects, we can drop this dual approach and begin utilizing non-QEMUFile-based Visitors.
--- hw/hw.h | 7 ++++ qemu-file.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 110 insertions(+), 1 deletions(-)
hw/hw.h +7 -0
@@ -10,6 +10,13 @@#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" + +Visitor *qemu_file_get_visitor (QEMUFile *f); +QEMUFile *qemu_file_from_visitor (Visitor *v);/* VM Load/Save */
qemu-file.c +103 -1
135 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH v2 7/10 trace: qemu_(put|get)_(byte|buffer) events
In reply to Michael Roth--- qemu-file.c | 13 +++++++++++++ trace-events | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+), 0 deletions(-)
qemu-file.c +13 -0
@@ -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
@@ -454,6 +455,8 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size) {int l; +trace_qemu_put_buffer (f, buf, size); +if (!f->last_error && f->is_write ==0 && f->buf_index >0 ) {fprintf (stderr,"Attempted to write to buffer while read buffer is not empty\n" );
@@ -484,6 +487,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 ) {
@@ -531,6 +535,8 @@ int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size)int pending = size;int done =0 ; +trace_qemu_get_buffer (f, buf, size); +while (pending >0 ) {int res;
@@ -570,6 +576,7 @@ int qemu_get_byte(QEMUFile *f) result =qemu_peek_byte (f,0 );qemu_file_skip (f,1 ); +trace_qemu_get_byte (f, result);return result; }
@@ -632,6 +639,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)
@@ -640,12 +648,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)
@@ -653,6 +663,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; }
@@ -663,6 +674,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; }
@@ -671,5 +683,6 @@ 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
@@ -624,3 +624,21 @@ win_helper_no_switch_pstate(uint32_t new_pstate_regs) "change_pstate: regs new=% win_helper_wrpil(uint32_t psrpil, uint32_t new_pil) "old=%x new=%x" win_helper_done(uint32_t tl) "tl=%d" win_helper_retry(uint32_t tl) "tl=%d" + +# 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 v2 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
@@ -642,3 +642,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 v2 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 v2 10/10 vmstate: use visitors
In reply to Michael Roth--- hw/eeprom93xx.c | 12 +- hw/fw_cfg.c | 12 +- hw/hw.h | 8 +- hw/pci.c | 38 +++- hw/twl92230.c | 18 +- qemu-timer.h | 5 + savevm.c | 521 ++++++++++++++++++++++++++++++------------------ target-alpha/machine.c | 13 +- target-i386/machine.c | 49 +++-- 9 files changed, 436 insertions(+), 240 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 +6 -2
@@ -293,8 +293,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 {
@@ -941,10 +941,14 @@ extern const VMStateDescription vmstate_hid_ptr_device;#define VMSTATE_END_OF_LIST () \ {} +#define VMS_LOAD true +#define VMS_SAVE falseint vmstate_load_state (QEMUFile *f,const VMStateDescription *vmsd,void *opaque,int version_id);void vmstate_save_state (QEMUFile *f,const VMStateDescription *vmsd,void *opaque); +int vmstate_process (Visitor *v,const VMStateDescription *vmsd, +void *opaque,int version_id,bool load,Error **errp);int vmstate_register (DeviceState *dev,int instance_id,const VMStateDescription *vmsd,void *base); int vmstate_register_with_alias_id(DeviceState *dev, int instance_id,
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.h +5 -0
@@ -6,6 +6,7 @@#include "notify.h" #include <time.h> #include <sys/time.h> +#include "qapi/qapi-visit-core.h" #ifdef _WIN32#include <windows.h>
@@ -137,7 +138,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 +329 -192
822 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