[libvirt] [PATCH 0/2] qemu and lxc: remove duplicate code and move some definitions to domain_conf

Ilias Stamatis (2): domain_conf: move DomainParseBlkioDeviceStr out of QEMU and LXC drivers domain_conf: move DomainMergeBlkioDevice out of QEMU and LXC drivers src/conf/domain_conf.c | 185 ++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 13 +++ src/libvirt_private.syms | 2 + src/lxc/lxc_driver.c | 184 +--------------------------------- src/qemu/qemu_driver.c | 207 +++------------------------------------ 5 files changed, 218 insertions(+), 373 deletions(-) -- 2.22.0

The qemuDomainParseBlkioDeviceStr and lxcDomainParseBlkioDeviceSts 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@gmail.com> --- src/conf/domain_conf.c | 115 +++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 6 ++ src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 112 +--------------------------------- src/qemu/qemu_driver.c | 126 +++------------------------------------ 5 files changed, 132 insertions(+), 228 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 3323c9a5b1..e10390189c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -30219,6 +30219,121 @@ virDomainDefGetShortName(const virDomainDef *def) #undef VIR_DOMAIN_SHORT_NAME_MAX + +/* blkioDeviceStr in the form of /device/path,weight,/device/path,weight + * for example, /dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0,800 + */ +int +virDomainParseBlkioDeviceStr(char *blkioDeviceStr, + const char *type, + virBlkioDevicePtr *dev, + size_t *size) +{ + char *temp; + int ndevices = 0; + int nsep = 0; + size_t i; + virBlkioDevicePtr result = NULL; + + *dev = NULL; + *size = 0; + + if (STREQ(blkioDeviceStr, "")) + return 0; + + temp = blkioDeviceStr; + while (temp) { + temp = strchr(temp, ','); + if (temp) { + temp++; + nsep++; + } + } + + /* A valid string must have even number of fields, hence an odd + * number of commas. */ + if (!(nsep & 1)) + goto parse_error; + + ndevices = (nsep + 1) / 2; + + if (VIR_ALLOC_N(result, ndevices) < 0) + return -1; + + i = 0; + temp = blkioDeviceStr; + while (temp) { + char *p = temp; + + /* device path */ + p = strchr(p, ','); + if (!p) + goto parse_error; + + if (VIR_STRNDUP(result[i].path, temp, p - temp) < 0) + goto cleanup; + + /* value */ + temp = p + 1; + + if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { + if (virStrToLong_uip(temp, &p, 10, &result[i].weight) < 0) + goto number_error; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) { + if (virStrToLong_uip(temp, &p, 10, &result[i].riops) < 0) + goto number_error; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) { + if (virStrToLong_uip(temp, &p, 10, &result[i].wiops) < 0) + goto number_error; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) { + if (virStrToLong_ullp(temp, &p, 10, &result[i].rbps) < 0) + goto number_error; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) { + if (virStrToLong_ullp(temp, &p, 10, &result[i].wbps) < 0) + goto number_error; + } else { + virReportError(VIR_ERR_INVALID_ARG, + _("unknown parameter '%s'"), type); + goto cleanup; + } + + i++; + + if (*p == '\0') + break; + else if (*p != ',') + goto parse_error; + temp = p + 1; + } + + if (!i) + VIR_FREE(result); + + *dev = result; + *size = i; + + return 0; + + parse_error: + virReportError(VIR_ERR_INVALID_ARG, + _("unable to parse blkio device '%s' '%s'"), + type, blkioDeviceStr); + goto cleanup; + + number_error: + virReportError(VIR_ERR_INVALID_ARG, + _("invalid value '%s' for parameter '%s' of device '%s'"), + temp, type, result[i].path); + + cleanup: + if (result) { + virBlkioDeviceArrayClear(result, ndevices); + VIR_FREE(result); + } + return -1; +} + + int virDomainGetBlkioParametersAssignFromDef(virDomainDefPtr def, virTypedParameterPtr params, diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index c1b5fc1337..f31193b8d6 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3535,6 +3535,12 @@ bool virDomainDefHasMemballoon(const virDomainDef *def) ATTRIBUTE_NONNULL(1); char *virDomainDefGetShortName(const virDomainDef *def) ATTRIBUTE_NONNULL(1); +int +virDomainParseBlkioDeviceStr(char *blkioDeviceStr, + const char *type, + virBlkioDevicePtr *dev, + size_t *size); + int virDomainGetBlkioParametersAssignFromDef(virDomainDefPtr def, virTypedParameterPtr params, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 0545c08428..5de3e6483f 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -521,6 +521,7 @@ virDomainOsDefFirmwareTypeFromString; virDomainOsDefFirmwareTypeToString; virDomainOSTypeFromString; virDomainOSTypeToString; +virDomainParseBlkioDeviceStr; virDomainParseMemory; virDomainPausedReasonTypeFromString; virDomainPausedReasonTypeToString; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 9db2a02dee..0b3ca6a3ce 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2102,114 +2102,6 @@ lxcDomainGetSchedulerParameters(virDomainPtr domain, return lxcDomainGetSchedulerParametersFlags(domain, params, nparams, 0); } -static int -lxcDomainParseBlkioDeviceStr(char *blkioDeviceStr, const char *type, - virBlkioDevicePtr *dev, size_t *size) -{ - char *temp; - int ndevices = 0; - int nsep = 0; - size_t i; - virBlkioDevicePtr result = NULL; - - *dev = NULL; - *size = 0; - - if (STREQ(blkioDeviceStr, "")) - return 0; - - temp = blkioDeviceStr; - while (temp) { - temp = strchr(temp, ','); - if (temp) { - temp++; - nsep++; - } - } - - /* A valid string must have even number of fields, hence an odd - * number of commas. */ - if (!(nsep & 1)) - goto parse_error; - - ndevices = (nsep + 1) / 2; - - if (VIR_ALLOC_N(result, ndevices) < 0) - return -1; - - i = 0; - temp = blkioDeviceStr; - while (temp) { - char *p = temp; - - /* device path */ - p = strchr(p, ','); - if (!p) - goto parse_error; - - if (VIR_STRNDUP(result[i].path, temp, p - temp) < 0) - goto cleanup; - - /* value */ - temp = p + 1; - - if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { - if (virStrToLong_uip(temp, &p, 10, &result[i].weight) < 0) - goto number_error; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) { - if (virStrToLong_uip(temp, &p, 10, &result[i].riops) < 0) - goto number_error; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) { - if (virStrToLong_uip(temp, &p, 10, &result[i].wiops) < 0) - goto number_error; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) { - if (virStrToLong_ullp(temp, &p, 10, &result[i].rbps) < 0) - goto number_error; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) { - if (virStrToLong_ullp(temp, &p, 10, &result[i].wbps) < 0) - goto number_error; - } else { - virReportError(VIR_ERR_INVALID_ARG, - _("unknown parameter '%s'"), type); - goto cleanup; - } - - i++; - - if (*p == '\0') - break; - else if (*p != ',') - goto parse_error; - temp = p + 1; - } - - if (!i) - VIR_FREE(result); - - *dev = result; - *size = i; - - return 0; - - parse_error: - virReportError(VIR_ERR_INVALID_ARG, - _("unable to parse blkio device '%s' '%s'"), - type, blkioDeviceStr); - goto cleanup; - - number_error: - virReportError(VIR_ERR_INVALID_ARG, - _("invalid value '%s' for parameter '%s' of device '%s'"), - temp, type, result[i].path); - - cleanup: - if (result) { - virBlkioDeviceArrayClear(result, ndevices); - VIR_FREE(result); - } - return -1; -} - static int lxcDomainMergeBlkioDevice(virBlkioDevicePtr *dest_array, size_t *dest_size, @@ -2549,7 +2441,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, virBlkioDevicePtr devices = NULL; size_t j; - if (lxcDomainParseBlkioDeviceStr(params[i].value.s, + if (virDomainParseBlkioDeviceStr(params[i].value.s, param->field, &devices, &ndevices) < 0) { @@ -2653,7 +2545,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, virBlkioDevicePtr devices = NULL; size_t ndevices; - if (lxcDomainParseBlkioDeviceStr(params[i].value.s, + if (virDomainParseBlkioDeviceStr(params[i].value.s, param->field, &devices, &ndevices) < 0) { diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 5a75f23981..a9e49501a7 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9220,116 +9220,6 @@ static char *qemuDomainGetSchedulerType(virDomainPtr dom, return ret; } -/* blkioDeviceStr in the form of /device/path,weight,/device/path,weight - * for example, /dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0,800 - */ -static int -qemuDomainParseBlkioDeviceStr(char *blkioDeviceStr, const char *type, - virBlkioDevicePtr *dev, size_t *size) -{ - char *temp; - int ndevices = 0; - int nsep = 0; - size_t i; - virBlkioDevicePtr result = NULL; - - *dev = NULL; - *size = 0; - - if (STREQ(blkioDeviceStr, "")) - return 0; - - temp = blkioDeviceStr; - while (temp) { - temp = strchr(temp, ','); - if (temp) { - temp++; - nsep++; - } - } - - /* A valid string must have even number of fields, hence an odd - * number of commas. */ - if (!(nsep & 1)) - goto parse_error; - - ndevices = (nsep + 1) / 2; - - if (VIR_ALLOC_N(result, ndevices) < 0) - return -1; - - i = 0; - temp = blkioDeviceStr; - while (temp) { - char *p = temp; - - /* device path */ - p = strchr(p, ','); - if (!p) - goto parse_error; - - if (VIR_STRNDUP(result[i].path, temp, p - temp) < 0) - goto cleanup; - - /* value */ - temp = p + 1; - - if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { - if (virStrToLong_uip(temp, &p, 10, &result[i].weight) < 0) - goto number_error; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) { - if (virStrToLong_uip(temp, &p, 10, &result[i].riops) < 0) - goto number_error; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) { - if (virStrToLong_uip(temp, &p, 10, &result[i].wiops) < 0) - goto number_error; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) { - if (virStrToLong_ullp(temp, &p, 10, &result[i].rbps) < 0) - goto number_error; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) { - if (virStrToLong_ullp(temp, &p, 10, &result[i].wbps) < 0) - goto number_error; - } else { - virReportError(VIR_ERR_INVALID_ARG, - _("unknown parameter '%s'"), type); - goto cleanup; - } - - i++; - - if (*p == '\0') - break; - else if (*p != ',') - goto parse_error; - temp = p + 1; - } - - if (!i) - VIR_FREE(result); - - *dev = result; - *size = i; - - return 0; - - parse_error: - virReportError(VIR_ERR_INVALID_ARG, - _("unable to parse blkio device '%s' '%s'"), - type, blkioDeviceStr); - goto cleanup; - - number_error: - virReportError(VIR_ERR_INVALID_ARG, - _("invalid value '%s' for parameter '%s' of device '%s'"), - temp, type, result[i].path); - - cleanup: - if (result) { - virBlkioDeviceArrayClear(result, ndevices); - VIR_FREE(result); - } - return -1; -} /* Modify dest_array to reflect all blkio device changes described in * src_array. */ @@ -9480,10 +9370,10 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, virBlkioDevicePtr devices = NULL; size_t j; - if (qemuDomainParseBlkioDeviceStr(param->value.s, - param->field, - &devices, - &ndevices) < 0) { + if (virDomainParseBlkioDeviceStr(param->value.s, + param->field, + &devices, + &ndevices) < 0) { ret = -1; continue; } @@ -9587,10 +9477,10 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, virBlkioDevicePtr devices = NULL; size_t ndevices; - if (qemuDomainParseBlkioDeviceStr(param->value.s, - param->field, - &devices, - &ndevices) < 0) { + if (virDomainParseBlkioDeviceStr(param->value.s, + param->field, + &devices, + &ndevices) < 0) { ret = -1; continue; } -- 2.22.0

On Wed, Jul 10, 2019 at 17:44:31 +0200, Ilias Stamatis wrote:
The qemuDomainParseBlkioDeviceStr and lxcDomainParseBlkioDeviceSts 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@gmail.com> --- src/conf/domain_conf.c | 115 +++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 6 ++ src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 112 +--------------------------------- src/qemu/qemu_driver.c | 126 +++------------------------------------ 5 files changed, 132 insertions(+), 228 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 3323c9a5b1..e10390189c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -30219,6 +30219,121 @@ virDomainDefGetShortName(const virDomainDef *def)
#undef VIR_DOMAIN_SHORT_NAME_MAX
+ +/* blkioDeviceStr in the form of /device/path,weight,/device/path,weight + * for example, /dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0,800 + */ +int +virDomainParseBlkioDeviceStr(char *blkioDeviceStr,
The domain_conf.c module is meant to collect stuff regarding the XML parser and configuration-related methods. This is a worker method which does not have to do anything with config. Please find a proper place in src/util/ for it.

On Thu, Jul 11, 2019 at 08:52:09AM +0200, Peter Krempa wrote:
On Wed, Jul 10, 2019 at 17:44:31 +0200, Ilias Stamatis wrote:
The qemuDomainParseBlkioDeviceStr and lxcDomainParseBlkioDeviceSts 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@gmail.com> --- src/conf/domain_conf.c | 115 +++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 6 ++ src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 112 +--------------------------------- src/qemu/qemu_driver.c | 126 +++------------------------------------ 5 files changed, 132 insertions(+), 228 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 3323c9a5b1..e10390189c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -30219,6 +30219,121 @@ virDomainDefGetShortName(const virDomainDef *def)
#undef VIR_DOMAIN_SHORT_NAME_MAX
+ +/* blkioDeviceStr in the form of /device/path,weight,/device/path,weight + * for example, /dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0,800 + */ +int +virDomainParseBlkioDeviceStr(char *blkioDeviceStr,
The domain_conf.c module is meant to collect stuff regarding the XML parser and configuration-related methods.
This is a worker method which does not have to do anything with config.
Please find a proper place in src/util/ for it.
In order to add it into src/util we need to remove dependency on virBlkioDevicePtr from the code as in util we should not include anything from other parts of libvirt. Pavel

On Thu, Jul 11, 2019 at 09:50:06 +0200, Pavel Hrdina wrote:
On Thu, Jul 11, 2019 at 08:52:09AM +0200, Peter Krempa wrote:
On Wed, Jul 10, 2019 at 17:44:31 +0200, Ilias Stamatis wrote:
The qemuDomainParseBlkioDeviceStr and lxcDomainParseBlkioDeviceSts 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@gmail.com> --- src/conf/domain_conf.c | 115 +++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 6 ++ src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 112 +--------------------------------- src/qemu/qemu_driver.c | 126 +++------------------------------------ 5 files changed, 132 insertions(+), 228 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 3323c9a5b1..e10390189c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -30219,6 +30219,121 @@ virDomainDefGetShortName(const virDomainDef *def)
#undef VIR_DOMAIN_SHORT_NAME_MAX
+ +/* blkioDeviceStr in the form of /device/path,weight,/device/path,weight + * for example, /dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0,800 + */ +int +virDomainParseBlkioDeviceStr(char *blkioDeviceStr,
The domain_conf.c module is meant to collect stuff regarding the XML parser and configuration-related methods.
This is a worker method which does not have to do anything with config.
Please find a proper place in src/util/ for it.
In order to add it into src/util we need to remove dependency on virBlkioDevicePtr from the code as in util we should not include anything from other parts of libvirt.
Hmpf right. Okay then. I retract my comment then. In the end domain_conf.c is already a dumping pile of random code anyways.

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@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
participants (3)
-
Ilias Stamatis
-
Pavel Hrdina
-
Peter Krempa