From nobody Fri May 16 01:17:33 2025 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1502371920803873.0670371103578; Thu, 10 Aug 2017 06:32:00 -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 CC1D9554C2; Thu, 10 Aug 2017 13:31:58 +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 2F26360BEB; Thu, 10 Aug 2017 13:31:58 +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 26CBF4BB79; Thu, 10 Aug 2017 13:31:55 +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 v7ADVsjL022591 for ; Thu, 10 Aug 2017 09:31:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6460FB1EDE; Thu, 10 Aug 2017 13:31:54 +0000 (UTC) Received: from caroline.localdomain (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0BBA1B1ED5 for ; Thu, 10 Aug 2017 13:31:51 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.brq.redhat.com [127.0.0.1]) by caroline.localdomain (Postfix) with ESMTP id 54DA51204A5 for ; Thu, 10 Aug 2017 15:31:50 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CC1D9554C2 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Martin Kletzander To: libvir-list@redhat.com Date: Thu, 10 Aug 2017 15:31:48 +0200 Message-Id: <15204a322ee1436887d84add58d7b5ee6589268e.1502368247.git.mkletzan@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 4/5] util: Make virResctrlGetCacheControlType() behave like other functions 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 10 Aug 2017 13:31:59 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" That means that returning negative values means error and non-negative values differ in meaning, but are all successful. Signed-off-by: Martin Kletzander --- src/conf/capabilities.c | 6 ++-- src/util/virresctrl.c | 84 ++++++++++++++++++++++++++++++++++-----------= ---- 2 files changed, 63 insertions(+), 27 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 18849adfcaec..69af3911a083 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -1647,15 +1647,17 @@ virCapabilitiesInitCaches(virCapsPtr caps) goto cleanup; =20 typeret =3D virResctrlGetCacheControlType(bank->level); + if (typeret < 0) + goto cleanup; =20 - if (typeret =3D=3D 0) { + if (typeret =3D=3D 1) { if (virResctrlGetCacheInfo(bank->level, bank->size, VIR_CACHE_TYPE_BOTH, &bank->controls, &bank->ncontrols) < 0) goto cleanup; - } else if (typeret =3D=3D 1) { + } else if (typeret =3D=3D 2) { if (virResctrlGetCacheInfo(bank->level, bank->size, VIR_CACHE_TYPE_CODE, diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index dfc062c2a0f8..ec1ad7b6edad 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -45,6 +45,16 @@ VIR_ENUM_IMPL(virCache, VIR_CACHE_TYPE_LAST, "code", "data") =20 +/* + * This is the same enum, but for the resctrl naming + * of the type (L) + */ +VIR_ENUM_DECL(virResctrl) +VIR_ENUM_IMPL(virResctrl, VIR_CACHE_TYPE_LAST, + "", + "CODE", + "DATA") + int virResctrlGetCacheInfo(unsigned int level, unsigned long long size, @@ -114,40 +124,64 @@ virResctrlGetCacheInfo(unsigned int level, } =20 =20 +static inline int +virResctrlGetCacheDir(char **path, + const char *prefix, + unsigned int level, + virCacheType type) +{ + return virAsprintf(path, + SYSFS_RESCTRL_PATH "%s/L%u%s", + prefix ? prefix : "", + level, + virResctrlTypeToString(type)); +} + + +/* + * This function tests whether TYPE of cache control is supported or not. + * + * Returns 0 if not, 1 if yes and negative value on error. + */ +static int +virResctrlGetCacheSupport(unsigned int level, virCacheType type) +{ + int ret =3D -1; + char *path =3D NULL; + + if (virResctrlGetCacheDir(&path, "/info", level, type) < 0) + return -1; + + ret =3D virFileExists(path); + VIR_FREE(path); + return ret; +} + + /* * This function tests which TYPE of cache control is supported * Return values are: - * -1: not supported - * 0: CAT - * 1: CDP + * -1: error + * 0: none + * 1: CAT + * 2: CDP */ int virResctrlGetCacheControlType(unsigned int level) { - int ret =3D -1; - char *path =3D NULL; + int rv =3D -1; =20 - if (virAsprintf(&path, - SYSFS_RESCTRL_PATH "/info/L%u", - level) < 0) + rv =3D virResctrlGetCacheSupport(level, VIR_CACHE_TYPE_BOTH); + if (rv < 0) return -1; + if (rv) + return 1; =20 - if (virFileExists(path)) { - ret =3D 0; - } else { - VIR_FREE(path); - /* - * If CDP is enabled, there will be both CODE and DATA, but it's e= nough - * to check one of those only. - */ - if (virAsprintf(&path, - SYSFS_RESCTRL_PATH "/info/L%uCODE", - level) < 0) - return -1; - if (virFileExists(path)) - ret =3D 1; - } + rv =3D virResctrlGetCacheSupport(level, VIR_CACHE_TYPE_CODE); + if (rv < 0) + return -1; + if (rv) + return 2; =20 - VIR_FREE(path); - return ret; + return 0; } --=20 2.14.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list