mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
libxl: Add libxl_version_info to libxlDriverPrivate
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().
This commit is contained in:
parent
2f8d0f9021
commit
cb0d49af11
@ -981,21 +981,16 @@ error:
|
|||||||
bool
|
bool
|
||||||
libxlGetAutoballoonConf(libxlDriverPrivatePtr driver)
|
libxlGetAutoballoonConf(libxlDriverPrivatePtr driver)
|
||||||
{
|
{
|
||||||
const libxl_version_info *info;
|
|
||||||
regex_t regex;
|
regex_t regex;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
info = libxl_get_version_info(driver->ctx);
|
|
||||||
if (!info)
|
|
||||||
return true; /* default to on */
|
|
||||||
|
|
||||||
ret = regcomp(®ex,
|
ret = regcomp(®ex,
|
||||||
"(^| )dom0_mem=((|min:|max:)[0-9]+[bBkKmMgG]?,?)+($| )",
|
"(^| )dom0_mem=((|min:|max:)[0-9]+[bBkKmMgG]?,?)+($| )",
|
||||||
REG_NOSUB | REG_EXTENDED);
|
REG_NOSUB | REG_EXTENDED);
|
||||||
if (ret)
|
if (ret)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
ret = regexec(®ex, info->commandline, 0, NULL, 0);
|
ret = regexec(®ex, driver->verInfo->commandline, 0, NULL, 0);
|
||||||
regfree(®ex);
|
regfree(®ex);
|
||||||
return ret == REG_NOMATCH;
|
return ret == REG_NOMATCH;
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,7 @@ struct _libxlDriverPrivate {
|
|||||||
virMutex lock;
|
virMutex lock;
|
||||||
virCapsPtr caps;
|
virCapsPtr caps;
|
||||||
virDomainXMLOptionPtr xmlopt;
|
virDomainXMLOptionPtr xmlopt;
|
||||||
|
const libxl_version_info *verInfo;
|
||||||
unsigned int version;
|
unsigned int version;
|
||||||
|
|
||||||
/* log stream for driver-wide libxl ctx */
|
/* log stream for driver-wide libxl ctx */
|
||||||
|
@ -125,7 +125,6 @@ static int
|
|||||||
libxlDoNodeGetInfo(libxlDriverPrivatePtr driver, virNodeInfoPtr info)
|
libxlDoNodeGetInfo(libxlDriverPrivatePtr driver, virNodeInfoPtr info)
|
||||||
{
|
{
|
||||||
libxl_physinfo phy_info;
|
libxl_physinfo phy_info;
|
||||||
const libxl_version_info* ver_info;
|
|
||||||
virArch hostarch = virArchFromHost();
|
virArch hostarch = virArchFromHost();
|
||||||
|
|
||||||
if (libxl_get_physinfo(driver->ctx, &phy_info)) {
|
if (libxl_get_physinfo(driver->ctx, &phy_info)) {
|
||||||
@ -134,12 +133,6 @@ libxlDoNodeGetInfo(libxlDriverPrivatePtr driver, virNodeInfoPtr info)
|
|||||||
return -1;
|
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) {
|
if (virStrcpyStatic(info->model, virArchToString(hostarch)) == NULL) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("machine type %s too big for destination"),
|
_("machine type %s too big for destination"),
|
||||||
@ -147,7 +140,7 @@ libxlDoNodeGetInfo(libxlDriverPrivatePtr driver, virNodeInfoPtr info)
|
|||||||
return -1;
|
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->cpus = phy_info.nr_cpus;
|
||||||
info->nodes = phy_info.nr_nodes;
|
info->nodes = phy_info.nr_nodes;
|
||||||
info->cores = phy_info.cores_per_socket;
|
info->cores = phy_info.cores_per_socket;
|
||||||
@ -931,6 +924,7 @@ libxlStateInitialize(bool privileged,
|
|||||||
_("failed to get version information from libxenlight"));
|
_("failed to get version information from libxenlight"));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
libxl_driver->verInfo = ver_info;
|
||||||
libxl_driver->version = (ver_info->xen_version_major * 1000000) +
|
libxl_driver->version = (ver_info->xen_version_major * 1000000) +
|
||||||
(ver_info->xen_version_minor * 1000);
|
(ver_info->xen_version_minor * 1000);
|
||||||
|
|
||||||
@ -2728,7 +2722,6 @@ libxlConnectDomainXMLFromNative(virConnectPtr conn, const char * nativeFormat,
|
|||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
libxlDriverPrivatePtr driver = conn->privateData;
|
libxlDriverPrivatePtr driver = conn->privateData;
|
||||||
const libxl_version_info *ver_info;
|
|
||||||
virDomainDefPtr def = NULL;
|
virDomainDefPtr def = NULL;
|
||||||
virConfPtr conf = NULL;
|
virConfPtr conf = NULL;
|
||||||
char *xml = NULL;
|
char *xml = NULL;
|
||||||
@ -2744,15 +2737,12 @@ libxlConnectDomainXMLFromNative(virConnectPtr conn, const char * nativeFormat,
|
|||||||
goto cleanup;
|
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)))
|
if (!(conf = virConfReadMem(nativeConfig, strlen(nativeConfig), 0)))
|
||||||
goto cleanup;
|
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"));
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("parsing xm config failed"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -2773,7 +2763,6 @@ libxlConnectDomainXMLToNative(virConnectPtr conn, const char * nativeFormat,
|
|||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
libxlDriverPrivatePtr driver = conn->privateData;
|
libxlDriverPrivatePtr driver = conn->privateData;
|
||||||
const libxl_version_info *ver_info;
|
|
||||||
virDomainDefPtr def = NULL;
|
virDomainDefPtr def = NULL;
|
||||||
virConfPtr conf = NULL;
|
virConfPtr conf = NULL;
|
||||||
int len = MAX_CONFIG_SIZE;
|
int len = MAX_CONFIG_SIZE;
|
||||||
@ -2790,17 +2779,12 @@ libxlConnectDomainXMLToNative(virConnectPtr conn, const char * nativeFormat,
|
|||||||
goto cleanup;
|
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,
|
if (!(def = virDomainDefParseString(domainXml,
|
||||||
driver->caps, driver->xmlopt,
|
driver->caps, driver->xmlopt,
|
||||||
1 << VIR_DOMAIN_VIRT_XEN, 0)))
|
1 << VIR_DOMAIN_VIRT_XEN, 0)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(conf = xenFormatXM(conn, def, ver_info->xen_version_major)))
|
if (!(conf = xenFormatXM(conn, def, driver->verInfo->xen_version_major)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (VIR_ALLOC_N(ret, len) < 0)
|
if (VIR_ALLOC_N(ret, len) < 0)
|
||||||
@ -3702,7 +3686,6 @@ static unsigned long long
|
|||||||
libxlNodeGetFreeMemory(virConnectPtr conn)
|
libxlNodeGetFreeMemory(virConnectPtr conn)
|
||||||
{
|
{
|
||||||
libxl_physinfo phy_info;
|
libxl_physinfo phy_info;
|
||||||
const libxl_version_info* ver_info;
|
|
||||||
libxlDriverPrivatePtr driver = conn->privateData;
|
libxlDriverPrivatePtr driver = conn->privateData;
|
||||||
|
|
||||||
if (virNodeGetFreeMemoryEnsureACL(conn) < 0)
|
if (virNodeGetFreeMemoryEnsureACL(conn) < 0)
|
||||||
@ -3714,13 +3697,7 @@ libxlNodeGetFreeMemory(virConnectPtr conn)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ver_info = libxl_get_version_info(driver->ctx)) == NULL) {
|
return phy_info.free_pages * driver->verInfo->pagesize;
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_("libxl_get_version_info failed"));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return phy_info.free_pages * ver_info->pagesize;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
Loading…
x
Reference in New Issue
Block a user