From nobody Sun Feb 8 07:48:13 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1537285654996651.8975575431214; Tue, 18 Sep 2018 08:47:34 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 1DF883002617; Tue, 18 Sep 2018 15:47:32 +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 E07D17E66D; Tue, 18 Sep 2018 15:47:31 +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 79412181D0AF; Tue, 18 Sep 2018 15:47:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8IFkdkm012477 for ; Tue, 18 Sep 2018 11:46:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6CBF15D9C7; Tue, 18 Sep 2018 15:46:39 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id E51F482216 for ; Tue, 18 Sep 2018 15:46:38 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:49 +0200 Message-Id: <52eaca00e90fa18ac7bebb94bb6f2f927633363d.1537285203.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 28/47] vircgroup: extract virCgroupV1(Set|Get)BlkioDeviceWriteBps 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 18 Sep 2018 15:47:33 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio --- src/util/vircgroup.c | 34 ++----------------------- src/util/vircgroupbackend.h | 12 +++++++++ src/util/vircgroupv1.c | 50 +++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 32 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 08b8387fba..ab50342dbb 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1437,19 +1437,7 @@ virCgroupSetBlkioDeviceWriteBps(virCgroupPtr group, const char *path, unsigned long long wbps) { - VIR_AUTOFREE(char *) str =3D NULL; - VIR_AUTOFREE(char *) blkstr =3D NULL; - - if (!(blkstr =3D virCgroupGetBlockDevString(path))) - return -1; - - if (virAsprintf(&str, "%s%llu", blkstr, wbps) < 0) - return -1; - - return virCgroupSetValueStr(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.throttle.write_bps_device", - str); + VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceWriteBps, -1, path, wbps); } =20 =20 @@ -1531,25 +1519,7 @@ virCgroupGetBlkioDeviceWriteBps(virCgroupPtr group, const char *path, unsigned long long *wbps) { - VIR_AUTOFREE(char *) str =3D NULL; - - if (virCgroupGetValueForBlkDev(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.throttle.write_bps_device", - path, - &str) < 0) - return -1; - - if (!str) { - *wbps =3D 0; - } else if (virStrToLong_ull(str, NULL, 10, wbps) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unable to parse '%s' as an integer"), - str); - return -1; - } - - return 0; + VIR_CGROUP_BACKEND_CALL(group, getBlkioDeviceWriteBps, -1, path, wbps); } =20 /** diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 3ec9a95327..b59462d6ab 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -192,6 +192,16 @@ typedef int const char *path, unsigned long long *rbps); =20 +typedef int +(*virCgroupSetBlkioDeviceWriteBpsCB)(virCgroupPtr group, + const char *path, + unsigned long long wbps); + +typedef int +(*virCgroupGetBlkioDeviceWriteBpsCB)(virCgroupPtr group, + const char *path, + unsigned long long *wbps); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -228,6 +238,8 @@ struct _virCgroupBackend { virCgroupGetBlkioDeviceWriteIopsCB getBlkioDeviceWriteIops; virCgroupSetBlkioDeviceReadBpsCB setBlkioDeviceReadBps; virCgroupGetBlkioDeviceReadBpsCB getBlkioDeviceReadBps; + virCgroupSetBlkioDeviceWriteBpsCB setBlkioDeviceWriteBps; + virCgroupGetBlkioDeviceWriteBpsCB getBlkioDeviceWriteBps; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 2c19e6147a..4f6d20e31f 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1329,6 +1329,54 @@ virCgroupV1GetBlkioDeviceReadBps(virCgroupPtr group, } =20 =20 +static int +virCgroupV1SetBlkioDeviceWriteBps(virCgroupPtr group, + const char *path, + unsigned long long wbps) +{ + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) blkstr =3D NULL; + + if (!(blkstr =3D virCgroupGetBlockDevString(path))) + return -1; + + if (virAsprintf(&str, "%s%llu", blkstr, wbps) < 0) + return -1; + + return virCgroupSetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.throttle.write_bps_device", + str); +} + + +static int +virCgroupV1GetBlkioDeviceWriteBps(virCgroupPtr group, + const char *path, + unsigned long long *wbps) +{ + VIR_AUTOFREE(char *) str =3D NULL; + + if (virCgroupGetValueForBlkDev(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.throttle.write_bps_device", + path, + &str) < 0) + return -1; + + if (!str) { + *wbps =3D 0; + } else if (virStrToLong_ull(str, NULL, 10, wbps) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to parse '%s' as an integer"), + str); + return -1; + } + + return 0; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -1363,6 +1411,8 @@ virCgroupBackend virCgroupV1Backend =3D { .getBlkioDeviceWriteIops =3D virCgroupV1GetBlkioDeviceWriteIops, .setBlkioDeviceReadBps =3D virCgroupV1SetBlkioDeviceReadBps, .getBlkioDeviceReadBps =3D virCgroupV1GetBlkioDeviceReadBps, + .setBlkioDeviceWriteBps =3D virCgroupV1SetBlkioDeviceWriteBps, + .getBlkioDeviceWriteBps =3D virCgroupV1GetBlkioDeviceWriteBps, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list