lxcDomainMergeBlkioDevice() and -qemuDomainMergeBlkioDevice()
are the same functions. Put the code in a new
virDomainMergeBlkioDevice() inside domain_conf.c and update
both callers.
This change is a preliminary step for more code reduction of
cgroup related code inside lxcDomainSetBlkioParameters() and
qemuDomainSetBlkioParameters().
Signed-off-by: Daniel Henrique Barboza <danielhb413(a)gmail.com>
---
src/conf/domain_conf.c | 70 +++++++++++++++++++++++++++++++++++
src/conf/domain_conf.h | 6 +++
src/libvirt_private.syms | 1 +
src/lxc/lxc_driver.c | 72 +-----------------------------------
src/qemu/qemu_driver.c | 80 +++-------------------------------------
5 files changed, 85 insertions(+), 144 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index de74a2a2d5..88bcf1b64b 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1625,6 +1625,76 @@ virDomainBlkioDeviceParseXML(xmlNodePtr root,
}
+/* 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;
+}
+
+
/**
* virDomainDefCheckUnsupportedMemoryHotplug:
* @def: domain definition
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 2db3c19473..460aad9278 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2209,6 +2209,12 @@ struct _virDomainPanicDef {
void virBlkioDeviceArrayClear(virBlkioDevicePtr deviceWeights,
int ndevices);
+int virDomainMergeBlkioDevice(virBlkioDevicePtr *dest_array,
+ size_t *dest_size,
+ virBlkioDevicePtr src_array,
+ size_t src_size,
+ const char *type);
+
struct _virDomainResourceDef {
char *partition;
};
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 38fe847cef..70e45f1e8a 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -491,6 +491,7 @@ virDomainMemoryModelTypeToString;
virDomainMemoryRemove;
virDomainMemorySourceTypeFromString;
virDomainMemorySourceTypeToString;
+virDomainMergeBlkioDevice;
virDomainNetAllocateActualDevice;
virDomainNetAppendIPAddress;
virDomainNetARPInterfaces;
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 69016881dc..e42fd99c72 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -2215,74 +2215,6 @@ lxcDomainParseBlkioDeviceStr(char *blkioDeviceStr, const char
*type,
return -1;
}
-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,
@@ -2633,7 +2565,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;
@@ -2665,7 +2597,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 0d58893d7e..509a57b01c 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -9419,74 +9419,6 @@ qemuDomainParseBlkioDeviceStr(char *blkioDeviceStr, const char
*type,
return -1;
}
-/* 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,
@@ -9647,9 +9579,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);
@@ -9682,9 +9614,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.24.1