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

[libvirt] [PATCHv4 1/4] API: prevent query of --live and --config at once



Drivers were inconsistent when presented both --live and --config
at once.  For example, within qemu, getting memory parameters
favored live, while getting blkio tuning favored config.  Some,
but not all, attempts to mix flags on query were filtered at
the virsh level, but we shouldn't have to duplicate efforts in
every client app.  So, it is simpler to just enforce that the two
flags cannot both be used at once on query operations, which has
precedence, and which matches the documentation of
virDomainModificationImpact.

* src/libvirt.c (virDomainGetMemoryParameters)
(virDomainGetBlkioParameters)
(virDomainGetSchedulerParametersFlags, virDomainGetVcpuPinInfo):
Borrow sanity checking from virDomainGetVcpusFlags.
---
 src/libvirt.c |   36 ++++++++++++++++++++++++++++++++----
 1 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/src/libvirt.c b/src/libvirt.c
index 1518ed2..3a6e8e9 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -3745,6 +3745,13 @@ virDomainGetMemoryParameters(virDomainPtr domain,
     if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
                                  VIR_DRV_FEATURE_TYPED_PARAM_STRING))
         flags |= VIR_TYPED_PARAM_STRING_OKAY;
+
+    /* At most one of these two flags should be set.  */
+    if ((flags & VIR_DOMAIN_AFFECT_LIVE) &&
+        (flags & VIR_DOMAIN_AFFECT_CONFIG)) {
+        virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+        goto error;
+    }
     conn = domain->conn;

     if (conn->driver->domainGetMemoryParameters) {
@@ -3870,6 +3877,13 @@ virDomainGetBlkioParameters(virDomainPtr domain,
     if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
                                  VIR_DRV_FEATURE_TYPED_PARAM_STRING))
         flags |= VIR_TYPED_PARAM_STRING_OKAY;
+
+    /* At most one of these two flags should be set.  */
+    if ((flags & VIR_DOMAIN_AFFECT_LIVE) &&
+        (flags & VIR_DOMAIN_AFFECT_CONFIG)) {
+        virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+        goto error;
+    }
     conn = domain->conn;

     if (conn->driver->domainGetBlkioParameters) {
@@ -6515,6 +6529,13 @@ virDomainGetSchedulerParametersFlags(virDomainPtr domain,
     if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
                                  VIR_DRV_FEATURE_TYPED_PARAM_STRING))
         flags |= VIR_TYPED_PARAM_STRING_OKAY;
+
+    /* At most one of these two flags should be set.  */
+    if ((flags & VIR_DOMAIN_AFFECT_LIVE) &&
+        (flags & VIR_DOMAIN_AFFECT_CONFIG)) {
+        virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+        goto error;
+    }
     conn = domain->conn;

     if (conn->driver->domainGetSchedulerParametersFlags) {
@@ -7914,7 +7935,8 @@ virDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags)
     }

     /* At most one of these two flags should be set.  */
-    if ((flags & VIR_DOMAIN_AFFECT_LIVE) && (flags & VIR_DOMAIN_AFFECT_CONFIG)) {
+    if ((flags & VIR_DOMAIN_AFFECT_LIVE) &&
+        (flags & VIR_DOMAIN_AFFECT_CONFIG)) {
         virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         goto error;
     }
@@ -8011,7 +8033,7 @@ error:
  *      underlying virtualization system (Xen...).
  *      If maplen < size, missing bytes are set to zero.
  *      If maplen > size, failure code is returned.
- * @flags: bitwise-OR of virDomainModificationImpac
+ * @flags: bitwise-OR of virDomainModificationImpact
  *
  * Dynamically change the real CPUs which can be allocated to a virtual CPU.
  * This function may require privileged access to the hypervisor.
@@ -8102,8 +8124,8 @@ error:
  * -1 in case of failure.
  */
 int
-virDomainGetVcpuPinInfo (virDomainPtr domain, int ncpumaps,
-                         unsigned char *cpumaps, int maplen, unsigned int flags)
+virDomainGetVcpuPinInfo(virDomainPtr domain, int ncpumaps,
+                        unsigned char *cpumaps, int maplen, unsigned int flags)
 {
     virConnectPtr conn;

@@ -8124,6 +8146,12 @@ virDomainGetVcpuPinInfo (virDomainPtr domain, int ncpumaps,
         goto error;
     }

+    /* At most one of these two flags should be set.  */
+    if ((flags & VIR_DOMAIN_AFFECT_LIVE) &&
+        (flags & VIR_DOMAIN_AFFECT_CONFIG)) {
+        virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+        goto error;
+    }
     conn = domain->conn;

     if (conn->driver->domainGetVcpuPinInfo) {
-- 
1.7.7.1


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