[xen master] tools/helpers: don't hardcode domain type for dom0 and xenstore domain

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[xen master] tools/helpers: don't hardcode domain type for dom0 and xenstore domain

patchbot
commit 7757cce0ab399eabf1d93e610f6c2dc1a7b5e185
Author:     Juergen Gross <[hidden email]>
AuthorDate: Wed Jul 25 16:50:40 2018 +0200
Commit:     Wei Liu <[hidden email]>
CommitDate: Fri Jul 27 09:27:26 2018 +0100

    tools/helpers: don't hardcode domain type for dom0 and xenstore domain
   
    Today when setting up a minimal domain configuration file for dom0 and
    eventually xenstore-domain the domain type is harcoded as PV. Change
    that by asking the hypervisor for the correct type.
   
    Signed-off-by: Juergen Gross <[hidden email]>
    Acked-by: Wei Liu <[hidden email]>
---
 tools/helpers/init-dom-json.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/tools/helpers/init-dom-json.c b/tools/helpers/init-dom-json.c
index 91b1fdf3db..704e7cb4f0 100644
--- a/tools/helpers/init-dom-json.c
+++ b/tools/helpers/init-dom-json.c
@@ -13,6 +13,7 @@ int gen_stub_json_config(uint32_t domid)
     xentoollog_logger_stdiostream *logger;
     libxl_ctx *ctx;
     libxl_domain_config dom_config;
+    libxl_dominfo dominfo;
     char *json = NULL;
 
     logger = xtl_createlogger_stdiostream(stderr, XTL_ERROR, 0);
@@ -27,10 +28,17 @@ int gen_stub_json_config(uint32_t domid)
 
     libxl_domain_config_init(&dom_config);
 
+    libxl_dominfo_init(&dominfo);
+    if (libxl_domain_info(ctx, &dominfo, domid)) {
+        fprintf(stderr, "cannot get domain type\n");
+        goto outdispose;
+    }
+
     /* Generate stub JSON config. */
-    dom_config.c_info.type = LIBXL_DOMAIN_TYPE_PV;
+    dom_config.c_info.type = (dominfo.domain_type == LIBXL_DOMAIN_TYPE_HVM)
+                             ? LIBXL_DOMAIN_TYPE_PVH : LIBXL_DOMAIN_TYPE_PV;
     libxl_domain_build_info_init_type(&dom_config.b_info,
-                                      LIBXL_DOMAIN_TYPE_PV);
+                                      dom_config.c_info.type);
 
     json = libxl_domain_config_to_json(ctx, &dom_config);
     /* libxl-json format requires the string ends with '\0'. Code
@@ -42,6 +50,8 @@ int gen_stub_json_config(uint32_t domid)
     if (rc)
         fprintf(stderr, "cannot store stub json config for domain %u\n", domid);
 
+outdispose:
+    libxl_dominfo_dispose(&dominfo);
     libxl_domain_config_dispose(&dom_config);
     free(json);
     libxl_ctx_free(ctx);
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
[hidden email]
https://lists.xenproject.org/xen-changelog