Xen provides a xen_version hypercall to query the values of several
interesting things (like hypervisor version, commandline used,
actual changeset, etc.). Create a user-friendly and efficient
wrapper around the libxc function to provide values for xl info output.
Signed-off-by: Andre Przywara <andre.przywara@xxxxxxx>
--
Andre Przywara
AMD-Operating System Research Center (OSRC), Dresden, Germany
Tel: +49 351 488-3567-12
diff -r 7ee8bb40200a tools/libxl/libxl.c
--- a/tools/libxl/libxl.c Thu Apr 15 19:11:16 2010 +0100
+++ b/tools/libxl/libxl.c Sun Apr 18 14:41:48 2010 +0200
@@ -2351,6 +2351,92 @@
return 0;
}
+int libxl_get_version_info(struct libxl_ctx *ctx,
+ libxl_version_info *info,
+ uint32_t query_mask)
+{
+ union {
+ xen_extraversion_t xen_extra;
+ xen_compile_info_t xen_cc;
+ xen_changeset_info_t xen_chgset;
+ xen_capabilities_info_t xen_caps;
+ xen_platform_parameters_t p_parms;
+ xen_commandline_t xen_commandline;
+ } u;
+ long xen_version;
+
+ if (query_mask & LIBXL_VERSION_VERSION_MASK) {
+ xen_version = xc_version(ctx->xch, XENVER_version, NULL);
+ info->xen_version_major = xen_version >> 16;
+ info->xen_version_minor = xen_version & 0xFF;
+ xc_version(ctx->xch, XENVER_extraversion, &u.xen_extra);
+ info->xen_version_extra = strdup(u.xen_extra);
+ } else {
+ info->xen_version_major = 0;
+ info->xen_version_minor = 0;
+ info->xen_version_extra = NULL;
+ }
+
+ if (query_mask & LIBXL_VERSION_COMPILER_MASK) {
+ xc_version(ctx->xch, XENVER_compile_info, &u.xen_cc);
+ info->compiler = strdup(u.xen_cc.compiler);
+ info->compile_by = strdup(u.xen_cc.compile_by);
+ info->compile_domain = strdup(u.xen_cc.compile_domain);
+ info->compile_date = strdup(u.xen_cc.compile_date);
+ } else {
+ info->compiler = NULL;
+ info->compile_by = NULL;
+ info->compile_domain = NULL;
+ info->compile_date = NULL;
+ }
+
+ if (query_mask & LIBXL_VERSION_CAPS_MASK) {
+ xc_version(ctx->xch, XENVER_capabilities, &u.xen_caps);
+ info->capabilities = strdup(u.xen_caps);
+ } else
+ info->capabilities = NULL;
+
+ if (query_mask & LIBXL_VERSION_CHANGESET_MASK) {
+ xc_version(ctx->xch, XENVER_changeset, &u.xen_chgset);
+ info->changeset = strdup(u.xen_chgset);
+ } else
+ info->changeset = NULL;
+
+ if (query_mask & LIBXL_VERSION_VIRT_START_MASK) {
+ xc_version(ctx->xch, XENVER_platform_parameters, &u.p_parms);
+ info->virt_start = u.p_parms.virt_start;
+ } else
+ info->virt_start = 0;
+
+ if (query_mask & LIBXL_VERSION_PAGESIZE_MASK)
+ info->pagesize = xc_version(ctx->xch, XENVER_pagesize, NULL);
+ else
+ info->pagesize = 0;
+
+ if (query_mask & LIBXL_VERSION_COMMANDLINE_MASK) {
+ xc_version(ctx->xch, XENVER_commandline, &u.xen_commandline);
+ info->commandline = strdup(u.xen_commandline);
+ } else
+ info->commandline = NULL;
+
+ return 0;
+}
+
+#define FREE_IF_NOT_ZERO(ptr) if((ptr) != NULL) {free(ptr); ptr = NULL;}
+
+void libxl_free_version_info(libxl_version_info *info)
+{
+ FREE_IF_NOT_ZERO(info->xen_version_extra)
+ FREE_IF_NOT_ZERO(info->compiler)
+ FREE_IF_NOT_ZERO(info->compile_by)
+ FREE_IF_NOT_ZERO(info->compile_domain)
+ FREE_IF_NOT_ZERO(info->compile_date)
+ FREE_IF_NOT_ZERO(info->capabilities)
+ FREE_IF_NOT_ZERO(info->changeset)
+ FREE_IF_NOT_ZERO(info->commandline)
+}
+#undef FREE_IF_NOT_ZERO
+
struct libxl_vcpuinfo *libxl_list_vcpu(struct libxl_ctx *ctx, uint32_t domid,
int *nb_vcpu, int *cpusize)
{
diff -r 7ee8bb40200a tools/libxl/libxl.h
--- a/tools/libxl/libxl.h Thu Apr 15 19:11:16 2010 +0100
+++ b/tools/libxl/libxl.h Sun Apr 18 14:41:48 2010 +0200
@@ -59,6 +59,35 @@
};
typedef struct {
+ int xen_version_major;
+ int xen_version_minor;
+ char *xen_version_extra;
+ char *compiler;
+ char *compile_by;
+ char *compile_domain;
+ char *compile_date;
+ char *capabilities;
+ char *changeset;
+ unsigned long virt_start;
+ unsigned long pagesize;
+ char *commandline;
+} libxl_version_info;
+
+#define LIBXL_VERSION_VERSION_MASK (1 << 0)
+#define LIBXL_VERSION_COMPILER_MASK (1 << 1)
+#define LIBXL_VERSION_CAPS_MASK (1 << 2)
+#define LIBXL_VERSION_CHANGESET_MASK (1 << 3)
+#define LIBXL_VERSION_VIRT_START_MASK (1 << 4)
+#define LIBXL_VERSION_PAGESIZE_MASK (1 << 5)
+#define LIBXL_VERSION_COMMANDLINE_MASK (1 << 6)
+#define LIBXL_VERSION_ALL_MASK ((1 << 7) - 1)
+
+int libxl_get_version_info(struct libxl_ctx *ctx,
+ libxl_version_info *info,
+ uint32_t query_mask);
+void libxl_free_version_info(libxl_version_info *info);
+
+typedef struct {
bool hvm;
bool hap;
int ssidref;
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|