vmstate: Add suppot for field_exist() test
Signed-off-by: Juan Quintela <quintela@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
3c8ce630c5
commit
f11f6a5fff
26
hw/hw.h
26
hw/hw.h
@ -10,6 +10,7 @@
|
||||
#include "cpu-common.h"
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "ioport.h"
|
||||
#include "irq.h"
|
||||
|
||||
@ -299,6 +300,7 @@ typedef struct {
|
||||
enum VMStateFlags flags;
|
||||
const VMStateDescription *vmsd;
|
||||
int version_id;
|
||||
bool (*field_exists)(void *opaque, int version_id);
|
||||
} VMStateField;
|
||||
|
||||
struct VMStateDescription {
|
||||
@ -345,6 +347,16 @@ extern const VMStateInfo vmstate_info_buffer;
|
||||
+ type_check(_type,typeof_field(_state, _field)) \
|
||||
}
|
||||
|
||||
#define VMSTATE_SINGLE_TEST(_field, _state, _test, _info, _type) { \
|
||||
.name = (stringify(_field)), \
|
||||
.field_exists = (_test), \
|
||||
.size = sizeof(_type), \
|
||||
.info = &(_info), \
|
||||
.flags = VMS_SINGLE, \
|
||||
.offset = offsetof(_state, _field) \
|
||||
+ type_check(_type,typeof_field(_state, _field)) \
|
||||
}
|
||||
|
||||
#define VMSTATE_POINTER(_field, _state, _version, _info, _type) { \
|
||||
.name = (stringify(_field)), \
|
||||
.version_id = (_version), \
|
||||
@ -366,6 +378,17 @@ extern const VMStateInfo vmstate_info_buffer;
|
||||
+ type_check_array(_type,typeof_field(_state, _field),_num) \
|
||||
}
|
||||
|
||||
#define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\
|
||||
.name = (stringify(_field)), \
|
||||
.field_exists = (_test), \
|
||||
.num = (_num), \
|
||||
.info = &(_info), \
|
||||
.size = sizeof(_type), \
|
||||
.flags = VMS_ARRAY, \
|
||||
.offset = offsetof(_state, _field) \
|
||||
+ type_check_array(_type,typeof_field(_state, _field),_num) \
|
||||
}
|
||||
|
||||
#define VMSTATE_VARRAY(_field, _state, _field_num, _version, _info, _type) {\
|
||||
.name = (stringify(_field)), \
|
||||
.version_id = (_version), \
|
||||
@ -524,6 +547,9 @@ extern const VMStateDescription vmstate_i2c_slave;
|
||||
#define VMSTATE_INT32_LE(_f, _s) \
|
||||
VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)
|
||||
|
||||
#define VMSTATE_UINT32_TEST(_f, _s, _t) \
|
||||
VMSTATE_SINGLE_TEST(_f, _s, _t, vmstate_info_uint32, uint32_t)
|
||||
|
||||
#define VMSTATE_TIMER_V(_f, _s, _v) \
|
||||
VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *)
|
||||
|
||||
|
40
savevm.c
40
savevm.c
@ -1055,7 +1055,10 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
|
||||
return ret;
|
||||
}
|
||||
while(field->name) {
|
||||
if (field->version_id <= version_id) {
|
||||
if ((field->field_exists &&
|
||||
field->field_exists(opaque, version_id)) ||
|
||||
(!field->field_exists &&
|
||||
field->version_id <= version_id)) {
|
||||
void *base_addr = opaque + field->offset;
|
||||
int ret, i, n_elems = 1;
|
||||
|
||||
@ -1101,24 +1104,27 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
|
||||
vmsd->pre_save(opaque);
|
||||
}
|
||||
while(field->name) {
|
||||
void *base_addr = opaque + field->offset;
|
||||
int i, n_elems = 1;
|
||||
if (!field->field_exists ||
|
||||
field->field_exists(opaque, vmsd->version_id)) {
|
||||
void *base_addr = opaque + field->offset;
|
||||
int i, n_elems = 1;
|
||||
|
||||
if (field->flags & VMS_ARRAY) {
|
||||
n_elems = field->num;
|
||||
} else if (field->flags & VMS_VARRAY) {
|
||||
n_elems = *(size_t *)(opaque+field->num_offset);
|
||||
}
|
||||
if (field->flags & VMS_POINTER) {
|
||||
base_addr = *(void **)base_addr;
|
||||
}
|
||||
for (i = 0; i < n_elems; i++) {
|
||||
void *addr = base_addr + field->size * i;
|
||||
if (field->flags & VMS_ARRAY) {
|
||||
n_elems = field->num;
|
||||
} else if (field->flags & VMS_VARRAY) {
|
||||
n_elems = *(size_t *)(opaque+field->num_offset);
|
||||
}
|
||||
if (field->flags & VMS_POINTER) {
|
||||
base_addr = *(void **)base_addr;
|
||||
}
|
||||
for (i = 0; i < n_elems; i++) {
|
||||
void *addr = base_addr + field->size * i;
|
||||
|
||||
if (field->flags & VMS_STRUCT) {
|
||||
vmstate_save_state(f, field->vmsd, addr);
|
||||
} else {
|
||||
field->info->put(f, addr, field->size);
|
||||
if (field->flags & VMS_STRUCT) {
|
||||
vmstate_save_state(f, field->vmsd, addr);
|
||||
} else {
|
||||
field->info->put(f, addr, field->size);
|
||||
}
|
||||
}
|
||||
}
|
||||
field++;
|
||||
|
Loading…
Reference in New Issue
Block a user