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