In subject: Refer to 'test_driver' to make it more obvious that this is not tests. On Thu, Apr 11, 2024 at 19:01:56 -0700, wucf@xxxxxxxxxxxxx wrote: > From: Chun Feng Wu <wucf@xxxxxxxxxxxxx> > > * Test "Set": testDomainSetThrottleGroup > * Test "Get": testDomainGetThrottleGroup > * Test "Del": testDomainDelThrottleGroup > > Signed-off-by: Chun Feng Wu <wucf@xxxxxxxxxxxxx> > --- Note I'm not really interested into the test driver at this point so I'll just skim this through. > src/test/test_driver.c | 382 +++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 382 insertions(+) > > diff --git a/src/test/test_driver.c b/src/test/test_driver.c > index ed0cdc0dab..6c631fc519 100644 > --- a/src/test/test_driver.c > +++ b/src/test/test_driver.c > @@ -4115,6 +4115,385 @@ testDomainGetBlockIoTune(virDomainPtr dom, > virDomainObjEndAPI(&vm); > return ret; > } > + > + > +static int > +testDomainSetThrottleGroup(virDomainPtr dom, > + const char *group, > + virTypedParameterPtr params, > + int nparams, > + unsigned int flags) > +{ > + virDomainObj *vm = NULL; > + virDomainDef *def = NULL; > + virDomainThrottleGroupDef info = { 0 }; > + virDomainThrottleGroupDef *cur_info = NULL; > + virTypedParameterPtr eventParams = NULL; > + int eventNparams = 0; > + int eventMaxparams = 0; > + int ret = -1; > + size_t i; > + > + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | > + VIR_DOMAIN_AFFECT_CONFIG, -1); > + if (virTypedParamsValidate(params, nparams, > + VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC, > + VIR_TYPED_PARAM_ULLONG, > + VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC, > + VIR_TYPED_PARAM_ULLONG, > + VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC, > + VIR_TYPED_PARAM_ULLONG, > + VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC, > + VIR_TYPED_PARAM_ULLONG, > + VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC, > + VIR_TYPED_PARAM_ULLONG, > + VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC, > + VIR_TYPED_PARAM_ULLONG, > + VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC_MAX, > + VIR_TYPED_PARAM_ULLONG, > + VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC_MAX, > + VIR_TYPED_PARAM_ULLONG, > + VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC_MAX, > + VIR_TYPED_PARAM_ULLONG, > + VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC_MAX, > + VIR_TYPED_PARAM_ULLONG, > + VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC_MAX, > + VIR_TYPED_PARAM_ULLONG, > + VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC_MAX, > + VIR_TYPED_PARAM_ULLONG, > + VIR_DOMAIN_BLOCK_IOTUNE_SIZE_IOPS_SEC, > + VIR_TYPED_PARAM_ULLONG, > + VIR_DOMAIN_BLOCK_IOTUNE_GROUP_NAME, > + VIR_TYPED_PARAM_STRING, > + VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC_MAX_LENGTH, > + VIR_TYPED_PARAM_ULLONG, > + VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC_MAX_LENGTH, > + VIR_TYPED_PARAM_ULLONG, > + VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC_MAX_LENGTH, > + VIR_TYPED_PARAM_ULLONG, > + VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC_MAX_LENGTH, > + VIR_TYPED_PARAM_ULLONG, > + VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC_MAX_LENGTH, > + VIR_TYPED_PARAM_ULLONG, > + VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC_MAX_LENGTH, > + VIR_TYPED_PARAM_ULLONG, > + NULL) < 0) > + return -1; > + > + if (!(vm = testDomObjFromDomain(dom))) > + return -1; > + > + if (!(def = virDomainObjGetOneDef(vm, flags))) > + goto cleanup; > + > + if (virTypedParamsAddString(&eventParams, &eventNparams, &eventMaxparams, > + VIR_DOMAIN_THROTTLE_GROUP, group) < 0) > + goto cleanup; > + > +#define SET_THROTTLE_FIELD(FIELD, STR, TUNABLE_STR) \ > + if (STREQ(param->field, STR)) { \ > + info.FIELD = param->value.ul; \ > + if (virTypedParamsAddULLong(&eventParams, &eventNparams, \ > + &eventMaxparams, \ > + TUNABLE_STR, \ > + param->value.ul) < 0) \ > + goto cleanup; \ > + continue; \ > + } > + > + for (i = 0; i < nparams; i++) { > + virTypedParameterPtr param = ¶ms[i]; > + > + if (param->value.ul > TEST_BLOCK_IOTUNE_MAX) { > + virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, > + _("throttle group value must be no more than %1$llu"), > + TEST_BLOCK_IOTUNE_MAX); > + goto cleanup; > + } > + > + SET_THROTTLE_FIELD(total_bytes_sec, > + VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC, > + VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_BYTES_SEC); > + SET_THROTTLE_FIELD(read_bytes_sec, > + VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC, > + VIR_DOMAIN_TUNABLE_BLKDEV_READ_BYTES_SEC); > + SET_THROTTLE_FIELD(write_bytes_sec, > + VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC, > + VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_BYTES_SEC); > + SET_THROTTLE_FIELD(total_iops_sec, > + VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC, > + VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_IOPS_SEC); > + SET_THROTTLE_FIELD(read_iops_sec, > + VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC, > + VIR_DOMAIN_TUNABLE_BLKDEV_READ_IOPS_SEC); > + SET_THROTTLE_FIELD(write_iops_sec, > + VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC, > + VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_IOPS_SEC); > + > + SET_THROTTLE_FIELD(total_bytes_sec_max, > + VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC_MAX, > + VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_BYTES_SEC_MAX); > + SET_THROTTLE_FIELD(read_bytes_sec_max, > + VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC_MAX, > + VIR_DOMAIN_TUNABLE_BLKDEV_READ_BYTES_SEC_MAX); > + SET_THROTTLE_FIELD(write_bytes_sec_max, > + VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC_MAX, > + VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_BYTES_SEC_MAX); > + SET_THROTTLE_FIELD(total_iops_sec_max, > + VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC_MAX, > + VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_IOPS_SEC_MAX); > + SET_THROTTLE_FIELD(read_iops_sec_max, > + VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC_MAX, > + VIR_DOMAIN_TUNABLE_BLKDEV_READ_IOPS_SEC_MAX); > + SET_THROTTLE_FIELD(write_iops_sec_max, > + VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC_MAX, > + VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_IOPS_SEC_MAX); > + SET_THROTTLE_FIELD(size_iops_sec, > + VIR_DOMAIN_BLOCK_IOTUNE_SIZE_IOPS_SEC, > + VIR_DOMAIN_TUNABLE_BLKDEV_SIZE_IOPS_SEC); > + > + /* NB: Cannot use macro since this is a value.s not a value.ul */ > + if (STREQ(param->field, VIR_DOMAIN_BLOCK_IOTUNE_GROUP_NAME)) { > + VIR_FREE(info.group_name); > + info.group_name = g_strdup(param->value.s); > + if (virTypedParamsAddString(&eventParams, &eventNparams, > + &eventMaxparams, > + VIR_DOMAIN_TUNABLE_BLKDEV_GROUP_NAME, > + param->value.s) < 0) > + goto cleanup; > + continue; > + } > + > + SET_THROTTLE_FIELD(total_bytes_sec_max_length, > + VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC_MAX_LENGTH, > + VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_BYTES_SEC_MAX_LENGTH); > + SET_THROTTLE_FIELD(read_bytes_sec_max_length, > + VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC_MAX_LENGTH, > + VIR_DOMAIN_TUNABLE_BLKDEV_READ_BYTES_SEC_MAX_LENGTH); > + SET_THROTTLE_FIELD(write_bytes_sec_max_length, > + VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC_MAX_LENGTH, > + VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_BYTES_SEC_MAX_LENGTH); > + SET_THROTTLE_FIELD(total_iops_sec_max_length, > + VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC_MAX_LENGTH, > + VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_IOPS_SEC_MAX_LENGTH); > + SET_THROTTLE_FIELD(read_iops_sec_max_length, > + VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC_MAX_LENGTH, > + VIR_DOMAIN_TUNABLE_BLKDEV_READ_IOPS_SEC_MAX_LENGTH); > + SET_THROTTLE_FIELD(write_iops_sec_max_length, > + VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC_MAX_LENGTH, > + VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_IOPS_SEC_MAX_LENGTH); > + } > + > +#undef SET_THROTTLE_FIELD > + > + if ((info.total_bytes_sec && info.read_bytes_sec) || > + (info.total_bytes_sec && info.write_bytes_sec)) { > + virReportError(VIR_ERR_INVALID_ARG, "%s", > + _("total and read/write of bytes_sec cannot be set at the same time")); > + goto cleanup; > + } > + > + if ((info.total_iops_sec && info.read_iops_sec) || > + (info.total_iops_sec && info.write_iops_sec)) { > + virReportError(VIR_ERR_INVALID_ARG, "%s", > + _("total and read/write of iops_sec cannot be set at the same time")); > + goto cleanup; > + } > + > + if ((info.total_bytes_sec_max && info.read_bytes_sec_max) || > + (info.total_bytes_sec_max && info.write_bytes_sec_max)) { > + virReportError(VIR_ERR_INVALID_ARG, "%s", > + _("total and read/write of bytes_sec_max cannot be set at the same time")); > + goto cleanup; > + } > + > + if ((info.total_iops_sec_max && info.read_iops_sec_max) || > + (info.total_iops_sec_max && info.write_iops_sec_max)) { > + virReportError(VIR_ERR_INVALID_ARG, "%s", > + _("total and read/write of iops_sec_max cannot be set at the same time")); > + goto cleanup; > + } > + > +#define TEST_BLOCK_IOTUNE_MAX_CHECK(FIELD, FIELD_MAX) \ > + do { \ > + if (info.FIELD > info.FIELD_MAX) { \ > + virReportError(VIR_ERR_INVALID_ARG, \ > + _("%1$s cannot be set higher than %2$s"), \ > + #FIELD, #FIELD_MAX); \ > + goto cleanup; \ > + } \ > + } while (0); > + > + TEST_BLOCK_IOTUNE_MAX_CHECK(total_bytes_sec, total_bytes_sec_max); > + TEST_BLOCK_IOTUNE_MAX_CHECK(read_bytes_sec, read_bytes_sec_max); > + TEST_BLOCK_IOTUNE_MAX_CHECK(write_bytes_sec, write_bytes_sec_max); > + TEST_BLOCK_IOTUNE_MAX_CHECK(total_iops_sec, total_iops_sec_max); > + TEST_BLOCK_IOTUNE_MAX_CHECK(read_iops_sec, read_iops_sec_max); > + TEST_BLOCK_IOTUNE_MAX_CHECK(write_iops_sec, write_iops_sec_max); > + > +#undef TEST_BLOCK_IOTUNE_MAX_CHECK > + > + cur_info = virDomainThrottleGroupByName(def, group); > + if (cur_info != NULL) { > + virDomainThrottleGroupUpdate(def, &info); > + }else{ > + virDomainThrottleGroupAdd(def, &info); > + } > + ret = 0; > + > + cleanup: > + VIR_FREE(info.group_name); > + virDomainObjEndAPI(&vm); > + if (eventNparams) > + virTypedParamsFree(eventParams, eventNparams); > + return ret; > +} > + > + > +static int > +testDomainGetThrottleGroup(virDomainPtr dom, > + const char *groupname, > + virTypedParameterPtr params, > + int *nparams, > + unsigned int flags) > +{ > + virDomainObj *vm = NULL; > + virDomainDef *def = NULL; > + virDomainThrottleGroupDef groupDef = {0}; > + virDomainThrottleGroupDef *reply = &groupDef; > + int ret = -1; > + > + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | > + VIR_DOMAIN_AFFECT_CONFIG | > + VIR_TYPED_PARAM_STRING_OKAY, -1); > + > + /* We don't return strings, and thus trivially support this flag. */ > + flags &= ~VIR_TYPED_PARAM_STRING_OKAY; > + > + if (*nparams == 0) { > + *nparams = 20; > + return 0; > + } > + > + if (!(vm = testDomObjFromDomain(dom))) > + return -1; > + > + if (!(def = virDomainObjGetOneDef(vm, flags))) > + goto cleanup; > + > + > + if (!(reply = virDomainThrottleGroupByName(def, groupname))) { > + virReportError(VIR_ERR_INVALID_ARG, > + _("throttle group '%1$s' was not found in the domain config"), > + groupname); > + goto cleanup; > + } > + reply->group_name = g_strdup(groupname); > + TEST_SET_PARAM(0, VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC, > + VIR_TYPED_PARAM_ULLONG, reply->total_bytes_sec); > + TEST_SET_PARAM(1, VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC, > + VIR_TYPED_PARAM_ULLONG, reply->read_bytes_sec); > + TEST_SET_PARAM(2, VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC, > + VIR_TYPED_PARAM_ULLONG, reply->write_bytes_sec); > + > + TEST_SET_PARAM(3, VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC, > + VIR_TYPED_PARAM_ULLONG, reply->total_iops_sec); > + TEST_SET_PARAM(4, VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC, > + VIR_TYPED_PARAM_ULLONG, reply->read_iops_sec); > + TEST_SET_PARAM(5, VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC, > + VIR_TYPED_PARAM_ULLONG, reply->write_iops_sec); > + > + TEST_SET_PARAM(6, VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC_MAX, > + VIR_TYPED_PARAM_ULLONG, reply->total_bytes_sec_max); > + TEST_SET_PARAM(7, VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC_MAX, > + VIR_TYPED_PARAM_ULLONG, reply->read_bytes_sec_max); > + TEST_SET_PARAM(8, VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC_MAX, > + VIR_TYPED_PARAM_ULLONG, reply->write_bytes_sec_max); > + > + TEST_SET_PARAM(9, VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC_MAX, > + VIR_TYPED_PARAM_ULLONG, reply->total_iops_sec_max); > + TEST_SET_PARAM(10, VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC_MAX, > + VIR_TYPED_PARAM_ULLONG, reply->read_iops_sec_max); > + TEST_SET_PARAM(11, VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC_MAX, > + VIR_TYPED_PARAM_ULLONG, reply->write_iops_sec_max); > + > + TEST_SET_PARAM(12, VIR_DOMAIN_BLOCK_IOTUNE_SIZE_IOPS_SEC, > + VIR_TYPED_PARAM_ULLONG, reply->size_iops_sec); > + > + TEST_SET_PARAM(13, VIR_DOMAIN_BLOCK_IOTUNE_GROUP_NAME, > + VIR_TYPED_PARAM_STRING, reply->group_name); > + reply->group_name = NULL; > + > + TEST_SET_PARAM(14, VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC_MAX_LENGTH, > + VIR_TYPED_PARAM_ULLONG, reply->total_bytes_sec_max_length); > + TEST_SET_PARAM(15, VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC_MAX_LENGTH, > + VIR_TYPED_PARAM_ULLONG, reply->read_bytes_sec_max_length); > + TEST_SET_PARAM(16, VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC_MAX_LENGTH, > + VIR_TYPED_PARAM_ULLONG, reply->write_bytes_sec_max_length); > + > + TEST_SET_PARAM(17, VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC_MAX_LENGTH, > + VIR_TYPED_PARAM_ULLONG, reply->total_iops_sec_max_length); > + TEST_SET_PARAM(18, VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC_MAX_LENGTH, > + VIR_TYPED_PARAM_ULLONG, reply->read_iops_sec_max_length); > + TEST_SET_PARAM(19, VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC_MAX_LENGTH, > + VIR_TYPED_PARAM_ULLONG, reply->write_iops_sec_max_length); > + > + if (*nparams > 20) > + *nparams = 20; > + > + ret = 0; > + > + cleanup: > + if (reply != NULL && reply->group_name != NULL) { > + g_free(reply->group_name); > + } > + virDomainObjEndAPI(&vm); > + return ret; > +} > + > + > +static int > +testDomainDelThrottleGroup(virDomainPtr dom, > + const char *groupname, > + unsigned int flags) > +{ > + virDomainObj *vm = NULL; > + virDomainDef *def = NULL; > + virDomainThrottleGroupDef groupDef = {0}; > + virDomainThrottleGroupDef *reply = &groupDef; > + int ret = -1; > + > + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | > + VIR_DOMAIN_AFFECT_CONFIG | > + VIR_TYPED_PARAM_STRING_OKAY, -1); > + > + /* We don't return strings, and thus trivially support this flag. */ > + flags &= ~VIR_TYPED_PARAM_STRING_OKAY; > + > + if (!(vm = testDomObjFromDomain(dom))) > + return -1; > + > + /* the API check guarantees that only one of the definitions will be set */ > + if (!(def = virDomainObjGetOneDef(vm, flags))) > + goto cleanup; > + > + if (!(reply = virDomainThrottleGroupByName(def, groupname))) { > + virReportError(VIR_ERR_INVALID_ARG, > + _("throttle group '%1$s' was not found in the domain config"), > + groupname); > + goto cleanup; > + } > + > + ret = 0; > + > + cleanup: > + if (reply) { > + VIR_FREE(reply->group_name); This looks a bit fragile, didn't you declare a destructor for this? > + } > + virDomainObjEndAPI(&vm); > + return ret; > +} > + > #undef TEST_SET_PARAM > > > @@ -10468,6 +10847,9 @@ static virHypervisorDriver testHypervisorDriver = { > .domainGetInterfaceParameters = testDomainGetInterfaceParameters, /* 5.6.0 */ > .domainSetBlockIoTune = testDomainSetBlockIoTune, /* 5.7.0 */ > .domainGetBlockIoTune = testDomainGetBlockIoTune, /* 5.7.0 */ > + .domainSetThrottleGroup = testDomainSetThrottleGroup, /* 10.3.0 */ > + .domainGetThrottleGroup = testDomainGetThrottleGroup, /* 10.3.0 */ > + .domainDelThrottleGroup = testDomainDelThrottleGroup, /* 10.3.0 */ Don't forget to update these.