thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
958e1b
From 0aa1a1886452bb26cc60ac482f70d0ef78b85165 Mon Sep 17 00:00:00 2001
eb5a2f
From: Michael S. Tsirkin <mst@redhat.com>
958e1b
Date: Wed, 14 May 2014 08:52:47 +0200
958e1b
Subject: [PATCH 21/31] vmstate: add VMS_MUST_EXIST
eb5a2f
eb5a2f
RH-Author: Michael S. Tsirkin <mst@redhat.com>
958e1b
Message-id: <1400057538-6975-3-git-send-email-mst@redhat.com>
958e1b
Patchwork-id: 58869
958e1b
O-Subject: [PATCH qemu-kvm RHEL7.1 2/5] vmstate: add VMS_MUST_EXIST
958e1b
Bugzilla: 1095716
eb5a2f
RH-Acked-by: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
eb5a2f
RH-Acked-by: Marcel Apfelbaum <marcel.a@redhat.com>
eb5a2f
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
eb5a2f
RH-Acked-by: Juan Quintela <quintela@redhat.com>
eb5a2f
eb5a2f
Can be used to verify a required field exists or validate
eb5a2f
state in some other way.
eb5a2f
eb5a2f
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
eb5a2f
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
eb5a2f
Signed-off-by: Juan Quintela <quintela@redhat.com>
eb5a2f
(cherry picked from commit 5bf81c8d63db0216a4d29dc87f9ce530bb791dd1)
eb5a2f
---
eb5a2f
 include/migration/vmstate.h |  1 +
eb5a2f
 savevm.c                    | 10 ++++++++++
eb5a2f
 2 files changed, 11 insertions(+)
eb5a2f
eb5a2f
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
eb5a2f
---
eb5a2f
 include/migration/vmstate.h |    1 +
eb5a2f
 savevm.c                    |   10 ++++++++++
eb5a2f
 2 files changed, 11 insertions(+), 0 deletions(-)
eb5a2f
eb5a2f
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
eb5a2f
index 11d93e1..95d1ce6 100644
eb5a2f
--- a/include/migration/vmstate.h
eb5a2f
+++ b/include/migration/vmstate.h
eb5a2f
@@ -98,6 +98,7 @@ enum VMStateFlags {
eb5a2f
     VMS_MULTIPLY         = 0x200,  /* multiply "size" field by field_size */
eb5a2f
     VMS_VARRAY_UINT8     = 0x400,  /* Array with size in uint8_t field*/
eb5a2f
     VMS_VARRAY_UINT32    = 0x800,  /* Array with size in uint32_t field*/
eb5a2f
+    VMS_MUST_EXIST       = 0x1000, /* Field must exist in input */
eb5a2f
 };
eb5a2f
 
eb5a2f
 typedef struct {
eb5a2f
diff --git a/savevm.c b/savevm.c
958e1b
index 707caac..94512dd 100644
eb5a2f
--- a/savevm.c
eb5a2f
+++ b/savevm.c
958e1b
@@ -1764,6 +1764,10 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
eb5a2f
                     return ret;
eb5a2f
                 }
eb5a2f
             }
eb5a2f
+        } else if (field->flags & VMS_MUST_EXIST) {
eb5a2f
+            fprintf(stderr, "Input validation failed: %s/%s\n",
eb5a2f
+                    vmsd->name, field->name);
eb5a2f
+            return -1;
eb5a2f
         }
eb5a2f
         field++;
eb5a2f
     }
958e1b
@@ -1804,6 +1808,12 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
eb5a2f
                     field->info->put(f, addr, size);
eb5a2f
                 }
eb5a2f
             }
eb5a2f
+        } else {
eb5a2f
+            if (field->flags & VMS_MUST_EXIST) {
eb5a2f
+                fprintf(stderr, "Output state validation failed: %s/%s\n",
eb5a2f
+                        vmsd->name, field->name);
eb5a2f
+                assert(!(field->flags & VMS_MUST_EXIST));
eb5a2f
+            }
eb5a2f
         }
eb5a2f
         field++;
eb5a2f
     }
eb5a2f
-- 
eb5a2f
1.7.1
eb5a2f