[libvirt] [PATCHv4 1/4] vcpupin: inroduce a new libvir API (virDomainPinVcpuFlags)

Taku Izumi izumi.taku at jp.fujitsu.com
Fri May 20 09:08:29 UTC 2011


This patch introduces a new libvirt API (virDomainPinVcpuFlags)

Signd-off-by: Taku Izumi <izumi.taku at jp.fujitsu.com>
---
 include/libvirt/libvirt.h.in |    6 +++
 src/driver.h                 |    7 +++
 src/libvirt.c                |   83 +++++++++++++++++++++++++++++++++++++++++++
 src/libvirt_public.syms      |    1 
 4 files changed, 97 insertions(+)

Index: libvirt/include/libvirt/libvirt.h.in
===================================================================
--- libvirt.orig/include/libvirt/libvirt.h.in
+++ libvirt/include/libvirt/libvirt.h.in
@@ -1114,6 +1114,7 @@ typedef virVcpuInfo *virVcpuInfoPtr;
 
 /* Flags for controlling virtual CPU hot-plugging.  */
 typedef enum {
+    VIR_DOMAIN_VCPU_CURRENT = 0,        /* Affect current domain state */
     /* Must choose at least one of these two bits; SetVcpus can choose both */
     VIR_DOMAIN_VCPU_LIVE    = (1 << 0), /* Affect active domain */
     VIR_DOMAIN_VCPU_CONFIG  = (1 << 1), /* Affect next boot */
@@ -1134,6 +1135,11 @@ int                     virDomainPinVcpu
                                                  unsigned int vcpu,
                                                  unsigned char *cpumap,
                                                  int maplen);
+int                     virDomainPinVcpuFlags   (virDomainPtr domain,
+                                                 unsigned int vcpu,
+                                                 unsigned char *cpumap,
+                                                 int maplen,
+                                                 unsigned int flags);
 
 /**
  * VIR_USE_CPU:
Index: libvirt/src/driver.h
===================================================================
--- libvirt.orig/src/driver.h
+++ libvirt/src/driver.h
@@ -230,6 +230,12 @@ typedef int
                                          unsigned char *cpumap,
                                          int maplen);
 typedef int
+        (*virDrvDomainPinVcpuFlags)     (virDomainPtr domain,
+                                         unsigned int vcpu,
+                                         unsigned char *cpumap,
+                                         int maplen,
+                                         unsigned int flags);
+typedef int
         (*virDrvDomainGetVcpus)		(virDomainPtr domain,
                                          virVcpuInfoPtr info,
                                          int maxinfo,
@@ -661,6 +667,7 @@ struct _virDriver {
     virDrvDomainSetVcpusFlags		domainSetVcpusFlags;
     virDrvDomainGetVcpusFlags		domainGetVcpusFlags;
     virDrvDomainPinVcpu		domainPinVcpu;
+    virDrvDomainPinVcpuFlags    domainPinVcpuFlags;
     virDrvDomainGetVcpus		domainGetVcpus;
     virDrvDomainGetMaxVcpus		domainGetMaxVcpus;
     virDrvDomainGetSecurityLabel     domainGetSecurityLabel;
Index: libvirt/src/libvirt.c
===================================================================
--- libvirt.orig/src/libvirt.c
+++ libvirt/src/libvirt.c
@@ -6330,6 +6330,89 @@ error:
 }
 
 /**
+ * virDomainPinVcpuFlags:
+ * @domain: pointer to domain object, or NULL for Domain0
+ * @vcpu: virtual CPU number
+ * @cpumap: pointer to a bit map of real CPUs (in 8-bit bytes) (IN)
+ *      Each bit set to 1 means that corresponding CPU is usable.
+ *      Bytes are stored in little-endian order: CPU0-7, 8-15...
+ *      In each byte, lowest CPU number is least significant bit.
+ * @maplen: number of bytes in cpumap, from 1 up to size of CPU map in
+ *      underlying virtualization system (Xen...).
+ *      If maplen < size, missing bytes are set to zero.
+ *      If maplen > size, failure code is returned.
+ * @flags: an OR'ed subset of virDomainVcpuFlags
+ *
+ * Dynamically change the real CPUs which can be allocated to a virtual CPU.
+ * This function requires privileged access to the hypervisor.
+ *
+ * @flags may include VIR_DOMAIN_VCPU_LIVE or VIR_DOMAIN_VCPU_CONFIG.
+ * Both flags may be set, but VIR_DOMAIN_VCPU_MAXIMUM cannot be set.
+ * If VIR_DOMAIN_VCPU_LIVE is set, the change affects a running domain
+ * and may fail if domain is not alive.
+ * If VIR_DOMAIN_VCPU_CONFIG is set, the change affects persistent state,
+ * and will fail for transient domains.
+ * If neither flag is specified (that is, @flags is VIR_DOMAIN_VCPU_CURRENT),
+ * then an inactive domain modifies persistent setup, while an active domain
+ * is hypervisor-dependent on whether just live or both live and persistent
+ * state is changed.
+ * Not all hypervisors can support all flag combinations.
+ *
+ * Returns 0 in case of success, -1 in case of failure.
+ *
+ */
+int
+virDomainPinVcpuFlags(virDomainPtr domain, unsigned int vcpu,
+                      unsigned char *cpumap, int maplen, unsigned int flags)
+{
+    virConnectPtr conn;
+
+    VIR_DOMAIN_DEBUG(domain, "vcpu=%u, cpumap=%p, maplen=%d, flags=%u",
+                     vcpu, cpumap, maplen, flags);
+
+    virResetLastError();
+
+    if (flags & ~(VIR_DOMAIN_VCPU_LIVE | VIR_DOMAIN_VCPU_CONFIG)) {
+        virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+        virDispatchError(NULL);
+        return -1;
+    }
+
+    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
+        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
+        virDispatchError(NULL);
+        return -1;
+    }
+
+    if (domain->conn->flags & VIR_CONNECT_RO) {
+        virLibDomainError(VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+        goto error;
+    }
+
+    if ((vcpu > 32000) || (cpumap == NULL) || (maplen < 1)) {
+        virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+        goto error;
+    }
+
+    conn = domain->conn;
+
+    if (conn->driver->domainPinVcpuFlags) {
+        int ret;
+        ret = conn->driver->domainPinVcpuFlags (domain, vcpu, cpumap, maplen, flags);
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+    virDispatchError(domain->conn);
+    return -1;
+
+}
+
+/**
  * virDomainGetVcpus:
  * @domain: pointer to domain object, or NULL for Domain0
  * @info: pointer to an array of virVcpuInfo structures (OUT)
Index: libvirt/src/libvirt_public.syms
===================================================================
--- libvirt.orig/src/libvirt_public.syms
+++ libvirt/src/libvirt_public.syms
@@ -442,6 +442,7 @@ LIBVIRT_0.9.2 {
         virDomainInjectNMI;
         virDomainScreenshot;
         virDomainSetSchedulerParametersFlags;
+        virDomainPinVcpuFlags;
 } LIBVIRT_0.9.0;
 
 # .... define new API here using predicted next version number ....




More information about the libvir-list mailing list