Patchwork [v3,1/3] vmstate: Add support for two dimensional arrays

login
register
mail settings
Submitter Peter Maydell
Date March 22, 2013, 6:02 p.m.
Message ID <1363975375-3166-2-git-send-email-peter.maydell@linaro.org>
Download mbox | patch
Permalink /patch/230233/
State New
Headers show

Comments

Peter Maydell - March 22, 2013, 6:02 p.m.
Add support for migrating two dimensional arrays, by defining
a set of new macros VMSTATE_*_2DARRAY paralleling the existing
VMSTATE_*_ARRAY macros. 2D arrays are handled the same for actual
state serialization; the only difference is that the type check
has to change for a 2D array.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 include/migration/vmstate.h |   27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
Igor Mitsyanko - March 22, 2013, 7:20 p.m.
On Mar 22, 2013 10:02 PM, "Peter Maydell" <peter.maydell@linaro.org> wrote:
>
> Add support for migrating two dimensional arrays, by defining
> a set of new macros VMSTATE_*_2DARRAY paralleling the existing
> VMSTATE_*_ARRAY macros. 2D arrays are handled the same for actual
> state serialization; the only difference is that the type check
> has to change for a 2D array.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  include/migration/vmstate.h |   27 +++++++++++++++++++++++++++
>  1 file changed, 27 insertions(+)
>

Reviewed-by: Igor Mitsyanko <i.mitsyanko@gmail.com>

> diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
> index 6666d27..24bc537 100644
> --- a/include/migration/vmstate.h
> +++ b/include/migration/vmstate.h
> @@ -161,6 +161,7 @@ extern const VMStateInfo vmstate_info_buffer;
>  extern const VMStateInfo vmstate_info_unused_buffer;
>  extern const VMStateInfo vmstate_info_bitmap;
>
> +#define type_check_2darray(t1,t2,n,m) ((t1(*)[n][m])0 - (t2*)0)
>  #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
>  #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)
>
> @@ -176,6 +177,10 @@ extern const VMStateInfo vmstate_info_bitmap;
>      (offsetof(_state, _field) +                                      \
>       type_check_array(_type, typeof_field(_state, _field), _num))
>
> +#define vmstate_offset_2darray(_state, _field, _type, _n1, _n2)      \
> +    (offsetof(_state, _field) +                                      \
> +     type_check_2darray(_type, typeof_field(_state, _field), _n1, _n2))
> +
>  #define vmstate_offset_sub_array(_state, _field, _type, _start)      \
>      (offsetof(_state, _field[_start]))
>
> @@ -221,6 +226,16 @@ extern const VMStateInfo vmstate_info_bitmap;
>      .offset     = vmstate_offset_array(_state, _field, _type, _num), \
>  }
>
> +#define VMSTATE_2DARRAY(_field, _state, _n1, _n2, _version, _info,
_type) { \
> +    .name       = (stringify(_field)),
   \
> +    .version_id = (_version),
    \
> +    .num        = (_n1) * (_n2),
   \
> +    .info       = &(_info),
    \
> +    .size       = sizeof(_type),
   \
> +    .flags      = VMS_ARRAY,
   \
> +    .offset     = vmstate_offset_2darray(_state, _field, _type, _n1,
_n2),  \
> +}
> +
>  #define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\
>      .name         = (stringify(_field)),                              \
>      .field_exists = (_test),                                          \
> @@ -554,15 +569,27 @@ extern const VMStateInfo vmstate_info_bitmap;
>  #define VMSTATE_UINT16_ARRAY_V(_f, _s, _n, _v)                         \
>      VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint16, uint16_t)
>
> +#define VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, _v)                \
> +    VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint16, uint16_t)
> +
>  #define VMSTATE_UINT16_ARRAY(_f, _s, _n)                               \
>      VMSTATE_UINT16_ARRAY_V(_f, _s, _n, 0)
>
> +#define VMSTATE_UINT16_2DARRAY(_f, _s, _n1, _n2)                      \
> +    VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, 0)
> +
> +#define VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, _v)                 \
> +    VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint8, uint8_t)
> +
>  #define VMSTATE_UINT8_ARRAY_V(_f, _s, _n, _v)                         \
>      VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint8, uint8_t)
>
>  #define VMSTATE_UINT8_ARRAY(_f, _s, _n)                               \
>      VMSTATE_UINT8_ARRAY_V(_f, _s, _n, 0)
>
> +#define VMSTATE_UINT8_2DARRAY(_f, _s, _n1, _n2)                       \
> +    VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, 0)
> +
>  #define VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v)                        \
>      VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint32, uint32_t)
>
> --
> 1.7.9.5
>

Patch

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 6666d27..24bc537 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -161,6 +161,7 @@  extern const VMStateInfo vmstate_info_buffer;
 extern const VMStateInfo vmstate_info_unused_buffer;
 extern const VMStateInfo vmstate_info_bitmap;
 
+#define type_check_2darray(t1,t2,n,m) ((t1(*)[n][m])0 - (t2*)0)
 #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
 #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)
 
@@ -176,6 +177,10 @@  extern const VMStateInfo vmstate_info_bitmap;
     (offsetof(_state, _field) +                                      \
      type_check_array(_type, typeof_field(_state, _field), _num))
 
+#define vmstate_offset_2darray(_state, _field, _type, _n1, _n2)      \
+    (offsetof(_state, _field) +                                      \
+     type_check_2darray(_type, typeof_field(_state, _field), _n1, _n2))
+
 #define vmstate_offset_sub_array(_state, _field, _type, _start)      \
     (offsetof(_state, _field[_start]))
 
@@ -221,6 +226,16 @@  extern const VMStateInfo vmstate_info_bitmap;
     .offset     = vmstate_offset_array(_state, _field, _type, _num), \
 }
 
+#define VMSTATE_2DARRAY(_field, _state, _n1, _n2, _version, _info, _type) { \
+    .name       = (stringify(_field)),                                      \
+    .version_id = (_version),                                               \
+    .num        = (_n1) * (_n2),                                            \
+    .info       = &(_info),                                                 \
+    .size       = sizeof(_type),                                            \
+    .flags      = VMS_ARRAY,                                                \
+    .offset     = vmstate_offset_2darray(_state, _field, _type, _n1, _n2),  \
+}
+
 #define VMSTATE_ARRAY_TEST(_field, _state, _num, _test, _info, _type) {\
     .name         = (stringify(_field)),                              \
     .field_exists = (_test),                                          \
@@ -554,15 +569,27 @@  extern const VMStateInfo vmstate_info_bitmap;
 #define VMSTATE_UINT16_ARRAY_V(_f, _s, _n, _v)                         \
     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint16, uint16_t)
 
+#define VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, _v)                \
+    VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint16, uint16_t)
+
 #define VMSTATE_UINT16_ARRAY(_f, _s, _n)                               \
     VMSTATE_UINT16_ARRAY_V(_f, _s, _n, 0)
 
+#define VMSTATE_UINT16_2DARRAY(_f, _s, _n1, _n2)                      \
+    VMSTATE_UINT16_2DARRAY_V(_f, _s, _n1, _n2, 0)
+
+#define VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, _v)                 \
+    VMSTATE_2DARRAY(_f, _s, _n1, _n2, _v, vmstate_info_uint8, uint8_t)
+
 #define VMSTATE_UINT8_ARRAY_V(_f, _s, _n, _v)                         \
     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint8, uint8_t)
 
 #define VMSTATE_UINT8_ARRAY(_f, _s, _n)                               \
     VMSTATE_UINT8_ARRAY_V(_f, _s, _n, 0)
 
+#define VMSTATE_UINT8_2DARRAY(_f, _s, _n1, _n2)                       \
+    VMSTATE_UINT8_2DARRAY_V(_f, _s, _n1, _n2, 0)
+
 #define VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v)                        \
     VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_uint32, uint32_t)