From nobody Fri Mar 29 06:30:50 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 1581372359687950.4416242064286; Mon, 10 Feb 2020 14:05:59 -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-39-LtjWR2pCOqS33G7iWL53yA-1; Mon, 10 Feb 2020 17:05:55 -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 80D898C8943; Mon, 10 Feb 2020 22:05:47 +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 50BB190066; Mon, 10 Feb 2020 22:05:47 +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 BA9E5866D7; Mon, 10 Feb 2020 22:05:45 +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 01AM5gkT010991 for ; Mon, 10 Feb 2020 17:05:42 -0500 Received: by smtp.corp.redhat.com (Postfix) id C666BB3516; Mon, 10 Feb 2020 22:05:42 +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 C1FA0178B1 for ; Mon, 10 Feb 2020 22:05:42 +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 A43BE90085B for ; Mon, 10 Feb 2020 22:05:42 +0000 (UTC) Received: from mail-qv1-f67.google.com (mail-qv1-f67.google.com [209.85.219.67]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-372-vx5F3oYkMCaHyt47P_iyVA-1; Mon, 10 Feb 2020 17:05:36 -0500 Received: by mail-qv1-f67.google.com with SMTP id o18so4024938qvf.1; Mon, 10 Feb 2020 14:05:36 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:3c07:1c6d:d4f2:46f3:c31d]) by smtp.gmail.com with ESMTPSA id z5sm970908qta.7.2020.02.10.14.05.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2020 14:05:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581372358; 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=SjDGofDrSpEfm92t80v7L/h5qG6TMCj6He2ai1UFJTA=; b=CiPkysVj53rIkhI3LPXe1V5CRmMuf6yynNODj/eJ92D7ucLx/oZUvYMLHPOIOd8fayjQCn bxYzYkdenrOMOhxsdh+mHCHtieVjLFlK+/kVOzJlnU2YqcTp4OUb2OQ6GkAM2TgCD7rZMc 0wrYCj1Vp1Co+a0vIfj8KrIZxrmx11I= 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=XuZ3SYa3wcwPCr8iu5boReJgUnfrmIc0Xj7SEO4UWWM=; b=M3wu870kAwgEwvKRzuSdL95oLGb4md/vbA0ZpC0E6HrYLZO1tvjIAmHtypqwO7tDe1 aGML3D1UJe0uek+V0ILyrEG5CWRj1Rf2tOnK+i5bf8kE+Y+WUDg3xLGpwAW1LyyYceXK lSoBFbX91HG8TMPu7pjIg7cco3mHhK9/Mcc76NXQnygbYzQtCohm22rup5PgV4Kb3YzX 2JfxWb0qMgQwynOoqM46Khk8cu6leOYeUYoeyBwwM2fA3VGA08MZIaCnFCqr51Y2Sv5j w4/KxOnRN8rYXX5bM9p+g70t1vMpDldheIvBQPHbDKBDlzIZE81gsM74itPd2umWSIYa P3cw== X-Gm-Message-State: APjAAAUeK7VFLm99RkdFRKeIOnTMgpk3u7pIPlwlqb4Y5LfC5oRzsEk+ XsOrBhyh4qUfDfioH5YtWlsqqWPC51c= X-Google-Smtp-Source: APXvYqxMN7vr3GpRyW1dwBpjAijmkDFlYI+jWNtJ+uF5tOfeAXYupQ/ZRC/Iwx8XAi7Jtrw5jMb9WQ== X-Received: by 2002:a05:6214:1907:: with SMTP id er7mr12104844qvb.199.1581372335989; Mon, 10 Feb 2020 14:05:35 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v1 01/14] vircgroup: add virCgroupSetupBlkioTune() Date: Mon, 10 Feb 2020 19:05:07 -0300 Message-Id: <20200210220520.817666-2-danielhb413@gmail.com> In-Reply-To: <20200210220520.817666-1-danielhb413@gmail.com> References: <20200210220520.817666-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: vx5F3oYkMCaHyt47P_iyVA-1 X-MC-Unique: LtjWR2pCOqS33G7iWL53yA-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 01AM5gkT010991 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , 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" This new util function puts the duplicated code from qemu_cgroup.c:qemuSetupBlkioCgroup() and lxc_cgroup.c:virLXCCgroupSetupBlkioTune() in a single function to be used in both places. Signed-off-by: Daniel Henrique Barboza --- src/libvirt_private.syms | 1 + src/lxc/lxc_cgroup.c | 49 +---------------------------------- src/qemu/qemu_cgroup.c | 47 +--------------------------------- src/util/vircgroup.c | 55 ++++++++++++++++++++++++++++++++++++++++ src/util/vircgroup.h | 3 +++ 5 files changed, 61 insertions(+), 94 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index dc0449d1d8..64163a5e56 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1728,6 +1728,7 @@ virCgroupSetMemoryHardLimit; virCgroupSetMemorySoftLimit; virCgroupSetMemSwapHardLimit; virCgroupSetOwner; +virCgroupSetupBlkioTune; virCgroupSupportsCpuBW; virCgroupTerminateMachine; =20 diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 7f3701593a..96d43b06f2 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -101,54 +101,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 && - (virCgroupSetBlkioDeviceWeight(cgroup, dev->path, - dev->weight) < 0 || - virCgroupGetBlkioDeviceWeight(cgroup, dev->path, - &dev->weight) < 0)) - return -1; - - if (dev->riops && - (virCgroupSetBlkioDeviceReadIops(cgroup, dev->path, - dev->riops) < 0 || - virCgroupGetBlkioDeviceReadIops(cgroup, dev->path, - &dev->riops) < 0)) - return -1; - - if (dev->wiops && - (virCgroupSetBlkioDeviceWriteIops(cgroup, dev->path, - dev->wiops) < 0 || - virCgroupGetBlkioDeviceWriteIops(cgroup, dev->path, - &dev->wiops) < 0)) - return -1; - - if (dev->rbps && - (virCgroupSetBlkioDeviceReadBps(cgroup, dev->path, - dev->rbps) < 0 || - virCgroupGetBlkioDeviceReadBps(cgroup, dev->path, - &dev->rbps) < 0)) - return -1; - - if (dev->wbps && - (virCgroupSetBlkioDeviceWriteBps(cgroup, dev->path, - dev->wbps) < 0 || - virCgroupGetBlkioDeviceWriteBps(cgroup, dev->path, - &dev->wbps) < 0)) - return -1; - } - } - - return 0; + return virCgroupSetupBlkioTune(cgroup, def->blkio); } =20 =20 diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 45701b4c6e..a5eaa24d90 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -591,7 +591,6 @@ static int qemuSetupBlkioCgroup(virDomainObjPtr vm) { qemuDomainObjPrivatePtr priv =3D vm->privateData; - size_t i; =20 if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_BLKIO)) { @@ -604,51 +603,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]; - if (dev->weight && - (virCgroupSetBlkioDeviceWeight(priv->cgroup, dev->path, - dev->weight) < 0 || - virCgroupGetBlkioDeviceWeight(priv->cgroup, dev->path, - &dev->weight) < 0)) - return -1; - - if (dev->riops && - (virCgroupSetBlkioDeviceReadIops(priv->cgroup, dev->path, - dev->riops) < 0 || - virCgroupGetBlkioDeviceReadIops(priv->cgroup, dev->path, - &dev->riops) < 0)) - return -1; - - if (dev->wiops && - (virCgroupSetBlkioDeviceWriteIops(priv->cgroup, dev->path, - dev->wiops) < 0 || - virCgroupGetBlkioDeviceWriteIops(priv->cgroup, dev->path, - &dev->wiops) < 0)) - return -1; - - if (dev->rbps && - (virCgroupSetBlkioDeviceReadBps(priv->cgroup, dev->path, - dev->rbps) < 0 || - virCgroupGetBlkioDeviceReadBps(priv->cgroup, dev->path, - &dev->rbps) < 0)) - return -1; - - if (dev->wbps && - (virCgroupSetBlkioDeviceWriteBps(priv->cgroup, dev->path, - dev->wbps) < 0 || - virCgroupGetBlkioDeviceWriteBps(priv->cgroup, dev->path, - &dev->wbps) < 0)) - return -1; - } - } - - return 0; + return virCgroupSetupBlkioTune(priv->cgroup, vm->def->blkio); } =20 =20 diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 0680ff7c24..0d83e2094f 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -35,6 +35,7 @@ #define LIBVIRT_VIRCGROUPPRIV_H_ALLOW #include "vircgrouppriv.h" =20 +#include "conf/domain_conf.h" #include "virutil.h" #include "viralloc.h" #include "vircgroupbackend.h" @@ -3581,3 +3582,57 @@ virCgroupDelThread(virCgroupPtr cgroup, =20 return 0; } + + +int +virCgroupSetupBlkioTune(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 !=3D 0 && + (virCgroupSetBlkioDeviceWeight(cgroup, dev->path, + dev->weight) < 0 || + virCgroupGetBlkioDeviceWeight(cgroup, dev->path, + &dev->weight) < 0)) + return -1; + + if (dev->riops !=3D 0 && + (virCgroupSetBlkioDeviceReadIops(cgroup, dev->path, + dev->riops) < 0 || + virCgroupGetBlkioDeviceReadIops(cgroup, dev->path, + &dev->riops) < 0)) + return -1; + + if (dev->wiops !=3D 0 && + (virCgroupSetBlkioDeviceWriteIops(cgroup, dev->path, + dev->wiops) < 0 || + virCgroupGetBlkioDeviceWriteIops(cgroup, dev->path, + &dev->wiops) < 0)) + return -1; + + if (dev->rbps !=3D 0 && + (virCgroupSetBlkioDeviceReadBps(cgroup, dev->path, + dev->rbps) < 0 || + virCgroupGetBlkioDeviceReadBps(cgroup, dev->path, + &dev->rbps) < 0)) + return -1; + + if (dev->wbps !=3D 0 && + (virCgroupSetBlkioDeviceWriteBps(cgroup, dev->path, + dev->wbps) < 0 || + virCgroupGetBlkioDeviceWriteBps(cgroup, dev->path, + &dev->wbps) < 0)) + return -1; + } + } + + return 0; +} diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 15263f534a..d2d7e7ab51 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -24,6 +24,7 @@ #include "virutil.h" #include "virbitmap.h" #include "virenum.h" +#include "conf/virconftypes.h" =20 struct _virCgroup; typedef struct _virCgroup virCgroup; @@ -285,3 +286,5 @@ int virCgroupSetOwner(virCgroupPtr cgroup, int virCgroupHasEmptyTasks(virCgroupPtr cgroup, int controller); =20 bool virCgroupControllerAvailable(int controller); + +int virCgroupSetupBlkioTune(virCgroupPtr cgroup, virDomainBlkiotune blkio); --=20 2.24.1 From nobody Fri Mar 29 06:30:50 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-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1581372648510634.5243741596387; Mon, 10 Feb 2020 14:10:48 -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-413-mwJKRthIOvGQzPZr_W_C_g-1; Mon, 10 Feb 2020 17:10:39 -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 D6AA9DBA8; Mon, 10 Feb 2020 22:10:32 +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 ACDAF5C119; Mon, 10 Feb 2020 22:10:32 +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 66103866D8; Mon, 10 Feb 2020 22:10:32 +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 01AM5jeu011018 for ; Mon, 10 Feb 2020 17:05:45 -0500 Received: by smtp.corp.redhat.com (Postfix) id B896D2166B2B; Mon, 10 Feb 2020 22:05:45 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B2EB22166B27 for ; Mon, 10 Feb 2020 22:05: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 D0B238EB465 for ; Mon, 10 Feb 2020 22:05:40 +0000 (UTC) Received: from mail-qv1-f68.google.com (mail-qv1-f68.google.com [209.85.219.68]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-140-uFuCdMOyOP-_F6dORzTzeA-1; Mon, 10 Feb 2020 17:05:38 -0500 Received: by mail-qv1-f68.google.com with SMTP id p2so4001746qvo.10; Mon, 10 Feb 2020 14:05:37 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:3c07:1c6d:d4f2:46f3:c31d]) by smtp.gmail.com with ESMTPSA id z5sm970908qta.7.2020.02.10.14.05.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2020 14:05:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581372647; 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=ncGvNfpMUgEFF081hzcvj/Tr/Vqjr1Dd0manAb/cAlU=; b=A+JP46tCSIh1UYqAtVeEWei1XwxVLU9YmD+Sz0xwAZpJlIKNW02fHggt2kXmfn1oP9RunH xOJ1eE/mnJD/ZWMIKP4Cr8/J6bJAYQd1juDdNbGhSSGAlsy4StvO4F/d5plpnGGBucvVes UUTj1DoVv2Wkarc9KFKO20jJqWjobc0= 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=3RskJQD5JMhmTsMXL1JeanG0pds2LCrCUhXNBUhM3yM=; b=NnYP9KK4dqisg7xQLwRHfZRA/w38yubRpy0oMl5EQV54R0EKMYreyq91LsEDbwFvbZ /rtAHHlGar4gpdpFJxnGyiVqRJ8E/2AXofHbJgilDXnrvo/unLrWKdtx8umdOLUXGoVG P/AeMCvE9QXtqvwOLZSX6x7QZxO0dxWLXFG7kiV0PowrxvMu+d8F66vUImJPKlIj0ZKZ pvwoebSJ1JLc4WKKSYRhLqTt81a1UIrDYU5Eo6tnUqR5epq/qQ2pzcNveHSNKkZNHT74 JHgp6WT7Wmp7M5/Sp9jfJtOee/xQfAWRWkMfyXYjz5yL64I+vLc+UM3svxd/MdUcJKVd WSEw== X-Gm-Message-State: APjAAAVzRTrtyAXmAXvj4BhQ7tQqdQiVg4Dzbwh4bHws3LEbDyYEOemk rINkK4MzK6U23pnwJQLtOqoO4euSPOk= X-Google-Smtp-Source: APXvYqxbXiuK8WXwy+UyZWY9O+Bo5A+KwqREQosIp3jjKRRLFppc5Nzkhcg/Z2JbT7MH/c6Ropx6kg== X-Received: by 2002:ad4:446b:: with SMTP id s11mr45774qvt.148.1581372337423; Mon, 10 Feb 2020 14:05:37 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v1 02/14] vircgroup: add virCgroupSetupMemtune() Date: Mon, 10 Feb 2020 19:05:08 -0300 Message-Id: <20200210220520.817666-3-danielhb413@gmail.com> In-Reply-To: <20200210220520.817666-1-danielhb413@gmail.com> References: <20200210220520.817666-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: uFuCdMOyOP-_F6dORzTzeA-1 X-MC-Unique: mwJKRthIOvGQzPZr_W_C_g-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 01AM5jeu011018 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , 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" virLXCCgroupSetupMemTune() and qemuSetupMemoryCgroup() shares duplicated code that can be put in a new helper to avoid code repetition. Signed-off-by: Daniel Henrique Barboza --- src/libvirt_private.syms | 1 + src/lxc/lxc_cgroup.c | 14 +------------- src/qemu/qemu_cgroup.c | 14 +------------- src/util/vircgroup.c | 19 +++++++++++++++++++ src/util/vircgroup.h | 1 + 5 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 64163a5e56..075bb8b3a1 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1729,6 +1729,7 @@ virCgroupSetMemorySoftLimit; virCgroupSetMemSwapHardLimit; virCgroupSetOwner; virCgroupSetupBlkioTune; +virCgroupSetupMemtune; virCgroupSupportsCpuBW; virCgroupTerminateMachine; =20 diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 96d43b06f2..b156a3273a 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -111,19 +111,7 @@ static int virLXCCgroupSetupMemTune(virDomainDefPtr de= f, if (virCgroupSetMemory(cgroup, virDomainDefGetMemoryInitial(def)) < 0) return -1; =20 - if (virMemoryLimitIsSet(def->mem.hard_limit)) - if (virCgroupSetMemoryHardLimit(cgroup, def->mem.hard_limit) < 0) - return -1; - - if (virMemoryLimitIsSet(def->mem.soft_limit)) - if (virCgroupSetMemorySoftLimit(cgroup, def->mem.soft_limit) < 0) - return -1; - - if (virMemoryLimitIsSet(def->mem.swap_hard_limit)) - if (virCgroupSetMemSwapHardLimit(cgroup, def->mem.swap_hard_limit)= < 0) - return -1; - - return 0; + return virCgroupSetupMemtune(cgroup, def->mem); } =20 =20 diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index a5eaa24d90..0b78cebd34 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -624,19 +624,7 @@ qemuSetupMemoryCgroup(virDomainObjPtr vm) } } =20 - if (virMemoryLimitIsSet(vm->def->mem.hard_limit)) - if (virCgroupSetMemoryHardLimit(priv->cgroup, vm->def->mem.hard_li= mit) < 0) - return -1; - - if (virMemoryLimitIsSet(vm->def->mem.soft_limit)) - if (virCgroupSetMemorySoftLimit(priv->cgroup, vm->def->mem.soft_li= mit) < 0) - return -1; - - if (virMemoryLimitIsSet(vm->def->mem.swap_hard_limit)) - if (virCgroupSetMemSwapHardLimit(priv->cgroup, vm->def->mem.swap_h= ard_limit) < 0) - return -1; - - return 0; + return virCgroupSetupMemtune(priv->cgroup, vm->def->mem); } =20 =20 diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 0d83e2094f..814c954284 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -3636,3 +3636,22 @@ virCgroupSetupBlkioTune(virCgroupPtr cgroup, virDoma= inBlkiotune blkio) =20 return 0; } + + +int +virCgroupSetupMemtune(virCgroupPtr cgroup, virDomainMemtune mem) +{ + if (virMemoryLimitIsSet(mem.hard_limit)) + if (virCgroupSetMemoryHardLimit(cgroup, mem.hard_limit) < 0) + return -1; + + if (virMemoryLimitIsSet(mem.soft_limit)) + if (virCgroupSetMemorySoftLimit(cgroup, mem.soft_limit) < 0) + return -1; + + if (virMemoryLimitIsSet(mem.swap_hard_limit)) + if (virCgroupSetMemSwapHardLimit(cgroup, mem.swap_hard_limit) < 0) + return -1; + + return 0; +} diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index d2d7e7ab51..3cb9bc24f9 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -288,3 +288,4 @@ int virCgroupHasEmptyTasks(virCgroupPtr cgroup, int con= troller); bool virCgroupControllerAvailable(int controller); =20 int virCgroupSetupBlkioTune(virCgroupPtr cgroup, virDomainBlkiotune blkio); +int virCgroupSetupMemtune(virCgroupPtr cgroup, virDomainMemtune mem); --=20 2.24.1 From nobody Fri Mar 29 06:30:50 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 1581372632876933.6661366899584; Mon, 10 Feb 2020 14:10:32 -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-177-aLvfgdB3MEuQrp8LivpO0g-1; Mon, 10 Feb 2020 17:10:29 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 286048C8943; Mon, 10 Feb 2020 22:10:24 +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 00D7289F2C; Mon, 10 Feb 2020 22:10:24 +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 B0A87866D6; Mon, 10 Feb 2020 22:10:23 +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 01AM5gf0010983 for ; Mon, 10 Feb 2020 17:05:42 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0C9D9AF99E; Mon, 10 Feb 2020 22:05:42 +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 0898C178B1 for ; Mon, 10 Feb 2020 22:05:42 +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 E49B21019299 for ; Mon, 10 Feb 2020 22:05:41 +0000 (UTC) Received: from mail-qv1-f65.google.com (mail-qv1-f65.google.com [209.85.219.65]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-128-gN94gDbLPnWqi05QQxXquw-1; Mon, 10 Feb 2020 17:05:39 -0500 Received: by mail-qv1-f65.google.com with SMTP id y8so4008786qvk.6; Mon, 10 Feb 2020 14:05:39 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:3c07:1c6d:d4f2:46f3:c31d]) by smtp.gmail.com with ESMTPSA id z5sm970908qta.7.2020.02.10.14.05.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2020 14:05:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581372631; 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=sZFSUvnfISoE1WZnzvv0pCI3Y4P7PPY8MA/+yWS0wA4=; b=LycIb3YekEEenShy0A4+aORGjHFqaUlfFrcy3hvyIa24a0d6cqJhq209B7I7liZUAYPe/3 KJf3hjFOMP77xOFGV5Zq4vT3z1rpEfjGCKYt1mqUor15Rs7/n60Ys1295s7EXhA84m3ClZ BAB2YPnfQ4JwLB2IlWWY1RoPydU5pQA= 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=KI085NX4MKkqR4qQK0oUxIuNu8QPl7m3CAOHuH64VLg=; b=RqRiT2/zaxB0LguADMnYH8tZgbQyB9c4qhlO5PKPZHL/8pd7zOUHNdu2zhQnSw0Wff ZOna3HPd85hMnUQnMnkuJiuTaFmMOGnSbwF7l1fLPWzh0GNneiuMPKmmlmubzPYPWi9F oukCkY7OqKuIfyPOTVJD+xGOVpI8/bWM2i5by8cGRV9jhhjIOCkQf7L78fq75REYd/Ar gC5vfv5kzUmWrDO/5oENqdzW8px4hyPF4GGhU7FIajF7PcK4A8yZE0Oz1oNqe5oH3wCD oc1z0Xqd4olO3iKj++ayuUUSOUiPE9G3oQkLvgPXIRWGTfqY8rol39j5HHD2jY5Zbr00 vmrA== X-Gm-Message-State: APjAAAVowcggCeClBcCIig1WfEuJ5hNVAgLZDfRw6COvIEi2HbTBRdg9 J5si45oAobNO3h7AhG7LABPUXhB68QY= X-Google-Smtp-Source: APXvYqxElhpfPI4qz8Hro7O532kDiQaMqfstVe3Lact8dlmqIWeA9YfWwbXYGS+uaeX5jgU2NHKFlQ== X-Received: by 2002:ad4:4c42:: with SMTP id cs2mr37608qvb.198.1581372338769; Mon, 10 Feb 2020 14:05:38 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v1 03/14] vircgroup: add virCgroupSetupCpusetCpus() Date: Mon, 10 Feb 2020 19:05:09 -0300 Message-Id: <20200210220520.817666-4-danielhb413@gmail.com> In-Reply-To: <20200210220520.817666-1-danielhb413@gmail.com> References: <20200210220520.817666-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: gN94gDbLPnWqi05QQxXquw-1 X-MC-Unique: aLvfgdB3MEuQrp8LivpO0g-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 01AM5gf0010983 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , 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.11 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" The code from qemuSetupCgroupCpusetCpus() and virLXCCgroupSetupCpusetTune() can be centralized in a new helper called virCgroupSetupCpusetCpus(). Signed-off-by: Daniel Henrique Barboza --- src/libvirt_private.syms | 1 + src/lxc/lxc_cgroup.c | 11 +++-------- src/qemu/qemu_cgroup.c | 14 +------------- src/util/vircgroup.c | 15 +++++++++++++++ src/util/vircgroup.h | 1 + 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 075bb8b3a1..817f73fc98 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1729,6 +1729,7 @@ virCgroupSetMemorySoftLimit; virCgroupSetMemSwapHardLimit; virCgroupSetOwner; virCgroupSetupBlkioTune; +virCgroupSetupCpusetCpus; virCgroupSetupMemtune; virCgroupSupportsCpuBW; virCgroupTerminateMachine; diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index b156a3273a..3f15614c7f 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -68,14 +68,9 @@ static int virLXCCgroupSetupCpusetTune(virDomainDefPtr d= ef, virDomainNumatuneMemMode mode; =20 if (def->placement_mode !=3D VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO && - def->cpumask) { - if (!(mask =3D virBitmapFormat(def->cpumask))) - return -1; - - if (virCgroupSetCpusetCpus(cgroup, mask) < 0) - goto cleanup; - /* free mask to make sure we won't use it in a wrong way later */ - VIR_FREE(mask); + def->cpumask && + virCgroupSetupCpusetCpus(cgroup, def->cpumask) < 0) { + return -1; } =20 if (virDomainNumatuneGetMode(def->numa, -1, &mode) < 0 || diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 0b78cebd34..0181e869fe 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -1164,19 +1164,7 @@ int qemuSetupCgroupCpusetCpus(virCgroupPtr cgroup, virBitmapPtr cpumask) { - int ret =3D -1; - char *new_cpus =3D NULL; - - if (!(new_cpus =3D virBitmapFormat(cpumask))) - goto cleanup; - - if (virCgroupSetCpusetCpus(cgroup, new_cpus) < 0) - goto cleanup; - - ret =3D 0; - cleanup: - VIR_FREE(new_cpus); - return ret; + return virCgroupSetupCpusetCpus(cgroup, cpumask); } =20 =20 diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 814c954284..75037ff8dd 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -3655,3 +3655,18 @@ virCgroupSetupMemtune(virCgroupPtr cgroup, virDomain= Memtune mem) =20 return 0; } + + +int +virCgroupSetupCpusetCpus(virCgroupPtr cgroup, virBitmapPtr cpumask) +{ + g_autofree char *new_cpus =3D NULL; + + if (!(new_cpus =3D virBitmapFormat(cpumask))) + return -1; + + if (virCgroupSetCpusetCpus(cgroup, new_cpus) < 0) + return -1; + + return 0; +} diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 3cb9bc24f9..0c84bb762b 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -289,3 +289,4 @@ bool virCgroupControllerAvailable(int controller); =20 int virCgroupSetupBlkioTune(virCgroupPtr cgroup, virDomainBlkiotune blkio); int virCgroupSetupMemtune(virCgroupPtr cgroup, virDomainMemtune mem); +int virCgroupSetupCpusetCpus(virCgroupPtr cgroup, virBitmapPtr cpumask); --=20 2.24.1 From nobody Fri Mar 29 06:30:50 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 1581372637627665.0797873075974; Mon, 10 Feb 2020 14:10: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-29-BHjyxzdVMUigT2Tp1lDEHA-1; Mon, 10 Feb 2020 17:10:34 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 72020800D53; Mon, 10 Feb 2020 22:10: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 4A7FA89F2C; Mon, 10 Feb 2020 22:10: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 0A0CC180880D; Mon, 10 Feb 2020 22:10:28 +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 01AM5iaE010999 for ; Mon, 10 Feb 2020 17:05:44 -0500 Received: by smtp.corp.redhat.com (Postfix) id ECDA52166B2A; Mon, 10 Feb 2020 22:05:43 +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 E8D3D2166B27 for ; Mon, 10 Feb 2020 22:05:43 +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 CEEE4101928D for ; Mon, 10 Feb 2020 22:05:43 +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-58-IFE3OfguM4SJtKDhgmuGEw-1; Mon, 10 Feb 2020 17:05:41 -0500 Received: by mail-qk1-f196.google.com with SMTP id c188so8173213qkg.4; Mon, 10 Feb 2020 14:05:40 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:3c07:1c6d:d4f2:46f3:c31d]) by smtp.gmail.com with ESMTPSA id z5sm970908qta.7.2020.02.10.14.05.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2020 14:05:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581372636; 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=SscAXwKzYBzM3DVnIBRwLXu152kPEaght1tO9ZmhlRg=; b=CxijXWXcxcOGW6egzCz2k17rtM1g44AH4pXHggdoOYTftdAitZSCm7X17CUyLxb/nXo2Nw c3MUgp9Vq2nBh+Tuy4mlAId2UgqL9aglhGXshzwFO8162oxxmj7Qxuw1HXUnmm/bCTUkTl iNqw+cRH9NzAW85w7lj35LORZJOEAzA= 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=YMbVAt7b8UVy3tB5+NGUt1qD1RdhU2+ez/Y7mbgkXh8=; b=LtIWOLqsWEZymgDUFP5PIC86LBbewxu6etblWSgfVAaPaC6P8Oltcod5CUkMJWlgXA d1M1d+EUdD4sJCgh10Jr72+zQ99VfQqZq5GmHNl4XapWYgkNvyf4S/q+Y8WDNG6Yn+UE SIDqcRggeMLqgq6fh4dpzhlt3UnLzZ3puI0UajsbaNmyIjE1nmeS8PUVXfFtixGBBkDC hkk+Su6w46qTU32kWCKX698yvhxCr8/iE8CmREq3cprUhPaV7T123c8bWHwtR1sbERwH ugogVW4Ej6C7Ud/VzX/ywHiIym5gmAqYtNvhtY6/FPEFNG7ngwgYMPps3c3Xo3o0horM noQQ== X-Gm-Message-State: APjAAAVIsqc8XLmYeB8iLGbfLh+UXw5sHFUaKSQjRx8DTRRNufEHfRxW Ma++Q7EBOLCHUoCeCUnsaolSU/0Cj0g= X-Google-Smtp-Source: APXvYqy1zR1/B70q3vkL9hAeoJcJ6bpkpDFDuIZqT+0fIkrpk7JnEFKEGAsL6sb2/aF4Kse8GeKm6A== X-Received: by 2002:a37:ad02:: with SMTP id f2mr13232qkm.239.1581372340185; Mon, 10 Feb 2020 14:05:40 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v1 04/14] vircgroup: add virCgroupSetAndRetrieveCpuShares() Date: Mon, 10 Feb 2020 19:05:10 -0300 Message-Id: <20200210220520.817666-5-danielhb413@gmail.com> In-Reply-To: <20200210220520.817666-1-danielhb413@gmail.com> References: <20200210220520.817666-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: IFE3OfguM4SJtKDhgmuGEw-1 X-MC-Unique: BHjyxzdVMUigT2Tp1lDEHA-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 01AM5iaE010999 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , 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.11 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" The code that calls virCgroupSetCpuShares() and virCgroupGetCpuShares() is repeated in 4 different places. Let's put it in a new virCgroupSetAndRetrieveCpuShares() to avoid code repetition. There's a reason of why we execute a Get in the same value we just executed Set, explained in detail by commit 97814d8ab3. Let's add a gist of the reasoning behind it as a comment in this new function as well. Signed-off-by: Daniel Henrique Barboza --- src/libvirt_private.syms | 1 + src/lxc/lxc_cgroup.c | 6 +++--- src/lxc/lxc_driver.c | 7 +++---- src/qemu/qemu_cgroup.c | 7 ++++--- src/qemu/qemu_driver.c | 6 ++---- src/util/vircgroup.c | 21 +++++++++++++++++++++ src/util/vircgroup.h | 3 +++ 7 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 817f73fc98..6aa3f670db 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1710,6 +1710,7 @@ virCgroupNewSelf; virCgroupNewThread; virCgroupPathOfController; virCgroupRemove; +virCgroupSetAndRetrieveCpuShares; virCgroupSetBlkioDeviceReadBps; virCgroupSetBlkioDeviceReadIops; virCgroupSetBlkioDeviceWeight; diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 3f15614c7f..2ccc1ae5a1 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -39,11 +39,11 @@ static int virLXCCgroupSetupCpuTune(virDomainDefPtr def, { if (def->cputune.sharesSpecified) { unsigned long long val; - if (virCgroupSetCpuShares(cgroup, def->cputune.shares) < 0) - return -1; =20 - if (virCgroupGetCpuShares(cgroup, &val) < 0) + if (virCgroupSetAndRetrieveCpuShares(cgroup, def->cputune.shares, + &val) < 0) return -1; + def->cputune.shares =3D val; } =20 diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index f7376188f0..51f1284d56 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1959,10 +1959,9 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr do= m, if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_CPU_SHARES)) { if (def) { unsigned long long val; - if (virCgroupSetCpuShares(priv->cgroup, params[i].value.ul= ) < 0) - goto endjob; - - if (virCgroupGetCpuShares(priv->cgroup, &val) < 0) + if (virCgroupSetAndRetrieveCpuShares(priv->cgroup, + params[i].value.ul, + &val) < 0) goto endjob; =20 def->cputune.shares =3D val; diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 0181e869fe..0ca62ba3ee 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -893,11 +893,12 @@ qemuSetupCpuCgroup(virDomainObjPtr vm) =20 if (vm->def->cputune.sharesSpecified) { unsigned long long val; - if (virCgroupSetCpuShares(priv->cgroup, vm->def->cputune.shares) <= 0) - return -1; =20 - if (virCgroupGetCpuShares(priv->cgroup, &val) < 0) + if (virCgroupSetAndRetrieveCpuShares(priv->cgroup, + vm->def->cputune.shares, + &val) < 0) return -1; + if (vm->def->cputune.shares !=3D val) { vm->def->cputune.shares =3D val; if (virTypedParamsAddULLong(&eventParams, &eventNparams, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 2813f084cd..0d58893d7e 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -10667,10 +10667,8 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr= dom, if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_CPU_SHARES)) { if (def) { unsigned long long val; - if (virCgroupSetCpuShares(priv->cgroup, value_ul) < 0) - goto endjob; - - if (virCgroupGetCpuShares(priv->cgroup, &val) < 0) + if (virCgroupSetAndRetrieveCpuShares(priv->cgroup, value_u= l, + &val) < 0) goto endjob; =20 def->cputune.shares =3D val; diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 75037ff8dd..cfb34a0f0e 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -3670,3 +3670,24 @@ virCgroupSetupCpusetCpus(virCgroupPtr cgroup, virBit= mapPtr cpumask) =20 return 0; } + + +/* Per commit 97814d8ab3, the Linux kernel can consider a 'shares' + * value of '0' and '1' as 2, and any value larger than a maximum + * is reduced to maximum. + * + * The 'realValue' pointer holds the actual 'shares' value set by + * the kernel if the function returned success. */ +int +virCgroupSetAndRetrieveCpuShares(virCgroupPtr cgroup, + unsigned long long shares, + unsigned long long *realValue) +{ + if (virCgroupSetCpuShares(cgroup, shares) < 0) + return -1; + + if (virCgroupGetCpuShares(cgroup, realValue) < 0) + return -1; + + return 0; +} diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 0c84bb762b..ed8ee30a58 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -290,3 +290,6 @@ bool virCgroupControllerAvailable(int controller); int virCgroupSetupBlkioTune(virCgroupPtr cgroup, virDomainBlkiotune blkio); int virCgroupSetupMemtune(virCgroupPtr cgroup, virDomainMemtune mem); int virCgroupSetupCpusetCpus(virCgroupPtr cgroup, virBitmapPtr cpumask); +int virCgroupSetAndRetrieveCpuShares(virCgroupPtr cgroup, + unsigned long long shares, + unsigned long long *realValue); --=20 2.24.1 From nobody Fri Mar 29 06:30:50 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 1581372377337232.45012570295944; Mon, 10 Feb 2020 14:06:17 -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-42-D4xchyBcMN-CBm2ULaHz4A-1; Mon, 10 Feb 2020 17:05:52 -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 64B608017DF; Mon, 10 Feb 2020 22:05:47 +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 2E6C18ED1A; Mon, 10 Feb 2020 22:05:47 +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 D481318089CD; Mon, 10 Feb 2020 22:05:46 +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 01AM5jh1011005 for ; Mon, 10 Feb 2020 17:05:45 -0500 Received: by smtp.corp.redhat.com (Postfix) id 01FCCAF99E; Mon, 10 Feb 2020 22:05:45 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F1FB5B3516 for ; Mon, 10 Feb 2020 22:05:44 +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 D99CD802063 for ; Mon, 10 Feb 2020 22:05:44 +0000 (UTC) Received: from mail-qk1-f193.google.com (mail-qk1-f193.google.com [209.85.222.193]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-318-K3i-lp-0PkS2Z4k_gfpsMg-1; Mon, 10 Feb 2020 17:05:42 -0500 Received: by mail-qk1-f193.google.com with SMTP id v195so8152717qkb.11; Mon, 10 Feb 2020 14:05:42 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:3c07:1c6d:d4f2:46f3:c31d]) by smtp.gmail.com with ESMTPSA id z5sm970908qta.7.2020.02.10.14.05.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2020 14:05:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581372375; 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=iLpedpg7NalyqQKHaOLEiQfUO+puczPT62ZfEsrvH1g=; b=aWyQQSnf782MoKq3JKpYqGnwVLfDC4vhf9xpoV9f2Pg7AgIlW+afPJdjrqfbRhP23WvSYC p2457jsCUGrnPbLMPysC/dvFA6Owbic+oDDhyHdM6UQ6aadK0TFVMSFXdyfJGhJT5CD4T8 M9e1yP0rJpS3tWpjcXl8DnFyiMXmJ9I= 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=1KNE1roUWdJEvvlEFllBUcFcXIxDuYB9UeRuYDWdyOY=; b=EMZuDIpA4YmarxdOQIuLO5v/wNahk5CJaXmp6PtTo2AiCIMheH0TbVKTYFPzqzGCj+ QJuX8QIdFjJj8i2ixfXgRuRLLi4zGnQ8mRkypndPAfd51JUE8+lbzK8jANkhqNebK/kN FHRKdbzhgDsOW6ccKGisHqtZtk8INBbPYgh7Pv/lGXwuxOIGZzENktjkEH79inTj+RVQ KdZ8SKQN2fYResrL+ffHOLNjG7eLDTqOK7DjfkGRuLidWXfHMbERG7VJBS+raosU1NoA jnAjJxP8WlzSgbQ68M0QM3i9ZJBtOp0QY4cNwGyQOeOMaMZdB/a+JWhLfxXbqRU0t1um ojpg== X-Gm-Message-State: APjAAAViaWjX7qwkP8SNT3aUrj1FV2ZDjbuKJUz7w/q8YwfRQ4MbSd8J iuLBsEyyulAjtiMARkvOuavxSF+SoCk= X-Google-Smtp-Source: APXvYqyhdewMLT0fG3FYc5VLhuAbCW07AEMDjjRSABRKz3cMkzo0/73CR/Aerq0T395VuBIrBzVNAg== X-Received: by 2002:a05:620a:218d:: with SMTP id g13mr3499184qka.286.1581372341641; Mon, 10 Feb 2020 14:05:41 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v1 05/14] vircgroup: add virCgroupSetupCpuPeriodQuota() Date: Mon, 10 Feb 2020 19:05:11 -0300 Message-Id: <20200210220520.817666-6-danielhb413@gmail.com> In-Reply-To: <20200210220520.817666-1-danielhb413@gmail.com> References: <20200210220520.817666-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: K3i-lp-0PkS2Z4k_gfpsMg-1 X-MC-Unique: D4xchyBcMN-CBm2ULaHz4A-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 01AM5jh1011005 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , 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" qemuSetupCgroupVcpuBW() and lxcSetVcpuBWLive() shares the same code to set CPU CFS period and quota. This code can be moved to a new virCgroupSetupCpuPeriodQuota() helper to avoid code repetition. A similar code is also executed in virLXCCgroupSetupCpuTune(), but without the rollback on error. Use the new helper in this function as well since the 'period' rollback, if not a straight improvement for virLXCCgroupSetupCpuTune(), is benign. And we end up cutting more code repetition. Signed-off-by: Daniel Henrique Barboza --- src/libvirt_private.syms | 1 + src/lxc/lxc_cgroup.c | 11 ++--------- src/lxc/lxc_driver.c | 32 +------------------------------- src/qemu/qemu_cgroup.c | 31 +------------------------------ src/util/vircgroup.c | 38 ++++++++++++++++++++++++++++++++++++++ src/util/vircgroup.h | 3 +++ 6 files changed, 46 insertions(+), 70 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 6aa3f670db..38fe847cef 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1730,6 +1730,7 @@ virCgroupSetMemorySoftLimit; virCgroupSetMemSwapHardLimit; virCgroupSetOwner; virCgroupSetupBlkioTune; +virCgroupSetupCpuPeriodQuota; virCgroupSetupCpusetCpus; virCgroupSetupMemtune; virCgroupSupportsCpuBW; diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 2ccc1ae5a1..d520f9cb3b 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -47,15 +47,8 @@ static int virLXCCgroupSetupCpuTune(virDomainDefPtr def, def->cputune.shares =3D val; } =20 - if (def->cputune.quota !=3D 0 && - virCgroupSetCpuCfsQuota(cgroup, def->cputune.quota) < 0) - return -1; - - if (def->cputune.period !=3D 0 && - virCgroupSetCpuCfsPeriod(cgroup, def->cputune.period) < 0) - return -1; - - return 0; + return virCgroupSetupCpuPeriodQuota(cgroup, def->cputune.period, + def->cputune.quota); } =20 =20 diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 51f1284d56..69016881dc 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1857,37 +1857,7 @@ lxcGetVcpuBWLive(virCgroupPtr cgroup, unsigned long = long *period, static int lxcSetVcpuBWLive(virCgroupPtr cgroup, unsigned long long period, long long quota) { - unsigned long long old_period; - - if (period =3D=3D 0 && quota =3D=3D 0) - return 0; - - if (period) { - /* get old period, and we can rollback if set quota failed */ - if (virCgroupGetCpuCfsPeriod(cgroup, &old_period) < 0) - return -1; - - if (virCgroupSetCpuCfsPeriod(cgroup, period) < 0) - return -1; - } - - if (quota) { - if (virCgroupSetCpuCfsQuota(cgroup, quota) < 0) - goto error; - } - - return 0; - - error: - if (period) { - virErrorPtr saved; - - virErrorPreserveLast(&saved); - virCgroupSetCpuCfsPeriod(cgroup, old_period); - virErrorRestore(&saved); - } - - return -1; + return virCgroupSetupCpuPeriodQuota(cgroup, period, quota); } =20 =20 diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 0ca62ba3ee..636c531bd5 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -1128,36 +1128,7 @@ qemuSetupCgroupVcpuBW(virCgroupPtr cgroup, unsigned long long period, long long quota) { - unsigned long long old_period; - - if (period =3D=3D 0 && quota =3D=3D 0) - return 0; - - if (period) { - /* get old period, and we can rollback if set quota failed */ - if (virCgroupGetCpuCfsPeriod(cgroup, &old_period) < 0) - return -1; - - if (virCgroupSetCpuCfsPeriod(cgroup, period) < 0) - return -1; - } - - if (quota && - virCgroupSetCpuCfsQuota(cgroup, quota) < 0) - goto error; - - return 0; - - error: - if (period) { - virErrorPtr saved; - - virErrorPreserveLast(&saved); - ignore_value(virCgroupSetCpuCfsPeriod(cgroup, old_period)); - virErrorRestore(&saved); - } - - return -1; + return virCgroupSetupCpuPeriodQuota(cgroup, period, quota); } =20 =20 diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index cfb34a0f0e..9dc60f66c9 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -3691,3 +3691,41 @@ virCgroupSetAndRetrieveCpuShares(virCgroupPtr cgroup, =20 return 0; } + + +int +virCgroupSetupCpuPeriodQuota(virCgroupPtr cgroup, + unsigned long long period, + long long quota) +{ + unsigned long long old_period; + + if (period =3D=3D 0 && quota =3D=3D 0) + return 0; + + if (period) { + /* get old period, and we can rollback if set quota failed */ + if (virCgroupGetCpuCfsPeriod(cgroup, &old_period) < 0) + return -1; + + if (virCgroupSetCpuCfsPeriod(cgroup, period) < 0) + return -1; + } + + if (quota && + virCgroupSetCpuCfsQuota(cgroup, quota) < 0) + goto error; + + return 0; + + error: + if (period) { + virErrorPtr saved; + + virErrorPreserveLast(&saved); + ignore_value(virCgroupSetCpuCfsPeriod(cgroup, old_period)); + virErrorRestore(&saved); + } + + return -1; +} diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index ed8ee30a58..97ffa3f7df 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -293,3 +293,6 @@ int virCgroupSetupCpusetCpus(virCgroupPtr cgroup, virBi= tmapPtr cpumask); int virCgroupSetAndRetrieveCpuShares(virCgroupPtr cgroup, unsigned long long shares, unsigned long long *realValue); +int virCgroupSetupCpuPeriodQuota(virCgroupPtr cgroup, + unsigned long long period, + long long quota); --=20 2.24.1 From nobody Fri Mar 29 06:30:50 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 1581372519067910.5496136814728; Mon, 10 Feb 2020 14:08:39 -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-104--mV9SwD9OTyaJvIYfFnM0Q-1; Mon, 10 Feb 2020 17:08:34 -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 E1D8C800D48; Mon, 10 Feb 2020 22:08:29 +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 B248060C63; Mon, 10 Feb 2020 22:08:29 +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 5C298866D6; Mon, 10 Feb 2020 22:08:29 +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 01AM5old011043 for ; Mon, 10 Feb 2020 17:05:50 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6B79E2063209; Mon, 10 Feb 2020 22:05:50 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 65FDB2026D67 for ; Mon, 10 Feb 2020 22:05:48 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.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 5AD5E80066D for ; Mon, 10 Feb 2020 22:05:48 +0000 (UTC) Received: from mail-qv1-f67.google.com (mail-qv1-f67.google.com [209.85.219.67]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-374-iDTqTxYNPF6CUalYF3jhQg-1; Mon, 10 Feb 2020 17:05:44 -0500 Received: by mail-qv1-f67.google.com with SMTP id y2so3991317qvu.13; Mon, 10 Feb 2020 14:05:43 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:3c07:1c6d:d4f2:46f3:c31d]) by smtp.gmail.com with ESMTPSA id z5sm970908qta.7.2020.02.10.14.05.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2020 14:05:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581372517; 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=GFV9s357o4Lf0YW3p/pakkCUZ2cEeRnduHvIsx4umo4=; b=SMZaoapsQngeD7C3YWjWK7wMy2F8MJeVXbMmPGSzhdIlalLQeWokQXIhb2e5COYTZBWdxU 2NLt/VrAfobg1XhHPF4nPNbGCluq5BcrmBsWsmH9L7sBuLHj480ro/cxszIvZmYvcCTOiD pkevIx6VGuw5vo+FG0R4uHAPpqOp8iY= 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=QLJRrI99tOdRhe7Cws0xbkRpW9R1dO/OD3XkfqP43Wg=; b=XcJPmcci6N08ogQCS2ygkeFeSGGMAnemY4fATjGLFICLFoDRSIYin3mfTCZ4Q69xDL TAGkAW5/Lk78xJtLJDLGzIN5GKDgda5fK618w803khyOG+cGlTGtyiuME4KSUGMqktDe h9oZ/BR7Ry7butZjtCenTpzpchNygwWJCjFWZfrY249swMsg1OucwXBqKhH8DbEkKqOv jDNI9flONYD3wyzlyrXFq2NWdFhJMBvhM9TrMUDqKtU09GbH1x6dlBrRlTVezu60t/NZ OmexrhyNK2MU/DWPfUwYE434x/Ki9KjyGjbmj26lLkHi+3dLicovYcAEnDDhM2/dBZmQ IB3Q== X-Gm-Message-State: APjAAAVbNAdHqeJ3xffDTbdm2Mt+2t8Vz8cHxjA1bo/Kqq6EtP1R9HXs 1CMFF4r15cPl5ItpZWlZDEbxpU3RxTA= X-Google-Smtp-Source: APXvYqyR7zaGd5+Shd/bJ7mRpEzZZOUvEzeazewafZa6QSpLfk9FfCLwbIGu+x3MCtXfftx8Wli6HQ== X-Received: by 2002:a05:6214:13a3:: with SMTP id h3mr35048qvz.212.1581372343222; Mon, 10 Feb 2020 14:05:43 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v1 06/14] domain_conf: add virDomainMergeBlkioDevice() Date: Mon, 10 Feb 2020 19:05:12 -0300 Message-Id: <20200210220520.817666-7-danielhb413@gmail.com> In-Reply-To: <20200210220520.817666-1-danielhb413@gmail.com> References: <20200210220520.817666-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: iDTqTxYNPF6CUalYF3jhQg-1 X-MC-Unique: -mV9SwD9OTyaJvIYfFnM0Q-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 01AM5old011043 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , 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" lxcDomainMergeBlkioDevice() and -qemuDomainMergeBlkioDevice() are the same functions. Put the code in a new virDomainMergeBlkioDevice() inside domain_conf.c and update both callers. This change is a preliminary step for more code reduction of cgroup related code inside lxcDomainSetBlkioParameters() and qemuDomainSetBlkioParameters(). Signed-off-by: Daniel Henrique Barboza --- src/conf/domain_conf.c | 70 +++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 6 +++ src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 72 +----------------------------------- src/qemu/qemu_driver.c | 80 +++------------------------------------- 5 files changed, 85 insertions(+), 144 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index de74a2a2d5..88bcf1b64b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1625,6 +1625,76 @@ virDomainBlkioDeviceParseXML(xmlNodePtr root, } =20 =20 +/* 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; +} + + /** * virDomainDefCheckUnsupportedMemoryHotplug: * @def: domain definition diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 2db3c19473..460aad9278 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2209,6 +2209,12 @@ struct _virDomainPanicDef { void virBlkioDeviceArrayClear(virBlkioDevicePtr deviceWeights, int ndevices); =20 +int virDomainMergeBlkioDevice(virBlkioDevicePtr *dest_array, + size_t *dest_size, + virBlkioDevicePtr src_array, + size_t src_size, + const char *type); + struct _virDomainResourceDef { char *partition; }; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 38fe847cef..70e45f1e8a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -491,6 +491,7 @@ virDomainMemoryModelTypeToString; virDomainMemoryRemove; virDomainMemorySourceTypeFromString; virDomainMemorySourceTypeToString; +virDomainMergeBlkioDevice; virDomainNetAllocateActualDevice; virDomainNetAppendIPAddress; virDomainNetARPInterfaces; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 69016881dc..e42fd99c72 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2215,74 +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; -} - =20 static int lxcDomainBlockStats(virDomainPtr dom, @@ -2633,7 +2565,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, } =20 if (j !=3D ndevices || - lxcDomainMergeBlkioDevice(&def->blkio.devices, + virDomainMergeBlkioDevice(&def->blkio.devices, &def->blkio.ndevices, devices, ndevices, param->fi= eld) < 0) ret =3D -1; @@ -2665,7 +2597,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 0d58893d7e..509a57b01c 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9419,74 +9419,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, @@ -9647,9 +9579,9 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, } =20 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); @@ -9682,9 +9614,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); --=20 2.24.1 From nobody Fri Mar 29 06:30:50 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-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1581372538505621.4423163735122; Mon, 10 Feb 2020 14:08:58 -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-61-7qqDjdsWO_6EjHZCLxjzkQ-1; Mon, 10 Feb 2020 17:08:54 -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 E2CFE801F77; Mon, 10 Feb 2020 22:08:48 +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 B66135C101; Mon, 10 Feb 2020 22:08:48 +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 721B318089D5; Mon, 10 Feb 2020 22:08:48 +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 01AM5w7c011095 for ; Mon, 10 Feb 2020 17:05:59 -0500 Received: by smtp.corp.redhat.com (Postfix) id D03E0C124E; Mon, 10 Feb 2020 22:05:58 +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 CB67CB351E for ; Mon, 10 Feb 2020 22:05:58 +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 5FEB8185AB94 for ; Mon, 10 Feb 2020 22:05:58 +0000 (UTC) Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-218-SB_to8o9M2u_x4sSp6q9bg-1; Mon, 10 Feb 2020 17:05:55 -0500 Received: by mail-qk1-f180.google.com with SMTP id b7so8190737qkl.7; Mon, 10 Feb 2020 14:05:45 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:3c07:1c6d:d4f2:46f3:c31d]) by smtp.gmail.com with ESMTPSA id z5sm970908qta.7.2020.02.10.14.05.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2020 14:05:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581372537; 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=gOf0x7feaJvN+V1sFAh/6KxNikUgRsH6608einbVpOA=; b=KtmJ4xwKKysUYzf8jmwgK+bNJvGH7oJ7AVOLSHjdTqhsQZUGRLjdyoPKEJnAT5yeno6x5m 5jC2M/OfQZPchD3MyG0VmI+Tm1Xk+ajjAoW/eOPdrx1IbSbA0QOUodLpwRPcLDlVeqrZkB 7EGh8yH7yXUhbc6gUWcIaLJvSUiTCEY= 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=Vbb6RTAOfimOgnRQpekCNFkiAHFhTFrmSX8GFe82jqM=; b=CzEVnjXGec84+SZlu8xjv9zr23/tIAxlEMgPPglSB9vHKONbGdM0JhEBhJYfqBivMT fgTuBix8BRGqKgnDENGpsVa4kRxwnwaM5LTfvEHzjtC8SNq78+lD6pAh9SPZz2eVX6pT JTx8yPL1NfLJ7cFJPgnolsBAY9yo8UdkhpiuIqa+dDdxSppm3Vme/ANkxGZ2GRFo7hqs V/84g7+AEfnjt9ZaDWuwazrL1QeGfarU2A3oZkJRw4f4crn46zylLWWKFs28LB459ede 2gC+I4x8TBSZUa+QlU+8LE/HZ+CtTe706HMu162Z9bLi4Y7c4DwIrI1QSi7aZOez8jSI +F9g== X-Gm-Message-State: APjAAAWAOCGMosjEmUSFc+8ixwWJNX369Bw5GUvsQ46ZtWRWBfFaZ21c /AtA9UX34Tgs7s2gn+gcTbmOgV5uugE= X-Google-Smtp-Source: APXvYqyi30Asy+wKbU26SObN4N0qJt78ntrTbeWmAOFzj1GBnKvNLaAbf9Sov42RBtd9Jh1xbJBROw== X-Received: by 2002:a37:742:: with SMTP id 63mr3479817qkh.31.1581372344987; Mon, 10 Feb 2020 14:05:44 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v1 07/14] domain_conf: add virDomainParseBlkioDeviceStr() Date: Mon, 10 Feb 2020 19:05:13 -0300 Message-Id: <20200210220520.817666-8-danielhb413@gmail.com> In-Reply-To: <20200210220520.817666-1-danielhb413@gmail.com> References: <20200210220520.817666-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: SB_to8o9M2u_x4sSp6q9bg-1 X-MC-Unique: 7qqDjdsWO_6EjHZCLxjzkQ-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 01AM5w7c011095 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , 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" lxcDomainParseBlkioDeviceStr() and qemuDomainParseBlkioDeviceStr() are the same function. Avoid code repetition by putting the code in a new helper. Signed-off-by: Daniel Henrique Barboza --- src/conf/domain_conf.c | 111 ++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 3 + src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 111 +--------------------------------- src/qemu/qemu_driver.c | 126 +++------------------------------------ 5 files changed, 125 insertions(+), 227 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 88bcf1b64b..df8a71290d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1695,6 +1695,117 @@ virDomainMergeBlkioDevice(virBlkioDevicePtr *dest_a= rray, } =20 =20 +/* 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; + + result[i].path =3D g_strndup(temp, p - temp); + + /* 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; +} + + /** * virDomainDefCheckUnsupportedMemoryHotplug: * @def: domain definition diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 460aad9278..e1daf26e07 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2215,6 +2215,9 @@ int virDomainMergeBlkioDevice(virBlkioDevicePtr *dest= _array, size_t src_size, const char *type); =20 +int virDomainParseBlkioDeviceStr(char *blkioDeviceStr, const char *type, + virBlkioDevicePtr *dev, size_t *size); + struct _virDomainResourceDef { char *partition; }; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 70e45f1e8a..d483b75aeb 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -563,6 +563,7 @@ virDomainOsDefFirmwareTypeFromString; virDomainOsDefFirmwareTypeToString; virDomainOSTypeFromString; virDomainOSTypeToString; +virDomainParseBlkioDeviceStr; virDomainParseMemory; virDomainPausedReasonTypeFromString; virDomainPausedReasonTypeToString; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index e42fd99c72..96e61ff4ca 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2108,113 +2108,6 @@ lxcDomainGetSchedulerParameters(virDomainPtr domain, return lxcDomainGetSchedulerParametersFlags(domain, params, nparams, 0= ); } =20 -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; - - result[i].path =3D g_strndup(temp, p - temp); - - /* 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; -} - =20 static int lxcDomainBlockStats(virDomainPtr dom, @@ -2486,7 +2379,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, virBlkioDevicePtr devices =3D NULL; size_t j; =20 - if (lxcDomainParseBlkioDeviceStr(params[i].value.s, + if (virDomainParseBlkioDeviceStr(params[i].value.s, param->field, &devices, &ndevices) < 0) { @@ -2590,7 +2483,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, virBlkioDevicePtr devices =3D NULL; size_t ndevices; =20 - 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 509a57b01c..d458b59b99 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9309,116 +9309,6 @@ static char *qemuDomainGetSchedulerType(virDomainPt= r dom, return ret; } =20 -/* 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; - - result[i].path =3D g_strndup(temp, p - temp); - - /* 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; -} - =20 static int qemuDomainSetBlkioParameters(virDomainPtr dom, @@ -9500,10 +9390,10 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, virBlkioDevicePtr devices =3D NULL; size_t j; =20 - if (qemuDomainParseBlkioDeviceStr(param->value.s, - param->field, - &devices, - &ndevices) < 0) { + if (virDomainParseBlkioDeviceStr(param->value.s, + param->field, + &devices, + &ndevices) < 0) { ret =3D -1; continue; } @@ -9607,10 +9497,10 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, virBlkioDevicePtr devices =3D NULL; size_t ndevices; =20 - if (qemuDomainParseBlkioDeviceStr(param->value.s, - param->field, - &devices, - &ndevices) < 0) { + if (virDomainParseBlkioDeviceStr(param->value.s, + param->field, + &devices, + &ndevices) < 0) { ret =3D -1; continue; } --=20 2.24.1 From nobody Fri Mar 29 06:30:50 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 1581372526189554.6914038702182; Mon, 10 Feb 2020 14:08:46 -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-333-NVnfHdQOPlSSBmawv2IelA-1; Mon, 10 Feb 2020 17:08:41 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DB1D1800D5A; Mon, 10 Feb 2020 22:08:35 +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 AA2DB10027B3; Mon, 10 Feb 2020 22:08:35 +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 6ADBE866D9; Mon, 10 Feb 2020 22:08:35 +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 01AM5pwI011050 for ; Mon, 10 Feb 2020 17:05:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id D8A3C2166B2A; Mon, 10 Feb 2020 22:05:51 +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 D410D2166B27 for ; Mon, 10 Feb 2020 22:05:51 +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 B33448001FD for ; Mon, 10 Feb 2020 22:05:51 +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-296-5vYJmcoKN6C3qHjaDtV4rw-1; Mon, 10 Feb 2020 17:05:47 -0500 Received: by mail-qk1-f196.google.com with SMTP id d11so8180100qko.8; Mon, 10 Feb 2020 14:05:47 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:3c07:1c6d:d4f2:46f3:c31d]) by smtp.gmail.com with ESMTPSA id z5sm970908qta.7.2020.02.10.14.05.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2020 14:05:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581372523; 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=sVR3y62PwqEBwTKsRN1XQ4XZd15J99y0sW3GZvMsDR4=; b=cDeiAqzGssAe50kPprIfNWI3XrhRG40ecgSOz3o2fYuGjWwtmVJWE8Nvj34gwG42d88MJh NFV8VuwlNN7X6viZPey47NWc9DknCh8KIgkdJA7EcAgnrFmqPCDItC/ECRXYcLk2WhpUTq x5NusjbOnCP699NQlK3WcyvgpR3tEsU= 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=3OfunP5jrGlOGTtx8wtI4cJZJk0vZV60VTt8jcNcRfM=; b=lR7UHHThxbZ51VGFARc9G52ZAAMy/T/p7j8vqaO2/q4Ee6dwX8sgz4BEEzQxbAjT9g p7MQ7ntirNh4sdH+X7TF5KfrNV/zVFThN1zmhpJCP2hiIukODzf0os3e2maHBS/U2nP+ ElcwC2t2b1pJmozhzOXgUYn0r+jYEuBr9+GUNXXLOkBaOWOvUnFri7AaEwO7GltcyhXw xhVo2UNwby/dIfrLlpbNYX2VhGUYOB3WuVar7oyIj+lLVAX20niu4aSTbcBJYRCgvu/X uP4N2TFW2GUp5udnWw32fvOOxsKBVZOniz7tPRpgPxVC30yHnyzBsOXC1iSWSgE1DWWt Ig6Q== X-Gm-Message-State: APjAAAUniS1o+sGyYps5zAcobNOYiiv9zZ8ErPOFtWpD+Z3nCDpQ34H0 G6mij4dWZzCIkq4kHLBNQIbdqPNcY1E= X-Google-Smtp-Source: APXvYqyO+Jc4Zle2ae/CiIqPcIA9kjs0OaO3K/YuFlpETQtlI6X02ErCFP3jw0bito5zOZjsE3j5dg== X-Received: by 2002:a37:8183:: with SMTP id c125mr3518110qkd.0.1581372346703; Mon, 10 Feb 2020 14:05:46 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v1 08/14] vircgroup: add virCgroupSetupDomainBlkioParameters() Date: Mon, 10 Feb 2020 19:05:14 -0300 Message-Id: <20200210220520.817666-9-danielhb413@gmail.com> In-Reply-To: <20200210220520.817666-1-danielhb413@gmail.com> References: <20200210220520.817666-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: 5vYJmcoKN6C3qHjaDtV4rw-1 X-MC-Unique: NVnfHdQOPlSSBmawv2IelA-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 01AM5pwI011050 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , 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.84 on 10.5.11.22 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 virDomainMergeBlkioDevice() 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 virCgroupSetupDomainBlkioParameters(). Signed-off-by: Daniel Henrique Barboza --- src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 104 +---------------------------------- src/qemu/qemu_driver.c | 105 +---------------------------------- src/util/vircgroup.c | 115 +++++++++++++++++++++++++++++++++++++++ src/util/vircgroup.h | 4 ++ 5 files changed, 124 insertions(+), 205 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d483b75aeb..196c7bdb23 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1734,6 +1734,7 @@ virCgroupSetOwner; virCgroupSetupBlkioTune; virCgroupSetupCpuPeriodQuota; virCgroupSetupCpusetCpus; +virCgroupSetupDomainBlkioParameters; virCgroupSetupMemtune; virCgroupSupportsCpuBW; virCgroupTerminateMachine; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 96e61ff4ca..9a585d0d07 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2364,108 +2364,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)) { - size_t ndevices; - virBlkioDevicePtr devices =3D NULL; - size_t j; - - if (virDomainParseBlkioDeviceStr(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 (virCgroupSetBlkioDeviceWeight(priv->cgroup, - devices[j].path, - devices[j].weigh= t) < 0 || - virCgroupGetBlkioDeviceWeight(priv->cgroup, - devices[j].path, - &devices[j].weig= ht) < 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 (virCgroupSetBlkioDeviceReadIops(priv->cgroup, - devices[j].pat= h, - devices[j].rio= ps) < 0 || - virCgroupGetBlkioDeviceReadIops(priv->cgroup, - devices[j].pat= h, - &devices[j].ri= ops) < 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 (virCgroupSetBlkioDeviceWriteIops(priv->cgroup, - devices[j].pa= th, - devices[j].wi= ops) < 0 || - virCgroupGetBlkioDeviceWriteIops(priv->cgroup, - devices[j].pa= th, - &devices[j].w= iops) < 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 (virCgroupSetBlkioDeviceReadBps(priv->cgroup, - devices[j].path, - devices[j].rbps= ) < 0 || - virCgroupGetBlkioDeviceReadBps(priv->cgroup, - devices[j].path, - &devices[j].rbp= s) < 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 (virCgroupSetBlkioDeviceWriteBps(priv->cgroup, - devices[j].pat= h, - devices[j].wbp= s) < 0 || - virCgroupGetBlkioDeviceWriteBps(priv->cgroup, - devices[j].pat= h, - &devices[j].wb= ps) < 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 || - virDomainMergeBlkioDevice(&def->blkio.devices, - &def->blkio.ndevices, - devices, ndevices, param->fi= eld) < 0) - ret =3D -1; - virBlkioDeviceArrayClear(devices, ndevices); - VIR_FREE(devices); - } - } + ret =3D virCgroupSetupDomainBlkioParameters(priv->cgroup, def, + params, nparams); } if (ret < 0) goto endjob; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d458b59b99..da4e6d7a93 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9374,109 +9374,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)) { - size_t ndevices; - virBlkioDevicePtr devices =3D NULL; - size_t j; - - if (virDomainParseBlkioDeviceStr(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 (virCgroupSetBlkioDeviceWeight(priv->cgroup, - devices[j].path, - devices[j].weigh= t) < 0 || - virCgroupGetBlkioDeviceWeight(priv->cgroup, - devices[j].path, - &devices[j].weig= ht) < 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 (virCgroupSetBlkioDeviceReadIops(priv->cgroup, - devices[j].pat= h, - devices[j].rio= ps) < 0 || - virCgroupGetBlkioDeviceReadIops(priv->cgroup, - devices[j].pat= h, - &devices[j].ri= ops) < 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 (virCgroupSetBlkioDeviceWriteIops(priv->cgroup, - devices[j].pa= th, - devices[j].wi= ops) < 0 || - virCgroupGetBlkioDeviceWriteIops(priv->cgroup, - devices[j].pa= th, - &devices[j].w= iops) < 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 (virCgroupSetBlkioDeviceReadBps(priv->cgroup, - devices[j].path, - devices[j].rbps= ) < 0 || - virCgroupGetBlkioDeviceReadBps(priv->cgroup, - devices[j].path, - &devices[j].rbp= s) < 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 (virCgroupSetBlkioDeviceWriteBps(priv->cgroup, - devices[j].pat= h, - devices[j].wbp= s) < 0 || - virCgroupGetBlkioDeviceWriteBps(priv->cgroup, - devices[j].pat= h, - &devices[j].wb= ps) < 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 || - virDomainMergeBlkioDevice(&def->blkio.devices, - &def->blkio.ndevices, - devices, ndevices, param->fi= eld) < 0) - ret =3D -1; - virBlkioDeviceArrayClear(devices, ndevices); - VIR_FREE(devices); - } - } + ret =3D virCgroupSetupDomainBlkioParameters(priv->cgroup, def, + params, nparams); =20 if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto endjob; diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 9dc60f66c9..67855b685f 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -3729,3 +3729,118 @@ virCgroupSetupCpuPeriodQuota(virCgroupPtr cgroup, =20 return -1; } + + +int +virCgroupSetupDomainBlkioParameters(virCgroupPtr cgroup, virDomainDefPtr d= ef, + virTypedParameterPtr params, int npara= ms) +{ + 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, param->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 (virDomainParseBlkioDeviceStr(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 (virCgroupSetBlkioDeviceWeight(cgroup, + devices[j].path, + devices[j].weight) <= 0 || + virCgroupGetBlkioDeviceWeight(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 (virCgroupSetBlkioDeviceReadIops(cgroup, + devices[j].path, + devices[j].riops) = < 0 || + virCgroupGetBlkioDeviceReadIops(cgroup, + devices[j].path, + &devices[j].riops)= < 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 (virCgroupSetBlkioDeviceWriteIops(cgroup, + devices[j].path, + devices[j].wiops)= < 0 || + virCgroupGetBlkioDeviceWriteIops(cgroup, + devices[j].path, + &devices[j].wiops= ) < 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 (virCgroupSetBlkioDeviceReadBps(cgroup, + devices[j].path, + devices[j].rbps) < = 0 || + virCgroupGetBlkioDeviceReadBps(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 (virCgroupSetBlkioDeviceWriteBps(cgroup, + devices[j].path, + devices[j].wbps) <= 0 || + virCgroupGetBlkioDeviceWriteBps(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); + VIR_FREE(devices); + + continue; + } + + if (j !=3D ndevices || + virDomainMergeBlkioDevice(&def->blkio.devices, + &def->blkio.ndevices, + devices, ndevices, param->field)= < 0) + ret =3D -1; + + virBlkioDeviceArrayClear(devices, ndevices); + VIR_FREE(devices); + } + } + + return ret; +} diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 97ffa3f7df..85309e800d 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -296,3 +296,7 @@ int virCgroupSetAndRetrieveCpuShares(virCgroupPtr cgrou= p, int virCgroupSetupCpuPeriodQuota(virCgroupPtr cgroup, unsigned long long period, long long quota); +int virCgroupSetupDomainBlkioParameters(virCgroupPtr cgroup, + virDomainDefPtr def, + virTypedParameterPtr params, + int nparams); --=20 2.24.1 From nobody Fri Mar 29 06:30:50 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 1581372532018213.49235212827432; Mon, 10 Feb 2020 14:08:52 -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-410-ScH5II1sN7mIP_0wHLdM4g-1; Mon, 10 Feb 2020 17:08:47 -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 176CE8C8945; Mon, 10 Feb 2020 22:08:42 +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 DFFC95C103; Mon, 10 Feb 2020 22:08:41 +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 991BA18089CE; Mon, 10 Feb 2020 22:08:41 +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 01AM5u4d011078 for ; Mon, 10 Feb 2020 17:05:56 -0500 Received: by smtp.corp.redhat.com (Postfix) id F26E210F1CA5; Mon, 10 Feb 2020 22:05:55 +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 EC70610F1CA1 for ; Mon, 10 Feb 2020 22:05:53 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.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 EE0EE8001FE for ; Mon, 10 Feb 2020 22:05:52 +0000 (UTC) Received: from mail-qk1-f195.google.com (mail-qk1-f195.google.com [209.85.222.195]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-139-bcdhSsjvPyiFMt2IE6-Icg-1; Mon, 10 Feb 2020 17:05:49 -0500 Received: by mail-qk1-f195.google.com with SMTP id b7so8190866qkl.7; Mon, 10 Feb 2020 14:05:48 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:3c07:1c6d:d4f2:46f3:c31d]) by smtp.gmail.com with ESMTPSA id z5sm970908qta.7.2020.02.10.14.05.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2020 14:05:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581372530; 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=zroSHYFf4cpMfDV27f3EnTgfgwwLQ4RXZCsKmdcUJNI=; b=VHBj8F/wuWsNMeviP4VDlOsTAu2AV3XhvzjUMlYy+zYneTCF0vr3djBygjc6cXO+Bk+y8u dXLL7qzS68eyzdoCw4BaGI3DGFvzzfjaGza6y6qj22rfJCZnBmgkKQmQCdMt4EkfkSeuDy ZPmLs6HmroDa77kQCSAQL26ZjgrimWA= 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=7h87ygtd65qEyAgBR52HAArcy3wRWmES0yreheTIljk=; b=djhj9OLAT6b26cOOlvH/2H2VckiUBkZPZvWc53xFlXPcNLM3xZCgxVOa2W4mqhtmzM M+/LHNhh5aOQ2LW18ZB6nei0dDDp05GtojqxfwFWAn7s11HSmbyIOqX5Ixhh6iZX61DD oxZFTbxunxnF7qUaxHPGfD/79qrbgi1Jxu47B+CeZ3RG+2RtnlkGgSlFWvFAIJ1UbRKw +PqDvxgsHUsgn2LtOCvIeey9EnqLhh6WXvbSdERD7NnRPm5rOgke0PWosWeoiIzwmIX2 l9QnKhtNtoWlelDZWlmsHmLkcKCuFM93vSRY11GGvI2kdQc26cBMVJDf/zqaYhBREJT6 HuxA== X-Gm-Message-State: APjAAAWn7K86apA//suZYd8fn2jQqO3ktCyYOzyaYPYI5r77uBQgBrmh LelhogDjqXpH00HMMFE8uG3eshTZvM8= X-Google-Smtp-Source: APXvYqx4tuYInISA3j5tDHNbhjEtW4JHsub9wc9pDjzYyEXwL+W3GA6MFAcbEzEEuzjv//R4F/83uQ== X-Received: by 2002:a37:9ce:: with SMTP id 197mr3539850qkj.194.1581372348264; Mon, 10 Feb 2020 14:05:48 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v1 09/14] domain_conf: add virDomainParseMergePersistentDefBlkioParams() Date: Mon, 10 Feb 2020 19:05:15 -0300 Message-Id: <20200210220520.817666-10-danielhb413@gmail.com> In-Reply-To: <20200210220520.817666-1-danielhb413@gmail.com> References: <20200210220520.817666-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: bcdhSsjvPyiFMt2IE6-Icg-1 X-MC-Unique: ScH5II1sN7mIP_0wHLdM4g-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 01AM5u4d011078 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , 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 --- src/conf/domain_conf.c | 41 ++++++++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 4 ++++ src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 32 +++---------------------------- src/qemu/qemu_driver.c | 32 +++---------------------------- 5 files changed, 52 insertions(+), 58 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index df8a71290d..fa1ef10899 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1806,6 +1806,47 @@ virDomainParseBlkioDeviceStr(char *blkioDeviceStr, c= onst char *type, } =20 =20 +int +virDomainParseMergePersistentDefBlkioParams(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 (virDomainParseBlkioDeviceStr(param->value.s, + param->field, + &devices, + &ndevices) < 0) { + ret =3D -1; + continue; + } + if (virDomainMergeBlkioDevice(&persistentDef->blkio.devices, + &persistentDef->blkio.ndevices, + devices, ndevices, param->field)= < 0) + ret =3D -1; + virBlkioDeviceArrayClear(devices, ndevices); + VIR_FREE(devices); + } + } + + return ret; +} + + /** * virDomainDefCheckUnsupportedMemoryHotplug: * @def: domain definition diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index e1daf26e07..c09bc31c12 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2218,6 +2218,10 @@ int virDomainMergeBlkioDevice(virBlkioDevicePtr *des= t_array, int virDomainParseBlkioDeviceStr(char *blkioDeviceStr, const char *type, virBlkioDevicePtr *dev, size_t *size); =20 +int virDomainParseMergePersistentDefBlkioParams(virDomainDefPtr persistent= Def, + virTypedParameterPtr param= s, + int nparams); + struct _virDomainResourceDef { char *partition; }; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 196c7bdb23..1422fbc3d9 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -565,6 +565,7 @@ virDomainOSTypeFromString; virDomainOSTypeToString; virDomainParseBlkioDeviceStr; virDomainParseMemory; +virDomainParseMergePersistentDefBlkioParams; virDomainPausedReasonTypeFromString; virDomainPausedReasonTypeToString; virDomainPMSuspendedReasonTypeFromString; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 9a585d0d07..1fabba40bd 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2313,7 +2313,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; @@ -2370,34 +2369,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 (virDomainParseBlkioDeviceStr(params[i].value.s, - param->field, - &devices, - &ndevices) < 0) { - ret =3D -1; - continue; - } - 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); - } - } + ret =3D virDomainParseMergePersistentDefBlkioParams(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 da4e6d7a93..c154efbaf6 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9317,7 +9317,6 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, unsigned int flags) { virQEMUDriverPtr driver =3D dom->conn->privateData; - size_t i; virDomainObjPtr vm =3D NULL; virDomainDefPtr def; virDomainDefPtr persistentDef; @@ -9383,34 +9382,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 (virDomainParseBlkioDeviceStr(param->value.s, - param->field, - &devices, - &ndevices) < 0) { - ret =3D -1; - continue; - } - 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); - } - } + ret =3D virDomainParseMergePersistentDefBlkioParams(persistentDef, + params, + nparams); =20 if (virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir= ) < 0) ret =3D -1; --=20 2.24.1 From nobody Fri Mar 29 06:30:50 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-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1581372567868417.074905794153; Mon, 10 Feb 2020 14:09:27 -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-288-O2kAz-5zOFCNwNaxk6pu1w-1; Mon, 10 Feb 2020 17:09:24 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 15B4C107ACC7; Mon, 10 Feb 2020 22:09:19 +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 E81CE5DA82; Mon, 10 Feb 2020 22:09: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 A21B11808878; Mon, 10 Feb 2020 22:09:18 +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 01AM5r9T011060 for ; Mon, 10 Feb 2020 17:05:53 -0500 Received: by smtp.corp.redhat.com (Postfix) id BC4502063209; Mon, 10 Feb 2020 22:05:53 +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 B6BE12026D67 for ; Mon, 10 Feb 2020 22:05:53 +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 97B22101928D for ; Mon, 10 Feb 2020 22:05:53 +0000 (UTC) Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-380-YKpqNXrOMFKBDdDuX8eegw-1; Mon, 10 Feb 2020 17:05:51 -0500 Received: by mail-qv1-f54.google.com with SMTP id z3so4025521qvn.0; Mon, 10 Feb 2020 14:05:50 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:3c07:1c6d:d4f2:46f3:c31d]) by smtp.gmail.com with ESMTPSA id z5sm970908qta.7.2020.02.10.14.05.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2020 14:05:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581372566; 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=I0mJ/Vv+sap0Ux8QffGxTUbLKhTMs9dcQO4QQkEPEq4=; b=XCFr7CiqodjdEBU/tVYeL1NIR4L/4Fym22mXyU5ssk488Y0hkc/xu8odTpKM/esTf9hYqo IRJ5E4D62q/VCMSmyx/x4kXBj2T1cfiuus3rTU5P4v1P+tACLs86GcUA9CT23CTLPBATMD DRiyb7YFa3gNHRGtidsKC/YHOiQOUjQ= 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=LrGGPw+I1BEG86qIM1PZ7nWtKZkD/XPukWak1MetYTA=; b=b+1gzv5e8qAvmsMIKnUeXc2soAnp7DQ3HEsqz1BmWtWVHZfwqghL71UyeSiUvk5YI0 BVLhxbFAaTcZh1qaacKgsqk0DyijtxO3zgreQLKYbw0jj4ZW8gk1lnsbTflBJq6sUy8Z oKAIFysh0L0ew6coQIU42UDqVEsH7b06+rzrxLrKayw0qNLFSGxfcApuAYOPDQDa/lAq /8Ez34LNyN9+0CviPpnKHIlHai23wYhflkpc86Bp6wWKU5kVLtf4DnOcJ7dmXMfKKBEX CkThWCTbQJQoGNumNsNfgcgKEdN2xBlGvjDCsVR0He7ZEc8eJscDSmoEmvqL9Cge8ZQo Gj9Q== X-Gm-Message-State: APjAAAWRHcwSpLDf/favlgedB9S7vSJYb0YFBMPXibzj6gHZaP6/0dgU rQoechhDLjnfIiTox3Vjw+iRUhuYN+k= X-Google-Smtp-Source: APXvYqy7HXpLu7DhtPkUs2o/IEqZlMBZJdypjipeFy3i0H755V8O2NsTrK5WYtXkvo/ORIz/5RR8vA== X-Received: by 2002:a0c:8605:: with SMTP id p5mr4020qva.109.1581372350059; Mon, 10 Feb 2020 14:05:50 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v1 10/14] vircgroup: add virCgroupSetMemoryLimitParameters() Date: Mon, 10 Feb 2020 19:05:16 -0300 Message-Id: <20200210220520.817666-11-danielhb413@gmail.com> In-Reply-To: <20200210220520.817666-1-danielhb413@gmail.com> References: <20200210220520.817666-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: YKpqNXrOMFKBDdDuX8eegw-1 X-MC-Unique: O2kAz-5zOFCNwNaxk6pu1w-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 01AM5r9T011060 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , 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.14 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" lxcDomainSetMemoryParameters() and qemuDomainSetMemoryParameters() has duplicated chunks of code that can be put in a new helper. Signed-off-by: Daniel Henrique Barboza --- src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 70 ++--------------------------------- src/qemu/qemu_driver.c | 70 ++--------------------------------- src/util/vircgroup.c | 79 ++++++++++++++++++++++++++++++++++++++++ src/util/vircgroup.h | 6 +++ 5 files changed, 92 insertions(+), 134 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 1422fbc3d9..7143e12838 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1729,6 +1729,7 @@ virCgroupSetCpuShares; virCgroupSetFreezerState; virCgroupSetMemory; virCgroupSetMemoryHardLimit; +virCgroupSetMemoryLimitParameters; virCgroupSetMemorySoftLimit; virCgroupSetMemSwapHardLimit; virCgroupSetOwner; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 1fabba40bd..b5c02b3ccb 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -747,13 +747,6 @@ lxcDomainSetMemoryParameters(virDomainPtr dom, virLXCDomainObjPrivatePtr priv =3D NULL; virLXCDriverConfigPtr cfg =3D NULL; virLXCDriverPtr driver =3D dom->conn->privateData; - unsigned long long hard_limit; - unsigned long long soft_limit; - unsigned long long swap_hard_limit; - bool set_hard_limit =3D false; - bool set_soft_limit =3D false; - bool set_swap_hard_limit =3D false; - int rc; int ret =3D -1; =20 virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | @@ -792,66 +785,9 @@ lxcDomainSetMemoryParameters(virDomainPtr dom, goto endjob; } =20 -#define VIR_GET_LIMIT_PARAMETER(PARAM, VALUE) \ - if ((rc =3D virTypedParamsGetULLong(params, nparams, PARAM, &VALUE)) <= 0) \ - goto endjob; \ - \ - if (rc =3D=3D 1) \ - set_ ## VALUE =3D true; - - VIR_GET_LIMIT_PARAMETER(VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT, swap_hard_l= imit) - VIR_GET_LIMIT_PARAMETER(VIR_DOMAIN_MEMORY_HARD_LIMIT, hard_limit) - VIR_GET_LIMIT_PARAMETER(VIR_DOMAIN_MEMORY_SOFT_LIMIT, soft_limit) - -#undef VIR_GET_LIMIT_PARAMETER - - /* Swap hard limit must be greater than hard limit. */ - if (set_swap_hard_limit || set_hard_limit) { - unsigned long long mem_limit =3D vm->def->mem.hard_limit; - unsigned long long swap_limit =3D vm->def->mem.swap_hard_limit; - - if (set_swap_hard_limit) - swap_limit =3D swap_hard_limit; - - if (set_hard_limit) - mem_limit =3D hard_limit; - - if (mem_limit > swap_limit) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("memory hard_limit tunable value must be lowe= r " - "than or equal to swap_hard_limit")); - goto endjob; - } - } - -#define VIR_SET_MEM_PARAMETER(FUNC, VALUE) \ - if (set_ ## VALUE) { \ - if (def) { \ - if ((rc =3D FUNC(priv->cgroup, VALUE)) < 0) \ - goto endjob; \ - def->mem.VALUE =3D VALUE; \ - } \ - \ - if (persistentDef) \ - persistentDef->mem.VALUE =3D VALUE; \ - } - - /* Soft limit doesn't clash with the others */ - VIR_SET_MEM_PARAMETER(virCgroupSetMemorySoftLimit, soft_limit); - - /* set hard limit before swap hard limit if decreasing it */ - if (def && def->mem.hard_limit > hard_limit) { - VIR_SET_MEM_PARAMETER(virCgroupSetMemoryHardLimit, hard_limit); - /* inhibit changing the limit a second time */ - set_hard_limit =3D false; - } - - VIR_SET_MEM_PARAMETER(virCgroupSetMemSwapHardLimit, swap_hard_limit); - - /* otherwise increase it after swap hard limit */ - VIR_SET_MEM_PARAMETER(virCgroupSetMemoryHardLimit, hard_limit); - -#undef VIR_SET_MEM_PARAMETER + if (virCgroupSetMemoryLimitParameters(priv->cgroup, vm, def, persisten= tDef, + params, nparams) < 0) + goto endjob; =20 if (def && virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index c154efbaf6..d2177d73a2 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9500,14 +9500,7 @@ qemuDomainSetMemoryParameters(virDomainPtr dom, virDomainDefPtr def =3D NULL; virDomainDefPtr persistentDef =3D NULL; virDomainObjPtr vm =3D NULL; - unsigned long long swap_hard_limit; - unsigned long long hard_limit =3D 0; - unsigned long long soft_limit =3D 0; - bool set_swap_hard_limit =3D false; - bool set_hard_limit =3D false; - bool set_soft_limit =3D false; g_autoptr(virQEMUDriverConfig) cfg =3D NULL; - int rc; int ret =3D -1; qemuDomainObjPrivatePtr priv; =20 @@ -9554,66 +9547,9 @@ qemuDomainSetMemoryParameters(virDomainPtr dom, goto endjob; } =20 -#define VIR_GET_LIMIT_PARAMETER(PARAM, VALUE) \ - if ((rc =3D virTypedParamsGetULLong(params, nparams, PARAM, &VALUE)) <= 0) \ - goto endjob; \ - \ - if (rc =3D=3D 1) \ - set_ ## VALUE =3D true; - - VIR_GET_LIMIT_PARAMETER(VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT, swap_hard_l= imit) - VIR_GET_LIMIT_PARAMETER(VIR_DOMAIN_MEMORY_HARD_LIMIT, hard_limit) - VIR_GET_LIMIT_PARAMETER(VIR_DOMAIN_MEMORY_SOFT_LIMIT, soft_limit) - -#undef VIR_GET_LIMIT_PARAMETER - - /* Swap hard limit must be greater than hard limit. */ - if (set_swap_hard_limit || set_hard_limit) { - unsigned long long mem_limit =3D vm->def->mem.hard_limit; - unsigned long long swap_limit =3D vm->def->mem.swap_hard_limit; - - if (set_swap_hard_limit) - swap_limit =3D swap_hard_limit; - - if (set_hard_limit) - mem_limit =3D hard_limit; - - if (mem_limit > swap_limit) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("memory hard_limit tunable value must be lowe= r " - "than or equal to swap_hard_limit")); - goto endjob; - } - } - -#define VIR_SET_MEM_PARAMETER(FUNC, VALUE) \ - if (set_ ## VALUE) { \ - if (def) { \ - if ((rc =3D FUNC(priv->cgroup, VALUE)) < 0) \ - goto endjob; \ - def->mem.VALUE =3D VALUE; \ - } \ - \ - if (persistentDef) \ - persistentDef->mem.VALUE =3D VALUE; \ - } - - /* Soft limit doesn't clash with the others */ - VIR_SET_MEM_PARAMETER(virCgroupSetMemorySoftLimit, soft_limit); - - /* set hard limit before swap hard limit if decreasing it */ - if (def && def->mem.hard_limit > hard_limit) { - VIR_SET_MEM_PARAMETER(virCgroupSetMemoryHardLimit, hard_limit); - /* inhibit changing the limit a second time */ - set_hard_limit =3D false; - } - - VIR_SET_MEM_PARAMETER(virCgroupSetMemSwapHardLimit, swap_hard_limit); - - /* otherwise increase it after swap hard limit */ - VIR_SET_MEM_PARAMETER(virCgroupSetMemoryHardLimit, hard_limit); - -#undef VIR_SET_MEM_PARAMETER + if (virCgroupSetMemoryLimitParameters(priv->cgroup, vm, def, persisten= tDef, + params, nparams) < 0) + goto endjob; =20 if (def && virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 67855b685f..530f1b7223 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -3844,3 +3844,82 @@ virCgroupSetupDomainBlkioParameters(virCgroupPtr cgr= oup, virDomainDefPtr def, =20 return ret; } + + +int +virCgroupSetMemoryLimitParameters(virCgroupPtr cgroup, virDomainObjPtr vm, + virDomainDefPtr liveDef, + virDomainDefPtr persistentDef, + virTypedParameterPtr params, int nparams) +{ + unsigned long long swap_hard_limit; + unsigned long long hard_limit =3D 0; + unsigned long long soft_limit =3D 0; + bool set_swap_hard_limit =3D false; + bool set_hard_limit =3D false; + bool set_soft_limit =3D false; + int rc; + +#define VIR_GET_LIMIT_PARAMETER(PARAM, VALUE) \ + if ((rc =3D virTypedParamsGetULLong(params, nparams, PARAM, &VALUE)) <= 0) \ + return -1; \ + \ + if (rc =3D=3D 1) \ + set_ ## VALUE =3D true; + + VIR_GET_LIMIT_PARAMETER(VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT, swap_hard_l= imit) + VIR_GET_LIMIT_PARAMETER(VIR_DOMAIN_MEMORY_HARD_LIMIT, hard_limit) + VIR_GET_LIMIT_PARAMETER(VIR_DOMAIN_MEMORY_SOFT_LIMIT, soft_limit) + +#undef VIR_GET_LIMIT_PARAMETER + + /* Swap hard limit must be greater than hard limit. */ + if (set_swap_hard_limit || set_hard_limit) { + unsigned long long mem_limit =3D vm->def->mem.hard_limit; + unsigned long long swap_limit =3D vm->def->mem.swap_hard_limit; + + if (set_swap_hard_limit) + swap_limit =3D swap_hard_limit; + + if (set_hard_limit) + mem_limit =3D hard_limit; + + if (mem_limit > swap_limit) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("memory hard_limit tunable value must be lowe= r " + "than or equal to swap_hard_limit")); + return -1; + } + } + +#define VIR_SET_MEM_PARAMETER(FUNC, VALUE) \ + if (set_ ## VALUE) { \ + if (liveDef) { \ + if ((rc =3D FUNC(cgroup, VALUE)) < 0) \ + return -1; \ + liveDef->mem.VALUE =3D VALUE; \ + } \ + \ + if (persistentDef) \ + persistentDef->mem.VALUE =3D VALUE; \ + } + + /* Soft limit doesn't clash with the others */ + VIR_SET_MEM_PARAMETER(virCgroupSetMemorySoftLimit, soft_limit); + + /* set hard limit before swap hard limit if decreasing it */ + if (liveDef && liveDef->mem.hard_limit > hard_limit) { + VIR_SET_MEM_PARAMETER(virCgroupSetMemoryHardLimit, hard_limit); + /* inhibit changing the limit a second time */ + set_hard_limit =3D false; + } + + VIR_SET_MEM_PARAMETER(virCgroupSetMemSwapHardLimit, swap_hard_limit); + + /* otherwise increase it after swap hard limit */ + VIR_SET_MEM_PARAMETER(virCgroupSetMemoryHardLimit, hard_limit); + +#undef VIR_SET_MEM_PARAMETER + + return 0; +} diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 85309e800d..5d238937d2 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -300,3 +300,9 @@ int virCgroupSetupDomainBlkioParameters(virCgroupPtr cg= roup, virDomainDefPtr def, virTypedParameterPtr params, int nparams); +int virCgroupSetMemoryLimitParameters(virCgroupPtr cgroup, + virDomainObjPtr vm, + virDomainDefPtr liveDef, + virDomainDefPtr persistentDef, + virTypedParameterPtr params, + int nparams); --=20 2.24.1 From nobody Fri Mar 29 06:30:50 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 1581372600272814.5450644727295; Mon, 10 Feb 2020 14:10:00 -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-395-0_R27N7nNyqlABH4nE-PWA-1; Mon, 10 Feb 2020 17:09:28 -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 0885C800D5A; Mon, 10 Feb 2020 22:09:23 +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 D5A8860BF4; Mon, 10 Feb 2020 22:09:22 +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 8379D866D9; Mon, 10 Feb 2020 22:09:22 +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 01AM68XO011126 for ; Mon, 10 Feb 2020 17:06:08 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0F7222166B2B; Mon, 10 Feb 2020 22:06:08 +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 0AE432166B27 for ; Mon, 10 Feb 2020 22:06:05 +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 8C27A8012A5 for ; Mon, 10 Feb 2020 22:06:05 +0000 (UTC) Received: from mail-qk1-f193.google.com (mail-qk1-f193.google.com [209.85.222.193]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-356-1WUoIR6UOc2aGz9WMiJ81g-1; Mon, 10 Feb 2020 17:05:52 -0500 Received: by mail-qk1-f193.google.com with SMTP id p7so3230304qkh.10; Mon, 10 Feb 2020 14:05:52 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:3c07:1c6d:d4f2:46f3:c31d]) by smtp.gmail.com with ESMTPSA id z5sm970908qta.7.2020.02.10.14.05.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2020 14:05:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581372599; 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=l3pyFw1S09ui6ipKqUn+iru7yKYsldUdtEN+vEMGBuw=; b=Sq0zFax8ICYTUtSqZ3jpLfJ+pFBcWqZHSo3dBxGk2ZdBSNY+j3lyP1RZjFjsEzeB5Lt2Aa m6irpGaOF4AW8fnPtUSSO+RkZezmteCXIKtOp12B+abl7+ZDD6tqndKDQzfqcXIiUbrUv1 xvWHRRXdrWsAErt5plldB+r7KrbG+Ys= 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=b7rPx7dIX6uPKFk8Ya4kJbIHQP46Vy7+OZ5ijSoAdyA=; b=hilsJTL3xrZyuIe+/GCQtd5KketQkB3DEWunULgVHyeFRDwxUdKmHTRN04/fLhiJSq F0T/7Fuah72aw6FXPVMiBrcJqdIkKXWln0DaLvkNWW1YaZ652BRDDqHlXe8dE8FNlJNg S8nb2y4Q499rN5RpssobP5PlMVz2ImCfq652o1NM4ruUi977Bf3+9yGveeqyTtfoyrUn 2QLkam7Y/zWlUqASFi356kIAZus3XgiBdwTSr/e3fBw2Bbt8AXUuSjsGPT+qa1dsm5ui QMhkC5Y5tTXsU81GtBm4Eie7ggle8fR44d7yt6vQUF4QN/rNUG0WYv8pKkpvdqKMNdGA se6A== X-Gm-Message-State: APjAAAWBMp94tlrIYY4kmGxB5/Ae3KmDsxoNkiNH3sqdoJKLFY3arWxP hoC1mD8yF+McohIgJWodQVbseyjBO8s= X-Google-Smtp-Source: APXvYqzpueq0WpeLPQIgdAESQa53xZM7K68BTrKZJ9Bl9G7Y6RsBGUubw00b9waxF+Z1acq4YtRFbw== X-Received: by 2002:a37:3c5:: with SMTP id 188mr39954qkd.312.1581372351539; Mon, 10 Feb 2020 14:05:51 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v1 11/14] vircgroup: add virCgroupGetCpuPeriodQuota() Date: Mon, 10 Feb 2020 19:05:17 -0300 Message-Id: <20200210220520.817666-12-danielhb413@gmail.com> In-Reply-To: <20200210220520.817666-1-danielhb413@gmail.com> References: <20200210220520.817666-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: 1WUoIR6UOc2aGz9WMiJ81g-1 X-MC-Unique: 0_R27N7nNyqlABH4nE-PWA-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 01AM68XO011126 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , 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" Another vircgroup helper to avoid code repetition between the LXC and QEMU driver. Signed-off-by: Daniel Henrique Barboza --- src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 8 +------- src/qemu/qemu_driver.c | 8 +------- src/util/vircgroup.c | 14 ++++++++++++++ src/util/vircgroup.h | 2 ++ 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 7143e12838..ffd76253b3 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1685,6 +1685,7 @@ virCgroupGetCpuacctStat; virCgroupGetCpuacctUsage; virCgroupGetCpuCfsPeriod; virCgroupGetCpuCfsQuota; +virCgroupGetCpuPeriodQuota; virCgroupGetCpusetCpus; virCgroupGetCpusetMemoryMigrate; virCgroupGetCpusetMems; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index b5c02b3ccb..2b4b68ba41 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1780,13 +1780,7 @@ static int lxcGetVcpuBWLive(virCgroupPtr cgroup, unsigned long long *period, long long *quota) { - if (virCgroupGetCpuCfsPeriod(cgroup, period) < 0) - return -1; - - if (virCgroupGetCpuCfsQuota(cgroup, quota) < 0) - return -1; - - return 0; + return virCgroupGetCpuPeriodQuota(cgroup, period, quota); } =20 =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d2177d73a2..148424d5f0 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -10530,13 +10530,7 @@ static int qemuGetVcpuBWLive(virCgroupPtr cgroup, unsigned long long *period, long long *quota) { - if (virCgroupGetCpuCfsPeriod(cgroup, period) < 0) - return -1; - - if (virCgroupGetCpuCfsQuota(cgroup, quota) < 0) - return -1; - - return 0; + return virCgroupGetCpuPeriodQuota(cgroup, period, quota); } =20 static int diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 530f1b7223..dad475c436 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -3731,6 +3731,20 @@ virCgroupSetupCpuPeriodQuota(virCgroupPtr cgroup, } =20 =20 +int +virCgroupGetCpuPeriodQuota(virCgroupPtr cgroup, unsigned long long *period, + long long *quota) +{ + if (virCgroupGetCpuCfsPeriod(cgroup, period) < 0) + return -1; + + if (virCgroupGetCpuCfsQuota(cgroup, quota) < 0) + return -1; + + return 0; +} + + int virCgroupSetupDomainBlkioParameters(virCgroupPtr cgroup, virDomainDefPtr d= ef, virTypedParameterPtr params, int npara= ms) diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 5d238937d2..10c4b75863 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -290,6 +290,8 @@ bool virCgroupControllerAvailable(int controller); int virCgroupSetupBlkioTune(virCgroupPtr cgroup, virDomainBlkiotune blkio); int virCgroupSetupMemtune(virCgroupPtr cgroup, virDomainMemtune mem); int virCgroupSetupCpusetCpus(virCgroupPtr cgroup, virBitmapPtr cpumask); +int virCgroupGetCpuPeriodQuota(virCgroupPtr cgroup, unsigned long long *pe= riod, + long long *quota); int virCgroupSetAndRetrieveCpuShares(virCgroupPtr cgroup, unsigned long long shares, unsigned long long *realValue); --=20 2.24.1 From nobody Fri Mar 29 06:30:50 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-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1581372646188164.72371324456526; Mon, 10 Feb 2020 14:10:46 -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-341-sjz9sGtzPTyhhLIV43PUJQ-1; Mon, 10 Feb 2020 17:10:42 -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 E4BED801FC8; Mon, 10 Feb 2020 22:10:36 +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 B999B8ED1C; Mon, 10 Feb 2020 22:10:36 +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 7E9D21804744; Mon, 10 Feb 2020 22:10:36 +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 01AM5w1C011094 for ; Mon, 10 Feb 2020 17:05:59 -0500 Received: by smtp.corp.redhat.com (Postfix) id CF573178B1; Mon, 10 Feb 2020 22:05:58 +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 CB203B3516 for ; Mon, 10 Feb 2020 22:05:56 +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 74E2D185AB8B for ; Mon, 10 Feb 2020 22:05:56 +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-142-88EmmVloMk-Rox8D7mmbJQ-1; Mon, 10 Feb 2020 17:05:54 -0500 Received: by mail-qk1-f194.google.com with SMTP id q15so8175803qke.9; Mon, 10 Feb 2020 14:05:53 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:3c07:1c6d:d4f2:46f3:c31d]) by smtp.gmail.com with ESMTPSA id z5sm970908qta.7.2020.02.10.14.05.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2020 14:05:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581372644; 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=5nhi9Me45m3K8jl5wrUuZfWXku5Hj2rdrb4xGqdMsRM=; b=AF+zh39RAV7D2FrDSm1pj0c45/pjpL0ESO2QCjiOr0JRaCXjrd8qxxUOfkUvcK0KrZCwlE sNvXhnDIRdAAaM5YoCNM5mOviTIHamVt2paPJecgTREOGyzUSIQ3qQpFuZToPv26lcViNO iH0cEQXxezflR6uVTSIlh4TWqLpV3c8= 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=fwtny98RJM4vo+QgYbKnRQxCY1RjTfcO7gTAkMiLNJ0=; b=foA1em0mq1LJfa2qwVJmezO1V1Draoz977dAdwM8hO97YEj/0sGMfZLy1Dj8t/JLIu HNWeNj7r6JE4Fp1PUV00ALMdHeJdaZ94jdwUfTxBDAWd24U9kVNY1UuSKkpd+10SeJw9 GkfRU+52VKIXJMHO+ZrxJ3/TOfFJwvOrD7UEFfB/dF8EQiEI3VsEEW+usWQM14JPyr/Z G5sBCltCLQF6dZzx9JeRab3jMu4DFTDfhwsXLh+0YSQXEY08tBBEFDDm0FW3PuZGs95h oFwtGDEEpsPf7SyfwT1krBH4vak1AS7Dc0yTw5kZjh/saKcQOQSrntsLvvoK11NiZaZs 4YZA== X-Gm-Message-State: APjAAAWk3ZR5R+BzBWhIIKauLJnPwf4c1x3BU7TCNUoghq9yr5z8qiyy tSQDnRmJlBy3hci0IcAaVVL73qz0Isw= X-Google-Smtp-Source: APXvYqx88nmOQZjrBDE1EVcKrzh82RoeiqW2XId9QHtN3K2Kjb2Njbvzx51gTcE5q8vzYnBUxjZ9SA== X-Received: by 2002:a05:620a:12c6:: with SMTP id e6mr3036917qkl.135.1581372353084; Mon, 10 Feb 2020 14:05:53 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v1 12/14] vircgroup: turn virCgroup{Get/Set}BlkioDevice* static Date: Mon, 10 Feb 2020 19:05:18 -0300 Message-Id: <20200210220520.817666-13-danielhb413@gmail.com> In-Reply-To: <20200210220520.817666-1-danielhb413@gmail.com> References: <20200210220520.817666-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: 88EmmVloMk-Rox8D7mmbJQ-1 X-MC-Unique: sjz9sGtzPTyhhLIV43PUJQ-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 01AM5w1C011094 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , 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" The new virCgroupSetupBlkioTune() centralized all the code that call those functions inside vircgroup.c. Signed-off-by: Daniel Henrique Barboza --- src/libvirt_private.syms | 11 ---------- src/util/vircgroup.c | 44 ++++++++++++++++++++-------------------- src/util/vircgroup.h | 41 ------------------------------------- 3 files changed, 22 insertions(+), 74 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index ffd76253b3..3dc65916bf 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1672,11 +1672,6 @@ virCgroupDenyAllDevices; virCgroupDenyDevice; virCgroupDenyDevicePath; virCgroupFree; -virCgroupGetBlkioDeviceReadBps; -virCgroupGetBlkioDeviceReadIops; -virCgroupGetBlkioDeviceWeight; -virCgroupGetBlkioDeviceWriteBps; -virCgroupGetBlkioDeviceWriteIops; virCgroupGetBlkioIoDeviceServiced; virCgroupGetBlkioIoServiced; virCgroupGetBlkioWeight; @@ -1715,12 +1710,6 @@ virCgroupNewThread; virCgroupPathOfController; virCgroupRemove; virCgroupSetAndRetrieveCpuShares; -virCgroupSetBlkioDeviceReadBps; -virCgroupSetBlkioDeviceReadIops; -virCgroupSetBlkioDeviceWeight; -virCgroupSetBlkioDeviceWriteBps; -virCgroupSetBlkioDeviceWriteIops; -virCgroupSetBlkioWeight; virCgroupSetCpuCfsPeriod; virCgroupSetCpuCfsQuota; virCgroupSetCpusetCpus; diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index dad475c436..8ee37cde7c 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1385,7 +1385,7 @@ virCgroupGetBlkioIoDeviceServiced(virCgroupPtr group, * * Returns: 0 on success, -1 on error */ -int +static int virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight) { VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO, @@ -1416,7 +1416,7 @@ virCgroupGetBlkioWeight(virCgroupPtr group, unsigned = int *weight) * * Returns: 0 on success, -1 on error */ -int +static int virCgroupSetBlkioDeviceReadIops(virCgroupPtr group, const char *path, unsigned int riops) @@ -1434,7 +1434,7 @@ virCgroupSetBlkioDeviceReadIops(virCgroupPtr group, * * Returns: 0 on success, -1 on error */ -int +static int virCgroupSetBlkioDeviceWriteIops(virCgroupPtr group, const char *path, unsigned int wiops) @@ -1452,7 +1452,7 @@ virCgroupSetBlkioDeviceWriteIops(virCgroupPtr group, * * Returns: 0 on success, -1 on error */ -int +static int virCgroupSetBlkioDeviceReadBps(virCgroupPtr group, const char *path, unsigned long long rbps) @@ -1469,7 +1469,7 @@ virCgroupSetBlkioDeviceReadBps(virCgroupPtr group, * * Returns: 0 on success, -1 on error */ -int +static int virCgroupSetBlkioDeviceWriteBps(virCgroupPtr group, const char *path, unsigned long long wbps) @@ -1488,7 +1488,7 @@ virCgroupSetBlkioDeviceWriteBps(virCgroupPtr group, * * Returns: 0 on success, -1 on error */ -int +static int virCgroupSetBlkioDeviceWeight(virCgroupPtr group, const char *path, unsigned int weight) @@ -1505,7 +1505,7 @@ virCgroupSetBlkioDeviceWeight(virCgroupPtr group, * * Returns: 0 on success, -1 on error */ -int +static int virCgroupGetBlkioDeviceReadIops(virCgroupPtr group, const char *path, unsigned int *riops) @@ -1522,7 +1522,7 @@ virCgroupGetBlkioDeviceReadIops(virCgroupPtr group, * * Returns: 0 on success, -1 on error */ -int +static int virCgroupGetBlkioDeviceWriteIops(virCgroupPtr group, const char *path, unsigned int *wiops) @@ -1539,7 +1539,7 @@ virCgroupGetBlkioDeviceWriteIops(virCgroupPtr group, * * Returns: 0 on success, -1 on error */ -int +static int virCgroupGetBlkioDeviceReadBps(virCgroupPtr group, const char *path, unsigned long long *rbps) @@ -1556,7 +1556,7 @@ virCgroupGetBlkioDeviceReadBps(virCgroupPtr group, * * Returns: 0 on success, -1 on error */ -int +static int virCgroupGetBlkioDeviceWriteBps(virCgroupPtr group, const char *path, unsigned long long *wbps) @@ -1573,7 +1573,7 @@ virCgroupGetBlkioDeviceWriteBps(virCgroupPtr group, * * Returns: 0 on success, -1 on error */ -int +static int virCgroupGetBlkioDeviceWeight(virCgroupPtr group, const char *path, unsigned int *weight) @@ -2974,7 +2974,7 @@ virCgroupGetBlkioIoDeviceServiced(virCgroupPtr group = G_GNUC_UNUSED, } =20 =20 -int +static int virCgroupSetBlkioWeight(virCgroupPtr group G_GNUC_UNUSED, unsigned int weight G_GNUC_UNUSED) { @@ -2994,7 +2994,7 @@ virCgroupGetBlkioWeight(virCgroupPtr group G_GNUC_UNU= SED, } =20 =20 -int +static int virCgroupSetBlkioDeviceWeight(virCgroupPtr group G_GNUC_UNUSED, const char *path G_GNUC_UNUSED, unsigned int weight G_GNUC_UNUSED) @@ -3004,7 +3004,7 @@ virCgroupSetBlkioDeviceWeight(virCgroupPtr group G_GN= UC_UNUSED, return -1; } =20 -int +static int virCgroupSetBlkioDeviceReadIops(virCgroupPtr group G_GNUC_UNUSED, const char *path G_GNUC_UNUSED, unsigned int riops G_GNUC_UNUSED) @@ -3014,7 +3014,7 @@ virCgroupSetBlkioDeviceReadIops(virCgroupPtr group G_= GNUC_UNUSED, return -1; } =20 -int +static int virCgroupSetBlkioDeviceWriteIops(virCgroupPtr group G_GNUC_UNUSED, const char *path G_GNUC_UNUSED, unsigned int wiops G_GNUC_UNUSED) @@ -3024,7 +3024,7 @@ virCgroupSetBlkioDeviceWriteIops(virCgroupPtr group G= _GNUC_UNUSED, return -1; } =20 -int +static int virCgroupSetBlkioDeviceReadBps(virCgroupPtr group G_GNUC_UNUSED, const char *path G_GNUC_UNUSED, unsigned long long rbps G_GNUC_UNUSED) @@ -3034,7 +3034,7 @@ virCgroupSetBlkioDeviceReadBps(virCgroupPtr group G_G= NUC_UNUSED, return -1; } =20 -int +static int virCgroupSetBlkioDeviceWriteBps(virCgroupPtr group G_GNUC_UNUSED, const char *path G_GNUC_UNUSED, unsigned long long wbps G_GNUC_UNUSED) @@ -3044,7 +3044,7 @@ virCgroupSetBlkioDeviceWriteBps(virCgroupPtr group G_= GNUC_UNUSED, return -1; } =20 -int +static int virCgroupGetBlkioDeviceWeight(virCgroupPtr group G_GNUC_UNUSED, const char *path G_GNUC_UNUSED, unsigned int *weight G_GNUC_UNUSED) @@ -3054,7 +3054,7 @@ virCgroupGetBlkioDeviceWeight(virCgroupPtr group G_GN= UC_UNUSED, return -1; } =20 -int +static int virCgroupGetBlkioDeviceReadIops(virCgroupPtr group G_GNUC_UNUSED, const char *path G_GNUC_UNUSED, unsigned int *riops G_GNUC_UNUSED) @@ -3064,7 +3064,7 @@ virCgroupGetBlkioDeviceReadIops(virCgroupPtr group G_= GNUC_UNUSED, return -1; } =20 -int +static int virCgroupGetBlkioDeviceWriteIops(virCgroupPtr group G_GNUC_UNUSED, const char *path G_GNUC_UNUSED, unsigned int *wiops G_GNUC_UNUSED) @@ -3074,7 +3074,7 @@ virCgroupGetBlkioDeviceWriteIops(virCgroupPtr group G= _GNUC_UNUSED, return -1; } =20 -int +static int virCgroupGetBlkioDeviceReadBps(virCgroupPtr group G_GNUC_UNUSED, const char *path G_GNUC_UNUSED, unsigned long long *rbps G_GNUC_UNUSED) @@ -3084,7 +3084,7 @@ virCgroupGetBlkioDeviceReadBps(virCgroupPtr group G_G= NUC_UNUSED, return -1; } =20 -int +static int virCgroupGetBlkioDeviceWriteBps(virCgroupPtr group G_GNUC_UNUSED, const char *path G_GNUC_UNUSED, unsigned long long *wbps G_GNUC_UNUSED) diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 10c4b75863..35a11e6b67 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -121,7 +121,6 @@ int virCgroupAddProcess(virCgroupPtr group, pid_t pid); int virCgroupAddMachineProcess(virCgroupPtr group, pid_t pid); int virCgroupAddThread(virCgroupPtr group, pid_t pid); =20 -int virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight); int virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight); =20 int virCgroupGetBlkioIoServiced(virCgroupPtr group, @@ -136,46 +135,6 @@ int virCgroupGetBlkioIoDeviceServiced(virCgroupPtr gro= up, long long *requests_read, long long *requests_write); =20 -int virCgroupSetBlkioDeviceWeight(virCgroupPtr group, - const char *path, - unsigned int weight); - -int virCgroupSetBlkioDeviceReadIops(virCgroupPtr group, - const char *path, - unsigned int riops); - -int virCgroupSetBlkioDeviceWriteIops(virCgroupPtr group, - const char *path, - unsigned int wiops); - -int virCgroupSetBlkioDeviceReadBps(virCgroupPtr group, - const char *path, - unsigned long long rbps); - -int virCgroupSetBlkioDeviceWriteBps(virCgroupPtr group, - const char *path, - unsigned long long wbps); - -int virCgroupGetBlkioDeviceWeight(virCgroupPtr group, - const char *path, - unsigned int *weight); - -int virCgroupGetBlkioDeviceReadIops(virCgroupPtr group, - const char *path, - unsigned int *riops); - -int virCgroupGetBlkioDeviceWriteIops(virCgroupPtr group, - const char *path, - unsigned int *wiops); - -int virCgroupGetBlkioDeviceReadBps(virCgroupPtr group, - const char *path, - unsigned long long *rbps); - -int virCgroupGetBlkioDeviceWriteBps(virCgroupPtr group, - const char *path, - unsigned long long *wbps); - int virCgroupSetMemory(virCgroupPtr group, unsigned long long kb); int virCgroupGetMemoryStat(virCgroupPtr group, unsigned long long *cache, --=20 2.24.1 From nobody Fri Mar 29 06:30:50 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 1581372534557192.61605720215186; Mon, 10 Feb 2020 14:08:54 -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-294-8ZrOq7u_N06OBzxaAx12Fw-1; Mon, 10 Feb 2020 17:08:50 -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 92F25107B785; Mon, 10 Feb 2020 22:08:45 +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 6CF6F87B2F; Mon, 10 Feb 2020 22:08:45 +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 30D3A18089CD; Mon, 10 Feb 2020 22:08:45 +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 01AM5vAO011083 for ; Mon, 10 Feb 2020 17:05:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8479C2166B2A; Mon, 10 Feb 2020 22:05:57 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 804122166B27 for ; Mon, 10 Feb 2020 22:05:57 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.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 64A3780005E for ; Mon, 10 Feb 2020 22:05:57 +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-253-7ej9xtw3PkauQjMtMKNUag-1; Mon, 10 Feb 2020 17:05:55 -0500 Received: by mail-qk1-f196.google.com with SMTP id q15so8175873qke.9; Mon, 10 Feb 2020 14:05:55 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:3c07:1c6d:d4f2:46f3:c31d]) by smtp.gmail.com with ESMTPSA id z5sm970908qta.7.2020.02.10.14.05.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2020 14:05:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581372533; 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=PhQmvJUot2oryCIiVgUwoRgKIcTGa8Cw8eFUreES/BY=; b=ReegI+jGxEhZI5Y2Jh590Z/Q8h/oFOEcSEEEVmJqBr1tOaajPa+HAFG7zuBD+w0BF28D4C EUsPDfsLnBk8ZcFo1DxerGWccboV8xKRA64hGCtHxzeFGzw1qA2PK+n45xlwuwl9u1+N4/ 8M7ZztIFZ1XEKUst1U3WYii2KV+JhB8= 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=Cd36IIuxUP7rcPJ+4ON1TFiS4ahfLT6wWnzWtPMnOH8=; b=WdjkowZrjqepr554Il+YTTI695YNGaqNq0370fUktSspXoiKzi7fe/OI0+sGuXw6Mo fZcfQEuW7xfhpL8If1SXhRxR0CSP1OgTmQRy7Qqe6As2aR8cJa9ykJGTO8dG3a8MdRAL xmtahHSceaJcwkxmCfZekL7M6CxqMq4VxluY/sj60BhD4PXx4ZLOpb/pyacFv3/8QGZl ATXcdnW9Cca8jcLCaT1eWRnlWJY4p5wWBrFl5qt6yzCEcpt87VRWny5z04A2X4dN+JRf juCuLZtLf8dzqO4NVdJeSvoD5RSexam6oIocJ5NOs+aG9qFaCc+HLbCemtBGaA9dtLs5 D+OQ== X-Gm-Message-State: APjAAAVUR7+AXSQ7EUYRZv73P365KNuI1t9zTALC+00vFf8xgRo5yXwN 5wPR15lCAHCbbQ3bvRl2EJWL2AZNtYo= X-Google-Smtp-Source: APXvYqyjijQMJAmVp/EGBPzZztVinndWAT4uP2cvit5/DVTBMz5wtI4FhosARrWHIsS+RLR6wYWnWQ== X-Received: by 2002:a05:620a:954:: with SMTP id w20mr22749qkw.139.1581372354623; Mon, 10 Feb 2020 14:05:54 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v1 13/14] vircgroup: turn SetMemory and SetCpusetCpus functions static Date: Mon, 10 Feb 2020 19:05:19 -0300 Message-Id: <20200210220520.817666-14-danielhb413@gmail.com> In-Reply-To: <20200210220520.817666-1-danielhb413@gmail.com> References: <20200210220520.817666-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: 7ej9xtw3PkauQjMtMKNUag-1 X-MC-Unique: 8ZrOq7u_N06OBzxaAx12Fw-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 01AM5vAO011083 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , 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" The new virCgroupSetupMemtune() virCgroupSetupCpusetCpus() made the cgroup SetMemory and SetCpusetCpus functions to be called only inside vircgroup.c. Signed-off-by: Daniel Henrique Barboza --- src/libvirt_private.syms | 4 ---- src/util/vircgroup.c | 16 ++++++++-------- src/util/vircgroup.h | 4 ---- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 3dc65916bf..1ec73a13c2 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1712,16 +1712,12 @@ virCgroupRemove; virCgroupSetAndRetrieveCpuShares; virCgroupSetCpuCfsPeriod; virCgroupSetCpuCfsQuota; -virCgroupSetCpusetCpus; virCgroupSetCpusetMemoryMigrate; virCgroupSetCpusetMems; virCgroupSetCpuShares; virCgroupSetFreezerState; virCgroupSetMemory; -virCgroupSetMemoryHardLimit; virCgroupSetMemoryLimitParameters; -virCgroupSetMemorySoftLimit; -virCgroupSetMemSwapHardLimit; virCgroupSetOwner; virCgroupSetupBlkioTune; virCgroupSetupCpuPeriodQuota; diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 8ee37cde7c..f0103d8062 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1653,7 +1653,7 @@ virCgroupGetMemoryUsage(virCgroupPtr group, unsigned = long *kb) * * Returns: 0 on success */ -int +static int virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long long kb) { VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY, @@ -1685,7 +1685,7 @@ virCgroupGetMemoryHardLimit(virCgroupPtr group, unsig= ned long long *kb) * * Returns: 0 on success */ -int +static int virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned long long kb) { VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY, @@ -1717,7 +1717,7 @@ virCgroupGetMemorySoftLimit(virCgroupPtr group, unsig= ned long long *kb) * * Returns: 0 on success */ -int +static int virCgroupSetMemSwapHardLimit(virCgroupPtr group, unsigned long long kb) { VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY, @@ -1829,7 +1829,7 @@ virCgroupGetCpusetMemoryMigrate(virCgroupPtr group, b= ool *migrate) * * Returns: 0 on success */ -int +static int virCgroupSetCpusetCpus(virCgroupPtr group, const char *cpus) { VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPUSET, @@ -3129,7 +3129,7 @@ virCgroupGetMemoryUsage(virCgroupPtr group G_GNUC_UNU= SED, } =20 =20 -int +static int virCgroupSetMemoryHardLimit(virCgroupPtr group G_GNUC_UNUSED, unsigned long long kb G_GNUC_UNUSED) { @@ -3149,7 +3149,7 @@ virCgroupGetMemoryHardLimit(virCgroupPtr group G_GNUC= _UNUSED, } =20 =20 -int +static int virCgroupSetMemorySoftLimit(virCgroupPtr group G_GNUC_UNUSED, unsigned long long kb G_GNUC_UNUSED) { @@ -3169,7 +3169,7 @@ virCgroupGetMemorySoftLimit(virCgroupPtr group G_GNUC= _UNUSED, } =20 =20 -int +static int virCgroupSetMemSwapHardLimit(virCgroupPtr group G_GNUC_UNUSED, unsigned long long kb G_GNUC_UNUSED) { @@ -3239,7 +3239,7 @@ virCgroupGetCpusetMemoryMigrate(virCgroupPtr group G_= GNUC_UNUSED, } =20 =20 -int +static int virCgroupSetCpusetCpus(virCgroupPtr group G_GNUC_UNUSED, const char *cpus G_GNUC_UNUSED) { diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 35a11e6b67..1607e951b1 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -145,11 +145,8 @@ int virCgroupGetMemoryStat(virCgroupPtr group, unsigned long long *unevictable); int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb); =20 -int virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long long kb); int virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long long *kb= ); -int virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned long long kb); int virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long long *kb= ); -int virCgroupSetMemSwapHardLimit(virCgroupPtr group, unsigned long long kb= ); int virCgroupGetMemSwapHardLimit(virCgroupPtr group, unsigned long long *k= b); int virCgroupGetMemSwapUsage(virCgroupPtr group, unsigned long long *kb); =20 @@ -223,7 +220,6 @@ int virCgroupGetCpusetMems(virCgroupPtr group, char **m= ems); int virCgroupSetCpusetMemoryMigrate(virCgroupPtr group, bool migrate); int virCgroupGetCpusetMemoryMigrate(virCgroupPtr group, bool *migrate); =20 -int virCgroupSetCpusetCpus(virCgroupPtr group, const char *cpus); int virCgroupGetCpusetCpus(virCgroupPtr group, char **cpus); =20 int virCgroupRemove(virCgroupPtr group); --=20 2.24.1 From nobody Fri Mar 29 06:30:50 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 1581372542250284.22549109994065; Mon, 10 Feb 2020 14:09:02 -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-32-Xt8_i2qCMKKLsuhfzOuVNA-1; Mon, 10 Feb 2020 17:08:57 -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 89B39800D48; Mon, 10 Feb 2020 22:08:52 +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 640928ED0B; Mon, 10 Feb 2020 22:08:52 +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 2225F18089D8; Mon, 10 Feb 2020 22:08:52 +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 01AM6E8e011140 for ; Mon, 10 Feb 2020 17:06:14 -0500 Received: by smtp.corp.redhat.com (Postfix) id DFD2B10F1CC8; Mon, 10 Feb 2020 22:06:13 +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 DB02510F1CA7 for ; Mon, 10 Feb 2020 22:06:11 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.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 57A811019291 for ; Mon, 10 Feb 2020 22:06:11 +0000 (UTC) Received: from mail-qt1-f195.google.com (mail-qt1-f195.google.com [209.85.160.195]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-344-WIkWjTsAPvGg6Uhr3owAtw-1; Mon, 10 Feb 2020 17:06:06 -0500 Received: by mail-qt1-f195.google.com with SMTP id n17so6464175qtv.2; Mon, 10 Feb 2020 14:05:56 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:3c07:1c6d:d4f2:46f3:c31d]) by smtp.gmail.com with ESMTPSA id z5sm970908qta.7.2020.02.10.14.05.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2020 14:05:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581372540; 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=2iH2HaYULjBH98ZvMTgfCckcJamqEYLt7QU6M9V6ZgI=; b=E60bEIOt95z0u2NBn/eVlKBDhYSSTShAOU8TyuIKCaxUQ01Z+Y0x/Fp6QR+5y6r9wWBGik F2an6L5EQD6Vzv8fx6HkyUAq6PWVQ5GJrHuwnJAMV4hkEe1NqqMIHOS8nMt+KPSo6mGNl/ yXQHa9k6a+vU9cSByjZslB4r1fVeBKM= 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=9zfu/5AApU1jSc8IK7r1rF/bE9BLWKZr1VS2tgXzsgg=; b=Zn5CxaUGkA7UdHO7ff2UJ645tJQ5S1fRL/ImGpA5vDLRAUCCqpKAdNbHvtcToDh3pF +AH5OmgolkRgeuf18ysHydLZxmJ9DWOBkDlqVhuee0znfjzlixvlQ6wdPt+1y6wD0X39 QSIJlhwO/PrDzfsFtoVyzLQTvFCKvaNZ+bfZYGwndloyiifrf77nyr3rvuytB8Pna0QE LUX6HcOkKVzCMPcES8MPkGIbTpFn4Igwg8NwIyvvZTYDQ4oi1J4ONgUpi/iPgEJfgXtg m1XLwViWUyH0Q9WoXxDiYRoIiWKX+dUBSw3MoDgHe4yxGrCx5hoW4tak6KurXo0yivnO boQQ== X-Gm-Message-State: APjAAAXszlGYE5qwi7itoZkmDpKT7d6/r4LG3OCNoC3ilqdGQejgMG1J TJLa1o4Q6bCQMAnznjmdPA4qgRUL5rY= X-Google-Smtp-Source: APXvYqy2FUWfjDyEFHbh5JRO7eWqfzxbE5/60Q0XqL9cZsanLdAFbmYSHFGzFM0KYMO6QgGIvVkEgw== X-Received: by 2002:ac8:1198:: with SMTP id d24mr11981960qtj.105.1581372356058; Mon, 10 Feb 2020 14:05:56 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v1 14/14] vircgroup: turn more cgroup functions static Date: Mon, 10 Feb 2020 19:05:20 -0300 Message-Id: <20200210220520.817666-15-danielhb413@gmail.com> In-Reply-To: <20200210220520.817666-1-danielhb413@gmail.com> References: <20200210220520.817666-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: WIkWjTsAPvGg6Uhr3owAtw-1 X-MC-Unique: Xt8_i2qCMKKLsuhfzOuVNA-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 01AM6E8e011140 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , 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" The new functions virCgroupSetAndRetrieveCpuShares(), virCgroupSetupCpuPeriodQuota() and virCgroupGetCpuPeriodQuota() centralized all callers of {get/set}Cpu{Shares,CfsPeriod,CfsQuota} to be inside vircgroup.c. Signed-off-by: Daniel Henrique Barboza --- src/libvirt_private.syms | 5 ----- src/util/vircgroup.c | 20 ++++++++++---------- src/util/vircgroup.h | 7 ------- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 1ec73a13c2..eff741fe23 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1678,8 +1678,6 @@ virCgroupGetBlkioWeight; virCgroupGetCpuacctPercpuUsage; virCgroupGetCpuacctStat; virCgroupGetCpuacctUsage; -virCgroupGetCpuCfsPeriod; -virCgroupGetCpuCfsQuota; virCgroupGetCpuPeriodQuota; virCgroupGetCpusetCpus; virCgroupGetCpusetMemoryMigrate; @@ -1710,11 +1708,8 @@ virCgroupNewThread; virCgroupPathOfController; virCgroupRemove; virCgroupSetAndRetrieveCpuShares; -virCgroupSetCpuCfsPeriod; -virCgroupSetCpuCfsQuota; virCgroupSetCpusetMemoryMigrate; virCgroupSetCpusetMems; -virCgroupSetCpuShares; virCgroupSetFreezerState; virCgroupSetMemory; virCgroupSetMemoryLimitParameters; diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index f0103d8062..c39f7b1957 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -2249,7 +2249,7 @@ virCgroupGetDomainTotalCpuStats(virCgroupPtr group, } =20 =20 -int +static int virCgroupSetCpuShares(virCgroupPtr group, unsigned long long shares) { VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPU, @@ -2273,7 +2273,7 @@ virCgroupGetCpuShares(virCgroupPtr group, unsigned lo= ng long *shares) * * Returns: 0 on success */ -int +static int virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned long long cfs_period) { VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPU, @@ -2289,7 +2289,7 @@ virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned= long long cfs_period) * * Returns: 0 on success */ -int +static int virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned long long *cfs_perio= d) { VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPU, @@ -2306,7 +2306,7 @@ virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned= long long *cfs_period) * * Returns: 0 on success */ -int +static int virCgroupSetCpuCfsQuota(virCgroupPtr group, long long cfs_quota) { VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPU, @@ -2660,7 +2660,7 @@ virCgroupKillPainfully(virCgroupPtr group) * * Returns: 0 on success */ -int +static int virCgroupGetCpuCfsQuota(virCgroupPtr group, long long *cfs_quota) { VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPU, @@ -3326,7 +3326,7 @@ virCgroupDenyDevicePath(virCgroupPtr group G_GNUC_UNU= SED, } =20 =20 -int +static int virCgroupSetCpuShares(virCgroupPtr group G_GNUC_UNUSED, unsigned long long shares G_GNUC_UNUSED) { @@ -3346,7 +3346,7 @@ virCgroupGetCpuShares(virCgroupPtr group G_GNUC_UNUSE= D, } =20 =20 -int +static int virCgroupSetCpuCfsPeriod(virCgroupPtr group G_GNUC_UNUSED, unsigned long long cfs_period G_GNUC_UNUSED) { @@ -3356,7 +3356,7 @@ virCgroupSetCpuCfsPeriod(virCgroupPtr group G_GNUC_UN= USED, } =20 =20 -int +static int virCgroupGetCpuCfsPeriod(virCgroupPtr group G_GNUC_UNUSED, unsigned long long *cfs_period G_GNUC_UNUSED) { @@ -3366,7 +3366,7 @@ virCgroupGetCpuCfsPeriod(virCgroupPtr group G_GNUC_UN= USED, } =20 =20 -int +static int virCgroupSetCpuCfsQuota(virCgroupPtr group G_GNUC_UNUSED, long long cfs_quota G_GNUC_UNUSED) { @@ -3404,7 +3404,7 @@ virCgroupKillPainfully(virCgroupPtr group G_GNUC_UNUS= ED) } =20 =20 -int +static int virCgroupGetCpuCfsQuota(virCgroupPtr group G_GNUC_UNUSED, long long *cfs_quota G_GNUC_UNUSED) { diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 1607e951b1..1a47c234de 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -197,15 +197,8 @@ virCgroupGetDomainTotalCpuStats(virCgroupPtr group, virTypedParameterPtr params, int nparams); =20 -int virCgroupSetCpuShares(virCgroupPtr group, unsigned long long shares); int virCgroupGetCpuShares(virCgroupPtr group, unsigned long long *shares); =20 -int virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned long long cfs_pe= riod); -int virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned long long *cfs_p= eriod); - -int virCgroupSetCpuCfsQuota(virCgroupPtr group, long long cfs_quota); -int virCgroupGetCpuCfsQuota(virCgroupPtr group, long long *cfs_quota); - int virCgroupGetCpuacctUsage(virCgroupPtr group, unsigned long long *usage= ); int virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, char **usage); int virCgroupGetCpuacctStat(virCgroupPtr group, unsigned long long *user, --=20 2.24.1