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"
 | 
					#include "cpu-common.h"
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <stdbool.h>
 | 
				
			||||||
#include "ioport.h"
 | 
					#include "ioport.h"
 | 
				
			||||||
#include "irq.h"
 | 
					#include "irq.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -299,6 +300,7 @@ typedef struct {
 | 
				
			|||||||
    enum VMStateFlags flags;
 | 
					    enum VMStateFlags flags;
 | 
				
			||||||
    const VMStateDescription *vmsd;
 | 
					    const VMStateDescription *vmsd;
 | 
				
			||||||
    int version_id;
 | 
					    int version_id;
 | 
				
			||||||
 | 
					    bool (*field_exists)(void *opaque, int version_id);
 | 
				
			||||||
} VMStateField;
 | 
					} VMStateField;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct VMStateDescription {
 | 
					struct VMStateDescription {
 | 
				
			||||||
@ -345,6 +347,16 @@ extern const VMStateInfo vmstate_info_buffer;
 | 
				
			|||||||
            + type_check(_type,typeof_field(_state, _field))         \
 | 
					            + 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) {    \
 | 
					#define VMSTATE_POINTER(_field, _state, _version, _info, _type) {    \
 | 
				
			||||||
    .name       = (stringify(_field)),                               \
 | 
					    .name       = (stringify(_field)),                               \
 | 
				
			||||||
    .version_id = (_version),                                        \
 | 
					    .version_id = (_version),                                        \
 | 
				
			||||||
@ -366,6 +378,17 @@ extern const VMStateInfo vmstate_info_buffer;
 | 
				
			|||||||
        + type_check_array(_type,typeof_field(_state, _field),_num)  \
 | 
					        + 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) {\
 | 
					#define VMSTATE_VARRAY(_field, _state, _field_num, _version, _info, _type) {\
 | 
				
			||||||
    .name       = (stringify(_field)),                               \
 | 
					    .name       = (stringify(_field)),                               \
 | 
				
			||||||
    .version_id = (_version),                                        \
 | 
					    .version_id = (_version),                                        \
 | 
				
			||||||
@ -524,6 +547,9 @@ extern const VMStateDescription vmstate_i2c_slave;
 | 
				
			|||||||
#define VMSTATE_INT32_LE(_f, _s)                                   \
 | 
					#define VMSTATE_INT32_LE(_f, _s)                                   \
 | 
				
			||||||
    VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)
 | 
					    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)                                   \
 | 
					#define VMSTATE_TIMER_V(_f, _s, _v)                                   \
 | 
				
			||||||
    VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *)
 | 
					    VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										8
									
								
								savevm.c
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								savevm.c
									
									
									
									
									
								
							@ -1055,7 +1055,10 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
 | 
				
			|||||||
            return ret;
 | 
					            return ret;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    while(field->name) {
 | 
					    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;
 | 
					            void *base_addr = opaque + field->offset;
 | 
				
			||||||
            int ret, i, n_elems = 1;
 | 
					            int ret, i, n_elems = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -1101,6 +1104,8 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
 | 
				
			|||||||
        vmsd->pre_save(opaque);
 | 
					        vmsd->pre_save(opaque);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    while(field->name) {
 | 
					    while(field->name) {
 | 
				
			||||||
 | 
					        if (!field->field_exists ||
 | 
				
			||||||
 | 
					            field->field_exists(opaque, vmsd->version_id)) {
 | 
				
			||||||
            void *base_addr = opaque + field->offset;
 | 
					            void *base_addr = opaque + field->offset;
 | 
				
			||||||
            int i, n_elems = 1;
 | 
					            int i, n_elems = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -1121,6 +1126,7 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
 | 
				
			|||||||
                    field->info->put(f, addr, field->size);
 | 
					                    field->info->put(f, addr, field->size);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        field++;
 | 
					        field++;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (vmsd->post_save) {
 | 
					    if (vmsd->post_save) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user