[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH v9 04/15] tools/libxc: C implementation of stream format



On Fri, 2015-04-10 at 18:15 +0100, Andrew Cooper wrote:
> Provide the C structures matching the binary (wire) format of the new
> stream format.  All header/record fields are naturally aligned and
> explicit padding fields are used to ensure the correct layout (i.e.,
> there is no need for any non-standard structure packing pragma or
> attribute).
> 
> Provide some helper functions for converting types to string for
> diagnostic purposes.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
> CC: Ian Campbell <Ian.Campbell@xxxxxxxxxx>
> CC: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
> CC: Wei Liu <wei.liu2@xxxxxxxxxx>

I think I already acked a substantially similar version of this in
<1410432498.6166.79.camel@xxxxxxxxxxxxxxxxxxxxxx>, so given the lack of
an intra-patch changelog here:

Acked-by: Ian Campbell <ian.campbell@xxxxxxxxxx>

If there was some substantial change let me know and I'll actually read
the patch.

> ---
>  tools/libxc/Makefile              |    1 +
>  tools/libxc/xc_sr_common.c        |   72 ++++++++++++++++++
>  tools/libxc/xc_sr_common.h        |    8 ++
>  tools/libxc/xc_sr_stream_format.h |  148 
> +++++++++++++++++++++++++++++++++++++
>  4 files changed, 229 insertions(+)
>  create mode 100644 tools/libxc/xc_sr_common.c
>  create mode 100644 tools/libxc/xc_sr_stream_format.h
> 
> diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile
> index 0c9a7a7..c505fde 100644
> --- a/tools/libxc/Makefile
> +++ b/tools/libxc/Makefile
> @@ -53,6 +53,7 @@ GUEST_SRCS-y :=
>  GUEST_SRCS-y += xg_private.c xc_suspend.c
>  ifeq ($(CONFIG_MIGRATE),y)
>  GUEST_SRCS-y += xc_domain_restore.c xc_domain_save.c
> +GUEST_SRCS-y += xc_sr_common.c
>  GUEST_SRCS-y += xc_sr_restore.c
>  GUEST_SRCS-y += xc_sr_save.c
>  GUEST_SRCS-y += xc_offline_page.c xc_compression.c
> diff --git a/tools/libxc/xc_sr_common.c b/tools/libxc/xc_sr_common.c
> new file mode 100644
> index 0000000..294a626
> --- /dev/null
> +++ b/tools/libxc/xc_sr_common.c
> @@ -0,0 +1,72 @@
> +#include "xc_sr_common.h"
> +
> +static const char *dhdr_types[] =
> +{
> +    [DHDR_TYPE_X86_PV]  = "x86 PV",
> +    [DHDR_TYPE_X86_HVM] = "x86 HVM",
> +    [DHDR_TYPE_X86_PVH] = "x86 PVH",
> +    [DHDR_TYPE_ARM]     = "ARM",
> +};
> +
> +const char *dhdr_type_to_str(uint32_t type)
> +{
> +    if ( type < ARRAY_SIZE(dhdr_types) && dhdr_types[type] )
> +        return dhdr_types[type];
> +
> +    return "Reserved";
> +}
> +
> +static const char *mandatory_rec_types[] =
> +{
> +    [REC_TYPE_END]                  = "End",
> +    [REC_TYPE_PAGE_DATA]            = "Page data",
> +    [REC_TYPE_X86_PV_INFO]          = "x86 PV info",
> +    [REC_TYPE_X86_PV_P2M_FRAMES]    = "x86 PV P2M frames",
> +    [REC_TYPE_X86_PV_VCPU_BASIC]    = "x86 PV vcpu basic",
> +    [REC_TYPE_X86_PV_VCPU_EXTENDED] = "x86 PV vcpu extended",
> +    [REC_TYPE_X86_PV_VCPU_XSAVE]    = "x86 PV vcpu xsave",
> +    [REC_TYPE_SHARED_INFO]          = "Shared info",
> +    [REC_TYPE_TSC_INFO]             = "TSC info",
> +    [REC_TYPE_HVM_CONTEXT]          = "HVM context",
> +    [REC_TYPE_HVM_PARAMS]           = "HVM params",
> +    [REC_TYPE_TOOLSTACK]            = "Toolstack",
> +    [REC_TYPE_X86_PV_VCPU_MSRS]     = "x86 PV vcpu msrs",
> +    [REC_TYPE_VERIFY]               = "Verify",
> +};
> +
> +const char *rec_type_to_str(uint32_t type)
> +{
> +    if ( !(type & REC_TYPE_OPTIONAL) )
> +    {
> +        if ( (type < ARRAY_SIZE(mandatory_rec_types)) &&
> +             (mandatory_rec_types[type]) )
> +            return mandatory_rec_types[type];
> +    }
> +
> +    return "Reserved";
> +}
> +
> +static void __attribute__((unused)) build_assertions(void)
> +{
> +    XC_BUILD_BUG_ON(sizeof(struct xc_sr_ihdr) != 24);
> +    XC_BUILD_BUG_ON(sizeof(struct xc_sr_dhdr) != 16);
> +    XC_BUILD_BUG_ON(sizeof(struct xc_sr_rhdr) != 8);
> +
> +    XC_BUILD_BUG_ON(sizeof(struct xc_sr_rec_page_data_header)  != 8);
> +    XC_BUILD_BUG_ON(sizeof(struct xc_sr_rec_x86_pv_info)       != 8);
> +    XC_BUILD_BUG_ON(sizeof(struct xc_sr_rec_x86_pv_p2m_frames) != 8);
> +    XC_BUILD_BUG_ON(sizeof(struct xc_sr_rec_x86_pv_vcpu_hdr)   != 8);
> +    XC_BUILD_BUG_ON(sizeof(struct xc_sr_rec_tsc_info)          != 24);
> +    XC_BUILD_BUG_ON(sizeof(struct xc_sr_rec_hvm_params_entry)  != 16);
> +    XC_BUILD_BUG_ON(sizeof(struct xc_sr_rec_hvm_params)        != 8);
> +}
> +
> +/*
> + * Local variables:
> + * mode: C
> + * c-file-style: "BSD"
> + * c-basic-offset: 4
> + * tab-width: 4
> + * indent-tabs-mode: nil
> + * End:
> + */
> diff --git a/tools/libxc/xc_sr_common.h b/tools/libxc/xc_sr_common.h
> index ab7cb46..b65e52b 100644
> --- a/tools/libxc/xc_sr_common.h
> +++ b/tools/libxc/xc_sr_common.h
> @@ -3,6 +3,14 @@
>  
>  #include "xg_private.h"
>  
> +#include "xc_sr_stream_format.h"
> +
> +/* String representation of Domain Header types. */
> +const char *dhdr_type_to_str(uint32_t type);
> +
> +/* String representation of Record types. */
> +const char *rec_type_to_str(uint32_t type);
> +
>  #endif
>  /*
>   * Local variables:
> diff --git a/tools/libxc/xc_sr_stream_format.h 
> b/tools/libxc/xc_sr_stream_format.h
> new file mode 100644
> index 0000000..d116ca6
> --- /dev/null
> +++ b/tools/libxc/xc_sr_stream_format.h
> @@ -0,0 +1,148 @@
> +#ifndef __STREAM_FORMAT__H
> +#define __STREAM_FORMAT__H
> +
> +/*
> + * C structures for the Migration v2 stream format.
> + * See docs/specs/libxc-migration-stream.pandoc
> + */
> +
> +#include <inttypes.h>
> +
> +/*
> + * Image Header
> + */
> +struct xc_sr_ihdr
> +{
> +    uint64_t marker;
> +    uint32_t id;
> +    uint32_t version;
> +    uint16_t options;
> +    uint16_t _res1;
> +    uint32_t _res2;
> +};
> +
> +#define IHDR_MARKER  0xffffffffffffffffULL
> +#define IHDR_ID      0x58454E46U
> +#define IHDR_VERSION 2
> +
> +#define _IHDR_OPT_ENDIAN 0
> +#define IHDR_OPT_LITTLE_ENDIAN (0 << _IHDR_OPT_ENDIAN)
> +#define IHDR_OPT_BIG_ENDIAN    (1 << _IHDR_OPT_ENDIAN)
> +
> +/*
> + * Domain Header
> + */
> +struct xc_sr_dhdr
> +{
> +    uint32_t type;
> +    uint16_t page_shift;
> +    uint16_t _res1;
> +    uint32_t xen_major;
> +    uint32_t xen_minor;
> +};
> +
> +#define DHDR_TYPE_X86_PV  0x00000001U
> +#define DHDR_TYPE_X86_HVM 0x00000002U
> +#define DHDR_TYPE_X86_PVH 0x00000003U
> +#define DHDR_TYPE_ARM     0x00000004U
> +
> +/*
> + * Record Header
> + */
> +struct xc_sr_rhdr
> +{
> +    uint32_t type;
> +    uint32_t length;
> +};
> +
> +/* All records must be aligned up to an 8 octet boundary */
> +#define REC_ALIGN_ORDER               (3U)
> +/* Somewhat arbitrary - 8MB */
> +#define REC_LENGTH_MAX                (8U << 20)
> +
> +#define REC_TYPE_END                  0x00000000U
> +#define REC_TYPE_PAGE_DATA            0x00000001U
> +#define REC_TYPE_X86_PV_INFO          0x00000002U
> +#define REC_TYPE_X86_PV_P2M_FRAMES    0x00000003U
> +#define REC_TYPE_X86_PV_VCPU_BASIC    0x00000004U
> +#define REC_TYPE_X86_PV_VCPU_EXTENDED 0x00000005U
> +#define REC_TYPE_X86_PV_VCPU_XSAVE    0x00000006U
> +#define REC_TYPE_SHARED_INFO          0x00000007U
> +#define REC_TYPE_TSC_INFO             0x00000008U
> +#define REC_TYPE_HVM_CONTEXT          0x00000009U
> +#define REC_TYPE_HVM_PARAMS           0x0000000aU
> +#define REC_TYPE_TOOLSTACK            0x0000000bU
> +#define REC_TYPE_X86_PV_VCPU_MSRS     0x0000000cU
> +#define REC_TYPE_VERIFY               0x0000000dU
> +
> +#define REC_TYPE_OPTIONAL             0x80000000U
> +
> +/* PAGE_DATA */
> +struct xc_sr_rec_page_data_header
> +{
> +    uint32_t count;
> +    uint32_t _res1;
> +    uint64_t pfn[0];
> +};
> +
> +#define PAGE_DATA_PFN_MASK  0x000fffffffffffffULL
> +#define PAGE_DATA_TYPE_MASK 0xf000000000000000ULL
> +
> +/* X86_PV_INFO */
> +struct xc_sr_rec_x86_pv_info
> +{
> +    uint8_t guest_width;
> +    uint8_t pt_levels;
> +    uint8_t _res[6];
> +};
> +
> +/* X86_PV_P2M_FRAMES */
> +struct xc_sr_rec_x86_pv_p2m_frames
> +{
> +    uint32_t start_pfn;
> +    uint32_t end_pfn;
> +    uint64_t p2m_pfns[0];
> +};
> +
> +/* X86_PV_VCPU_{BASIC,EXTENDED,XSAVE,MSRS} */
> +struct xc_sr_rec_x86_pv_vcpu_hdr
> +{
> +    uint32_t vcpu_id;
> +    uint32_t _res1;
> +    uint8_t context[0];
> +};
> +
> +/* TSC_INFO */
> +struct xc_sr_rec_tsc_info
> +{
> +    uint32_t mode;
> +    uint32_t khz;
> +    uint64_t nsec;
> +    uint32_t incarnation;
> +    uint32_t _res1;
> +};
> +
> +/* HVM_PARAMS */
> +struct xc_sr_rec_hvm_params_entry
> +{
> +    uint64_t index;
> +    uint64_t value;
> +};
> +
> +struct xc_sr_rec_hvm_params
> +{
> +    uint32_t count;
> +    uint32_t _res1;
> +    struct xc_sr_rec_hvm_params_entry param[0];
> +};
> +
> +#endif
> +/*
> + * Local variables:
> + * mode: C
> + * c-file-style: "BSD"
> + * c-basic-offset: 4
> + * tab-width: 4
> + * indent-tabs-mode: nil
> + * End:
> + */



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.