mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
domain_driver.c: add virDomainDriverSetupPersistentDefBlkioParams()
This new helper avoids more code repetition inside lxcDomainSetBlkioParameters() and qemuDomainSetBlkioParameters(). Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
ac87d3520a
commit
309a8305b7
@ -206,3 +206,47 @@ virDomainDriverParseBlkioDeviceStr(char *blkioDeviceStr, const char *type,
|
|||||||
}
|
}
|
||||||
return -1;
|
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;
|
||||||
|
}
|
||||||
|
@ -30,3 +30,7 @@ int virDomainDriverMergeBlkioDevice(virBlkioDevicePtr *dest_array,
|
|||||||
|
|
||||||
int virDomainDriverParseBlkioDeviceStr(char *blkioDeviceStr, const char *type,
|
int virDomainDriverParseBlkioDeviceStr(char *blkioDeviceStr, const char *type,
|
||||||
virBlkioDevicePtr *dev, size_t *size);
|
virBlkioDevicePtr *dev, size_t *size);
|
||||||
|
|
||||||
|
int virDomainDriverSetupPersistentDefBlkioParams(virDomainDefPtr persistentDef,
|
||||||
|
virTypedParameterPtr params,
|
||||||
|
int nparams);
|
||||||
|
@ -1399,6 +1399,7 @@ virDomainCgroupSetupMemtune;
|
|||||||
# hypervisor/domain_cgroup.h
|
# hypervisor/domain_cgroup.h
|
||||||
virDomainDriverMergeBlkioDevice;
|
virDomainDriverMergeBlkioDevice;
|
||||||
virDomainDriverParseBlkioDeviceStr;
|
virDomainDriverParseBlkioDeviceStr;
|
||||||
|
virDomainDriverSetupPersistentDefBlkioParams;
|
||||||
|
|
||||||
|
|
||||||
# libvirt_internal.h
|
# libvirt_internal.h
|
||||||
|
@ -2314,7 +2314,6 @@ lxcDomainSetBlkioParameters(virDomainPtr dom,
|
|||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
virLXCDriverPtr driver = dom->conn->privateData;
|
virLXCDriverPtr driver = dom->conn->privateData;
|
||||||
size_t i;
|
|
||||||
virDomainObjPtr vm = NULL;
|
virDomainObjPtr vm = NULL;
|
||||||
virDomainDefPtr def = NULL;
|
virDomainDefPtr def = NULL;
|
||||||
virDomainDefPtr persistentDef = NULL;
|
virDomainDefPtr persistentDef = NULL;
|
||||||
@ -2371,35 +2370,9 @@ lxcDomainSetBlkioParameters(virDomainPtr dom,
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
if (persistentDef) {
|
if (persistentDef) {
|
||||||
for (i = 0; i < nparams; i++) {
|
ret = virDomainDriverSetupPersistentDefBlkioParams(persistentDef,
|
||||||
virTypedParameterPtr param = ¶ms[i];
|
params,
|
||||||
|
nparams);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir) < 0)
|
if (virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir) < 0)
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
@ -9319,7 +9319,6 @@ qemuDomainSetBlkioParameters(virDomainPtr dom,
|
|||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
virQEMUDriverPtr driver = dom->conn->privateData;
|
virQEMUDriverPtr driver = dom->conn->privateData;
|
||||||
size_t i;
|
|
||||||
virDomainObjPtr vm = NULL;
|
virDomainObjPtr vm = NULL;
|
||||||
virDomainDefPtr def;
|
virDomainDefPtr def;
|
||||||
virDomainDefPtr persistentDef;
|
virDomainDefPtr persistentDef;
|
||||||
@ -9385,35 +9384,9 @@ qemuDomainSetBlkioParameters(virDomainPtr dom,
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
if (persistentDef) {
|
if (persistentDef) {
|
||||||
for (i = 0; i < nparams; i++) {
|
ret = virDomainDriverSetupPersistentDefBlkioParams(persistentDef,
|
||||||
virTypedParameterPtr param = ¶ms[i];
|
params,
|
||||||
|
nparams);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir) < 0)
|
if (virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir) < 0)
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user