diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index a98eee0abd..327ddd398d 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -750,6 +750,14 @@ int virNodeSetMemoryParameters(virConnectPtr conn, int nparams, unsigned int flags); +/* + * node CPU map + */ +int virNodeGetCPUMap(virConnectPtr conn, + unsigned char **cpumap, + unsigned int *online, + unsigned int flags); + /* Management of scheduler parameters */ diff --git a/python/generator.py b/python/generator.py index ced7e41f24..c76ff2a5b0 100755 --- a/python/generator.py +++ b/python/generator.py @@ -429,6 +429,7 @@ skip_impl = ( 'virConnectRegisterCloseCallback', 'virNodeGetMemoryParameters', 'virNodeSetMemoryParameters', + 'virNodeGetCPUMap', ) qemu_skip_impl = ( diff --git a/src/driver.h b/src/driver.h index bdcaa0183d..7ba66adab7 100644 --- a/src/driver.h +++ b/src/driver.h @@ -898,6 +898,12 @@ typedef int int nparams, unsigned int flags); +typedef int + (*virDrvNodeGetCPUMap)(virConnectPtr conn, + unsigned char **cpumap, + unsigned int *online, + unsigned int flags); + /** * _virDriver: * @@ -1087,6 +1093,7 @@ struct _virDriver { virDrvDomainGetMetadata domainGetMetadata; virDrvNodeGetMemoryParameters nodeGetMemoryParameters; virDrvNodeSetMemoryParameters nodeSetMemoryParameters; + virDrvNodeGetCPUMap nodeGetCPUMap; }; typedef int diff --git a/src/libvirt.c b/src/libvirt.c index 33cf7cbeb6..7e7947087f 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -20106,3 +20106,54 @@ error: virDispatchError(domain->conn); return NULL; } + +/** + * virNodeGetCPUMap: + * @conn: pointer to the hypervisor connection + * @cpumap: optional pointer to a bit map of real CPUs on the host node + * (in 8-bit bytes) (OUT) + * In case of success each bit set to 1 means that corresponding + * CPU is online. + * Bytes are stored in little-endian order: CPU0-7, 8-15... + * In each byte, lowest CPU number is least significant bit. + * The bit map is allocated by virNodeGetCPUMap and needs + * to be released using free() by the caller. + * @online: optional number of online CPUs in cpumap (OUT) + * Contains the number of online CPUs if the call was successful. + * @flags: extra flags; not used yet, so callers should always pass 0 + * + * Get CPU map of host node CPUs. + * + * Returns number of CPUs present on the host node, + * or -1 if there was an error. + */ +int +virNodeGetCPUMap(virConnectPtr conn, + unsigned char **cpumap, + unsigned int *online, + unsigned int flags) +{ + VIR_DEBUG("conn=%p, cpumap=%p, online=%p, flags=%x", + conn, cpumap, online, flags); + + virResetLastError(); + + if (!VIR_IS_CONNECT(conn)) { + virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); + virDispatchError(NULL); + return -1; + } + + if (conn->driver->nodeGetCPUMap) { + int ret = conn->driver->nodeGetCPUMap(conn, cpumap, online, flags); + if (ret < 0) + goto error; + return ret; + } + + virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__); + +error: + virDispatchError(conn); + return -1; +} diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 2c924d5e3f..f494821be2 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -569,4 +569,9 @@ LIBVIRT_0.10.2 { virStoragePoolListAllVolumes; } LIBVIRT_0.10.0; +LIBVIRT_1.0.0 { + global: + virNodeGetCPUMap; +} LIBVIRT_0.10.2; + # .... define new API here using predicted next version number ....