Add VMState support for int32_t check value
We read the saved value and check that it is the same that the one
is stored in the structure.
Signed-off-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
diff --git a/hw/hw.h b/hw/hw.h
index 98afd22..ba81230 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -311,6 +311,8 @@
extern const VMStateInfo vmstate_info_int32;
extern const VMStateInfo vmstate_info_int64;
+extern const VMStateInfo vmstate_info_int32_equal;
+
extern const VMStateInfo vmstate_info_uint8;
extern const VMStateInfo vmstate_info_uint16;
extern const VMStateInfo vmstate_info_uint32;
@@ -414,6 +416,9 @@
#define VMSTATE_UINT64(_f, _s) \
VMSTATE_UINT64_V(_f, _s, 0)
+#define VMSTATE_INT32_EQUAL(_f, _s) \
+ VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_equal, int32_t)
+
#define VMSTATE_TIMER_V(_f, _s, _v) \
VMSTATE_POINTER(_f, _s, _v, vmstate_info_timer, QEMUTimer *)
diff --git a/savevm.c b/savevm.c
index 71ec4ca..9df198c 100644
--- a/savevm.c
+++ b/savevm.c
@@ -702,6 +702,26 @@
.put = put_int32,
};
+/* 32 bit int. See that the received value is the same than the one
+ in the field */
+
+static int get_int32_equal(QEMUFile *f, void *pv, size_t size)
+{
+ int32_t *v = pv;
+ int32_t v2;
+ qemu_get_sbe32s(f, &v2);
+
+ if (*v == v2)
+ return 0;
+ return -EINVAL;
+}
+
+const VMStateInfo vmstate_info_int32_equal = {
+ .name = "int32 equal",
+ .get = get_int32_equal,
+ .put = put_int32,
+};
+
/* 64 bit int */
static int get_int64(QEMUFile *f, void *pv, size_t size)