From nobody Tue Nov 26 08:44:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1581975024518606.3135059932732; Mon, 17 Feb 2020 13:30:24 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-222-5SlRNCg-OI6wZDT_ZaBvNQ-1; Mon, 17 Feb 2020 16:30:19 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C968A1005514; Mon, 17 Feb 2020 21:30:13 +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 9B56A90765; Mon, 17 Feb 2020 21:30:13 +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 2A7FB35B0E; Mon, 17 Feb 2020 21:30:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 01HLTehi032036 for ; Mon, 17 Feb 2020 16:29:40 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6C9BC2166B2A; Mon, 17 Feb 2020 21:29:40 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 680D92166B27 for ; Mon, 17 Feb 2020 21:29:40 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4980F186E15D for ; Mon, 17 Feb 2020 21:29:40 +0000 (UTC) Received: from mail-qk1-f196.google.com (mail-qk1-f196.google.com [209.85.222.196]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-6-UT5K3tZtP8S3WNu_Qc7mCQ-1; Mon, 17 Feb 2020 16:29:37 -0500 Received: by mail-qk1-f196.google.com with SMTP id u124so17077229qkh.13; Mon, 17 Feb 2020 13:29:37 -0800 (PST) Received: from rekt.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id i7sm872284qki.83.2020.02.17.13.29.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 13:29:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581975023; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=CnuHcuoTXFyPjF6s6KqDgCAsgwHYtipVBDHdYoXrxDk=; b=dXUmNj+InhAJwMi3Zv/+mCSJNGUNmonJGIu/nFvLoBbM5dMnAyXgEZKOuDESwzectn7lt0 5cklubo2W7ZYb2IGglmZ/HtuNs8GMR7V/R44UlQj0kv1g9l9I3hMqiiRvD54DtJHcuRN7O l2w5Ib0c3wDS0lVzh/c0/7yh0QSreck= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=i9uCGelhb/CXlMZ8bI/C3bZKgB+fU7khyppHCaJe3LQ=; b=m0pcp9P1B8m9Wj5r698D3YojZgrwTA6uAo4vWDhCIaxgUzXWvpfoYESEor+szCcIIJ OBUyZf3Cs41pzgpzJd6Q0nxs00+wbbrAvQu8+bu0bbnMyjipWRskpm+uycfMhgLFl1uX k7H4JAkkVR0Tz5+woVNTDeROcrBz83DVe+ZQ91xNwmCyr0ZoX1N0O+4WLyayhf2gNX7S i4CdAgLUnRXTgsiXuGElIekkxLxwQ3i/4t7wc+77XaXupJSbSqjHry+pfCfvofS1gtBM VwXQOvmKpnJrmRJBFC1+RmBq330ctVX7YKDzNnFWXfg3U8JSmSyboV16URSR66wAzUlE Epcg== X-Gm-Message-State: APjAAAVm18LcfghMSXoW5QtH5bgguXh3Bammc/F9CUKbDZmJZYmuVDQw YvpZYmueYlKfxFB+8xlfQPvLBqgRcAk= X-Google-Smtp-Source: APXvYqz/7Eo51FiDVFa3UXVJB/jtypy/XHJNdIMRQe9NkSoVqUnRiQwsy6ik3QjRvJtJLaTAKVkPBQ== X-Received: by 2002:a37:de16:: with SMTP id h22mr16157104qkj.400.1581974976966; Mon, 17 Feb 2020 13:29:36 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 11/14] domain_cgroup.c: add virDomainCgroupSetupDomainBlkioParameters() Date: Mon, 17 Feb 2020 16:29:18 -0500 Message-Id: <20200217212921.251616-12-danielhb413@gmail.com> In-Reply-To: <20200217212921.251616-1-danielhb413@gmail.com> References: <20200217212921.251616-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: UT5K3tZtP8S3WNu_Qc7mCQ-1 X-MC-Unique: 5SlRNCg-OI6wZDT_ZaBvNQ-1 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 01HLTehi032036 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , jtomko@redhat.com, crobinso@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" After the introduction of virDomainDriverMergeBlkioDevice() in a previous patch, it is now clear that lxcDomainSetBlkioParameters() and qemuDomainSetBlkioParameters() uses the same loop to set cgroup blkio parameter of a domain. Avoid the repetition by adding a new helper called virDomainCgroupSetupDomainBlkioParameters(). Signed-off-by: Daniel Henrique Barboza Reviewed-by: J=C3=A1n Tomko --- po/POTFILES.in | 1 + src/hypervisor/domain_cgroup.c | 101 +++++++++++++++++++++++++++++++++ src/hypervisor/domain_cgroup.h | 4 ++ src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 87 +--------------------------- src/qemu/qemu_driver.c | 88 +--------------------------- 6 files changed, 113 insertions(+), 169 deletions(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index aa5c1fb6c7..1675c45206 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -78,6 +78,7 @@ @SRCDIR@/src/hyperv/hyperv_driver.c @SRCDIR@/src/hyperv/hyperv_util.c @SRCDIR@/src/hyperv/hyperv_wmi.c +@SRCDIR@/src/hypervisor/domain_cgroup.c @SRCDIR@/src/hypervisor/domain_driver.c @SRCDIR@/src/interface/interface_backend_netcf.c @SRCDIR@/src/interface/interface_backend_udev.c diff --git a/src/hypervisor/domain_cgroup.c b/src/hypervisor/domain_cgroup.c index e60abd536c..32b07be3d6 100644 --- a/src/hypervisor/domain_cgroup.c +++ b/src/hypervisor/domain_cgroup.c @@ -21,6 +21,9 @@ #include =20 #include "domain_cgroup.h" +#include "domain_driver.h" + +#define VIR_FROM_THIS VIR_FROM_DOMAIN =20 =20 int @@ -84,3 +87,101 @@ virDomainCgroupSetupMemtune(virCgroupPtr cgroup, virDom= ainMemtune mem) =20 return 0; } + + +int +virDomainCgroupSetupDomainBlkioParameters(virCgroupPtr cgroup, + virDomainDefPtr def, + virTypedParameterPtr params, + int nparams) +{ + size_t i; + int ret =3D 0; + + for (i =3D 0; i < nparams; i++) { + virTypedParameterPtr param =3D ¶ms[i]; + + if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) { + if (virCgroupSetBlkioWeight(cgroup, params[i].value.ui) < 0) + ret =3D -1; + } 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))= { + size_t ndevices; + virBlkioDevicePtr devices =3D NULL; + size_t j; + + if (virDomainDriverParseBlkioDeviceStr(params[i].value.s, + param->field, + &devices, + &ndevices) < 0) { + ret =3D -1; + continue; + } + + if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { + for (j =3D 0; j < ndevices; j++) { + if (virCgroupSetupBlkioDeviceWeight(cgroup, devices[j]= .path, + &devices[j].weight= ) < 0) { + ret =3D -1; + break; + } + } + } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_IO= PS)) { + for (j =3D 0; j < ndevices; j++) { + if (virCgroupSetupBlkioDeviceReadIops(cgroup, devices[= j].path, + &devices[j].riop= s) < 0) { + ret =3D -1; + break; + } + } + } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_I= OPS)) { + for (j =3D 0; j < ndevices; j++) { + if (virCgroupSetupBlkioDeviceWriteIops(cgroup, devices= [j].path, + &devices[j].wio= ps) < 0) { + ret =3D -1; + break; + } + } + } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_BP= S)) { + for (j =3D 0; j < ndevices; j++) { + if (virCgroupSetupBlkioDeviceReadBps(cgroup, devices[j= ].path, + &devices[j].rbps)= < 0) { + ret =3D -1; + break; + } + } + } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_B= PS)) { + for (j =3D 0; j < ndevices; j++) { + if (virCgroupSetupBlkioDeviceWriteBps(cgroup, devices[= j].path, + &devices[j].wbps= ) < 0) { + ret =3D -1; + break; + } + } + } else { + virReportError(VIR_ERR_INVALID_ARG, _("Unknown blkio param= eter %s"), + param->field); + ret =3D -1; + virBlkioDeviceArrayClear(devices, ndevices); + g_free(devices); + + continue; + } + + if (j !=3D ndevices || + virDomainDriverMergeBlkioDevice(&def->blkio.devices, + &def->blkio.ndevices, + devices, ndevices, + param->field) < 0) + ret =3D -1; + + virBlkioDeviceArrayClear(devices, ndevices); + g_free(devices); + } + } + + return ret; +} diff --git a/src/hypervisor/domain_cgroup.h b/src/hypervisor/domain_cgroup.h index 82ba47e85f..7f3a0d12f9 100644 --- a/src/hypervisor/domain_cgroup.h +++ b/src/hypervisor/domain_cgroup.h @@ -26,3 +26,7 @@ =20 int virDomainCgroupSetupBlkio(virCgroupPtr cgroup, virDomainBlkiotune blki= o); int virDomainCgroupSetupMemtune(virCgroupPtr cgroup, virDomainMemtune mem); +int virDomainCgroupSetupDomainBlkioParameters(virCgroupPtr cgroup, + virDomainDefPtr def, + virTypedParameterPtr params, + int nparams); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 88f9ca16d1..a01a0223f3 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1391,6 +1391,7 @@ virSetConnectStorage; =20 # hypervisor/domain_cgroup.h virDomainCgroupSetupBlkio; +virDomainCgroupSetupDomainBlkioParameters; virDomainCgroupSetupMemtune; =20 =20 diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 78a0174277..c93dee37f8 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -56,6 +56,7 @@ #include "virpidfile.h" #include "virfdstream.h" #include "domain_audit.h" +#include "domain_cgroup.h" #include "domain_driver.h" #include "domain_nwfilter.h" #include "virinitctl.h" @@ -2364,90 +2365,8 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, =20 ret =3D 0; if (def) { - for (i =3D 0; i < nparams; i++) { - virTypedParameterPtr param =3D ¶ms[i]; - - if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) { - if (virCgroupSetBlkioWeight(priv->cgroup, params[i].value.= ui) < 0) - ret =3D -1; - } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)= || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_IO= PS) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_I= OPS) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_BP= S) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_B= PS)) { - virCgroupPtr cgroup =3D priv->cgroup; - size_t ndevices; - virBlkioDevicePtr devices =3D NULL; - size_t j; - - if (virDomainDriverParseBlkioDeviceStr(params[i].value.s, - param->field, - &devices, - &ndevices) < 0) { - ret =3D -1; - continue; - } - - if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { - for (j =3D 0; j < ndevices; j++) { - if (virCgroupSetupBlkioDeviceWeight(cgroup, device= s[j].path, - &devices[j].we= ight) < 0) { - ret =3D -1; - break; - } - } - } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_REA= D_IOPS)) { - for (j =3D 0; j < ndevices; j++) { - if (virCgroupSetupBlkioDeviceReadIops(cgroup, devi= ces[j].path, - &devices[j].= riops) < 0) { - ret =3D -1; - break; - } - } - } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRI= TE_IOPS)) { - for (j =3D 0; j < ndevices; j++) { - if (virCgroupSetupBlkioDeviceWriteIops(cgroup, dev= ices[j].path, - &devices[j]= .wiops) < 0) { - ret =3D -1; - break; - } - } - } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_REA= D_BPS)) { - for (j =3D 0; j < ndevices; j++) { - if (virCgroupSetupBlkioDeviceReadBps(cgroup, devic= es[j].path, - &devices[j].r= bps) < 0) { - ret =3D -1; - break; - } - } - } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRI= TE_BPS)) { - for (j =3D 0; j < ndevices; j++) { - if (virCgroupSetupBlkioDeviceWriteBps(cgroup, devi= ces[j].path, - &devices[j].= wbps) < 0) { - ret =3D -1; - break; - } - } - } else { - virReportError(VIR_ERR_INVALID_ARG, _("Unknown blkio p= arameter %s"), - param->field); - ret =3D -1; - virBlkioDeviceArrayClear(devices, ndevices); - VIR_FREE(devices); - - continue; - } - - if (j !=3D ndevices || - virDomainDriverMergeBlkioDevice(&def->blkio.devices, - &def->blkio.ndevices, - devices, ndevices, - param->field) < 0) - ret =3D -1; - virBlkioDeviceArrayClear(devices, ndevices); - VIR_FREE(devices); - } - } + ret =3D virDomainCgroupSetupDomainBlkioParameters(priv->cgroup, de= f, + params, nparams); } if (ret < 0) goto endjob; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 2205dd1194..850d6699ce 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -65,6 +65,7 @@ #include "viruuid.h" #include "domain_conf.h" #include "domain_audit.h" +#include "domain_cgroup.h" #include "domain_driver.h" #include "node_device_conf.h" #include "virpci.h" @@ -9375,91 +9376,8 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, =20 ret =3D 0; if (def) { - for (i =3D 0; i < nparams; i++) { - virTypedParameterPtr param =3D ¶ms[i]; - - if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) { - if (virCgroupSetBlkioWeight(priv->cgroup, param->value.ui)= < 0 || - virCgroupGetBlkioWeight(priv->cgroup, &def->blkio.weig= ht) < 0) - ret =3D -1; - } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)= || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_IO= PS) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_I= OPS) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_BP= S) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_B= PS)) { - virCgroupPtr cgroup =3D priv->cgroup; - size_t ndevices; - virBlkioDevicePtr devices =3D NULL; - size_t j; - - if (virDomainDriverParseBlkioDeviceStr(param->value.s, - param->field, - &devices, - &ndevices) < 0) { - ret =3D -1; - continue; - } - - if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { - for (j =3D 0; j < ndevices; j++) { - if (virCgroupSetupBlkioDeviceWeight(cgroup, device= s[j].path, - &devices[j].we= ight) < 0) { - ret =3D -1; - break; - } - } - } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_REA= D_IOPS)) { - for (j =3D 0; j < ndevices; j++) { - if (virCgroupSetupBlkioDeviceReadIops(cgroup, devi= ces[j].path, - &devices[j].= riops) < 0) { - ret =3D -1; - break; - } - } - } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRI= TE_IOPS)) { - for (j =3D 0; j < ndevices; j++) { - if (virCgroupSetupBlkioDeviceWriteIops(cgroup, dev= ices[j].path, - &devices[j]= .wiops) < 0) { - ret =3D -1; - break; - } - } - } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_REA= D_BPS)) { - for (j =3D 0; j < ndevices; j++) { - if (virCgroupSetupBlkioDeviceReadBps(cgroup, devic= es[j].path, - &devices[j].r= bps) < 0) { - ret =3D -1; - break; - } - } - } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRI= TE_BPS)) { - for (j =3D 0; j < ndevices; j++) { - if (virCgroupSetupBlkioDeviceWriteBps(cgroup, devi= ces[j].path, - &devices[j].= wbps) < 0) { - ret =3D -1; - break; - } - } - } else { - virReportError(VIR_ERR_INVALID_ARG, _("Unknown blkio p= arameter %s"), - param->field); - ret =3D -1; - virBlkioDeviceArrayClear(devices, ndevices); - VIR_FREE(devices); - - continue; - } - - if (j !=3D ndevices || - virDomainDriverMergeBlkioDevice(&def->blkio.devices, - &def->blkio.ndevices, - devices, ndevices, - param->field) < 0) - ret =3D -1; - virBlkioDeviceArrayClear(devices, ndevices); - VIR_FREE(devices); - } - } + ret =3D virDomainCgroupSetupDomainBlkioParameters(priv->cgroup, de= f, + params, nparams); =20 if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto endjob; --=20 2.24.1