[libvirt] [PATCH 02/12] lib: introduce an API to add new iothread with parameters

Pavel Hrdina phrdina at redhat.com
Tue Feb 21 12:14:58 UTC 2017


This basically copies and extend the existing virDomainAddIOThread
API by adding support for parameters.  This allows you to add a new
iothread into a domain and also sets polling parameters along with
the new iothread.

Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
---
 include/libvirt/libvirt-domain.h | 39 +++++++++++++++++++++
 src/driver-hypervisor.h          |  8 +++++
 src/libvirt-domain.c             | 75 ++++++++++++++++++++++++++++++++++++++++
 src/libvirt_public.syms          |  5 +++
 src/remote/remote_driver.c       |  1 +
 src/remote/remote_protocol.x     | 20 ++++++++++-
 src/remote_protocol-structs      | 10 ++++++
 7 files changed, 157 insertions(+), 1 deletion(-)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index e303140a23..5ce974292e 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -1855,6 +1855,40 @@ int                     virDomainGetEmulatorPinInfo (virDomainPtr domain,
                                                      int maplen,
                                                      unsigned int flags);
 
+/* IOThread parameters */
+
+/**
+ * VIR_DOMAIN_IOTHREAD_POLL_ENABLED:
+ *
+ * Whether polling should be enabled or not.  If omitted the default is set
+ * by hypervisor.
+ */
+# define VIR_DOMAIN_IOTHREAD_POLL_ENABLED "poll_enabled"
+
+/**
+ * VIR_DOMAIN_IOTHREAD_POLL_MAX_NS:
+ *
+ * The maximal polling time that can be used by polling algorithm in ns.
+ * If omitted the default is 0.
+ */
+# define VIR_DOMAIN_IOTHREAD_POLL_MAX_NS "poll_max_ns"
+
+/**
+ * VIR_DOMAIN_IOTHREAD_POLL_GROW:
+ *
+ * This tells the polling algorithm how many ns it should grow current
+ * polling time if it's not optimal anymore.  If omitted the default is 0.
+ */
+# define VIR_DOMAIN_IOTHREAD_POLL_GROW "poll_grow"
+
+/**
+ * VIR_DOMAIN_IOTHREAD_POLL_SHRINK:
+ *
+ * This tells the polling algorithm how many ns it should shrink current
+ * polling time if it's not optimal anymore.  If omitted the default is 0.
+ */
+# define VIR_DOMAIN_IOTHREAD_POLL_SHRINK "poll_shrink"
+
 /**
  * virIOThreadInfo:
  *
@@ -1882,6 +1916,11 @@ int                  virDomainPinIOThread(virDomainPtr domain,
 int                  virDomainAddIOThread(virDomainPtr domain,
                                           unsigned int iothread_id,
                                           unsigned int flags);
+int                  virDomainAddIOThreadParams(virDomainPtr domain,
+                                                unsigned int iothread_id,
+                                                virTypedParameterPtr params,
+                                                int nparams,
+                                                unsigned int flags);
 int                  virDomainDelIOThread(virDomainPtr domain,
                                           unsigned int iothread_id,
                                           unsigned int flags);
diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h
index 51af73200b..9c7ce83cd3 100644
--- a/src/driver-hypervisor.h
+++ b/src/driver-hypervisor.h
@@ -399,6 +399,13 @@ typedef int
                            unsigned int flags);
 
 typedef int
+(*virDrvDomainAddIOThreadParams)(virDomainPtr domain,
+                                 unsigned int iothread_id,
+                                 virTypedParameterPtr params,
+                                 int nparams,
+                                 unsigned int flags);
+
+typedef int
 (*virDrvDomainDelIOThread)(virDomainPtr domain,
                            unsigned int iothread_id,
                            unsigned int flags);
@@ -1334,6 +1341,7 @@ struct _virHypervisorDriver {
     virDrvDomainGetIOThreadInfo domainGetIOThreadInfo;
     virDrvDomainPinIOThread domainPinIOThread;
     virDrvDomainAddIOThread domainAddIOThread;
+    virDrvDomainAddIOThreadParams domainAddIOThreadParams;
     virDrvDomainDelIOThread domainDelIOThread;
     virDrvDomainGetSecurityLabel domainGetSecurityLabel;
     virDrvDomainGetSecurityLabelList domainGetSecurityLabelList;
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 5b3e842058..691c72dedd 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -7751,6 +7751,81 @@ virDomainAddIOThread(virDomainPtr domain,
 
 
 /**
+ * virDomainAddIOThreadParams:
+ * @domain: a domain object
+ * @iothread_id: the specific IOThread ID value to add
+ * @params: pointer to IOThread parameter objects
+ * @nparams: number of IOThread parameters
+ * @flags: bitwise-OR of virDomainModificationImpact and virTypedParameterFlags
+ *
+ * Dynamically add an IOThread to the domain. It is left up to the
+ * underlying virtual hypervisor to determine the valid range for an
+ * @iothread_id and determining whether the @iothread_id already exists.
+ *
+ * The combination of parameters has some limitation:
+ *
+ * - If VIR_DOMAIN_IOTHREAD_POLL_ENABLED is set to true,
+ *   VIR_DOMAIN_IOTHREAD_POLL_MAX_NS must be set as well.
+ *
+ * - If VIR_DOMAIN_IOTHREAD_POLL_MAX_NS is set to value > 0,
+ *   VIR_DOMAIN_IOTHREAD_POLL_ENABLED is set to true.
+ *
+ * - If one of VIR_DOMAIN_IOTHREAD_POLL_GROW or VIR_DOMAIN_IOTHREAD_POLL_SHRINK
+ *   is set to value > 0, VIR_DOMAIN_IOTHREAD_POLL_MAX_NS must be set as well.
+ *
+ * See VIR_DOMAIN_IOTHREAD_* for detailed description of accepted IOThread
+ * parameters.
+ *
+ * Note that this call can fail if the underlying virtualization hypervisor
+ * does not support it or if growing the number of iothreads is arbitrarily
+ * limited.  This function requires privileged access to the hypervisor.
+ *
+ * Returns 0 in case of success, -1 in case of failure.
+ */
+int
+virDomainAddIOThreadParams(virDomainPtr domain,
+                           unsigned int iothread_id,
+                           virTypedParameterPtr params,
+                           int nparams,
+                           unsigned int flags)
+{
+    virConnectPtr conn;
+
+    VIR_DOMAIN_DEBUG(domain, "iothread_id=%u, params=%p, nparams=%d, flags=%x",
+                     iothread_id, params, nparams, flags);
+    VIR_TYPED_PARAMS_DEBUG(params, nparams);
+
+    virResetLastError();
+
+    virCheckDomainReturn(domain, -1);
+    conn = domain->conn;
+
+    virCheckReadOnlyGoto(conn->flags, error);
+    virCheckNonNegativeArgGoto(nparams, error);
+    if (nparams)
+        virCheckNonNullArgGoto(params, error);
+
+    if (virTypedParameterValidateSet(conn, params, nparams) < 0)
+        goto error;
+
+    if (conn->driver->domainAddIOThreadParams) {
+        int ret;
+        ret = conn->driver->domainAddIOThreadParams(domain, iothread_id,
+                                                    params, nparams, flags);
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virReportUnsupportedError();
+
+ error:
+    virDispatchError(domain->conn);
+    return -1;
+}
+
+
+/**
  * virDomainDelIOThread:
  * @domain: a domain object
  * @iothread_id: the specific IOThread ID value to delete
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index 62885ac415..edf72d23aa 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -753,4 +753,9 @@ LIBVIRT_3.0.0 {
         virConnectSecretEventDeregisterAny;
 } LIBVIRT_2.2.0;
 
+LIBVIRT_3.1.0 {
+    global:
+        virDomainAddIOThreadParams;
+} LIBVIRT_3.0.0;
+
 # .... define new API here using predicted next version number ....
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index a3f7d9b0ba..f9e246b8bc 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -8246,6 +8246,7 @@ static virHypervisorDriver hypervisor_driver = {
     .domainGetIOThreadInfo = remoteDomainGetIOThreadInfo, /* 1.2.14 */
     .domainPinIOThread = remoteDomainPinIOThread, /* 1.2.14 */
     .domainAddIOThread = remoteDomainAddIOThread, /* 1.2.15 */
+    .domainAddIOThreadParams = remoteDomainAddIOThreadParams, /* 3.1.0 */
     .domainDelIOThread = remoteDomainDelIOThread, /* 1.2.15 */
     .domainGetSecurityLabel = remoteDomainGetSecurityLabel, /* 0.6.1 */
     .domainGetSecurityLabelList = remoteDomainGetSecurityLabelList, /* 0.10.0 */
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index cd0a14cc69..146c38b3f4 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -253,6 +253,9 @@ const REMOTE_DOMAIN_IP_ADDR_MAX = 2048;
 /* Upper limit on number of guest vcpu information entries */
 const REMOTE_DOMAIN_GUEST_VCPU_PARAMS_MAX = 64;
 
+/* Upper limit on number of IOThread information entries */
+const REMOTE_DOMAIN_IOTHREAD_PARAMS_MAX = 64;
+
 /* UUID.  VIR_UUID_BUFLEN definition comes from libvirt.h */
 typedef opaque remote_uuid[VIR_UUID_BUFLEN];
 
@@ -1227,6 +1230,13 @@ struct remote_domain_add_iothread_args {
     unsigned int flags;
 };
 
+struct remote_domain_add_iothread_params_args {
+    remote_nonnull_domain dom;
+    unsigned int iothread_id;
+    remote_typed_param params<REMOTE_DOMAIN_IOTHREAD_PARAMS_MAX>;
+    unsigned int flags;
+};
+
 struct remote_domain_del_iothread_args {
     remote_nonnull_domain dom;
     unsigned int iothread_id;
@@ -6018,6 +6028,14 @@ enum remote_procedure {
      * @generate: both
      * @acl: none
      */
-    REMOTE_PROC_SECRET_EVENT_VALUE_CHANGED = 383
+    REMOTE_PROC_SECRET_EVENT_VALUE_CHANGED = 383,
+
+    /**
+     * @generate: both
+     * @acl: domain:write
+     * @acl: domain:save:!VIR_DOMAIN_AFFECT_CONFIG|VIR_DOMAIN_AFFECT_LIVE
+     * @acl: domain:save:VIR_DOMAIN_AFFECT_CONFIG
+     */
+    REMOTE_PROC_DOMAIN_ADD_IOTHREAD_PARAMS = 384
 
 };
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index 0360600cfb..2e3245322f 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -857,6 +857,15 @@ struct remote_domain_add_iothread_args {
         u_int                      iothread_id;
         u_int                      flags;
 };
+struct remote_domain_add_iothread_params_args {
+        remote_nonnull_domain      dom;
+        u_int                      iothread_id;
+        struct {
+                u_int              params_len;
+                remote_typed_param * params_val;
+        } params;
+        u_int                      flags;
+};
 struct remote_domain_del_iothread_args {
         remote_nonnull_domain      dom;
         u_int                      iothread_id;
@@ -3210,4 +3219,5 @@ enum remote_procedure {
         REMOTE_PROC_CONNECT_SECRET_EVENT_DEREGISTER_ANY = 381,
         REMOTE_PROC_SECRET_EVENT_LIFECYCLE = 382,
         REMOTE_PROC_SECRET_EVENT_VALUE_CHANGED = 383,
+        REMOTE_PROC_DOMAIN_ADD_IOTHREAD_PARAMS = 384,
 };
-- 
2.11.1




More information about the libvir-list mailing list