The qemuDomainMergeBlkioDevice and lxcDomainMergeBlkioDevice
functions residing in the QEMU and LXC drivers respectively are
completely identical.
By moving the code to src/conf we avoid code duplication and we make the
function available to other drivers that might need to call it such as
the test driver.
Signed-off-by: Ilias Stamatis <stamatis.iliass(a)gmail.com>
---
src/conf/domain_conf.c | 70 ++++++++++++++++++++++++++++++++++
src/conf/domain_conf.h | 7 ++++
src/libvirt_private.syms | 1 +
src/lxc/lxc_driver.c | 72 +----------------------------------
src/qemu/qemu_driver.c | 81 +++-------------------------------------
5 files changed, 86 insertions(+), 145 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index e10390189c..80e463cc3f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -30334,6 +30334,76 @@ virDomainParseBlkioDeviceStr(char *blkioDeviceStr,
}
+/* Modify dest_array to reflect all blkio device changes described in
+ * src_array. */
+int
+virDomainMergeBlkioDevice(virBlkioDevicePtr *dest_array,
+ size_t *dest_size,
+ virBlkioDevicePtr src_array,
+ size_t src_size,
+ const char *type)
+{
+ size_t i, j;
+ virBlkioDevicePtr dest, src;
+
+ for (i = 0; i < src_size; i++) {
+ bool found = false;
+
+ src = &src_array[i];
+ for (j = 0; j < *dest_size; j++) {
+ dest = &(*dest_array)[j];
+ if (STREQ(src->path, dest->path)) {
+ found = true;
+
+ if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) {
+ dest->weight = src->weight;
+ } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) {
+ dest->riops = src->riops;
+ } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) {
+ dest->wiops = src->wiops;
+ } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) {
+ dest->rbps = src->rbps;
+ } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) {
+ dest->wbps = src->wbps;
+ } else {
+ virReportError(VIR_ERR_INVALID_ARG, _("Unknown parameter
%s"),
+ type);
+ return -1;
+ }
+ break;
+ }
+ }
+ if (!found) {
+ if (!src->weight && !src->riops && !src->wiops
&& !src->rbps && !src->wbps)
+ continue;
+ if (VIR_EXPAND_N(*dest_array, *dest_size, 1) < 0)
+ return -1;
+ dest = &(*dest_array)[*dest_size - 1];
+
+ if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) {
+ dest->weight = src->weight;
+ } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) {
+ dest->riops = src->riops;
+ } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) {
+ dest->wiops = src->wiops;
+ } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) {
+ dest->rbps = src->rbps;
+ } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) {
+ dest->wbps = src->wbps;
+ } else {
+ *dest_size = *dest_size - 1;
+ return -1;
+ }
+
+ dest->path = src->path;
+ src->path = NULL;
+ }
+ }
+
+ return 0;
+}
+
+
int
virDomainGetBlkioParametersAssignFromDef(virDomainDefPtr def,
virTypedParameterPtr params,
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index f31193b8d6..df02f60109 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3547,6 +3547,13 @@ virDomainGetBlkioParametersAssignFromDef(virDomainDefPtr def,
int *nparams,
int maxparams);
+int
+virDomainMergeBlkioDevice(virBlkioDevicePtr *dest_array,
+ size_t *dest_size,
+ virBlkioDevicePtr src_array,
+ size_t src_size,
+ const char *type);
+
int virDomainDiskSetBlockIOTune(virDomainDiskDefPtr disk,
virDomainBlockIoTuneInfo *info);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 5de3e6483f..a85c99525f 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -455,6 +455,7 @@ virDomainMemoryModelTypeToString;
virDomainMemoryRemove;
virDomainMemorySourceTypeFromString;
virDomainMemorySourceTypeToString;
+virDomainMergeBlkioDevice;
virDomainNetAllocateActualDevice;
virDomainNetAppendIPAddress;
virDomainNetBandwidthUpdate;
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 0b3ca6a3ce..ad83cc94d7 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -2102,74 +2102,6 @@ lxcDomainGetSchedulerParameters(virDomainPtr domain,
return lxcDomainGetSchedulerParametersFlags(domain, params, nparams, 0);
}
-static int
-lxcDomainMergeBlkioDevice(virBlkioDevicePtr *dest_array,
- size_t *dest_size,
- virBlkioDevicePtr src_array,
- size_t src_size,
- const char *type)
-{
- size_t i, j;
- virBlkioDevicePtr dest, src;
-
- for (i = 0; i < src_size; i++) {
- bool found = false;
-
- src = &src_array[i];
- for (j = 0; j < *dest_size; j++) {
- dest = &(*dest_array)[j];
- if (STREQ(src->path, dest->path)) {
- found = true;
-
- if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) {
- dest->weight = src->weight;
- } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) {
- dest->riops = src->riops;
- } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) {
- dest->wiops = src->wiops;
- } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) {
- dest->rbps = src->rbps;
- } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) {
- dest->wbps = src->wbps;
- } else {
- virReportError(VIR_ERR_INVALID_ARG, _("Unknown parameter
%s"),
- type);
- return -1;
- }
-
- break;
- }
- }
- if (!found) {
- if (!src->weight && !src->riops && !src->wiops
&& !src->rbps && !src->wbps)
- continue;
- if (VIR_EXPAND_N(*dest_array, *dest_size, 1) < 0)
- return -1;
- dest = &(*dest_array)[*dest_size - 1];
-
- if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) {
- dest->weight = src->weight;
- } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) {
- dest->riops = src->riops;
- } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) {
- dest->wiops = src->wiops;
- } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) {
- dest->rbps = src->rbps;
- } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) {
- dest->wbps = src->wbps;
- } else {
- *dest_size = *dest_size - 1;
- return -1;
- }
-
- dest->path = src->path;
- src->path = NULL;
- }
- }
-
- return 0;
-}
-
static int
lxcDomainBlockStats(virDomainPtr dom,
@@ -2520,7 +2452,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom,
}
if (j != ndevices ||
- lxcDomainMergeBlkioDevice(&def->blkio.devices,
+ virDomainMergeBlkioDevice(&def->blkio.devices,
&def->blkio.ndevices,
devices, ndevices, param->field) <
0)
ret = -1;
@@ -2552,7 +2484,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom,
ret = -1;
continue;
}
- if (lxcDomainMergeBlkioDevice(&persistentDef->blkio.devices,
+ if (virDomainMergeBlkioDevice(&persistentDef->blkio.devices,
&persistentDef->blkio.ndevices,
devices, ndevices, param->field) <
0)
ret = -1;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index a9e49501a7..d76941ee70 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -9221,75 +9221,6 @@ static char *qemuDomainGetSchedulerType(virDomainPtr dom,
}
-/* Modify dest_array to reflect all blkio device changes described in
- * src_array. */
-static int
-qemuDomainMergeBlkioDevice(virBlkioDevicePtr *dest_array,
- size_t *dest_size,
- virBlkioDevicePtr src_array,
- size_t src_size,
- const char *type)
-{
- size_t i, j;
- virBlkioDevicePtr dest, src;
-
- for (i = 0; i < src_size; i++) {
- bool found = false;
-
- src = &src_array[i];
- for (j = 0; j < *dest_size; j++) {
- dest = &(*dest_array)[j];
- if (STREQ(src->path, dest->path)) {
- found = true;
-
- if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) {
- dest->weight = src->weight;
- } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) {
- dest->riops = src->riops;
- } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) {
- dest->wiops = src->wiops;
- } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) {
- dest->rbps = src->rbps;
- } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) {
- dest->wbps = src->wbps;
- } else {
- virReportError(VIR_ERR_INVALID_ARG, _("Unknown parameter
%s"),
- type);
- return -1;
- }
- break;
- }
- }
- if (!found) {
- if (!src->weight && !src->riops && !src->wiops
&& !src->rbps && !src->wbps)
- continue;
- if (VIR_EXPAND_N(*dest_array, *dest_size, 1) < 0)
- return -1;
- dest = &(*dest_array)[*dest_size - 1];
-
- if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) {
- dest->weight = src->weight;
- } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) {
- dest->riops = src->riops;
- } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) {
- dest->wiops = src->wiops;
- } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) {
- dest->rbps = src->rbps;
- } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) {
- dest->wbps = src->wbps;
- } else {
- *dest_size = *dest_size - 1;
- return -1;
- }
-
- dest->path = src->path;
- src->path = NULL;
- }
- }
-
- return 0;
-}
-
static int
qemuDomainSetBlkioParameters(virDomainPtr dom,
virTypedParameterPtr params,
@@ -9449,9 +9380,9 @@ qemuDomainSetBlkioParameters(virDomainPtr dom,
}
if (j != ndevices ||
- qemuDomainMergeBlkioDevice(&def->blkio.devices,
- &def->blkio.ndevices,
- devices, ndevices, param->field) <
0)
+ virDomainMergeBlkioDevice(&def->blkio.devices,
+ &def->blkio.ndevices,
+ devices, ndevices, param->field) <
0)
ret = -1;
virBlkioDeviceArrayClear(devices, ndevices);
VIR_FREE(devices);
@@ -9484,9 +9415,9 @@ qemuDomainSetBlkioParameters(virDomainPtr dom,
ret = -1;
continue;
}
- if (qemuDomainMergeBlkioDevice(&persistentDef->blkio.devices,
- &persistentDef->blkio.ndevices,
- devices, ndevices, param->field) <
0)
+ if (virDomainMergeBlkioDevice(&persistentDef->blkio.devices,
+ &persistentDef->blkio.ndevices,
+ devices, ndevices, param->field) <
0)
ret = -1;
virBlkioDeviceArrayClear(devices, ndevices);
VIR_FREE(devices);
--
2.22.0