From nobody Fri Apr 26 10:44:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1562773623; cv=none; d=zoho.com; s=zohoarc; b=OoGkC4AtErIWdXD83G5LF8uRDFRxEZKQnIMjYiYJSW+tf1uR7wpJ1l4QIuQKAgjuytX29fjKwrKyycLGLIuglpDmBwNVoReq45OK3lFmZB71Gmst8zlDIDRqfBkGGkCTANJEahM5uHWDFWkfFdzcO+DfibG6Mmed1ATCxHViWXc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562773623; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=KF2T6yC5OY1bX3sEP9ieAxE6Pqo8wFo1e2zq3u+D2Ts=; b=PSPi7oQFEp0oeW1Izn+d0S/PUYHYsuuGQPjZDBM6jhPp2p9f475Cfi14XkOUmWKQPuIT3SogG2gSFI80MzfcXYlq5zt11ZdS/tpde9fo2AgNdZlHaxY5w+zCmoOHNGW14rsdHPi9irzC5gZNDaukfIpVJuAuTp+PERYapiTCgJs= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1562773623239101.8520372689801; Wed, 10 Jul 2019 08:47:03 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 16DD9FA8CA; Wed, 10 Jul 2019 15:47:01 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E128C60C05; Wed, 10 Jul 2019 15:47:00 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 9E72D206D2; Wed, 10 Jul 2019 15:47:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x6AFkxRv017399 for ; Wed, 10 Jul 2019 11:46:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5C36460A97; Wed, 10 Jul 2019 15:46:59 +0000 (UTC) Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.45]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 54201608A6 for ; Wed, 10 Jul 2019 15:46:56 +0000 (UTC) Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 59E1E30DCC28 for ; Wed, 10 Jul 2019 15:46:54 +0000 (UTC) Received: by mail-wr1-f66.google.com with SMTP id 31so3025467wrm.1 for ; Wed, 10 Jul 2019 08:46:54 -0700 (PDT) Received: from archpc.localdomain (x8d1ee222.agdsn.tu-dresden.de. [141.30.226.34]) by smtp.gmail.com with ESMTPSA id r15sm2603408wrj.68.2019.07.10.08.46.51 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 10 Jul 2019 08:46:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=bDPNOq4KX3JvAkqlvbrcPt95qA5rYQ/e9Hj6QTJBhAc=; b=jBIxu6atC/h6PgeUNXRh1DOYhIW6RBlAqni1wOGa5hOGi5i1C2nYC473tGeJqvmvBp EK7kiWuun+UW4DpDGVemRzOP43q32yqiD/Ci3ldMrlh3BUtfhPBk4npTd3Jfz3IywZH9 1jxBWy+Yu6tCIz3Tvqyh1qQBwBOXLZN5hcS8vj+iV5SfJbj4b12wegKXiJYGT/683EdK p/k41dkw/lxPdROxePj1QE1AOEGqEpxsm11TfaKzNyskoDxSQYsDqT9gzaOjHebdEtw5 08j7cWgrsi2LcavG5Zxu41Hx759YbKGNKYVY/SGFWFVgoPX1kgDbTAbqPDVuhleSWzpx WPPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bDPNOq4KX3JvAkqlvbrcPt95qA5rYQ/e9Hj6QTJBhAc=; b=Sin8H34SOKhueZo51JG6PzrY5nOa89ygpdzJpm8nvAXxx8revuYwVl+e/jlgbWVKKE ZYo2Y4dv7eIMSSnsBfT9A3dp6G7rjzRCUlZfvh4TNUBxyDSOZTXGsmgD+S8xsBJLnI2h /iMDm4k85ZkDujH/K2XxHFIKZ8hR2Xxl9RiMOi4Krz5uXu7AMuKS9hVfzmOT8EibHbrj tB3Xh+3yaXUNOk3hIUXBpO/e63FpKxVC8j+q30Tph9PLJbyqXrTJTY34OW5w/pedK0G6 u/e86QX/Emu+5u2X/ngTwL2CC0SUoDAI6ITu2DLtzzF1lykltff4lqj1wSMrCuzIzJTQ up6Q== X-Gm-Message-State: APjAAAVcKnMt9k98BRopz4ocPxrxPmamgePRzWjimJE30sn64l/Ykkg6 6DrHayRZN5nLzQabsJHrFKkgRjnjO5c= X-Google-Smtp-Source: APXvYqyMj0MUQ99jo5dBn0PkDRbjEQZF33T+G9tza/l5j6Jg8hHXdORqICZe2r34AEaTkbAMzQHrrQ== X-Received: by 2002:a5d:5507:: with SMTP id b7mr31456980wrv.35.1562773612189; Wed, 10 Jul 2019 08:46:52 -0700 (PDT) From: Ilias Stamatis To: libvir-list@redhat.com Date: Wed, 10 Jul 2019 17:44:31 +0200 Message-Id: <20190710154431.30778-2-stamatis.iliass@gmail.com> In-Reply-To: <20190710154431.30778-1-stamatis.iliass@gmail.com> References: <20190710154431.30778-1-stamatis.iliass@gmail.com> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 10 Jul 2019 15:46:54 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 10 Jul 2019 15:46:54 +0000 (UTC) for IP:'209.85.221.66' DOMAIN:'mail-wr1-f66.google.com' HELO:'mail-wr1-f66.google.com' FROM:'stamatis.iliass@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.194 * (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, PDS_NO_HELO_DNS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS) 209.85.221.66 mail-wr1-f66.google.com 209.85.221.66 mail-wr1-f66.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.45 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/2] domain_conf: move DomainParseBlkioDeviceStr out of QEMU and LXC drivers X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 10 Jul 2019 15:47:01 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 --- 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 =3D 0; + int nsep =3D 0; + size_t i; + virBlkioDevicePtr result =3D NULL; + + *dev =3D NULL; + *size =3D 0; + + if (STREQ(blkioDeviceStr, "")) + return 0; + + temp =3D blkioDeviceStr; + while (temp) { + temp =3D 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 =3D (nsep + 1) / 2; + + if (VIR_ALLOC_N(result, ndevices) < 0) + return -1; + + i =3D 0; + temp =3D blkioDeviceStr; + while (temp) { + char *p =3D temp; + + /* device path */ + p =3D strchr(p, ','); + if (!p) + goto parse_error; + + if (VIR_STRNDUP(result[i].path, temp, p - temp) < 0) + goto cleanup; + + /* value */ + temp =3D 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 =3D=3D '\0') + break; + else if (*p !=3D ',') + goto parse_error; + temp =3D p + 1; + } + + if (!i) + VIR_FREE(result); + + *dev =3D result; + *size =3D 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 *d= ef) 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 =3D 0; - int nsep =3D 0; - size_t i; - virBlkioDevicePtr result =3D NULL; - - *dev =3D NULL; - *size =3D 0; - - if (STREQ(blkioDeviceStr, "")) - return 0; - - temp =3D blkioDeviceStr; - while (temp) { - temp =3D 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 =3D (nsep + 1) / 2; - - if (VIR_ALLOC_N(result, ndevices) < 0) - return -1; - - i =3D 0; - temp =3D blkioDeviceStr; - while (temp) { - char *p =3D temp; - - /* device path */ - p =3D strchr(p, ','); - if (!p) - goto parse_error; - - if (VIR_STRNDUP(result[i].path, temp, p - temp) < 0) - goto cleanup; - - /* value */ - temp =3D 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 =3D=3D '\0') - break; - else if (*p !=3D ',') - goto parse_error; - temp =3D p + 1; - } - - if (!i) - VIR_FREE(result); - - *dev =3D result; - *size =3D 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 =3D 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 =3D 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(virDomainPt= r 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 =3D 0; - int nsep =3D 0; - size_t i; - virBlkioDevicePtr result =3D NULL; - - *dev =3D NULL; - *size =3D 0; - - if (STREQ(blkioDeviceStr, "")) - return 0; - - temp =3D blkioDeviceStr; - while (temp) { - temp =3D 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 =3D (nsep + 1) / 2; - - if (VIR_ALLOC_N(result, ndevices) < 0) - return -1; - - i =3D 0; - temp =3D blkioDeviceStr; - while (temp) { - char *p =3D temp; - - /* device path */ - p =3D strchr(p, ','); - if (!p) - goto parse_error; - - if (VIR_STRNDUP(result[i].path, temp, p - temp) < 0) - goto cleanup; - - /* value */ - temp =3D 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 =3D=3D '\0') - break; - else if (*p !=3D ',') - goto parse_error; - temp =3D p + 1; - } - - if (!i) - VIR_FREE(result); - - *dev =3D result; - *size =3D 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 =3D 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 =3D -1; continue; } @@ -9587,10 +9477,10 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, virBlkioDevicePtr devices =3D 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 =3D -1; continue; } -- 2.22.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 10:44:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1562773640; cv=none; d=zoho.com; s=zohoarc; b=fXcYXb2NiAKsF2w7mvPIrHvq8HQGCqvSRt3eJqtV9ccwqzfWYyW64u7ULzsfoj/ZyCohS419zN8OrFhYUu0uD/f0SMvsfwQVTx88og264bAsloxK7VcXCivrB8KWA+YT/pBW6Xjeks5m2G5rNDnX5YaPmurZ3YgGnO55OpgWRwk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562773640; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=mvlbRw7GCt7EGD9dSyCrQ1bgYmQDDbEENW+D+xqmZtM=; b=dKouY/TD75/f6p6Z4KEUzHx6rT7qAJHc2hQzF8X3EJcEsoaMLspRb0FFqAsEk67+/Z+NMPhEaa3Ft3SNAdqBCyg8S3ApiuskiiWRhApadMWoeCEKMHMPHBxrhYKTsMqWs833u+QbdSFgJGqwxqx1NsvLNp7NQ3jMrqm/WyzangM= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1562773640346120.33512298672588; Wed, 10 Jul 2019 08:47:20 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8C0E130C1D06; Wed, 10 Jul 2019 15:47:18 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 662F0BA114; Wed, 10 Jul 2019 15:47:18 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 28CA2206D4; Wed, 10 Jul 2019 15:47:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x6AFlGe0017716 for ; Wed, 10 Jul 2019 11:47:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8CE161001DDD; Wed, 10 Jul 2019 15:47:16 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 844EB1001DDA for ; Wed, 10 Jul 2019 15:47:14 +0000 (UTC) Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B49803D97F for ; Wed, 10 Jul 2019 15:47:12 +0000 (UTC) Received: by mail-wr1-f67.google.com with SMTP id y4so3030176wrm.2 for ; Wed, 10 Jul 2019 08:47:12 -0700 (PDT) Received: from archpc.localdomain (x8d1ee222.agdsn.tu-dresden.de. [141.30.226.34]) by smtp.gmail.com with ESMTPSA id r15sm2603408wrj.68.2019.07.10.08.47.09 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 10 Jul 2019 08:47:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Yb6FmVUKZUiOwsaM3MB27gI8cLdODaqr4BdH/h6burc=; b=XB4vz4VhdpP9I7NUXSCc1q0rkusqAI2g3GIE0cV/goKoX/xqz5AELp915uP0oynp9q kQzoa8DYNPw2BEKyx+34e0Brx2bCUCkicPHnhwBKBsIvL8LX6o/nFx+4vumS9tkWXu3B /cMliT1rOYDK41k1nkBlasYvppQKVM2o/2SljISzQh8RcH051basWtQTWHjoYwB71e94 EyeuNZczWFIyUwKBcIh+J1AED75QqElnuQ3on6tayjIgY2roihoC/eXrMfY2Xi7xUWFF FCEB+itmYUIiSJEoNrpvw+rtFQNG9J6B7xxiPXALOinYFW825t+pm2atxy90wR7yh14g 3aMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Yb6FmVUKZUiOwsaM3MB27gI8cLdODaqr4BdH/h6burc=; b=l8c6Jpcf5X53zP2TR0R0AV941UW2VQDAWGNEoCBpfmkk8T+Rk7Ed+uwShfeSQE1aYv pF9oXJO5xoclTuKP3R8nqf2uSexLHAb2hnJxTH4Cm5L9QeubqzGPqsvl7/oE82VKlEEM TgsPBdKAH5nGeNlCOuZ3yJwdhHG8ORD2v6PuC+dOj/4y/p+ZcouZB66qyM5Iq6JExRBP vNhHFsGFp8/lVWwUO39fHw7LtM5pfO97dqwi7wa4+uRdEGn+saAo97e4WnGEKoKxpZH+ 24N+chQDg6+9K/WDx4K11d1Tc9wN9/bT1KCXB2rNB/3+Xnm9qt0kQI61DnuVd7K5ct00 rW1A== X-Gm-Message-State: APjAAAUyvwFbOg5/G7+M1UeHJ9c3ROCS2aQagfW9MtIrhSHBnag0IS9t QO6d2eUKqRaZoFePbKn87+gxN09f/Io= X-Google-Smtp-Source: APXvYqzz97m9sRMo7Il07Sui5h9oZusPerFkcMxM2MSJcPgOELV8CnrSwm2zLyk42nvYrDg+tboZSw== X-Received: by 2002:a5d:4b91:: with SMTP id b17mr21954209wrt.57.1562773630753; Wed, 10 Jul 2019 08:47:10 -0700 (PDT) From: Ilias Stamatis To: libvir-list@redhat.com Date: Wed, 10 Jul 2019 17:44:32 +0200 Message-Id: <20190710154431.30778-3-stamatis.iliass@gmail.com> In-Reply-To: <20190710154431.30778-1-stamatis.iliass@gmail.com> References: <20190710154431.30778-1-stamatis.iliass@gmail.com> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 10 Jul 2019 15:47:13 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 10 Jul 2019 15:47:13 +0000 (UTC) for IP:'209.85.221.67' DOMAIN:'mail-wr1-f67.google.com' HELO:'mail-wr1-f67.google.com' FROM:'stamatis.iliass@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.194 * (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, PDS_NO_HELO_DNS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS) 209.85.221.67 mail-wr1-f67.google.com 209.85.221.67 mail-wr1-f67.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/2] domain_conf: move DomainMergeBlkioDevice out of QEMU and LXC drivers X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 10 Jul 2019 15:47:19 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 --- 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 =3D 0; i < src_size; i++) { + bool found =3D false; + + src =3D &src_array[i]; + for (j =3D 0; j < *dest_size; j++) { + dest =3D &(*dest_array)[j]; + if (STREQ(src->path, dest->path)) { + found =3D true; + + if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { + dest->weight =3D src->weight; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS))= { + dest->riops =3D src->riops; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)= ) { + dest->wiops =3D src->wiops; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) { + dest->rbps =3D src->rbps; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS))= { + dest->wbps =3D src->wbps; + } else { + virReportError(VIR_ERR_INVALID_ARG, _("Unknown paramet= er %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 =3D &(*dest_array)[*dest_size - 1]; + + if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { + dest->weight =3D src->weight; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) { + dest->riops =3D src->riops; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) { + dest->wiops =3D src->wiops; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) { + dest->rbps =3D src->rbps; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) { + dest->wbps =3D src->wbps; + } else { + *dest_size =3D *dest_size - 1; + return -1; + } + + dest->path =3D src->path; + src->path =3D 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(virDomainDe= fPtr 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 =3D 0; i < src_size; i++) { - bool found =3D false; - - src =3D &src_array[i]; - for (j =3D 0; j < *dest_size; j++) { - dest =3D &(*dest_array)[j]; - if (STREQ(src->path, dest->path)) { - found =3D true; - - if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { - dest->weight =3D src->weight; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS))= { - dest->riops =3D src->riops; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)= ) { - dest->wiops =3D src->wiops; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) { - dest->rbps =3D src->rbps; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS))= { - dest->wbps =3D src->wbps; - } else { - virReportError(VIR_ERR_INVALID_ARG, _("Unknown paramet= er %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 =3D &(*dest_array)[*dest_size - 1]; - - if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { - dest->weight =3D src->weight; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) { - dest->riops =3D src->riops; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) { - dest->wiops =3D src->wiops; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) { - dest->rbps =3D src->rbps; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) { - dest->wbps =3D src->wbps; - } else { - *dest_size =3D *dest_size - 1; - return -1; - } - - dest->path =3D src->path; - src->path =3D NULL; - } - } - - return 0; -} - static int lxcDomainBlockStats(virDomainPtr dom, @@ -2520,7 +2452,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, } if (j !=3D ndevices || - lxcDomainMergeBlkioDevice(&def->blkio.devices, + virDomainMergeBlkioDevice(&def->blkio.devices, &def->blkio.ndevices, devices, ndevices, param->fi= eld) < 0) ret =3D -1; @@ -2552,7 +2484,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, ret =3D -1; continue; } - if (lxcDomainMergeBlkioDevice(&persistentDef->blkio.device= s, + if (virDomainMergeBlkioDevice(&persistentDef->blkio.device= s, &persistentDef->blkio.ndevic= es, devices, ndevices, param->fi= eld) < 0) ret =3D -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 =3D 0; i < src_size; i++) { - bool found =3D false; - - src =3D &src_array[i]; - for (j =3D 0; j < *dest_size; j++) { - dest =3D &(*dest_array)[j]; - if (STREQ(src->path, dest->path)) { - found =3D true; - - if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { - dest->weight =3D src->weight; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS))= { - dest->riops =3D src->riops; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)= ) { - dest->wiops =3D src->wiops; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) { - dest->rbps =3D src->rbps; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS))= { - dest->wbps =3D src->wbps; - } else { - virReportError(VIR_ERR_INVALID_ARG, _("Unknown paramet= er %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 =3D &(*dest_array)[*dest_size - 1]; - - if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { - dest->weight =3D src->weight; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) { - dest->riops =3D src->riops; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) { - dest->wiops =3D src->wiops; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) { - dest->rbps =3D src->rbps; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) { - dest->wbps =3D src->wbps; - } else { - *dest_size =3D *dest_size - 1; - return -1; - } - - dest->path =3D src->path; - src->path =3D NULL; - } - } - - return 0; -} - static int qemuDomainSetBlkioParameters(virDomainPtr dom, virTypedParameterPtr params, @@ -9449,9 +9380,9 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, } if (j !=3D ndevices || - qemuDomainMergeBlkioDevice(&def->blkio.devices, - &def->blkio.ndevices, - devices, ndevices, param->f= ield) < 0) + virDomainMergeBlkioDevice(&def->blkio.devices, + &def->blkio.ndevices, + devices, ndevices, param->fi= eld) < 0) ret =3D -1; virBlkioDeviceArrayClear(devices, ndevices); VIR_FREE(devices); @@ -9484,9 +9415,9 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, ret =3D -1; continue; } - if (qemuDomainMergeBlkioDevice(&persistentDef->blkio.devic= es, - &persistentDef->blkio.ndevi= ces, - devices, ndevices, param->f= ield) < 0) + if (virDomainMergeBlkioDevice(&persistentDef->blkio.device= s, + &persistentDef->blkio.ndevic= es, + devices, ndevices, param->fi= eld) < 0) ret =3D -1; virBlkioDeviceArrayClear(devices, ndevices); VIR_FREE(devices); -- 2.22.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list