Fix VMState design flaws
v2 cover Fix VMState design flaws
Hi
v2:
- fix old_version field for ps2 keyboard (thanks paolo)
v1:
I know you are not going to believe it, but VMState design have flaws:
(everybody) Ooohhhhhhh!!!!
This patches fixes (some) of them:
* When we added .pre_save() and .post_save(), we have it basically to change values in the variable pointed by the "void *opaque". Without this functions, it made sense that this variables were const, with them, it means that we have to do
FooState *s = (void *)opaque
in every pre/post_save() function. Just remove the const.
* Add version_id field to post_load(). Now we can assign default values in post_load for old versions of the state (ps2_kbd as example). This one is also needed for ioapic in qemu-kvm.
* Add support for sending partial struct arrays (i.e. only some fields starting from the beggining) fdc cleanups for getting pc98 in need it.
That is all for now :)
Later, Juan.
Juan Quintela (4):
vmstate: remove const for put operations
vmstate: add version_id argument to post_load
vmstate: remove ps2_kbd_load_old()
vmstate: Add support for sending partial arrays
exec.c | 2 +- hw/acpi.c | 2 +- hw/cirrus_vga.c | 2 +- hw/dma.c | 2 +- hw/fdc.c | 2 +- hw/hpet.c | 2 +- hw/hw.h | 18 +++++++++++++++--- hw/pci.c | 2 +- hw/piix_pci.c | 2 +- hw/ps2.c | 16 ++++------------ hw/ptimer.c | 4 ++-- hw/serial.c | 2 +- hw/slavio_intctl.c | 2 +- hw/tcx.c | 2 +- hw/vmmouse.c | 2 +- savevm.c | 48 ++++++++++++++++++++++++------------------------ 16 files changed, 57 insertions(+), 53 deletions(-)
PATCH v2 1/4 vmstate: remove const for put operations
In a later patch, we introduce pre_save() and post_save() functions. The whole point of that operation is to change things in the state. Without this patch, we have to remove the const qualifier in each use with a cast
--- hw/hw.h | 4 ++-- hw/pci.c | 2 +- hw/ptimer.c | 4 ++-- savevm.c | 46 +++++++++++++++++++++++----------------------- 4 files changed, 28 insertions(+), 28 deletions(-)
hw/hw.h +2 -2
@@ -276,7 +276,7 @@ typedef struct VMStateDescription VMStateDescription;struct VMStateInfo {const char *name;int (*get)(QEMUFile *f,void *pv,size_t size); -void (*put)(QEMUFile *f,const void *pv,size_t size); +void (*put)(QEMUFile *f,void *pv,size_t size); };enum VMStateFlags {
@@ -534,7 +534,7 @@ extern const VMStateDescription vmstate_pci_device;extern int vmstate_load_state (QEMUFile *f,const VMStateDescription *vmsd,void *opaque,int version_id);extern void vmstate_save_state (QEMUFile *f,const VMStateDescription *vmsd, -const void *opaque); +void *opaque);extern int vmstate_register (int instance_id,const VMStateDescription *vmsd,void *base);void vmstate_unregister (const VMStateDescription *vmsd,void *opaque);
hw/pci.c +1 -1
@@ -156,7 +156,7 @@ static int get_pci_config_device(QEMUFile *f, void *pv, size_t size) }/* just put buffer */ -static void put_pci_config_device (QEMUFile *f,const void *pv,size_t size) +static void put_pci_config_device (QEMUFile *f,void *pv,size_t size) {const uint8_t *v = pv;qemu_put_buffer (f, v, size);
hw/ptimer.c +2 -2
@@ -220,9 +220,9 @@ static int get_ptimer(QEMUFile *f, void *pv, size_t size)return 0 ; } -static void put_ptimer (QEMUFile *f,const void *pv,size_t size) +static void put_ptimer (QEMUFile *f,void *pv,size_t size) { -ptimer_state *v = (void *)pv; +ptimer_state *v = pv;qemu_put_ptimer (f, v); }
savevm.c +23 -23
134 lines not on this page · raw message
Signature · 1 line
1.6.2.5
PATCH v2 2/4 vmstate: add version_id argument to post_load
In reply to Juan Quintela--- exec.c | 2 +- hw/acpi.c | 2 +- hw/cirrus_vga.c | 2 +- hw/dma.c | 2 +- hw/fdc.c | 2 +- hw/hpet.c | 2 +- hw/hw.h | 2 +- hw/piix_pci.c | 2 +- hw/serial.c | 2 +- hw/slavio_intctl.c | 2 +- hw/tcx.c | 2 +- hw/vmmouse.c | 2 +- savevm.c | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-)
exec.c +1 -1
@@ -528,7 +528,7 @@ static int cpu_common_pre_load(void *opaque)return 0 ; } -static int cpu_common_post_load (void *opaque) +static int cpu_common_post_load (void *opaque,int version_id) {CPUState *env = opaque;
hw/acpi.c +1 -1
@@ -441,7 +441,7 @@ static void pm_write_config(PCIDevice *d,pm_io_space_update ((PIIX4PMState *)d); } -static int vmstate_acpi_post_load (void *opaque) +static int vmstate_acpi_post_load (void *opaque,int version_id) {PIIX4PMState *s = opaque;
hw/cirrus_vga.c +1 -1
@@ -2955,7 +2955,7 @@ static CPUWriteMemoryFunc * const cirrus_mmio_write[3] = {/* load/save state */ -static int cirrus_post_load (void *opaque) +static int cirrus_post_load (void *opaque,int version_id) {CirrusVGAState *s = opaque;
hw/dma.c +1 -1
@@ -517,7 +517,7 @@ static const VMStateDescription vmstate_dma_regs = { } }; -static int dma_post_load (void *opaque) +static int dma_post_load (void *opaque,int version_id) {DMA_run ();
hw/fdc.c +1 -1
@@ -650,7 +650,7 @@ static void fdc_pre_save(const void *opaque) s->dor_vmstate = s->dor |GET_CUR_DRV (s); } -static int fdc_post_load (void *opaque) +static int fdc_post_load (void *opaque,int version_id) {fdctrl_t *s = opaque;
hw/hpet.c +1 -1
@@ -164,7 +164,7 @@ static void hpet_pre_save(const void *opaque) s->hpet_counter =hpet_get_ticks (); } -static int hpet_post_load (void *opaque) +static int hpet_post_load (void *opaque,int version_id) {HPETState *s = opaque;
hw/hw.h +1 -1
@@ -307,7 +307,7 @@ struct VMStateDescription {int minimum_version_id_old;LoadStateHandler *load_state_old;int (*pre_load)(void *opaque); -int (*post_load)(void *opaque); +int (*post_load)(void *opaque,int version_id);void (*pre_save)(const void *opaque);void (*post_save)(const void *opaque);VMStateField *fields;
hw/piix_pci.c +1 -1
@@ -172,7 +172,7 @@ static int i440fx_load_old(QEMUFile* f, void *opaque, int version_id)return 0 ; } -static int i440fx_post_load (void *opaque) +static int i440fx_post_load (void *opaque,int version_id) {PCII440FXState *d = opaque;
hw/serial.c +1 -1
@@ -650,7 +650,7 @@ static int serial_pre_load(void *opaque)return 0 ; } -static int serial_post_load (void *opaque) +static int serial_post_load (void *opaque,int version_id) {SerialState *s = opaque;
hw/slavio_intctl.c +1 -1
@@ -374,7 +374,7 @@ static void slavio_set_irq_all(void *opaque, int irq, int level) } } -static int vmstate_intctl_post_load (void *opaque) +static int vmstate_intctl_post_load (void *opaque,int version_id) {SLAVIO_INTCTLState *s = opaque;
hw/tcx.c +1 -1
@@ -378,7 +378,7 @@ static void tcx24_invalidate_display(void *opaque)qemu_console_resize (s->ds, s->width, s->height); } -static int vmstate_tcx_post_load (void *opaque) +static int vmstate_tcx_post_load (void *opaque,int version_id) {TCXState *s = opaque;
hw/vmmouse.c +1 -1
@@ -235,7 +235,7 @@ static uint32_t vmmouse_ioport_read(void *opaque, uint32_t addr)return data[0 ]; } -static int vmmouse_post_load (void *opaque) +static int vmmouse_post_load (void *opaque,int version_id) {VMMouseState *s = opaque;
savevm.c +1 -1
@@ -1084,7 +1084,7 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, field++; }if (vmsd->post_load) { -return vmsd->post_load (opaque); +return vmsd->post_load (opaque, version_id); }return 0 ; }
Signature · 1 line
1.6.2.5
PATCH v2 3/4 vmstate: remove ps2_kbd_load_old()
In reply to Juan QuintelaNow that we have version_id on post_load() we don't need the old load function
--- hw/ps2.c | 16 ++++------------ 1 files changed, 4 insertions(+), 12 deletions(-)
hw/ps2.c +4 -12
@@ -541,19 +541,11 @@ static const VMStateDescription vmstate_ps2_common = { } }; -static int ps2_kbd_load_old (QEMUFile * f,void * opaque,int version_id) +static int ps2_kbd_post_load (void * opaque,int version_id) {PS2KbdState *s = (PS2KbdState *)opaque; -if (version_id !=2 && version_id !=3 ) -return -EINVAL ; - -vmstate_load_state (f, &vmstate_ps2_common, &s->common, version_id); - s->scan_enabled=qemu_get_be32 (f); - s->translate=qemu_get_be32 (f); -if (version_id ==3 ) - s->scancode_set=qemu_get_be32 (f); -else +if (version_id ==2 ) s->scancode_set=2 ;return 0 ; }
@@ -561,9 +553,9 @@ static int ps2_kbd_load_old(QEMUFile* f, void* opaque, int version_id)static const VMStateDescription vmstate_ps2_keyboard = { .name ="ps2kbd" , .version_id =3 , - .minimum_version_id =3 , + .minimum_version_id =2 , .minimum_version_id_old =2 , - .load_state_old = ps2_kbd_load_old, + .post_load = ps2_kbd_post_load, .fields = (VMStateField []) {VMSTATE_STRUCT (common, PS2KbdState,0 , vmstate_ps2_common, PS2State),VMSTATE_INT32 (scan_enabled, PS2KbdState),
Signature · 1 line
1.6.2.5
PATCH v2 4/4 vmstate: Add support for sending partial arrays
In reply to Juan QuintelaThis one is needed for changees happening on fdc. It allows you to send arrays of structs whose size we want to send it is another field with type uint8_t. (If you have been able to read the whole sentence without stoping for breathing, you can use it.
--- hw/hw.h | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-)
hw/hw.h +12 -0
@@ -398,6 +398,18 @@ extern const VMStateInfo vmstate_info_buffer; + type_check_array(_type,typeof_field(_state, _field),_num) \ } +#define VMSTATE_STRUCT_ARRAY_SIZE_UINT8 (_field, _state, _field__num, _version, _vmsd, _type) { \ + .name = (stringify(_field)), \ + .num_offset = offsetof(_state, _field_num) \ + + type_check(uint8_t,typeof_field(_state, _field_num)), \ + .version_id = (_version), \ + .vmsd = &(_vmsd), \ + .size = sizeof(_type), \ + .flags = VMS_STRUCT|VMS_ARRAY, \ + .offset = offsetof(_state, _field) \ + + type_check_array(_type,typeof_field(_state, _field),_num) \ +} +#define VMSTATE_STATIC_BUFFER (_field, _state, _version) { \ .name = (stringify(_field)), \ .version_id = (_version), \
Signature · 1 line
1.6.2.5