Patchwork [03/11] vmstate: for vmstate types that reuse the same field, make sure name is unique

login
register
mail settings
Submitter Anthony Liguori
Date March 23, 2011, 12:16 a.m.
Message ID <1300839376-22520-4-git-send-email-aliguori@us.ibm.com>
Download mbox | patch
Permalink /patch/87974/
State New
Headers show

Comments

Anthony Liguori - March 23, 2011, 12:16 a.m.
For a schema to work, we need to make sure that each field name is unique.  We
have a number of derivative types today that reuse the base name.  This patch
fixes this.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
 hw/hw.h |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)
Anthony Liguori - March 23, 2011, 2:29 a.m.
On 03/22/2011 07:16 PM, Anthony Liguori wrote:
> For a schema to work, we need to make sure that each field name is unique.  We
> have a number of derivative types today that reuse the base name.  This patch
> fixes this.
>
> Signed-off-by: Anthony Liguori<aliguori@us.ibm.com>
> ---
>   hw/hw.h |   16 +++++++++++++---
>   1 files changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/hw/hw.h b/hw/hw.h
> index 81bbd7a..9a9012f 100644
> --- a/hw/hw.h
> +++ b/hw/hw.h
> @@ -390,6 +390,16 @@ extern const VMStateInfo vmstate_info_unused_buffer;
>       .offset       = vmstate_offset_value(_state, _field, _type),     \
>   }
>
> +#define VMSTATE_SINGLE_TEST_HACK(_field, _state, _test, _version, _info, _type) { \
> +    .name         = (stringify(_field) "-hack"),                     \
> +    .version_id   = (_version),                                      \
> +    .field_exists = (_test),                                         \
> +    .size         = sizeof(_type),                                   \
> +    .info         =&(_info),                                        \
> +    .flags        = VMS_SINGLE,                                      \
> +    .offset       = vmstate_offset_value(_state, _field, _type),     \
> +}
> +
>   #define VMSTATE_POINTER(_field, _state, _version, _info, _type) {    \
>       .name       = (stringify(_field)),                               \
>       .version_id = (_version),                                        \
> @@ -419,7 +429,7 @@ extern const VMStateInfo vmstate_info_unused_buffer;
>   }
>
>   #define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\
> -    .name         = (stringify(_field)),                              \
> +    .name         = (stringify(_field) "-" stringify(_test)),         \
>       .field_exists = (_test),                                          \
>       .num          = (_num),                                           \
>       .info         =&(_info),                                         \
> @@ -429,7 +439,7 @@ extern const VMStateInfo vmstate_info_unused_buffer;
>   }
>
>   #define VMSTATE_SUB_ARRAY(_field, _state, _start, _num, _version, _info, _type) { \
> -    .name       = (stringify(_field)),                               \
> +    .name       = (stringify(_field) "[" stringify(_start) "]"),      \
>       .version_id = (_version),                                        \
>       .num        = (_num),                                            \
>       .info       =&(_info),                                          \
> @@ -621,7 +631,7 @@ extern const VMStateInfo vmstate_info_unused_buffer;
>   }
>
>   #define VMSTATE_UNUSED_BUFFER(_test, _version, _size) {              \
> -    .name         = "unused",                                        \
> +    .name         = "unused" stringify(__LINE__),                    \

Why this does generate a unique name, it does not generate a stable 
name.  We need to add a name argument to this macro and all its 
derivatives.  I'll update tomorrow.

If the test suite fails saying you added a new field labelled 
"unusedXXXX", this is why.

Regards,

Anthony Liguori

>       .field_exists = (_test),                                         \
>       .version_id   = (_version),                                      \
>       .size         = (_size),                                         \

Patch

diff --git a/hw/hw.h b/hw/hw.h
index 81bbd7a..9a9012f 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -390,6 +390,16 @@  extern const VMStateInfo vmstate_info_unused_buffer;
     .offset       = vmstate_offset_value(_state, _field, _type),     \
 }
 
+#define VMSTATE_SINGLE_TEST_HACK(_field, _state, _test, _version, _info, _type) { \
+    .name         = (stringify(_field) "-hack"),                     \
+    .version_id   = (_version),                                      \
+    .field_exists = (_test),                                         \
+    .size         = sizeof(_type),                                   \
+    .info         = &(_info),                                        \
+    .flags        = VMS_SINGLE,                                      \
+    .offset       = vmstate_offset_value(_state, _field, _type),     \
+}
+
 #define VMSTATE_POINTER(_field, _state, _version, _info, _type) {    \
     .name       = (stringify(_field)),                               \
     .version_id = (_version),                                        \
@@ -419,7 +429,7 @@  extern const VMStateInfo vmstate_info_unused_buffer;
 }
 
 #define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\
-    .name         = (stringify(_field)),                              \
+    .name         = (stringify(_field) "-" stringify(_test)),         \
     .field_exists = (_test),                                          \
     .num          = (_num),                                           \
     .info         = &(_info),                                         \
@@ -429,7 +439,7 @@  extern const VMStateInfo vmstate_info_unused_buffer;
 }
 
 #define VMSTATE_SUB_ARRAY(_field, _state, _start, _num, _version, _info, _type) { \
-    .name       = (stringify(_field)),                               \
+    .name       = (stringify(_field) "[" stringify(_start) "]"),      \
     .version_id = (_version),                                        \
     .num        = (_num),                                            \
     .info       = &(_info),                                          \
@@ -621,7 +631,7 @@  extern const VMStateInfo vmstate_info_unused_buffer;
 }
 
 #define VMSTATE_UNUSED_BUFFER(_test, _version, _size) {              \
-    .name         = "unused",                                        \
+    .name         = "unused" stringify(__LINE__),                    \
     .field_exists = (_test),                                         \
     .version_id   = (_version),                                      \
     .size         = (_size),                                         \