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 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list