]> xenbits.xensource.com Git - libvirt.git/commitdiff
virNodeGetCPUMap: Define public API.
authorViktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
Tue, 23 Oct 2012 20:34:53 +0000 (14:34 -0600)
committerEric Blake <eblake@redhat.com>
Wed, 24 Oct 2012 00:46:47 +0000 (18:46 -0600)
Adding a new API to obtain information about the
host node's present, online and offline CPUs.

int virNodeGetCPUMap(virConnectPtr conn,
                     unsigned char **cpumap,
                     unsigned int *online,
                     unsigned int flags);

The function will return the number of CPUs present on the host
or -1 on failure;
If cpumap is non-NULL virNodeGetCPUMap will allocate an array
containing a bit map representation of the online CPUs. It's
the callers responsibility to deallocate cpumap using free().
If online is non-NULL, the variable pointed to will contain
the number of online host node CPUs.
The variable flags has been added to support future extensions
and must be set to 0.

Extend the driver structure by nodeGetCPUMap entry in support of the
new API virNodeGetCPUMap.
Added implementation of virNodeGetCPUMap to libvirt.c

Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
include/libvirt/libvirt.h.in
python/generator.py
src/driver.h
src/libvirt.c
src/libvirt_public.syms

index a98eee0abdc8a9d50a33c182d9b5d30a261fe700..327ddd398d39e6b0dce9551fb748c592a14bf6bb 100644 (file)
@@ -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 */
 
index ced7e41f24e5f26c096d3a539111d77a9891d393..c76ff2a5b0170eb6d1a7a8704f2a3047d53fa596 100755 (executable)
@@ -429,6 +429,7 @@ skip_impl = (
     'virConnectRegisterCloseCallback',
     'virNodeGetMemoryParameters',
     'virNodeSetMemoryParameters',
+    'virNodeGetCPUMap',
 )
 
 qemu_skip_impl = (
index bdcaa0183d2dcb55c00372a6b16ae45f2a93d6a6..7ba66adab7093d1bd8554dd0430ab499b18eaf47 100644 (file)
@@ -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
index 33cf7cbeb6e398c67d30306d80d8e5497b0caa8e..7e7947087f234338065a586f75961d35f87a60ae 100644 (file)
@@ -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;
+}
index 2c924d5e3f5a140c3c126bfc5a078b425cfdefcd..f494821be2f2c7f41bf3f3a891eaea61df44cb81 100644 (file)
@@ -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 ....