From nobody Tue Apr 30 19:42:19 2024 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=1560953860; cv=none; d=zoho.com; s=zohoarc; b=E3zkOsVnSiPFiLo/mWyDLGjHMv6Hch0YFH4MNI9jIjGjZwrx1R/sTN6e873OytIVzNmpntWlD1eP6wwegInti1dUApsPxmy8FpFP6NWqZr2JJqXo5hnquuQEXkVGKF30RMPIGs5y6nDgHgwuHzxIm5gtrox+HoIYqtBTArW/ZFg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560953860; 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=ZdiLaQbpAgwujFRdLVR1OZqUKlHhfaoHnMUk66+V2Rk=; b=eUzDlk658tlfAUSezMPDs6++Z9nQy+20SmOIyRH+7S2cOgB7cNpavSFOlA37FDA1f7Mo3ohygck2wjLIQc8qpGUxCiBQ18Yg5Ab4U2CBCcM5O/Czm7Ijdd+Mhj+oiGNR3U6um9E7XkJpCylsKlMlxQvd+59LYX2++n6wqM3mnm4= 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 1560953860977833.6457750280263; Wed, 19 Jun 2019 07:17:40 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 0704930C31AA; Wed, 19 Jun 2019 14:17:34 +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 CEB6710190A8; Wed, 19 Jun 2019 14:17:32 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1257A1806B1A; Wed, 19 Jun 2019 14:17:28 +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 x5JEGvrg017684 for ; Wed, 19 Jun 2019 10:16:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id 18C6B60FFE; Wed, 19 Jun 2019 14:16:57 +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 75E9660FAB for ; Wed, 19 Jun 2019 14:16:56 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Wed, 19 Jun 2019 16:16:47 +0200 Message-Id: <89d11dbd6cd11bda97731b6613e74bfbb1428575.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 1/4] util: vircgroup: introduce virCgroup(Get|Set)ValueRaw 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.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 19 Jun 2019 14:17:39 +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/set values instead of calling the existing get/set value functions which would be building the path again. Signed-off-by: Pavel Hrdina Reviewed-by: J=C3=A1n Tomko --- src/util/vircgroup.c | 62 ++++++++++++++++++++++++++-------------- src/util/vircgrouppriv.h | 6 ++++ 2 files changed, 46 insertions(+), 22 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index f58e336404..278453ea2f 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -455,28 +455,22 @@ virCgroupGetBlockDevString(const char *path) =20 =20 int -virCgroupSetValueStr(virCgroupPtr group, - int controller, - const char *key, +virCgroupSetValueRaw(const char *path, const char *value) { - VIR_AUTOFREE(char *) keypath =3D NULL; - char *tmp =3D NULL; + char *tmp; =20 - if (virCgroupPathOfController(group, controller, key, &keypath) < 0) - return -1; - - VIR_DEBUG("Set value '%s' to '%s'", keypath, value); - if (virFileWriteStr(keypath, value, 0) < 0) { + VIR_DEBUG("Set value '%s' to '%s'", path, value); + if (virFileWriteStr(path, value, 0) < 0) { if (errno =3D=3D EINVAL && - (tmp =3D strrchr(keypath, '/'))) { + (tmp =3D strrchr(path, '/'))) { virReportSystemError(errno, _("Invalid value '%s' for '%s'"), value, tmp + 1); return -1; } virReportSystemError(errno, - _("Unable to write to '%s'"), keypath); + _("Unable to write to '%s'"), path); return -1; } =20 @@ -485,24 +479,18 @@ virCgroupSetValueStr(virCgroupPtr group, =20 =20 int -virCgroupGetValueStr(virCgroupPtr group, - int controller, - const char *key, +virCgroupGetValueRaw(const char *path, char **value) { - VIR_AUTOFREE(char *) keypath =3D NULL; int rc; =20 *value =3D NULL; =20 - if (virCgroupPathOfController(group, controller, key, &keypath) < 0) - return -1; + VIR_DEBUG("Get value %s", path); =20 - VIR_DEBUG("Get value %s", keypath); - - if ((rc =3D virFileReadAll(keypath, 1024*1024, value)) < 0) { + if ((rc =3D virFileReadAll(path, 1024*1024, value)) < 0) { virReportSystemError(errno, - _("Unable to read from '%s'"), keypath); + _("Unable to read from '%s'"), path); return -1; } =20 @@ -514,6 +502,36 @@ virCgroupGetValueStr(virCgroupPtr group, } =20 =20 +int +virCgroupSetValueStr(virCgroupPtr group, + int controller, + const char *key, + const char *value) +{ + VIR_AUTOFREE(char *) keypath =3D NULL; + + if (virCgroupPathOfController(group, controller, key, &keypath) < 0) + return -1; + + return virCgroupSetValueRaw(keypath, value); +} + + +int +virCgroupGetValueStr(virCgroupPtr group, + int controller, + const char *key, + char **value) +{ + VIR_AUTOFREE(char *) keypath =3D NULL; + + if (virCgroupPathOfController(group, controller, key, &keypath) < 0) + return -1; + + return virCgroupGetValueRaw(keypath, value); +} + + int virCgroupGetValueForBlkDev(virCgroupPtr group, int controller, diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index 9110c77297..758091811e 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -58,6 +58,12 @@ struct _virCgroup { virCgroupV2Controller unified; }; =20 +int virCgroupSetValueRaw(const char *path, + const char *value); + +int virCgroupGetValueRaw(const char *path, + char **value); + int virCgroupSetValueStr(virCgroupPtr group, int controller, const char *key, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue Apr 30 19:42:19 2024 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 Reviewed-by: J=C3=A1n Tomko --- 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 From nobody Tue Apr 30 19:42:19 2024 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=1560953849; cv=none; d=zoho.com; s=zohoarc; b=mP9+aeCMW8w0+Ar4tEYWRVZ1io6GsesA3vYCO1wWNKXiE6Nfg8jg9usneVnWs+3hQRZrZcl5V134duxzXlZtzP7HMZbAOmbdMB4WuOua8jXWdpGU8J1ZvGVagu13DFzpCv09njcm45g2fO+JNBbdDsDQEDkm9qc/HLv8z6ZSqsQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560953849; 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=490QJ1NcUDlwIJCYW9EwTODdJ5gN7f54W2DXo/KR17g=; b=gXSqov/UuHitdGfhcV1AcCAHmfxH3RKA541MCe2+2fjCEvkGQgQ8Ae5dzj3YPQXVlLiIjGUdGI1HyNDIL61I00RYDI1AxfFjimG4KrRiDpUsVkmkP1nKIb0IuFRiAmzD5dseAUOdD3E+l3od3d4JPIVooibrP5IJLLn7Oek/kII= 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 15609538495891014.6173591394812; Wed, 19 Jun 2019 07:17:29 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 2A9E2308A9E2; Wed, 19 Jun 2019 14:17:08 +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 E7BC3608A7; 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 7C2EE19725; Wed, 19 Jun 2019 14:17:02 +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 x5JEH103017706 for ; Wed, 19 Jun 2019 10:17:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 104A760FAB; Wed, 19 Jun 2019 14:17:01 +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 7459260FFE for ; Wed, 19 Jun 2019 14:17:00 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Wed, 19 Jun 2019 16:16:49 +0200 Message-Id: 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 3/4] util: vircgroupv1: add support for BFQ blkio files 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 19 Jun 2019 14:17:23 +0000 (UTC) Content-Type: text/plain; charset="utf-8" In kernel 4.12 there was introduced new BFQ scheduler and in kernel 5.0 the old CFQ scheduler was removed. This has an implication on the cgroups file names. If the CFQ controller is enabled we use these two files: blkio.weight blkio.weight_device The new BFQ controller expose only one file with different name: blkio.bfq.weight The reason is that BFQ controller doesn't support per-device weight. Signed-off-by: Pavel Hrdina Reviewed-by: J=C3=A1n Tomko --- src/util/vircgroupv1.c | 114 ++++++++++++++++++++++++++++++++--------- 1 file changed, 90 insertions(+), 24 deletions(-) diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 064b99dceb..97258917bc 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -949,10 +949,33 @@ static int virCgroupV1SetBlkioWeight(virCgroupPtr group, unsigned int weight) { - return virCgroupSetValueU64(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.weight", - weight); + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(char *) value =3D NULL; + + if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.bfq.weight", &path) < 0) { + return -1; + } + + if (!virFileExists(path)) { + VIR_FREE(path); + + if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.weight", &path) < 0) { + return -1; + } + } + + if (!virFileExists(path)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("blkio device weight is valid only for bfq or cfq= scheduler")); + return -1; + } + + if (virAsprintf(&value, "%u", weight) < 0) + return -1; + + return virCgroupSetValueRaw(path, value); } =20 =20 @@ -960,14 +983,40 @@ static int virCgroupV1GetBlkioWeight(virCgroupPtr group, unsigned int *weight) { - unsigned long long tmp; - int ret; - ret =3D virCgroupGetValueU64(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.weight", &tmp); - if (ret =3D=3D 0) - *weight =3D tmp; - return ret; + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(char *) value =3D NULL; + + if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.bfq.weight", &path) < 0) { + return -1; + } + + if (!virFileExists(path)) { + VIR_FREE(path); + + if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.weight", &path) < 0) { + return -1; + } + } + + if (!virFileExists(path)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("blkio device weight is valid only for bfq or cfq= scheduler")); + return -1; + } + + if (virCgroupGetValueRaw(path, &value) < 0) + return -1; + + if (virStrToLong_ui(value, NULL, 10, weight) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to parse '%s' as an integer"), + value); + return -1; + } + + return 0; } =20 =20 @@ -1156,41 +1205,58 @@ virCgroupV1GetBlkioIoDeviceServiced(virCgroupPtr gr= oup, =20 static int virCgroupV1SetBlkioDeviceWeight(virCgroupPtr group, - const char *path, + const char *devPath, unsigned int weight) { VIR_AUTOFREE(char *) str =3D NULL; VIR_AUTOFREE(char *) blkstr =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; =20 - if (!(blkstr =3D virCgroupGetBlockDevString(path))) + if (!(blkstr =3D virCgroupGetBlockDevString(devPath))) return -1; =20 if (virAsprintf(&str, "%s%d", blkstr, weight) < 0) return -1; =20 - return virCgroupSetValueStr(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.weight_device", - str); + if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.weight_device", &path) < 0) { + return -1; + } + + if (!virFileExists(path)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("blkio device weight is valid only for cfq schedu= ler")); + return -1; + } + + return virCgroupSetValueRaw(path, str); } =20 =20 static int virCgroupV1GetBlkioDeviceWeight(virCgroupPtr group, - const char *path, + const char *devPath, unsigned int *weight) { VIR_AUTOFREE(char *) str =3D NULL; VIR_AUTOFREE(char *) value =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; =20 - if (virCgroupGetValueStr(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.weight_device", - &value) < 0) { + if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.weight_device", &path) < 0) { return -1; } =20 - if (virCgroupGetValueForBlkDev(value, path, &str) < 0) + if (!virFileExists(path)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("blkio device weight is valid only for cfq schedu= ler")); + return -1; + } + + if (virCgroupGetValueRaw(path, &value) < 0) + return -1; + + if (virCgroupGetValueForBlkDev(value, devPath, &str) < 0) return -1; =20 if (!str) { --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue Apr 30 19:42:19 2024 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=1560953868; cv=none; d=zoho.com; s=zohoarc; b=La5in5c5EO61kcP+IheCZUc/Q3blnf4Gl9LVDDL7criyTeul3pyyaeM7kwIaEsZ15OCjV9llyBaSK5kHtt+Fh/aF5e56FK7rO5HBXEG1IXgr5lvA61gTyN3U4Vy1TDecpQR47/icSlPT2M7k2b2GaBWkIAbCp3VMvlwmf9nzBh0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560953868; 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=0IFMyKY+OzQGiPWB2g/BRDmWXUizjT9Ih0tGlQm9glU=; b=js1ls7mBFNNZlgf7q1f6upS7ua3E5PIFgNp471rp6eGB3FTokOwdGbB8gn75UPQx8SsDoq647296ZOHFmH470k4n+oGKl/IiqRGvQjD8/6Fr9zn4mTlJEdC2qXawpTm+1BIol2zRuGZh0vNP8rWov+MBMT9XsajcZZN9GVhFtOU= 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 1560953868312889.3406506566448; Wed, 19 Jun 2019 07:17:48 -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 6C38181DE1; Wed, 19 Jun 2019 14:17:36 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3C60B6013D; Wed, 19 Jun 2019 14:17:34 +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 0F41F1806B16; Wed, 19 Jun 2019 14:17:30 +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 x5JEH3Rv017719 for ; Wed, 19 Jun 2019 10:17:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7E3AA60FFE; Wed, 19 Jun 2019 14:17:03 +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 06F6360FAB for ; Wed, 19 Jun 2019 14:17:01 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Wed, 19 Jun 2019 16:16:50 +0200 Message-Id: <9e8646a8d52fe08f67ace078531a85a9bbb3cae3.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 4/4] util: vircgroupv2: add support for BFQ files 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 19 Jun 2019 14:17:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" In kernel 4.12 there was introduced new BFQ scheduler and in kernel 5.0 the old CFQ scheduler was removed. This has an implication on the cgroups file names. If the CFQ controller is enabled we use one file: io.weight The new BFQ controller expose one file with different name: io.bfq.weight Except for different name they have different syntax. io.weight: default $val major:minor $val io.bfq.weight: $val The difference is that BFQ doesn't support per-device weight. Signed-off-by: Pavel Hrdina Reviewed-by: J=C3=A1n Tomko --- src/util/vircgroupv2.c | 101 +++++++++++++++++++++++++++++++---------- 1 file changed, 78 insertions(+), 23 deletions(-) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index de3a9dae8a..1179c4459a 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -554,15 +554,35 @@ static int virCgroupV2SetBlkioWeight(virCgroupPtr group, unsigned int weight) { + VIR_AUTOFREE(char *) path =3D NULL; VIR_AUTOFREE(char *) value =3D NULL; + const char *format =3D "%u"; =20 - if (virAsprintf(&value, "default %u", weight) < 0) + if (virCgroupV2PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO, + "io.bfq.weight", &path) < 0) { return -1; + } =20 - return virCgroupSetValueStr(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "io.weight", - value); + if (!virFileExists(path)) { + VIR_FREE(path); + format =3D "default %u"; + + if (virCgroupV2PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO, + "io.weight", &path) < 0) { + return -1; + } + } + + if (!virFileExists(path)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("blkio weight is valid only for bfq or cfq schedu= ler")); + return -1; + } + + if (virAsprintf(&value, format, weight) < 0) + return -1; + + return virCgroupSetValueRaw(path, value); } =20 =20 @@ -570,20 +590,38 @@ static int virCgroupV2GetBlkioWeight(virCgroupPtr group, unsigned int *weight) { + VIR_AUTOFREE(char *) path =3D NULL; VIR_AUTOFREE(char *) value =3D NULL; char *tmp; =20 - if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_BLKIO, - "io.weight", &value) < 0) { + if (virCgroupV2PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO, + "io.bfq.weight", &path) < 0) { return -1; } =20 - if (!(tmp =3D strstr(value, "default "))) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot find default io weight.")); + if (!virFileExists(path)) { + VIR_FREE(path); + + if (virCgroupV2PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO, + "io.weight", &path) < 0) { + return -1; + } + } + + if (!virFileExists(path)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("blkio weight is valid only for bfq or cfq schedu= ler")); return -1; } - tmp +=3D strlen("default "); + + if (virCgroupGetValueRaw(path, &value) < 0) + return -1; + + if ((tmp =3D strstr(value, "default "))) { + tmp +=3D strlen("default "); + } else { + tmp =3D value; + } =20 if (virStrToLong_ui(tmp, NULL, 10, weight) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -725,41 +763,58 @@ virCgroupV2GetBlkioIoDeviceServiced(virCgroupPtr grou= p, =20 static int virCgroupV2SetBlkioDeviceWeight(virCgroupPtr group, - const char *path, + const char *devPath, unsigned int weight) { + VIR_AUTOFREE(char *) path =3D NULL; VIR_AUTOFREE(char *) str =3D NULL; VIR_AUTOFREE(char *) blkstr =3D NULL; =20 - if (!(blkstr =3D virCgroupGetBlockDevString(path))) + if (!(blkstr =3D virCgroupGetBlockDevString(devPath))) return -1; =20 if (virAsprintf(&str, "%s%d", blkstr, weight) < 0) return -1; =20 - return virCgroupSetValueStr(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "io.weight", - str); + if (virCgroupV2PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO, + "io.weight", &path) < 0) { + return -1; + } + + if (!virFileExists(path)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("blkio device weight is valid only for cfq schedu= ler")); + return -1; + } + + return virCgroupSetValueRaw(path, str); } =20 =20 static int virCgroupV2GetBlkioDeviceWeight(virCgroupPtr group, - const char *path, + const char *devPath, unsigned int *weight) { + VIR_AUTOFREE(char *) path =3D NULL; VIR_AUTOFREE(char *) str =3D NULL; VIR_AUTOFREE(char *) value =3D NULL; =20 - if (virCgroupGetValueStr(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "io.weight", - &value) < 0) { + if (virCgroupV2PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO, + "io.weight", &path) < 0) { return -1; } =20 - if (virCgroupGetValueForBlkDev(value, path, &str) < 0) + if (!virFileExists(path)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("blkio device weight is valid only for cfq schedu= ler")); + return -1; + } + + if (virCgroupGetValueRaw(path, &value) < 0) + return -1; + + if (virCgroupGetValueForBlkDev(value, devPath, &str) < 0) return -1; =20 if (!str) { --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list