On Wed, Jul 24, 2019 at 04:07:29PM +0200, Ilias Stamatis wrote: > Signed-off-by: Ilias Stamatis <stamatis.iliass@xxxxxxxxx> > --- > src/test/test_driver.c | 106 +++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 106 insertions(+) > > diff --git a/src/test/test_driver.c b/src/test/test_driver.c > index 7cf92e78a7..fce38acc17 100644 > --- a/src/test/test_driver.c > +++ b/src/test/test_driver.c > @@ -3108,6 +3108,111 @@ testDomainGetNumaParameters(virDomainPtr dom, > } > > > +static int > +testDomainSetInterfaceParameters(virDomainPtr dom, > + const char *device, > + virTypedParameterPtr params, > + int nparams, > + unsigned int flags) > +{ > + virDomainObjPtr vm = NULL; > + virDomainDefPtr def; > + virDomainNetDefPtr net = NULL; > + virNetDevBandwidthPtr bandwidth = NULL; > + bool inboundSpecified = false; > + bool outboundSpecified = false; > + size_t i; > + int ret = -1; > + > + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | > + VIR_DOMAIN_AFFECT_CONFIG, -1); > + > + if (virTypedParamsValidate(params, nparams, > + VIR_DOMAIN_BANDWIDTH_IN_AVERAGE, > + VIR_TYPED_PARAM_UINT, > + VIR_DOMAIN_BANDWIDTH_IN_PEAK, > + VIR_TYPED_PARAM_UINT, > + VIR_DOMAIN_BANDWIDTH_IN_BURST, > + VIR_TYPED_PARAM_UINT, > + VIR_DOMAIN_BANDWIDTH_IN_FLOOR, > + VIR_TYPED_PARAM_UINT, > + VIR_DOMAIN_BANDWIDTH_OUT_AVERAGE, > + VIR_TYPED_PARAM_UINT, > + VIR_DOMAIN_BANDWIDTH_OUT_PEAK, > + VIR_TYPED_PARAM_UINT, > + VIR_DOMAIN_BANDWIDTH_OUT_BURST, > + VIR_TYPED_PARAM_UINT, > + NULL) < 0) > + return -1; > + > + if (!(vm = testDomObjFromDomain(dom))) > + return -1; > + > + if (!(def = virDomainObjGetOneDef(vm, flags))) > + goto cleanup; > + > + if (!(net = virDomainNetFind(def, device))) > + goto cleanup; > + > + if ((VIR_ALLOC(bandwidth) < 0) || > + (VIR_ALLOC(bandwidth->in) < 0) || > + (VIR_ALLOC(bandwidth->out) < 0)) > + goto cleanup; > + > + for (i = 0; i < nparams; i++) { > + virTypedParameterPtr param = ¶ms[i]; > + > + if (STREQ(param->field, VIR_DOMAIN_BANDWIDTH_IN_AVERAGE)) { > + bandwidth->in->average = param->value.ui; > + inboundSpecified = true; > + } else if (STREQ(param->field, VIR_DOMAIN_BANDWIDTH_IN_PEAK)) { > + bandwidth->in->peak = param->value.ui; > + } else if (STREQ(param->field, VIR_DOMAIN_BANDWIDTH_IN_BURST)) { > + bandwidth->in->burst = param->value.ui; > + } else if (STREQ(param->field, VIR_DOMAIN_BANDWIDTH_IN_FLOOR)) { > + bandwidth->in->floor = param->value.ui; > + inboundSpecified = true; > + } else if (STREQ(param->field, VIR_DOMAIN_BANDWIDTH_OUT_AVERAGE)) { > + bandwidth->out->average = param->value.ui; > + outboundSpecified = true; > + } else if (STREQ(param->field, VIR_DOMAIN_BANDWIDTH_OUT_PEAK)) { > + bandwidth->out->peak = param->value.ui; > + } else if (STREQ(param->field, VIR_DOMAIN_BANDWIDTH_OUT_BURST)) { > + bandwidth->out->burst = param->value.ui; > + } > + } > + > + /* average or floor are mandatory, peak and burst are optional */ > + if (!bandwidth->in->average && !bandwidth->in->floor) > + VIR_FREE(bandwidth->in); > + if (!bandwidth->out->average) > + VIR_FREE(bandwidth->out); > + > + if (!net->bandwidth) { > + VIR_STEAL_PTR(net->bandwidth, bandwidth); > + } else { > + if (bandwidth->in) { > + VIR_FREE(net->bandwidth->in); > + VIR_STEAL_PTR(net->bandwidth->in, bandwidth->in); > + } else if (inboundSpecified) { To avoid any kind of confusion in the future I'd prefer an explicit comment like the following: /* If we got here it means user requested inbound to be cleared */ > + VIR_FREE(net->bandwidth->in); > + } > + if (bandwidth->out) { > + VIR_FREE(net->bandwidth->out); > + VIR_STEAL_PTR(net->bandwidth->out, bandwidth->out); > + } else if (outboundSpecified) { Similarly here for outbound... I'll adjust before merging. Reviewed-by: Erik Skultety <eskultet@xxxxxxxxxx> -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list