Move qemuDomainGetBlkioParametersAssignFromDef into domain_conf and export it, to allow reuse in the LXC driver. --- src/conf/domain_conf.c | 51 +++++++++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 6 +++++ src/libvirt_private.syms | 1 + src/qemu/qemu_driver.c | 59 ++++-------------------------------------------- 4 files changed, 62 insertions(+), 55 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 11ec80d..0c09546 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -24558,3 +24558,54 @@ virDomainObjGetShortName(virDomainObjPtr vm) return ret; } + + +int +virDomainGetBlkioParametersAssignFromDef(virDomainDefPtr def, + virTypedParameterPtr params, + int *nparams, + int maxparams) +{ + virBuffer buf = VIR_BUFFER_INITIALIZER; + char *data = NULL; + size_t i; + +#define VIR_BLKIO_ASSIGN(param, format, name) \ + if (*nparams < maxparams) { \ + for (i = 0; i < def->blkio.ndevices; i++) { \ + if (!def->blkio.devices[i].param) \ + continue; \ + virBufferAsprintf(&buf, "%s," format ",", \ + def->blkio.devices[i].path, \ + def->blkio.devices[i].param); \ + } \ + virBufferTrim(&buf, ",", -1); \ + if (virBufferCheckError(&buf) < 0) \ + goto error; \ + data = virBufferContentAndReset(&buf); \ + if (virTypedParameterAssign(&(params[(*nparams)++]), name, \ + VIR_TYPED_PARAM_STRING, data) < 0) \ + goto error; \ + VIR_FREE(data); \ + } + + /* blkiotune.device_weight */ + VIR_BLKIO_ASSIGN(weight, "%u", VIR_DOMAIN_BLKIO_DEVICE_WEIGHT); + /* blkiotune.device_read_iops */ + VIR_BLKIO_ASSIGN(riops, "%u", VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS); + /* blkiotune.device_write_iops */ + VIR_BLKIO_ASSIGN(wiops, "%u", VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS); + /* blkiotune.device_read_bps */ + VIR_BLKIO_ASSIGN(rbps, "%llu", VIR_DOMAIN_BLKIO_DEVICE_READ_BPS); + /* blkiotune.device_write_bps */ + VIR_BLKIO_ASSIGN(wbps, "%llu", VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS); + +#undef VIR_BLKIO_ASSIGN + + return 0; + + error: + VIR_FREE(data); + virBufferFreeAndReset(&buf); + return -1; +} diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index c182747..0d18304 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -52,6 +52,7 @@ # include "virprocess.h" # include "virgic.h" # include "virperf.h" +# include "virtypedparam.h" /* forward declarations of all device types, required by * virDomainDeviceDef @@ -3062,4 +3063,9 @@ bool virDomainDefHasMemballoon(const virDomainDef *def) ATTRIBUTE_NONNULL(1); char *virDomainObjGetShortName(virDomainObjPtr vm); +int +virDomainGetBlkioParametersAssignFromDef(virDomainDefPtr def, + virTypedParameterPtr params, + int *nparams, + int maxparams); #endif /* __DOMAIN_CONF_H */ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 333bf7c..3968a8d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -93,6 +93,7 @@ virDomainCCWAddressReleaseAddr; virDomainCCWAddressSetCreate; virDomainCCWAddressSetFree; virDomainCCWAddressValidate; +virDomainGetBlkioParametersAssignFromDef; virDomainPCIAddressAsString; virDomainPCIAddressBusSetModel; virDomainPCIAddressEnsureAddr; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 10d3e3d..1a674af 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9083,57 +9083,6 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, static int -qemuDomainGetBlkioParametersAssignFromDef(virDomainDefPtr def, - virTypedParameterPtr params, - int *nparams, - int maxparams) -{ - virBuffer buf = VIR_BUFFER_INITIALIZER; - char *data = NULL; - size_t i; - -#define QEMU_BLKIO_ASSIGN(param, format, name) \ - if (*nparams < maxparams) { \ - for (i = 0; i < def->blkio.ndevices; i++) { \ - if (!def->blkio.devices[i].param) \ - continue; \ - virBufferAsprintf(&buf, "%s," format ",", \ - def->blkio.devices[i].path, \ - def->blkio.devices[i].param); \ - } \ - virBufferTrim(&buf, ",", -1); \ - if (virBufferCheckError(&buf) < 0) \ - goto error; \ - data = virBufferContentAndReset(&buf); \ - if (virTypedParameterAssign(&(params[(*nparams)++]), name, \ - VIR_TYPED_PARAM_STRING, data) < 0) \ - goto error; \ - VIR_FREE(data); \ - } - - /* blkiotune.device_weight */ - QEMU_BLKIO_ASSIGN(weight, "%u", VIR_DOMAIN_BLKIO_DEVICE_WEIGHT); - /* blkiotune.device_read_iops */ - QEMU_BLKIO_ASSIGN(riops, "%u", VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS); - /* blkiotune.device_write_iops */ - QEMU_BLKIO_ASSIGN(wiops, "%u", VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS); - /* blkiotune.device_read_bps */ - QEMU_BLKIO_ASSIGN(rbps, "%llu", VIR_DOMAIN_BLKIO_DEVICE_READ_BPS); - /* blkiotune.device_write_bps */ - QEMU_BLKIO_ASSIGN(wbps, "%llu", VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS); - -#undef QEMU_BLKIO_ASSIGN - - return 0; - - error: - VIR_FREE(data); - virBufferFreeAndReset(&buf); - return -1; -} - - -static int qemuDomainGetBlkioParameters(virDomainPtr dom, virTypedParameterPtr params, int *nparams, @@ -9200,8 +9149,8 @@ qemuDomainGetBlkioParameters(virDomainPtr dom, VIR_TYPED_PARAM_UINT, val) < 0) goto cleanup; - if (qemuDomainGetBlkioParametersAssignFromDef(def, params, nparams, - maxparams) < 0) + if (virDomainGetBlkioParametersAssignFromDef(def, params, nparams, + maxparams) < 0) goto cleanup; } else if (persistentDef) { @@ -9212,8 +9161,8 @@ qemuDomainGetBlkioParameters(virDomainPtr dom, persistentDef->blkio.weight) < 0) goto cleanup; - if (qemuDomainGetBlkioParametersAssignFromDef(persistentDef, params, - nparams, maxparams) < 0) + if (virDomainGetBlkioParametersAssignFromDef(persistentDef, params, + nparams, maxparams) < 0) goto cleanup; } -- 2.7.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list