[libvirt] [PATCH 0/3] bhyve: capabilities and CPU-capabilities support

Add following changes: - support for connectBaselineCPU (required by OpenStack) - move capabilites functions to separate file + API change - implement connectCompareCPU Wojciech Macek (3): bhyve: support for connectBaselineCPU bhyve: create capabilities submodule bhyve: connectCompareCPU support src/Makefile.am | 2 + src/bhyve/bhyve_capabilities.c | 105 ++++++++++++++++++++++++++++++++++++++++ src/bhyve/bhyve_capabilities.h | 30 ++++++++++++ src/bhyve/bhyve_driver.c | 107 ++++++++++++++++++++++++++++++++--------- 4 files changed, 222 insertions(+), 22 deletions(-) create mode 100644 src/bhyve/bhyve_capabilities.c create mode 100644 src/bhyve/bhyve_capabilities.h -- 1.9.0

Implement bhyveConnectBaselineCPU to support OpenStack/Nova --- src/bhyve/bhyve_driver.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 7a12d69..3321a79 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -806,6 +806,25 @@ bhyveNodeSetMemoryParameters(virConnectPtr conn, return nodeSetMemoryParameters(params, nparams, flags); } +static char * +bhyveConnectBaselineCPU(virConnectPtr conn ATTRIBUTE_UNUSED, + const char **xmlCPUs, + unsigned int ncpus, + unsigned int flags) +{ + char *cpu = NULL; + + virCheckFlags(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES, NULL); + + if (virConnectBaselineCPUEnsureACL(conn) < 0) + goto cleanup; + + cpu = cpuBaselineXML(xmlCPUs, ncpus, NULL, 0, flags); + + cleanup: + return cpu; +} + static virDriver bhyveDriver = { .no = VIR_DRV_BHYVE, .name = "bhyve", @@ -840,6 +859,7 @@ static virDriver bhyveDriver = { .nodeGetCPUMap = bhyveNodeGetCPUMap, /* 1.2.3 */ .nodeGetMemoryParameters = bhyveNodeGetMemoryParameters, /* 1.2.3 */ .nodeSetMemoryParameters = bhyveNodeSetMemoryParameters, /* 1.2.3 */ + .connectBaselineCPU = bhyveConnectBaselineCPU, /* 1.2.4 */ }; -- 1.9.0

- Move all capabilities functions to separate file - Add initCPU --- src/Makefile.am | 2 + src/bhyve/bhyve_capabilities.c | 105 +++++++++++++++++++++++++++++++++++++++++ src/bhyve/bhyve_capabilities.h | 30 ++++++++++++ src/bhyve/bhyve_driver.c | 56 +++++++++++++--------- 4 files changed, 171 insertions(+), 22 deletions(-) create mode 100644 src/bhyve/bhyve_capabilities.c create mode 100644 src/bhyve/bhyve_capabilities.h diff --git a/src/Makefile.am b/src/Makefile.am index 55427ed..c715422 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -780,6 +780,8 @@ PARALLELS_DRIVER_SOURCES = \ parallels/parallels_network.c BHYVE_DRIVER_SOURCES = \ + bhyve/bhyve_capabilities.c \ + bhyve/bhyve_capabilities.h \ bhyve/bhyve_command.c \ bhyve/bhyve_command.h \ bhyve/bhyve_driver.h \ diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c new file mode 100644 index 0000000..b8a9db4 --- /dev/null +++ b/src/bhyve/bhyve_capabilities.c @@ -0,0 +1,105 @@ +/* + * bhyve_capabilities.c: bhyve capabilities module + * + * Copyright (C) 2014 Wojciech Macek <wma@semihalf.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + */ +#include <config.h> +#include <sys/utsname.h> + +#include "viralloc.h" +#include "virlog.h" +#include "virstring.h" +#include "cpu/cpu.h" +#include "nodeinfo.h" +#include "bhyve_utils.h" +#include "domain_conf.h" +#include "vircommand.h" +#include "bhyve_capabilities.h" + +#define VIR_FROM_THIS VIR_FROM_BHYVE + +VIR_LOG_INIT("bhyve.bhyve_capabilities"); + +static int +virBhyveCapsInitCPU(virCapsPtr caps, + virArch arch) +{ + virCPUDefPtr cpu = NULL; + virCPUDataPtr data = NULL; + virNodeInfo nodeinfo; + int ret = -1; + + if (VIR_ALLOC(cpu) < 0) + goto error; + + cpu->arch = arch; + + if (nodeGetInfo(&nodeinfo)) + goto error; + + cpu->type = VIR_CPU_TYPE_HOST; + cpu->sockets = nodeinfo.sockets; + cpu->cores = nodeinfo.cores; + cpu->threads = nodeinfo.threads; + caps->host.cpu = cpu; + + if (!(data = cpuNodeData(arch)) + || cpuDecode(cpu, data, NULL, 0, NULL) < 0) + goto cleanup; + + ret = 0; + + cleanup: + cpuDataFree(data); + + return ret; + + error: + virCPUDefFree(cpu); + goto cleanup; +} + +virCapsPtr +virBhyveCapsBuild(void) +{ + virCapsPtr caps; + virCapsGuestPtr guest; + + if ((caps = virCapabilitiesNew(virArchFromHost(), + 0, 0)) == NULL) + return NULL; + + if ((guest = virCapabilitiesAddGuest(caps, "hvm", + VIR_ARCH_X86_64, + "bhyve", + NULL, 0, NULL)) == NULL) + goto error; + + if (virCapabilitiesAddGuestDomain(guest, + "bhyve", NULL, NULL, 0, NULL) == NULL) + goto error; + + if (virBhyveCapsInitCPU(caps, virArchFromHost()) < 0) + VIR_WARN("Failed to get host CPU"); + + return caps; + + error: + virObjectUnref(caps); + return NULL; +} diff --git a/src/bhyve/bhyve_capabilities.h b/src/bhyve/bhyve_capabilities.h new file mode 100644 index 0000000..efe496e --- /dev/null +++ b/src/bhyve/bhyve_capabilities.h @@ -0,0 +1,30 @@ +/* + * bhyve_capabilities.h: bhyve capabilities module + * + * Copyright (C) 2014 Wojciech Macek <wma@semihalf.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#ifndef _BHYVE_CAPABILITIES +#define _BHYVE_CAPABILITIES + +#include "capabilities.h" + +virCapsPtr virBhyveCapsBuild(void); + +#endif + diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 3321a79..ef9192a 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -53,6 +53,7 @@ #include "bhyve_driver.h" #include "bhyve_process.h" #include "bhyve_utils.h" +#include "bhyve_capabilities.h" #define VIR_FROM_THIS VIR_FROM_BHYVE @@ -72,44 +73,49 @@ bhyveDriverUnlock(bhyveConnPtr driver) virMutexUnlock(&driver->lock); } +/** + * bhyveDriverGetCapabilities: + * + * Get a reference to the virCapsPtr instance for the + * driver. + * + * The caller must release the reference with virObjetUnref + * + * Returns: a reference to a virCapsPtr instance or NULL + */ static virCapsPtr -bhyveBuildCapabilities(void) +bhyveDriverGetCapabilities(bhyveConnPtr driver) { - virCapsPtr caps; - virCapsGuestPtr guest; + virCapsPtr ret = NULL; - if ((caps = virCapabilitiesNew(virArchFromHost(), - 0, 0)) == NULL) + if(driver == NULL) return NULL; - if ((guest = virCapabilitiesAddGuest(caps, "hvm", - VIR_ARCH_X86_64, - "bhyve", - NULL, 0, NULL)) == NULL) - goto error; + ret = virObjectRef(driver->caps); - if (virCapabilitiesAddGuestDomain(guest, - "bhyve", NULL, NULL, 0, NULL) == NULL) - goto error; - - return caps; - - error: - virObjectUnref(caps); - return NULL; + return ret; } static char * bhyveConnectGetCapabilities(virConnectPtr conn) { bhyveConnPtr privconn = conn->privateData; + virCapsPtr caps; char *xml; if (virConnectGetCapabilitiesEnsureACL(conn) < 0) return NULL; - if ((xml = virCapabilitiesFormatXML(privconn->caps)) == NULL) + caps = bhyveDriverGetCapabilities(privconn); + if (!caps) + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to get Capabilities")); + + if ((xml = virCapabilitiesFormatXML(privconn->caps)) == NULL) { + virObjectUnref(caps); virReportOOMError(); + } + virObjectUnref(caps); return xml; } @@ -326,8 +332,13 @@ bhyveDomainDefineXML(virConnectPtr conn, const char *xml) virDomainDefPtr def = NULL; virDomainDefPtr oldDef = NULL; virDomainObjPtr vm = NULL; + virCapsPtr caps = NULL; + + caps = bhyveDriverGetCapabilities(privconn); + if (!caps) + return NULL; - if ((def = virDomainDefParseString(xml, privconn->caps, privconn->xmlopt, + if ((def = virDomainDefParseString(xml, caps, privconn->xmlopt, 1 << VIR_DOMAIN_VIRT_BHYVE, VIR_DOMAIN_XML_INACTIVE)) == NULL) goto cleanup; @@ -350,6 +361,7 @@ bhyveDomainDefineXML(virConnectPtr conn, const char *xml) goto cleanup; cleanup: + virObjectUnref(caps); virDomainDefFree(def); virObjectUnlock(vm); @@ -704,7 +716,7 @@ bhyveStateInitialize(bool priveleged ATTRIBUTE_UNUSED, if (!(bhyve_driver->closeCallbacks = virCloseCallbacksNew())) goto cleanup; - if (!(bhyve_driver->caps = bhyveBuildCapabilities())) + if (!(bhyve_driver->caps = virBhyveCapsBuild())) goto cleanup; if (!(bhyve_driver->xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL))) -- 1.9.0

Adding one minor change to copyrights header... - Move all capabilities functions to separate file - Add initCPU --- src/Makefile.am | 2 + src/bhyve/bhyve_capabilities.c | 105 ++++++++++++++++++++++++++++++ +++++++++++ src/bhyve/bhyve_capabilities.h | 30 ++++++++++++ src/bhyve/bhyve_driver.c | 56 +++++++++++++--------- 4 files changed, 171 insertions(+), 22 deletions(-) create mode 100644 src/bhyve/bhyve_capabilities.c create mode 100644 src/bhyve/bhyve_capabilities.h diff --git a/src/Makefile.am b/src/Makefile.am index 55427ed..c715422 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -780,6 +780,8 @@ PARALLELS_DRIVER_SOURCES = \ parallels/parallels_network.c BHYVE_DRIVER_SOURCES = \ + bhyve/bhyve_capabilities.c \ + bhyve/bhyve_capabilities.h \ bhyve/bhyve_command.c \ bhyve/bhyve_command.h \ bhyve/bhyve_driver.h \ diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c new file mode 100644 index 0000000..b8a9db4 --- /dev/null +++ b/src/bhyve/bhyve_capabilities.c @@ -0,0 +1,105 @@ +/* + * bhyve_capabilities.c: bhyve capabilities module + * + * Copyright (C) 2014 Semihalf + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + */ +#include <config.h> +#include <sys/utsname.h> + +#include "viralloc.h" +#include "virlog.h" +#include "virstring.h" +#include "cpu/cpu.h" +#include "nodeinfo.h" +#include "bhyve_utils.h" +#include "domain_conf.h" +#include "vircommand.h" +#include "bhyve_capabilities.h" + +#define VIR_FROM_THIS VIR_FROM_BHYVE + +VIR_LOG_INIT("bhyve.bhyve_capabilities"); + +static int +virBhyveCapsInitCPU(virCapsPtr caps, + virArch arch) +{ + virCPUDefPtr cpu = NULL; + virCPUDataPtr data = NULL; + virNodeInfo nodeinfo; + int ret = -1; + + if (VIR_ALLOC(cpu) < 0) + goto error; + + cpu->arch = arch; + + if (nodeGetInfo(&nodeinfo)) + goto error; + + cpu->type = VIR_CPU_TYPE_HOST; + cpu->sockets = nodeinfo.sockets; + cpu->cores = nodeinfo.cores; + cpu->threads = nodeinfo.threads; + caps->host.cpu = cpu; + + if (!(data = cpuNodeData(arch)) + || cpuDecode(cpu, data, NULL, 0, NULL) < 0) + goto cleanup; + + ret = 0; + + cleanup: + cpuDataFree(data); + + return ret; + + error: + virCPUDefFree(cpu); + goto cleanup; +} + +virCapsPtr +virBhyveCapsBuild(void) +{ + virCapsPtr caps; + virCapsGuestPtr guest; + + if ((caps = virCapabilitiesNew(virArchFromHost(), + 0, 0)) == NULL) + return NULL; + + if ((guest = virCapabilitiesAddGuest(caps, "hvm", + VIR_ARCH_X86_64, + "bhyve", + NULL, 0, NULL)) == NULL) + goto error; + + if (virCapabilitiesAddGuestDomain(guest, + "bhyve", NULL, NULL, 0, NULL) == NULL) + goto error; + + if (virBhyveCapsInitCPU(caps, virArchFromHost()) < 0) + VIR_WARN("Failed to get host CPU"); + + return caps; + + error: + virObjectUnref(caps); + return NULL; +} diff --git a/src/bhyve/bhyve_capabilities.h b/src/bhyve/bhyve_capabilities.h new file mode 100644 index 0000000..efe496e --- /dev/null +++ b/src/bhyve/bhyve_capabilities.h @@ -0,0 +1,30 @@ +/* + * bhyve_capabilities.h: bhyve capabilities module + * + * Copyright (C) 2014 Semihalf + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#ifndef _BHYVE_CAPABILITIES +#define _BHYVE_CAPABILITIES + +#include "capabilities.h" + +virCapsPtr virBhyveCapsBuild(void); + +#endif + diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 3321a79..ef9192a 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -53,6 +53,7 @@ #include "bhyve_driver.h" #include "bhyve_process.h" #include "bhyve_utils.h" +#include "bhyve_capabilities.h" #define VIR_FROM_THIS VIR_FROM_BHYVE @@ -72,44 +73,49 @@ bhyveDriverUnlock(bhyveConnPtr driver) virMutexUnlock(&driver->lock); } +/** + * bhyveDriverGetCapabilities: + * + * Get a reference to the virCapsPtr instance for the + * driver. + * + * The caller must release the reference with virObjetUnref + * + * Returns: a reference to a virCapsPtr instance or NULL + */ static virCapsPtr -bhyveBuildCapabilities(void) +bhyveDriverGetCapabilities(bhyveConnPtr driver) { - virCapsPtr caps; - virCapsGuestPtr guest; + virCapsPtr ret = NULL; - if ((caps = virCapabilitiesNew(virArchFromHost(), - 0, 0)) == NULL) + if(driver == NULL) return NULL; - if ((guest = virCapabilitiesAddGuest(caps, "hvm", - VIR_ARCH_X86_64, - "bhyve", - NULL, 0, NULL)) == NULL) - goto error; + ret = virObjectRef(driver->caps); - if (virCapabilitiesAddGuestDomain(guest, - "bhyve", NULL, NULL, 0, NULL) == NULL) - goto error; - - return caps; - - error: - virObjectUnref(caps); - return NULL; + return ret; } static char * bhyveConnectGetCapabilities(virConnectPtr conn) { bhyveConnPtr privconn = conn->privateData; + virCapsPtr caps; char *xml; if (virConnectGetCapabilitiesEnsureACL(conn) < 0) return NULL; - if ((xml = virCapabilitiesFormatXML(privconn->caps)) == NULL) + caps = bhyveDriverGetCapabilities(privconn); + if (!caps) + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to get Capabilities")); + + if ((xml = virCapabilitiesFormatXML(privconn->caps)) == NULL) { + virObjectUnref(caps); virReportOOMError(); + } + virObjectUnref(caps); return xml; } @@ -326,8 +332,13 @@ bhyveDomainDefineXML(virConnectPtr conn, const char *xml) virDomainDefPtr def = NULL; virDomainDefPtr oldDef = NULL; virDomainObjPtr vm = NULL; + virCapsPtr caps = NULL; + + caps = bhyveDriverGetCapabilities(privconn); + if (!caps) + return NULL; - if ((def = virDomainDefParseString(xml, privconn->caps, privconn->xmlopt, + if ((def = virDomainDefParseString(xml, caps, privconn->xmlopt, 1 << VIR_DOMAIN_VIRT_BHYVE, VIR_DOMAIN_XML_INACTIVE)) == NULL) goto cleanup; @@ -350,6 +361,7 @@ bhyveDomainDefineXML(virConnectPtr conn, const char *xml) goto cleanup; cleanup: + virObjectUnref(caps); virDomainDefFree(def); virObjectUnlock(vm); @@ -704,7 +716,7 @@ bhyveStateInitialize(bool priveleged ATTRIBUTE_UNUSED, if (!(bhyve_driver->closeCallbacks = virCloseCallbacksNew())) goto cleanup; - if (!(bhyve_driver->caps = bhyveBuildCapabilities())) + if (!(bhyve_driver->caps = virBhyveCapsBuild())) goto cleanup; if (!(bhyve_driver->xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL))) 2014-03-31 12:54 GMT+02:00 Wojciech Macek <wma@semihalf.com>:
- Move all capabilities functions to separate file - Add initCPU --- src/Makefile.am | 2 + src/bhyve/bhyve_capabilities.c | 105 +++++++++++++++++++++++++++++++++++++++++ src/bhyve/bhyve_capabilities.h | 30 ++++++++++++ src/bhyve/bhyve_driver.c | 56 +++++++++++++--------- 4 files changed, 171 insertions(+), 22 deletions(-) create mode 100644 src/bhyve/bhyve_capabilities.c create mode 100644 src/bhyve/bhyve_capabilities.h
diff --git a/src/Makefile.am b/src/Makefile.am index 55427ed..c715422 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -780,6 +780,8 @@ PARALLELS_DRIVER_SOURCES = \ parallels/parallels_network.c
BHYVE_DRIVER_SOURCES = \ + bhyve/bhyve_capabilities.c \ + bhyve/bhyve_capabilities.h \ bhyve/bhyve_command.c \ bhyve/bhyve_command.h \ bhyve/bhyve_driver.h \ diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c new file mode 100644 index 0000000..b8a9db4 --- /dev/null +++ b/src/bhyve/bhyve_capabilities.c @@ -0,0 +1,105 @@ +/* + * bhyve_capabilities.c: bhyve capabilities module + * + * Copyright (C) 2014 Wojciech Macek <wma@semihalf.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + */ +#include <config.h> +#include <sys/utsname.h> + +#include "viralloc.h" +#include "virlog.h" +#include "virstring.h" +#include "cpu/cpu.h" +#include "nodeinfo.h" +#include "bhyve_utils.h" +#include "domain_conf.h" +#include "vircommand.h" +#include "bhyve_capabilities.h" + +#define VIR_FROM_THIS VIR_FROM_BHYVE + +VIR_LOG_INIT("bhyve.bhyve_capabilities"); + +static int +virBhyveCapsInitCPU(virCapsPtr caps, + virArch arch) +{ + virCPUDefPtr cpu = NULL; + virCPUDataPtr data = NULL; + virNodeInfo nodeinfo; + int ret = -1; + + if (VIR_ALLOC(cpu) < 0) + goto error; + + cpu->arch = arch; + + if (nodeGetInfo(&nodeinfo)) + goto error; + + cpu->type = VIR_CPU_TYPE_HOST; + cpu->sockets = nodeinfo.sockets; + cpu->cores = nodeinfo.cores; + cpu->threads = nodeinfo.threads; + caps->host.cpu = cpu; + + if (!(data = cpuNodeData(arch)) + || cpuDecode(cpu, data, NULL, 0, NULL) < 0) + goto cleanup; + + ret = 0; + + cleanup: + cpuDataFree(data); + + return ret; + + error: + virCPUDefFree(cpu); + goto cleanup; +} + +virCapsPtr +virBhyveCapsBuild(void) +{ + virCapsPtr caps; + virCapsGuestPtr guest; + + if ((caps = virCapabilitiesNew(virArchFromHost(), + 0, 0)) == NULL) + return NULL; + + if ((guest = virCapabilitiesAddGuest(caps, "hvm", + VIR_ARCH_X86_64, + "bhyve", + NULL, 0, NULL)) == NULL) + goto error; + + if (virCapabilitiesAddGuestDomain(guest, + "bhyve", NULL, NULL, 0, NULL) == NULL) + goto error; + + if (virBhyveCapsInitCPU(caps, virArchFromHost()) < 0) + VIR_WARN("Failed to get host CPU"); + + return caps; + + error: + virObjectUnref(caps); + return NULL; +} diff --git a/src/bhyve/bhyve_capabilities.h b/src/bhyve/bhyve_capabilities.h new file mode 100644 index 0000000..efe496e --- /dev/null +++ b/src/bhyve/bhyve_capabilities.h @@ -0,0 +1,30 @@ +/* + * bhyve_capabilities.h: bhyve capabilities module + * + * Copyright (C) 2014 Wojciech Macek <wma@semihalf.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#ifndef _BHYVE_CAPABILITIES +#define _BHYVE_CAPABILITIES + +#include "capabilities.h" + +virCapsPtr virBhyveCapsBuild(void); + +#endif + diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 3321a79..ef9192a 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -53,6 +53,7 @@ #include "bhyve_driver.h" #include "bhyve_process.h" #include "bhyve_utils.h" +#include "bhyve_capabilities.h"
#define VIR_FROM_THIS VIR_FROM_BHYVE
@@ -72,44 +73,49 @@ bhyveDriverUnlock(bhyveConnPtr driver) virMutexUnlock(&driver->lock); }
+/** + * bhyveDriverGetCapabilities: + * + * Get a reference to the virCapsPtr instance for the + * driver. + * + * The caller must release the reference with virObjetUnref + * + * Returns: a reference to a virCapsPtr instance or NULL + */ static virCapsPtr -bhyveBuildCapabilities(void) +bhyveDriverGetCapabilities(bhyveConnPtr driver) { - virCapsPtr caps; - virCapsGuestPtr guest; + virCapsPtr ret = NULL;
- if ((caps = virCapabilitiesNew(virArchFromHost(), - 0, 0)) == NULL) + if(driver == NULL) return NULL;
- if ((guest = virCapabilitiesAddGuest(caps, "hvm", - VIR_ARCH_X86_64, - "bhyve", - NULL, 0, NULL)) == NULL) - goto error; + ret = virObjectRef(driver->caps);
- if (virCapabilitiesAddGuestDomain(guest, - "bhyve", NULL, NULL, 0, NULL) == NULL) - goto error; - - return caps; - - error: - virObjectUnref(caps); - return NULL; + return ret; }
static char * bhyveConnectGetCapabilities(virConnectPtr conn) { bhyveConnPtr privconn = conn->privateData; + virCapsPtr caps; char *xml;
if (virConnectGetCapabilitiesEnsureACL(conn) < 0) return NULL;
- if ((xml = virCapabilitiesFormatXML(privconn->caps)) == NULL) + caps = bhyveDriverGetCapabilities(privconn); + if (!caps) + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to get Capabilities")); + + if ((xml = virCapabilitiesFormatXML(privconn->caps)) == NULL) { + virObjectUnref(caps); virReportOOMError(); + } + virObjectUnref(caps);
return xml; } @@ -326,8 +332,13 @@ bhyveDomainDefineXML(virConnectPtr conn, const char *xml) virDomainDefPtr def = NULL; virDomainDefPtr oldDef = NULL; virDomainObjPtr vm = NULL; + virCapsPtr caps = NULL; + + caps = bhyveDriverGetCapabilities(privconn); + if (!caps) + return NULL;
- if ((def = virDomainDefParseString(xml, privconn->caps, privconn->xmlopt, + if ((def = virDomainDefParseString(xml, caps, privconn->xmlopt, 1 << VIR_DOMAIN_VIRT_BHYVE, VIR_DOMAIN_XML_INACTIVE)) == NULL) goto cleanup; @@ -350,6 +361,7 @@ bhyveDomainDefineXML(virConnectPtr conn, const char *xml) goto cleanup;
cleanup: + virObjectUnref(caps); virDomainDefFree(def); virObjectUnlock(vm);
@@ -704,7 +716,7 @@ bhyveStateInitialize(bool priveleged ATTRIBUTE_UNUSED, if (!(bhyve_driver->closeCallbacks = virCloseCallbacksNew())) goto cleanup;
- if (!(bhyve_driver->caps = bhyveBuildCapabilities())) + if (!(bhyve_driver->caps = virBhyveCapsBuild())) goto cleanup;
if (!(bhyve_driver->xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL))) -- 1.9.0

On 02.04.2014 10:30, Wojciech Macek wrote:
Adding one minor change to copyrights header...
- Move all capabilities functions to separate file - Add initCPU --- src/Makefile.am | 2 + src/bhyve/bhyve_capabilities.c | 105 ++++++++++++++++++++++++++++++ +++++++++++ src/bhyve/bhyve_capabilities.h | 30 ++++++++++++ src/bhyve/bhyve_driver.c | 56 +++++++++++++--------- 4 files changed, 171 insertions(+), 22 deletions(-) create mode 100644 src/bhyve/bhyve_capabilities.c create mode 100644 src/bhyve/bhyve_capabilities.h
This is not the best way to send patch as reply. I see you've used git send-email to send the previous patches. If you want to send a v2 just to a specific one (say 2/3), you should use git send-email too; just specify in-reply-to and adjust subject prefix: PATCHv2: .... Moreover, sending patches other way than git send-email is tricky as you need to make sure the lines are not wrapped (yes, it happened in this case too). Can you resend the v2? It's okay to send v2 just to a single patch. Michal

Michal Privoznik wrote:
On 02.04.2014 10:30, Wojciech Macek wrote:
Adding one minor change to copyrights header...
- Move all capabilities functions to separate file - Add initCPU --- src/Makefile.am | 2 + src/bhyve/bhyve_capabilities.c | 105 ++++++++++++++++++++++++++++++ +++++++++++ src/bhyve/bhyve_capabilities.h | 30 ++++++++++++ src/bhyve/bhyve_driver.c | 56 +++++++++++++--------- 4 files changed, 171 insertions(+), 22 deletions(-) create mode 100644 src/bhyve/bhyve_capabilities.c create mode 100644 src/bhyve/bhyve_capabilities.h
This is not the best way to send patch as reply. I see you've used git send-email to send the previous patches. If you want to send a v2 just to a specific one (say 2/3), you should use git send-email too; just specify in-reply-to and adjust subject prefix: PATCHv2: .... Moreover, sending patches other way than git send-email is tricky as you need to make sure the lines are not wrapped (yes, it happened in this case too).
And for minor changes I think it's easier to just command so the person who will be pushing that could just squash that in instead of re-applying the series. As for the copyright change, I think, technically, I should be on a list for bhyve_capabilities.c as well because it still contains some of the code I previously wrote :-)
Can you resend the v2? It's okay to send v2 just to a single patch.
Agreed, and v2 would be useful for another reason: I wasn't able to apply this patch, git am gives me: fatal: sha1 information is lacking or useless (src/bhyve/bhyve_driver.c). I'd guess it reference some non-published or changed commit? Thanks, Roman Bogorodskiy

Wojciech Macek wrote:
- Move all capabilities functions to separate file - Add initCPU --- src/Makefile.am | 2 + src/bhyve/bhyve_capabilities.c | 105 +++++++++++++++++++++++++++++++++++++++++ src/bhyve/bhyve_capabilities.h | 30 ++++++++++++ src/bhyve/bhyve_driver.c | 56 +++++++++++++--------- 4 files changed, 171 insertions(+), 22 deletions(-) create mode 100644 src/bhyve/bhyve_capabilities.c create mode 100644 src/bhyve/bhyve_capabilities.h
diff --git a/src/Makefile.am b/src/Makefile.am index 55427ed..c715422 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -780,6 +780,8 @@ PARALLELS_DRIVER_SOURCES = \ parallels/parallels_network.c
BHYVE_DRIVER_SOURCES = \ + bhyve/bhyve_capabilities.c \ + bhyve/bhyve_capabilities.h \ bhyve/bhyve_command.c \ bhyve/bhyve_command.h \ bhyve/bhyve_driver.h \ diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c new file mode 100644 index 0000000..b8a9db4 --- /dev/null +++ b/src/bhyve/bhyve_capabilities.c @@ -0,0 +1,105 @@ +/* + * bhyve_capabilities.c: bhyve capabilities module + * + * Copyright (C) 2014 Wojciech Macek <wma@semihalf.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + */ +#include <config.h> +#include <sys/utsname.h> + +#include "viralloc.h" +#include "virlog.h" +#include "virstring.h" +#include "cpu/cpu.h" +#include "nodeinfo.h" +#include "bhyve_utils.h" +#include "domain_conf.h" +#include "vircommand.h" +#include "bhyve_capabilities.h" + +#define VIR_FROM_THIS VIR_FROM_BHYVE + +VIR_LOG_INIT("bhyve.bhyve_capabilities"); + +static int +virBhyveCapsInitCPU(virCapsPtr caps, + virArch arch) +{ + virCPUDefPtr cpu = NULL; + virCPUDataPtr data = NULL; + virNodeInfo nodeinfo; + int ret = -1; + + if (VIR_ALLOC(cpu) < 0) + goto error; + + cpu->arch = arch; + + if (nodeGetInfo(&nodeinfo)) + goto error; + + cpu->type = VIR_CPU_TYPE_HOST; + cpu->sockets = nodeinfo.sockets; + cpu->cores = nodeinfo.cores; + cpu->threads = nodeinfo.threads; + caps->host.cpu = cpu; + + if (!(data = cpuNodeData(arch)) + || cpuDecode(cpu, data, NULL, 0, NULL) < 0) + goto cleanup; + + ret = 0; + + cleanup: + cpuDataFree(data); + + return ret; + + error: + virCPUDefFree(cpu); + goto cleanup; +} + +virCapsPtr +virBhyveCapsBuild(void) +{ + virCapsPtr caps; + virCapsGuestPtr guest; + + if ((caps = virCapabilitiesNew(virArchFromHost(), + 0, 0)) == NULL) + return NULL; + + if ((guest = virCapabilitiesAddGuest(caps, "hvm", + VIR_ARCH_X86_64, + "bhyve", + NULL, 0, NULL)) == NULL) + goto error; + + if (virCapabilitiesAddGuestDomain(guest, + "bhyve", NULL, NULL, 0, NULL) == NULL) + goto error; + + if (virBhyveCapsInitCPU(caps, virArchFromHost()) < 0) + VIR_WARN("Failed to get host CPU"); + + return caps; + + error: + virObjectUnref(caps); + return NULL; +} diff --git a/src/bhyve/bhyve_capabilities.h b/src/bhyve/bhyve_capabilities.h new file mode 100644 index 0000000..efe496e --- /dev/null +++ b/src/bhyve/bhyve_capabilities.h @@ -0,0 +1,30 @@ +/* + * bhyve_capabilities.h: bhyve capabilities module + * + * Copyright (C) 2014 Wojciech Macek <wma@semihalf.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#ifndef _BHYVE_CAPABILITIES +#define _BHYVE_CAPABILITIES
Incorrect indentation, it should be: #ifndef ... # define ... # include ... Please check 'Preprocessor' section in HACKING about that. There's a 'syntax-check' rule to check that. On FreeBSD, it requires installing devel/cppi port. Also, for the time being, a hack is required to make 'syntax-check' work on FreeBSD: you'd need to s/ sed / $(SED) / in cfg.mk. And it'd be nice to keep a consistent style for bhyve headers and use #ifnded __BHYVE_CAPABILITIES_H__.
+ +#include "capabilities.h" + +virCapsPtr virBhyveCapsBuild(void); + +#endif + diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 3321a79..ef9192a 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -53,6 +53,7 @@ #include "bhyve_driver.h" #include "bhyve_process.h" #include "bhyve_utils.h" +#include "bhyve_capabilities.h"
#define VIR_FROM_THIS VIR_FROM_BHYVE
@@ -72,44 +73,49 @@ bhyveDriverUnlock(bhyveConnPtr driver) virMutexUnlock(&driver->lock); }
+/** + * bhyveDriverGetCapabilities: + * + * Get a reference to the virCapsPtr instance for the + * driver. + * + * The caller must release the reference with virObjetUnref + * + * Returns: a reference to a virCapsPtr instance or NULL + */ static virCapsPtr -bhyveBuildCapabilities(void) +bhyveDriverGetCapabilities(bhyveConnPtr driver) { - virCapsPtr caps; - virCapsGuestPtr guest; + virCapsPtr ret = NULL;
- if ((caps = virCapabilitiesNew(virArchFromHost(), - 0, 0)) == NULL) + if(driver == NULL) ^^ missing space return NULL;
- if ((guest = virCapabilitiesAddGuest(caps, "hvm", - VIR_ARCH_X86_64, - "bhyve", - NULL, 0, NULL)) == NULL) - goto error; + ret = virObjectRef(driver->caps);
- if (virCapabilitiesAddGuestDomain(guest, - "bhyve", NULL, NULL, 0, NULL) == NULL) - goto error; - - return caps; - - error: - virObjectUnref(caps); - return NULL; + return ret; }
static char * bhyveConnectGetCapabilities(virConnectPtr conn) { bhyveConnPtr privconn = conn->privateData; + virCapsPtr caps; char *xml;
if (virConnectGetCapabilitiesEnsureACL(conn) < 0) return NULL;
- if ((xml = virCapabilitiesFormatXML(privconn->caps)) == NULL) + caps = bhyveDriverGetCapabilities(privconn); + if (!caps) + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to get Capabilities"));
I might misread the diff as I failed to apply the diff for the reasons mentioned in the other mail, so sorry of the question is irrelevant, but.. If we fail at this point, should we return NULL instead of moving forward?
+ + if ((xml = virCapabilitiesFormatXML(privconn->caps)) == NULL) { ^^^ should it be just 'caps'? + virObjectUnref(caps); virReportOOMError(); + } + virObjectUnref(caps); Could we end up calling that twice in case previous check fails? What would be returned as 'xml' in that case?
return xml; } @@ -326,8 +332,13 @@ bhyveDomainDefineXML(virConnectPtr conn, const char *xml) virDomainDefPtr def = NULL; virDomainDefPtr oldDef = NULL; virDomainObjPtr vm = NULL; + virCapsPtr caps = NULL; + + caps = bhyveDriverGetCapabilities(privconn); + if (!caps) + return NULL;
- if ((def = virDomainDefParseString(xml, privconn->caps, privconn->xmlopt, + if ((def = virDomainDefParseString(xml, caps, privconn->xmlopt, 1 << VIR_DOMAIN_VIRT_BHYVE, VIR_DOMAIN_XML_INACTIVE)) == NULL) goto cleanup; @@ -350,6 +361,7 @@ bhyveDomainDefineXML(virConnectPtr conn, const char *xml) goto cleanup;
cleanup: + virObjectUnref(caps); virDomainDefFree(def); virObjectUnlock(vm);
@@ -704,7 +716,7 @@ bhyveStateInitialize(bool priveleged ATTRIBUTE_UNUSED, if (!(bhyve_driver->closeCallbacks = virCloseCallbacksNew())) goto cleanup;
- if (!(bhyve_driver->caps = bhyveBuildCapabilities())) + if (!(bhyve_driver->caps = virBhyveCapsBuild())) goto cleanup;
if (!(bhyve_driver->xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL))) -- 1.9.0
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Roman Bogorodskiy

Implement support for connectCompareCPU. --- src/bhyve/bhyve_driver.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index ef9192a..f6973af 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -837,6 +837,36 @@ bhyveConnectBaselineCPU(virConnectPtr conn ATTRIBUTE_UNUSED, return cpu; } +static int +bhyveConnectCompareCPU(virConnectPtr conn, + const char *xmlDesc, + unsigned int flags) +{ + bhyveConnPtr driver = conn->privateData; + int ret = VIR_CPU_COMPARE_ERROR; + virCapsPtr caps = NULL; + + virCheckFlags(0, VIR_CPU_COMPARE_ERROR); + + if (virConnectCompareCPUEnsureACL(conn) < 0) + goto cleanup; + + if (!(caps = bhyveDriverGetCapabilities(driver))) + goto cleanup; + + if (!caps->host.cpu || + !caps->host.cpu->model) { + VIR_WARN("cannot get host CPU capabilities"); + ret = VIR_CPU_COMPARE_INCOMPATIBLE; + } else { + ret = cpuCompareXML(caps->host.cpu, xmlDesc); + } + + cleanup: + virObjectUnref(caps); + return ret; +} + static virDriver bhyveDriver = { .no = VIR_DRV_BHYVE, .name = "bhyve", @@ -872,6 +902,7 @@ static virDriver bhyveDriver = { .nodeGetMemoryParameters = bhyveNodeGetMemoryParameters, /* 1.2.3 */ .nodeSetMemoryParameters = bhyveNodeSetMemoryParameters, /* 1.2.3 */ .connectBaselineCPU = bhyveConnectBaselineCPU, /* 1.2.4 */ + .connectCompareCPU = bhyveConnectCompareCPU, /* 1.2.4 */ }; -- 1.9.0
participants (3)
-
Michal Privoznik
-
Roman Bogorodskiy
-
Wojciech Macek