All of lore.kernel.org
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: xen-devel@lists.xenproject.org
Cc: Juergen Gross <jgross@suse.com>, Wei Liu <wei.liu2@citrix.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>
Subject: [PATCH v2 2/2] tools: add new xl command get-hypervisor-config
Date: Thu, 14 Mar 2019 12:59:37 +0100	[thread overview]
Message-ID: <20190314115937.26394-3-jgross@suse.com> (raw)
In-Reply-To: <20190314115937.26394-1-jgross@suse.com>

Add   new subcommand "get-hypervisor-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@suse.com>
---
V2:
- rename subcommand to get-hypervisor-config (Wei Liu)
- use goto style error handling (Wei Liu)
---
 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            | 34 ++++++++++++++++++++++++++++++++++
 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, 136 insertions(+), 4 deletions(-)

diff --git a/docs/man/xl.1.pod.in b/docs/man/xl.1.pod.in
index 4310fcd818..9d20958e91 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-hypervisor-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 a3628e56bb..c6a203e1a4 100644
--- a/tools/libxc/include/xenctrl.h
+++ b/tools/libxc/include/xenctrl.h
@@ -2632,6 +2632,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..e363371811 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -669,6 +669,40 @@ int libxl_set_parameters(libxl_ctx *ctx, char *params)
     return 0;
 }
 
+int libxl_get_hypervisor_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");
+        ret = ERROR_FAIL;
+        goto out;
+    }
+
+    *buffer = xc_inflate_buffer(ctx->xch, gz_buffer, gz_size, &out_size);
+
+    free(gz_buffer);
+
+    if (!*buffer) {
+        LOGE(ERROR, "decompressing config data failed");
+        ret = ERROR_FAIL;
+        goto out;
+    }
+
+    *buffer = libxl__realloc(NOGC, *buffer, out_size + 1);
+    (*buffer)[out_size] = 0;
+
+    ret = 0;
+
+out:
+    GC_FREE;
+    return ret;
+}
+
 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..0d48ac0ae3 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_HYPERVISOR_CONFIG
+ *
+ * If this is defined getting hypervisor config is supported.
+ */
+#define LIBXL_HAVE_GET_HYPERVISOR_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_hypervisor_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..cc537b07b9 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_hypervisor_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..53b1f1f922 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-hypervisor-config",
+      &main_get_hypervisor_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..00dd51e935 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_hypervisor_config(int argc, char **argv)
+{
+    int opt;
+    char *conf;
+
+    SWITCH_FOREACH_OPT(opt, "", NULL, "get-hypervisor-config", 0) {
+        /* No options */
+    }
+
+    if (libxl_get_hypervisor_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@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2019-03-14 11:59 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-14 11:59 [PATCH v2 0/2] add xl command to get hypervisor .config Juergen Gross
2019-03-14 11:59 ` [PATCH v2 1/2] xen: add interface for obtaining .config from hypervisor Juergen Gross
2019-03-14 12:27   ` Wei Liu
2019-03-15 13:57   ` Jan Beulich
     [not found]   ` <5C8BAF5A020000780021F53D@suse.com>
2019-03-15 14:01     ` Juergen Gross
2019-03-15 14:24       ` Jan Beulich
2019-03-15 15:55   ` Andrew Cooper
2019-03-15 16:29     ` Juergen Gross
2019-04-04 13:27       ` Wei Liu
2019-04-04 13:35         ` Juergen Gross
2019-08-05 15:07           ` [Xen-devel] " George Dunlap
2019-08-05 15:12             ` Juergen Gross
2019-03-15 18:57   ` Daniel De Graaf
2019-03-14 11:59 ` Juergen Gross [this message]
2019-03-14 12:27   ` [PATCH v2 2/2] tools: add new xl command get-hypervisor-config Wei Liu

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=20190314115937.26394-3-jgross@suse.com \
    --to=jgross@suse.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.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.