[PATCH 1/6] Clarify semantic of nparams argument of virDomainGetSchedulerType

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

 



Some drivers assumed it can be NULL (e.g. qemu and lxc) and check it
before assigning to it, other drivers assumed it must be non-NULL
(e.g. test and esx) and just assigned to it.

Unify this to nparams being optional and document it.
---
 src/esx/esx_driver.c       |    4 +++-
 src/libvirt.c              |    5 +++--
 src/libxl/libxl_driver.c   |    6 ++++--
 src/test/test_driver.c     |    4 +++-
 src/xen/xend_internal.c    |    9 +++++----
 src/xenapi/xenapi_driver.c |    4 +++-
 6 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index bb9d60a..7fe5446 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -3513,7 +3513,9 @@ esxDomainGetSchedulerType(virDomainPtr domain ATTRIBUTE_UNUSED, int *nparams)
         return NULL;
     }
 
-    *nparams = 3; /* reservation, limit, shares */
+    if (nparams != NULL) {
+        *nparams = 3; /* reservation, limit, shares */
+    }
 
     return type;
 }
diff --git a/src/libvirt.c b/src/libvirt.c
index 56b1257..45bc9b0 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -4973,9 +4973,10 @@ error:
 /**
  * virDomainGetSchedulerType:
  * @domain: pointer to domain object
- * @nparams: number of scheduler parameters(return value)
+ * @nparams: pointer to number of scheduler parameters, can be NULL
+ *           (return value)
  *
- * Get the scheduler type.
+ * Get the scheduler type and the number of scheduler parameters.
  *
  * Returns NULL in case of error. The caller must free the returned string.
  */
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 5cc9362..6b2d806 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -2396,14 +2396,16 @@ libxlDomainGetSchedulerType(virDomainPtr dom, int *nparams)
         goto cleanup;
     }
 
-    *nparams = 0;
+    if (nparams)
+        *nparams = 0;
     switch(sched_id) {
     case XEN_SCHEDULER_SEDF:
         ret = strdup("sedf");
         break;
     case XEN_SCHEDULER_CREDIT:
         ret = strdup("credit");
-        *nparams = XEN_SCHED_CREDIT_NPARAM;
+        if (nparams)
+            *nparams = XEN_SCHED_CREDIT_NPARAM;
         break;
     case XEN_SCHEDULER_CREDIT2:
         ret = strdup("credit2");
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 658bcee..d9e9cb9 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -2617,7 +2617,9 @@ static char *testDomainGetSchedulerType(virDomainPtr domain ATTRIBUTE_UNUSED,
 {
     char *type = NULL;
 
-    *nparams = 1;
+    if (nparams)
+        *nparams = 1;
+
     type = strdup("fair");
     if (!type)
         virReportOOMError();
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index dfa0342..359d5f4 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -3531,8 +3531,7 @@ xenDaemonGetSchedulerType(virDomainPtr domain, int *nparams)
     const char *ret = NULL;
     char *schedulertype = NULL;
 
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)
-        || (nparams == NULL)) {
+    if (domain->conn == NULL || domain->name == NULL) {
         virXendError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return NULL;
     }
@@ -3562,14 +3561,16 @@ xenDaemonGetSchedulerType(virDomainPtr domain, int *nparams)
             virReportOOMError();
             goto error;
         }
-        *nparams = XEN_SCHED_CRED_NPARAM;
+        if (nparams)
+            *nparams = XEN_SCHED_CRED_NPARAM;
     } else if (STREQ (ret, "sedf")) {
         schedulertype = strdup("sedf");
         if (schedulertype == NULL){
             virReportOOMError();
             goto error;
         }
-        *nparams = XEN_SCHED_SEDF_NPARAM;
+        if (nparams)
+            *nparams = XEN_SCHED_SEDF_NPARAM;
     } else {
         virXendError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unknown scheduler"));
         goto error;
diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c
index 13b9161..6f64208 100644
--- a/src/xenapi/xenapi_driver.c
+++ b/src/xenapi/xenapi_driver.c
@@ -1767,7 +1767,9 @@ static char *
 xenapiDomainGetSchedulerType (virDomainPtr dom ATTRIBUTE_UNUSED, int *nparams)
 {
     char *result = NULL;
-    *nparams = 0;
+
+    if (nparams)
+        *nparams = 0;
     if (!(result = strdup("credit")))
         virReportOOMError();
     return result;
-- 
1.7.0.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]