From nobody Tue Nov 26 08:23:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.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 207.211.31.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 [207.211.31.120]) by mx.zohomail.com with SMTPS id 1581975009880161.37380210322; Mon, 17 Feb 2020 13:30:09 -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-319-wTX96fTyO4-Qpixeozgt3g-1; Mon, 17 Feb 2020 16:30:06 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id A815F100726F; Mon, 17 Feb 2020 21:30:00 +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 72CEF60C99; Mon, 17 Feb 2020 21:30: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 12C8018089D5; Mon, 17 Feb 2020 21:30:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 01HLTZus031957 for ; Mon, 17 Feb 2020 16:29:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id DDDD4201808D; Mon, 17 Feb 2020 21:29:34 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D85132026D67 for ; Mon, 17 Feb 2020 21:29:34 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 B8184802711 for ; Mon, 17 Feb 2020 21:29:34 +0000 (UTC) Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-354-gWsUHooVORyNr-TktXruJg-1; Mon, 17 Feb 2020 16:29:32 -0500 Received: by mail-qk1-f171.google.com with SMTP id c188so17592884qkg.4; Mon, 17 Feb 2020 13:29:31 -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.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 13:29:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581975008; 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=XNQxVJiQy076DuN6FP9sx9ytAAvzBf3EGBr6bKfjtqc=; b=BmjjkhdQtHHyZlQXv/SbA3ldagzD/ZS8aM3XXdxM4R4LraLtVSYwUieLtHd8kocGlY0pX7 msXpnQTU7YQQoELBKhkFhI5xtFtxHdhXqedNRJ8Bie18d368ax/VGa3k4XQuggBuyfH3Du uEDnms1k1oqqHyU1UC62uKn8KNhAHwc= 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=0NghzWTjbvH2pi38fODXWjgERN5+CMNzigihg1pxnG4=; b=e9bDKNTKt3WuKM6UXAa8Q36ux2HfJpw6P8r24Nl2VuMaOcYsSYInbWJxvVBYdXYvUL Ly0YWDf9gCxlCSVi8wQzlFYbpuuWa9ed9Qd81kK2OGUV1kXeATu8+0rKXRA+ZcBEDa5D Rm+sjhnfUP/HGNzB+URDTYZ7QvKBZ7dWjCksF4bDqoZfUa4ORZAq+wzT+z0VNOQ1XZGi JeYP52ATSM1nYlwDNOu8GH6dw9fmwUzG8YkI/MufS3n7Bl1SHJhCJHSnyktxjy0XeG/I d42VrEBv1NP/QbAQ7bxtwwcX1g6p7RHaypEiapnFD0d7Bhi7NBqYWISbSfJHnb2t7tX4 TSWg== X-Gm-Message-State: APjAAAWZna+871Hvneju9BPShYZ02MGVxMSKepscCH6xauCmFRI5aK+h YRBsokvJaqfM7RGEtJXUEUJqfRfjmZU= X-Google-Smtp-Source: APXvYqzmZSt2lVh5zRnUv8WXiLC9D6jqxFc0BfND/4BRN8RMQLpvlbt4ZRdQvi+pmvP1pB+4T4p6Qw== X-Received: by 2002:a05:620a:4cc:: with SMTP id 12mr15684353qks.153.1581974971297; Mon, 17 Feb 2020 13:29:31 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 04/14] src: introducing hypervisor/domain_cgroup.c Date: Mon, 17 Feb 2020 16:29:11 -0500 Message-Id: <20200217212921.251616-5-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: gWsUHooVORyNr-TktXruJg-1 X-MC-Unique: wTX96fTyO4-Qpixeozgt3g-1 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 01HLTZus031957 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.12 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" There is duplicated code between virt drivers that needs to be moved to avoid code repetition. In the case of duplicated code between lxc_cgroup.c and qemu_cgroup.c a common place would be utils/vircgroup.c. The problem is that this would introduce /conf related definitions that shouldn't be imported to vircgroup.c, which is supposed to be a place for utilitary cgroups functions only. And syntax-check would forbid it anyway due to cross-directory includes being used. An alternative would be to overload domain_conf.c, which already contains all the definitions required. But that file is already crowded with XML handling code and we wouldn't do any favors to it by putting more utilitary, non-XML parsing/formatting code there. In [1], Colesuggested a 'domain_cgroup' file to host common code between lxc_cgroup and qemu_cgroup, and Daniel suggested a 'src/hypervisor' dir to host these type of files. This patch introduces src/hypervisor/domain_cgroup.c and, to get started, introduces a new virDomainCgroupSetupBlkio() function to host shared code between virLXCCgroupSetupBlkioTune() and qemuSetupBlkioCgroup(). [1] https://www.redhat.com/archives/libvir-list/2019-December/msg00817.html Signed-off-by: Daniel Henrique Barboza Reviewed-by: J=C3=A1n Tomko --- src/Makefile.am | 1 + src/hypervisor/Makefile.inc.am | 14 +++++++ src/hypervisor/domain_cgroup.c | 67 ++++++++++++++++++++++++++++++++++ src/hypervisor/domain_cgroup.h | 27 ++++++++++++++ src/libvirt_private.syms | 4 ++ src/lxc/Makefile.inc.am | 2 + src/lxc/lxc_cgroup.c | 40 +------------------- src/qemu/Makefile.inc.am | 1 + src/qemu/qemu_cgroup.c | 40 +------------------- 9 files changed, 120 insertions(+), 76 deletions(-) create mode 100644 src/hypervisor/Makefile.inc.am create mode 100644 src/hypervisor/domain_cgroup.c create mode 100644 src/hypervisor/domain_cgroup.h diff --git a/src/Makefile.am b/src/Makefile.am index 952dfdbb5f..12dd6b80e1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -108,6 +108,7 @@ include locking/Makefile.inc.am include admin/Makefile.inc.am include rpc/Makefile.inc.am include test/Makefile.inc.am +include hypervisor/Makefile.inc.am include esx/Makefile.inc.am include hyperv/Makefile.inc.am include vmx/Makefile.inc.am diff --git a/src/hypervisor/Makefile.inc.am b/src/hypervisor/Makefile.inc.am new file mode 100644 index 0000000000..961b4e2b95 --- /dev/null +++ b/src/hypervisor/Makefile.inc.am @@ -0,0 +1,14 @@ +# vim: filetype=3Dautomake + +HYPERVISOR_SOURCES =3D \ + hypervisor/domain_cgroup.h \ + hypervisor/domain_cgroup.c \ + $(NULL) + +noinst_LTLIBRARIES +=3D libvirt_hypervisor.la +libvirt_la_BUILT_LIBADD +=3D libvirt_hypervisor.la +libvirt_hypervisor_la_CFLAGS =3D \ + -I$(srcdir)/conf \ + $(AM_CFLAGS) \ + $(NULL) +libvirt_hypervisor_la_SOURCES =3D $(HYPERVISOR_SOURCES) diff --git a/src/hypervisor/domain_cgroup.c b/src/hypervisor/domain_cgroup.c new file mode 100644 index 0000000000..bef60f56c5 --- /dev/null +++ b/src/hypervisor/domain_cgroup.c @@ -0,0 +1,67 @@ +/* + * domain_cgroup.c: cgroup 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_cgroup.h" + + +int +virDomainCgroupSetupBlkio(virCgroupPtr cgroup, virDomainBlkiotune blkio) +{ + size_t i; + + if (blkio.weight !=3D 0 && + virCgroupSetBlkioWeight(cgroup, blkio.weight) < 0) + return -1; + + if (blkio.ndevices) { + for (i =3D 0; i < blkio.ndevices; i++) { + virBlkioDevicePtr dev =3D &blkio.devices[i]; + + if (dev->weight && + virCgroupSetupBlkioDeviceWeight(cgroup, dev->path, + &dev->weight) < 0) + return -1; + + if (dev->riops && + virCgroupSetupBlkioDeviceReadIops(cgroup, dev->path, + &dev->riops) < 0) + return -1; + + if (dev->wiops && + virCgroupSetupBlkioDeviceWriteIops(cgroup, dev->path, + &dev->wiops) < 0) + return -1; + + if (dev->rbps && + virCgroupSetupBlkioDeviceReadBps(cgroup, dev->path, + &dev->rbps) < 0) + return -1; + + if (dev->wbps && + virCgroupSetupBlkioDeviceWriteBps(cgroup, dev->path, + &dev->wbps) < 0) + return -1; + } + } + + return 0; +} diff --git a/src/hypervisor/domain_cgroup.h b/src/hypervisor/domain_cgroup.h new file mode 100644 index 0000000000..af244bd2d2 --- /dev/null +++ b/src/hypervisor/domain_cgroup.h @@ -0,0 +1,27 @@ +/* + * domain_cgroup.h: cgroup 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 "vircgroup.h" +#include "domain_conf.h" + + +int virDomainCgroupSetupBlkio(virCgroupPtr cgroup, virDomainBlkiotune blki= o); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 2bbfa4bd9d..dc06b1ae24 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1389,6 +1389,10 @@ virSetConnectSecret; virSetConnectStorage; =20 =20 +# hypervisor/domain_cgroup.h +virDomainCgroupSetupBlkio; + + # libvirt_internal.h virConnectSupportsFeature; virDomainMigrateBegin3; diff --git a/src/lxc/Makefile.inc.am b/src/lxc/Makefile.inc.am index f69c1acff5..2fee607d3d 100644 --- a/src/lxc/Makefile.inc.am +++ b/src/lxc/Makefile.inc.am @@ -97,6 +97,7 @@ libvirt_driver_lxc_impl_la_CFLAGS =3D \ -I$(srcdir)/conf \ -I$(builddir)/lxc \ -I$(builddir)/rpc \ + -I$(srcdir)/hypervisor \ $(AM_CFLAGS) \ $(NULL) libvirt_driver_lxc_impl_la_LIBADD =3D \ @@ -221,6 +222,7 @@ libvirt_lxc_CFLAGS =3D \ -I$(srcdir)/conf \ -I$(builddir)/lxc \ -I$(builddir)/rpc \ + -I$(srcdir)/hypervisor \ $(AM_CFLAGS) \ $(PIE_CFLAGS) \ $(CAPNG_CFLAGS) \ diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 3c7e31c36b..96a89256a1 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -23,6 +23,7 @@ =20 #include "lxc_cgroup.h" #include "lxc_container.h" +#include "domain_cgroup.h" #include "virfile.h" #include "virerror.h" #include "virlog.h" @@ -101,44 +102,7 @@ static int virLXCCgroupSetupCpusetTune(virDomainDefPtr= def, static int virLXCCgroupSetupBlkioTune(virDomainDefPtr def, virCgroupPtr cgroup) { - size_t i; - - if (def->blkio.weight && - virCgroupSetBlkioWeight(cgroup, def->blkio.weight) < 0) - return -1; - - if (def->blkio.ndevices) { - for (i =3D 0; i < def->blkio.ndevices; i++) { - virBlkioDevicePtr dev =3D &def->blkio.devices[i]; - - if (dev->weight && - virCgroupSetupBlkioDeviceWeight(cgroup, dev->path, - &dev->weight) < 0) - return -1; - - if (dev->riops && - virCgroupSetupBlkioDeviceReadIops(cgroup, dev->path, - &dev->riops) < 0) - return -1; - - if (dev->wiops && - virCgroupSetupBlkioDeviceWriteIops(cgroup, dev->path, - &dev->wiops) < 0) - return -1; - - if (dev->rbps && - virCgroupSetupBlkioDeviceReadBps(cgroup, dev->path, - &dev->rbps) < 0) - return -1; - - if (dev->wbps && - virCgroupSetupBlkioDeviceWriteBps(cgroup, dev->path, - &dev->wbps) < 0) - return -1; - } - } - - return 0; + return virDomainCgroupSetupBlkio(cgroup, def->blkio); } =20 =20 diff --git a/src/qemu/Makefile.inc.am b/src/qemu/Makefile.inc.am index b9c0c6ea9c..94a333f855 100644 --- a/src/qemu/Makefile.inc.am +++ b/src/qemu/Makefile.inc.am @@ -98,6 +98,7 @@ libvirt_driver_qemu_impl_la_CFLAGS =3D \ -I$(builddir)/access \ -I$(srcdir)/conf \ -I$(srcdir)/secret \ + -I$(srcdir)/hypervisor \ $(AM_CFLAGS) \ $(NULL) libvirt_driver_qemu_impl_la_LDFLAGS =3D $(AM_LDFLAGS) diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index da96a60a08..475c063823 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -30,6 +30,7 @@ #include "viralloc.h" #include "virerror.h" #include "domain_audit.h" +#include "domain_cgroup.h" #include "virscsi.h" #include "virstring.h" #include "virfile.h" @@ -591,7 +592,6 @@ static int qemuSetupBlkioCgroup(virDomainObjPtr vm) { qemuDomainObjPrivatePtr priv =3D vm->privateData; - size_t i; =20 if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_BLKIO)) { @@ -604,43 +604,7 @@ qemuSetupBlkioCgroup(virDomainObjPtr vm) } } =20 - if (vm->def->blkio.weight !=3D 0 && - virCgroupSetBlkioWeight(priv->cgroup, vm->def->blkio.weight) < 0) - return -1; - - if (vm->def->blkio.ndevices) { - for (i =3D 0; i < vm->def->blkio.ndevices; i++) { - virBlkioDevicePtr dev =3D &vm->def->blkio.devices[i]; - virCgroupPtr cgroup =3D priv->cgroup; - - if (dev->weight && - virCgroupSetupBlkioDeviceWeight(cgroup, dev->path, - &dev->weight) < 0) - return -1; - - if (dev->riops && - virCgroupSetupBlkioDeviceReadIops(cgroup, dev->path, - &dev->riops) < 0) - return -1; - - if (dev->wiops && - virCgroupSetupBlkioDeviceWriteIops(cgroup, dev->path, - &dev->wiops) < 0) - return -1; - - if (dev->rbps && - virCgroupSetupBlkioDeviceReadBps(cgroup, dev->path, - &dev->rbps) < 0) - return -1; - - if (dev->wbps && - virCgroupSetupBlkioDeviceWriteBps(cgroup, dev->path, - &dev->wbps) < 0) - return -1; - } - } - - return 0; + return virDomainCgroupSetupBlkio(priv->cgroup, vm->def->blkio); } =20 =20 --=20 2.24.1