|
|
9ae3a8 |
From 2bf018e4c436e31188ea61fb767dbcec16495cfd Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Michael S. Tsirkin <mst@redhat.com>
|
|
|
9ae3a8 |
Date: Wed, 14 May 2014 08:52:43 +0200
|
|
|
9ae3a8 |
Subject: [PATCH 20/31] vmstate: reduce code duplication
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Michael S. Tsirkin <mst@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1400057538-6975-2-git-send-email-mst@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 58868
|
|
|
9ae3a8 |
O-Subject: [PATCH qemu-kvm RHEL7.1 1/5] vmstate: reduce code duplication
|
|
|
9ae3a8 |
Bugzilla: 1095716
|
|
|
9ae3a8 |
RH-Acked-by: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Marcel Apfelbaum <marcel.a@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Juan Quintela <quintela@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
move size offset and number of elements math out
|
|
|
9ae3a8 |
to functions, to reduce code duplication.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
|
|
|
9ae3a8 |
Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Juan Quintela <quintela@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit 35fc1f71899fd42323bd8f33da18f0211e0d2727)
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
savevm.c | 100 +++++++++++++++++++++++++++++++++------------------------------
|
|
|
9ae3a8 |
1 file changed, 52 insertions(+), 48 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
savevm.c | 100 ++++++++++++++++++++++++++++++++-----------------------------
|
|
|
9ae3a8 |
1 files changed, 52 insertions(+), 48 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/savevm.c b/savevm.c
|
|
|
9ae3a8 |
index 6efbb75..707caac 100644
|
|
|
9ae3a8 |
--- a/savevm.c
|
|
|
9ae3a8 |
+++ b/savevm.c
|
|
|
9ae3a8 |
@@ -1675,6 +1675,50 @@ static void vmstate_subsection_save(QEMUFile *f, const VMStateDescription *vmsd,
|
|
|
9ae3a8 |
static int vmstate_subsection_load(QEMUFile *f, const VMStateDescription *vmsd,
|
|
|
9ae3a8 |
void *opaque);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+static int vmstate_n_elems(void *opaque, VMStateField *field)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ int n_elems = 1;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (field->flags & VMS_ARRAY) {
|
|
|
9ae3a8 |
+ n_elems = field->num;
|
|
|
9ae3a8 |
+ } else if (field->flags & VMS_VARRAY_INT32) {
|
|
|
9ae3a8 |
+ n_elems = *(int32_t *)(opaque+field->num_offset);
|
|
|
9ae3a8 |
+ } else if (field->flags & VMS_VARRAY_UINT32) {
|
|
|
9ae3a8 |
+ n_elems = *(uint32_t *)(opaque+field->num_offset);
|
|
|
9ae3a8 |
+ } else if (field->flags & VMS_VARRAY_UINT16) {
|
|
|
9ae3a8 |
+ n_elems = *(uint16_t *)(opaque+field->num_offset);
|
|
|
9ae3a8 |
+ } else if (field->flags & VMS_VARRAY_UINT8) {
|
|
|
9ae3a8 |
+ n_elems = *(uint8_t *)(opaque+field->num_offset);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ return n_elems;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static int vmstate_size(void *opaque, VMStateField *field)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ int size = field->size;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (field->flags & VMS_VBUFFER) {
|
|
|
9ae3a8 |
+ size = *(int32_t *)(opaque+field->size_offset);
|
|
|
9ae3a8 |
+ if (field->flags & VMS_MULTIPLY) {
|
|
|
9ae3a8 |
+ size *= field->size;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ return size;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void *vmstate_base_addr(void *opaque, VMStateField *field)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ void *base_addr = opaque + field->offset;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (field->flags & VMS_POINTER) {
|
|
|
9ae3a8 |
+ base_addr = *(void **)base_addr + field->start;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ return base_addr;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
|
|
|
9ae3a8 |
void *opaque, int version_id)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
@@ -1700,30 +1744,10 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
|
|
|
9ae3a8 |
field->field_exists(opaque, version_id)) ||
|
|
|
9ae3a8 |
(!field->field_exists &&
|
|
|
9ae3a8 |
field->version_id <= version_id)) {
|
|
|
9ae3a8 |
- void *base_addr = opaque + field->offset;
|
|
|
9ae3a8 |
- int i, n_elems = 1;
|
|
|
9ae3a8 |
- int size = field->size;
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- if (field->flags & VMS_VBUFFER) {
|
|
|
9ae3a8 |
- size = *(int32_t *)(opaque+field->size_offset);
|
|
|
9ae3a8 |
- if (field->flags & VMS_MULTIPLY) {
|
|
|
9ae3a8 |
- size *= field->size;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- if (field->flags & VMS_ARRAY) {
|
|
|
9ae3a8 |
- n_elems = field->num;
|
|
|
9ae3a8 |
- } else if (field->flags & VMS_VARRAY_INT32) {
|
|
|
9ae3a8 |
- n_elems = *(int32_t *)(opaque+field->num_offset);
|
|
|
9ae3a8 |
- } else if (field->flags & VMS_VARRAY_UINT32) {
|
|
|
9ae3a8 |
- n_elems = *(uint32_t *)(opaque+field->num_offset);
|
|
|
9ae3a8 |
- } else if (field->flags & VMS_VARRAY_UINT16) {
|
|
|
9ae3a8 |
- n_elems = *(uint16_t *)(opaque+field->num_offset);
|
|
|
9ae3a8 |
- } else if (field->flags & VMS_VARRAY_UINT8) {
|
|
|
9ae3a8 |
- n_elems = *(uint8_t *)(opaque+field->num_offset);
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- if (field->flags & VMS_POINTER) {
|
|
|
9ae3a8 |
- base_addr = *(void **)base_addr + field->start;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
+ void *base_addr = vmstate_base_addr(opaque, field);
|
|
|
9ae3a8 |
+ int i, n_elems = vmstate_n_elems(opaque, field);
|
|
|
9ae3a8 |
+ int size = vmstate_size(opaque, field);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
for (i = 0; i < n_elems; i++) {
|
|
|
9ae3a8 |
void *addr = base_addr + size * i;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -1764,30 +1788,10 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
|
|
|
9ae3a8 |
while(field->name) {
|
|
|
9ae3a8 |
if (!field->field_exists ||
|
|
|
9ae3a8 |
field->field_exists(opaque, vmsd->version_id)) {
|
|
|
9ae3a8 |
- void *base_addr = opaque + field->offset;
|
|
|
9ae3a8 |
- int i, n_elems = 1;
|
|
|
9ae3a8 |
- int size = field->size;
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- if (field->flags & VMS_VBUFFER) {
|
|
|
9ae3a8 |
- size = *(int32_t *)(opaque+field->size_offset);
|
|
|
9ae3a8 |
- if (field->flags & VMS_MULTIPLY) {
|
|
|
9ae3a8 |
- size *= field->size;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- if (field->flags & VMS_ARRAY) {
|
|
|
9ae3a8 |
- n_elems = field->num;
|
|
|
9ae3a8 |
- } else if (field->flags & VMS_VARRAY_INT32) {
|
|
|
9ae3a8 |
- n_elems = *(int32_t *)(opaque+field->num_offset);
|
|
|
9ae3a8 |
- } else if (field->flags & VMS_VARRAY_UINT32) {
|
|
|
9ae3a8 |
- n_elems = *(uint32_t *)(opaque+field->num_offset);
|
|
|
9ae3a8 |
- } else if (field->flags & VMS_VARRAY_UINT16) {
|
|
|
9ae3a8 |
- n_elems = *(uint16_t *)(opaque+field->num_offset);
|
|
|
9ae3a8 |
- } else if (field->flags & VMS_VARRAY_UINT8) {
|
|
|
9ae3a8 |
- n_elems = *(uint8_t *)(opaque+field->num_offset);
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- if (field->flags & VMS_POINTER) {
|
|
|
9ae3a8 |
- base_addr = *(void **)base_addr + field->start;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
+ void *base_addr = vmstate_base_addr(opaque, field);
|
|
|
9ae3a8 |
+ int i, n_elems = vmstate_n_elems(opaque, field);
|
|
|
9ae3a8 |
+ int size = vmstate_size(opaque, field);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
for (i = 0; i < n_elems; i++) {
|
|
|
9ae3a8 |
void *addr = base_addr + size * i;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.7.1
|
|
|
9ae3a8 |
|