From nobody Tue Nov 26 06:56:51 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 1581975010170631.2888625429256; Mon, 17 Feb 2020 13:30:10 -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-10-B8xNtfaYOpumAf4V_h41eQ-1; Mon, 17 Feb 2020 16:30:06 -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 AE0718018A3; Mon, 17 Feb 2020 21:30:00 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7B27F90F6A; Mon, 17 Feb 2020 21:30:00 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 145B218089D6; Mon, 17 Feb 2020 21:30:00 +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 01HLTZu3031968 for ; Mon, 17 Feb 2020 16:29:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id A8D532166B2B; Mon, 17 Feb 2020 21:29:35 +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 A4C4D2166B27 for ; Mon, 17 Feb 2020 21:29:33 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8921F8012B3 for ; Mon, 17 Feb 2020 21:29:33 +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-111-NYMTarp7Mredol_gxHZ-_A-1; Mon, 17 Feb 2020 16:29:29 -0500 Received: by mail-qk1-f193.google.com with SMTP id b7so17583668qkl.7; Mon, 17 Feb 2020 13:29:29 -0800 (PST) Received: from rekt.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id i7sm872284qki.83.2020.02.17.13.29.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 13:29:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581975008; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=27v6Zb0M/14Fi9k6yxzaYLrb5tcfhbEvTUp98Tr5egs=; b=ihdenYbLs66LJoRPpLeUM/+ed0xykr+0cABJFyR36FJewg2F7hsG1urPrdr7Y8qEN04mr+ ubyJbfrUN1h+2Qa0qFCeh4n9Pcrfew2tfp4kzWpvFeDdejfduhQPeh4BmctTDrqzZaTWPh I/aMmQendyPqi9UQUUYPXDJDXovN3lI= 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=fpgAPSw2BkLAEAL8NjGLxFpx3Dt7qkmOd/zrhYe09dU=; b=Qc2WbYCSu6ukrNkS/rNr+0yZUTDMRMDMZQiK8BivfivLSMe0casAiY1LqOAOsoHI6R waV34VAnqK7etm/9ddte5f990wfuzIxMvOygmB9gzY5xZFi4+GIWTw2a80vFb5yk+RbI lTTBwT10LEvBmtwVRgjLHQrRQkA+C6sbyLKGmi6Kl8bTrv5Wjz76jpOncXn8mHwjxFu/ lFmmkM1II/ulGYVQFrlCOJCxBtVGqQj4e46WSzJWwZdl3bXnXwmydUn9KDv5yk+bhvba j61nZ8WoAY75rEenYZKGo36kYsDdiEnzz6rFsLJs3W913apKF2Xu1fJWGeGumJocrmjP gItQ== X-Gm-Message-State: APjAAAV6ja+QSgKYfE0F+8MtWnrj8EQFkZiv6kR+wYqlIj3fke4OVdwC iEZdRAjjWotTlRy+wzrwp1kT8PXbzvw= X-Google-Smtp-Source: APXvYqwLefbNXoBfgNTlzZDUpyiJEXmoUEdjncVOqJ1KFJuevBiG2N85kYjoqn+8XGrMK/mwT9qV5Q== X-Received: by 2002:a37:6d2:: with SMTP id 201mr15957690qkg.270.1581974968761; Mon, 17 Feb 2020 13:29:28 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 01/14] vircgroup.c: adding virCgroupSetupBlkioDevice* helpers Date: Mon, 17 Feb 2020 16:29:08 -0500 Message-Id: <20200217212921.251616-2-danielhb413@gmail.com> In-Reply-To: <20200217212921.251616-1-danielhb413@gmail.com> References: <20200217212921.251616-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: NYMTarp7Mredol_gxHZ-_A-1 X-MC-Unique: B8xNtfaYOpumAf4V_h41eQ-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 01HLTZu3031968 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , jtomko@redhat.com, crobinso@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The current use of the functions that sets and gets BlkioDevice attributes is doing a set(), following by a get() of the same parameter right after. This is done because there is no guarantee that the kernel will accept the desired value given by the set() call, thus we need to execute a get() right after to get the actual value. This patch adds helpers inside vircgroup.c to execute these operations. Next patch will use these helpers to reduce code repetition in LXC and QEMU files. Signed-off-by: Daniel Henrique Barboza Reviewed-by: J=C3=A1n Tomko --- src/libvirt_private.syms | 5 +++ src/util/vircgroup.c | 85 ++++++++++++++++++++++++++++++++++++++++ src/util/vircgroup.h | 20 ++++++++++ 3 files changed, 110 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 125d1836dd..e26bfab101 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1730,6 +1730,11 @@ virCgroupSetMemoryHardLimit; virCgroupSetMemorySoftLimit; virCgroupSetMemSwapHardLimit; virCgroupSetOwner; +virCgroupSetupBlkioDeviceReadBps; +virCgroupSetupBlkioDeviceReadIops; +virCgroupSetupBlkioDeviceWeight; +virCgroupSetupBlkioDeviceWriteBps; +virCgroupSetupBlkioDeviceWriteIops; virCgroupSupportsCpuBW; virCgroupTerminateMachine; =20 diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 0680ff7c24..302352aca3 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -3581,3 +3581,88 @@ virCgroupDelThread(virCgroupPtr cgroup, =20 return 0; } + + +/** + * Calls virCgroupSetBlkioDeviceWeight() to set up blkio device weight, + * then retrieves the actual value set by the kernel with + * virCgroupGetBlkioDeviceWeight() in the same @weight pointer. + */ +int +virCgroupSetupBlkioDeviceWeight(virCgroupPtr cgroup, const char *path, + unsigned int *weight) +{ + if (virCgroupSetBlkioDeviceWeight(cgroup, path, *weight) < 0 || + virCgroupGetBlkioDeviceWeight(cgroup, path, weight) < 0) + return -1; + + return 0; +} + + +/** + * Calls virCgroupSetBlkioDeviceReadIops() to set up blkio device riops, + * then retrieves the actual value set by the kernel with + * virCgroupGetBlkioDeviceReadIops() in the same @riops pointer. + */ +int +virCgroupSetupBlkioDeviceReadIops(virCgroupPtr cgroup, const char *path, + unsigned int *riops) +{ + if (virCgroupSetBlkioDeviceReadIops(cgroup, path, *riops) < 0 || + virCgroupGetBlkioDeviceReadIops(cgroup, path, riops) < 0) + return -1; + + return 0; +} + + +/** + * Calls virCgroupSetBlkioDeviceWriteIops() to set up blkio device wiops, + * then retrieves the actual value set by the kernel with + * virCgroupGetBlkioDeviceWriteIops() in the same @wiops pointer. + */ +int +virCgroupSetupBlkioDeviceWriteIops(virCgroupPtr cgroup, const char *path, + unsigned int *wiops) +{ + if (virCgroupSetBlkioDeviceWriteIops(cgroup, path, *wiops) < 0 || + virCgroupGetBlkioDeviceWriteIops(cgroup, path, wiops) < 0) + return -1; + + return 0; +} + + +/** + * Calls virCgroupSetBlkioDeviceReadBps() to set up blkio device rbps, + * then retrieves the actual value set by the kernel with + * virCgroupGetBlkioDeviceReadBps() in the same @rbps pointer. + */ +int +virCgroupSetupBlkioDeviceReadBps(virCgroupPtr cgroup, const char *path, + unsigned long long *rbps) +{ + if (virCgroupSetBlkioDeviceReadBps(cgroup, path, *rbps) < 0 || + virCgroupGetBlkioDeviceReadBps(cgroup, path, rbps) < 0) + return -1; + + return 0; +} + + +/** + * Calls virCgroupSetBlkioDeviceWriteBps() to set up blkio device wbps, + * then retrieves the actual value set by the kernel with + * virCgroupGetBlkioDeviceWriteBps() in the same @wbps pointer. + */ +int +virCgroupSetupBlkioDeviceWriteBps(virCgroupPtr cgroup, const char *path, + unsigned long long *wbps) +{ + if (virCgroupSetBlkioDeviceWriteBps(cgroup, path, *wbps) < 0 || + virCgroupGetBlkioDeviceWriteBps(cgroup, path, wbps) < 0) + return -1; + + return 0; +} diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 15263f534a..6bd3f4fe9d 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -175,6 +175,26 @@ int virCgroupGetBlkioDeviceWriteBps(virCgroupPtr group, const char *path, unsigned long long *wbps); =20 +int virCgroupSetupBlkioDeviceWeight(virCgroupPtr cgroup, + const char *path, + unsigned int *weight); + +int virCgroupSetupBlkioDeviceReadIops(virCgroupPtr cgroup, + const char *path, + unsigned int *riops); + +int virCgroupSetupBlkioDeviceWriteIops(virCgroupPtr cgroup, + const char *path, + unsigned int *wiops); + +int virCgroupSetupBlkioDeviceReadBps(virCgroupPtr cgroup, + const char *path, + unsigned long long *rbps); + +int virCgroupSetupBlkioDeviceWriteBps(virCgroupPtr cgroup, + 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 Tue Nov 26 06:56:51 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 158197499488838.610659013032546; Mon, 17 Feb 2020 13:29: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-33-bMA9cXzZNfuxnhfM5TLKKw-1; Mon, 17 Feb 2020 16:29:51 -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 D1C9718A8C88; Mon, 17 Feb 2020 21:29:45 +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 0B1F160C81; Mon, 17 Feb 2020 21:29:43 +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 A396935B03; Mon, 17 Feb 2020 21:29:38 +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 01HLTZIE031958 for ; Mon, 17 Feb 2020 16:29:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id 17D642026D69; Mon, 17 Feb 2020 21:29:35 +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 12A222026D67 for ; Mon, 17 Feb 2020 21:29:35 +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 E8187186E15B for ; Mon, 17 Feb 2020 21:29:34 +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-34-0j7m13JEP_mnIeRcvrbasw-1; Mon, 17 Feb 2020 16:29:30 -0500 Received: by mail-qk1-f194.google.com with SMTP id d11so17561203qko.8; Mon, 17 Feb 2020 13:29:30 -0800 (PST) Received: from rekt.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id i7sm872284qki.83.2020.02.17.13.29.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 13:29:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581974993; 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=Oj5ycssylyivE6+Bo6iiah0DWG6TekqK4ppeWBSgAPM=; b=LbzAPCOhi+g82ZvoPUQh8SAuF2WXOTIK1VL3dO/0sjVmuHZWTKgtm6aZ6SOjSunf+eMcAx BbcNhDPls/a0d16Hr2o5W1OXC9aDY2LtcYdtzOxlviC9m41vN8lhsYa3xTDNJbjeYjio6C sIYj2hNzVrv4SnmIsDw6SxYJebkwh3I= 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=gK03h+04NGbfFpvH4WXc0d/0H6Af0H6qzqYahz2CXQA=; b=DjlttRARIuT4hAw66ZE/dfrp8qIJyExSpdkRZkPGktLXFQ/aaj87yAO3IEZeHwCh2J AGLsxPfv1RIhfr06vg4MJh5KIX1cTlwnjf2H5m+5ce2BJczbfbO5knCq+6tzAUSqF3hR 1pmS3aMAskOJjeFBHhlWsg4oNn5dWmeDN2f56x+l7Wkg6d7d7dVCme6j/nvy81maK7yF yMUWyGKhNrJbOHl9YCCeMkVmeGpoH4jsq85RI3c4P1SzqWe9bNtbjqEbfTDTSv+cmsZA lSJFDQilFIuCAscH6fPrDCpWHPGDFOXJgfY+99tk89mBJVY7buy6+8TIQWdPrNwsU9eq /ZkA== X-Gm-Message-State: APjAAAUTpkPmX0vvQeLQnSvhZvKN82hie3EGV3hlGUganIHORTjw4UzI 6znCaZRCEJTSUQ0yH8YSZVQ61w85eqM= X-Google-Smtp-Source: APXvYqy18RBrtGPwb44/ozhnDICo9x9+rvbbqxxczpVm7aMVCH3iJ2YCRalDd1ziegULmV80QKOggA== X-Received: by 2002:a37:bfc5:: with SMTP id p188mr14588969qkf.283.1581974969630; Mon, 17 Feb 2020 13:29:29 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 02/14] lxc,qemu: use virCgroupSetupBlkioDevice* helpers Date: Mon, 17 Feb 2020 16:29:09 -0500 Message-Id: <20200217212921.251616-3-danielhb413@gmail.com> In-Reply-To: <20200217212921.251616-1-danielhb413@gmail.com> References: <20200217212921.251616-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: 0j7m13JEP_mnIeRcvrbasw-1 X-MC-Unique: bMA9cXzZNfuxnhfM5TLKKw-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 01HLTZIE031958 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , jtomko@redhat.com, crobinso@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" There are code repetition of set() and get() blkio device parameters across lxc and qemu files. Use the new vircgroup helpers to trim the repetition a bit. Signed-off-by: Daniel Henrique Barboza Reviewed-by: J=C3=A1n Tomko --- src/lxc/lxc_cgroup.c | 30 ++++++++++-------------------- src/lxc/lxc_driver.c | 41 +++++++++++------------------------------ src/qemu/qemu_cgroup.c | 32 ++++++++++++-------------------- src/qemu/qemu_driver.c | 41 +++++++++++------------------------------ 4 files changed, 44 insertions(+), 100 deletions(-) diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 7f3701593a..3c7e31c36b 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -112,38 +112,28 @@ static int virLXCCgroupSetupBlkioTune(virDomainDefPtr= def, virBlkioDevicePtr dev =3D &def->blkio.devices[i]; =20 if (dev->weight && - (virCgroupSetBlkioDeviceWeight(cgroup, dev->path, - dev->weight) < 0 || - virCgroupGetBlkioDeviceWeight(cgroup, dev->path, - &dev->weight) < 0)) + virCgroupSetupBlkioDeviceWeight(cgroup, dev->path, + &dev->weight) < 0) return -1; =20 if (dev->riops && - (virCgroupSetBlkioDeviceReadIops(cgroup, dev->path, - dev->riops) < 0 || - virCgroupGetBlkioDeviceReadIops(cgroup, dev->path, - &dev->riops) < 0)) + virCgroupSetupBlkioDeviceReadIops(cgroup, dev->path, + &dev->riops) < 0) return -1; =20 if (dev->wiops && - (virCgroupSetBlkioDeviceWriteIops(cgroup, dev->path, - dev->wiops) < 0 || - virCgroupGetBlkioDeviceWriteIops(cgroup, dev->path, - &dev->wiops) < 0)) + virCgroupSetupBlkioDeviceWriteIops(cgroup, dev->path, + &dev->wiops) < 0) return -1; =20 if (dev->rbps && - (virCgroupSetBlkioDeviceReadBps(cgroup, dev->path, - dev->rbps) < 0 || - virCgroupGetBlkioDeviceReadBps(cgroup, dev->path, - &dev->rbps) < 0)) + virCgroupSetupBlkioDeviceReadBps(cgroup, dev->path, + &dev->rbps) < 0) return -1; =20 if (dev->wbps && - (virCgroupSetBlkioDeviceWriteBps(cgroup, dev->path, - dev->wbps) < 0 || - virCgroupGetBlkioDeviceWriteBps(cgroup, dev->path, - &dev->wbps) < 0)) + virCgroupSetupBlkioDeviceWriteBps(cgroup, dev->path, + &dev->wbps) < 0) return -1; } } diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index f7376188f0..439cc317c6 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2581,6 +2581,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_I= OPS) || STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_BP= S) || STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_B= PS)) { + virCgroupPtr cgroup =3D priv->cgroup; size_t ndevices; virBlkioDevicePtr devices =3D NULL; size_t j; @@ -2595,60 +2596,40 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, =20 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) { + if (virCgroupSetupBlkioDeviceWeight(cgroup, device= s[j].path, + &devices[j].we= ight) < 0) { ret =3D -1; break; } } } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_REA= D_IOPS)) { for (j =3D 0; j < ndevices; j++) { - if (virCgroupSetBlkioDeviceReadIops(priv->cgroup, - devices[j].pat= h, - devices[j].rio= ps) < 0 || - virCgroupGetBlkioDeviceReadIops(priv->cgroup, - devices[j].pat= h, - &devices[j].ri= ops) < 0) { + if (virCgroupSetupBlkioDeviceReadIops(cgroup, devi= ces[j].path, + &devices[j].= riops) < 0) { ret =3D -1; break; } } } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRI= TE_IOPS)) { for (j =3D 0; j < ndevices; j++) { - if (virCgroupSetBlkioDeviceWriteIops(priv->cgroup, - devices[j].pa= th, - devices[j].wi= ops) < 0 || - virCgroupGetBlkioDeviceWriteIops(priv->cgroup, - devices[j].pa= th, - &devices[j].w= iops) < 0) { + if (virCgroupSetupBlkioDeviceWriteIops(cgroup, dev= ices[j].path, + &devices[j]= .wiops) < 0) { ret =3D -1; break; } } } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_REA= D_BPS)) { for (j =3D 0; j < ndevices; j++) { - if (virCgroupSetBlkioDeviceReadBps(priv->cgroup, - devices[j].path, - devices[j].rbps= ) < 0 || - virCgroupGetBlkioDeviceReadBps(priv->cgroup, - devices[j].path, - &devices[j].rbp= s) < 0) { + if (virCgroupSetupBlkioDeviceReadBps(cgroup, devic= es[j].path, + &devices[j].r= bps) < 0) { ret =3D -1; break; } } } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRI= TE_BPS)) { for (j =3D 0; j < ndevices; j++) { - if (virCgroupSetBlkioDeviceWriteBps(priv->cgroup, - devices[j].pat= h, - devices[j].wbp= s) < 0 || - virCgroupGetBlkioDeviceWriteBps(priv->cgroup, - devices[j].pat= h, - &devices[j].wb= ps) < 0) { + if (virCgroupSetupBlkioDeviceWriteBps(cgroup, devi= ces[j].path, + &devices[j].= wbps) < 0) { ret =3D -1; break; } diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 45701b4c6e..da96a60a08 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -611,39 +611,31 @@ qemuSetupBlkioCgroup(virDomainObjPtr vm) if (vm->def->blkio.ndevices) { for (i =3D 0; i < vm->def->blkio.ndevices; i++) { virBlkioDevicePtr dev =3D &vm->def->blkio.devices[i]; + virCgroupPtr cgroup =3D priv->cgroup; + if (dev->weight && - (virCgroupSetBlkioDeviceWeight(priv->cgroup, dev->path, - dev->weight) < 0 || - virCgroupGetBlkioDeviceWeight(priv->cgroup, dev->path, - &dev->weight) < 0)) + virCgroupSetupBlkioDeviceWeight(cgroup, dev->path, + &dev->weight) < 0) return -1; =20 if (dev->riops && - (virCgroupSetBlkioDeviceReadIops(priv->cgroup, dev->path, - dev->riops) < 0 || - virCgroupGetBlkioDeviceReadIops(priv->cgroup, dev->path, - &dev->riops) < 0)) + virCgroupSetupBlkioDeviceReadIops(cgroup, dev->path, + &dev->riops) < 0) return -1; =20 if (dev->wiops && - (virCgroupSetBlkioDeviceWriteIops(priv->cgroup, dev->path, - dev->wiops) < 0 || - virCgroupGetBlkioDeviceWriteIops(priv->cgroup, dev->path, - &dev->wiops) < 0)) + virCgroupSetupBlkioDeviceWriteIops(cgroup, dev->path, + &dev->wiops) < 0) return -1; =20 if (dev->rbps && - (virCgroupSetBlkioDeviceReadBps(priv->cgroup, dev->path, - dev->rbps) < 0 || - virCgroupGetBlkioDeviceReadBps(priv->cgroup, dev->path, - &dev->rbps) < 0)) + virCgroupSetupBlkioDeviceReadBps(cgroup, dev->path, + &dev->rbps) < 0) return -1; =20 if (dev->wbps && - (virCgroupSetBlkioDeviceWriteBps(priv->cgroup, dev->path, - dev->wbps) < 0 || - virCgroupGetBlkioDeviceWriteBps(priv->cgroup, dev->path, - &dev->wbps) < 0)) + virCgroupSetupBlkioDeviceWriteBps(cgroup, dev->path, + &dev->wbps) < 0) return -1; } } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f686b858cf..c1a79dcda6 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9564,6 +9564,7 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_I= OPS) || STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_BP= S) || STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_B= PS)) { + virCgroupPtr cgroup =3D priv->cgroup; size_t ndevices; virBlkioDevicePtr devices =3D NULL; size_t j; @@ -9578,60 +9579,40 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, =20 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) { + if (virCgroupSetupBlkioDeviceWeight(cgroup, device= s[j].path, + &devices[j].we= ight) < 0) { ret =3D -1; break; } } } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_REA= D_IOPS)) { for (j =3D 0; j < ndevices; j++) { - if (virCgroupSetBlkioDeviceReadIops(priv->cgroup, - devices[j].pat= h, - devices[j].rio= ps) < 0 || - virCgroupGetBlkioDeviceReadIops(priv->cgroup, - devices[j].pat= h, - &devices[j].ri= ops) < 0) { + if (virCgroupSetupBlkioDeviceReadIops(cgroup, devi= ces[j].path, + &devices[j].= riops) < 0) { ret =3D -1; break; } } } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRI= TE_IOPS)) { for (j =3D 0; j < ndevices; j++) { - if (virCgroupSetBlkioDeviceWriteIops(priv->cgroup, - devices[j].pa= th, - devices[j].wi= ops) < 0 || - virCgroupGetBlkioDeviceWriteIops(priv->cgroup, - devices[j].pa= th, - &devices[j].w= iops) < 0) { + if (virCgroupSetupBlkioDeviceWriteIops(cgroup, dev= ices[j].path, + &devices[j]= .wiops) < 0) { ret =3D -1; break; } } } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_REA= D_BPS)) { for (j =3D 0; j < ndevices; j++) { - if (virCgroupSetBlkioDeviceReadBps(priv->cgroup, - devices[j].path, - devices[j].rbps= ) < 0 || - virCgroupGetBlkioDeviceReadBps(priv->cgroup, - devices[j].path, - &devices[j].rbp= s) < 0) { + if (virCgroupSetupBlkioDeviceReadBps(cgroup, devic= es[j].path, + &devices[j].r= bps) < 0) { ret =3D -1; break; } } } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRI= TE_BPS)) { for (j =3D 0; j < ndevices; j++) { - if (virCgroupSetBlkioDeviceWriteBps(priv->cgroup, - devices[j].pat= h, - devices[j].wbp= s) < 0 || - virCgroupGetBlkioDeviceWriteBps(priv->cgroup, - devices[j].pat= h, - &devices[j].wb= ps) < 0) { + if (virCgroupSetupBlkioDeviceWriteBps(cgroup, devi= ces[j].path, + &devices[j].= wbps) < 0) { ret =3D -1; break; } --=20 2.24.1 From nobody Tue Nov 26 06:56:51 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 1581974995026777.1087076026456; Mon, 17 Feb 2020 13:29:55 -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-308-QkwIyLdRPRemU7oQri9atQ-1; Mon, 17 Feb 2020 16:29:51 -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 57F2C100726C; Mon, 17 Feb 2020 21:29:46 +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 055225DA60; Mon, 17 Feb 2020 21:29:46 +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 0C00335B07; Mon, 17 Feb 2020 21:29: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 01HLTZvW031967 for ; Mon, 17 Feb 2020 16:29:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9672F2166B2A; Mon, 17 Feb 2020 21:29:35 +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 91D742166B27 for ; Mon, 17 Feb 2020 21:29:35 +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 72BE2803006 for ; Mon, 17 Feb 2020 21:29:35 +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-213-mwoWifgOO4mJWh35jpNU6w-1; Mon, 17 Feb 2020 16:29:31 -0500 Received: by mail-qv1-f67.google.com with SMTP id l14so8207746qvu.12; Mon, 17 Feb 2020 13:29:31 -0800 (PST) Received: from rekt.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id i7sm872284qki.83.2020.02.17.13.29.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 13:29:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581974993; 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=mVZ71KAK3vmUwjFCHYC/fEOTKf6JvBnDEBeBMH1bypI=; b=O8//BSxbSWsW2YyMmeSA5iQRxVnAceA+FaHOuPBtpAqM+xGlKd/Z18R72HXLEZj1RCun+T RzlfreJZVCt74J/PyZNoLjEZ3qIlrrOIMHmVKyTw2Dyp3PAo5h17AIYA8AF8c2Yhj3Nzs2 JxcRNWY+XiBvFYUFElrvgFcv+i9te+4= 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=jFHKbv5p729A+2caWSDz0iBPDDPlJElgqlW5tZrv/rU=; b=WyHep2Nxne0TNFWB6wY1nJoGyrVardyVgJEWtrJugD/51TndAp2CscVasuv/7/s9Ee BoX0D1XghuAFszzQluXhSTWhZVO9LYUgN2FEuVUmggUFYqDuTUrWGfzeXG1Rskh5gFIJ 9X6inHDk+aIai+ev+rXAGgdV/MorXiHgmWW3Dj1OZOAX8NtEC/7MIw62/cTP7KwuCDxZ iPomlTTIOBcVP2HwL8EgKN7xLaaoK7m5cf7NAuAiYDmPxiPpJA8kjPWATc1yFu04fufu BUQVHoNsZX+HMsF4+5uBAhAU9FthgstAYT/kBYtKQtF75QDnJQ0jCHM2HnCZNpljL/ri dhnw== X-Gm-Message-State: APjAAAWpS9OZixrxd28mGj7uu1HcRiRFHZeaaeJ59H2RnvfK/hHdckxu jnDYuHwVlnY7vtR19X8U42KK61TnEbw= X-Google-Smtp-Source: APXvYqwyx53/JS4lIdBS1ll9unUMmZSMrJWmSDc+9euagVO6/873dgKt8M/VsgWri6Z1sKAX2NoaDA== X-Received: by 2002:a0c:ea92:: with SMTP id d18mr14156371qvp.201.1581974970468; Mon, 17 Feb 2020 13:29:30 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 03/14] vircgroup.c: turn virCgroup{Get/Set}BlkioDevice* into static Date: Mon, 17 Feb 2020 16:29:10 -0500 Message-Id: <20200217212921.251616-4-danielhb413@gmail.com> In-Reply-To: <20200217212921.251616-1-danielhb413@gmail.com> References: <20200217212921.251616-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: mwoWifgOO4mJWh35jpNU6w-1 X-MC-Unique: QkwIyLdRPRemU7oQri9atQ-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 01HLTZvW031967 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , jtomko@redhat.com, crobinso@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.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" Previous patch moved all duplicated code that were setting and getting BlkioDevice parameters to vircgroup.c. We can turn them into static and spare a few symbols in libvirt_private.syms. Signed-off-by: Daniel Henrique Barboza Reviewed-by: J=C3=A1n Tomko --- src/libvirt_private.syms | 10 ---------- src/util/vircgroup.c | 40 ++++++++++++++++++++-------------------- src/util/vircgroup.h | 40 ---------------------------------------- 3 files changed, 20 insertions(+), 70 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index e26bfab101..2bbfa4bd9d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1671,11 +1671,6 @@ virCgroupDenyAllDevices; virCgroupDenyDevice; virCgroupDenyDevicePath; virCgroupFree; -virCgroupGetBlkioDeviceReadBps; -virCgroupGetBlkioDeviceReadIops; -virCgroupGetBlkioDeviceWeight; -virCgroupGetBlkioDeviceWriteBps; -virCgroupGetBlkioDeviceWriteIops; virCgroupGetBlkioIoDeviceServiced; virCgroupGetBlkioIoServiced; virCgroupGetBlkioWeight; @@ -1712,11 +1707,6 @@ virCgroupNewSelf; virCgroupNewThread; virCgroupPathOfController; virCgroupRemove; -virCgroupSetBlkioDeviceReadBps; -virCgroupSetBlkioDeviceReadIops; -virCgroupSetBlkioDeviceWeight; -virCgroupSetBlkioDeviceWriteBps; -virCgroupSetBlkioDeviceWriteIops; virCgroupSetBlkioWeight; virCgroupSetCpuCfsPeriod; virCgroupSetCpuCfsQuota; diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 302352aca3..261e63f6ec 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1415,7 +1415,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) @@ -1433,7 +1433,7 @@ virCgroupSetBlkioDeviceReadIops(virCgroupPtr group, * * Returns: 0 on success, -1 on error */ -int +static int virCgroupSetBlkioDeviceWriteIops(virCgroupPtr group, const char *path, unsigned int wiops) @@ -1451,7 +1451,7 @@ virCgroupSetBlkioDeviceWriteIops(virCgroupPtr group, * * Returns: 0 on success, -1 on error */ -int +static int virCgroupSetBlkioDeviceReadBps(virCgroupPtr group, const char *path, unsigned long long rbps) @@ -1468,7 +1468,7 @@ virCgroupSetBlkioDeviceReadBps(virCgroupPtr group, * * Returns: 0 on success, -1 on error */ -int +static int virCgroupSetBlkioDeviceWriteBps(virCgroupPtr group, const char *path, unsigned long long wbps) @@ -1487,7 +1487,7 @@ virCgroupSetBlkioDeviceWriteBps(virCgroupPtr group, * * Returns: 0 on success, -1 on error */ -int +static int virCgroupSetBlkioDeviceWeight(virCgroupPtr group, const char *path, unsigned int weight) @@ -1504,7 +1504,7 @@ virCgroupSetBlkioDeviceWeight(virCgroupPtr group, * * Returns: 0 on success, -1 on error */ -int +static int virCgroupGetBlkioDeviceReadIops(virCgroupPtr group, const char *path, unsigned int *riops) @@ -1521,7 +1521,7 @@ virCgroupGetBlkioDeviceReadIops(virCgroupPtr group, * * Returns: 0 on success, -1 on error */ -int +static int virCgroupGetBlkioDeviceWriteIops(virCgroupPtr group, const char *path, unsigned int *wiops) @@ -1538,7 +1538,7 @@ virCgroupGetBlkioDeviceWriteIops(virCgroupPtr group, * * Returns: 0 on success, -1 on error */ -int +static int virCgroupGetBlkioDeviceReadBps(virCgroupPtr group, const char *path, unsigned long long *rbps) @@ -1555,7 +1555,7 @@ virCgroupGetBlkioDeviceReadBps(virCgroupPtr group, * * Returns: 0 on success, -1 on error */ -int +static int virCgroupGetBlkioDeviceWriteBps(virCgroupPtr group, const char *path, unsigned long long *wbps) @@ -1572,7 +1572,7 @@ virCgroupGetBlkioDeviceWriteBps(virCgroupPtr group, * * Returns: 0 on success, -1 on error */ -int +static int virCgroupGetBlkioDeviceWeight(virCgroupPtr group, const char *path, unsigned int *weight) @@ -2993,7 +2993,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) @@ -3003,7 +3003,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) @@ -3013,7 +3013,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) @@ -3023,7 +3023,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) @@ -3033,7 +3033,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) @@ -3043,7 +3043,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) @@ -3053,7 +3053,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) @@ -3063,7 +3063,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) @@ -3073,7 +3073,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) @@ -3083,7 +3083,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 6bd3f4fe9d..d50a8d69d4 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -135,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 virCgroupSetupBlkioDeviceWeight(virCgroupPtr cgroup, const char *path, unsigned int *weight); --=20 2.24.1 From nobody Tue Nov 26 06:56:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1581975009880161.37380210322; Mon, 17 Feb 2020 13:30:09 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-319-wTX96fTyO4-Qpixeozgt3g-1; Mon, 17 Feb 2020 16:30:06 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A815F100726F; Mon, 17 Feb 2020 21:30:00 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 72CEF60C99; Mon, 17 Feb 2020 21:30:00 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 12C8018089D5; Mon, 17 Feb 2020 21:30:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 01HLTZus031957 for ; Mon, 17 Feb 2020 16:29:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id DDDD4201808D; Mon, 17 Feb 2020 21:29:34 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D85132026D67 for ; Mon, 17 Feb 2020 21:29:34 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B8184802711 for ; Mon, 17 Feb 2020 21:29:34 +0000 (UTC) Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-354-gWsUHooVORyNr-TktXruJg-1; Mon, 17 Feb 2020 16:29:32 -0500 Received: by mail-qk1-f171.google.com with SMTP id c188so17592884qkg.4; Mon, 17 Feb 2020 13:29:31 -0800 (PST) Received: from rekt.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id i7sm872284qki.83.2020.02.17.13.29.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 13:29:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581975008; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=XNQxVJiQy076DuN6FP9sx9ytAAvzBf3EGBr6bKfjtqc=; b=BmjjkhdQtHHyZlQXv/SbA3ldagzD/ZS8aM3XXdxM4R4LraLtVSYwUieLtHd8kocGlY0pX7 msXpnQTU7YQQoELBKhkFhI5xtFtxHdhXqedNRJ8Bie18d368ax/VGa3k4XQuggBuyfH3Du uEDnms1k1oqqHyU1UC62uKn8KNhAHwc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0NghzWTjbvH2pi38fODXWjgERN5+CMNzigihg1pxnG4=; b=e9bDKNTKt3WuKM6UXAa8Q36ux2HfJpw6P8r24Nl2VuMaOcYsSYInbWJxvVBYdXYvUL Ly0YWDf9gCxlCSVi8wQzlFYbpuuWa9ed9Qd81kK2OGUV1kXeATu8+0rKXRA+ZcBEDa5D Rm+sjhnfUP/HGNzB+URDTYZ7QvKBZ7dWjCksF4bDqoZfUa4ORZAq+wzT+z0VNOQ1XZGi JeYP52ATSM1nYlwDNOu8GH6dw9fmwUzG8YkI/MufS3n7Bl1SHJhCJHSnyktxjy0XeG/I d42VrEBv1NP/QbAQ7bxtwwcX1g6p7RHaypEiapnFD0d7Bhi7NBqYWISbSfJHnb2t7tX4 TSWg== X-Gm-Message-State: APjAAAWZna+871Hvneju9BPShYZ02MGVxMSKepscCH6xauCmFRI5aK+h YRBsokvJaqfM7RGEtJXUEUJqfRfjmZU= X-Google-Smtp-Source: APXvYqzmZSt2lVh5zRnUv8WXiLC9D6jqxFc0BfND/4BRN8RMQLpvlbt4ZRdQvi+pmvP1pB+4T4p6Qw== X-Received: by 2002:a05:620a:4cc:: with SMTP id 12mr15684353qks.153.1581974971297; Mon, 17 Feb 2020 13:29:31 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 04/14] src: introducing hypervisor/domain_cgroup.c Date: Mon, 17 Feb 2020 16:29:11 -0500 Message-Id: <20200217212921.251616-5-danielhb413@gmail.com> In-Reply-To: <20200217212921.251616-1-danielhb413@gmail.com> References: <20200217212921.251616-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: gWsUHooVORyNr-TktXruJg-1 X-MC-Unique: wTX96fTyO4-Qpixeozgt3g-1 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 01HLTZus031957 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , jtomko@redhat.com, crobinso@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" There is duplicated code between virt drivers that needs to be moved to avoid code repetition. In the case of duplicated code between lxc_cgroup.c and qemu_cgroup.c a common place would be utils/vircgroup.c. The problem is that this would introduce /conf related definitions that shouldn't be imported to vircgroup.c, which is supposed to be a place for utilitary cgroups functions only. And syntax-check would forbid it anyway due to cross-directory includes being used. An alternative would be to overload domain_conf.c, which already contains all the definitions required. But that file is already crowded with XML handling code and we wouldn't do any favors to it by putting more utilitary, non-XML parsing/formatting code there. In [1], Colesuggested a 'domain_cgroup' file to host common code between lxc_cgroup and qemu_cgroup, and Daniel suggested a 'src/hypervisor' dir to host these type of files. This patch introduces src/hypervisor/domain_cgroup.c and, to get started, introduces a new virDomainCgroupSetupBlkio() function to host shared code between virLXCCgroupSetupBlkioTune() and qemuSetupBlkioCgroup(). [1] https://www.redhat.com/archives/libvir-list/2019-December/msg00817.html Signed-off-by: Daniel Henrique Barboza Reviewed-by: J=C3=A1n Tomko --- src/Makefile.am | 1 + src/hypervisor/Makefile.inc.am | 14 +++++++ src/hypervisor/domain_cgroup.c | 67 ++++++++++++++++++++++++++++++++++ src/hypervisor/domain_cgroup.h | 27 ++++++++++++++ src/libvirt_private.syms | 4 ++ src/lxc/Makefile.inc.am | 2 + src/lxc/lxc_cgroup.c | 40 +------------------- src/qemu/Makefile.inc.am | 1 + src/qemu/qemu_cgroup.c | 40 +------------------- 9 files changed, 120 insertions(+), 76 deletions(-) create mode 100644 src/hypervisor/Makefile.inc.am create mode 100644 src/hypervisor/domain_cgroup.c create mode 100644 src/hypervisor/domain_cgroup.h diff --git a/src/Makefile.am b/src/Makefile.am index 952dfdbb5f..12dd6b80e1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -108,6 +108,7 @@ include locking/Makefile.inc.am include admin/Makefile.inc.am include rpc/Makefile.inc.am include test/Makefile.inc.am +include hypervisor/Makefile.inc.am include esx/Makefile.inc.am include hyperv/Makefile.inc.am include vmx/Makefile.inc.am diff --git a/src/hypervisor/Makefile.inc.am b/src/hypervisor/Makefile.inc.am new file mode 100644 index 0000000000..961b4e2b95 --- /dev/null +++ b/src/hypervisor/Makefile.inc.am @@ -0,0 +1,14 @@ +# vim: filetype=3Dautomake + +HYPERVISOR_SOURCES =3D \ + hypervisor/domain_cgroup.h \ + hypervisor/domain_cgroup.c \ + $(NULL) + +noinst_LTLIBRARIES +=3D libvirt_hypervisor.la +libvirt_la_BUILT_LIBADD +=3D libvirt_hypervisor.la +libvirt_hypervisor_la_CFLAGS =3D \ + -I$(srcdir)/conf \ + $(AM_CFLAGS) \ + $(NULL) +libvirt_hypervisor_la_SOURCES =3D $(HYPERVISOR_SOURCES) diff --git a/src/hypervisor/domain_cgroup.c b/src/hypervisor/domain_cgroup.c new file mode 100644 index 0000000000..bef60f56c5 --- /dev/null +++ b/src/hypervisor/domain_cgroup.c @@ -0,0 +1,67 @@ +/* + * domain_cgroup.c: cgroup functions shared between hypervisor drivers + * + * Copyright IBM Corp. 2020 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include "domain_cgroup.h" + + +int +virDomainCgroupSetupBlkio(virCgroupPtr cgroup, virDomainBlkiotune blkio) +{ + size_t i; + + if (blkio.weight !=3D 0 && + virCgroupSetBlkioWeight(cgroup, blkio.weight) < 0) + return -1; + + if (blkio.ndevices) { + for (i =3D 0; i < blkio.ndevices; i++) { + virBlkioDevicePtr dev =3D &blkio.devices[i]; + + if (dev->weight && + virCgroupSetupBlkioDeviceWeight(cgroup, dev->path, + &dev->weight) < 0) + return -1; + + if (dev->riops && + virCgroupSetupBlkioDeviceReadIops(cgroup, dev->path, + &dev->riops) < 0) + return -1; + + if (dev->wiops && + virCgroupSetupBlkioDeviceWriteIops(cgroup, dev->path, + &dev->wiops) < 0) + return -1; + + if (dev->rbps && + virCgroupSetupBlkioDeviceReadBps(cgroup, dev->path, + &dev->rbps) < 0) + return -1; + + if (dev->wbps && + virCgroupSetupBlkioDeviceWriteBps(cgroup, dev->path, + &dev->wbps) < 0) + return -1; + } + } + + return 0; +} diff --git a/src/hypervisor/domain_cgroup.h b/src/hypervisor/domain_cgroup.h new file mode 100644 index 0000000000..af244bd2d2 --- /dev/null +++ b/src/hypervisor/domain_cgroup.h @@ -0,0 +1,27 @@ +/* + * domain_cgroup.h: cgroup functions shared between hypervisor drivers + * + * Copyright IBM Corp. 2020 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#pragma once + +#include "vircgroup.h" +#include "domain_conf.h" + + +int virDomainCgroupSetupBlkio(virCgroupPtr cgroup, virDomainBlkiotune blki= o); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 2bbfa4bd9d..dc06b1ae24 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1389,6 +1389,10 @@ virSetConnectSecret; virSetConnectStorage; =20 =20 +# hypervisor/domain_cgroup.h +virDomainCgroupSetupBlkio; + + # libvirt_internal.h virConnectSupportsFeature; virDomainMigrateBegin3; diff --git a/src/lxc/Makefile.inc.am b/src/lxc/Makefile.inc.am index f69c1acff5..2fee607d3d 100644 --- a/src/lxc/Makefile.inc.am +++ b/src/lxc/Makefile.inc.am @@ -97,6 +97,7 @@ libvirt_driver_lxc_impl_la_CFLAGS =3D \ -I$(srcdir)/conf \ -I$(builddir)/lxc \ -I$(builddir)/rpc \ + -I$(srcdir)/hypervisor \ $(AM_CFLAGS) \ $(NULL) libvirt_driver_lxc_impl_la_LIBADD =3D \ @@ -221,6 +222,7 @@ libvirt_lxc_CFLAGS =3D \ -I$(srcdir)/conf \ -I$(builddir)/lxc \ -I$(builddir)/rpc \ + -I$(srcdir)/hypervisor \ $(AM_CFLAGS) \ $(PIE_CFLAGS) \ $(CAPNG_CFLAGS) \ diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 3c7e31c36b..96a89256a1 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -23,6 +23,7 @@ =20 #include "lxc_cgroup.h" #include "lxc_container.h" +#include "domain_cgroup.h" #include "virfile.h" #include "virerror.h" #include "virlog.h" @@ -101,44 +102,7 @@ static int virLXCCgroupSetupCpusetTune(virDomainDefPtr= def, static int virLXCCgroupSetupBlkioTune(virDomainDefPtr def, virCgroupPtr cgroup) { - size_t i; - - if (def->blkio.weight && - virCgroupSetBlkioWeight(cgroup, def->blkio.weight) < 0) - return -1; - - if (def->blkio.ndevices) { - for (i =3D 0; i < def->blkio.ndevices; i++) { - virBlkioDevicePtr dev =3D &def->blkio.devices[i]; - - if (dev->weight && - virCgroupSetupBlkioDeviceWeight(cgroup, dev->path, - &dev->weight) < 0) - return -1; - - if (dev->riops && - virCgroupSetupBlkioDeviceReadIops(cgroup, dev->path, - &dev->riops) < 0) - return -1; - - if (dev->wiops && - virCgroupSetupBlkioDeviceWriteIops(cgroup, dev->path, - &dev->wiops) < 0) - return -1; - - if (dev->rbps && - virCgroupSetupBlkioDeviceReadBps(cgroup, dev->path, - &dev->rbps) < 0) - return -1; - - if (dev->wbps && - virCgroupSetupBlkioDeviceWriteBps(cgroup, dev->path, - &dev->wbps) < 0) - return -1; - } - } - - return 0; + return virDomainCgroupSetupBlkio(cgroup, def->blkio); } =20 =20 diff --git a/src/qemu/Makefile.inc.am b/src/qemu/Makefile.inc.am index b9c0c6ea9c..94a333f855 100644 --- a/src/qemu/Makefile.inc.am +++ b/src/qemu/Makefile.inc.am @@ -98,6 +98,7 @@ libvirt_driver_qemu_impl_la_CFLAGS =3D \ -I$(builddir)/access \ -I$(srcdir)/conf \ -I$(srcdir)/secret \ + -I$(srcdir)/hypervisor \ $(AM_CFLAGS) \ $(NULL) libvirt_driver_qemu_impl_la_LDFLAGS =3D $(AM_LDFLAGS) diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index da96a60a08..475c063823 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -30,6 +30,7 @@ #include "viralloc.h" #include "virerror.h" #include "domain_audit.h" +#include "domain_cgroup.h" #include "virscsi.h" #include "virstring.h" #include "virfile.h" @@ -591,7 +592,6 @@ static int qemuSetupBlkioCgroup(virDomainObjPtr vm) { qemuDomainObjPrivatePtr priv =3D vm->privateData; - size_t i; =20 if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_BLKIO)) { @@ -604,43 +604,7 @@ qemuSetupBlkioCgroup(virDomainObjPtr vm) } } =20 - if (vm->def->blkio.weight !=3D 0 && - virCgroupSetBlkioWeight(priv->cgroup, vm->def->blkio.weight) < 0) - return -1; - - if (vm->def->blkio.ndevices) { - for (i =3D 0; i < vm->def->blkio.ndevices; i++) { - virBlkioDevicePtr dev =3D &vm->def->blkio.devices[i]; - virCgroupPtr cgroup =3D priv->cgroup; - - if (dev->weight && - virCgroupSetupBlkioDeviceWeight(cgroup, dev->path, - &dev->weight) < 0) - return -1; - - if (dev->riops && - virCgroupSetupBlkioDeviceReadIops(cgroup, dev->path, - &dev->riops) < 0) - return -1; - - if (dev->wiops && - virCgroupSetupBlkioDeviceWriteIops(cgroup, dev->path, - &dev->wiops) < 0) - return -1; - - if (dev->rbps && - virCgroupSetupBlkioDeviceReadBps(cgroup, dev->path, - &dev->rbps) < 0) - return -1; - - if (dev->wbps && - virCgroupSetupBlkioDeviceWriteBps(cgroup, dev->path, - &dev->wbps) < 0) - return -1; - } - } - - return 0; + return virDomainCgroupSetupBlkio(priv->cgroup, vm->def->blkio); } =20 =20 --=20 2.24.1 From nobody Tue Nov 26 06:56:51 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 1581975016292356.5507681085172; Mon, 17 Feb 2020 13:30:16 -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-179-VVK1WMInP6W-8ljc8N0bzw-1; Mon, 17 Feb 2020 16:30:13 -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 486C9801E67; Mon, 17 Feb 2020 21:30:07 +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 021BB5DA76; Mon, 17 Feb 2020 21:30:07 +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 85F9935B09; Mon, 17 Feb 2020 21:30:06 +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 01HLTbEe031992 for ; Mon, 17 Feb 2020 16:29:37 -0500 Received: by smtp.corp.redhat.com (Postfix) id 99C7410E60DF; Mon, 17 Feb 2020 21:29:37 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 950021003342 for ; Mon, 17 Feb 2020 21:29:35 +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 0FF7D8026E3 for ; Mon, 17 Feb 2020 21:29:35 +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-305-EstgAPnDMk-zAX_1zrvRkQ-1; Mon, 17 Feb 2020 16:29:32 -0500 Received: by mail-qv1-f68.google.com with SMTP id n8so8201813qvg.11; Mon, 17 Feb 2020 13:29:32 -0800 (PST) Received: from rekt.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id i7sm872284qki.83.2020.02.17.13.29.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 13:29:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581975015; 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=TaluYkgBZazlzuwVmFq3zdIf0tPdsYfuNbFSZSZpP9M=; b=OWvFkux9LUgobuca8TXEII4t/fVWa1NXPqByXvgRIgO604fg6K4KDwYu/TQ14FSCbxhhjH 8msbR8f1GZz15LlG7qLS4lI/JweShnQy24nD8s458p2qz80+YAwY8KZhjpohQLdEWx14oV wPj7W1DGtUMybMy0yq1Kgyz5LPVzEEg= 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=YDSPrc6zUPSrXAJj1rpCVw/NxCKjC4eFzZnQnTzRJog=; b=NIWBMQXtF9DnC6I3a+XgqmsmmAw/pHyRIIZ9gPvxkwPWBTUw7ss3jkJ0gYp48BYrXj KCjV29pi4wpfDMYrsM+wETkA1Wqvne8ZhiOG464I///+u9NfYL1dgmonpjo7ASx7xbxM MGDY/usNpb72SSlFDQh/ObM7ZhkRMH3jK2cjnWOaEndoZN4WuyUA4R44q5Wmp7F87Xsb jyH7USM6CLz5RhQuzBCYRRcq8Hgxbj6btL5Sg1fIfajDnSmINck1LprWcp1CcOpBWRcF Yhav08v7mWgy3GjBjhOmdezqOF7ZhFp1f6TB/HZxXlPCr4Y/FweGVDtLT1KAu32VjlaK k+ww== X-Gm-Message-State: APjAAAXY9k14ISwjr9jMZ0vCYoS8SUm5y9skinVvRaBHPKcBvMX7YUTd IpsgQ6F+vjRnNepJ4MbLoIMJ0+QmUVc= X-Google-Smtp-Source: APXvYqx0P+yUHm6+WUr+FdDboFddsy8YHmErxSm7b9ZD+Y1JFbTtRBZjbzXgiPcitlA/qiBeolI7jg== X-Received: by 2002:a0c:e408:: with SMTP id o8mr14427672qvl.236.1581974972156; Mon, 17 Feb 2020 13:29:32 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 05/14] domain_cgroup.c: add virDomainCgroupSetupMemtune() Date: Mon, 17 Feb 2020 16:29:12 -0500 Message-Id: <20200217212921.251616-6-danielhb413@gmail.com> In-Reply-To: <20200217212921.251616-1-danielhb413@gmail.com> References: <20200217212921.251616-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: EstgAPnDMk-zAX_1zrvRkQ-1 X-MC-Unique: VVK1WMInP6W-8ljc8N0bzw-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 01HLTbEe031992 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , jtomko@redhat.com, crobinso@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.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" virLXCCgroupSetupMemTune() and qemuSetupMemoryCgroup() shares duplicated code that can be put in a new helper to avoid code repetition. Signed-off-by: Daniel Henrique Barboza Reviewed-by: J=C3=A1n Tomko --- src/hypervisor/domain_cgroup.c | 19 +++++++++++++++++++ src/hypervisor/domain_cgroup.h | 1 + src/libvirt_private.syms | 1 + src/lxc/lxc_cgroup.c | 14 +------------- src/qemu/qemu_cgroup.c | 14 +------------- 5 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/hypervisor/domain_cgroup.c b/src/hypervisor/domain_cgroup.c index bef60f56c5..e60abd536c 100644 --- a/src/hypervisor/domain_cgroup.c +++ b/src/hypervisor/domain_cgroup.c @@ -65,3 +65,22 @@ virDomainCgroupSetupBlkio(virCgroupPtr cgroup, virDomain= Blkiotune blkio) =20 return 0; } + + +int +virDomainCgroupSetupMemtune(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/hypervisor/domain_cgroup.h b/src/hypervisor/domain_cgroup.h index af244bd2d2..82ba47e85f 100644 --- a/src/hypervisor/domain_cgroup.h +++ b/src/hypervisor/domain_cgroup.h @@ -25,3 +25,4 @@ =20 =20 int virDomainCgroupSetupBlkio(virCgroupPtr cgroup, virDomainBlkiotune blki= o); +int virDomainCgroupSetupMemtune(virCgroupPtr cgroup, virDomainMemtune mem); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index dc06b1ae24..1bc5d17000 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1391,6 +1391,7 @@ virSetConnectStorage; =20 # hypervisor/domain_cgroup.h virDomainCgroupSetupBlkio; +virDomainCgroupSetupMemtune; =20 =20 # libvirt_internal.h diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 96a89256a1..eac1ee1ee0 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -112,19 +112,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 virDomainCgroupSetupMemtune(cgroup, def->mem); } =20 =20 diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 475c063823..0c2f5f1b25 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -625,19 +625,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 virDomainCgroupSetupMemtune(priv->cgroup, vm->def->mem); } =20 =20 --=20 2.24.1 From nobody Tue Nov 26 06:56:51 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 1581975064335361.28077563885165; Mon, 17 Feb 2020 13:31:04 -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-314-LaDWHZoINjuqZTdGBo7ziA-1; Mon, 17 Feb 2020 16:30:12 -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 32E58800EBB; Mon, 17 Feb 2020 21:30:07 +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 E4DFB90F6C; Mon, 17 Feb 2020 21:30:06 +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 6AC7118089D8; Mon, 17 Feb 2020 21:30:06 +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 01HLTa41031980 for ; Mon, 17 Feb 2020 16:29:36 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1FA642026D69; Mon, 17 Feb 2020 21:29:36 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1A8E92026D67 for ; Mon, 17 Feb 2020 21:29:36 +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 F4216800F25 for ; Mon, 17 Feb 2020 21:29:35 +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-340-6-fiPve-O0u8_PCxQH6MeQ-1; Mon, 17 Feb 2020 16:29:33 -0500 Received: by mail-qv1-f67.google.com with SMTP id p2so8219977qvo.10; Mon, 17 Feb 2020 13:29:33 -0800 (PST) Received: from rekt.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id i7sm872284qki.83.2020.02.17.13.29.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 13:29:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581975062; 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=aJs54mh0O915cL0pYSMc19WQ57/Yye4plcTfGSr+qTo=; b=BrNVHTEoqKiyDho1PJMCFPYwhT49uvMK4kFZroa2jj0iiJrQDUV64it3I7+UsDqnk4sfRr 445qbwYoU/nTQRY2CLPneQrA3RK8R3d+Q5219DJ2+F35L1iDqP6m+iGdiZWKOD2MoaSD4P QYqISMnMxlUTko60ydC8kq/GNvwgf84= 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=2/40uXN8nxxVzodVpCikgAjtqme6wj+T4EYj6b6OZAs=; b=nrWw1rRLgprnBqe06lXrA2AvKKTP0osC6Nk/ZVeELxbVFyERC+YlHQ0MUDRfms8Zna BoNENn5qcQzVZa/JY7u4HfYP3MV551pEeMDrq8PeXwyZbC0VTYWoCPLjwI/1k5E7TAko zo5x2uYJOQcSMnUiGsd9XgRmqTewVPLk2wrQUexH5lKCOwiu7JVfZre4rgNPwKtjvwAC JVVSsl7rHlLcQgnNzDa1j8aMfgRCwAsEBfhaU2h6xnnAk2woaDDMtmaGDYLX4s+l4BKQ u5CT/OxXR32qkDIzj+ndyoZs9r/MYazODfgWZM9kXsBUcqqXNcVo2njGfkbKE7xXsyJC vqYg== X-Gm-Message-State: APjAAAWjvWKuNI6c441GYOBdoV2ybXKnLSQB5ztC2XNdrSX6zfpqBt5J El3UJ4XtbWCGLqc1dOQC7gJHG5NxoO8= X-Google-Smtp-Source: APXvYqyPq4b6ejGXVdIfkR27Q++6AnnBx6JJobFV2fQCMAe/bWAGMEsZQJN/800HJOOsuuRuD3QgLg== X-Received: by 2002:ad4:4d85:: with SMTP id cv5mr13839698qvb.171.1581974972879; Mon, 17 Feb 2020 13:29:32 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 06/14] vircgroup.c: add virCgroupSetupCpusetCpus() Date: Mon, 17 Feb 2020 16:29:13 -0500 Message-Id: <20200217212921.251616-7-danielhb413@gmail.com> In-Reply-To: <20200217212921.251616-1-danielhb413@gmail.com> References: <20200217212921.251616-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: 6-fiPve-O0u8_PCxQH6MeQ-1 X-MC-Unique: LaDWHZoINjuqZTdGBo7ziA-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 01HLTa41031980 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , jtomko@redhat.com, crobinso@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The code from qemuSetupCgroupCpusetCpus() and virLXCCgroupSetupCpusetTune() can be centralized in a new helper called virCgroupSetupCpusetCpus(). Signed-off-by: Daniel Henrique Barboza Reviewed-by: J=C3=A1n Tomko --- 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 1bc5d17000..a58a5ed78b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1730,6 +1730,7 @@ virCgroupSetupBlkioDeviceReadIops; virCgroupSetupBlkioDeviceWeight; virCgroupSetupBlkioDeviceWriteBps; virCgroupSetupBlkioDeviceWriteIops; +virCgroupSetupCpusetCpus; virCgroupSupportsCpuBW; virCgroupTerminateMachine; =20 diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index eac1ee1ee0..618063bf43 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -69,14 +69,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 0c2f5f1b25..ee08b99064 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -1165,19 +1165,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 261e63f6ec..dcbd55c0f1 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -3666,3 +3666,18 @@ virCgroupSetupBlkioDeviceWriteBps(virCgroupPtr cgrou= p, const char *path, =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 d50a8d69d4..55132dedb6 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -245,6 +245,7 @@ int virCgroupGetCpusetMemoryMigrate(virCgroupPtr group,= bool *migrate); =20 int virCgroupSetCpusetCpus(virCgroupPtr group, const char *cpus); int virCgroupGetCpusetCpus(virCgroupPtr group, char **cpus); +int virCgroupSetupCpusetCpus(virCgroupPtr cgroup, virBitmapPtr cpumask); =20 int virCgroupRemove(virCgroupPtr group); =20 --=20 2.24.1 From nobody Tue Nov 26 06:56:51 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 1581975026155228.58734376346592; Mon, 17 Feb 2020 13:30:26 -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-365-gbqmqmnxPS63D4BF0RhOwQ-1; Mon, 17 Feb 2020 16:30:20 -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 1C6738017DF; Mon, 17 Feb 2020 21:30:14 +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 DBA458B55D; Mon, 17 Feb 2020 21:30:13 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 828A8180887A; Mon, 17 Feb 2020 21:30:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 01HLTc4Z032004 for ; Mon, 17 Feb 2020 16:29:38 -0500 Received: by smtp.corp.redhat.com (Postfix) id A375F2166B2A; Mon, 17 Feb 2020 21:29:38 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9F35C2166B27 for ; Mon, 17 Feb 2020 21:29:38 +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 852E2900844 for ; Mon, 17 Feb 2020 21:29:38 +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-419-3NgwwkvlPki9ZeGVUHUacg-1; Mon, 17 Feb 2020 16:29:34 -0500 Received: by mail-qk1-f196.google.com with SMTP id o28so16256481qkj.9; Mon, 17 Feb 2020 13:29:34 -0800 (PST) Received: from rekt.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id i7sm872284qki.83.2020.02.17.13.29.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 13:29:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581975025; 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=ySyM0t+4MgRf9rcFPrQ8tebUBkBV/CKDtL1kbGAV8v4=; b=aOzpIfJuxKnJRagv8z1hq4ENqjEOT7K1JqcMb7NLgsAf+fe2g6nVr60GjhNpEAXegKjPsn 4Ees7EUZ5HGwpFafY5k/wcqsHS7zo5TKq9VSqbLvFI5nQxrImeJ8Jq1+lck7sTILkpMWow /CBHysDzD45tsWgSSk6TavSMzOtocqs= 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=ZbEFjeF9eWNoGNeJXO5J9Dk8wFwp7h/XvaIBNMEUTZ0=; b=MBljEVYUMGKsVL5HqMvt6p/b8PdbEuXzHALl6S0JCy1rgw69TbBDXI6SilKZzLfxDC EeeOhqTJNlt2QL1cnz+HjPHYU2cdgAFEFBjxJJwojWha/4fqht0jjfoxyrZ1FQla6Eai bLzGkEYVd/MIwtbmI6L3LdrZQKM7YFSfYSdLkUEVmLcOu54WnhaMH7H6AoVaPh1f87zX R61G9xfSbC9A2s/hLFE4U7bwtm4l9UR1g3IY/AhK/Mir7XJ445DRObcYhJro7KxSsyFg A2V4UuKPjLEXAbAw9usm1qAqYgIBbERBpG1czYZnJu3qC+HR6S4zJvaAaKbeQwV3CtX+ fPnQ== X-Gm-Message-State: APjAAAWiA5t/g59MUTlrI7Z0ek/oOO2Pt8RorvWaqY3l+L0MkA0qeaaG cdH89TBvZ5RRbhSe3nB38qylVxeR/cs= X-Google-Smtp-Source: APXvYqzpJJe7xWwRE5lyAi8QSDrazxdcKSefB9vo3qTnbR5HNZE3WyGf3KyqGHvmQlqlzIhIQgSTvQ== X-Received: by 2002:a37:aa8c:: with SMTP id t134mr15799415qke.243.1581974973695; Mon, 17 Feb 2020 13:29:33 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 07/14] vircgroup.c: add virCgroupSetupCpuShares() Date: Mon, 17 Feb 2020 16:29:14 -0500 Message-Id: <20200217212921.251616-8-danielhb413@gmail.com> In-Reply-To: <20200217212921.251616-1-danielhb413@gmail.com> References: <20200217212921.251616-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: 3NgwwkvlPki9ZeGVUHUacg-1 X-MC-Unique: gbqmqmnxPS63D4BF0RhOwQ-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 01HLTc4Z032004 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , jtomko@redhat.com, crobinso@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.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 virCgroupSetupCpuShares() 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 Reviewed-by: J=C3=A1n Tomko --- src/libvirt_private.syms | 1 + src/lxc/lxc_cgroup.c | 5 +---- src/lxc/lxc_driver.c | 6 ++---- src/qemu/qemu_cgroup.c | 5 ++--- src/qemu/qemu_driver.c | 5 +---- src/util/vircgroup.c | 20 ++++++++++++++++++++ src/util/vircgroup.h | 2 ++ 7 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a58a5ed78b..8be5fe7d9f 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1731,6 +1731,7 @@ virCgroupSetupBlkioDeviceWeight; virCgroupSetupBlkioDeviceWriteBps; virCgroupSetupBlkioDeviceWriteIops; virCgroupSetupCpusetCpus; +virCgroupSetupCpuShares; virCgroupSupportsCpuBW; virCgroupTerminateMachine; =20 diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 618063bf43..4c8464bd97 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -40,10 +40,7 @@ static int virLXCCgroupSetupCpuTune(virDomainDefPtr def, { if (def->cputune.sharesSpecified) { unsigned long long val; - if (virCgroupSetCpuShares(cgroup, def->cputune.shares) < 0) - return -1; - - if (virCgroupGetCpuShares(cgroup, &val) < 0) + if (virCgroupSetupCpuShares(cgroup, def->cputune.shares, &val) < 0) return -1; def->cputune.shares =3D val; } diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 439cc317c6..e66aa7b8f5 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1959,10 +1959,8 @@ 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 (virCgroupSetupCpuShares(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 ee08b99064..f969469931 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -894,11 +894,10 @@ qemuSetupCpuCgroup(virDomainObjPtr vm) =20 if (vm->def->cputune.sharesSpecified) { unsigned long long val; - if (virCgroupSetCpuShares(priv->cgroup, vm->def->cputune.shares) <= 0) + if (virCgroupSetupCpuShares(priv->cgroup, vm->def->cputune.shares, + &val) < 0) return -1; =20 - if (virCgroupGetCpuShares(priv->cgroup, &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 c1a79dcda6..e9feb50220 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -10648,10 +10648,7 @@ 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 (virCgroupSetupCpuShares(priv->cgroup, value_ul, &val) = < 0) goto endjob; =20 def->cputune.shares =3D val; diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index dcbd55c0f1..a1093e410d 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -3681,3 +3681,23 @@ 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 +virCgroupSetupCpuShares(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 55132dedb6..305d5c9853 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -222,6 +222,8 @@ virCgroupGetDomainTotalCpuStats(virCgroupPtr group, =20 int virCgroupSetCpuShares(virCgroupPtr group, unsigned long long shares); int virCgroupGetCpuShares(virCgroupPtr group, unsigned long long *shares); +int virCgroupSetupCpuShares(virCgroupPtr cgroup, unsigned long long shares, + unsigned long long *realValue); =20 int virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned long long cfs_pe= riod); int virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned long long *cfs_p= eriod); --=20 2.24.1 From nobody Tue Nov 26 06:56:51 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 1581975013673176.52629312581246; Mon, 17 Feb 2020 13:30:13 -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-411-D6TAUgyLMM2hZxPI2Q3OrQ-1; Mon, 17 Feb 2020 16:30:07 -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 D52DF800D5B; Mon, 17 Feb 2020 21:30:01 +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 9240D90F68; Mon, 17 Feb 2020 21:30:01 +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 35B7335B0A; Mon, 17 Feb 2020 21:30:01 +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 01HLTdaO032026 for ; Mon, 17 Feb 2020 16:29:40 -0500 Received: by smtp.corp.redhat.com (Postfix) id C348F2026D69; Mon, 17 Feb 2020 21:29:39 +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 BE13B2026D67 for ; Mon, 17 Feb 2020 21:29:39 +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 A30B3101929B for ; Mon, 17 Feb 2020 21:29:39 +0000 (UTC) Received: from mail-qv1-f66.google.com (mail-qv1-f66.google.com [209.85.219.66]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-307-O53LnWmjMW6GC4myeEOWtg-1; Mon, 17 Feb 2020 16:29:35 -0500 Received: by mail-qv1-f66.google.com with SMTP id l14so8207821qvu.12; Mon, 17 Feb 2020 13:29:34 -0800 (PST) Received: from rekt.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id i7sm872284qki.83.2020.02.17.13.29.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 13:29:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581975012; 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=cyhZqQY2DP7TyMJ5Kjype68I1GA7ULf2U9Kq+qM3+OY=; b=hOQMNQse4RRigA6942hyF5YET0iEuTUUnylIYBaRJGtl59F15oy5sPJdTMJ3UqysFlCAK3 Cb/M0SXQspIidNyFyx2Gn7ZXQRtSv46Cb5V7MN8mtEUokZFasfohA5IKYWx93igjR/qlt3 KYY0pAF6lC7VReHzKwzmHv2C8T3D4Fk= 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=jRgAsL0qYdowDBc8EcAM0dfjzdhIKosa96wIno2VL0Q=; b=OBWcmWO9+Bn08ohUnmr4+MyNPbm+PtjZo27N4ceCZX9lCjsHQv+rhHBEWTGpRFsdss tL11XagcrSiJ7nBOhBOvMESHdKEhmug6V0m6KcYYAOlQOn5FVZSBI1B1ZySLydyaOtcX OglYp+Z2DGPV0MLCQ7ayjH7+F1zMouYg9UMsP/mVSBM9OYflTxFefVj3BMCLO6YJcJQo Wh3dV8NM4gL3HBmLUNTWI+6eDsQ8Nw9KbJuDO278S8R5K0qxjXavlx7rPIIzroojVzfs Y8n2bkPkSVGpyTi6imYIZR6cQlSBgvgeqklY8HTtLJtptNJvyLIlSjpoz+7GaYw+7p2F AAsA== X-Gm-Message-State: APjAAAX6zzsiinnRNbJtD9U8gJDpI2M0RRvFQOPi8Od18ac1/dgyd3oJ /F22zG6f6cXZRT1EdADC9xNCY6MmEtA= X-Google-Smtp-Source: APXvYqwFrWIXpvPhzmOLEezg1LXG3LjxKfkyupc1I0w2kXoPIHtX8j6yRyvQ8iS+Mu0G+7b+LXzoqQ== X-Received: by 2002:a0c:ed32:: with SMTP id u18mr14374265qvq.2.1581974974456; Mon, 17 Feb 2020 13:29:34 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 08/14] vircgroup.c: add virCgroupSetupCpuPeriodQuota() Date: Mon, 17 Feb 2020 16:29:15 -0500 Message-Id: <20200217212921.251616-9-danielhb413@gmail.com> In-Reply-To: <20200217212921.251616-1-danielhb413@gmail.com> References: <20200217212921.251616-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: O53LnWmjMW6GC4myeEOWtg-1 X-MC-Unique: D6TAUgyLMM2hZxPI2Q3OrQ-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 01HLTdaO032026 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , jtomko@redhat.com, crobinso@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: J=C3=A1n Tomko --- 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 | 2 ++ 6 files changed, 45 insertions(+), 70 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 8be5fe7d9f..2f958b1c6f 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1730,6 +1730,7 @@ virCgroupSetupBlkioDeviceReadIops; virCgroupSetupBlkioDeviceWeight; virCgroupSetupBlkioDeviceWriteBps; virCgroupSetupBlkioDeviceWriteIops; +virCgroupSetupCpuPeriodQuota; virCgroupSetupCpusetCpus; virCgroupSetupCpuShares; virCgroupSupportsCpuBW; diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 4c8464bd97..4ebe5ef467 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -45,15 +45,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 e66aa7b8f5..d6d0f031a5 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 f969469931..548c5ec274 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -1127,36 +1127,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 a1093e410d..1f853beb73 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -3701,3 +3701,41 @@ virCgroupSetupCpuShares(virCgroupPtr cgroup, unsigne= d long long shares, =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 305d5c9853..cc53bae258 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -227,6 +227,8 @@ int virCgroupSetupCpuShares(virCgroupPtr cgroup, unsign= ed 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 virCgroupSetupCpuPeriodQuota(virCgroupPtr cgroup, unsigned long long p= eriod, + long long quota); =20 int virCgroupSetCpuCfsQuota(virCgroupPtr group, long long cfs_quota); int virCgroupGetCpuCfsQuota(virCgroupPtr group, long long *cfs_quota); --=20 2.24.1 From nobody Tue Nov 26 06:56:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 158197502924259.156669667289634; Mon, 17 Feb 2020 13:30:29 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-221-eXl8JZh0PiWoESN8Nlsb5Q-1; Mon, 17 Feb 2020 16:30:24 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8019E801E67; Mon, 17 Feb 2020 21:30:18 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 508D590F68; Mon, 17 Feb 2020 21:30:18 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id DB31B180BA96; Mon, 17 Feb 2020 21:30:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 01HLTcwM032007 for ; Mon, 17 Feb 2020 16:29:39 -0500 Received: by smtp.corp.redhat.com (Postfix) id D3F031003342; Mon, 17 Feb 2020 21:29:38 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CEDDE1004C44 for ; Mon, 17 Feb 2020 21:29:38 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A70AB8012B3 for ; Mon, 17 Feb 2020 21:29:38 +0000 (UTC) Received: from mail-qk1-f194.google.com (mail-qk1-f194.google.com [209.85.222.194]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-219-zFRMNLh4OvqHI38SvHMtjA-1; Mon, 17 Feb 2020 16:29:36 -0500 Received: by mail-qk1-f194.google.com with SMTP id b7so17583928qkl.7; Mon, 17 Feb 2020 13:29:35 -0800 (PST) Received: from rekt.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id i7sm872284qki.83.2020.02.17.13.29.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 13:29:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581975027; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=BCEfKXyc3M0ACsc7FIvban2pgZymwCFhHU0JuHytJA8=; b=MfF0vXV6e8eut2nF9nipYhMDXLSUBM+9lClZ7CQjkw1zsgYgTN4i1okL3l1wEUZWPPeBhT YD6DrmrJDnkHkOLJ33oaDTr4PQlsgbWPQAK6FxP/IH0/SFTTuqm4VCThksAAaS0hl2xv3u NXLgkARvD1XN+rUlsMc4Zsts9tjlg90= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TMk94VojuA2nvJW6hNzlxP0NDyi4lmRCp/EDvjro0rQ=; b=Y4xuLqAoevbKr5flxDti3Q5E+OdjyKamYaR9BVANB6jD+MzWIVa9UW2YAhqme+Y/Mg 3mC51MfBAOCcT7JM9HCkBAAVfxS/vrCc7vDCqGIb++me0G38pSC/ejFFdGrvqyl7ZTUW FTxG3h30GGbCCmNO5TPYtejg42ufT4b6F1UuRGpon6d2v7OGcl2Vnk2/W4nWIVlCdmIj 8P5PLzzosyb/Mf9d1l7Hi5BRWvStlu6iHzGL4h/BS2YlY1HSN0Up8mabBIheBNZNuIqv nn+rcEmaZfsVY8uLvndTJb+7qZ3tSHr5nwH5IRSEQNytZ4i8WX8Xhw6U9x6eep3oM3Sl qFdQ== X-Gm-Message-State: APjAAAWKEIk+RKuex74Zt36Z51iGuEmbELPwLy+ZAxGTRxv9LDY15OJm 6vW3gCJLWH1QDUsywCsu+3Zes1j/IaA= X-Google-Smtp-Source: APXvYqzBP30xNslwRNmhAvJ8mtt33YJHe84HG0KFLO7RAkppIDPprNmYZzrwjYdI5dfReYdZey4N6g== X-Received: by 2002:ae9:e50b:: with SMTP id w11mr16209404qkf.110.1581974975243; Mon, 17 Feb 2020 13:29:35 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 09/14] src/hypervisor: introduce domain_driver.c Date: Mon, 17 Feb 2020 16:29:16 -0500 Message-Id: <20200217212921.251616-10-danielhb413@gmail.com> In-Reply-To: <20200217212921.251616-1-danielhb413@gmail.com> References: <20200217212921.251616-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: zFRMNLh4OvqHI38SvHMtjA-1 X-MC-Unique: eXl8JZh0PiWoESN8Nlsb5Q-1 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 01HLTcwM032007 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , jtomko@redhat.com, crobinso@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" lxcDomainMergeBlkioDevice() and qemuDomainMergeBlkioDevice() are the same functions. This duplicated code can't be put in the existing domain_cgroup.c since it's not cgroup related. This patch introduces a new src/hypervisor/domain_driver.c to host this more generic code that can be shared between virt drivers. This new file is then used to create a new helper called virDomainDeivceMergeBlkioDevice() to eliminate the code repetition mentioned above. Callers in LXC and QEMU files were updated. This change is a preliminary step for more code reduction of cgroup related code inside lxcDomainSetBlkioParameters() and qemuDomainSetBlkioParameters(). Signed-off-by: Daniel Henrique Barboza Reviewed-by: J=C3=A1n Tomko --- src/hypervisor/Makefile.inc.am | 2 + src/hypervisor/domain_driver.c | 96 ++++++++++++++++++++++++++++++++++ src/hypervisor/domain_driver.h | 29 ++++++++++ src/libvirt_private.syms | 4 ++ src/lxc/lxc_driver.c | 84 ++++------------------------- src/qemu/qemu_driver.c | 83 ++++------------------------- 6 files changed, 149 insertions(+), 149 deletions(-) create mode 100644 src/hypervisor/domain_driver.c create mode 100644 src/hypervisor/domain_driver.h diff --git a/src/hypervisor/Makefile.inc.am b/src/hypervisor/Makefile.inc.am index 961b4e2b95..02cf2c7cb1 100644 --- a/src/hypervisor/Makefile.inc.am +++ b/src/hypervisor/Makefile.inc.am @@ -3,6 +3,8 @@ HYPERVISOR_SOURCES =3D \ hypervisor/domain_cgroup.h \ hypervisor/domain_cgroup.c \ + hypervisor/domain_driver.h \ + hypervisor/domain_driver.c \ $(NULL) =20 noinst_LTLIBRARIES +=3D libvirt_hypervisor.la diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c new file mode 100644 index 0000000000..c999458c25 --- /dev/null +++ b/src/hypervisor/domain_driver.c @@ -0,0 +1,96 @@ +/* + * domain_driver.c: general functions shared between hypervisor drivers + * + * Copyright IBM Corp. 2020 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include "domain_driver.h" +#include "viralloc.h" + +#define VIR_FROM_THIS VIR_FROM_DOMAIN + + +/* Modify dest_array to reflect all blkio device changes described in + * src_array. */ +int +virDomainDriverMergeBlkioDevice(virBlkioDevicePtr *dest_array, + size_t *dest_size, + virBlkioDevicePtr src_array, + size_t src_size, + const char *type) +{ + size_t i, j; + virBlkioDevicePtr dest, src; + + for (i =3D 0; i < src_size; i++) { + bool found =3D false; + + src =3D &src_array[i]; + for (j =3D 0; j < *dest_size; j++) { + dest =3D &(*dest_array)[j]; + if (STREQ(src->path, dest->path)) { + found =3D true; + + if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { + dest->weight =3D src->weight; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS))= { + dest->riops =3D src->riops; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)= ) { + dest->wiops =3D src->wiops; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) { + dest->rbps =3D src->rbps; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS))= { + dest->wbps =3D src->wbps; + } else { + virReportError(VIR_ERR_INVALID_ARG, _("Unknown paramet= er %s"), + type); + return -1; + } + break; + } + } + if (!found) { + if (!src->weight && !src->riops && !src->wiops && !src->rbps &= & !src->wbps) + continue; + if (VIR_EXPAND_N(*dest_array, *dest_size, 1) < 0) + return -1; + dest =3D &(*dest_array)[*dest_size - 1]; + + if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { + dest->weight =3D src->weight; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) { + dest->riops =3D src->riops; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) { + dest->wiops =3D src->wiops; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) { + dest->rbps =3D src->rbps; + } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) { + dest->wbps =3D src->wbps; + } else { + *dest_size =3D *dest_size - 1; + return -1; + } + + dest->path =3D src->path; + src->path =3D NULL; + } + } + + return 0; +} diff --git a/src/hypervisor/domain_driver.h b/src/hypervisor/domain_driver.h new file mode 100644 index 0000000000..2fb4148dff --- /dev/null +++ b/src/hypervisor/domain_driver.h @@ -0,0 +1,29 @@ +/* + * domain_driver.h: general functions shared between hypervisor drivers + * + * Copyright IBM Corp. 2020 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#pragma once + +#include "domain_conf.h" + +int virDomainDriverMergeBlkioDevice(virBlkioDevicePtr *dest_array, + size_t *dest_size, + virBlkioDevicePtr src_array, + size_t src_size, + const char *type); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 2f958b1c6f..c6b9afe259 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1394,6 +1394,10 @@ virDomainCgroupSetupBlkio; virDomainCgroupSetupMemtune; =20 =20 +# hypervisor/domain_cgroup.h +virDomainDriverMergeBlkioDevice; + + # libvirt_internal.h virConnectSupportsFeature; virDomainMigrateBegin3; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index d6d0f031a5..08c744a69b 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -56,6 +56,7 @@ #include "virpidfile.h" #include "virfdstream.h" #include "domain_audit.h" +#include "domain_driver.h" #include "domain_nwfilter.h" #include "virinitctl.h" #include "virnetdev.h" @@ -2214,75 +2215,6 @@ lxcDomainParseBlkioDeviceStr(char *blkioDeviceStr, c= onst char *type, return -1; } =20 -static int -lxcDomainMergeBlkioDevice(virBlkioDevicePtr *dest_array, - size_t *dest_size, - virBlkioDevicePtr src_array, - size_t src_size, - const char *type) -{ - size_t i, j; - virBlkioDevicePtr dest, src; - - for (i =3D 0; i < src_size; i++) { - bool found =3D false; - - src =3D &src_array[i]; - for (j =3D 0; j < *dest_size; j++) { - dest =3D &(*dest_array)[j]; - if (STREQ(src->path, dest->path)) { - found =3D true; - - if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { - dest->weight =3D src->weight; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS))= { - dest->riops =3D src->riops; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)= ) { - dest->wiops =3D src->wiops; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) { - dest->rbps =3D src->rbps; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS))= { - dest->wbps =3D src->wbps; - } else { - virReportError(VIR_ERR_INVALID_ARG, _("Unknown paramet= er %s"), - type); - return -1; - } - - break; - } - } - if (!found) { - if (!src->weight && !src->riops && !src->wiops && !src->rbps &= & !src->wbps) - continue; - if (VIR_EXPAND_N(*dest_array, *dest_size, 1) < 0) - return -1; - dest =3D &(*dest_array)[*dest_size - 1]; - - if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { - dest->weight =3D src->weight; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) { - dest->riops =3D src->riops; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) { - dest->wiops =3D src->wiops; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) { - dest->rbps =3D src->rbps; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) { - dest->wbps =3D src->wbps; - } else { - *dest_size =3D *dest_size - 1; - return -1; - } - - dest->path =3D src->path; - src->path =3D NULL; - } - } - - return 0; -} - - static int lxcDomainBlockStats(virDomainPtr dom, const char *path, @@ -2613,9 +2545,10 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, } =20 if (j !=3D ndevices || - lxcDomainMergeBlkioDevice(&def->blkio.devices, - &def->blkio.ndevices, - devices, ndevices, param->fi= eld) < 0) + virDomainDriverMergeBlkioDevice(&def->blkio.devices, + &def->blkio.ndevices, + devices, ndevices, + param->field) < 0) ret =3D -1; virBlkioDeviceArrayClear(devices, ndevices); VIR_FREE(devices); @@ -2645,9 +2578,10 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, ret =3D -1; continue; } - if (lxcDomainMergeBlkioDevice(&persistentDef->blkio.device= s, - &persistentDef->blkio.ndevic= es, - devices, ndevices, param->fi= eld) < 0) + if (virDomainDriverMergeBlkioDevice(&persistentDef->blkio.= devices, + &persistentDef->blkio.= ndevices, + devices, ndevices, + param->field) < 0) ret =3D -1; virBlkioDeviceArrayClear(devices, ndevices); VIR_FREE(devices); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index e9feb50220..3048e8a5c7 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -65,6 +65,7 @@ #include "viruuid.h" #include "domain_conf.h" #include "domain_audit.h" +#include "domain_driver.h" #include "node_device_conf.h" #include "virpci.h" #include "virusb.h" @@ -9419,74 +9420,6 @@ qemuDomainParseBlkioDeviceStr(char *blkioDeviceStr, = const char *type, return -1; } =20 -/* Modify dest_array to reflect all blkio device changes described in - * src_array. */ -static int -qemuDomainMergeBlkioDevice(virBlkioDevicePtr *dest_array, - size_t *dest_size, - virBlkioDevicePtr src_array, - size_t src_size, - const char *type) -{ - size_t i, j; - virBlkioDevicePtr dest, src; - - for (i =3D 0; i < src_size; i++) { - bool found =3D false; - - src =3D &src_array[i]; - for (j =3D 0; j < *dest_size; j++) { - dest =3D &(*dest_array)[j]; - if (STREQ(src->path, dest->path)) { - found =3D true; - - if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { - dest->weight =3D src->weight; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS))= { - dest->riops =3D src->riops; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)= ) { - dest->wiops =3D src->wiops; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) { - dest->rbps =3D src->rbps; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS))= { - dest->wbps =3D src->wbps; - } else { - virReportError(VIR_ERR_INVALID_ARG, _("Unknown paramet= er %s"), - type); - return -1; - } - break; - } - } - if (!found) { - if (!src->weight && !src->riops && !src->wiops && !src->rbps &= & !src->wbps) - continue; - if (VIR_EXPAND_N(*dest_array, *dest_size, 1) < 0) - return -1; - dest =3D &(*dest_array)[*dest_size - 1]; - - if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { - dest->weight =3D src->weight; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) { - dest->riops =3D src->riops; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) { - dest->wiops =3D src->wiops; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) { - dest->rbps =3D src->rbps; - } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) { - dest->wbps =3D src->wbps; - } else { - *dest_size =3D *dest_size - 1; - return -1; - } - - dest->path =3D src->path; - src->path =3D NULL; - } - } - - return 0; -} =20 static int qemuDomainSetBlkioParameters(virDomainPtr dom, @@ -9628,9 +9561,10 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, } =20 if (j !=3D ndevices || - qemuDomainMergeBlkioDevice(&def->blkio.devices, - &def->blkio.ndevices, - devices, ndevices, param->f= ield) < 0) + virDomainDriverMergeBlkioDevice(&def->blkio.devices, + &def->blkio.ndevices, + devices, ndevices, + param->field) < 0) ret =3D -1; virBlkioDeviceArrayClear(devices, ndevices); VIR_FREE(devices); @@ -9663,9 +9597,10 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, ret =3D -1; continue; } - if (qemuDomainMergeBlkioDevice(&persistentDef->blkio.devic= es, - &persistentDef->blkio.ndevi= ces, - devices, ndevices, param->f= ield) < 0) + if (virDomainDriverMergeBlkioDevice(&persistentDef->blkio.= devices, + &persistentDef->blkio.= ndevices, + devices, ndevices, + param->field) < 0) ret =3D -1; virBlkioDeviceArrayClear(devices, ndevices); VIR_FREE(devices); --=20 2.24.1 From nobody Tue Nov 26 06:56:51 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 1581975034370992.0230965415384; Mon, 17 Feb 2020 13:30:34 -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-124-JKD6-cGTN0ClUHHp3o8QAg-1; Mon, 17 Feb 2020 16:30:29 -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 418C7100DFC9; Mon, 17 Feb 2020 21:30: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 073BB60BE1; Mon, 17 Feb 2020 21:30: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 8B0DA35B03; Mon, 17 Feb 2020 21:30:23 +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 01HLTf5K032043 for ; Mon, 17 Feb 2020 16:29:41 -0500 Received: by smtp.corp.redhat.com (Postfix) id 504CD2166B2A; Mon, 17 Feb 2020 21:29:41 +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 4BA5F2166B27 for ; Mon, 17 Feb 2020 21:29:41 +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 2D41710192A2 for ; Mon, 17 Feb 2020 21:29:41 +0000 (UTC) Received: from mail-qv1-f41.google.com (mail-qv1-f41.google.com [209.85.219.41]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-144-WL83urzMM-6kOBlZiftM1g-1; Mon, 17 Feb 2020 16:29:37 -0500 Received: by mail-qv1-f41.google.com with SMTP id s7so8221081qvn.8; Mon, 17 Feb 2020 13:29:36 -0800 (PST) Received: from rekt.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id i7sm872284qki.83.2020.02.17.13.29.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 13:29:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581975032; 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=Tu35UMtiodjAjwkRnsa/maY/87L5VtQ6slnPOjWsDbA=; b=QLLVFsbOsWxb2LuxCOqiRFlprtgx7tM+qCVXScmV2dV0LvBuk05s031DhgW4T/I80LbH0N pIGM+3D0+B+aell4xLISeEHpVeZ467RWNAAp0nXLntBpYmJR7FyINnHHR85t2YHO4Qc9lb kHUfA32EpqvdeOGvfITGTQIRRh65y/o= 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=Sm8lV1Q0sw3/HPLQl/UbJDs2QuH+PVGafyfYxuagdZk=; b=Y135HkXMoIz73j0vkz7KNRmP5OStFGFA/7I8u3RLJal128buJHN392Ta1qWq972Kav mre5W5XeTzgD5T1BvS6/RBNVbB4UP3C3c42EXjoB8N8NaIuYqbZXCQL2wt4LEfhyU1fJ VfSljgBm8mfojEZJJtX5jcQxh9ojqkcfgx6zvEjX1MtLTqXuCxQp21Q2wrcd6bvWyS0I O+kt18oBqSkU7XrbwK7/a5JHEd8VXboJ6Qu1J/aq1Jv7QET7aZ8QvHxfdJb6YdudlkKo zI9055IEGhhK4QK3ENqW+788EGUcIn7FvJn0tT5qPNEeSSrSHFUgjPHJATE2EuoWjeI/ tGDw== X-Gm-Message-State: APjAAAU4guZEo2oN/kNbs34VkTcRPd/hBwiC+eswdZnqyLp1x3BsIDte 3JF37qK6RlVlmM8kRJUTtRNlalYzdgw= X-Google-Smtp-Source: APXvYqyzWR/JokMcMJ4P+6AbzpELK3lujtAvszBEj6I2WqbE7VGdLnbSK7m431Sjk37m8ahDwwWcdA== X-Received: by 2002:a05:6214:38c:: with SMTP id l12mr14150402qvy.224.1581974976082; Mon, 17 Feb 2020 13:29:36 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 10/14] domain_driver.c: add virDomainDriverParseBlkioDeviceStr() Date: Mon, 17 Feb 2020 16:29:17 -0500 Message-Id: <20200217212921.251616-11-danielhb413@gmail.com> In-Reply-To: <20200217212921.251616-1-danielhb413@gmail.com> References: <20200217212921.251616-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: WL83urzMM-6kOBlZiftM1g-1 X-MC-Unique: JKD6-cGTN0ClUHHp3o8QAg-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 01HLTf5K032043 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , jtomko@redhat.com, crobinso@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" lxcDomainParseBlkioDeviceStr() and qemuDomainParseBlkioDeviceStr() are the same function. Avoid code repetition by putting the code in a new helper. Signed-off-by: Daniel Henrique Barboza Reviewed-by: J=C3=A1n Tomko --- po/POTFILES.in | 1 + src/hypervisor/domain_driver.c | 112 +++++++++++++++++++++++++++++ src/hypervisor/domain_driver.h | 3 + src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 122 +++---------------------------- src/qemu/qemu_driver.c | 126 +++------------------------------ 6 files changed, 133 insertions(+), 232 deletions(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index dba0d3a12e..aa5c1fb6c7 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -78,6 +78,7 @@ @SRCDIR@/src/hyperv/hyperv_driver.c @SRCDIR@/src/hyperv/hyperv_util.c @SRCDIR@/src/hyperv/hyperv_wmi.c +@SRCDIR@/src/hypervisor/domain_driver.c @SRCDIR@/src/interface/interface_backend_netcf.c @SRCDIR@/src/interface/interface_backend_udev.c @SRCDIR@/src/internal.h diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index c999458c25..bbfadb3d9b 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -22,6 +22,7 @@ =20 #include "domain_driver.h" #include "viralloc.h" +#include "virstring.h" =20 #define VIR_FROM_THIS VIR_FROM_DOMAIN =20 @@ -94,3 +95,114 @@ virDomainDriverMergeBlkioDevice(virBlkioDevicePtr *dest= _array, =20 return 0; } + + +/* 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 +virDomainDriverParseBlkioDeviceStr(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; +} diff --git a/src/hypervisor/domain_driver.h b/src/hypervisor/domain_driver.h index 2fb4148dff..b78401ea42 100644 --- a/src/hypervisor/domain_driver.h +++ b/src/hypervisor/domain_driver.h @@ -27,3 +27,6 @@ int virDomainDriverMergeBlkioDevice(virBlkioDevicePtr *de= st_array, virBlkioDevicePtr src_array, size_t src_size, const char *type); + +int virDomainDriverParseBlkioDeviceStr(char *blkioDeviceStr, const char *t= ype, + virBlkioDevicePtr *dev, size_t *siz= e); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c6b9afe259..88f9ca16d1 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1396,6 +1396,7 @@ virDomainCgroupSetupMemtune; =20 # hypervisor/domain_cgroup.h virDomainDriverMergeBlkioDevice; +virDomainDriverParseBlkioDeviceStr; =20 =20 # libvirt_internal.h diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 08c744a69b..78a0174277 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2108,112 +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,10 +2380,10 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, virBlkioDevicePtr devices =3D NULL; size_t j; =20 - if (lxcDomainParseBlkioDeviceStr(params[i].value.s, - param->field, - &devices, - &ndevices) < 0) { + if (virDomainDriverParseBlkioDeviceStr(params[i].value.s, + param->field, + &devices, + &ndevices) < 0) { ret =3D -1; continue; } @@ -2571,10 +2465,10 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, virBlkioDevicePtr devices =3D NULL; size_t ndevices; =20 - if (lxcDomainParseBlkioDeviceStr(params[i].value.s, - param->field, - &devices, - &ndevices) < 0) { + if (virDomainDriverParseBlkioDeviceStr(params[i].value.s, + param->field, + &devices, + &ndevices) < 0) { ret =3D -1; continue; } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 3048e8a5c7..2205dd1194 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9310,116 +9310,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, @@ -9502,10 +9392,10 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, virBlkioDevicePtr devices =3D NULL; size_t j; =20 - if (qemuDomainParseBlkioDeviceStr(param->value.s, - param->field, - &devices, - &ndevices) < 0) { + if (virDomainDriverParseBlkioDeviceStr(param->value.s, + param->field, + &devices, + &ndevices) < 0) { ret =3D -1; continue; } @@ -9590,10 +9480,10 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, virBlkioDevicePtr devices =3D NULL; size_t ndevices; =20 - if (qemuDomainParseBlkioDeviceStr(param->value.s, - param->field, - &devices, - &ndevices) < 0) { + if (virDomainDriverParseBlkioDeviceStr(param->value.s, + param->field, + &devices, + &ndevices) < 0) { ret =3D -1; continue; } --=20 2.24.1 From nobody Tue Nov 26 06:56:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1581975024518606.3135059932732; Mon, 17 Feb 2020 13:30:24 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-222-5SlRNCg-OI6wZDT_ZaBvNQ-1; Mon, 17 Feb 2020 16:30:19 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C968A1005514; Mon, 17 Feb 2020 21:30:13 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9B56A90765; Mon, 17 Feb 2020 21:30:13 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 2A7FB35B0E; Mon, 17 Feb 2020 21:30:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 01HLTehi032036 for ; Mon, 17 Feb 2020 16:29:40 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6C9BC2166B2A; Mon, 17 Feb 2020 21:29:40 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 680D92166B27 for ; Mon, 17 Feb 2020 21:29:40 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4980F186E15D for ; Mon, 17 Feb 2020 21:29:40 +0000 (UTC) Received: from mail-qk1-f196.google.com (mail-qk1-f196.google.com [209.85.222.196]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-6-UT5K3tZtP8S3WNu_Qc7mCQ-1; Mon, 17 Feb 2020 16:29:37 -0500 Received: by mail-qk1-f196.google.com with SMTP id u124so17077229qkh.13; Mon, 17 Feb 2020 13:29:37 -0800 (PST) Received: from rekt.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id i7sm872284qki.83.2020.02.17.13.29.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 13:29:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581975023; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=CnuHcuoTXFyPjF6s6KqDgCAsgwHYtipVBDHdYoXrxDk=; b=dXUmNj+InhAJwMi3Zv/+mCSJNGUNmonJGIu/nFvLoBbM5dMnAyXgEZKOuDESwzectn7lt0 5cklubo2W7ZYb2IGglmZ/HtuNs8GMR7V/R44UlQj0kv1g9l9I3hMqiiRvD54DtJHcuRN7O l2w5Ib0c3wDS0lVzh/c0/7yh0QSreck= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=i9uCGelhb/CXlMZ8bI/C3bZKgB+fU7khyppHCaJe3LQ=; b=m0pcp9P1B8m9Wj5r698D3YojZgrwTA6uAo4vWDhCIaxgUzXWvpfoYESEor+szCcIIJ OBUyZf3Cs41pzgpzJd6Q0nxs00+wbbrAvQu8+bu0bbnMyjipWRskpm+uycfMhgLFl1uX k7H4JAkkVR0Tz5+woVNTDeROcrBz83DVe+ZQ91xNwmCyr0ZoX1N0O+4WLyayhf2gNX7S i4CdAgLUnRXTgsiXuGElIekkxLxwQ3i/4t7wc+77XaXupJSbSqjHry+pfCfvofS1gtBM VwXQOvmKpnJrmRJBFC1+RmBq330ctVX7YKDzNnFWXfg3U8JSmSyboV16URSR66wAzUlE Epcg== X-Gm-Message-State: APjAAAVm18LcfghMSXoW5QtH5bgguXh3Bammc/F9CUKbDZmJZYmuVDQw YvpZYmueYlKfxFB+8xlfQPvLBqgRcAk= X-Google-Smtp-Source: APXvYqz/7Eo51FiDVFa3UXVJB/jtypy/XHJNdIMRQe9NkSoVqUnRiQwsy6ik3QjRvJtJLaTAKVkPBQ== X-Received: by 2002:a37:de16:: with SMTP id h22mr16157104qkj.400.1581974976966; Mon, 17 Feb 2020 13:29:36 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 11/14] domain_cgroup.c: add virDomainCgroupSetupDomainBlkioParameters() Date: Mon, 17 Feb 2020 16:29:18 -0500 Message-Id: <20200217212921.251616-12-danielhb413@gmail.com> In-Reply-To: <20200217212921.251616-1-danielhb413@gmail.com> References: <20200217212921.251616-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: UT5K3tZtP8S3WNu_Qc7mCQ-1 X-MC-Unique: 5SlRNCg-OI6wZDT_ZaBvNQ-1 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 01HLTehi032036 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , jtomko@redhat.com, crobinso@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" After the introduction of virDomainDriverMergeBlkioDevice() in a previous patch, it is now clear that lxcDomainSetBlkioParameters() and qemuDomainSetBlkioParameters() uses the same loop to set cgroup blkio parameter of a domain. Avoid the repetition by adding a new helper called virDomainCgroupSetupDomainBlkioParameters(). Signed-off-by: Daniel Henrique Barboza Reviewed-by: J=C3=A1n Tomko --- po/POTFILES.in | 1 + src/hypervisor/domain_cgroup.c | 101 +++++++++++++++++++++++++++++++++ src/hypervisor/domain_cgroup.h | 4 ++ src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 87 +--------------------------- src/qemu/qemu_driver.c | 88 +--------------------------- 6 files changed, 113 insertions(+), 169 deletions(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index aa5c1fb6c7..1675c45206 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -78,6 +78,7 @@ @SRCDIR@/src/hyperv/hyperv_driver.c @SRCDIR@/src/hyperv/hyperv_util.c @SRCDIR@/src/hyperv/hyperv_wmi.c +@SRCDIR@/src/hypervisor/domain_cgroup.c @SRCDIR@/src/hypervisor/domain_driver.c @SRCDIR@/src/interface/interface_backend_netcf.c @SRCDIR@/src/interface/interface_backend_udev.c diff --git a/src/hypervisor/domain_cgroup.c b/src/hypervisor/domain_cgroup.c index e60abd536c..32b07be3d6 100644 --- a/src/hypervisor/domain_cgroup.c +++ b/src/hypervisor/domain_cgroup.c @@ -21,6 +21,9 @@ #include =20 #include "domain_cgroup.h" +#include "domain_driver.h" + +#define VIR_FROM_THIS VIR_FROM_DOMAIN =20 =20 int @@ -84,3 +87,101 @@ virDomainCgroupSetupMemtune(virCgroupPtr cgroup, virDom= ainMemtune mem) =20 return 0; } + + +int +virDomainCgroupSetupDomainBlkioParameters(virCgroupPtr cgroup, + virDomainDefPtr def, + virTypedParameterPtr params, + int nparams) +{ + size_t i; + int ret =3D 0; + + for (i =3D 0; i < nparams; i++) { + virTypedParameterPtr param =3D ¶ms[i]; + + if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) { + if (virCgroupSetBlkioWeight(cgroup, params[i].value.ui) < 0) + ret =3D -1; + } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT) || + STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS) = || + STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)= || + STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS) || + STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS))= { + size_t ndevices; + virBlkioDevicePtr devices =3D NULL; + size_t j; + + if (virDomainDriverParseBlkioDeviceStr(params[i].value.s, + param->field, + &devices, + &ndevices) < 0) { + ret =3D -1; + continue; + } + + if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { + for (j =3D 0; j < ndevices; j++) { + if (virCgroupSetupBlkioDeviceWeight(cgroup, devices[j]= .path, + &devices[j].weight= ) < 0) { + ret =3D -1; + break; + } + } + } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_IO= PS)) { + for (j =3D 0; j < ndevices; j++) { + if (virCgroupSetupBlkioDeviceReadIops(cgroup, devices[= j].path, + &devices[j].riop= s) < 0) { + ret =3D -1; + break; + } + } + } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_I= OPS)) { + for (j =3D 0; j < ndevices; j++) { + if (virCgroupSetupBlkioDeviceWriteIops(cgroup, devices= [j].path, + &devices[j].wio= ps) < 0) { + ret =3D -1; + break; + } + } + } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_BP= S)) { + for (j =3D 0; j < ndevices; j++) { + if (virCgroupSetupBlkioDeviceReadBps(cgroup, devices[j= ].path, + &devices[j].rbps)= < 0) { + ret =3D -1; + break; + } + } + } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_B= PS)) { + for (j =3D 0; j < ndevices; j++) { + if (virCgroupSetupBlkioDeviceWriteBps(cgroup, devices[= j].path, + &devices[j].wbps= ) < 0) { + ret =3D -1; + break; + } + } + } else { + virReportError(VIR_ERR_INVALID_ARG, _("Unknown blkio param= eter %s"), + param->field); + ret =3D -1; + virBlkioDeviceArrayClear(devices, ndevices); + g_free(devices); + + continue; + } + + if (j !=3D ndevices || + virDomainDriverMergeBlkioDevice(&def->blkio.devices, + &def->blkio.ndevices, + devices, ndevices, + param->field) < 0) + ret =3D -1; + + virBlkioDeviceArrayClear(devices, ndevices); + g_free(devices); + } + } + + return ret; +} diff --git a/src/hypervisor/domain_cgroup.h b/src/hypervisor/domain_cgroup.h index 82ba47e85f..7f3a0d12f9 100644 --- a/src/hypervisor/domain_cgroup.h +++ b/src/hypervisor/domain_cgroup.h @@ -26,3 +26,7 @@ =20 int virDomainCgroupSetupBlkio(virCgroupPtr cgroup, virDomainBlkiotune blki= o); int virDomainCgroupSetupMemtune(virCgroupPtr cgroup, virDomainMemtune mem); +int virDomainCgroupSetupDomainBlkioParameters(virCgroupPtr cgroup, + virDomainDefPtr def, + virTypedParameterPtr params, + int nparams); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 88f9ca16d1..a01a0223f3 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1391,6 +1391,7 @@ virSetConnectStorage; =20 # hypervisor/domain_cgroup.h virDomainCgroupSetupBlkio; +virDomainCgroupSetupDomainBlkioParameters; virDomainCgroupSetupMemtune; =20 =20 diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 78a0174277..c93dee37f8 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -56,6 +56,7 @@ #include "virpidfile.h" #include "virfdstream.h" #include "domain_audit.h" +#include "domain_cgroup.h" #include "domain_driver.h" #include "domain_nwfilter.h" #include "virinitctl.h" @@ -2364,90 +2365,8 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, =20 ret =3D 0; if (def) { - for (i =3D 0; i < nparams; i++) { - virTypedParameterPtr param =3D ¶ms[i]; - - if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) { - if (virCgroupSetBlkioWeight(priv->cgroup, params[i].value.= ui) < 0) - ret =3D -1; - } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)= || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_IO= PS) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_I= OPS) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_BP= S) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_B= PS)) { - virCgroupPtr cgroup =3D priv->cgroup; - size_t ndevices; - virBlkioDevicePtr devices =3D NULL; - size_t j; - - if (virDomainDriverParseBlkioDeviceStr(params[i].value.s, - param->field, - &devices, - &ndevices) < 0) { - ret =3D -1; - continue; - } - - if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { - for (j =3D 0; j < ndevices; j++) { - if (virCgroupSetupBlkioDeviceWeight(cgroup, device= s[j].path, - &devices[j].we= ight) < 0) { - ret =3D -1; - break; - } - } - } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_REA= D_IOPS)) { - for (j =3D 0; j < ndevices; j++) { - if (virCgroupSetupBlkioDeviceReadIops(cgroup, devi= ces[j].path, - &devices[j].= riops) < 0) { - ret =3D -1; - break; - } - } - } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRI= TE_IOPS)) { - for (j =3D 0; j < ndevices; j++) { - if (virCgroupSetupBlkioDeviceWriteIops(cgroup, dev= ices[j].path, - &devices[j]= .wiops) < 0) { - ret =3D -1; - break; - } - } - } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_REA= D_BPS)) { - for (j =3D 0; j < ndevices; j++) { - if (virCgroupSetupBlkioDeviceReadBps(cgroup, devic= es[j].path, - &devices[j].r= bps) < 0) { - ret =3D -1; - break; - } - } - } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRI= TE_BPS)) { - for (j =3D 0; j < ndevices; j++) { - if (virCgroupSetupBlkioDeviceWriteBps(cgroup, devi= ces[j].path, - &devices[j].= wbps) < 0) { - ret =3D -1; - break; - } - } - } else { - virReportError(VIR_ERR_INVALID_ARG, _("Unknown blkio p= arameter %s"), - param->field); - ret =3D -1; - virBlkioDeviceArrayClear(devices, ndevices); - VIR_FREE(devices); - - continue; - } - - if (j !=3D ndevices || - virDomainDriverMergeBlkioDevice(&def->blkio.devices, - &def->blkio.ndevices, - devices, ndevices, - param->field) < 0) - ret =3D -1; - virBlkioDeviceArrayClear(devices, ndevices); - VIR_FREE(devices); - } - } + ret =3D virDomainCgroupSetupDomainBlkioParameters(priv->cgroup, de= f, + params, nparams); } if (ret < 0) goto endjob; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 2205dd1194..850d6699ce 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -65,6 +65,7 @@ #include "viruuid.h" #include "domain_conf.h" #include "domain_audit.h" +#include "domain_cgroup.h" #include "domain_driver.h" #include "node_device_conf.h" #include "virpci.h" @@ -9375,91 +9376,8 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, =20 ret =3D 0; if (def) { - for (i =3D 0; i < nparams; i++) { - virTypedParameterPtr param =3D ¶ms[i]; - - if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) { - if (virCgroupSetBlkioWeight(priv->cgroup, param->value.ui)= < 0 || - virCgroupGetBlkioWeight(priv->cgroup, &def->blkio.weig= ht) < 0) - ret =3D -1; - } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)= || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_IO= PS) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_I= OPS) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_BP= S) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_B= PS)) { - virCgroupPtr cgroup =3D priv->cgroup; - size_t ndevices; - virBlkioDevicePtr devices =3D NULL; - size_t j; - - if (virDomainDriverParseBlkioDeviceStr(param->value.s, - param->field, - &devices, - &ndevices) < 0) { - ret =3D -1; - continue; - } - - if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) { - for (j =3D 0; j < ndevices; j++) { - if (virCgroupSetupBlkioDeviceWeight(cgroup, device= s[j].path, - &devices[j].we= ight) < 0) { - ret =3D -1; - break; - } - } - } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_REA= D_IOPS)) { - for (j =3D 0; j < ndevices; j++) { - if (virCgroupSetupBlkioDeviceReadIops(cgroup, devi= ces[j].path, - &devices[j].= riops) < 0) { - ret =3D -1; - break; - } - } - } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRI= TE_IOPS)) { - for (j =3D 0; j < ndevices; j++) { - if (virCgroupSetupBlkioDeviceWriteIops(cgroup, dev= ices[j].path, - &devices[j]= .wiops) < 0) { - ret =3D -1; - break; - } - } - } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_REA= D_BPS)) { - for (j =3D 0; j < ndevices; j++) { - if (virCgroupSetupBlkioDeviceReadBps(cgroup, devic= es[j].path, - &devices[j].r= bps) < 0) { - ret =3D -1; - break; - } - } - } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRI= TE_BPS)) { - for (j =3D 0; j < ndevices; j++) { - if (virCgroupSetupBlkioDeviceWriteBps(cgroup, devi= ces[j].path, - &devices[j].= wbps) < 0) { - ret =3D -1; - break; - } - } - } else { - virReportError(VIR_ERR_INVALID_ARG, _("Unknown blkio p= arameter %s"), - param->field); - ret =3D -1; - virBlkioDeviceArrayClear(devices, ndevices); - VIR_FREE(devices); - - continue; - } - - if (j !=3D ndevices || - virDomainDriverMergeBlkioDevice(&def->blkio.devices, - &def->blkio.ndevices, - devices, ndevices, - param->field) < 0) - ret =3D -1; - virBlkioDeviceArrayClear(devices, ndevices); - VIR_FREE(devices); - } - } + ret =3D virDomainCgroupSetupDomainBlkioParameters(priv->cgroup, de= f, + params, nparams); =20 if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto endjob; --=20 2.24.1 From nobody Tue Nov 26 06:56:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1581975037584521.2380080417652; Mon, 17 Feb 2020 13:30:37 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-64-VqvrlsdMPSuPObNHBAoWYA-1; Mon, 17 Feb 2020 16:30:34 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CAC64800D54; Mon, 17 Feb 2020 21:30:28 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9DA1B90F6F; Mon, 17 Feb 2020 21:30:28 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 41BEB1803C38; Mon, 17 Feb 2020 21:30:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 01HLTkpB032080 for ; Mon, 17 Feb 2020 16:29:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id 03F6AD1BCC; Mon, 17 Feb 2020 21:29:46 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F37DFD1D0E for ; Mon, 17 Feb 2020 21:29:43 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 20C79101929D for ; Mon, 17 Feb 2020 21:29:43 +0000 (UTC) Received: from mail-qt1-f196.google.com (mail-qt1-f196.google.com [209.85.160.196]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-373-9vJeIminMoOjq0G_YxQoRQ-1; Mon, 17 Feb 2020 16:29:38 -0500 Received: by mail-qt1-f196.google.com with SMTP id k7so13042286qth.11; Mon, 17 Feb 2020 13:29:38 -0800 (PST) Received: from rekt.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id i7sm872284qki.83.2020.02.17.13.29.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 13:29:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581975036; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=f2dHxKALdXJDIDBfuiySulS3h+zuJxYnNy1F07+nHTs=; b=hEtxNJIOO+zOi1EhSJZvMBX1t3rA49iPG4gregsZYmI1t+gKErjRcVJDEtR4m1jnlhyqWz fqfcvWY+OIlARXfQpFdW1cFhPqrZkY9wR2TGxdsAkPWeeXJxA/j5mxdhdi1ExMIeNMb552 99mr0Ehj8QHainTdoM1Y13NK2PtRaL0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MFK2///CY2n9aVky50uPnYYQlnaT3D5yyvNS5mRoNMo=; b=J4bKU09ILxBOfVWSZ5Ly5FbNg1idYST2MBMwpwJyIO19OQKOKspECYyPSCW7TCZylY +KMHWiRSXYqx6geGjpz5WX4afxFrrVH3tBkDwYIS1TbQo5VtR7kvnuUZgxn4lbOFIkYr 2Vy6HqzxmeDMjhPQMBw5tRNx7GbThG0ukoq7KDuJWcx0FcgHiLZ6Pxs1XqPyQ3YSxDVO hY1q8Y6y12mnjycSVMuAUUdqk909yOEpcZOprwQ4/PsBeGjU/Ry9KxaHnyTW1DJc4oSB tn11EaOqq/N6eDwfU8rX7f4MEzQ1SusfypYX2+AF5XKyIEB+2b2O78plyFjU43hAD667 IEbQ== X-Gm-Message-State: APjAAAV7aua4ec5lWrYT79s4EtoHeOT48wjsJ9idiBVbK6CwIuXWKQ+m 80DYYDl2ZsYc8BT9CNzXT4ZLcOuK97c= X-Google-Smtp-Source: APXvYqx+wmPXZMwBkH551ElSpxsW7A2q5+7sSkGV1cSYfciaFywKT5nlC490VaukmXdwaOe7o3NvTA== X-Received: by 2002:ac8:7155:: with SMTP id h21mr14036205qtp.95.1581974977846; Mon, 17 Feb 2020 13:29:37 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 12/14] domain_driver.c: add virDomainDriverSetupPersistentDefBlkioParams() Date: Mon, 17 Feb 2020 16:29:19 -0500 Message-Id: <20200217212921.251616-13-danielhb413@gmail.com> In-Reply-To: <20200217212921.251616-1-danielhb413@gmail.com> References: <20200217212921.251616-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: 9vJeIminMoOjq0G_YxQoRQ-1 X-MC-Unique: VqvrlsdMPSuPObNHBAoWYA-1 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 01HLTkpB032080 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , jtomko@redhat.com, crobinso@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This new helper avoids more code repetition inside lxcDomainSetBlkioParameters() and qemuDomainSetBlkioParameters(). Signed-off-by: Daniel Henrique Barboza Reviewed-by: J=C3=A1n Tomko --- src/hypervisor/domain_driver.c | 44 ++++++++++++++++++++++++++++++++++ src/hypervisor/domain_driver.h | 4 ++++ src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 33 +++---------------------- src/qemu/qemu_driver.c | 33 +++---------------------- 5 files changed, 55 insertions(+), 60 deletions(-) diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index bbfadb3d9b..0cf6c7604b 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -206,3 +206,47 @@ virDomainDriverParseBlkioDeviceStr(char *blkioDeviceSt= r, const char *type, } return -1; } + + +int +virDomainDriverSetupPersistentDefBlkioParams(virDomainDefPtr persistentDef, + virTypedParameterPtr params, + int nparams) +{ + size_t i; + int ret =3D 0; + + for (i =3D 0; i < nparams; i++) { + virTypedParameterPtr param =3D ¶ms[i]; + + if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) { + persistentDef->blkio.weight =3D param->value.ui; + } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT) || + STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS) = || + STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)= || + STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS) || + STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS))= { + virBlkioDevicePtr devices =3D NULL; + size_t ndevices; + + if (virDomainDriverParseBlkioDeviceStr(param->value.s, + param->field, + &devices, + &ndevices) < 0) { + ret =3D -1; + continue; + } + + if (virDomainDriverMergeBlkioDevice(&persistentDef->blkio.devi= ces, + &persistentDef->blkio.ndev= ices, + devices, ndevices, + param->field) < 0) + ret =3D -1; + + virBlkioDeviceArrayClear(devices, ndevices); + g_free(devices); + } + } + + return ret; +} diff --git a/src/hypervisor/domain_driver.h b/src/hypervisor/domain_driver.h index b78401ea42..b6d5e66bba 100644 --- a/src/hypervisor/domain_driver.h +++ b/src/hypervisor/domain_driver.h @@ -30,3 +30,7 @@ int virDomainDriverMergeBlkioDevice(virBlkioDevicePtr *de= st_array, =20 int virDomainDriverParseBlkioDeviceStr(char *blkioDeviceStr, const char *t= ype, virBlkioDevicePtr *dev, size_t *siz= e); + +int virDomainDriverSetupPersistentDefBlkioParams(virDomainDefPtr persisten= tDef, + virTypedParameterPtr para= ms, + int nparams); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a01a0223f3..c157012707 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1398,6 +1398,7 @@ virDomainCgroupSetupMemtune; # hypervisor/domain_cgroup.h virDomainDriverMergeBlkioDevice; virDomainDriverParseBlkioDeviceStr; +virDomainDriverSetupPersistentDefBlkioParams; =20 =20 # libvirt_internal.h diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index c93dee37f8..0332b7668a 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2314,7 +2314,6 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, unsigned int flags) { virLXCDriverPtr driver =3D dom->conn->privateData; - size_t i; virDomainObjPtr vm =3D NULL; virDomainDefPtr def =3D NULL; virDomainDefPtr persistentDef =3D NULL; @@ -2371,35 +2370,9 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, if (ret < 0) goto endjob; if (persistentDef) { - for (i =3D 0; i < nparams; i++) { - virTypedParameterPtr param =3D ¶ms[i]; - - if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) { - persistentDef->blkio.weight =3D params[i].value.ui; - } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)= || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_IO= PS) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_I= OPS) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_BP= S) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_B= PS)) { - virBlkioDevicePtr devices =3D NULL; - size_t ndevices; - - if (virDomainDriverParseBlkioDeviceStr(params[i].value.s, - param->field, - &devices, - &ndevices) < 0) { - ret =3D -1; - continue; - } - if (virDomainDriverMergeBlkioDevice(&persistentDef->blkio.= devices, - &persistentDef->blkio.= ndevices, - devices, ndevices, - param->field) < 0) - ret =3D -1; - virBlkioDeviceArrayClear(devices, ndevices); - VIR_FREE(devices); - } - } + ret =3D virDomainDriverSetupPersistentDefBlkioParams(persistentDef, + params, + nparams); =20 if (virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir= ) < 0) ret =3D -1; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 850d6699ce..44145a5f60 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9319,7 +9319,6 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, unsigned int flags) { virQEMUDriverPtr driver =3D dom->conn->privateData; - size_t i; virDomainObjPtr vm =3D NULL; virDomainDefPtr def; virDomainDefPtr persistentDef; @@ -9385,35 +9384,9 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, if (ret < 0) goto endjob; if (persistentDef) { - for (i =3D 0; i < nparams; i++) { - virTypedParameterPtr param =3D ¶ms[i]; - - if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) { - persistentDef->blkio.weight =3D param->value.ui; - } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)= || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_IO= PS) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_I= OPS) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_READ_BP= S) || - STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WRITE_B= PS)) { - virBlkioDevicePtr devices =3D NULL; - size_t ndevices; - - if (virDomainDriverParseBlkioDeviceStr(param->value.s, - param->field, - &devices, - &ndevices) < 0) { - ret =3D -1; - continue; - } - if (virDomainDriverMergeBlkioDevice(&persistentDef->blkio.= devices, - &persistentDef->blkio.= ndevices, - devices, ndevices, - param->field) < 0) - ret =3D -1; - virBlkioDeviceArrayClear(devices, ndevices); - VIR_FREE(devices); - } - } + ret =3D virDomainDriverSetupPersistentDefBlkioParams(persistentDef, + params, + nparams); =20 if (virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir= ) < 0) ret =3D -1; --=20 2.24.1 From nobody Tue Nov 26 06:56:51 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 1581975032913190.93635424761385; Mon, 17 Feb 2020 13:30: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-74-MqB8MW24Os-cjtkDfIosOw-1; Mon, 17 Feb 2020 16:30:29 -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 D195D18A8C91; Mon, 17 Feb 2020 21:30: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 9441560BE1; Mon, 17 Feb 2020 21:30:23 +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 1312A35B08; Mon, 17 Feb 2020 21:30:23 +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 01HLTlCa032092 for ; Mon, 17 Feb 2020 16:29:47 -0500 Received: by smtp.corp.redhat.com (Postfix) id 20C231004C40; Mon, 17 Feb 2020 21:29:47 +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 1BD841003342 for ; Mon, 17 Feb 2020 21:29:47 +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 F1200186E163 for ; Mon, 17 Feb 2020 21:29:46 +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-234-gwFofsRfMqy0LDSbYNur7g-1; Mon, 17 Feb 2020 16:29:39 -0500 Received: by mail-qt1-f195.google.com with SMTP id d5so13107921qto.0; Mon, 17 Feb 2020 13:29:39 -0800 (PST) Received: from rekt.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id i7sm872284qki.83.2020.02.17.13.29.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 13:29:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581975031; 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=kHKiVEn+V6v92ZaL8hqcD/fjGfyhJOqNQEIlDjk0Zog=; b=cjganl9FGKAh7LCkZekIBxHKQu0PAev3xIY+Gdwrwe6S1VsleOLV5VgP7CkpoCEVXIGX+5 76/eevI+78GbVsY5rBzSIK7Rd7Nq6EAxGIojM80mZ1URqWgn04b5mPNcoKZM6nSb/QzVyq DzuLH7GiLL3UFaFPJnnvh68vKzfct5I= 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=aBZLilArycuAofgIvDiRuGGi+5xw1jC8FtvYBsWlGh8=; b=az7eQHhUVo/w46vY3iItkGc0mca0cpjxfPH5BEaXn8bQdg/4fUFrjwEpaZtovtVwPX L/U6cZSLv/dLN6+n1v/ALrUKsEWkwAiT8YuKpbghoYX4v7bZIuVt8lFxeXwOs7kjajeO 8lNWP+Zn9HCfVlXFkVoMZ4WedIXyR9OJoNM5CVbGsE2IJ8trWBWach2V0LGR9xLfLORS 7gp9SB2XE4N/ON9W8r9MWvVwmIJgEkoHKQhH8GdeaI4WKCF/3AkclUWho+VRRRb+cDNf X41psV+aXeEniYQnWgnybRLjxOmZHr1J91LkNKxjKFVXCnoKklwlpx+1KGUjrmoKmZS8 RV4w== X-Gm-Message-State: APjAAAVuvLePodBP0ZxATyDKJTUgoXAkMPzP1CNI6MmWFvnRtzvidq4q RfGggSQ8uJPxqHQOpPNkKzzRrpM27Jo= X-Google-Smtp-Source: APXvYqyGowrJrRuXkDZl0iKPj7EGxtYRMOHEyjYEBjHumJq2Vvjg7uu4NJlNkSYLQWX4Fpetdgm/Ng== X-Received: by 2002:ac8:769a:: with SMTP id g26mr14791895qtr.259.1581974978671; Mon, 17 Feb 2020 13:29:38 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 13/14] domain_cgroup.c: add virDomainCgroupSetMemoryLimitParameters() Date: Mon, 17 Feb 2020 16:29:20 -0500 Message-Id: <20200217212921.251616-14-danielhb413@gmail.com> In-Reply-To: <20200217212921.251616-1-danielhb413@gmail.com> References: <20200217212921.251616-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: gwFofsRfMqy0LDSbYNur7g-1 X-MC-Unique: MqB8MW24Os-cjtkDfIosOw-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 01HLTlCa032092 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , jtomko@redhat.com, crobinso@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" lxcDomainSetMemoryParameters() and qemuDomainSetMemoryParameters() has duplicated chunks of code that can be put in a new helper. Signed-off-by: Daniel Henrique Barboza --- src/hypervisor/domain_cgroup.c | 81 ++++++++++++++++++++++++++++++++++ src/hypervisor/domain_cgroup.h | 6 +++ src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 71 ++--------------------------- src/qemu/qemu_driver.c | 71 ++--------------------------- 5 files changed, 96 insertions(+), 134 deletions(-) diff --git a/src/hypervisor/domain_cgroup.c b/src/hypervisor/domain_cgroup.c index 32b07be3d6..2b3e1d6956 100644 --- a/src/hypervisor/domain_cgroup.c +++ b/src/hypervisor/domain_cgroup.c @@ -185,3 +185,84 @@ virDomainCgroupSetupDomainBlkioParameters(virCgroupPtr= cgroup, =20 return ret; } + + +int +virDomainCgroupSetMemoryLimitParameters(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/hypervisor/domain_cgroup.h b/src/hypervisor/domain_cgroup.h index 7f3a0d12f9..5a6498b1ce 100644 --- a/src/hypervisor/domain_cgroup.h +++ b/src/hypervisor/domain_cgroup.h @@ -30,3 +30,9 @@ int virDomainCgroupSetupDomainBlkioParameters(virCgroupPt= r cgroup, virDomainDefPtr def, virTypedParameterPtr params, int nparams); +int virDomainCgroupSetMemoryLimitParameters(virCgroupPtr cgroup, + virDomainObjPtr vm, + virDomainDefPtr liveDef, + virDomainDefPtr persistentDef, + virTypedParameterPtr params, + int nparams); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c157012707..679e32116c 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1390,6 +1390,7 @@ virSetConnectStorage; =20 =20 # hypervisor/domain_cgroup.h +virDomainCgroupSetMemoryLimitParameters; virDomainCgroupSetupBlkio; virDomainCgroupSetupDomainBlkioParameters; virDomainCgroupSetupMemtune; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 0332b7668a..fc559d736a 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -749,13 +749,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 | @@ -794,66 +787,10 @@ 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 (virDomainCgroupSetMemoryLimitParameters(priv->cgroup, vm, def, + persistentDef, + 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 44145a5f60..b65708385f 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9502,14 +9502,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 @@ -9556,66 +9549,10 @@ 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 (virDomainCgroupSetMemoryLimitParameters(priv->cgroup, vm, def, + persistentDef, + params, nparams) < 0) + goto endjob; =20 if (def && virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) --=20 2.24.1 From nobody Tue Nov 26 06:56:51 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 1581975030907501.48325971939266; Mon, 17 Feb 2020 13:30:30 -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-285-cBtcv2GZMNWnQKvwG48VVg-1; Mon, 17 Feb 2020 16:30:25 -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 0737818A8C86; Mon, 17 Feb 2020 21:30: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 CA39B10021B2; Mon, 17 Feb 2020 21:30:18 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 63B771804744; Mon, 17 Feb 2020 21:30:18 +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 01HLTkEL032079 for ; Mon, 17 Feb 2020 16:29:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id 01653D1BC7; Mon, 17 Feb 2020 21:29:46 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F046AD0B4B for ; Mon, 17 Feb 2020 21:29: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 8AC69802711 for ; Mon, 17 Feb 2020 21:29:44 +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-274-1paov4dFPJ6j_6xhm4GfYw-1; Mon, 17 Feb 2020 16:29:40 -0500 Received: by mail-qk1-f194.google.com with SMTP id c20so17616475qkm.1; Mon, 17 Feb 2020 13:29:40 -0800 (PST) Received: from rekt.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id i7sm872284qki.83.2020.02.17.13.29.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 13:29:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581975029; 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=L3Uz6coJGHlhpCTDN6boTS0ts5zLRR1WEYLJ5Bi5Nao=; b=Y6tJ0rxAPFQV3RcVXMzY8qyRaiGVqGa6VFAXu8bqwKWrg1rwgafMNt9GlfUEOxqEJ8oZ7t CIFjk/V5HnE5ebRyqfWXiBBlW9BmeKaXCe+V2BPQBsXmMH1czvfQcQQvdIqd3GCnc5ZtMg bvgBpl8vttBXeM+Zg0MzidDIdkp5nXk= 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=Ql8WXdW2OXO3gETkbft+dyn4DG1yBYQoqraUZ/cKql0=; b=QA/Z8kpJMW77ABZKhoiPUrfoqp0fMB8k+LP57PKuV2xjP4ajesdY2W6yeBz2miDVC3 U2ai7u4lCs1OS8hK3TI9N3VDdx/1seJMhnauwEK9r9/0h8cmJm0kIwurMOY3tSK+ap0I H+wiOXu/Rh9O+EA04XqXbYPai77746LciLq9w8cwayVezOpWSs51Puo0EA5Nd28ECKqw f4wGBEzD0BRRy2cc5WUh3KUGEoVoEfSxYFgxCDGR99lRWN8eAfTF6bDSOBMNlcmxRola ga2zAtIMsKtAr4ULrxvsjaounYKJ6yrxfS8mPinBhYKDgGp5hQBe25QhhzIKGYNX/wmp KogA== X-Gm-Message-State: APjAAAX7IG4gw/DTaRODD5J+QkUwlzMweum0xd59Mdwp/QbfkGMBaaSG BJDnOygmiXUNXnWkpecOBRGvwhJ+tb8= X-Google-Smtp-Source: APXvYqxGhWEys4P9TCTkLEEypLGAyNRSrH809mH4noTYoT/wEEaegHI6gn6fmEAntei5FiaodWxmdg== X-Received: by 2002:a05:620a:15c2:: with SMTP id o2mr2374105qkm.324.1581974979555; Mon, 17 Feb 2020 13:29:39 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 14/14] vircgroup: add virCgroupGetCpuPeriodQuota() Date: Mon, 17 Feb 2020 16:29:21 -0500 Message-Id: <20200217212921.251616-15-danielhb413@gmail.com> In-Reply-To: <20200217212921.251616-1-danielhb413@gmail.com> References: <20200217212921.251616-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: 1paov4dFPJ6j_6xhm4GfYw-1 X-MC-Unique: cBtcv2GZMNWnQKvwG48VVg-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 01HLTkEL032079 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , jtomko@redhat.com, crobinso@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.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" Another vircgroup helper to avoid code repetition between the LXC and QEMU driver. Signed-off-by: Daniel Henrique Barboza Reviewed-by: J=C3=A1n Tomko --- 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 679e32116c..4c6ad89ecc 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1692,6 +1692,7 @@ virCgroupGetCpuacctStat; virCgroupGetCpuacctUsage; virCgroupGetCpuCfsPeriod; virCgroupGetCpuCfsQuota; +virCgroupGetCpuPeriodQuota; virCgroupGetCpusetCpus; virCgroupGetCpusetMemoryMigrate; virCgroupGetCpusetMems; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index fc559d736a..b2e9bc3a46 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1783,13 +1783,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 b65708385f..dda4bded08 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -10532,13 +10532,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 1f853beb73..70d85200cb 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -3739,3 +3739,17 @@ virCgroupSetupCpuPeriodQuota(virCgroupPtr cgroup, =20 return -1; } + + +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; +} diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index cc53bae258..a5bd35586d 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -227,6 +227,8 @@ int virCgroupSetupCpuShares(virCgroupPtr cgroup, unsign= ed 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 virCgroupGetCpuPeriodQuota(virCgroupPtr cgroup, unsigned long long *pe= riod, + long long *quota); int virCgroupSetupCpuPeriodQuota(virCgroupPtr cgroup, unsigned long long p= eriod, long long quota); =20 --=20 2.24.1