From nobody Sun Feb 8 19:24:38 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 ARC-Seal: i=1; a=rsa-sha256; t=1560953842; cv=none; d=zoho.com; s=zohoarc; b=WjUv44gvSkNxFjfeSNu9lyrPyRfux3ZruPtAe/VOVOs5vwe4vwtm0XaNFgf6tBBsEBz52H1ycQgqIy4+ajOaBCyQhkC58Lwf5JiJW1xICkoXbPaOiUI36uwRn7D2Z8S7MO9N1O0UeNOuilaul2VBnvtb8wMEAp1gEWRfxOGxCUo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560953842; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=Q7Rgs7AO5cslyNOTYt9Q/ChUWHVqsT1F0yxsmvUs2fg=; b=T6ySr5rLLHYM3Q+Z4Hk5bQYnoyjsRh1x+iQ1fhdXnbvoyHPbuowAmQjL7wC0dGz4SVg8JsCd+IrMwpGAaQGTMQ/sPQNtHSfxOz6oHzca7x6EZ8LTE5clIGRdcT+YX3/BTDdaeUjT2cS1mxgK/mYyqIvQscinsq2rMRl8t6h2t+0= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1560953842961372.742987243121; Wed, 19 Jun 2019 07:17:22 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 19E513680B; Wed, 19 Jun 2019 14:17:09 +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 E505760FFE; Wed, 19 Jun 2019 14:17:04 +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 82DE31806B19; Wed, 19 Jun 2019 14:17:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5JEH0ka017701 for ; Wed, 19 Jun 2019 10:17:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1A41584FF; Wed, 19 Jun 2019 14:17:00 +0000 (UTC) Received: from antique-laptop.redhat.com (ovpn-200-46.brq.redhat.com [10.40.200.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 674B36108C for ; Wed, 19 Jun 2019 14:16:57 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Wed, 19 Jun 2019 16:16:48 +0200 Message-Id: <34e625b8f03c40770332fb86bbb81768340150a7.1560953706.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/4] util: vircgroup: move virCgroupGetValueStr out of virCgroupGetValueForBlkDev 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: , 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 19 Jun 2019 14:17:21 +0000 (UTC) Content-Type: text/plain; charset="utf-8" If we need to get a path of specific file and we need to check its existence before we use it then we can reuse that path to get value for specific device. This way we will not build the path again in virCgroupGetValueForBlkDev. Signed-off-by: Pavel Hrdina --- src/util/vircgroup.c | 8 +---- src/util/vircgrouppriv.h | 6 ++-- src/util/vircgroupv1.c | 70 ++++++++++++++++++++++++++-------------- src/util/vircgroupv2.c | 65 +++++++++++++++++++++++-------------- 4 files changed, 88 insertions(+), 61 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 278453ea2f..e32215935b 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -533,20 +533,14 @@ virCgroupGetValueStr(virCgroupPtr group, =20 =20 int -virCgroupGetValueForBlkDev(virCgroupPtr group, - int controller, - const char *key, +virCgroupGetValueForBlkDev(const char *str, const char *path, char **value) { VIR_AUTOFREE(char *) prefix =3D NULL; - VIR_AUTOFREE(char *) str =3D NULL; char **lines =3D NULL; int ret =3D -1; =20 - if (virCgroupGetValueStr(group, controller, key, &str) < 0) - goto error; - if (!(prefix =3D virCgroupGetBlockDevString(path))) goto error; =20 diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index 758091811e..334095719e 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -98,10 +98,8 @@ int virCgroupPartitionEscape(char **path); =20 char *virCgroupGetBlockDevString(const char *path); =20 -int virCgroupGetValueForBlkDev(virCgroupPtr group, - int controller, - const char *key, - const char *path, +int virCgroupGetValueForBlkDev(const char *str, + const char *devPath, char **value); =20 int virCgroupNew(pid_t pid, diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 8ce10d3608..064b99dceb 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1181,12 +1181,16 @@ virCgroupV1GetBlkioDeviceWeight(virCgroupPtr group, unsigned int *weight) { VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) value =3D NULL; =20 - if (virCgroupGetValueForBlkDev(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.weight_device", - path, - &str) < 0) + if (virCgroupGetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.weight_device", + &value) < 0) { + return -1; + } + + if (virCgroupGetValueForBlkDev(value, path, &str) < 0) return -1; =20 if (!str) { @@ -1229,12 +1233,16 @@ virCgroupV1GetBlkioDeviceReadIops(virCgroupPtr grou= p, unsigned int *riops) { VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) value =3D NULL; =20 - if (virCgroupGetValueForBlkDev(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.throttle.read_iops_device", - path, - &str) < 0) + if (virCgroupGetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.throttle.read_iops_device", + &value) < 0) { + return -1; + } + + if (virCgroupGetValueForBlkDev(value, path, &str) < 0) return -1; =20 if (!str) { @@ -1277,12 +1285,16 @@ virCgroupV1GetBlkioDeviceWriteIops(virCgroupPtr gro= up, unsigned int *wiops) { VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) value =3D NULL; =20 - if (virCgroupGetValueForBlkDev(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.throttle.write_iops_device", - path, - &str) < 0) + if (virCgroupGetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.throttle.write_iops_device", + &value) < 0) { + return -1; + } + + if (virCgroupGetValueForBlkDev(value, path, &str) < 0) return -1; =20 if (!str) { @@ -1325,12 +1337,16 @@ virCgroupV1GetBlkioDeviceReadBps(virCgroupPtr group, unsigned long long *rbps) { VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) value =3D NULL; =20 - if (virCgroupGetValueForBlkDev(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.throttle.read_bps_device", - path, - &str) < 0) + if (virCgroupGetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.throttle.read_bps_device", + &value) < 0) { + return -1; + } + + if (virCgroupGetValueForBlkDev(value, path, &str) < 0) return -1; =20 if (!str) { @@ -1373,12 +1389,16 @@ virCgroupV1GetBlkioDeviceWriteBps(virCgroupPtr grou= p, unsigned long long *wbps) { VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) value =3D NULL; =20 - if (virCgroupGetValueForBlkDev(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.throttle.write_bps_device", - path, - &str) < 0) + if (virCgroupGetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.throttle.write_bps_device", + &value) < 0) { + return -1; + } + + if (virCgroupGetValueForBlkDev(value, path, &str) < 0) return -1; =20 if (!str) { diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 0cfbc96264..de3a9dae8a 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -750,15 +750,18 @@ virCgroupV2GetBlkioDeviceWeight(virCgroupPtr group, unsigned int *weight) { VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) value =3D NULL; =20 - if (virCgroupGetValueForBlkDev(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "io.weight", - path, - &str) < 0) { + if (virCgroupGetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "io.weight", + &value) < 0) { return -1; } =20 + if (virCgroupGetValueForBlkDev(value, path, &str) < 0) + return -1; + if (!str) { *weight =3D 0; } else if (virStrToLong_ui(str, NULL, 10, weight) < 0) { @@ -804,17 +807,20 @@ virCgroupV2GetBlkioDeviceReadIops(virCgroupPtr group, unsigned int *riops) { VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) value =3D NULL; const char *name =3D "riops=3D"; char *tmp; =20 - if (virCgroupGetValueForBlkDev(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "io.max", - path, - &str) < 0) { + if (virCgroupGetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "io.max", + &value) < 0) { return -1; } =20 + if (virCgroupGetValueForBlkDev(value, path, &str) < 0) + return -1; + if (!str) { *riops =3D 0; } else { @@ -872,17 +878,20 @@ virCgroupV2GetBlkioDeviceWriteIops(virCgroupPtr group, unsigned int *wiops) { VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) value =3D NULL; const char *name =3D "wiops=3D"; char *tmp; =20 - if (virCgroupGetValueForBlkDev(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "io.max", - path, - &str) < 0) { + if (virCgroupGetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "io.max", + &value) < 0) { return -1; } =20 + if (virCgroupGetValueForBlkDev(value, path, &str) < 0) + return -1; + if (!str) { *wiops =3D 0; } else { @@ -940,17 +949,20 @@ virCgroupV2GetBlkioDeviceReadBps(virCgroupPtr group, unsigned long long *rbps) { VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) value =3D NULL; const char *name =3D "rbps=3D"; char *tmp; =20 - if (virCgroupGetValueForBlkDev(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "io.max", - path, - &str) < 0) { + if (virCgroupGetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "io.max", + &value) < 0) { return -1; } =20 + if (virCgroupGetValueForBlkDev(value, path, &str) < 0) + return -1; + if (!str) { *rbps =3D 0; } else { @@ -1008,17 +1020,20 @@ virCgroupV2GetBlkioDeviceWriteBps(virCgroupPtr grou= p, unsigned long long *wbps) { VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) value =3D NULL; const char *name =3D "wbps=3D"; char *tmp; =20 - if (virCgroupGetValueForBlkDev(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "io.max", - path, - &str) < 0) { + if (virCgroupGetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "io.max", + &value) < 0) { return -1; } =20 + if (virCgroupGetValueForBlkDev(value, path, &str) < 0) + return -1; + if (!str) { *wbps =3D 0; } else { --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list