[PATCH v4 2/8] libxl: pass driver config to libxlMakeDomBuildInfo

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

 



Preparation for global nestedhvm configuration - libxlMakeDomBuildInfo
needs access to libxlDriverConfig.
No functional change.

Adjusting tests require slightly more mockup functions, because of
libxlDriverConfigNew() call.

---
Changes since v3:
 - new patch, preparation
---
 src/libxl/libxl_conf.c         |  8 +++++---
 src/libxl/libxl_conf.h         |  2 +-
 src/libxl/libxl_domain.c       |  2 +-
 tests/libxlxml2domconfigtest.c | 20 +++++++++++++-------
 tests/virmocklibxl.c           | 25 +++++++++++++++++++++++++
 5 files changed, 45 insertions(+), 12 deletions(-)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 2d2a707..8cced29 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -271,10 +271,11 @@ libxlMakeChrdevStr(virDomainChrDefPtr def, char **buf)
 
 static int
 libxlMakeDomBuildInfo(virDomainDefPtr def,
-                      libxl_ctx *ctx,
+                      libxlDriverConfigPtr cfg,
                       virCapsPtr caps,
                       libxl_domain_config *d_config)
 {
+    libxl_ctx *ctx = cfg->ctx;
     libxl_domain_build_info *b_info = &d_config->b_info;
     int hvm = def->os.type == VIR_DOMAIN_OSTYPE_HVM;
     size_t i;
@@ -2288,16 +2289,17 @@ int
 libxlBuildDomainConfig(virPortAllocatorPtr graphicsports,
                        virDomainDefPtr def,
                        const char *channelDir LIBXL_ATTR_UNUSED,
-                       libxl_ctx *ctx,
+                       libxlDriverConfigPtr cfg,
                        virCapsPtr caps,
                        libxl_domain_config *d_config)
 {
+    libxl_ctx *ctx = cfg->ctx;
     libxl_domain_config_init(d_config);
 
     if (libxlMakeDomCreateInfo(ctx, def, &d_config->c_info) < 0)
         return -1;
 
-    if (libxlMakeDomBuildInfo(def, ctx, caps, d_config) < 0)
+    if (libxlMakeDomBuildInfo(def, cfg, caps, d_config) < 0)
         return -1;
 
 #ifdef LIBXL_HAVE_VNUMA
diff --git a/src/libxl/libxl_conf.h b/src/libxl/libxl_conf.h
index 264df11..8eefe06 100644
--- a/src/libxl/libxl_conf.h
+++ b/src/libxl/libxl_conf.h
@@ -216,7 +216,7 @@ int
 libxlBuildDomainConfig(virPortAllocatorPtr graphicsports,
                        virDomainDefPtr def,
                        const char *channelDir LIBXL_ATTR_UNUSED,
-                       libxl_ctx *ctx,
+                       libxlDriverConfigPtr cfg,
                        virCapsPtr caps,
                        libxl_domain_config *d_config);
 
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index 395c8a9..0a60444 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -1253,7 +1253,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver,
         goto cleanup_dom;
 
     if (libxlBuildDomainConfig(driver->reservedGraphicsPorts, vm->def,
-                               cfg->channelDir, cfg->ctx, cfg->caps, &d_config) < 0)
+                               cfg->channelDir, cfg, cfg->caps, &d_config) < 0)
         goto cleanup_dom;
 
     if (cfg->autoballoon && libxlDomainFreeMem(cfg->ctx, &d_config) < 0)
diff --git a/tests/libxlxml2domconfigtest.c b/tests/libxlxml2domconfigtest.c
index bd4c3af..0105550 100644
--- a/tests/libxlxml2domconfigtest.c
+++ b/tests/libxlxml2domconfigtest.c
@@ -56,8 +56,8 @@ testCompareXMLToDomConfig(const char *xmlfile,
     int ret = -1;
     libxl_domain_config actualconfig;
     libxl_domain_config expectconfig;
+    libxlDriverConfigPtr cfg;
     xentoollog_logger *log = NULL;
-    libxl_ctx *ctx = NULL;
     virPortAllocatorPtr gports = NULL;
     virDomainXMLOptionPtr xmlopt = NULL;
     virDomainDefPtr vmdef = NULL;
@@ -68,10 +68,16 @@ testCompareXMLToDomConfig(const char *xmlfile,
     libxl_domain_config_init(&actualconfig);
     libxl_domain_config_init(&expectconfig);
 
+    if (!(cfg = libxlDriverConfigNew()))
+        goto cleanup;
+
     if (!(log = (xentoollog_logger *)xtl_createlogger_stdiostream(stderr, XTL_DEBUG, 0)))
         goto cleanup;
 
-    if (libxl_ctx_alloc(&ctx, LIBXL_VERSION, 0, log) < 0)
+    /* replace logger with stderr one */
+    libxl_ctx_free(cfg->ctx);
+
+    if (libxl_ctx_alloc(&cfg->ctx, LIBXL_VERSION, 0, log) < 0)
         goto cleanup;
 
     if (!(gports = virPortAllocatorNew("vnc", 5900, 6000,
@@ -85,22 +91,22 @@ testCompareXMLToDomConfig(const char *xmlfile,
                                         NULL, VIR_DOMAIN_XML_INACTIVE)))
         goto cleanup;
 
-    if (libxlBuildDomainConfig(gports, vmdef, NULL, ctx, caps, &actualconfig) < 0)
+    if (libxlBuildDomainConfig(gports, vmdef, NULL, cfg, caps, &actualconfig) < 0)
         goto cleanup;
 
-    if (!(actualjson = libxl_domain_config_to_json(ctx, &actualconfig))) {
+    if (!(actualjson = libxl_domain_config_to_json(cfg->ctx, &actualconfig))) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        "Failed to retrieve JSON doc for libxl_domain_config");
         goto cleanup;
     }
 
     virTestLoadFile(jsonfile, &tempjson);
-    if (libxl_domain_config_from_json(ctx, &expectconfig, tempjson) != 0) {
+    if (libxl_domain_config_from_json(cfg->ctx, &expectconfig, tempjson) != 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        "Failed to create libxl_domain_config from JSON doc");
         goto cleanup;
     }
-    if (!(expectjson = libxl_domain_config_to_json(ctx, &expectconfig))) {
+    if (!(expectjson = libxl_domain_config_to_json(cfg->ctx, &expectconfig))) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        "Failed to retrieve JSON doc for libxl_domain_config");
         goto cleanup;
@@ -118,10 +124,10 @@ testCompareXMLToDomConfig(const char *xmlfile,
     virDomainDefFree(vmdef);
     virObjectUnref(gports);
     virObjectUnref(xmlopt);
-    libxl_ctx_free(ctx);
     libxl_domain_config_dispose(&actualconfig);
     libxl_domain_config_dispose(&expectconfig);
     xtl_logger_destroy(log);
+    virObjectUnref(cfg);
     return ret;
 }
 
diff --git a/tests/virmocklibxl.c b/tests/virmocklibxl.c
index 747f9f8..133064b 100644
--- a/tests/virmocklibxl.c
+++ b/tests/virmocklibxl.c
@@ -27,6 +27,7 @@
 # include <sys/stat.h>
 # include <unistd.h>
 # include <libxl.h>
+# include <util/virfile.h>
 # include <xenstore.h>
 # include <xenctrl.h>
 
@@ -48,6 +49,19 @@ VIR_MOCK_IMPL_RET_ARGS(xc_interface_open,
 }
 
 
+VIR_MOCK_IMPL_RET_ARGS(libxl_get_version_info,
+                       const libxl_version_info*,
+                       libxl_ctx *, ctx)
+{
+    static libxl_version_info info;
+
+    memset(&info, 0, sizeof(info));
+
+    return &info;
+    /* silence gcc warning */
+    return real_libxl_get_version_info(ctx);
+}
+
 VIR_MOCK_STUB_RET_ARGS(xc_interface_close,
                        int, 0,
                        xc_interface *, handle)
@@ -68,6 +82,17 @@ VIR_MOCK_STUB_RET_ARGS(xc_sharing_used_frames,
 VIR_MOCK_STUB_VOID_ARGS(xs_daemon_close,
                         struct xs_handle *, handle)
 
+VIR_MOCK_IMPL_RET_ARGS(virFileMakePath, int,
+                       const char *, path)
+{
+    /* replace log path with a writable directory */
+    if (strstr(path, "/log/")) {
+        snprintf((char*)path, strlen(path), ".");
+        return 0;
+    }
+    return real_virFileMakePath(path);
+}
+
 VIR_MOCK_IMPL_RET_ARGS(__xstat, int,
                        int, ver,
                        const char *, path,
-- 
git-series 0.9.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux