src/test/test_driver.c | 97 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+)
Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
---
src/test/test_driver.c | 97 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 97 insertions(+)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 7dd448bb20..fd57c8c572 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -2945,6 +2945,102 @@ 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;
+ 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;
+ } 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;
+ } else if (STREQ(param->field, VIR_DOMAIN_BANDWIDTH_OUT_AVERAGE)) {
+ bandwidth->out->average = param->value.ui;
+ } 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);
+ }
+ if (bandwidth->out) {
+ VIR_FREE(net->bandwidth->out);
+ VIR_STEAL_PTR(net->bandwidth->out, bandwidth->out);
+ }
+ }
+
+ ret = 0;
+ cleanup:
+ virNetDevBandwidthFree(bandwidth);
+ virDomainObjEndAPI(&vm);
+ return ret;
+}
+
+
static int
testDomainGetInterfaceParameters(virDomainPtr dom,
const char *device,
@@ -7617,6 +7713,7 @@ static virHypervisorDriver testHypervisorDriver = {
.domainGetXMLDesc = testDomainGetXMLDesc, /* 0.1.4 */
.domainGetMemoryParameters = testDomainGetMemoryParameters, /* 5.6.0 */
.domainGetNumaParameters = testDomainGetNumaParameters, /* 5.6.0 */
+ .domainSetInterfaceParameters = testDomainSetInterfaceParameters, /* 5.6.0 */
.domainGetInterfaceParameters = testDomainGetInterfaceParameters, /* 5.6.0 */
.connectListDefinedDomains = testConnectListDefinedDomains, /* 0.1.11 */
.connectNumOfDefinedDomains = testConnectNumOfDefinedDomains, /* 0.1.11 */
--
2.22.0
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
On Sat, Jul 06, 2019 at 01:24:22PM +0200, Ilias Stamatis wrote: > Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com> > --- ... > + > + /* 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); > + } > + if (bandwidth->out) { > + VIR_FREE(net->bandwidth->out); > + VIR_STEAL_PTR(net->bandwidth->out, bandwidth->out); > + } > + } Doesn't look quite right, you just lost any way of resetting the bandwidth when in fact this should be possible simply with setting .average=0, that's why the original QEMU code uses booleans, because then at the end, the whole net->bandwidth structure is set to NULL if reset was requested. Erik -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
On Wed, Jul 24, 2019 at 1:04 PM Erik Skultety <eskultet@redhat.com> wrote: > > On Sat, Jul 06, 2019 at 01:24:22PM +0200, Ilias Stamatis wrote: > > Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com> > > --- > ... > > > + > > + /* 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); > > + } > > + if (bandwidth->out) { > > + VIR_FREE(net->bandwidth->out); > > + VIR_STEAL_PTR(net->bandwidth->out, bandwidth->out); > > + } > > + } > > Doesn't look quite right, you just lost any way of resetting the bandwidth when > in fact this should be possible simply with setting .average=0, that's why the > original QEMU code uses booleans, because then at the end, the whole > net->bandwidth structure is set to NULL if reset was requested. > > Erik Aaah, right. This is one of the cases where many implicit comparisons can be confusing. When I was reading that code I was wondering how these booleans are useful at all. Now I get it, I'll send a v2. Thanks, Ilias -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
On Sat, Jul 6, 2019 at 1:24 PM Ilias Stamatis <stamatis.iliass@gmail.com> wrote: > > Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com> > --- > src/test/test_driver.c | 97 ++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 97 insertions(+) > > diff --git a/src/test/test_driver.c b/src/test/test_driver.c > index 7dd448bb20..fd57c8c572 100644 > --- a/src/test/test_driver.c > +++ b/src/test/test_driver.c > @@ -2945,6 +2945,102 @@ 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; > + 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; > + } 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; > + } else if (STREQ(param->field, VIR_DOMAIN_BANDWIDTH_OUT_AVERAGE)) { > + bandwidth->out->average = param->value.ui; > + } 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); > + } > + if (bandwidth->out) { > + VIR_FREE(net->bandwidth->out); > + VIR_STEAL_PTR(net->bandwidth->out, bandwidth->out); > + } > + } > + > + ret = 0; > + cleanup: > + virNetDevBandwidthFree(bandwidth); > + virDomainObjEndAPI(&vm); > + return ret; > +} > + > + > static int > testDomainGetInterfaceParameters(virDomainPtr dom, > const char *device, > @@ -7617,6 +7713,7 @@ static virHypervisorDriver testHypervisorDriver = { > .domainGetXMLDesc = testDomainGetXMLDesc, /* 0.1.4 */ > .domainGetMemoryParameters = testDomainGetMemoryParameters, /* 5.6.0 */ > .domainGetNumaParameters = testDomainGetNumaParameters, /* 5.6.0 */ > + .domainSetInterfaceParameters = testDomainSetInterfaceParameters, /* 5.6.0 */ > .domainGetInterfaceParameters = testDomainGetInterfaceParameters, /* 5.6.0 */ > .connectListDefinedDomains = testConnectListDefinedDomains, /* 0.1.11 */ > .connectNumOfDefinedDomains = testConnectNumOfDefinedDomains, /* 0.1.11 */ > -- > 2.22.0 > Oops, I forgot to prepend the subject / commit message with "test_driver: " -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
© 2016 - 2024 Red Hat, Inc.