From nobody Tue Nov 26 09:52:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1581975037584521.2380080417652; Mon, 17 Feb 2020 13:30:37 -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-64-VqvrlsdMPSuPObNHBAoWYA-1; Mon, 17 Feb 2020 16:30:34 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CAC64800D54; Mon, 17 Feb 2020 21:30:28 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9DA1B90F6F; Mon, 17 Feb 2020 21:30:28 +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 41BEB1803C38; Mon, 17 Feb 2020 21:30:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 01HLTkpB032080 for ; Mon, 17 Feb 2020 16:29:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id 03F6AD1BCC; Mon, 17 Feb 2020 21:29:46 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F37DFD1D0E for ; Mon, 17 Feb 2020 21:29:43 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (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 20C79101929D for ; Mon, 17 Feb 2020 21:29:43 +0000 (UTC) Received: from mail-qt1-f196.google.com (mail-qt1-f196.google.com [209.85.160.196]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-373-9vJeIminMoOjq0G_YxQoRQ-1; Mon, 17 Feb 2020 16:29:38 -0500 Received: by mail-qt1-f196.google.com with SMTP id k7so13042286qth.11; Mon, 17 Feb 2020 13:29:38 -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.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 13:29:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581975036; 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=f2dHxKALdXJDIDBfuiySulS3h+zuJxYnNy1F07+nHTs=; b=hEtxNJIOO+zOi1EhSJZvMBX1t3rA49iPG4gregsZYmI1t+gKErjRcVJDEtR4m1jnlhyqWz fqfcvWY+OIlARXfQpFdW1cFhPqrZkY9wR2TGxdsAkPWeeXJxA/j5mxdhdi1ExMIeNMb552 99mr0Ehj8QHainTdoM1Y13NK2PtRaL0= 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=MFK2///CY2n9aVky50uPnYYQlnaT3D5yyvNS5mRoNMo=; b=J4bKU09ILxBOfVWSZ5Ly5FbNg1idYST2MBMwpwJyIO19OQKOKspECYyPSCW7TCZylY +KMHWiRSXYqx6geGjpz5WX4afxFrrVH3tBkDwYIS1TbQo5VtR7kvnuUZgxn4lbOFIkYr 2Vy6HqzxmeDMjhPQMBw5tRNx7GbThG0ukoq7KDuJWcx0FcgHiLZ6Pxs1XqPyQ3YSxDVO hY1q8Y6y12mnjycSVMuAUUdqk909yOEpcZOprwQ4/PsBeGjU/Ry9KxaHnyTW1DJc4oSB tn11EaOqq/N6eDwfU8rX7f4MEzQ1SusfypYX2+AF5XKyIEB+2b2O78plyFjU43hAD667 IEbQ== X-Gm-Message-State: APjAAAV7aua4ec5lWrYT79s4EtoHeOT48wjsJ9idiBVbK6CwIuXWKQ+m 80DYYDl2ZsYc8BT9CNzXT4ZLcOuK97c= X-Google-Smtp-Source: APXvYqx+wmPXZMwBkH551ElSpxsW7A2q5+7sSkGV1cSYfciaFywKT5nlC490VaukmXdwaOe7o3NvTA== X-Received: by 2002:ac8:7155:: with SMTP id h21mr14036205qtp.95.1581974977846; Mon, 17 Feb 2020 13:29:37 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 12/14] domain_driver.c: add virDomainDriverSetupPersistentDefBlkioParams() Date: Mon, 17 Feb 2020 16:29:19 -0500 Message-Id: <20200217212921.251616-13-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: 9vJeIminMoOjq0G_YxQoRQ-1 X-MC-Unique: VqvrlsdMPSuPObNHBAoWYA-1 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 01HLTkpB032080 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.15 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" This new helper avoids more code repetition inside lxcDomainSetBlkioParameters() and qemuDomainSetBlkioParameters(). Signed-off-by: Daniel Henrique Barboza Reviewed-by: J=C3=A1n Tomko --- src/hypervisor/domain_driver.c | 44 ++++++++++++++++++++++++++++++++++ src/hypervisor/domain_driver.h | 4 ++++ src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 33 +++---------------------- src/qemu/qemu_driver.c | 33 +++---------------------- 5 files changed, 55 insertions(+), 60 deletions(-) diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index bbfadb3d9b..0cf6c7604b 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -206,3 +206,47 @@ virDomainDriverParseBlkioDeviceStr(char *blkioDeviceSt= r, const char *type, } return -1; } + + +int +virDomainDriverSetupPersistentDefBlkioParams(virDomainDefPtr persistentDef, + 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)) { + persistentDef->blkio.weight =3D param->value.ui; + } 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))= { + virBlkioDevicePtr devices =3D NULL; + size_t ndevices; + + if (virDomainDriverParseBlkioDeviceStr(param->value.s, + param->field, + &devices, + &ndevices) < 0) { + ret =3D -1; + continue; + } + + if (virDomainDriverMergeBlkioDevice(&persistentDef->blkio.devi= ces, + &persistentDef->blkio.ndev= ices, + devices, ndevices, + param->field) < 0) + ret =3D -1; + + virBlkioDeviceArrayClear(devices, ndevices); + g_free(devices); + } + } + + return ret; +} diff --git a/src/hypervisor/domain_driver.h b/src/hypervisor/domain_driver.h index b78401ea42..b6d5e66bba 100644 --- a/src/hypervisor/domain_driver.h +++ b/src/hypervisor/domain_driver.h @@ -30,3 +30,7 @@ int virDomainDriverMergeBlkioDevice(virBlkioDevicePtr *de= st_array, =20 int virDomainDriverParseBlkioDeviceStr(char *blkioDeviceStr, const char *t= ype, virBlkioDevicePtr *dev, size_t *siz= e); + +int virDomainDriverSetupPersistentDefBlkioParams(virDomainDefPtr persisten= tDef, + virTypedParameterPtr para= ms, + int nparams); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a01a0223f3..c157012707 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1398,6 +1398,7 @@ virDomainCgroupSetupMemtune; # hypervisor/domain_cgroup.h virDomainDriverMergeBlkioDevice; virDomainDriverParseBlkioDeviceStr; +virDomainDriverSetupPersistentDefBlkioParams; =20 =20 # libvirt_internal.h diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index c93dee37f8..0332b7668a 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2314,7 +2314,6 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, unsigned int flags) { virLXCDriverPtr driver =3D dom->conn->privateData; - size_t i; virDomainObjPtr vm =3D NULL; virDomainDefPtr def =3D NULL; virDomainDefPtr persistentDef =3D NULL; @@ -2371,35 +2370,9 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, if (ret < 0) goto endjob; if (persistentDef) { - for (i =3D 0; i < nparams; i++) { - virTypedParameterPtr param =3D ¶ms[i]; - - if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) { - persistentDef->blkio.weight =3D params[i].value.ui; - } 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)) { - virBlkioDevicePtr devices =3D NULL; - size_t ndevices; - - if (virDomainDriverParseBlkioDeviceStr(params[i].value.s, - param->field, - &devices, - &ndevices) < 0) { - ret =3D -1; - continue; - } - if (virDomainDriverMergeBlkioDevice(&persistentDef->blkio.= devices, - &persistentDef->blkio.= ndevices, - devices, ndevices, - param->field) < 0) - ret =3D -1; - virBlkioDeviceArrayClear(devices, ndevices); - VIR_FREE(devices); - } - } + ret =3D virDomainDriverSetupPersistentDefBlkioParams(persistentDef, + params, + nparams); =20 if (virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir= ) < 0) ret =3D -1; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 850d6699ce..44145a5f60 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9319,7 +9319,6 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, unsigned int flags) { virQEMUDriverPtr driver =3D dom->conn->privateData; - size_t i; virDomainObjPtr vm =3D NULL; virDomainDefPtr def; virDomainDefPtr persistentDef; @@ -9385,35 +9384,9 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, if (ret < 0) goto endjob; if (persistentDef) { - for (i =3D 0; i < nparams; i++) { - virTypedParameterPtr param =3D ¶ms[i]; - - if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) { - persistentDef->blkio.weight =3D param->value.ui; - } 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)) { - virBlkioDevicePtr devices =3D NULL; - size_t ndevices; - - if (virDomainDriverParseBlkioDeviceStr(param->value.s, - param->field, - &devices, - &ndevices) < 0) { - ret =3D -1; - continue; - } - if (virDomainDriverMergeBlkioDevice(&persistentDef->blkio.= devices, - &persistentDef->blkio.= ndevices, - devices, ndevices, - param->field) < 0) - ret =3D -1; - virBlkioDeviceArrayClear(devices, ndevices); - VIR_FREE(devices); - } - } + ret =3D virDomainDriverSetupPersistentDefBlkioParams(persistentDef, + params, + nparams); =20 if (virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir= ) < 0) ret =3D -1; --=20 2.24.1