From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Subject: [PATCH 2/6] tools/libxc: Stream specification and some common code
Date: Wed, 9 Apr 2014 19:28:20 +0100 [thread overview]
Message-ID: <1397068104-23714-3-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1397068104-23714-1-git-send-email-andrew.cooper3@citrix.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
tools/libxc/saverestore/common.c | 59 ++++++++++++++
tools/libxc/saverestore/common.h | 8 ++
tools/libxc/saverestore/stream_format.h | 130 +++++++++++++++++++++++++++++++
3 files changed, 197 insertions(+)
create mode 100644 tools/libxc/saverestore/common.c
create mode 100644 tools/libxc/saverestore/stream_format.h
diff --git a/tools/libxc/saverestore/common.c b/tools/libxc/saverestore/common.c
new file mode 100644
index 0000000..d2dfd5a
--- /dev/null
+++ b/tools/libxc/saverestore/common.c
@@ -0,0 +1,59 @@
+#include "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_x86_pv_shared_info] = "x86 PV shared info",
+ [REC_TYPE_tsc_info] = "TSC info",
+};
+
+/*
+static const char *optional_rec_types[] =
+{
+};
+*/
+
+const char *rec_type_to_str(uint32_t type)
+{
+ if ( type & REC_TYPE_optional )
+ return "Reserved";
+
+ if ( ((type & REC_TYPE_optional) == 0 ) &&
+ (type < ARRAY_SIZE(mandatory_rec_types)) &&
+ (mandatory_rec_types[type]) )
+ return mandatory_rec_types[type];
+
+ return "Reserved";
+}
+
+/*
+ * 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/saverestore/common.h b/tools/libxc/saverestore/common.h
index f1aff44..fff0a39 100644
--- a/tools/libxc/saverestore/common.h
+++ b/tools/libxc/saverestore/common.h
@@ -3,6 +3,14 @@
#include "../xg_private.h"
+#include "stream_format.h"
+
+// TODO: Find a better place to put this...
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
+
+const char *dhdr_type_to_str(uint32_t type);
+const char *rec_type_to_str(uint32_t type);
+
#endif
/*
* Local variables:
diff --git a/tools/libxc/saverestore/stream_format.h b/tools/libxc/saverestore/stream_format.h
new file mode 100644
index 0000000..6898c3c
--- /dev/null
+++ b/tools/libxc/saverestore/stream_format.h
@@ -0,0 +1,130 @@
+#ifndef __STREAM_FORMAT__H
+#define __STREAM_FORMAT__H
+
+#include <inttypes.h>
+
+/*
+ * Image Header
+ */
+struct 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 1
+
+#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 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 rhdr
+{
+ uint32_t type;
+ uint32_t length;
+};
+
+/* 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_x86_pv_shared_info 0x00000007U
+#define REC_TYPE_tsc_info 0x00000008U
+
+#define REC_TYPE_optional 0x80000000U
+
+/* PAGE_DATA */
+struct 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 rec_x86_pv_info
+{
+ uint8_t guest_width;
+ uint8_t pt_levels;
+ uint8_t options;
+};
+
+/* X86_PV_P2M_FRAMES */
+struct rec_x86_pv_p2m_frames
+{
+ uint32_t start_pfn;
+ uint32_t end_pfn;
+ uint64_t p2m_pfns[0];
+};
+
+/* VCPU_CONTEXT_{basic,extended} */
+struct rec_x86_pv_vcpu
+{
+ uint32_t vcpu_id;
+ uint32_t _res1;
+ uint8_t context[0];
+};
+
+/* VCPU_CONTEXT_XSAVE */
+struct rec_x86_pv_vcpu_xsave
+{
+ uint32_t vcpu_id;
+ uint32_t _res1;
+ uint64_t xfeature_mask;
+ uint8_t context[0];
+};
+
+/* TSC_INFO */
+struct rec_tsc_info
+{
+ uint32_t mode;
+ uint32_t khz;
+ uint64_t nsec;
+ uint32_t incarnation;
+};
+
+#endif
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--
1.7.10.4
next prev parent reply other threads:[~2014-04-09 18:28 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-09 18:28 [PATCH 0/6] [VERY RFC] Migration Stream v2 Andrew Cooper
2014-04-09 18:28 ` [PATCH 1/6] [HACK] tools/libxc: save/restore v2 framework Andrew Cooper
2014-04-09 18:28 ` Andrew Cooper [this message]
2014-04-09 18:28 ` [PATCH 3/6] tools/libxc: Scripts for inspection/valdiation of legacy and new streams Andrew Cooper
2014-04-09 18:28 ` [PATCH 4/6] tools/libxc: x86 pv common code Andrew Cooper
2014-04-09 18:28 ` [PATCH 5/6] tools/libxc: x86 pv save implementation Andrew Cooper
2014-04-09 18:28 ` [PATCH 6/6] tools/libxc: x86 pv restore implementation Andrew Cooper
2014-04-10 10:42 ` [PATCH 0/6] [VERY RFC] Migration Stream v2 Ian Campbell
2014-04-10 11:21 ` Andrew Cooper
2014-04-10 13:05 ` Frediano Ziglio
2014-04-10 13:49 ` Andrew Cooper
2014-04-14 17:49 ` George Dunlap
2014-04-14 18:06 ` Andrew Cooper
2014-04-14 18:16 ` George Dunlap
2014-04-14 23:43 ` Andrew Cooper
2014-04-14 18:11 ` David Vrabel
2014-04-15 8:30 ` Frediano Ziglio
2014-04-15 10:35 ` Ian Jackson
2014-04-15 10:38 ` George Dunlap
2014-04-23 13:47 ` Ian Campbell
2014-04-23 14:02 ` Andrew Cooper
2014-04-23 14:13 ` 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=1397068104-23714-3-git-send-email-andrew.cooper3@citrix.com \
--to=andrew.cooper3@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).