[libvirt] [PATCHv2 12/14] lib: Add API to modify vCPU state from the guest using the guest agent

Peter Krempa pkrempa at redhat.com
Wed Jun 5 13:44:03 UTC 2013


This patch introduces API virDomainSetGuestVcpus that will be used to
work with vCPU state from the point of view of the guest using the guest
agent.
---
 include/libvirt/libvirt.h.in |  4 ++++
 src/driver.h                 |  8 +++++++
 src/libvirt.c                | 55 ++++++++++++++++++++++++++++++++++++++++++++
 src/libvirt_public.syms      |  1 +
 src/remote/remote_driver.c   |  1 +
 src/remote/remote_protocol.x | 15 +++++++++++-
 src/remote_protocol-structs  |  7 ++++++
 7 files changed, 90 insertions(+), 1 deletion(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index c8f639a..2dccc68 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2128,6 +2128,10 @@ int                     virDomainSetVcpus       (virDomainPtr domain,
 int                     virDomainSetVcpusFlags  (virDomainPtr domain,
                                                  unsigned int nvcpus,
                                                  unsigned int flags);
+int                     virDomainSetGuestVcpu   (virDomainPtr domain,
+                                                 unsigned int id,
+                                                 unsigned int online,
+                                                 unsigned int flags);
 int                     virDomainGetVcpusFlags  (virDomainPtr domain,
                                                  unsigned int flags);

diff --git a/src/driver.h b/src/driver.h
index cbafdce..301e490 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -1050,6 +1050,13 @@ typedef int
                           unsigned char **cpumap,
                           unsigned int flags);

+typedef int
+(*virDrvDomainSetGuestVcpu)(virDomainPtr dom,
+                            unsigned int id,
+                            unsigned int online,
+                            unsigned int flags);
+
+
 typedef struct _virDriver virDriver;
 typedef virDriver *virDriverPtr;

@@ -1252,6 +1259,7 @@ struct _virDriver {
     virDrvDomainSendProcessSignal domainSendProcessSignal;
     virDrvDomainLxcOpenNamespace domainLxcOpenNamespace;
     virDrvDomainGetVCPUMap domainGetVCPUMap;
+    virDrvDomainSetGuestVcpu domainSetGuestVcpu;
 };


diff --git a/src/libvirt.c b/src/libvirt.c
index 59e02a1..9dd6b97 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -8969,6 +8969,61 @@ error:
     return -1;
 }

+
+/**
+ * virDomainSetGuestVcpu:
+ * @domain: pointer to domain object, or NULL for Domain0
+ * @id: vcpu ID in the guest
+ * @online: desired state of the vcpu
+ * @flags: currently unused, callers should pass 0
+ *
+ * Dynamically change the state of a virtual CPUs used by the domain by
+ * using the guest agent. The vCPU id used is from the point of view of
+ * the guest.
+ *
+ * Returns 0 in case of success, -1 in case of failure.
+ */
+
+int
+virDomainSetGuestVcpu(virDomainPtr domain,
+                      unsigned int id,
+                      unsigned int online,
+                      unsigned int flags)
+{
+    virConnectPtr conn;
+
+    VIR_DOMAIN_DEBUG(domain, "id=%u, online=%u, flags=%x", id, online, flags);
+
+    virResetLastError();
+
+    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;
+    }
+
+    conn = domain->conn;
+
+    if (conn->driver->domainSetGuestVcpu) {
+        int ret;
+        ret = conn->driver->domainSetGuestVcpu(domain, id, online, flags);
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+    virDispatchError(domain->conn);
+    return -1;
+}
+
+
 /**
  * virDomainGetVcpusFlags:
  * @domain: pointer to domain object, or NULL for Domain0
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index 04465be..bbb7c77 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -624,6 +624,7 @@ LIBVIRT_1.0.6 {
 LIBVIRT_1.0.7 {
     global:
         virDomainGetVCPUMap;
+        virDomainSetGuestVcpu;
 } LIBVIRT_1.0.6;


diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 99fa3c1..4dca3eb 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -6395,6 +6395,7 @@ static virDriver remote_driver = {
     .domainFSTrim = remoteDomainFSTrim, /* 1.0.1 */
     .domainLxcOpenNamespace = remoteDomainLxcOpenNamespace, /* 1.0.2 */
     .domainGetVCPUMap = remoteDomainGetVCPUMap, /* 1.0.7 */
+    .domainSetGuestVcpu = remoteDomainSetGuestVcpu, /* 1.0.7 */
 };

 static virNetworkDriver network_driver = {
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index cec3541..374df42 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -2748,6 +2748,13 @@ struct remote_domain_get_vcpu_map_ret {
     int ret;
 };

+struct remote_domain_set_guest_vcpu_args {
+    remote_nonnull_domain dom;
+    unsigned int id;
+    unsigned int online;
+    unsigned int flags;
+};
+
 struct remote_domain_fstrim_args {
     remote_nonnull_domain dom;
     remote_string mountPoint;
@@ -4450,6 +4457,12 @@ enum remote_procedure {
     /**
      * @generate: none
      */
-    REMOTE_PROC_DOMAIN_GET_VCPU_MAP = 302
+    REMOTE_PROC_DOMAIN_GET_VCPU_MAP = 302,
+
+    /**
+     * @generate: both
+     */
+    REMOTE_PROC_DOMAIN_SET_GUEST_VCPU = 303
+

 };
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index e1ceabd..0ded7d8 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -2198,6 +2198,12 @@ struct remote_domain_get_vcpu_map_ret {
         } cpumap;
         int                        ret;
 };
+struct remote_domain_set_guest_vcpu_args {
+        remote_nonnull_domain      dom;
+        u_int                      id;
+        u_int                      online;
+        u_int                      flags;
+};
 struct remote_domain_fstrim_args {
         remote_nonnull_domain      dom;
         remote_string              mountPoint;
@@ -2507,4 +2513,5 @@ enum remote_procedure {
         REMOTE_PROC_DOMAIN_MIGRATE_SET_COMPRESSION_CACHE = 300,
         REMOTE_PROC_NODE_DEVICE_DETACH_FLAGS = 301,
         REMOTE_PROC_DOMAIN_GET_VCPU_MAP = 302,
+        REMOTE_PROC_DOMAIN_SET_GUEST_VCPU = 303,
 };
-- 
1.8.2.1




More information about the libvir-list mailing list