[libvirt] [PATCH 0/3] Rewrite GetBlkioParameters

Reuse the code and make it (hoepfully) more readable. Ján Tomko (3): Split out virDomainGetBlkioParametersInternal Reuse GetBlkioParameters code for live and persistent XML Rewrite virDomainGetBlkioParametersInternal src/conf/domain_conf.c | 169 +++++++++++++++++++++ src/conf/domain_conf.h | 8 + src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 374 +-------------------------------------------- src/qemu/qemu_driver.c | 383 +---------------------------------------------- 5 files changed, 186 insertions(+), 749 deletions(-) -- 1.8.5.5

Reuse the common code from LXC and QEMU drivers. --- src/conf/domain_conf.c | 383 +++++++++++++++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 8 + src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 374 +-------------------------------------------- src/qemu/qemu_driver.c | 383 +---------------------------------------------- 5 files changed, 400 insertions(+), 749 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 4114289..4fe7cb6 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19777,3 +19777,386 @@ virDomainObjSetMetadata(virDomainObjPtr vm, return 0; } + +#define CONF_NB_BLKIO_PARAM 6 + +int +virDomainGetBlkioParametersInternal(virCgroupPtr cgroup, + virDomainDefPtr def, + virDomainDefPtr persistentDef, + virTypedParameterPtr params, + int *nparams, + unsigned int flags) +{ + int ret = -1; + size_t i, j; + unsigned int val; + + if ((*nparams) == 0) { + /* Current number of blkio parameters supported by cgroups */ + *nparams = CONF_NB_BLKIO_PARAM; + ret = 0; + goto cleanup; + } + + if (flags & VIR_DOMAIN_AFFECT_LIVE) { + if (!virCgroupHasController(cgroup, VIR_CGROUP_CONTROLLER_BLKIO)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("blkio cgroup isn't mounted")); + goto cleanup; + } + + for (i = 0; i < *nparams && i < CONF_NB_BLKIO_PARAM; i++) { + virTypedParameterPtr param = ¶ms[i]; + val = 0; + + switch (i) { + case 0: /* fill blkio weight here */ + if (virCgroupGetBlkioWeight(cgroup, &val) < 0) + goto cleanup; + if (virTypedParameterAssign(param, VIR_DOMAIN_BLKIO_WEIGHT, + VIR_TYPED_PARAM_UINT, val) < 0) + goto cleanup; + break; + + case 1: /* blkiotune.device_weight */ + if (def->blkio.ndevices > 0) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + bool comma = false; + + for (j = 0; j < def->blkio.ndevices; j++) { + if (!def->blkio.devices[j].weight) + continue; + if (comma) + virBufferAddChar(&buf, ','); + else + comma = true; + virBufferAsprintf(&buf, "%s,%u", + def->blkio.devices[j].path, + def->blkio.devices[j].weight); + } + if (virBufferError(&buf)) { + virReportOOMError(); + goto cleanup; + } + param->value.s = virBufferContentAndReset(&buf); + } + if (virTypedParameterAssign(param, + VIR_DOMAIN_BLKIO_DEVICE_WEIGHT, + VIR_TYPED_PARAM_STRING, + param->value.s) < 0) + goto cleanup; + break; + + case 2: /* blkiotune.device_read_iops */ + if (def->blkio.ndevices > 0) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + bool comma = false; + + for (j = 0; j < def->blkio.ndevices; j++) { + if (!def->blkio.devices[j].riops) + continue; + if (comma) + virBufferAddChar(&buf, ','); + else + comma = true; + virBufferAsprintf(&buf, "%s,%u", + def->blkio.devices[j].path, + def->blkio.devices[j].riops); + } + if (virBufferError(&buf)) { + virReportOOMError(); + goto cleanup; + } + param->value.s = virBufferContentAndReset(&buf); + } + if (virTypedParameterAssign(param, + VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS, + VIR_TYPED_PARAM_STRING, + param->value.s) < 0) + goto cleanup; + break; + + case 3: /* blkiotune.device_write_iops */ + if (def->blkio.ndevices > 0) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + bool comma = false; + + for (j = 0; j < def->blkio.ndevices; j++) { + if (!def->blkio.devices[j].wiops) + continue; + if (comma) + virBufferAddChar(&buf, ','); + else + comma = true; + virBufferAsprintf(&buf, "%s,%u", + def->blkio.devices[j].path, + def->blkio.devices[j].wiops); + } + if (virBufferError(&buf)) { + virReportOOMError(); + goto cleanup; + } + param->value.s = virBufferContentAndReset(&buf); + } + if (virTypedParameterAssign(param, + VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS, + VIR_TYPED_PARAM_STRING, + param->value.s) < 0) + goto cleanup; + break; + + case 4: /* blkiotune.device_read_bps */ + if (def->blkio.ndevices > 0) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + bool comma = false; + + for (j = 0; j < def->blkio.ndevices; j++) { + if (!def->blkio.devices[j].rbps) + continue; + if (comma) + virBufferAddChar(&buf, ','); + else + comma = true; + virBufferAsprintf(&buf, "%s,%llu", + def->blkio.devices[j].path, + def->blkio.devices[j].rbps); + } + if (virBufferError(&buf)) { + virReportOOMError(); + goto cleanup; + } + param->value.s = virBufferContentAndReset(&buf); + } + if (virTypedParameterAssign(param, + VIR_DOMAIN_BLKIO_DEVICE_READ_BPS, + VIR_TYPED_PARAM_STRING, + param->value.s) < 0) + goto cleanup; + break; + + case 5: /* blkiotune.device_write_bps */ + if (def->blkio.ndevices > 0) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + bool comma = false; + + for (j = 0; j < def->blkio.ndevices; j++) { + if (!def->blkio.devices[j].wbps) + continue; + if (comma) + virBufferAddChar(&buf, ','); + else + comma = true; + virBufferAsprintf(&buf, "%s,%llu", + def->blkio.devices[j].path, + def->blkio.devices[j].wbps); + } + if (virBufferError(&buf)) { + virReportOOMError(); + goto cleanup; + } + param->value.s = virBufferContentAndReset(&buf); + } + if (virTypedParameterAssign(param, + VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS, + VIR_TYPED_PARAM_STRING, + param->value.s) < 0) + goto cleanup; + break; + } + } + } else if (flags & VIR_DOMAIN_AFFECT_CONFIG) { + for (i = 0; i < *nparams && i < CONF_NB_BLKIO_PARAM; i++) { + virTypedParameterPtr param = ¶ms[i]; + val = 0; + param->value.ui = 0; + param->type = VIR_TYPED_PARAM_UINT; + + switch (i) { + case 0: /* fill blkio weight here */ + if (virStrcpyStatic(param->field, VIR_DOMAIN_BLKIO_WEIGHT) == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Field name '%s' too long"), + VIR_DOMAIN_BLKIO_WEIGHT); + goto cleanup; + } + param->value.ui = persistentDef->blkio.weight; + break; + + case 1: /* blkiotune.device_weight */ + if (persistentDef->blkio.ndevices > 0) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + bool comma = false; + + for (j = 0; j < persistentDef->blkio.ndevices; j++) { + if (!persistentDef->blkio.devices[j].weight) + continue; + if (comma) + virBufferAddChar(&buf, ','); + else + comma = true; + virBufferAsprintf(&buf, "%s,%u", + persistentDef->blkio.devices[j].path, + persistentDef->blkio.devices[j].weight); + } + if (virBufferError(&buf)) { + virReportOOMError(); + goto cleanup; + } + param->value.s = virBufferContentAndReset(&buf); + } + if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) + goto cleanup; + param->type = VIR_TYPED_PARAM_STRING; + if (virStrcpyStatic(param->field, + VIR_DOMAIN_BLKIO_DEVICE_WEIGHT) == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Field name '%s' too long"), + VIR_DOMAIN_BLKIO_DEVICE_WEIGHT); + goto cleanup; + } + break; + + case 2: /* blkiotune.device_read_iops */ + if (persistentDef->blkio.ndevices > 0) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + bool comma = false; + + for (j = 0; j < persistentDef->blkio.ndevices; j++) { + if (!persistentDef->blkio.devices[j].riops) + continue; + if (comma) + virBufferAddChar(&buf, ','); + else + comma = true; + virBufferAsprintf(&buf, "%s,%u", + persistentDef->blkio.devices[j].path, + persistentDef->blkio.devices[j].riops); + } + if (virBufferError(&buf)) { + virReportOOMError(); + goto cleanup; + } + param->value.s = virBufferContentAndReset(&buf); + } + if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) + goto cleanup; + param->type = VIR_TYPED_PARAM_STRING; + if (virStrcpyStatic(param->field, + VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS) == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Field name '%s' too long"), + VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS); + goto cleanup; + } + break; + case 3: /* blkiotune.device_write_iops */ + if (persistentDef->blkio.ndevices > 0) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + bool comma = false; + + for (j = 0; j < persistentDef->blkio.ndevices; j++) { + if (!persistentDef->blkio.devices[j].wiops) + continue; + if (comma) + virBufferAddChar(&buf, ','); + else + comma = true; + virBufferAsprintf(&buf, "%s,%u", + persistentDef->blkio.devices[j].path, + persistentDef->blkio.devices[j].wiops); + } + if (virBufferError(&buf)) { + virReportOOMError(); + goto cleanup; + } + param->value.s = virBufferContentAndReset(&buf); + } + if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) + goto cleanup; + param->type = VIR_TYPED_PARAM_STRING; + if (virStrcpyStatic(param->field, + VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS) == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Field name '%s' too long"), + VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS); + goto cleanup; + } + break; + case 4: /* blkiotune.device_read_bps */ + if (persistentDef->blkio.ndevices > 0) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + bool comma = false; + + for (j = 0; j < persistentDef->blkio.ndevices; j++) { + if (!persistentDef->blkio.devices[j].rbps) + continue; + if (comma) + virBufferAddChar(&buf, ','); + else + comma = true; + virBufferAsprintf(&buf, "%s,%llu", + persistentDef->blkio.devices[j].path, + persistentDef->blkio.devices[j].rbps); + } + if (virBufferError(&buf)) { + virReportOOMError(); + goto cleanup; + } + param->value.s = virBufferContentAndReset(&buf); + } + if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) + goto cleanup; + param->type = VIR_TYPED_PARAM_STRING; + if (virStrcpyStatic(param->field, + VIR_DOMAIN_BLKIO_DEVICE_READ_BPS) == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Field name '%s' too long"), + VIR_DOMAIN_BLKIO_DEVICE_READ_BPS); + goto cleanup; + } + break; + + case 5: /* blkiotune.device_write_bps */ + if (persistentDef->blkio.ndevices > 0) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + bool comma = false; + + for (j = 0; j < persistentDef->blkio.ndevices; j++) { + if (!persistentDef->blkio.devices[j].wbps) + continue; + if (comma) + virBufferAddChar(&buf, ','); + else + comma = true; + virBufferAsprintf(&buf, "%s,%llu", + persistentDef->blkio.devices[j].path, + persistentDef->blkio.devices[j].wbps); + } + if (virBufferError(&buf)) { + virReportOOMError(); + goto cleanup; + } + param->value.s = virBufferContentAndReset(&buf); + } + if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) + goto cleanup; + param->type = VIR_TYPED_PARAM_STRING; + if (virStrcpyStatic(param->field, + VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS) == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Field name '%s' too long"), + VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS); + goto cleanup; + } + break; + } + } + } + + if (CONF_NB_BLKIO_PARAM < *nparams) + *nparams = CONF_NB_BLKIO_PARAM; + ret = 0; + cleanup: + return ret; +} diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index a6ac95a..02cc10b 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -48,6 +48,8 @@ # include "virstoragefile.h" # include "virnuma.h" # include "virseclabel.h" +# include "vircgroup.h" +# include "virtypedparam.h" /* forward declarations of all device types, required by * virDomainDeviceDef @@ -2711,4 +2713,10 @@ int virDomainObjSetMetadata(virDomainObjPtr vm, const char *configDir, unsigned int flags); +int virDomainGetBlkioParametersInternal(virCgroupPtr cgroup, + virDomainDefPtr def, + virDomainDefPtr persistentDef, + virTypedParameterPtr params, + int *nparams, + unsigned int flags); #endif /* __DOMAIN_CONF_H */ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 29a9ed1..4ef3687 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -248,6 +248,7 @@ virDomainFSTypeFromString; virDomainFSTypeToString; virDomainFSWrpolicyTypeFromString; virDomainFSWrpolicyTypeToString; +virDomainGetBlkioParametersInternal; virDomainGetFilesystemForTarget; virDomainGraphicsAuthConnectedTypeFromString; virDomainGraphicsAuthConnectedTypeToString; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index d2852a7..fd5e06e 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2647,8 +2647,6 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, } -#define LXC_NB_BLKIO_PARAM 6 - static int lxcDomainGetBlkioParameters(virDomainPtr dom, virTypedParameterPtr params, @@ -2656,10 +2654,8 @@ lxcDomainGetBlkioParameters(virDomainPtr dom, unsigned int flags) { virLXCDriverPtr driver = dom->conn->privateData; - size_t i, j; virDomainObjPtr vm = NULL; virDomainDefPtr persistentDef = NULL; - unsigned int val; int ret = -1; virCapsPtr caps = NULL; virLXCDomainObjPrivatePtr priv; @@ -2684,375 +2680,13 @@ lxcDomainGetBlkioParameters(virDomainPtr dom, if (!(caps = virLXCDriverGetCapabilities(driver, false))) goto cleanup; - if ((*nparams) == 0) { - /* Current number of blkio parameters supported by cgroups */ - *nparams = LXC_NB_BLKIO_PARAM; - ret = 0; - goto cleanup; - } - - if (virDomainLiveConfigHelperMethod(caps, driver->xmlopt, vm, &flags, + if (*nparams && + virDomainLiveConfigHelperMethod(caps, driver->xmlopt, vm, &flags, &persistentDef) < 0) goto cleanup; - if (flags & VIR_DOMAIN_AFFECT_LIVE) { - if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_BLKIO)) { - virReportError(VIR_ERR_OPERATION_INVALID, "%s", - _("blkio cgroup isn't mounted")); - goto cleanup; - } - - for (i = 0; i < *nparams && i < LXC_NB_BLKIO_PARAM; i++) { - virTypedParameterPtr param = ¶ms[i]; - val = 0; - - switch (i) { - case 0: /* fill blkio weight here */ - if (virCgroupGetBlkioWeight(priv->cgroup, &val) < 0) - goto cleanup; - if (virTypedParameterAssign(param, VIR_DOMAIN_BLKIO_WEIGHT, - VIR_TYPED_PARAM_UINT, val) < 0) - goto cleanup; - break; - - case 1: /* blkiotune.device_weight */ - if (vm->def->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < vm->def->blkio.ndevices; j++) { - if (!vm->def->blkio.devices[j].weight) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%u", - vm->def->blkio.devices[j].path, - vm->def->blkio.devices[j].weight); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (virTypedParameterAssign(param, - VIR_DOMAIN_BLKIO_DEVICE_WEIGHT, - VIR_TYPED_PARAM_STRING, - param->value.s) < 0) - goto cleanup; - break; - - case 2: /* blkiotune.device_read_iops */ - if (vm->def->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < vm->def->blkio.ndevices; j++) { - if (!vm->def->blkio.devices[j].riops) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%u", - vm->def->blkio.devices[j].path, - vm->def->blkio.devices[j].riops); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (virTypedParameterAssign(param, - VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS, - VIR_TYPED_PARAM_STRING, - param->value.s) < 0) - goto cleanup; - break; - - case 3: /* blkiotune.device_write_iops */ - if (vm->def->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < vm->def->blkio.ndevices; j++) { - if (!vm->def->blkio.devices[j].wiops) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%u", - vm->def->blkio.devices[j].path, - vm->def->blkio.devices[j].wiops); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (virTypedParameterAssign(param, - VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS, - VIR_TYPED_PARAM_STRING, - param->value.s) < 0) - goto cleanup; - break; - - case 4: /* blkiotune.device_read_bps */ - if (vm->def->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < vm->def->blkio.ndevices; j++) { - if (!vm->def->blkio.devices[j].rbps) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%llu", - vm->def->blkio.devices[j].path, - vm->def->blkio.devices[j].rbps); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (virTypedParameterAssign(param, - VIR_DOMAIN_BLKIO_DEVICE_READ_BPS, - VIR_TYPED_PARAM_STRING, - param->value.s) < 0) - goto cleanup; - break; - - case 5: /* blkiotune.device_write_bps */ - if (vm->def->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < vm->def->blkio.ndevices; j++) { - if (!vm->def->blkio.devices[j].wbps) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%llu", - vm->def->blkio.devices[j].path, - vm->def->blkio.devices[j].wbps); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (virTypedParameterAssign(param, - VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS, - VIR_TYPED_PARAM_STRING, - param->value.s) < 0) - goto cleanup; - break; - } - } - } else if (flags & VIR_DOMAIN_AFFECT_CONFIG) { - for (i = 0; i < *nparams && i < LXC_NB_BLKIO_PARAM; i++) { - virTypedParameterPtr param = ¶ms[i]; - val = 0; - param->value.ui = 0; - param->type = VIR_TYPED_PARAM_UINT; - - switch (i) { - case 0: /* fill blkio weight here */ - if (virStrcpyStatic(param->field, VIR_DOMAIN_BLKIO_WEIGHT) == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Field name '%s' too long"), - VIR_DOMAIN_BLKIO_WEIGHT); - goto cleanup; - } - param->value.ui = persistentDef->blkio.weight; - break; - - case 1: /* blkiotune.device_weight */ - if (persistentDef->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < persistentDef->blkio.ndevices; j++) { - if (!persistentDef->blkio.devices[j].weight) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%u", - persistentDef->blkio.devices[j].path, - persistentDef->blkio.devices[j].weight); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) - goto cleanup; - param->type = VIR_TYPED_PARAM_STRING; - if (virStrcpyStatic(param->field, - VIR_DOMAIN_BLKIO_DEVICE_WEIGHT) == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Field name '%s' too long"), - VIR_DOMAIN_BLKIO_DEVICE_WEIGHT); - goto cleanup; - } - break; - - case 2: /* blkiotune.device_read_iops */ - if (persistentDef->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < persistentDef->blkio.ndevices; j++) { - if (!persistentDef->blkio.devices[j].riops) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%u", - persistentDef->blkio.devices[j].path, - persistentDef->blkio.devices[j].riops); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) - goto cleanup; - param->type = VIR_TYPED_PARAM_STRING; - if (virStrcpyStatic(param->field, - VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS) == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Field name '%s' too long"), - VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS); - goto cleanup; - } - break; - case 3: /* blkiotune.device_write_iops */ - if (persistentDef->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < persistentDef->blkio.ndevices; j++) { - if (!persistentDef->blkio.devices[j].wiops) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%u", - persistentDef->blkio.devices[j].path, - persistentDef->blkio.devices[j].wiops); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) - goto cleanup; - param->type = VIR_TYPED_PARAM_STRING; - if (virStrcpyStatic(param->field, - VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS) == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Field name '%s' too long"), - VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS); - goto cleanup; - } - break; - case 4: /* blkiotune.device_read_bps */ - if (persistentDef->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < persistentDef->blkio.ndevices; j++) { - if (!persistentDef->blkio.devices[j].rbps) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%llu", - persistentDef->blkio.devices[j].path, - persistentDef->blkio.devices[j].rbps); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) - goto cleanup; - param->type = VIR_TYPED_PARAM_STRING; - if (virStrcpyStatic(param->field, - VIR_DOMAIN_BLKIO_DEVICE_READ_BPS) == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Field name '%s' too long"), - VIR_DOMAIN_BLKIO_DEVICE_READ_BPS); - goto cleanup; - } - break; - - case 5: /* blkiotune.device_write_bps */ - if (persistentDef->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < persistentDef->blkio.ndevices; j++) { - if (!persistentDef->blkio.devices[j].wbps) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%llu", - persistentDef->blkio.devices[j].path, - persistentDef->blkio.devices[j].wbps); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) - goto cleanup; - param->type = VIR_TYPED_PARAM_STRING; - if (virStrcpyStatic(param->field, - VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS) == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Field name '%s' too long"), - VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS); - goto cleanup; - } - break; - } - } - } - - if (LXC_NB_BLKIO_PARAM < *nparams) - *nparams = LXC_NB_BLKIO_PARAM; - ret = 0; + ret = virDomainGetBlkioParametersInternal(priv->cgroup, vm->def, persistentDef, + params, nparams, flags); cleanup: if (vm) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 4ab5a7b..e5786c3 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7921,10 +7921,8 @@ qemuDomainGetBlkioParameters(virDomainPtr dom, unsigned int flags) { virQEMUDriverPtr driver = dom->conn->privateData; - size_t i, j; virDomainObjPtr vm = NULL; virDomainDefPtr persistentDef = NULL; - unsigned int val; int ret = -1; virCapsPtr caps = NULL; qemuDomainObjPrivatePtr priv; @@ -7957,386 +7955,13 @@ qemuDomainGetBlkioParameters(virDomainPtr dom, if (!(caps = virQEMUDriverGetCapabilities(driver, false))) goto cleanup; - if ((*nparams) == 0) { - /* Current number of blkio parameters supported by cgroups */ - *nparams = QEMU_NB_BLKIO_PARAM; - ret = 0; - goto cleanup; - } - - if (virDomainLiveConfigHelperMethod(caps, driver->xmlopt, vm, &flags, + if (*nparams && + virDomainLiveConfigHelperMethod(caps, driver->xmlopt, vm, &flags, &persistentDef) < 0) goto cleanup; - if (flags & VIR_DOMAIN_AFFECT_LIVE) { - if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_BLKIO)) { - virReportError(VIR_ERR_OPERATION_INVALID, "%s", - _("blkio cgroup isn't mounted")); - goto cleanup; - } - } - - if (flags & VIR_DOMAIN_AFFECT_LIVE) { - for (i = 0; i < *nparams && i < QEMU_NB_BLKIO_PARAM; i++) { - virTypedParameterPtr param = ¶ms[i]; - val = 0; - - switch (i) { - case 0: /* fill blkio weight here */ - if (virCgroupGetBlkioWeight(priv->cgroup, &val) < 0) - goto cleanup; - if (virTypedParameterAssign(param, VIR_DOMAIN_BLKIO_WEIGHT, - VIR_TYPED_PARAM_UINT, val) < 0) - goto cleanup; - break; - - case 1: /* blkiotune.device_weight */ - if (vm->def->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < vm->def->blkio.ndevices; j++) { - if (!vm->def->blkio.devices[j].weight) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%u", - vm->def->blkio.devices[j].path, - vm->def->blkio.devices[j].weight); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (virTypedParameterAssign(param, - VIR_DOMAIN_BLKIO_DEVICE_WEIGHT, - VIR_TYPED_PARAM_STRING, - param->value.s) < 0) - goto cleanup; - break; - - case 2: /* blkiotune.device_read_iops */ - if (vm->def->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < vm->def->blkio.ndevices; j++) { - if (!vm->def->blkio.devices[j].riops) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%u", - vm->def->blkio.devices[j].path, - vm->def->blkio.devices[j].riops); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (virTypedParameterAssign(param, - VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS, - VIR_TYPED_PARAM_STRING, - param->value.s) < 0) - goto cleanup; - break; - - case 3: /* blkiotune.device_write_iops */ - if (vm->def->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < vm->def->blkio.ndevices; j++) { - if (!vm->def->blkio.devices[j].wiops) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%u", - vm->def->blkio.devices[j].path, - vm->def->blkio.devices[j].wiops); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (virTypedParameterAssign(param, - VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS, - VIR_TYPED_PARAM_STRING, - param->value.s) < 0) - goto cleanup; - break; - - case 4: /* blkiotune.device_read_bps */ - if (vm->def->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < vm->def->blkio.ndevices; j++) { - if (!vm->def->blkio.devices[j].rbps) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%llu", - vm->def->blkio.devices[j].path, - vm->def->blkio.devices[j].rbps); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (virTypedParameterAssign(param, - VIR_DOMAIN_BLKIO_DEVICE_READ_BPS, - VIR_TYPED_PARAM_STRING, - param->value.s) < 0) - goto cleanup; - break; - - case 5: /* blkiotune.device_write_bps */ - if (vm->def->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < vm->def->blkio.ndevices; j++) { - if (!vm->def->blkio.devices[j].wbps) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%llu", - vm->def->blkio.devices[j].path, - vm->def->blkio.devices[j].wbps); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (virTypedParameterAssign(param, - VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS, - VIR_TYPED_PARAM_STRING, - param->value.s) < 0) - goto cleanup; - break; - - default: - break; - /* should not hit here */ - } - } - } else if (flags & VIR_DOMAIN_AFFECT_CONFIG) { - for (i = 0; i < *nparams && i < QEMU_NB_BLKIO_PARAM; i++) { - virTypedParameterPtr param = ¶ms[i]; - val = 0; - param->value.ui = 0; - param->type = VIR_TYPED_PARAM_UINT; - - switch (i) { - case 0: /* fill blkio weight here */ - if (virStrcpyStatic(param->field, VIR_DOMAIN_BLKIO_WEIGHT) == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Field name '%s' too long"), - VIR_DOMAIN_BLKIO_WEIGHT); - goto cleanup; - } - param->value.ui = persistentDef->blkio.weight; - break; - - case 1: /* blkiotune.device_weight */ - if (persistentDef->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < persistentDef->blkio.ndevices; j++) { - if (!persistentDef->blkio.devices[j].weight) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%u", - persistentDef->blkio.devices[j].path, - persistentDef->blkio.devices[j].weight); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) - goto cleanup; - param->type = VIR_TYPED_PARAM_STRING; - if (virStrcpyStatic(param->field, - VIR_DOMAIN_BLKIO_DEVICE_WEIGHT) == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Field name '%s' too long"), - VIR_DOMAIN_BLKIO_DEVICE_WEIGHT); - goto cleanup; - } - break; - - case 2: /* blkiotune.device_read_iops */ - if (persistentDef->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < persistentDef->blkio.ndevices; j++) { - if (!persistentDef->blkio.devices[j].riops) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%u", - persistentDef->blkio.devices[j].path, - persistentDef->blkio.devices[j].riops); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) - goto cleanup; - param->type = VIR_TYPED_PARAM_STRING; - if (virStrcpyStatic(param->field, - VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS) == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Field name '%s' too long"), - VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS); - goto cleanup; - } - break; - case 3: /* blkiotune.device_write_iops */ - if (persistentDef->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < persistentDef->blkio.ndevices; j++) { - if (!persistentDef->blkio.devices[j].wiops) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%u", - persistentDef->blkio.devices[j].path, - persistentDef->blkio.devices[j].wiops); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) - goto cleanup; - param->type = VIR_TYPED_PARAM_STRING; - if (virStrcpyStatic(param->field, - VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS) == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Field name '%s' too long"), - VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS); - goto cleanup; - } - break; - case 4: /* blkiotune.device_read_bps */ - if (persistentDef->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < persistentDef->blkio.ndevices; j++) { - if (!persistentDef->blkio.devices[j].rbps) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%llu", - persistentDef->blkio.devices[j].path, - persistentDef->blkio.devices[j].rbps); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) - goto cleanup; - param->type = VIR_TYPED_PARAM_STRING; - if (virStrcpyStatic(param->field, - VIR_DOMAIN_BLKIO_DEVICE_READ_BPS) == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Field name '%s' too long"), - VIR_DOMAIN_BLKIO_DEVICE_READ_BPS); - goto cleanup; - } - break; - - case 5: /* blkiotune.device_write_bps */ - if (persistentDef->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < persistentDef->blkio.ndevices; j++) { - if (!persistentDef->blkio.devices[j].wbps) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%llu", - persistentDef->blkio.devices[j].path, - persistentDef->blkio.devices[j].wbps); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) - goto cleanup; - param->type = VIR_TYPED_PARAM_STRING; - if (virStrcpyStatic(param->field, - VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS) == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Field name '%s' too long"), - VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS); - goto cleanup; - } - break; - - - default: - break; - /* should not hit here */ - } - } - } - - if (QEMU_NB_BLKIO_PARAM < *nparams) - *nparams = QEMU_NB_BLKIO_PARAM; - ret = 0; + ret = virDomainGetBlkioParametersInternal(priv->cgroup, vm->def, persistentDef, + params, nparams, flags); cleanup: if (vm) -- 1.8.5.5

On Tue, Jun 17, 2014 at 03:03:36PM +0200, Ján Tomko wrote:
Reuse the common code from LXC and QEMU drivers. --- src/conf/domain_conf.c | 383 +++++++++++++++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 8 + src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 374 +-------------------------------------------- src/qemu/qemu_driver.c | 383 +---------------------------------------------- 5 files changed, 400 insertions(+), 749 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 4114289..4fe7cb6 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19777,3 +19777,386 @@ virDomainObjSetMetadata(virDomainObjPtr vm,
return 0; } + +#define CONF_NB_BLKIO_PARAM 6 + +int +virDomainGetBlkioParametersInternal(virCgroupPtr cgroup, + virDomainDefPtr def, + virDomainDefPtr persistentDef, + virTypedParameterPtr params, + int *nparams, + unsigned int flags)
This kind of code really does not belong in domain_config.c - it is nothing at all todo with domain XML parsing / formatting, and is very much Linux specific Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 06/17/2014 03:06 PM, Daniel P. Berrange wrote:
On Tue, Jun 17, 2014 at 03:03:36PM +0200, Ján Tomko wrote:
Reuse the common code from LXC and QEMU drivers. --- src/conf/domain_conf.c | 383 +++++++++++++++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 8 + src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 374 +-------------------------------------------- src/qemu/qemu_driver.c | 383 +---------------------------------------------- 5 files changed, 400 insertions(+), 749 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 4114289..4fe7cb6 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19777,3 +19777,386 @@ virDomainObjSetMetadata(virDomainObjPtr vm,
return 0; } + +#define CONF_NB_BLKIO_PARAM 6 + +int +virDomainGetBlkioParametersInternal(virCgroupPtr cgroup, + virDomainDefPtr def, + virDomainDefPtr persistentDef, + virTypedParameterPtr params, + int *nparams, + unsigned int flags)
This kind of code really does not belong in domain_config.c - it is nothing at all todo with domain XML parsing / formatting, and is very much Linux specific
My first choice was util/vircgroup.c, but including domain_conf.h there felt wrong. Jan

On Tue, Jun 17, 2014 at 03:18:25PM +0200, Ján Tomko wrote:
On 06/17/2014 03:06 PM, Daniel P. Berrange wrote:
On Tue, Jun 17, 2014 at 03:03:36PM +0200, Ján Tomko wrote:
Reuse the common code from LXC and QEMU drivers. --- src/conf/domain_conf.c | 383 +++++++++++++++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 8 + src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 374 +-------------------------------------------- src/qemu/qemu_driver.c | 383 +---------------------------------------------- 5 files changed, 400 insertions(+), 749 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 4114289..4fe7cb6 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19777,3 +19777,386 @@ virDomainObjSetMetadata(virDomainObjPtr vm,
return 0; } + +#define CONF_NB_BLKIO_PARAM 6 + +int +virDomainGetBlkioParametersInternal(virCgroupPtr cgroup, + virDomainDefPtr def, + virDomainDefPtr persistentDef, + virTypedParameterPtr params, + int *nparams, + unsigned int flags)
This kind of code really does not belong in domain_config.c - it is nothing at all todo with domain XML parsing / formatting, and is very much Linux specific
My first choice was util/vircgroup.c, but including domain_conf.h there felt wrong.
You'll need to introduce some new shared file that's not in util/ since util/ cannot depend on conf/ Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Most of the values are read from the XML and the only difference is that one of them open-codes virTypedParameterAssign. --- src/conf/domain_conf.c | 435 ++++++++++++++++--------------------------------- 1 file changed, 140 insertions(+), 295 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 4fe7cb6..99ab232 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19782,7 +19782,7 @@ virDomainObjSetMetadata(virDomainObjPtr vm, int virDomainGetBlkioParametersInternal(virCgroupPtr cgroup, - virDomainDefPtr def, + virDomainDefPtr liveDef, virDomainDefPtr persistentDef, virTypedParameterPtr params, int *nparams, @@ -19791,6 +19791,12 @@ virDomainGetBlkioParametersInternal(virCgroupPtr cgroup, int ret = -1; size_t i, j; unsigned int val; + virDomainDefPtr def; + + if (flags & VIR_DOMAIN_AFFECT_LIVE) + def = liveDef; + else + def = persistentDef; if ((*nparams) == 0) { /* Current number of blkio parameters supported by cgroups */ @@ -19818,151 +19824,6 @@ virDomainGetBlkioParametersInternal(virCgroupPtr cgroup, VIR_TYPED_PARAM_UINT, val) < 0) goto cleanup; break; - - case 1: /* blkiotune.device_weight */ - if (def->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < def->blkio.ndevices; j++) { - if (!def->blkio.devices[j].weight) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%u", - def->blkio.devices[j].path, - def->blkio.devices[j].weight); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (virTypedParameterAssign(param, - VIR_DOMAIN_BLKIO_DEVICE_WEIGHT, - VIR_TYPED_PARAM_STRING, - param->value.s) < 0) - goto cleanup; - break; - - case 2: /* blkiotune.device_read_iops */ - if (def->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < def->blkio.ndevices; j++) { - if (!def->blkio.devices[j].riops) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%u", - def->blkio.devices[j].path, - def->blkio.devices[j].riops); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (virTypedParameterAssign(param, - VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS, - VIR_TYPED_PARAM_STRING, - param->value.s) < 0) - goto cleanup; - break; - - case 3: /* blkiotune.device_write_iops */ - if (def->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < def->blkio.ndevices; j++) { - if (!def->blkio.devices[j].wiops) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%u", - def->blkio.devices[j].path, - def->blkio.devices[j].wiops); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (virTypedParameterAssign(param, - VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS, - VIR_TYPED_PARAM_STRING, - param->value.s) < 0) - goto cleanup; - break; - - case 4: /* blkiotune.device_read_bps */ - if (def->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < def->blkio.ndevices; j++) { - if (!def->blkio.devices[j].rbps) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%llu", - def->blkio.devices[j].path, - def->blkio.devices[j].rbps); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (virTypedParameterAssign(param, - VIR_DOMAIN_BLKIO_DEVICE_READ_BPS, - VIR_TYPED_PARAM_STRING, - param->value.s) < 0) - goto cleanup; - break; - - case 5: /* blkiotune.device_write_bps */ - if (def->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < def->blkio.ndevices; j++) { - if (!def->blkio.devices[j].wbps) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%llu", - def->blkio.devices[j].path, - def->blkio.devices[j].wbps); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (virTypedParameterAssign(param, - VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS, - VIR_TYPED_PARAM_STRING, - param->value.s) < 0) - goto cleanup; - break; } } } else if (flags & VIR_DOMAIN_AFFECT_CONFIG) { @@ -19982,175 +19843,159 @@ virDomainGetBlkioParametersInternal(virCgroupPtr cgroup, } param->value.ui = persistentDef->blkio.weight; break; + } + } + } - case 1: /* blkiotune.device_weight */ - if (persistentDef->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; + for (i = 1; i < *nparams && i < CONF_NB_BLKIO_PARAM; i++) { + virTypedParameterPtr param = ¶ms[i]; + val = 0; - for (j = 0; j < persistentDef->blkio.ndevices; j++) { - if (!persistentDef->blkio.devices[j].weight) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%u", - persistentDef->blkio.devices[j].path, - persistentDef->blkio.devices[j].weight); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); + switch (i) { + case 1: /* blkiotune.device_weight */ + if (def->blkio.ndevices > 0) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + bool comma = false; + + for (j = 0; j < def->blkio.ndevices; j++) { + if (!def->blkio.devices[j].weight) + continue; + if (comma) + virBufferAddChar(&buf, ','); + else + comma = true; + virBufferAsprintf(&buf, "%s,%u", + def->blkio.devices[j].path, + def->blkio.devices[j].weight); } - if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) - goto cleanup; - param->type = VIR_TYPED_PARAM_STRING; - if (virStrcpyStatic(param->field, - VIR_DOMAIN_BLKIO_DEVICE_WEIGHT) == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Field name '%s' too long"), - VIR_DOMAIN_BLKIO_DEVICE_WEIGHT); + if (virBufferError(&buf)) { + virReportOOMError(); goto cleanup; } - break; - - case 2: /* blkiotune.device_read_iops */ - if (persistentDef->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; + param->value.s = virBufferContentAndReset(&buf); + } + if (virTypedParameterAssign(param, + VIR_DOMAIN_BLKIO_DEVICE_WEIGHT, + VIR_TYPED_PARAM_STRING, + param->value.s) < 0) + goto cleanup; + break; - for (j = 0; j < persistentDef->blkio.ndevices; j++) { - if (!persistentDef->blkio.devices[j].riops) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%u", - persistentDef->blkio.devices[j].path, - persistentDef->blkio.devices[j].riops); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); + case 2: /* blkiotune.device_read_iops */ + if (def->blkio.ndevices > 0) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + bool comma = false; + + for (j = 0; j < def->blkio.ndevices; j++) { + if (!def->blkio.devices[j].riops) + continue; + if (comma) + virBufferAddChar(&buf, ','); + else + comma = true; + virBufferAsprintf(&buf, "%s,%u", + def->blkio.devices[j].path, + def->blkio.devices[j].riops); } - if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) - goto cleanup; - param->type = VIR_TYPED_PARAM_STRING; - if (virStrcpyStatic(param->field, - VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS) == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Field name '%s' too long"), - VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS); + if (virBufferError(&buf)) { + virReportOOMError(); goto cleanup; } - break; - case 3: /* blkiotune.device_write_iops */ - if (persistentDef->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < persistentDef->blkio.ndevices; j++) { - if (!persistentDef->blkio.devices[j].wiops) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%u", - persistentDef->blkio.devices[j].path, - persistentDef->blkio.devices[j].wiops); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); + param->value.s = virBufferContentAndReset(&buf); + } + if (virTypedParameterAssign(param, + VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS, + VIR_TYPED_PARAM_STRING, + param->value.s) < 0) + goto cleanup; + break; + + case 3: /* blkiotune.device_write_iops */ + if (def->blkio.ndevices > 0) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + bool comma = false; + + for (j = 0; j < def->blkio.ndevices; j++) { + if (!def->blkio.devices[j].wiops) + continue; + if (comma) + virBufferAddChar(&buf, ','); + else + comma = true; + virBufferAsprintf(&buf, "%s,%u", + def->blkio.devices[j].path, + def->blkio.devices[j].wiops); } - if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) - goto cleanup; - param->type = VIR_TYPED_PARAM_STRING; - if (virStrcpyStatic(param->field, - VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS) == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Field name '%s' too long"), - VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS); + if (virBufferError(&buf)) { + virReportOOMError(); goto cleanup; } - break; - case 4: /* blkiotune.device_read_bps */ - if (persistentDef->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < persistentDef->blkio.ndevices; j++) { - if (!persistentDef->blkio.devices[j].rbps) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%llu", - persistentDef->blkio.devices[j].path, - persistentDef->blkio.devices[j].rbps); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); + param->value.s = virBufferContentAndReset(&buf); + } + if (virTypedParameterAssign(param, + VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS, + VIR_TYPED_PARAM_STRING, + param->value.s) < 0) + goto cleanup; + break; + + case 4: /* blkiotune.device_read_bps */ + if (def->blkio.ndevices > 0) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + bool comma = false; + + for (j = 0; j < def->blkio.ndevices; j++) { + if (!def->blkio.devices[j].rbps) + continue; + if (comma) + virBufferAddChar(&buf, ','); + else + comma = true; + virBufferAsprintf(&buf, "%s,%llu", + def->blkio.devices[j].path, + def->blkio.devices[j].rbps); } - if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) - goto cleanup; - param->type = VIR_TYPED_PARAM_STRING; - if (virStrcpyStatic(param->field, - VIR_DOMAIN_BLKIO_DEVICE_READ_BPS) == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Field name '%s' too long"), - VIR_DOMAIN_BLKIO_DEVICE_READ_BPS); + if (virBufferError(&buf)) { + virReportOOMError(); goto cleanup; } - break; - - case 5: /* blkiotune.device_write_bps */ - if (persistentDef->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; + param->value.s = virBufferContentAndReset(&buf); + } + if (virTypedParameterAssign(param, + VIR_DOMAIN_BLKIO_DEVICE_READ_BPS, + VIR_TYPED_PARAM_STRING, + param->value.s) < 0) + goto cleanup; + break; - for (j = 0; j < persistentDef->blkio.ndevices; j++) { - if (!persistentDef->blkio.devices[j].wbps) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%llu", - persistentDef->blkio.devices[j].path, - persistentDef->blkio.devices[j].wbps); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); + case 5: /* blkiotune.device_write_bps */ + if (def->blkio.ndevices > 0) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + bool comma = false; + + for (j = 0; j < def->blkio.ndevices; j++) { + if (!def->blkio.devices[j].wbps) + continue; + if (comma) + virBufferAddChar(&buf, ','); + else + comma = true; + virBufferAsprintf(&buf, "%s,%llu", + def->blkio.devices[j].path, + def->blkio.devices[j].wbps); } - if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) - goto cleanup; - param->type = VIR_TYPED_PARAM_STRING; - if (virStrcpyStatic(param->field, - VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS) == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Field name '%s' too long"), - VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS); + if (virBufferError(&buf)) { + virReportOOMError(); goto cleanup; } - break; + param->value.s = virBufferContentAndReset(&buf); } + if (virTypedParameterAssign(param, + VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS, + VIR_TYPED_PARAM_STRING, + param->value.s) < 0) + goto cleanup; + break; } } -- 1.8.5.5

Use: if (n <= 1) goto success; ... fill in params[1] ... if (n <= 2) goto success; Instead of: for (i = 0; i < n; i++) { switch(i) { case 0: fill in params[0] case 1: fill in params[1] } Also end the string with a comma unconditionally and trim it after. --- src/conf/domain_conf.c | 291 ++++++++++++++++++++----------------------------- 1 file changed, 116 insertions(+), 175 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 99ab232..75e708e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19788,10 +19788,12 @@ virDomainGetBlkioParametersInternal(virCgroupPtr cgroup, int *nparams, unsigned int flags) { + virBuffer buf = VIR_BUFFER_INITIALIZER; int ret = -1; - size_t i, j; + size_t i; unsigned int val; virDomainDefPtr def; + char *str; if (flags & VIR_DOMAIN_AFFECT_LIVE) def = liveDef; @@ -19812,193 +19814,132 @@ virDomainGetBlkioParametersInternal(virCgroupPtr cgroup, goto cleanup; } - for (i = 0; i < *nparams && i < CONF_NB_BLKIO_PARAM; i++) { - virTypedParameterPtr param = ¶ms[i]; - val = 0; + if (virCgroupGetBlkioWeight(cgroup, &val) < 0) + goto cleanup; + } else { + val = def->blkio.weight; + } + /* 0: fill blkio weight here */ + if (virTypedParameterAssign(¶ms[0], VIR_DOMAIN_BLKIO_WEIGHT, + VIR_TYPED_PARAM_UINT, val) < 0) + goto cleanup; - switch (i) { - case 0: /* fill blkio weight here */ - if (virCgroupGetBlkioWeight(cgroup, &val) < 0) - goto cleanup; - if (virTypedParameterAssign(param, VIR_DOMAIN_BLKIO_WEIGHT, - VIR_TYPED_PARAM_UINT, val) < 0) - goto cleanup; - break; - } - } - } else if (flags & VIR_DOMAIN_AFFECT_CONFIG) { - for (i = 0; i < *nparams && i < CONF_NB_BLKIO_PARAM; i++) { - virTypedParameterPtr param = ¶ms[i]; - val = 0; - param->value.ui = 0; - param->type = VIR_TYPED_PARAM_UINT; + /* 1: blkiotune.device_weight */ + if (*nparams <= 1) + goto success; - switch (i) { - case 0: /* fill blkio weight here */ - if (virStrcpyStatic(param->field, VIR_DOMAIN_BLKIO_WEIGHT) == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Field name '%s' too long"), - VIR_DOMAIN_BLKIO_WEIGHT); - goto cleanup; - } - param->value.ui = persistentDef->blkio.weight; - break; - } - } + for (i = 0; i < def->blkio.ndevices; i++) { + if (!def->blkio.devices[i].weight) + continue; + virBufferAsprintf(&buf, "%s,%u,", + def->blkio.devices[i].path, + def->blkio.devices[i].weight); } + if (virBufferError(&buf)) { + virReportOOMError(); + goto cleanup; + } + virBufferTrim(&buf, ",", -1); + str = virBufferContentAndReset(&buf); + if (virTypedParameterAssign(¶ms[1], + VIR_DOMAIN_BLKIO_DEVICE_WEIGHT, + VIR_TYPED_PARAM_STRING, + str) < 0) + goto cleanup; - for (i = 1; i < *nparams && i < CONF_NB_BLKIO_PARAM; i++) { - virTypedParameterPtr param = ¶ms[i]; - val = 0; + /* 2: blkiotune.device_read_iops */ + if (*nparams <= 2) + goto success; - switch (i) { - case 1: /* blkiotune.device_weight */ - if (def->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; + for (i = 0; i < def->blkio.ndevices; i++) { + if (!def->blkio.devices[i].riops) + continue; + virBufferAsprintf(&buf, "%s,%u,", + def->blkio.devices[i].path, + def->blkio.devices[i].riops); + } + if (virBufferError(&buf)) { + virReportOOMError(); + goto cleanup; + } + virBufferTrim(&buf, ",", -1); + str = virBufferContentAndReset(&buf); + if (virTypedParameterAssign(¶ms[2], + VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS, + VIR_TYPED_PARAM_STRING, + str) < 0) + goto cleanup; - for (j = 0; j < def->blkio.ndevices; j++) { - if (!def->blkio.devices[j].weight) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%u", - def->blkio.devices[j].path, - def->blkio.devices[j].weight); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (virTypedParameterAssign(param, - VIR_DOMAIN_BLKIO_DEVICE_WEIGHT, - VIR_TYPED_PARAM_STRING, - param->value.s) < 0) - goto cleanup; - break; + /* 3: blkiotune.device_write_iops */ + if (*nparams <= 3) + goto success; - case 2: /* blkiotune.device_read_iops */ - if (def->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < def->blkio.ndevices; j++) { - if (!def->blkio.devices[j].riops) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%u", - def->blkio.devices[j].path, - def->blkio.devices[j].riops); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (virTypedParameterAssign(param, - VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS, - VIR_TYPED_PARAM_STRING, - param->value.s) < 0) - goto cleanup; - break; + for (i = 0; i < def->blkio.ndevices; i++) { + if (!def->blkio.devices[i].wiops) + continue; + virBufferAsprintf(&buf, "%s,%u,", + def->blkio.devices[i].path, + def->blkio.devices[i].wiops); + } + if (virBufferError(&buf)) { + virReportOOMError(); + goto cleanup; + } + virBufferTrim(&buf, ",", -1); + str = virBufferContentAndReset(&buf); + if (virTypedParameterAssign(¶ms[3], + VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS, + VIR_TYPED_PARAM_STRING, + str) < 0) + goto cleanup; - case 3: /* blkiotune.device_write_iops */ - if (def->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < def->blkio.ndevices; j++) { - if (!def->blkio.devices[j].wiops) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%u", - def->blkio.devices[j].path, - def->blkio.devices[j].wiops); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (virTypedParameterAssign(param, - VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS, - VIR_TYPED_PARAM_STRING, - param->value.s) < 0) - goto cleanup; - break; + /* 4: blkiotune.device_read_bps */ + if (*nparams <= 4) + goto success; - case 4: /* blkiotune.device_read_bps */ - if (def->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < def->blkio.ndevices; j++) { - if (!def->blkio.devices[j].rbps) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%llu", - def->blkio.devices[j].path, - def->blkio.devices[j].rbps); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (virTypedParameterAssign(param, - VIR_DOMAIN_BLKIO_DEVICE_READ_BPS, - VIR_TYPED_PARAM_STRING, - param->value.s) < 0) - goto cleanup; - break; + for (i = 0; i < def->blkio.ndevices; i++) { + if (!def->blkio.devices[i].rbps) + continue; + virBufferAsprintf(&buf, "%s,%llu,", + def->blkio.devices[i].path, + def->blkio.devices[i].rbps); + } + if (virBufferError(&buf)) { + virReportOOMError(); + goto cleanup; + } + virBufferTrim(&buf, ",", -1); + str = virBufferContentAndReset(&buf); + if (virTypedParameterAssign(¶ms[4], + VIR_DOMAIN_BLKIO_DEVICE_READ_BPS, + VIR_TYPED_PARAM_STRING, + str) < 0) + goto cleanup; - case 5: /* blkiotune.device_write_bps */ - if (def->blkio.ndevices > 0) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - bool comma = false; - - for (j = 0; j < def->blkio.ndevices; j++) { - if (!def->blkio.devices[j].wbps) - continue; - if (comma) - virBufferAddChar(&buf, ','); - else - comma = true; - virBufferAsprintf(&buf, "%s,%llu", - def->blkio.devices[j].path, - def->blkio.devices[j].wbps); - } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - param->value.s = virBufferContentAndReset(&buf); - } - if (virTypedParameterAssign(param, - VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS, - VIR_TYPED_PARAM_STRING, - param->value.s) < 0) - goto cleanup; - break; + /* 5: blkiotune.device_write_bps */ + if (*nparams <= 5) + goto success; + + for (i = 0; i < def->blkio.ndevices; i++) { + if (!def->blkio.devices[i].wbps) + continue; + virBufferAsprintf(&buf, "%s,%llu,", + def->blkio.devices[i].path, + def->blkio.devices[i].wbps); + if (virBufferError(&buf)) { + virReportOOMError(); + goto cleanup; } + virBufferTrim(&buf, ",", -1); + str = virBufferContentAndReset(&buf); } + if (virTypedParameterAssign(¶ms[5], + VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS, + VIR_TYPED_PARAM_STRING, + str) < 0) + goto cleanup; + success: if (CONF_NB_BLKIO_PARAM < *nparams) *nparams = CONF_NB_BLKIO_PARAM; ret = 0; -- 1.8.5.5
participants (2)
-
Daniel P. Berrange
-
Ján Tomko