]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
libxl: Add libxl_version_info to libxlDriverPrivate
authorJim Fehlig <jfehlig@suse.com>
Fri, 30 Aug 2013 20:32:10 +0000 (14:32 -0600)
committerJim Fehlig <jfehlig@suse.com>
Tue, 3 Sep 2013 22:43:20 +0000 (16:43 -0600)
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().

src/libxl/libxl_conf.c
src/libxl/libxl_conf.h
src/libxl/libxl_driver.c

index f9ffe5de564681e78eebfabab6fd90ebae63c8e7..81b4af4465d7ed94e65eef3a1ae1b41cbf4d8e1d 100644 (file)
@@ -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;
 }
index 68e770c88dc0893d33346f6a3c9cef73aea15a78..be3a473e7b26d40f9219c609e847bd6d4bc974a4 100644 (file)
@@ -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 */
index a18032b6d7ef7f99922964c04ca60996e66c686c..b8c34f7618f535fa5c3b6740c93c3a8fff67b793 100644 (file)
@@ -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;
@@ -931,8 +924,9 @@ libxlStateInitialize(bool privileged,
                        _("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) {
@@ -2728,7 +2722,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;
@@ -2744,15 +2737,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;
     }
@@ -2773,7 +2763,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;
@@ -2790,17 +2779,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)
@@ -3702,7 +3686,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)
@@ -3714,13 +3697,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