From: Ian Campbell <ian.campbell@citrix.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>,
Ian Jackson <Ian.Jackson@eu.citrix.com>,
Xen-devel <xen-devel@lists.xen.org>
Subject: Re: [PATCH v9 04/15] tools/libxc: C implementation of stream format
Date: Wed, 15 Apr 2015 11:59:20 +0100 [thread overview]
Message-ID: <1429095560.15516.197.camel@citrix.com> (raw)
In-Reply-To: <1428686167-8279-5-git-send-email-andrew.cooper3@citrix.com>
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@citrix.com>
> CC: Ian Campbell <Ian.Campbell@citrix.com>
> CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
> CC: Wei Liu <wei.liu2@citrix.com>
I think I already acked a substantially similar version of this in
<1410432498.6166.79.camel@kazak.uk.xensource.com>, so given the lack of
an intra-patch changelog here:
Acked-by: Ian Campbell <ian.campbell@citrix.com>
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:
> + */
next prev parent reply other threads:[~2015-04-15 10:59 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-10 17:15 [PATCH v9 00/15] Migration v2 (libxc) Andrew Cooper
2015-04-10 17:15 ` [PATCH v9 01/15] tools/libxc: Implement writev_exact() in the same style as write_exact() Andrew Cooper
2015-04-15 10:44 ` Ian Campbell
2015-04-10 17:15 ` [PATCH v9 02/15] libxc/progress: Extend the progress interface Andrew Cooper
2015-04-15 10:55 ` Ian Campbell
2015-04-20 13:15 ` Andrew Cooper
2015-04-22 15:38 ` Ian Campbell
2015-04-10 17:15 ` [PATCH v9 03/15] tools/libxc: Migration v2 framework Andrew Cooper
2015-04-15 10:57 ` Ian Campbell
2015-04-10 17:15 ` [PATCH v9 04/15] tools/libxc: C implementation of stream format Andrew Cooper
2015-04-15 10:59 ` Ian Campbell [this message]
2015-04-10 17:15 ` [PATCH v9 05/15] tools/libxc: noarch common code Andrew Cooper
2015-04-15 11:00 ` Ian Campbell
2015-04-10 17:15 ` [PATCH v9 06/15] tools/libxc: x86 " Andrew Cooper
2015-04-10 17:15 ` [PATCH v9 07/15] tools/libxc: x86 PV " Andrew Cooper
2015-04-15 11:07 ` Ian Campbell
2015-04-10 17:16 ` [PATCH v9 08/15] tools/libxc: x86 PV save code Andrew Cooper
2015-04-15 11:13 ` Ian Campbell
2015-04-15 11:41 ` Andrew Cooper
2015-04-15 11:52 ` Ian Campbell
2015-04-10 17:16 ` [PATCH v9 09/15] tools/libxc: x86 PV restore code Andrew Cooper
2015-04-15 11:22 ` Ian Campbell
2015-04-10 17:16 ` [PATCH v9 10/15] tools/libxc: x86 HVM save code Andrew Cooper
2015-04-13 12:28 ` Vitaly Kuznetsov
2015-04-13 13:21 ` Andrew Cooper
2015-04-15 11:29 ` Ian Campbell
2015-04-15 11:30 ` Ian Campbell
2015-04-10 17:16 ` [PATCH v9 11/15] tools/libxc: x86 HVM restore code Andrew Cooper
2015-04-15 11:31 ` Ian Campbell
2015-04-10 17:16 ` [PATCH v9 12/15] tools/libxc: noarch save code Andrew Cooper
2015-04-15 11:34 ` Ian Campbell
2015-04-10 17:16 ` [PATCH v9 13/15] tools/libxc: noarch restore code Andrew Cooper
2015-04-15 11:42 ` Ian Campbell
2015-04-15 11:50 ` Andrew Cooper
2015-04-15 11:53 ` Ian Campbell
2015-04-10 17:16 ` [PATCH v9 14/15] docs: libxc migration stream specification Andrew Cooper
2015-04-15 11:46 ` Ian Campbell
2015-04-15 12:05 ` Andrew Cooper
2015-04-15 12:11 ` Ian Campbell
2015-04-15 12:02 ` David Vrabel
2015-04-15 12:09 ` Andrew Cooper
2015-04-10 17:16 ` [PATCH v9 15/15] tools/libxc: Migration v2 compatibility for unmodified libxl Andrew Cooper
2015-04-15 11:51 ` Ian Campbell
2015-04-15 12:14 ` Andrew Cooper
2015-04-15 12:52 ` Ian Campbell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1429095560.15516.197.camel@citrix.com \
--to=ian.campbell@citrix.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.