Add VMState support for pointers
authorJuan Quintela <quintela@redhat.com>
Thu, 20 Aug 2009 17:42:26 +0000 (19:42 +0200)
committerAnthony Liguori <aliguori@us.ibm.com>
Fri, 28 Aug 2009 01:30:21 +0000 (20:30 -0500)
This patch adds support for saving pointers to values

Signed-off-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/hw.h
savevm.c

diff --git a/hw/hw.h b/hw/hw.h
index 659a3d619ec64dde2dc846bdb65cd21b95534b13..9a1ba18a861bd9eca69a038175d7279d9e36af8b 100644 (file)
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -281,6 +281,7 @@ struct VMStateInfo {
 
 enum VMStateFlags {
     VMS_SINGLE  = 0x001,
+    VMS_POINTER = 0x002,
 };
 
 typedef struct {
@@ -311,6 +312,8 @@ extern const VMStateInfo vmstate_info_uint16;
 extern const VMStateInfo vmstate_info_uint32;
 extern const VMStateInfo vmstate_info_uint64;
 
+extern const VMStateInfo vmstate_info_timer;
+
 #define VMSTATE_SINGLE(_field, _state, _version, _info, _type) {     \
     .name       = (stringify(_field)),                               \
     .version_id = (_version),                                        \
@@ -321,6 +324,16 @@ extern const VMStateInfo vmstate_info_uint64;
             + type_check(_type,typeof_field(_state, _field))         \
 }
 
+#define VMSTATE_POINTER(_field, _state, _version, _info, _type) {    \
+    .name       = (stringify(_field)),                               \
+    .version_id = (_version),                                        \
+    .info       = &(_info),                                          \
+    .size       = sizeof(_type),                                     \
+    .flags      = VMS_SINGLE|VMS_POINTER,                            \
+    .offset     = offsetof(_state, _field)                           \
+            + type_check(_type,typeof_field(_state, _field))         \
+}
+
 /* _f : field name
    _s : struct state name
    _v : version
@@ -362,6 +375,12 @@ extern const VMStateInfo vmstate_info_uint64;
 #define VMSTATE_UINT64(_f, _s)                                        \
     VMSTATE_UINT64_V(_f, _s, 0)
 
+#define VMSTATE_TIMER_V(_f, _s, _v)                                   \
+    VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *)
+
+#define VMSTATE_TIMER(_f, _s)                                         \
+    VMSTATE_TIMER_V(_f, _s, 0)
+
 #define VMSTATE_END_OF_LIST()                                         \
     {}
 
index 616637a39344501321c5835ace5a449c09b9251a..7e56a89531eab509543935ba2f73174ba5fc8351 100644 (file)
--- a/savevm.c
+++ b/savevm.c
@@ -807,6 +807,27 @@ const VMStateInfo vmstate_info_uint64 = {
     .put  = put_uint64,
 };
 
+/* timers  */
+
+static int get_timer(QEMUFile *f, void *pv, size_t size)
+{
+    QEMUTimer *v = pv;
+    qemu_get_timer(f, v);
+    return 0;
+}
+
+static void put_timer(QEMUFile *f, const void *pv, size_t size)
+{
+    QEMUTimer *v = (void *)pv;
+    qemu_put_timer(f, v);
+}
+
+const VMStateInfo vmstate_info_timer = {
+    .name = "timer",
+    .get  = get_timer,
+    .put  = put_timer,
+};
+
 typedef struct SaveStateEntry {
     char idstr[256];
     int instance_id;
@@ -954,6 +975,9 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
             void *addr = opaque + field->offset;
             int ret;
 
+            if (field->flags & VMS_POINTER) {
+                addr = *(void **)addr;
+            }
             ret = field->info->get(f, addr, field->size);
             if (ret < 0) {
                 return ret;
@@ -971,6 +995,10 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
 
     while(field->name) {
         const void *addr = opaque + field->offset;
+
+        if (field->flags & VMS_POINTER) {
+            addr = *(void **)addr;
+        }
         field->info->put(f, addr, field->size);
         field++;
     }