Add invalid argument checks for params and nparams to the public API and remove the from the drivers (e.g. xend).
Add subset handling to libxl and test drivers. --- src/libvirt.c | 24 ++++++++++++++++++------ src/libxl/libxl_driver.c | 6 ++++-- src/test/test_driver.c | 27 +++++++++++++-------------- src/xen/xen_hypervisor.c | 7 +++---- src/xen/xend_internal.c | 3 +-- 5 files changed, 39 insertions(+), 28 deletions(-) diff --git a/src/libvirt.c b/src/libvirt.c index e8b5b80..2c2866e 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -5069,11 +5069,11 @@ error: * virDomainSetSchedulerParameters: * @domain: pointer to domain object * @params: pointer to scheduler parameter objects - * @nparams: number of scheduler parameter - * (this value should be same or less than the returned value + * @nparams: number of scheduler parameter objects + * (this value can be the same or less than the returned value * nparams of virDomainGetSchedulerType) * - * Change the scheduler parameters + * Change all or a subset or the scheduler parameters. * * Returns -1 in case of error, 0 in case of success. */ @@ -5092,6 +5092,12 @@ virDomainSetSchedulerParameters(virDomainPtr domain, virDispatchError(NULL); return -1; } + + if (params == NULL || nparams < 0) { + virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__); + goto error; + } + if (domain->conn->flags & VIR_CONNECT_RO) { virLibDomainError(VIR_ERR_OPERATION_DENIED, __FUNCTION__); goto error; @@ -5118,12 +5124,12 @@ error: * virDomainSetSchedulerParametersFlags: * @domain: pointer to domain object * @params: pointer to scheduler parameter objects - * @nparams: number of scheduler parameter - * (this value should be same or less than the returned value + * @nparams: number of scheduler parameter objects + * (this value can be the same or less than the returned value * nparams of virDomainGetSchedulerType) * @flags: virDomainSchedParameterFlags * - * Change the scheduler parameters + * Change a subset or all scheduler parameters. * * Returns -1 in case of error, 0 in case of success. */ @@ -5153,6 +5159,12 @@ virDomainSetSchedulerParametersFlags(virDomainPtr domain, virDispatchError(NULL); return -1; } + + if (params == NULL || nparams < 0) { + virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__); + goto error; + } + if (domain->conn->flags & VIR_CONNECT_RO) { virLibDomainError(VIR_ERR_OPERATION_DENIED, __FUNCTION__); goto error; diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index b85c743..1d41e2d 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -2544,8 +2544,10 @@ libxlDomainSetSchedulerParameters(virDomainPtr dom, virSchedParameterPtr params, goto cleanup; } - if (nparams != XEN_SCHED_CREDIT_NPARAM) { - libxlError(VIR_ERR_INVALID_ARG, "%s", _("Invalid parameter count")); + if (libxl_sched_credit_domain_get(&priv->ctx, dom->id, &sc_info) != 0) { + libxlError(VIR_ERR_INTERNAL_ERROR, + _("Failed to get scheduler parameters for domain '%d'" + " with libxenlight"), dom->id); goto cleanup; } diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 4897081..69aeb29 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -2671,7 +2671,7 @@ static int testDomainSetSchedulerParams(virDomainPtr domain, { testConnPtr privconn = domain->conn->privateData; virDomainObjPtr privdom; - int ret = -1; + int ret = -1, i; testDriverLock(privconn); privdom = virDomainFindByName(&privconn->domains, @@ -2683,20 +2683,19 @@ static int testDomainSetSchedulerParams(virDomainPtr domain, goto cleanup; } - if (nparams != 1) { - testError(VIR_ERR_INVALID_ARG, "nparams"); - goto cleanup; - } - if (STRNEQ(params[0].field, "weight")) { - testError(VIR_ERR_INVALID_ARG, "field"); - goto cleanup; - } - if (params[0].type != VIR_DOMAIN_SCHED_FIELD_UINT) { - testError(VIR_ERR_INVALID_ARG, "type"); - goto cleanup; + for (i = 0; i < nparams; i++) { + if (STRNEQ(params[i].field, "weight")) { + testError(VIR_ERR_INVALID_ARG, "field"); + goto cleanup; + } + if (params[i].type != VIR_DOMAIN_SCHED_FIELD_UINT) { + testError(VIR_ERR_INVALID_ARG, "type"); + goto cleanup; + } + /* XXX */ + /*privdom->weight = params[i].value.ui;*/ } - /* XXX */ - /*privdom->weight = params[0].value.ui;*/ + ret = 0; cleanup: diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c index 8d579bc..253164e 100644 --- a/src/xen/xen_hypervisor.c +++ b/src/xen/xen_hypervisor.c @@ -1364,10 +1364,9 @@ xenHypervisorSetSchedulerParameters(virDomainPtr domain, return -1; } - if ((nparams == 0) || (params == NULL)) { - virXenErrorFunc(VIR_ERR_INVALID_ARG, __FUNCTION__, - "Noparameters given", 0); - return(-1); + if (nparams == 0) { + /* nothing to do, exit early */ + return 0; } priv = (xenUnifiedPrivatePtr) domain->conn->privateData; diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c index 0fa8042..1a3c3b4 100644 --- a/src/xen/xend_internal.c +++ b/src/xen/xend_internal.c @@ -3712,8 +3712,7 @@ xenDaemonSetSchedulerParameters(virDomainPtr domain, int sched_nparam = 0; int ret = -1; - if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) - || (params == NULL)) { + if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) { virXendError(VIR_ERR_INVALID_ARG, __FUNCTION__); return (-1); } -- 1.7.0.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list