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

[Xen-devel] [PATCH v4 3/9] tools/libxc: Stream specification and some common code



Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
Signed-off-by: David Vrabel <david.vrabel@xxxxxxxxxx>
---
 tools/libxc/saverestore/common.c        |   63 ++++++++++++
 tools/libxc/saverestore/common.h        |    8 ++
 tools/libxc/saverestore/stream_format.h |  158 +++++++++++++++++++++++++++++++
 3 files changed, 229 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..de2e727
--- /dev/null
+++ b/tools/libxc/saverestore/common.c
@@ -0,0 +1,63 @@
+#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_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",
+};
+
+/*
+static const char *optional_rec_types[] =
+{
+     None yet...
+};
+*/
+
+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..efcca60
--- /dev/null
+++ b/tools/libxc/saverestore/stream_format.h
@@ -0,0 +1,158 @@
+#ifndef __STREAM_FORMAT__H
+#define __STREAM_FORMAT__H
+
+#include <inttypes.h>
+
+/* TODO - find somewhere more appropriate. rec_tsc_info needs it for 64bit */
+#ifndef __packed
+#define __packed __attribute__((packed))
+#endif
+
+/*
+ * Image Header
+ */
+struct __packed 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 __packed 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 __packed 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_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_optional             0x80000000U
+
+/* PAGE_DATA */
+struct __packed 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 __packed rec_x86_pv_info
+{
+    uint8_t guest_width;
+    uint8_t pt_levels;
+    uint8_t options;
+};
+
+/* X86_PV_P2M_FRAMES */
+struct __packed rec_x86_pv_p2m_frames
+{
+    uint32_t start_pfn;
+    uint32_t end_pfn;
+    uint64_t p2m_pfns[0];
+};
+
+/* VCPU_CONTEXT_{basic,extended} */
+struct __packed rec_x86_pv_vcpu
+{
+    uint32_t vcpu_id;
+    uint32_t _res1;
+    uint8_t context[0];
+};
+
+/* VCPU_CONTEXT_XSAVE */
+struct __packed rec_x86_pv_vcpu_xsave
+{
+    uint32_t vcpu_id;
+    uint32_t _res1;
+    uint64_t xfeature_mask;
+    uint8_t  context[0];
+};
+
+/* TSC_INFO */
+struct __packed rec_tsc_info
+{
+    uint32_t mode;
+    uint32_t khz;
+    uint64_t nsec;
+    uint32_t incarnation;
+};
+
+/* HVM_CONTEXT */
+struct __packed rec_hvm_context
+{
+    uint8_t context[0];
+};
+
+/* HVM_PARAMS */
+struct __packed rec_hvm_params_entry
+{
+    uint64_t index;
+    uint64_t value;
+};
+
+struct __packed rec_hvm_params
+{
+    uint32_t count;
+    uint32_t _res1;
+    struct 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:
+ */
-- 
1.7.10.4


_______________________________________________
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®.