|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 2/2] tools: add new xl command get-config for getting hypervisor config
Add new subcommand "get-config" to xl config to print the hypervisor
.config file.
To be able to reuse already existing decompressing code in libxenguest
xc_inflate_buffer() has to be moved to libxenguest.h.
Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
---
docs/man/xl.1.pod.in | 5 +++++
tools/libxc/include/xenctrl.h | 8 ++++++++
tools/libxc/include/xenguest.h | 13 +++++++++++++
tools/libxc/xc_misc.c | 42 ++++++++++++++++++++++++++++++++++++++++++
tools/libxc/xg_private.h | 4 ----
tools/libxl/libxl.c | 30 ++++++++++++++++++++++++++++++
tools/libxl/libxl.h | 8 ++++++++
tools/xl/xl.h | 1 +
tools/xl/xl_cmdtable.c | 5 +++++
tools/xl/xl_misc.c | 20 ++++++++++++++++++++
10 files changed, 132 insertions(+), 4 deletions(-)
diff --git a/docs/man/xl.1.pod.in b/docs/man/xl.1.pod.in
index 4310fcd818..b6eaf5b139 100644
--- a/docs/man/xl.1.pod.in
+++ b/docs/man/xl.1.pod.in
@@ -844,6 +844,11 @@ Clears Xen's message buffer.
=back
+=item B<get-config>
+
+Print the software configuration file (.config) used to build the
+hypervisor.
+
=item B<info> [I<OPTIONS>]
Print information about the Xen host in I<name : value> format. When
diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
index 31cdda76c6..decbc18f73 100644
--- a/tools/libxc/include/xenctrl.h
+++ b/tools/libxc/include/xenctrl.h
@@ -2627,6 +2627,14 @@ int xc_livepatch_replace(xc_interface *xch, char *name,
uint32_t timeout);
int xc_domain_cacheflush(xc_interface *xch, uint32_t domid,
xen_pfn_t start_pfn, xen_pfn_t nr_pfns);
+/*
+ * Get gzip-ed .config from hypervisor.
+ * *buffer must be free()-ed by caller.
+ * data size is returned in `size`.
+ * Returns 0 on success.
+ */
+int xc_get_config(xc_interface *xch, char **buffer, unsigned long *size);
+
/* Compat shims */
#include "xenctrl_compat.h"
diff --git a/tools/libxc/include/xenguest.h b/tools/libxc/include/xenguest.h
index b4b2e19619..76e87ea97c 100644
--- a/tools/libxc/include/xenguest.h
+++ b/tools/libxc/include/xenguest.h
@@ -310,4 +310,17 @@ xen_pfn_t *xc_map_m2p(xc_interface *xch,
unsigned long max_mfn,
int prot,
unsigned long *mfn0);
+
+/**
+ * Decompress a gzip-ed stream.
+ * @parm xch a handle to an open hypervisor interface
+ * @parm in_buf buffer holding the gzip-ed data
+ * @parm in_size size in bytes of the gzip-ed data
+ * @parm out_size where to store the gunzip-ed data length
+ * @return new allocated buffer holding the gunzip-ed data
+ */
+char *xc_inflate_buffer(xc_interface *xch,
+ const char *in_buf,
+ unsigned long in_size,
+ unsigned long *out_size);
#endif /* XENGUEST_H */
diff --git a/tools/libxc/xc_misc.c b/tools/libxc/xc_misc.c
index 5e6714ae2b..83d259e46e 100644
--- a/tools/libxc/xc_misc.c
+++ b/tools/libxc/xc_misc.c
@@ -888,6 +888,48 @@ int xc_livepatch_replace(xc_interface *xch, char *name,
uint32_t timeout)
return _xc_livepatch_action(xch, name, LIVEPATCH_ACTION_REPLACE, timeout);
}
+int xc_get_config(xc_interface *xch, char **buffer, unsigned long *size)
+{
+ int rc;
+ DECLARE_SYSCTL;
+ DECLARE_HYPERCALL_BUFFER(char, buf);
+
+ sysctl.cmd = XEN_SYSCTL_get_config;
+ sysctl.u.get_config.size = 0;
+ set_xen_guest_handle(sysctl.u.get_config.buffer, HYPERCALL_BUFFER_NULL);
+ rc = do_sysctl(xch, &sysctl);
+ if ( rc )
+ return rc;
+
+ *size = sysctl.u.get_config.size;
+ buf = xc_hypercall_buffer_alloc(xch, buf, *size);
+ if ( !buf )
+ {
+ errno = ENOMEM;
+ return -1;
+ }
+
+ sysctl.cmd = XEN_SYSCTL_get_config;
+ sysctl.u.get_config.size = *size;
+ set_xen_guest_handle(sysctl.u.get_config.buffer, buf);
+ rc = do_sysctl(xch, &sysctl);
+
+ if ( rc )
+ goto out;
+
+ *buffer = calloc(1, *size);
+ if ( !*buffer )
+ {
+ errno = ENOMEM;
+ goto out;
+ }
+ memmove(*buffer, buf, *size);
+
+out:
+ xc_hypercall_buffer_free(xch, buf);
+ return rc;
+}
+
/*
* Local variables:
* mode: C
diff --git a/tools/libxc/xg_private.h b/tools/libxc/xg_private.h
index f0a4b2c616..ca85e10737 100644
--- a/tools/libxc/xg_private.h
+++ b/tools/libxc/xg_private.h
@@ -43,10 +43,6 @@
char *xc_read_image(xc_interface *xch,
const char *filename, unsigned long *size);
-char *xc_inflate_buffer(xc_interface *xch,
- const char *in_buf,
- unsigned long in_size,
- unsigned long *out_size);
unsigned long csum_page (void * page);
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index ec71574e99..4cda9a3cd3 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -669,6 +669,36 @@ int libxl_set_parameters(libxl_ctx *ctx, char *params)
return 0;
}
+int libxl_get_config(libxl_ctx *ctx, char **buffer)
+{
+ int ret;
+ unsigned long gz_size, out_size;
+ char *gz_buffer;
+ GC_INIT(ctx);
+
+ ret = xc_get_config(ctx->xch, &gz_buffer, &gz_size);
+ if (ret < 0) {
+ LOGEV(ERROR, ret, "getting config");
+ GC_FREE;
+ return ERROR_FAIL;
+ }
+
+ *buffer = xc_inflate_buffer(ctx->xch, gz_buffer, gz_size, &out_size);
+
+ GC_FREE;
+ free(gz_buffer);
+
+ if (!*buffer) {
+ LOGE(ERROR, "decompressing config data failed");
+ return ERROR_FAIL;
+ }
+
+ *buffer = libxl__realloc(NOGC, *buffer, out_size + 1);
+ (*buffer)[out_size] = 0;
+
+ return 0;
+}
+
static int fd_set_flags(libxl_ctx *ctx, int fd,
int fcntlgetop, int fcntlsetop, const char *fl,
int flagmask, int set_p)
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index a38e5cdba2..2475df4d99 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -1149,6 +1149,13 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst,
const libxl_mac *src);
*/
#define LIBXL_HAVE_SET_PARAMETERS 1
+/*
+ * LIBXL_HAVE_GET_CONFIG
+ *
+ * If this is defined getting hypervisor config is supported.
+ */
+#define LIBXL_HAVE_GET_CONFIG 1
+
/*
* LIBXL_HAVE_PV_SHIM
*
@@ -2307,6 +2314,7 @@ int libxl_send_trigger(libxl_ctx *ctx, uint32_t domid,
int libxl_send_sysrq(libxl_ctx *ctx, uint32_t domid, char sysrq);
int libxl_send_debug_keys(libxl_ctx *ctx, char *keys);
int libxl_set_parameters(libxl_ctx *ctx, char *params);
+int libxl_get_config(libxl_ctx *ctx, char **buffer);
typedef struct libxl__xen_console_reader libxl_xen_console_reader;
diff --git a/tools/xl/xl.h b/tools/xl/xl.h
index cf4202bc89..3152b9b6fb 100644
--- a/tools/xl/xl.h
+++ b/tools/xl/xl.h
@@ -156,6 +156,7 @@ int main_trigger(int argc, char **argv);
int main_sysrq(int argc, char **argv);
int main_debug_keys(int argc, char **argv);
int main_set_parameters(int argc, char **argv);
+int main_get_config(int argc, char **argv);
int main_dmesg(int argc, char **argv);
int main_top(int argc, char **argv);
int main_networkattach(int argc, char **argv);
diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c
index 89716badcb..c7e0e90bc4 100644
--- a/tools/xl/xl_cmdtable.c
+++ b/tools/xl/xl_cmdtable.c
@@ -320,6 +320,11 @@ struct cmd_spec cmd_table[] = {
"Set hypervisor parameters",
"<Params>",
},
+ { "get-config",
+ &main_get_config, 0, 0,
+ "Get hypervisor build config",
+ "",
+ },
{ "dmesg",
&main_dmesg, 0, 0,
"Read and/or clear dmesg buffer",
diff --git a/tools/xl/xl_misc.c b/tools/xl/xl_misc.c
index dcf940a6d4..07acd6cb57 100644
--- a/tools/xl/xl_misc.c
+++ b/tools/xl/xl_misc.c
@@ -175,6 +175,26 @@ int main_set_parameters(int argc, char **argv)
return EXIT_SUCCESS;
}
+int main_get_config(int argc, char **argv)
+{
+ int opt;
+ char *conf;
+
+ SWITCH_FOREACH_OPT(opt, "", NULL, "get-config", 0) {
+ /* No options */
+ }
+
+ if (libxl_get_config(ctx, &conf)) {
+ fprintf(stderr, "cannot get config\n");
+ return EXIT_FAILURE;
+ }
+
+ printf("%s\n", conf);
+ free(conf);
+
+ return EXIT_SUCCESS;
+}
+
int main_devd(int argc, char **argv)
{
int ret = 0, opt = 0, daemonize = 1;
--
2.16.4
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |