On 11/02/2011 02:00 PM, Eric Blake wrote:
Allow the user to call with nparams too small, per API documentation. * src/xen/xen_hypervisor.c (xenHypervisorGetSchedulerParameters): Allow fewer than max. * src/xen/xend_internal.c (xenDaemonGetSchedulerParameters): Likewise. --- src/xen/xen_hypervisor.c | 26 ++++++++++++-------------- src/xen/xend_internal.c | 28 +++++++++++++--------------- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c index f1a8e68..634b23b 100644 --- a/src/xen/xen_hypervisor.c +++ b/src/xen/xen_hypervisor.c @@ -1274,11 +1274,6 @@ xenHypervisorGetSchedulerParameters(virDomainPtr domain, TODO return(-1); case XEN_SCHEDULER_CREDIT: - if (*nparams< XEN_SCHED_CRED_NPARAM) { - virXenError(VIR_ERR_INVALID_ARG, - "%s", _("Invalid parameter count")); - return -1; - } memset(&op_dom, 0, sizeof(op_dom)); op_dom.cmd = XEN_V2_OP_SCHEDULER; op_dom.domain = (domid_t) domain->id; @@ -1298,17 +1293,20 @@ xenHypervisorGetSchedulerParameters(virDomainPtr domain, params[0].type = VIR_TYPED_PARAM_UINT; params[0].value.ui = op_dom.u.getschedinfo.u.credit.weight;
Again assuming *nparams always >= 1, ok.
- if (virStrcpyStatic(params[1].field, - VIR_DOMAIN_SCHEDULER_CAP) == NULL) { - virXenError(VIR_ERR_INTERNAL_ERROR, - "Cap %s too big for destination", - VIR_DOMAIN_SCHEDULER_CAP); - return -1; + if (*nparams> 1) { + if (virStrcpyStatic(params[1].field, + VIR_DOMAIN_SCHEDULER_CAP) == NULL) { + virXenError(VIR_ERR_INTERNAL_ERROR, + "Cap %s too big for destination", + VIR_DOMAIN_SCHEDULER_CAP); + return -1; + } + params[1].type = VIR_TYPED_PARAM_UINT; + params[1].value.ui = op_dom.u.getschedinfo.u.credit.cap; } - params[1].type = VIR_TYPED_PARAM_UINT; - params[1].value.ui = op_dom.u.getschedinfo.u.credit.cap; - *nparams = XEN_SCHED_CRED_NPARAM; + if (*nparams> XEN_SCHED_CRED_NPARAM) + *nparams = XEN_SCHED_CRED_NPARAM; break; default: virXenErrorFunc(VIR_ERR_INVALID_ARG, __FUNCTION__, diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c index 4fcc628..80a2472 100644 --- a/src/xen/xend_internal.c +++ b/src/xen/xend_internal.c @@ -3614,12 +3614,6 @@ xenDaemonGetSchedulerParameters(virDomainPtr domain, TODO goto error; case XEN_SCHED_CRED_NPARAM: - if (*nparams< XEN_SCHED_CRED_NPARAM) { - virXendError(VIR_ERR_INVALID_ARG, - "%s", _("Invalid parameter count")); - goto error; - } - /* get cpu_weight/cpu_cap from xend/domain */ if (sexpr_node(root, "domain/cpu_weight") == NULL) { virXendError(VIR_ERR_INTERNAL_ERROR, @@ -3642,16 +3636,20 @@ xenDaemonGetSchedulerParameters(virDomainPtr domain, params[0].type = VIR_TYPED_PARAM_UINT; params[0].value.ui = sexpr_int(root, "domain/cpu_weight");
same as above
- if (virStrcpyStatic(params[1].field, - VIR_DOMAIN_SCHEDULER_CAP) == NULL) { - virXendError(VIR_ERR_INTERNAL_ERROR, - _("Cap %s too big for destination"), - VIR_DOMAIN_SCHEDULER_CAP); - goto error; + if (*nparams> 1) { + if (virStrcpyStatic(params[1].field, + VIR_DOMAIN_SCHEDULER_CAP) == NULL) { + virXendError(VIR_ERR_INTERNAL_ERROR, + _("Cap %s too big for destination"), + VIR_DOMAIN_SCHEDULER_CAP); + goto error; + } + params[1].type = VIR_TYPED_PARAM_UINT; + params[1].value.ui = sexpr_int(root, "domain/cpu_cap"); } - params[1].type = VIR_TYPED_PARAM_UINT; - params[1].value.ui = sexpr_int(root, "domain/cpu_cap"); - *nparams = XEN_SCHED_CRED_NPARAM; + + if (*nparams> XEN_SCHED_CRED_NPARAM) + *nparams = XEN_SCHED_CRED_NPARAM; ret = 0; break; default:
ACK -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list