diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index 90609cd2b819bca4d1332b128d13c79b338f0271..fc5b6eeefea1d14292fa620043f420e3c2382c89 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -206,3 +206,47 @@ virDomainDriverParseBlkioDeviceStr(char *blkioDeviceStr, const char *type, } return -1; } + + +int +virDomainDriverSetupPersistentDefBlkioParams(virDomainDefPtr persistentDef, + virTypedParameterPtr params, + int nparams) +{ + size_t i; + int ret = 0; + + for (i = 0; i < nparams; i++) { + virTypedParameterPtr param = ¶ms[i]; + + if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) { + persistentDef->blkio.weight = param->value.ui; + } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT) || + STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS) || + STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS) || + STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS) || + STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) { + virBlkioDevicePtr devices = NULL; + size_t ndevices; + + if (virDomainDriverParseBlkioDeviceStr(param->value.s, + param->field, + &devices, + &ndevices) < 0) { + ret = -1; + continue; + } + + if (virDomainDriverMergeBlkioDevice(&persistentDef->blkio.devices, + &persistentDef->blkio.ndevices, + devices, ndevices, + param->field) < 0) + ret = -1; + + virBlkioDeviceArrayClear(devices, ndevices); + g_free(devices); + } + } + + return ret; +} diff --git a/src/hypervisor/domain_driver.h b/src/hypervisor/domain_driver.h index b78401ea42eabb088c1a0420041b3fb2b8f2cca3..b6d5e66bba99b30e59d880b197500ab7c9442e9e 100644 --- a/src/hypervisor/domain_driver.h +++ b/src/hypervisor/domain_driver.h @@ -30,3 +30,7 @@ int virDomainDriverMergeBlkioDevice(virBlkioDevicePtr *dest_array, int virDomainDriverParseBlkioDeviceStr(char *blkioDeviceStr, const char *type, virBlkioDevicePtr *dev, size_t *size); + +int virDomainDriverSetupPersistentDefBlkioParams(virDomainDefPtr persistentDef, + virTypedParameterPtr params, + int nparams); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index ede894963dbaecf46160496947afc32c53b8582f..58c9fc14afa63b8562255b96dca028860418f30c 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1399,6 +1399,7 @@ virDomainCgroupSetupMemtune; # hypervisor/domain_cgroup.h virDomainDriverMergeBlkioDevice; virDomainDriverParseBlkioDeviceStr; +virDomainDriverSetupPersistentDefBlkioParams; # libvirt_internal.h diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index c93dee37f8c32f004c4514c14330954644a8b349..0332b7668a18057799f3b73c44c15bd865c0ee07 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2314,7 +2314,6 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, unsigned int flags) { virLXCDriverPtr driver = dom->conn->privateData; - size_t i; virDomainObjPtr vm = NULL; virDomainDefPtr def = NULL; virDomainDefPtr persistentDef = NULL; @@ -2371,35 +2370,9 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, if (ret < 0) goto endjob; if (persistentDef) { - for (i = 0; i < nparams; i++) { - virTypedParameterPtr param = ¶ms[i]; - - if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) { - persistentDef->blkio.weight = params[i].value.ui; - } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) { - virBlkioDevicePtr devices = NULL; - size_t ndevices; - - if (virDomainDriverParseBlkioDeviceStr(params[i].value.s, - param->field, - &devices, - &ndevices) < 0) { - ret = -1; - continue; - } - if (virDomainDriverMergeBlkioDevice(&persistentDef->blkio.devices, - &persistentDef->blkio.ndevices, - devices, ndevices, - param->field) < 0) - ret = -1; - virBlkioDeviceArrayClear(devices, ndevices); - VIR_FREE(devices); - } - } + ret = virDomainDriverSetupPersistentDefBlkioParams(persistentDef, + params, + nparams); if (virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir) < 0) ret = -1; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 41e0b4e7199cd42c7e1813368da8ece0a91355cb..7efae15be68da242a6a58eee8e8069b049eccdb7 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9319,7 +9319,6 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, unsigned int flags) { virQEMUDriverPtr driver = dom->conn->privateData; - size_t i; virDomainObjPtr vm = NULL; virDomainDefPtr def; virDomainDefPtr persistentDef; @@ -9385,35 +9384,9 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, if (ret < 0) goto endjob; if (persistentDef) { - for (i = 0; i < nparams; i++) { - virTypedParameterPtr param = ¶ms[i]; - - if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) { - persistentDef->blkio.weight = param->value.ui; - } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) { - virBlkioDevicePtr devices = NULL; - size_t ndevices; - - if (virDomainDriverParseBlkioDeviceStr(param->value.s, - param->field, - &devices, - &ndevices) < 0) { - ret = -1; - continue; - } - if (virDomainDriverMergeBlkioDevice(&persistentDef->blkio.devices, - &persistentDef->blkio.ndevices, - devices, ndevices, - param->field) < 0) - ret = -1; - virBlkioDeviceArrayClear(devices, ndevices); - VIR_FREE(devices); - } - } + ret = virDomainDriverSetupPersistentDefBlkioParams(persistentDef, + params, + nparams); if (virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir) < 0) ret = -1;