[libvirt] [PATCH 04/12] libxl: Add libxl_version_info to libxlDriverPrivate

Jim Fehlig jfehlig at suse.com
Fri Aug 30 21:46:50 UTC 2013


libxl version info is static data as far as the libxl driver
is concerned, so retrieve this info when the driver is initialized
and stash it in the libxlDriverPrivate object.  Subsequently use
the stashed info instead of repeatedly calling libxl_get_version_info().

Signed-off-by: Jim Fehlig <jfehlig at suse.com>
---
 src/libxl/libxl_conf.c   |  7 +------
 src/libxl/libxl_conf.h   |  1 +
 src/libxl/libxl_driver.c | 39 ++++++++-------------------------------
 3 files changed, 10 insertions(+), 37 deletions(-)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index f9ffe5d..81b4af4 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -981,21 +981,16 @@ error:
 bool
 libxlGetAutoballoonConf(libxlDriverPrivatePtr driver)
 {
-    const libxl_version_info *info;
     regex_t regex;
     int ret;
 
-    info = libxl_get_version_info(driver->ctx);
-    if (!info)
-        return true; /* default to on */
-
     ret = regcomp(&regex,
             "(^| )dom0_mem=((|min:|max:)[0-9]+[bBkKmMgG]?,?)+($| )",
             REG_NOSUB | REG_EXTENDED);
     if (ret)
         return true;
 
-    ret = regexec(&regex, info->commandline, 0, NULL, 0);
+    ret = regexec(&regex, driver->verInfo->commandline, 0, NULL, 0);
     regfree(&regex);
     return ret == REG_NOMATCH;
 }
diff --git a/src/libxl/libxl_conf.h b/src/libxl/libxl_conf.h
index 68e770c..be3a473 100644
--- a/src/libxl/libxl_conf.h
+++ b/src/libxl/libxl_conf.h
@@ -55,6 +55,7 @@ struct _libxlDriverPrivate {
     virMutex lock;
     virCapsPtr caps;
     virDomainXMLOptionPtr xmlopt;
+    const libxl_version_info *verInfo;
     unsigned int version;
 
     /* log stream for driver-wide libxl ctx */
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 759fed5..6fd9178 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -125,7 +125,6 @@ static int
 libxlDoNodeGetInfo(libxlDriverPrivatePtr driver, virNodeInfoPtr info)
 {
     libxl_physinfo phy_info;
-    const libxl_version_info* ver_info;
     virArch hostarch = virArchFromHost();
 
     if (libxl_get_physinfo(driver->ctx, &phy_info)) {
@@ -134,12 +133,6 @@ libxlDoNodeGetInfo(libxlDriverPrivatePtr driver, virNodeInfoPtr info)
         return -1;
     }
 
-    if ((ver_info = libxl_get_version_info(driver->ctx)) == NULL) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("libxl_get_version_info failed"));
-        return -1;
-    }
-
     if (virStrcpyStatic(info->model, virArchToString(hostarch)) == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("machine type %s too big for destination"),
@@ -147,7 +140,7 @@ libxlDoNodeGetInfo(libxlDriverPrivatePtr driver, virNodeInfoPtr info)
         return -1;
     }
 
-    info->memory = phy_info.total_pages * (ver_info->pagesize / 1024);
+    info->memory = phy_info.total_pages * (driver->verInfo->pagesize / 1024);
     info->cpus = phy_info.nr_cpus;
     info->nodes = phy_info.nr_nodes;
     info->cores = phy_info.cores_per_socket;
@@ -918,8 +911,9 @@ libxlStateInitialize(bool privileged,
         VIR_ERROR(_("Failed to get version information from libxenlight"));
         goto error;
     }
+    libxl_driver->verInfo = ver_info;
     libxl_driver->version = (ver_info->xen_version_major * 1000000) +
-            (ver_info->xen_version_minor * 1000);
+        (ver_info->xen_version_minor * 1000);
 
     if ((libxl_driver->caps =
          libxlMakeCapabilities(libxl_driver->ctx)) == NULL) {
@@ -2711,7 +2705,6 @@ libxlConnectDomainXMLFromNative(virConnectPtr conn, const char * nativeFormat,
                                 unsigned int flags)
 {
     libxlDriverPrivatePtr driver = conn->privateData;
-    const libxl_version_info *ver_info;
     virDomainDefPtr def = NULL;
     virConfPtr conf = NULL;
     char *xml = NULL;
@@ -2727,15 +2720,12 @@ libxlConnectDomainXMLFromNative(virConnectPtr conn, const char * nativeFormat,
         goto cleanup;
     }
 
-    if ((ver_info = libxl_get_version_info(driver->ctx)) == NULL) {
-        VIR_ERROR(_("cannot get version information from libxenlight"));
-        goto cleanup;
-    }
-
     if (!(conf = virConfReadMem(nativeConfig, strlen(nativeConfig), 0)))
         goto cleanup;
 
-    if (!(def = xenParseXM(conf, ver_info->xen_version_major, driver->caps))) {
+    if (!(def = xenParseXM(conf,
+                           driver->verInfo->xen_version_major,
+                           driver->caps))) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("parsing xm config failed"));
         goto cleanup;
     }
@@ -2756,7 +2746,6 @@ libxlConnectDomainXMLToNative(virConnectPtr conn, const char * nativeFormat,
                               unsigned int flags)
 {
     libxlDriverPrivatePtr driver = conn->privateData;
-    const libxl_version_info *ver_info;
     virDomainDefPtr def = NULL;
     virConfPtr conf = NULL;
     int len = MAX_CONFIG_SIZE;
@@ -2773,17 +2762,12 @@ libxlConnectDomainXMLToNative(virConnectPtr conn, const char * nativeFormat,
         goto cleanup;
     }
 
-    if ((ver_info = libxl_get_version_info(driver->ctx)) == NULL) {
-        VIR_ERROR(_("cannot get version information from libxenlight"));
-        goto cleanup;
-    }
-
     if (!(def = virDomainDefParseString(domainXml,
                                         driver->caps, driver->xmlopt,
                                         1 << VIR_DOMAIN_VIRT_XEN, 0)))
         goto cleanup;
 
-    if (!(conf = xenFormatXM(conn, def, ver_info->xen_version_major)))
+    if (!(conf = xenFormatXM(conn, def, driver->verInfo->xen_version_major)))
         goto cleanup;
 
     if (VIR_ALLOC_N(ret, len) < 0)
@@ -3685,7 +3669,6 @@ static unsigned long long
 libxlNodeGetFreeMemory(virConnectPtr conn)
 {
     libxl_physinfo phy_info;
-    const libxl_version_info* ver_info;
     libxlDriverPrivatePtr driver = conn->privateData;
 
     if (virNodeGetFreeMemoryEnsureACL(conn) < 0)
@@ -3697,13 +3680,7 @@ libxlNodeGetFreeMemory(virConnectPtr conn)
         return 0;
     }
 
-    if ((ver_info = libxl_get_version_info(driver->ctx)) == NULL) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("libxl_get_version_info failed"));
-        return 0;
-    }
-
-    return phy_info.free_pages * ver_info->pagesize;
+    return phy_info.free_pages * driver->verInfo->pagesize;
 }
 
 static int
-- 
1.8.1.4




More information about the libvir-list mailing list