qemu-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-commits] [COMMIT ec245e2] Add VMState support for structs


From: Anthony Liguori
Subject: [Qemu-commits] [COMMIT ec245e2] Add VMState support for structs
Date: Fri, 28 Aug 2009 02:19:57 -0000

From: Juan Quintela <address@hidden>

This patch adds support for saving one VMStateDescription from other
VMStateDescription.

Signed-off-by: Juan Quintela <address@hidden>
Signed-off-by: Anthony Liguori <address@hidden>

diff --git a/hw/hw.h b/hw/hw.h
index a8534fa..2ee307e 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -283,6 +283,7 @@ enum VMStateFlags {
     VMS_SINGLE  = 0x001,
     VMS_POINTER = 0x002,
     VMS_ARRAY   = 0x004,
+    VMS_STRUCT  = 0x008,
 };
 
 typedef struct {
@@ -292,6 +293,7 @@ typedef struct {
     int num;
     const VMStateInfo *info;
     enum VMStateFlags flags;
+    const VMStateDescription *vmsd;
     int version_id;
 } VMStateField;
 
@@ -349,6 +351,16 @@ extern const VMStateInfo vmstate_info_timer;
         + type_check_array(_type,typeof_field(_state, _field),_num)  \
 }
 
+#define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type) {     \
+    .name       = (stringify(_field)),                               \
+    .version_id = (_version),                                        \
+    .vmsd       = &(_vmsd),                                          \
+    .size       = sizeof(_type),                                     \
+    .flags      = VMS_STRUCT,                                        \
+    .offset     = offsetof(_state, _field)                           \
+            + type_check(_type,typeof_field(_state, _field))         \
+}
+
 /* _f : field name
    _n : num of elements
    _s : struct state name
diff --git a/savevm.c b/savevm.c
index 7bcb783..71ec4ca 100644
--- a/savevm.c
+++ b/savevm.c
@@ -983,7 +983,13 @@ int vmstate_load_state(QEMUFile *f, const 
VMStateDescription *vmsd,
             }
             for (i = 0; i < n_elems; i++) {
                 void *addr = base_addr + field->size * i;
-                ret = field->info->get(f, addr, field->size);
+
+                if (field->flags & VMS_STRUCT) {
+                    ret = vmstate_load_state(f, field->vmsd, addr, version_id);
+                } else {
+                    ret = field->info->get(f, addr, field->size);
+
+                }
                 if (ret < 0) {
                     return ret;
                 }
@@ -1011,7 +1017,12 @@ void vmstate_save_state(QEMUFile *f, const 
VMStateDescription *vmsd,
         }
         for (i = 0; i < n_elems; i++) {
             const void *addr = base_addr + field->size * i;
-            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++;
     }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]