From nobody Tue Nov 26 08:54:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; 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 207.211.31.81 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 [207.211.31.81]) by mx.zohomail.com with SMTPS id 158197502924259.156669667289634; Mon, 17 Feb 2020 13:30:29 -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-221-eXl8JZh0PiWoESN8Nlsb5Q-1; Mon, 17 Feb 2020 16:30:24 -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 8019E801E67; Mon, 17 Feb 2020 21:30:18 +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 508D590F68; Mon, 17 Feb 2020 21:30: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 DB31B180BA96; Mon, 17 Feb 2020 21:30:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 01HLTcwM032007 for ; Mon, 17 Feb 2020 16:29:39 -0500 Received: by smtp.corp.redhat.com (Postfix) id D3F031003342; Mon, 17 Feb 2020 21:29:38 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CEDDE1004C44 for ; Mon, 17 Feb 2020 21:29:38 +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 A70AB8012B3 for ; Mon, 17 Feb 2020 21:29:38 +0000 (UTC) Received: from mail-qk1-f194.google.com (mail-qk1-f194.google.com [209.85.222.194]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-219-zFRMNLh4OvqHI38SvHMtjA-1; Mon, 17 Feb 2020 16:29:36 -0500 Received: by mail-qk1-f194.google.com with SMTP id b7so17583928qkl.7; Mon, 17 Feb 2020 13:29:35 -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.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 13:29:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581975027; 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=BCEfKXyc3M0ACsc7FIvban2pgZymwCFhHU0JuHytJA8=; b=MfF0vXV6e8eut2nF9nipYhMDXLSUBM+9lClZ7CQjkw1zsgYgTN4i1okL3l1wEUZWPPeBhT YD6DrmrJDnkHkOLJ33oaDTr4PQlsgbWPQAK6FxP/IH0/SFTTuqm4VCThksAAaS0hl2xv3u NXLgkARvD1XN+rUlsMc4Zsts9tjlg90= 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=TMk94VojuA2nvJW6hNzlxP0NDyi4lmRCp/EDvjro0rQ=; b=Y4xuLqAoevbKr5flxDti3Q5E+OdjyKamYaR9BVANB6jD+MzWIVa9UW2YAhqme+Y/Mg 3mC51MfBAOCcT7JM9HCkBAAVfxS/vrCc7vDCqGIb++me0G38pSC/ejFFdGrvqyl7ZTUW FTxG3h30GGbCCmNO5TPYtejg42ufT4b6F1UuRGpon6d2v7OGcl2Vnk2/W4nWIVlCdmIj 8P5PLzzosyb/Mf9d1l7Hi5BRWvStlu6iHzGL4h/BS2YlY1HSN0Up8mabBIheBNZNuIqv nn+rcEmaZfsVY8uLvndTJb+7qZ3tSHr5nwH5IRSEQNytZ4i8WX8Xhw6U9x6eep3oM3Sl qFdQ== X-Gm-Message-State: APjAAAWKEIk+RKuex74Zt36Z51iGuEmbELPwLy+ZAxGTRxv9LDY15OJm 6vW3gCJLWH1QDUsywCsu+3Zes1j/IaA= X-Google-Smtp-Source: APXvYqzBP30xNslwRNmhAvJ8mtt33YJHe84HG0KFLO7RAkppIDPprNmYZzrwjYdI5dfReYdZey4N6g== X-Received: by 2002:ae9:e50b:: with SMTP id w11mr16209404qkf.110.1581974975243; Mon, 17 Feb 2020 13:29:35 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 09/14] src/hypervisor: introduce domain_driver.c Date: Mon, 17 Feb 2020 16:29:16 -0500 Message-Id: <20200217212921.251616-10-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: zFRMNLh4OvqHI38SvHMtjA-1 X-MC-Unique: eXl8JZh0PiWoESN8Nlsb5Q-1 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 01HLTcwM032007 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" lxcDomainMergeBlkioDevice() and qemuDomainMergeBlkioDevice() are the same functions. This duplicated code can't be put in the existing domain_cgroup.c since it's not cgroup related. This patch introduces a new src/hypervisor/domain_driver.c to host this more generic code that can be shared between virt drivers. This new file is then used to create a new helper called virDomainDeivceMergeBlkioDevice() to eliminate the code repetition mentioned above. Callers in LXC and QEMU files were updated. This change is a preliminary step for more code reduction of cgroup related code inside lxcDomainSetBlkioParameters() and qemuDomainSetBlkioParameters(). Signed-off-by: Daniel Henrique Barboza Reviewed-by: J=C3=A1n Tomko --- src/hypervisor/Makefile.inc.am | 2 + src/hypervisor/domain_driver.c | 96 ++++++++++++++++++++++++++++++++++ src/hypervisor/domain_driver.h | 29 ++++++++++ src/libvirt_private.syms | 4 ++ src/lxc/lxc_driver.c | 84 ++++------------------------- src/qemu/qemu_driver.c | 83 ++++------------------------- 6 files changed, 149 insertions(+), 149 deletions(-) create mode 100644 src/hypervisor/domain_driver.c create mode 100644 src/hypervisor/domain_driver.h diff --git a/src/hypervisor/Makefile.inc.am b/src/hypervisor/Makefile.inc.am index 961b4e2b95..02cf2c7cb1 100644 --- a/src/hypervisor/Makefile.inc.am +++ b/src/hypervisor/Makefile.inc.am @@ -3,6 +3,8 @@ HYPERVISOR_SOURCES =3D \ hypervisor/domain_cgroup.h \ hypervisor/domain_cgroup.c \ + hypervisor/domain_driver.h \ + hypervisor/domain_driver.c \ $(NULL) =20 noinst_LTLIBRARIES +=3D libvirt_hypervisor.la diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c new file mode 100644 index 0000000000..c999458c25 --- /dev/null +++ b/src/hypervisor/domain_driver.c @@ -0,0 +1,96 @@ +/* + * domain_driver.c: general functions shared between hypervisor drivers + * + * Copyright IBM Corp. 2020 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include "domain_driver.h" +#include "viralloc.h" + +#define VIR_FROM_THIS VIR_FROM_DOMAIN + + +/* Modify dest_array to reflect all blkio device changes described in + * src_array. */ +int +virDomainDriverMergeBlkioDevice(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; +} diff --git a/src/hypervisor/domain_driver.h b/src/hypervisor/domain_driver.h new file mode 100644 index 0000000000..2fb4148dff --- /dev/null +++ b/src/hypervisor/domain_driver.h @@ -0,0 +1,29 @@ +/* + * domain_driver.h: general functions shared between hypervisor drivers + * + * Copyright IBM Corp. 2020 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#pragma once + +#include "domain_conf.h" + +int virDomainDriverMergeBlkioDevice(virBlkioDevicePtr *dest_array, + size_t *dest_size, + virBlkioDevicePtr src_array, + size_t src_size, + const char *type); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 2f958b1c6f..c6b9afe259 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1394,6 +1394,10 @@ virDomainCgroupSetupBlkio; virDomainCgroupSetupMemtune; =20 =20 +# hypervisor/domain_cgroup.h +virDomainDriverMergeBlkioDevice; + + # libvirt_internal.h virConnectSupportsFeature; virDomainMigrateBegin3; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index d6d0f031a5..08c744a69b 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_driver.h" #include "domain_nwfilter.h" #include "virinitctl.h" #include "virnetdev.h" @@ -2214,75 +2215,6 @@ lxcDomainParseBlkioDeviceStr(char *blkioDeviceStr, c= onst char *type, return -1; } =20 -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, const char *path, @@ -2613,9 +2545,10 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, } =20 if (j !=3D ndevices || - lxcDomainMergeBlkioDevice(&def->blkio.devices, - &def->blkio.ndevices, - devices, ndevices, param->fi= eld) < 0) + virDomainDriverMergeBlkioDevice(&def->blkio.devices, + &def->blkio.ndevices, + devices, ndevices, + param->field) < 0) ret =3D -1; virBlkioDeviceArrayClear(devices, ndevices); VIR_FREE(devices); @@ -2645,9 +2578,10 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, ret =3D -1; continue; } - if (lxcDomainMergeBlkioDevice(&persistentDef->blkio.device= s, - &persistentDef->blkio.ndevic= es, - devices, ndevices, param->fi= eld) < 0) + if (virDomainDriverMergeBlkioDevice(&persistentDef->blkio.= devices, + &persistentDef->blkio.= ndevices, + devices, ndevices, + param->field) < 0) ret =3D -1; virBlkioDeviceArrayClear(devices, ndevices); VIR_FREE(devices); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index e9feb50220..3048e8a5c7 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_driver.h" #include "node_device_conf.h" #include "virpci.h" #include "virusb.h" @@ -9419,74 +9420,6 @@ qemuDomainParseBlkioDeviceStr(char *blkioDeviceStr, = const char *type, return -1; } =20 -/* 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; -} =20 static int qemuDomainSetBlkioParameters(virDomainPtr dom, @@ -9628,9 +9561,10 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, } =20 if (j !=3D ndevices || - qemuDomainMergeBlkioDevice(&def->blkio.devices, - &def->blkio.ndevices, - devices, ndevices, param->f= ield) < 0) + virDomainDriverMergeBlkioDevice(&def->blkio.devices, + &def->blkio.ndevices, + devices, ndevices, + param->field) < 0) ret =3D -1; virBlkioDeviceArrayClear(devices, ndevices); VIR_FREE(devices); @@ -9663,9 +9597,10 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, ret =3D -1; continue; } - if (qemuDomainMergeBlkioDevice(&persistentDef->blkio.devic= es, - &persistentDef->blkio.ndevi= ces, - devices, ndevices, param->f= ield) < 0) + if (virDomainDriverMergeBlkioDevice(&persistentDef->blkio.= devices, + &persistentDef->blkio.= ndevices, + devices, ndevices, + param->field) < 0) ret =3D -1; virBlkioDeviceArrayClear(devices, ndevices); VIR_FREE(devices); --=20 2.24.1