On 06/24/2011 02:56 AM, Taku Izumi wrote:
This patch introduces a new libvirt API (virDomainGetVcpupinInfo).
We can use virDomainGetVcpus API to retrieve CPU affinity information,
but can't use this API against inactive domains (at least in case of KVM).
There is the companion API of this, whose name is virDomainGetVcpusFlags.
Actually not a companion API. virDomainGetVcpusFlags is a counterpart
to virDomainGetMaxVcpus.
The choice of naming isn't perfect, but we're stuck with it.
However its signature is different from what everyone expect, so we
can't use
this to retrieve it either.
The virDomainGetVcpupinInfo is the new API to retrieve CPU affinity information
of active and inactive domains.
unsigned int
flags);
+int virDomainGetVcpupinInfo (virDomainPtr domain,
+ int maxinfo,
See other email about this naming choice.
--- libvirt.orig/src/libvirt_public.syms
+++ libvirt/src/libvirt_public.syms
@@ -467,6 +467,7 @@ LIBVIRT_0.9.3 {
virEventUpdateTimeout;
virNodeGetCPUStats;
virNodeGetMemoryStats;
+ virDomainGetVcpupinInfo;
I'm a fan of sorting, as others on this list will attest :)
+ * @flags: an OR'ed set of virDomainModificationImpact
+ * Must not be specified VIR_DOMAIN_AFFECT_LIVE and
+ * VIR_DOMAIN_AFFECT_CONFIG concurrently!
Grammar was a bit awkward, and ! is usually overkill in documentation.
+ *
+ * Query the CPU affinity setting of all virtual CPUs of domain, store it
+ * in cpumaps.
+ *
+ * Returns the number of virtual CPUs in case of success,
+ * -1 in case of failure.
+ */
+int
+virDomainGetVcpupinInfo (virDomainPtr domain, int maxinfo,
+ unsigned char *cpumaps, int maplen, unsigned int flags)
+{
+ virConnectPtr conn;
+
+ VIR_DOMAIN_DEBUG(domain, "maxinfo=%d, cpumaps=%p, maplen=%d, flags=%u",
+ maxinfo, cpumaps, maplen, flags);
+
+ virResetLastError();
+
+ if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
+ virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
+ virDispatchError(NULL);
+ return -1;
+ }
+
+ if (maxinfo < 1) {
+ virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+ goto error;
+ }
+
+ if ((cpumaps == NULL) || (cpumaps && maplen <= 0)) {
The 'cpumaps &&' check is redundant...
+ virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
...and this error is the same, so I merged some code.
Here's what I'm squashing in:
diff --git i/include/libvirt/libvirt.h.in w/include/libvirt/libvirt.h.in
index 2c78f1f..4f9f158 100644
--- i/include/libvirt/libvirt.h.in
+++ w/include/libvirt/libvirt.h.in
@@ -1267,7 +1267,7 @@ int virDomainPinVcpuFlags
(virDomainPtr domain,
unsigned int flags);
int virDomainGetVcpupinInfo (virDomainPtr domain,
- int maxinfo,
+ int ncpumaps,
unsigned char *cpumaps,
int maplen,
unsigned int flags);
diff --git i/src/libvirt.c w/src/libvirt.c
index e289fee..3f9585b 100644
--- i/src/libvirt.c
+++ w/src/libvirt.c
@@ -7111,20 +7111,20 @@ error:
/**
* virDomainGetVcpupinInfo:
* @domain: pointer to domain object, or NULL for Domain0
- * @maxinfo: the number of cpumap
+ * @ncpumaps: the number of cpumap (listed first to match
virDomainGetVcpus)
* @cpumaps: pointer to a bit map of real CPUs for all vcpus of this
* domain (in 8-bit bytes) (OUT)
- * It's assumed there is <maxinfo> cpumap in cpumaps array.
- * The memory allocated to cpumaps must be (maxinfo * maplen) bytes
- * (ie: calloc(maxinfo, maplen)).
+ * It's assumed there is <ncpumaps> cpumap in cpumaps array.
+ * The memory allocated to cpumaps must be (ncpumaps * maplen) bytes
+ * (ie: calloc(ncpumaps, maplen)).
* One cpumap inside cpumaps has the format described in
* virDomainPinVcpu() API.
* Must not be NULL.
* @maplen: the number of bytes in one cpumap, from 1 up to size of CPU
map.
* Must be positive.
* @flags: an OR'ed set of virDomainModificationImpact
- * Must not be specified VIR_DOMAIN_AFFECT_LIVE and
- * VIR_DOMAIN_AFFECT_CONFIG concurrently!
+ * Must not be VIR_DOMAIN_AFFECT_LIVE and
+ * VIR_DOMAIN_AFFECT_CONFIG concurrently.
*
* Query the CPU affinity setting of all virtual CPUs of domain, store it
* in cpumaps.
@@ -7133,13 +7133,13 @@ error:
* -1 in case of failure.
*/
int
-virDomainGetVcpupinInfo (virDomainPtr domain, int maxinfo,
+virDomainGetVcpupinInfo (virDomainPtr domain, int ncpumaps,
unsigned char *cpumaps, int maplen, unsigned
int flags)
{
virConnectPtr conn;
- VIR_DOMAIN_DEBUG(domain, "maxinfo=%d, cpumaps=%p, maplen=%d, flags=%u",
- maxinfo, cpumaps, maplen, flags);
+ VIR_DOMAIN_DEBUG(domain, "ncpumaps=%d, cpumaps=%p, maplen=%d,
flags=%u",
+ ncpumaps, cpumaps, maplen, flags);
virResetLastError();
@@ -7149,12 +7149,7 @@ virDomainGetVcpupinInfo (virDomainPtr domain, int
maxinfo,
return -1;
}
- if (maxinfo < 1) {
- virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
- goto error;
- }
-
- if ((cpumaps == NULL) || (cpumaps && maplen <= 0)) {
+ if (ncpumaps < 1 || !cpumaps || maplen <= 0) {
virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
goto error;
}
@@ -7163,7 +7158,7 @@ virDomainGetVcpupinInfo (virDomainPtr domain, int
maxinfo,
if (conn->driver->domainGetVcpupinInfo) {
int ret;
- ret = conn->driver->domainGetVcpupinInfo (domain, maxinfo,
+ ret = conn->driver->domainGetVcpupinInfo (domain, ncpumaps,
cpumaps, maplen, flags);
if (ret < 0)
goto error;
@@ -7197,6 +7192,9 @@ error:
* Extract information about virtual CPUs of domain, store it in info array
* and also in cpumaps if this pointer isn't NULL.
*
+ * See also virDomainGetVcpupinInfo for querying just cpumaps, including on
+ * an inactive domain.
+ *
* Returns the number of info filled in case of success, -1 in case of
failure.
*/
int
diff --git i/src/libvirt_public.syms w/src/libvirt_public.syms
index 38e8446..c7dc3c5 100644
--- i/src/libvirt_public.syms
+++ w/src/libvirt_public.syms
@@ -453,6 +453,7 @@ LIBVIRT_0.9.2 {
LIBVIRT_0.9.3 {
global:
virDomainGetControlInfo;
+ virDomainGetVcpupinInfo;
virDomainPinVcpuFlags;
virDomainSendKey;
virEventAddHandle;
@@ -463,7 +464,6 @@ LIBVIRT_0.9.3 {
virEventUpdateTimeout;
virNodeGetCPUStats;
virNodeGetMemoryStats;
- virDomainGetVcpupinInfo;
} LIBVIRT_0.9.2;
# .... define new API here using predicted next version number ....
--
Eric Blake eblake(a)redhat.com +1-801-349-2682
Libvirt virtualization library
http://libvirt.org