[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 09/11] lib: Add API to modify vCPU state from the guest using the guest agent



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 46d499c..c4c8224 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2127,6 +2127,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 0caa2d6..eca5f1d 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -1052,6 +1052,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;

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


diff --git a/src/libvirt.c b/src/libvirt.c
index 3f51e83..9c3bbe6 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -8947,6 +8947,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 7db6be3..bcc578f 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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]