Add VMState support for arrays
This patch adds support for saving arrays inside the struct Signed-off-by: Juan Quintela <quintela@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
dde0463b4e
commit
f752a6aae7
28
hw/hw.h
28
hw/hw.h
@ -282,12 +282,14 @@ struct VMStateInfo {
|
|||||||
enum VMStateFlags {
|
enum VMStateFlags {
|
||||||
VMS_SINGLE = 0x001,
|
VMS_SINGLE = 0x001,
|
||||||
VMS_POINTER = 0x002,
|
VMS_POINTER = 0x002,
|
||||||
|
VMS_ARRAY = 0x004,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *name;
|
const char *name;
|
||||||
size_t offset;
|
size_t offset;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
int num;
|
||||||
const VMStateInfo *info;
|
const VMStateInfo *info;
|
||||||
enum VMStateFlags flags;
|
enum VMStateFlags flags;
|
||||||
int version_id;
|
int version_id;
|
||||||
@ -314,6 +316,8 @@ extern const VMStateInfo vmstate_info_uint64;
|
|||||||
|
|
||||||
extern const VMStateInfo vmstate_info_timer;
|
extern const VMStateInfo vmstate_info_timer;
|
||||||
|
|
||||||
|
#define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
|
||||||
|
|
||||||
#define VMSTATE_SINGLE(_field, _state, _version, _info, _type) { \
|
#define VMSTATE_SINGLE(_field, _state, _version, _info, _type) { \
|
||||||
.name = (stringify(_field)), \
|
.name = (stringify(_field)), \
|
||||||
.version_id = (_version), \
|
.version_id = (_version), \
|
||||||
@ -334,7 +338,19 @@ extern const VMStateInfo vmstate_info_timer;
|
|||||||
+ type_check(_type,typeof_field(_state, _field)) \
|
+ type_check(_type,typeof_field(_state, _field)) \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define VMSTATE_ARRAY(_field, _state, _num, _version, _info, _type) {\
|
||||||
|
.name = (stringify(_field)), \
|
||||||
|
.version_id = (_version), \
|
||||||
|
.num = (_num), \
|
||||||
|
.info = &(_info), \
|
||||||
|
.size = sizeof(_type), \
|
||||||
|
.flags = VMS_ARRAY, \
|
||||||
|
.offset = offsetof(_state, _field) \
|
||||||
|
+ type_check_array(_type,typeof_field(_state, _field),_num) \
|
||||||
|
}
|
||||||
|
|
||||||
/* _f : field name
|
/* _f : field name
|
||||||
|
_n : num of elements
|
||||||
_s : struct state name
|
_s : struct state name
|
||||||
_v : version
|
_v : version
|
||||||
*/
|
*/
|
||||||
@ -381,6 +397,18 @@ extern const VMStateInfo vmstate_info_timer;
|
|||||||
#define VMSTATE_TIMER(_f, _s) \
|
#define VMSTATE_TIMER(_f, _s) \
|
||||||
VMSTATE_TIMER_V(_f, _s, 0)
|
VMSTATE_TIMER_V(_f, _s, 0)
|
||||||
|
|
||||||
|
#define VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v) \
|
||||||
|
VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint32, uint32_t)
|
||||||
|
|
||||||
|
#define VMSTATE_UINT32_ARRAY(_f, _s, _n) \
|
||||||
|
VMSTATE_UINT32_ARRAY_V(_f, _s, _n, 0)
|
||||||
|
|
||||||
|
#define VMSTATE_INT32_ARRAY_V(_f, _s, _n, _v) \
|
||||||
|
VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_int32, int32_t)
|
||||||
|
|
||||||
|
#define VMSTATE_INT32_ARRAY(_f, _s, _n) \
|
||||||
|
VMSTATE_INT32_ARRAY_V(_f, _s, _n, 0)
|
||||||
|
|
||||||
#define VMSTATE_END_OF_LIST() \
|
#define VMSTATE_END_OF_LIST() \
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
27
savevm.c
27
savevm.c
@ -972,17 +972,23 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
|
|||||||
}
|
}
|
||||||
while(field->name) {
|
while(field->name) {
|
||||||
if (field->version_id <= version_id) {
|
if (field->version_id <= version_id) {
|
||||||
void *addr = opaque + field->offset;
|
void *base_addr = opaque + field->offset;
|
||||||
int ret;
|
int ret, i, n_elems = 1;
|
||||||
|
|
||||||
if (field->flags & VMS_POINTER) {
|
if (field->flags & VMS_ARRAY) {
|
||||||
addr = *(void **)addr;
|
n_elems = field->num;
|
||||||
}
|
}
|
||||||
|
if (field->flags & VMS_POINTER) {
|
||||||
|
base_addr = *(void **)base_addr;
|
||||||
|
}
|
||||||
|
for (i = 0; i < n_elems; i++) {
|
||||||
|
void *addr = base_addr + field->size * i;
|
||||||
ret = field->info->get(f, addr, field->size);
|
ret = field->info->get(f, addr, field->size);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
field++;
|
field++;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -994,12 +1000,19 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
|
|||||||
VMStateField *field = vmsd->fields;
|
VMStateField *field = vmsd->fields;
|
||||||
|
|
||||||
while(field->name) {
|
while(field->name) {
|
||||||
const void *addr = opaque + field->offset;
|
const void *base_addr = opaque + field->offset;
|
||||||
|
int i, n_elems = 1;
|
||||||
|
|
||||||
if (field->flags & VMS_POINTER) {
|
if (field->flags & VMS_ARRAY) {
|
||||||
addr = *(void **)addr;
|
n_elems = field->num;
|
||||||
}
|
}
|
||||||
|
if (field->flags & VMS_POINTER) {
|
||||||
|
base_addr = *(void **)base_addr;
|
||||||
|
}
|
||||||
|
for (i = 0; i < n_elems; i++) {
|
||||||
|
const void *addr = base_addr + field->size * i;
|
||||||
field->info->put(f, addr, field->size);
|
field->info->put(f, addr, field->size);
|
||||||
|
}
|
||||||
field++;
|
field++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user