thebeanogamer / rpms / qemu-kvm

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