From nobody Mon Apr 29 16:36:49 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1528379679960103.89556861133849; Thu, 7 Jun 2018 06:54:39 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6013D81122; Thu, 7 Jun 2018 13:54:38 +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 1524728D35; Thu, 7 Jun 2018 13:54:38 +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 6FB504CA84; Thu, 7 Jun 2018 13:54:37 +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 w57DsYSs000417 for ; Thu, 7 Jun 2018 09:54:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 125DA2026DFD; Thu, 7 Jun 2018 13:54:34 +0000 (UTC) Received: from caroline (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C83522026DEF for ; Thu, 7 Jun 2018 13:54:33 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.usersys.redhat.com [127.0.0.1]) by caroline (Postfix) with ESMTP id CE6D012001E for ; Thu, 7 Jun 2018 15:54:32 +0200 (CEST) From: Martin Kletzander To: libvir-list@redhat.com Date: Thu, 7 Jun 2018 15:54:22 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 01/10] util: Rename resctrl to alloc if it is virResctrlAllocPtr 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 07 Jun 2018 13:54:39 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Just to stay consistent. Signed-off-by: Martin Kletzander Reviewed-by: J=EF=BF=BDn Tomko --- src/util/virresctrl.c | 64 +++++++++++++++++++++---------------------- src/util/virresctrl.h | 6 ++-- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index fc1163508ac1..c140276c0909 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -231,10 +231,10 @@ virResctrlAllocDispose(void *obj) size_t j =3D 0; size_t k =3D 0; =20 - virResctrlAllocPtr resctrl =3D obj; + virResctrlAllocPtr alloc =3D obj; =20 - for (i =3D 0; i < resctrl->nlevels; i++) { - virResctrlAllocPerLevelPtr level =3D resctrl->levels[i]; + for (i =3D 0; i < alloc->nlevels; i++) { + virResctrlAllocPerLevelPtr level =3D alloc->levels[i]; =20 if (!level) continue; @@ -259,9 +259,9 @@ virResctrlAllocDispose(void *obj) VIR_FREE(level); } =20 - VIR_FREE(resctrl->id); - VIR_FREE(resctrl->path); - VIR_FREE(resctrl->levels); + VIR_FREE(alloc->id); + VIR_FREE(alloc->path); + VIR_FREE(alloc->levels); } =20 =20 @@ -591,17 +591,17 @@ virResctrlInfoGetCache(virResctrlInfoPtr resctrl, =20 /* Alloc-related functions */ bool -virResctrlAllocIsEmpty(virResctrlAllocPtr resctrl) +virResctrlAllocIsEmpty(virResctrlAllocPtr alloc) { size_t i =3D 0; size_t j =3D 0; size_t k =3D 0; =20 - if (!resctrl) + if (!alloc) return true; =20 - for (i =3D 0; i < resctrl->nlevels; i++) { - virResctrlAllocPerLevelPtr a_level =3D resctrl->levels[i]; + for (i =3D 0; i < alloc->nlevels; i++) { + virResctrlAllocPerLevelPtr a_level =3D alloc->levels[i]; =20 if (!a_level) continue; @@ -629,30 +629,30 @@ virResctrlAllocIsEmpty(virResctrlAllocPtr resctrl) =20 =20 static virResctrlAllocPerTypePtr -virResctrlAllocGetType(virResctrlAllocPtr resctrl, +virResctrlAllocGetType(virResctrlAllocPtr alloc, unsigned int level, virCacheType type) { virResctrlAllocPerLevelPtr a_level =3D NULL; =20 - if (resctrl->nlevels <=3D level && - VIR_EXPAND_N(resctrl->levels, resctrl->nlevels, level - resctrl->n= levels + 1) < 0) + if (alloc->nlevels <=3D level && + VIR_EXPAND_N(alloc->levels, alloc->nlevels, level - alloc->nlevels= + 1) < 0) return NULL; =20 - if (!resctrl->levels[level]) { + if (!alloc->levels[level]) { virResctrlAllocPerTypePtr *types =3D NULL; =20 if (VIR_ALLOC_N(types, VIR_CACHE_TYPE_LAST) < 0) return NULL; =20 - if (VIR_ALLOC(resctrl->levels[level]) < 0) { + if (VIR_ALLOC(alloc->levels[level]) < 0) { VIR_FREE(types); return NULL; } - resctrl->levels[level]->types =3D types; + alloc->levels[level]->types =3D types; } =20 - a_level =3D resctrl->levels[level]; + a_level =3D alloc->levels[level]; =20 if (!a_level->types[type] && VIR_ALLOC(a_level->types[type]) < 0) return NULL; @@ -662,13 +662,13 @@ virResctrlAllocGetType(virResctrlAllocPtr resctrl, =20 =20 static int -virResctrlAllocUpdateMask(virResctrlAllocPtr resctrl, +virResctrlAllocUpdateMask(virResctrlAllocPtr alloc, unsigned int level, virCacheType type, unsigned int cache, virBitmapPtr mask) { - virResctrlAllocPerTypePtr a_type =3D virResctrlAllocGetType(resctrl, l= evel, type); + virResctrlAllocPerTypePtr a_type =3D virResctrlAllocGetType(alloc, lev= el, type); =20 if (!a_type) return -1; @@ -690,13 +690,13 @@ virResctrlAllocUpdateMask(virResctrlAllocPtr resctrl, =20 =20 static int -virResctrlAllocUpdateSize(virResctrlAllocPtr resctrl, +virResctrlAllocUpdateSize(virResctrlAllocPtr alloc, unsigned int level, virCacheType type, unsigned int cache, unsigned long long size) { - virResctrlAllocPerTypePtr a_type =3D virResctrlAllocGetType(resctrl, l= evel, type); + virResctrlAllocPerTypePtr a_type =3D virResctrlAllocGetType(alloc, lev= el, type); =20 if (!a_type) return -1; @@ -774,13 +774,13 @@ virResctrlAllocCheckCollision(virResctrlAllocPtr allo= c, =20 =20 int -virResctrlAllocSetSize(virResctrlAllocPtr resctrl, +virResctrlAllocSetSize(virResctrlAllocPtr alloc, unsigned int level, virCacheType type, unsigned int cache, unsigned long long size) { - if (virResctrlAllocCheckCollision(resctrl, level, type, cache)) { + if (virResctrlAllocCheckCollision(alloc, level, type, cache)) { virReportError(VIR_ERR_XML_ERROR, _("Colliding cache allocations for cache " "level '%u' id '%u', type '%s'"), @@ -788,12 +788,12 @@ virResctrlAllocSetSize(virResctrlAllocPtr resctrl, return -1; } =20 - return virResctrlAllocUpdateSize(resctrl, level, type, cache, size); + return virResctrlAllocUpdateSize(alloc, level, type, cache, size); } =20 =20 int -virResctrlAllocForeachSize(virResctrlAllocPtr resctrl, +virResctrlAllocForeachSize(virResctrlAllocPtr alloc, virResctrlAllocForeachSizeCallback cb, void *opaque) { @@ -802,11 +802,11 @@ virResctrlAllocForeachSize(virResctrlAllocPtr resctrl, unsigned int type =3D 0; unsigned int cache =3D 0; =20 - if (!resctrl) + if (!alloc) return 0; =20 - for (level =3D 0; level < resctrl->nlevels; level++) { - virResctrlAllocPerLevelPtr a_level =3D resctrl->levels[level]; + for (level =3D 0; level < alloc->nlevels; level++) { + virResctrlAllocPerLevelPtr a_level =3D alloc->levels[level]; =20 if (!a_level) continue; @@ -856,18 +856,18 @@ virResctrlAllocGetID(virResctrlAllocPtr alloc) =20 =20 char * -virResctrlAllocFormat(virResctrlAllocPtr resctrl) +virResctrlAllocFormat(virResctrlAllocPtr alloc) { virBuffer buf =3D VIR_BUFFER_INITIALIZER; unsigned int level =3D 0; unsigned int type =3D 0; unsigned int cache =3D 0; =20 - if (!resctrl) + if (!alloc) return NULL; =20 - for (level =3D 0; level < resctrl->nlevels; level++) { - virResctrlAllocPerLevelPtr a_level =3D resctrl->levels[level]; + for (level =3D 0; level < alloc->nlevels; level++) { + virResctrlAllocPerLevelPtr a_level =3D alloc->levels[level]; =20 if (!a_level) continue; diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h index 5368ba211924..cc648b521e8f 100644 --- a/src/util/virresctrl.h +++ b/src/util/virresctrl.h @@ -79,17 +79,17 @@ virResctrlAllocPtr virResctrlAllocNew(void); =20 bool -virResctrlAllocIsEmpty(virResctrlAllocPtr resctrl); +virResctrlAllocIsEmpty(virResctrlAllocPtr alloc); =20 int -virResctrlAllocSetSize(virResctrlAllocPtr resctrl, +virResctrlAllocSetSize(virResctrlAllocPtr alloc, unsigned int level, virCacheType type, unsigned int cache, unsigned long long size); =20 int -virResctrlAllocForeachSize(virResctrlAllocPtr resctrl, +virResctrlAllocForeachSize(virResctrlAllocPtr alloc, virResctrlAllocForeachSizeCallback cb, void *opaque); =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 16:36:49 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1528379695345679.48632866695; Thu, 7 Jun 2018 06:54:55 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id BA6EC30832C0; Thu, 7 Jun 2018 13:54:53 +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 77E435D9C5; Thu, 7 Jun 2018 13:54:53 +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 76D4E180BA80; Thu, 7 Jun 2018 13:54:51 +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 w57Dsa1T000463 for ; Thu, 7 Jun 2018 09:54:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id AA535111E3FE; Thu, 7 Jun 2018 13:54:36 +0000 (UTC) Received: from caroline (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 877EC111DCE5 for ; Thu, 7 Jun 2018 13:54:33 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.usersys.redhat.com [127.0.0.1]) by caroline (Postfix) with ESMTP id D945B12001F for ; Thu, 7 Jun 2018 15:54:32 +0200 (CEST) From: Martin Kletzander To: libvir-list@redhat.com Date: Thu, 7 Jun 2018 15:54:23 +0200 Message-Id: <9489d33bdea43a7720a9af1725c453588918fc1e.1528377367.git.mkletzan@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 02/10] util: Fix typo in error message %ud -> %u 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Thu, 07 Jun 2018 13:54:54 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Martin Kletzander Reviewed-by: J=EF=BF=BDn Tomko --- src/util/virresctrl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index c140276c0909..9a118fc3595d 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -941,7 +941,7 @@ virResctrlAllocParseProcessCache(virResctrlInfoPtr resc= trl, !resctrl->levels[level]->types[type]) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Missing or inconsistent resctrl info for " - "level '%ud' type '%s'"), + "level '%u' type '%s'"), level, virCacheTypeToString(type)); goto cleanup; } --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 16:36:49 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1528379680088671.6114346198449; Thu, 7 Jun 2018 06:54: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 AA2C2804E5; Thu, 7 Jun 2018 13:54:37 +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 26D02106223E; Thu, 7 Jun 2018 13:54:37 +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 9DA6F4CA82; Thu, 7 Jun 2018 13:54:36 +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 w57DsY2V000416 for ; Thu, 7 Jun 2018 09:54:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0F2F52035723; Thu, 7 Jun 2018 13:54:34 +0000 (UTC) Received: from caroline (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DFF1D2035721 for ; Thu, 7 Jun 2018 13:54:33 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.usersys.redhat.com [127.0.0.1]) by caroline (Postfix) with ESMTP id E44D412006B for ; Thu, 7 Jun 2018 15:54:32 +0200 (CEST) From: Martin Kletzander To: libvir-list@redhat.com Date: Thu, 7 Jun 2018 15:54:24 +0200 Message-Id: <83059507f479ec316a2006b8cfb460d1f4628a84.1528377367.git.mkletzan@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 03/10] util: Introduce virFileFlock 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.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.27]); Thu, 07 Jun 2018 13:54:39 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We already have virFileLock(), but we are now using flock() in the code as well (due to requirements for mutual exclusion between libvirt and other programs using flock() as well), so let's have a function for that as well = so we don't need to have stubs for unsupported platforms in other files. Signed-off-by: Martin Kletzander Reviewed-by: J=EF=BF=BDn Tomko --- src/libvirt_private.syms | 1 + src/util/virfile.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/util/virfile.h | 2 ++ 3 files changed, 43 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b4ab1f36290c..3a9680b3cd2b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1783,6 +1783,7 @@ virFileFindHugeTLBFS; virFileFindMountPoint; virFileFindResource; virFileFindResourceFull; +virFileFlock; virFileFreeACLs; virFileGetACLs; virFileGetHugepageSize; diff --git a/src/util/virfile.c b/src/util/virfile.c index 12b41a64e030..9296ccbe2a4f 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -51,6 +51,7 @@ #if HAVE_SYS_ACL_H # include #endif +#include =20 #ifdef __linux__ # if HAVE_LINUX_MAGIC_H @@ -362,6 +363,7 @@ virFileWrapperFdFree(virFileWrapperFdPtr wfd) =20 =20 #ifndef WIN32 + /** * virFileLock: * @fd: file descriptor to acquire the lock on @@ -430,7 +432,32 @@ int virFileUnlock(int fd, off_t start, off_t len) =20 return 0; } + + +/** + * virFileFlock: + * @fd: file descriptor to call flock on + * @lock: true for lock, false for unlock + * @shared: true if shared, false for exclusive, ignored if `@lock =3D=3D = false` + * + * This is just a simple wrapper around flock(2) that errors out on unsupp= orted + * platforms. + * + * The lock will be released when @fd is closed or this function is called= with + * `@lock =3D=3D false`. + * + * Returns 0 on success, -1 otherwise (with errno set) + */ +int virFileFlock(int fd, bool lock, bool shared) +{ + if (lock) + return flock(fd, shared ? LOCK_SH : LOCK_EX); + + return flock(fd, LOCK_UN); +} + #else + int virFileLock(int fd ATTRIBUTE_UNUSED, bool shared ATTRIBUTE_UNUSED, off_t start ATTRIBUTE_UNUSED, @@ -439,14 +466,27 @@ int virFileLock(int fd ATTRIBUTE_UNUSED, { return -ENOSYS; } + + int virFileUnlock(int fd ATTRIBUTE_UNUSED, off_t start ATTRIBUTE_UNUSED, off_t len ATTRIBUTE_UNUSED) { return -ENOSYS; } + + +int virFileFlock(int fd ATTRIBUTE_UNUSED, + bool lock ATTRIBUTE_UNUSED, + bool shared ATTRIBUTE_UNUSED) +{ + errno =3D ENOSYS; + return -1; +} + #endif =20 + int virFileRewrite(const char *path, mode_t mode, diff --git a/src/util/virfile.h b/src/util/virfile.h index 59c14b97a6ac..6f1e802fde78 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -104,6 +104,8 @@ void virFileWrapperFdFree(virFileWrapperFdPtr dfd); int virFileLock(int fd, bool shared, off_t start, off_t len, bool waitForL= ock); int virFileUnlock(int fd, off_t start, off_t len); =20 +int virFileFlock(int fd, bool lock, bool shared); + typedef int (*virFileRewriteFunc)(int fd, const void *opaque); int virFileRewrite(const char *path, mode_t mode, --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 16:36:49 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15283797003671016.540303854509; Thu, 7 Jun 2018 06:55:00 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 505F73086267; Thu, 7 Jun 2018 13:54:59 +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 12F683001A64; Thu, 7 Jun 2018 13:54:59 +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 8C9DF180BA87; Thu, 7 Jun 2018 13:54:58 +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 w57Dsa0J000461 for ; Thu, 7 Jun 2018 09:54:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id AB0011002962; Thu, 7 Jun 2018 13:54:36 +0000 (UTC) Received: from caroline (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 88164111DD03 for ; Thu, 7 Jun 2018 13:54:33 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.usersys.redhat.com [127.0.0.1]) by caroline (Postfix) with ESMTP id EFCB912006C for ; Thu, 7 Jun 2018 15:54:32 +0200 (CEST) From: Martin Kletzander To: libvir-list@redhat.com Date: Thu, 7 Jun 2018 15:54:25 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 04/10] util: Avoid needless preprocessor conditionals in virresctrl 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.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Thu, 07 Jun 2018 13:54:59 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By exporting virResctrlAllocMasksAssign() we can remove most of the conditionals. And that function should be used from the tests later anyway. Signed-off-by: Martin Kletzander Reviewed-by: J=EF=BF=BDn Tomko --- src/libvirt_private.syms | 1 + src/util/virresctrl.c | 30 +----------------------------- src/util/virresctrlpriv.h | 4 ++++ 3 files changed, 6 insertions(+), 29 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 3a9680b3cd2b..6a8b40bbbdb1 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2628,6 +2628,7 @@ virResctrlAllocForeachSize; virResctrlAllocFormat; virResctrlAllocGetID; virResctrlAllocGetUnused; +virResctrlAllocMasksAssign; virResctrlAllocNew; virResctrlAllocRemove; virResctrlAllocSetID; diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 9a118fc3595d..787db31b6126 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -380,8 +380,6 @@ virResctrlInfoIsEmpty(virResctrlInfoPtr resctrl) } =20 =20 -#ifdef __linux__ - int virResctrlGetInfo(virResctrlInfoPtr resctrl) { @@ -512,18 +510,6 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl) return ret; } =20 -#else /* ! __linux__ */ - -int -virResctrlGetInfo(virResctrlInfoPtr resctrl ATTRIBUTE_UNUSED) -{ - virReportSystemError(ENOSYS, "%s", - _("Cache tune not supported on this platform")); - return -1; -} - -#endif /* ! __linux__ */ - =20 int virResctrlInfoGetCache(virResctrlInfoPtr resctrl, @@ -1089,8 +1075,6 @@ virResctrlAllocGetDefault(virResctrlInfoPtr resctrl) } =20 =20 -#ifdef __linux__ - static void virResctrlAllocSubtractPerType(virResctrlAllocPerTypePtr dst, virResctrlAllocPerTypePtr src) @@ -1246,18 +1230,6 @@ virResctrlAllocGetUnused(virResctrlInfoPtr resctrl) goto cleanup; } =20 -#else /* ! __linux__ */ - -virResctrlAllocPtr -virResctrlAllocGetUnused(virResctrlInfoPtr resctrl ATTRIBUTE_UNUSED) -{ - virReportSystemError(ENOSYS, "%s", - _("Cache tune not supported on this platform")); - return NULL; -} - -#endif /* ! __linux__ */ - =20 /* * Given the information about requested allocation type `a_type`, the host @@ -1434,7 +1406,7 @@ virResctrlAllocCopyMasks(virResctrlAllocPtr dst, * then tries to find a proper space for every requested allocation effect= ively * transforming `sizes` into `masks`. */ -static int +int virResctrlAllocMasksAssign(virResctrlInfoPtr resctrl, virResctrlAllocPtr alloc) { diff --git a/src/util/virresctrlpriv.h b/src/util/virresctrlpriv.h index 72b115afd13e..80ddd4b875a3 100644 --- a/src/util/virresctrlpriv.h +++ b/src/util/virresctrlpriv.h @@ -24,4 +24,8 @@ virResctrlAllocPtr virResctrlAllocGetUnused(virResctrlInfoPtr resctrl); =20 +int +virResctrlAllocMasksAssign(virResctrlInfoPtr resctrl, + virResctrlAllocPtr alloc); + #endif /* __VIR_RESCTRL_PRIV_H__ */ --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 16:36:49 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1528379688637845.8308777350364; Thu, 7 Jun 2018 06:54:48 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 69D433086256; Thu, 7 Jun 2018 13:54:45 +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 1171D308BDAA; Thu, 7 Jun 2018 13:54:45 +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 4C1BF180BA83; Thu, 7 Jun 2018 13:54:44 +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 w57DsZNr000428 for ; Thu, 7 Jun 2018 09:54:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id 29F392035723; Thu, 7 Jun 2018 13:54:35 +0000 (UTC) Received: from caroline (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 07A7C2035721 for ; Thu, 7 Jun 2018 13:54:35 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.usersys.redhat.com [127.0.0.1]) by caroline (Postfix) with ESMTP id 06FAD12006E for ; Thu, 7 Jun 2018 15:54:33 +0200 (CEST) From: Martin Kletzander To: libvir-list@redhat.com Date: Thu, 7 Jun 2018 15:54:26 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 05/10] util: Use virFileFlock() in virresctrl 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.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Thu, 07 Jun 2018 13:54:48 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" That way we get rid of the last preprocessor conditional so the code compil= es on all platforms. Signed-off-by: Martin Kletzander Reviewed-by: J=EF=BF=BDn Tomko --- src/util/virresctrl.c | 31 ++++--------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 787db31b6126..ef649a08bf73 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -289,9 +289,8 @@ virResctrlAllocNew(void) =20 =20 /* Common functions */ -#ifdef __linux__ static int -virResctrlLockInternal(int op) +virResctrlLockWrite(void) { int fd =3D open(SYSFS_RESCTRL_PATH, O_DIRECTORY | O_CLOEXEC); =20 @@ -300,7 +299,7 @@ virResctrlLockInternal(int op) return -1; } =20 - if (flock(fd, op) < 0) { + if (virFileFlock(fd, true, true) < 0) { virReportSystemError(errno, "%s", _("Cannot lock resctrl")); VIR_FORCE_CLOSE(fd); return -1; @@ -310,45 +309,23 @@ virResctrlLockInternal(int op) } =20 =20 -static inline int -virResctrlLockWrite(void) -{ - return virResctrlLockInternal(LOCK_EX); -} - -#else - -static inline int -virResctrlLockWrite(void) -{ - virReportSystemError(ENOSYS, "%s", - _("resctrl not supported on this platform")); - return -1; -} - -#endif - - - - static int virResctrlUnlock(int fd) { if (fd =3D=3D -1) return 0; =20 -#ifdef __linux__ /* The lock gets unlocked by closing the fd, which we need to do anywa= y in * order to clean up properly */ if (VIR_CLOSE(fd) < 0) { virReportSystemError(errno, "%s", _("Cannot close resctrl")); =20 /* Trying to save the already broken */ - if (flock(fd, LOCK_UN) < 0) + if (virFileFlock(fd, false, false) < 0) virReportSystemError(errno, "%s", _("Cannot unlock resctrl")); + return -1; } -#endif /* ! __linux__ */ =20 return 0; } --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 16:36:49 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 152837969271547.11562050053567; Thu, 7 Jun 2018 06:54:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AD32E308A94C; Thu, 7 Jun 2018 13:54:51 +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 686B5617A5; Thu, 7 Jun 2018 13:54:51 +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 0EEB14CA87; Thu, 7 Jun 2018 13:54:51 +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 w57DsZHL000430 for ; Thu, 7 Jun 2018 09:54:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4573F202699A; Thu, 7 Jun 2018 13:54:35 +0000 (UTC) Received: from caroline (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0767D2026DEF for ; Thu, 7 Jun 2018 13:54:35 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.usersys.redhat.com [127.0.0.1]) by caroline (Postfix) with ESMTP id 120C212006F for ; Thu, 7 Jun 2018 15:54:33 +0200 (CEST) From: Martin Kletzander To: libvir-list@redhat.com Date: Thu, 7 Jun 2018 15:54:27 +0200 Message-Id: <668abca3969e114aa64b88315b735da4f3c311c4.1528377367.git.mkletzan@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 06/10] util: Reorder parts of virresctrl 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 07 Jun 2018 13:54:52 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Move description of the purpose of the file before any definition. One empty line between related enum definitions. All typedefs before all structs. This is exception from the usual, but not= the only one, we already have something similar for some other structs. This w= ay we can move contents between structs and reorder some parts nicely without mov= ing all definitions of one type before another one just so it's defined. Define all classes in one place. Have one initialization function for all classes in the file. Signed-off-by: Martin Kletzander Reviewed-by: J=EF=BF=BDn Tomko --- src/util/virresctrl.c | 156 +++++++++++++++++++++--------------------- 1 file changed, 79 insertions(+), 77 deletions(-) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index ef649a08bf73..0266fee4e959 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -37,21 +37,22 @@ VIR_LOG_INIT("util.virresctrl") =20 =20 -/* Common definitions */ -#define SYSFS_RESCTRL_PATH "/sys/fs/resctrl" - /* Resctrl is short for Resource Control. It might be implemented for var= ious * resources, but at the time of this writing this is only supported for c= ache * allocation technology (aka CAT). Hence the reson for leaving 'Cache' o= ut of * all the structure and function names for now (can be added later if nee= ded. */ =20 + +/* Common definitions */ +#define SYSFS_RESCTRL_PATH "/sys/fs/resctrl" + + /* Our naming for cache types and scopes */ VIR_ENUM_IMPL(virCache, VIR_CACHE_TYPE_LAST, "both", "code", "data") - /* * This is the same enum, but for the resctrl naming * of the type (L) @@ -63,9 +64,28 @@ VIR_ENUM_IMPL(virResctrl, VIR_CACHE_TYPE_LAST, "DATA") =20 =20 -/* Info-related definitions and InfoClass-related functions */ +/* All private typedefs so that they exist for all later definitions. Thi= s way + * structs can be included in one or another without reorganizing the code= every + * time. */ typedef struct _virResctrlInfoPerType virResctrlInfoPerType; typedef virResctrlInfoPerType *virResctrlInfoPerTypePtr; + +typedef struct _virResctrlInfoPerLevel virResctrlInfoPerLevel; +typedef virResctrlInfoPerLevel *virResctrlInfoPerLevelPtr; + +typedef struct _virResctrlAllocPerType virResctrlAllocPerType; +typedef virResctrlAllocPerType *virResctrlAllocPerTypePtr; + +typedef struct _virResctrlAllocPerLevel virResctrlAllocPerLevel; +typedef virResctrlAllocPerLevel *virResctrlAllocPerLevelPtr; + + +/* Class definitions and initializations */ +static virClassPtr virResctrlInfoClass; +static virClassPtr virResctrlAllocClass; + + +/* virResctrlInfo */ struct _virResctrlInfoPerType { /* Kernel-provided information */ char *cbm_mask; @@ -86,8 +106,6 @@ struct _virResctrlInfoPerType { virResctrlInfoPerCache control; }; =20 -typedef struct _virResctrlInfoPerLevel virResctrlInfoPerLevel; -typedef virResctrlInfoPerLevel *virResctrlInfoPerLevelPtr; struct _virResctrlInfoPerLevel { virResctrlInfoPerTypePtr *types; }; @@ -99,7 +117,6 @@ struct _virResctrlInfo { size_t nlevels; }; =20 -static virClassPtr virResctrlInfoClass; =20 static void virResctrlInfoDispose(void *obj) @@ -130,30 +147,7 @@ virResctrlInfoDispose(void *obj) } =20 =20 -static int -virResctrlInfoOnceInit(void) -{ - if (!VIR_CLASS_NEW(virResctrlInfo, virClassForObject())) - return -1; - - return 0; -} - - -VIR_ONCE_GLOBAL_INIT(virResctrlInfo) - - -virResctrlInfoPtr -virResctrlInfoNew(void) -{ - if (virResctrlInfoInitialize() < 0) - return NULL; - - return virObjectNew(virResctrlInfoClass); -} - - -/* Alloc-related definitions and AllocClass-related functions */ +/* virResctrlAlloc */ =20 /* * virResctrlAlloc represents one allocation (in XML under cputune/cachetu= ne and @@ -186,8 +180,6 @@ virResctrlInfoNew(void) * virBitmaps named `masks` indexed the same way as `sizes`. The upper bo= unds * of the sparse arrays are stored in nmasks or nsizes, respectively. */ -typedef struct _virResctrlAllocPerType virResctrlAllocPerType; -typedef virResctrlAllocPerType *virResctrlAllocPerTypePtr; struct _virResctrlAllocPerType { /* There could be bool saying whether this is set or not, but since ev= erything * in virResctrlAlloc (and most of libvirt) goes with pointer arrays w= e would @@ -201,8 +193,6 @@ struct _virResctrlAllocPerType { size_t nmasks; }; =20 -typedef struct _virResctrlAllocPerLevel virResctrlAllocPerLevel; -typedef virResctrlAllocPerLevel *virResctrlAllocPerLevelPtr; struct _virResctrlAllocPerLevel { virResctrlAllocPerTypePtr *types; /* Indexed with enum virCacheType */ /* There is no `ntypes` member variable as it is always allocated for @@ -222,7 +212,6 @@ struct _virResctrlAlloc { char *path; }; =20 -static virClassPtr virResctrlAllocClass; =20 static void virResctrlAllocDispose(void *obj) @@ -265,27 +254,20 @@ virResctrlAllocDispose(void *obj) } =20 =20 +/* Global initialization for classes */ static int -virResctrlAllocOnceInit(void) +virResctrlOnceInit(void) { + if (!VIR_CLASS_NEW(virResctrlInfo, virClassForObject())) + return -1; + if (!VIR_CLASS_NEW(virResctrlAlloc, virClassForObject())) return -1; =20 return 0; } =20 - -VIR_ONCE_GLOBAL_INIT(virResctrlAlloc) - - -virResctrlAllocPtr -virResctrlAllocNew(void) -{ - if (virResctrlAllocInitialize() < 0) - return NULL; - - return virObjectNew(virResctrlAllocClass); -} +VIR_ONCE_GLOBAL_INIT(virResctrl) =20 =20 /* Common functions */ @@ -331,32 +313,7 @@ virResctrlUnlock(int fd) } =20 =20 -/* Info-related functions */ -static bool -virResctrlInfoIsEmpty(virResctrlInfoPtr resctrl) -{ - size_t i =3D 0; - size_t j =3D 0; - - if (!resctrl) - return true; - - for (i =3D 0; i < resctrl->nlevels; i++) { - virResctrlInfoPerLevelPtr i_level =3D resctrl->levels[i]; - - if (!i_level) - continue; - - for (j =3D 0; j < VIR_CACHE_TYPE_LAST; j++) { - if (i_level->types[j]) - return false; - } - } - - return true; -} - - +/* virResctrlInfo-related definitions */ int virResctrlGetInfo(virResctrlInfoPtr resctrl) { @@ -488,6 +445,41 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl) } =20 =20 +virResctrlInfoPtr +virResctrlInfoNew(void) +{ + if (virResctrlInitialize() < 0) + return NULL; + + return virObjectNew(virResctrlInfoClass); +} + + +static bool +virResctrlInfoIsEmpty(virResctrlInfoPtr resctrl) +{ + size_t i =3D 0; + size_t j =3D 0; + + if (!resctrl) + return true; + + for (i =3D 0; i < resctrl->nlevels; i++) { + virResctrlInfoPerLevelPtr i_level =3D resctrl->levels[i]; + + if (!i_level) + continue; + + for (j =3D 0; j < VIR_CACHE_TYPE_LAST; j++) { + if (i_level->types[j]) + return false; + } + } + + return true; +} + + int virResctrlInfoGetCache(virResctrlInfoPtr resctrl, unsigned int level, @@ -552,7 +544,17 @@ virResctrlInfoGetCache(virResctrlInfoPtr resctrl, } =20 =20 -/* Alloc-related functions */ +/* virResctrlAlloc-related definitions */ +virResctrlAllocPtr +virResctrlAllocNew(void) +{ + if (virResctrlInitialize() < 0) + return NULL; + + return virObjectNew(virResctrlAllocClass); +} + + bool virResctrlAllocIsEmpty(virResctrlAllocPtr alloc) { --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 16:36:49 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1528379686743420.25327758430547; Thu, 7 Jun 2018 06:54:46 -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 259A53082A2C; Thu, 7 Jun 2018 13:54:45 +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 9F07F6090B; Thu, 7 Jun 2018 13:54:44 +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 E58F7180BA81; Thu, 7 Jun 2018 13:54:43 +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 w57DsZCJ000429 for ; Thu, 7 Jun 2018 09:54:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2A8162026993; Thu, 7 Jun 2018 13:54:35 +0000 (UTC) Received: from caroline (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 084C62026DFD for ; Thu, 7 Jun 2018 13:54:35 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.usersys.redhat.com [127.0.0.1]) by caroline (Postfix) with ESMTP id 1CE3A120070 for ; Thu, 7 Jun 2018 15:54:33 +0200 (CEST) From: Martin Kletzander To: libvir-list@redhat.com Date: Thu, 7 Jun 2018 15:54:28 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 07/10] util: Initialize virResctrlInfo struct right away 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.45]); Thu, 07 Jun 2018 13:54:45 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" There is no need to have virResctrlGetInfo() when it must be called after virResctrlInfoNew() anyway, otherwise it's just an unusable object. When we wrap the logic inside the New() function we'll save some calls later as wel= l. Signed-off-by: Martin Kletzander Reviewed-by: J=EF=BF=BDn Tomko --- src/conf/capabilities.c | 2 +- src/libvirt_private.syms | 1 - src/util/virresctrl.c | 15 +++++++++++++-- src/util/virresctrl.h | 3 --- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index d5f6f007300a..978edf871943 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -1604,7 +1604,7 @@ virCapabilitiesInitResctrl(virCapsPtr caps) if (!caps->host.resctrl) return -1; =20 - return virResctrlGetInfo(caps->host.resctrl); + return 0; } =20 =20 diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 6a8b40bbbdb1..20ec8760ec27 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2633,7 +2633,6 @@ virResctrlAllocNew; virResctrlAllocRemove; virResctrlAllocSetID; virResctrlAllocSetSize; -virResctrlGetInfo; virResctrlInfoGetCache; virResctrlInfoNew; =20 diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 0266fee4e959..4e35b19649ca 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -314,7 +314,7 @@ virResctrlUnlock(int fd) =20 =20 /* virResctrlInfo-related definitions */ -int +static int virResctrlGetInfo(virResctrlInfoPtr resctrl) { DIR *dirp =3D NULL; @@ -448,10 +448,21 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl) virResctrlInfoPtr virResctrlInfoNew(void) { + virResctrlInfoPtr ret =3D NULL; + if (virResctrlInitialize() < 0) return NULL; =20 - return virObjectNew(virResctrlInfoClass); + ret =3D virObjectNew(virResctrlInfoClass); + if (!ret) + return NULL; + + if (virResctrlGetInfo(ret) < 0) { + virObjectUnref(ret); + return NULL; + } + + return ret; } =20 =20 diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h index cc648b521e8f..a348fa7ab195 100644 --- a/src/util/virresctrl.h +++ b/src/util/virresctrl.h @@ -55,9 +55,6 @@ typedef virResctrlInfo *virResctrlInfoPtr; virResctrlInfoPtr virResctrlInfoNew(void); =20 -int -virResctrlGetInfo(virResctrlInfoPtr resctrl); - int virResctrlInfoGetCache(virResctrlInfoPtr resctrl, unsigned int level, --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 16:36:49 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1528379700938896.1757556102957; Thu, 7 Jun 2018 06:55:00 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 9D3D33082138; Thu, 7 Jun 2018 13:54:59 +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 3C9EF5D75A; Thu, 7 Jun 2018 13:54:59 +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 CF4E5180BA88; Thu, 7 Jun 2018 13:54:58 +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 w57Dsclg000487 for ; Thu, 7 Jun 2018 09:54:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9358D1C66F; Thu, 7 Jun 2018 13:54:38 +0000 (UTC) Received: from caroline (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 716C06F9E1 for ; Thu, 7 Jun 2018 13:54:35 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.usersys.redhat.com [127.0.0.1]) by caroline (Postfix) with ESMTP id 27F16120071 for ; Thu, 7 Jun 2018 15:54:33 +0200 (CEST) From: Martin Kletzander To: libvir-list@redhat.com Date: Thu, 7 Jun 2018 15:54:29 +0200 Message-Id: <222041a57ba5b86bb1e23649c39a7945985ab8c7.1528377367.git.mkletzan@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 08/10] Move virCacheKernel enum implemetation from conf/ to util/ 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Thu, 07 Jun 2018 13:55:00 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" It will be used in that file later on, plus it makes sense for all the implementations to be in same place. Also comment each one of them nicely = and add a comment explaining why they all need to end with the same _LAST value. Signed-off-by: Martin Kletzander Reviewed-by: J=EF=BF=BDn Tomko --- src/conf/capabilities.c | 6 ------ src/libvirt_private.syms | 2 ++ src/util/virresctrl.c | 19 ++++++++++++++----- src/util/virresctrl.h | 1 + 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 978edf871943..7a810efa6662 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -1544,12 +1544,6 @@ virCapabilitiesInitPages(virCapsPtr caps) return ret; } =20 -/* Cache name mapping for Linux kernel naming */ -VIR_ENUM_DECL(virCacheKernel); -VIR_ENUM_IMPL(virCacheKernel, VIR_CACHE_TYPE_LAST, - "Unified", - "Instruction", - "Data") =20 bool virCapsHostCacheBankEquals(virCapsHostCacheBankPtr a, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 20ec8760ec27..a4a0c95b474d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2619,6 +2619,8 @@ virRandomInt; =20 =20 # util/virresctrl.h +virCacheKernelTypeFromString; +virCacheKernelTypeToString; virCacheTypeFromString; virCacheTypeToString; virResctrlAllocAddPID; diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 4e35b19649ca..481577bbb9f6 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -48,15 +48,24 @@ VIR_LOG_INIT("util.virresctrl") #define SYSFS_RESCTRL_PATH "/sys/fs/resctrl" =20 =20 -/* Our naming for cache types and scopes */ +/* Following are three different enum implementations for the same enum. = Each + * one of them helps translating to/from strings for different interfaces.= The + * delimiter must be VIR_CACHE_TYPE_LAST for all of them in order to stay + * consistent in between all of them. */ + +/* Cache name mapping for Linux kernel naming. */ +VIR_ENUM_IMPL(virCacheKernel, VIR_CACHE_TYPE_LAST, + "Unified", + "Instruction", + "Data") + +/* Cache name mapping for our XML naming. */ VIR_ENUM_IMPL(virCache, VIR_CACHE_TYPE_LAST, "both", "code", "data") -/* - * This is the same enum, but for the resctrl naming - * of the type (L) - */ + +/* Cache name mapping for resctrl interface naming. */ VIR_ENUM_DECL(virResctrl) VIR_ENUM_IMPL(virResctrl, VIR_CACHE_TYPE_LAST, "", diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h index a348fa7ab195..9052a2b19a02 100644 --- a/src/util/virresctrl.h +++ b/src/util/virresctrl.h @@ -34,6 +34,7 @@ typedef enum { } virCacheType; =20 VIR_ENUM_DECL(virCache); +VIR_ENUM_DECL(virCacheKernel); =20 =20 typedef struct _virResctrlInfoPerCache virResctrlInfoPerCache; --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 16:36:49 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 152837968656619.467781061039545; Thu, 7 Jun 2018 06:54:46 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1ED993082136; Thu, 7 Jun 2018 13:54:45 +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 CFA992007FE0; Thu, 7 Jun 2018 13:54:44 +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 429E7180BA82; Thu, 7 Jun 2018 13:54:44 +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 w57DsaIS000452 for ; Thu, 7 Jun 2018 09:54:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4303C2035725; Thu, 7 Jun 2018 13:54:36 +0000 (UTC) Received: from caroline (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 201FA2035721 for ; Thu, 7 Jun 2018 13:54:36 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.usersys.redhat.com [127.0.0.1]) by caroline (Postfix) with ESMTP id 3301B120072 for ; Thu, 7 Jun 2018 15:54:33 +0200 (CEST) From: Martin Kletzander To: libvir-list@redhat.com Date: Thu, 7 Jun 2018 15:54:30 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 09/10] util: Remove cbm_mask from virResctrlInfoPerType 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.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Thu, 07 Jun 2018 13:54:45 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" It was used just temporarily to do a calculation, no need to keep that arou= nd. Also use virBitmap in the code instead of reimplementing two of its existing functions. And move the counting part next to where the value is read. Signed-off-by: Martin Kletzander Reviewed-by: J=EF=BF=BDn Tomko --- src/util/virresctrl.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 481577bbb9f6..2b72a3b36bae 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -24,8 +24,6 @@ #include =20 #include "virresctrlpriv.h" -#include "c-ctype.h" -#include "count-one-bits.h" #include "viralloc.h" #include "virfile.h" #include "virlog.h" @@ -97,7 +95,6 @@ static virClassPtr virResctrlAllocClass; /* virResctrlInfo */ struct _virResctrlInfoPerType { /* Kernel-provided information */ - char *cbm_mask; unsigned int min_cbm_bits; =20 /* Our computed information from the above */ @@ -142,11 +139,8 @@ virResctrlInfoDispose(void *obj) continue; =20 if (level->types) { - for (j =3D 0; j < VIR_CACHE_TYPE_LAST; j++) { - if (level->types[j]) - VIR_FREE(level->types[j]->cbm_mask); + for (j =3D 0; j < VIR_CACHE_TYPE_LAST; j++) VIR_FREE(level->types[j]); - } } VIR_FREE(level->types); VIR_FREE(level); @@ -334,6 +328,7 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl) int type =3D 0; struct dirent *ent =3D NULL; unsigned int level =3D 0; + virBitmapPtr tmp_map =3D NULL; virResctrlInfoPerLevelPtr i_level =3D NULL; virResctrlInfoPerTypePtr i_type =3D NULL; =20 @@ -378,7 +373,7 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl) goto cleanup; } =20 - rv =3D virFileReadValueString(&i_type->cbm_mask, + rv =3D virFileReadValueString(&tmp_str, SYSFS_RESCTRL_PATH "/info/%s/cbm_mask", ent->d_name); @@ -393,7 +388,19 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl) if (rv < 0) goto cleanup; =20 - virStringTrimOptionalNewline(i_type->cbm_mask); + virStringTrimOptionalNewline(tmp_str); + + tmp_map =3D virBitmapNewString(tmp_str); + VIR_FREE(tmp_str); + if (!tmp_map) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot parse cbm_mask from resctrl cache inf= o")); + goto cleanup; + } + + i_type->bits =3D virBitmapCountBits(tmp_map); + virBitmapFree(tmp_map); + tmp_map =3D NULL; =20 rv =3D virFileReadValueUint(&i_type->min_cbm_bits, SYSFS_RESCTRL_PATH "/info/%s/min_cbm_bit= s", @@ -431,24 +438,12 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl) goto cleanup; } =20 - for (tmp_str =3D i_type->cbm_mask; *tmp_str !=3D '\0'; tmp_str++) { - if (!c_isxdigit(*tmp_str)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot parse cbm_mask from resctrl cache= info")); - goto cleanup; - } - - i_type->bits +=3D count_one_bits(virHexToBin(*tmp_str)); - } - VIR_STEAL_PTR(i_level->types[type], i_type); } =20 ret =3D 0; cleanup: VIR_DIR_CLOSE(dirp); - if (i_type) - VIR_FREE(i_type->cbm_mask); VIR_FREE(i_type); return ret; } --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 16:36:50 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1528379694557927.8519435606069; Thu, 7 Jun 2018 06:54:54 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5CECF30820C0; Thu, 7 Jun 2018 13:54:52 +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 0C18F2007FE7; Thu, 7 Jun 2018 13:54:52 +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 8D472180BA81; Thu, 7 Jun 2018 13:54:51 +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 w57DsaSk000455 for ; Thu, 7 Jun 2018 09:54:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9A0CF2035721; Thu, 7 Jun 2018 13:54:36 +0000 (UTC) Received: from caroline (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 20DAD2035723 for ; Thu, 7 Jun 2018 13:54:36 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.usersys.redhat.com [127.0.0.1]) by caroline (Postfix) with ESMTP id 3E796120073 for ; Thu, 7 Jun 2018 15:54:33 +0200 (CEST) From: Martin Kletzander To: libvir-list@redhat.com Date: Thu, 7 Jun 2018 15:54:31 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 10/10] Move host cache handling from conf/ to util/ 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.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 07 Jun 2018 13:54:53 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Introduce virCache{Info,Bank} as structures describing host cache informati= on including the ways they can be managed by resctrl. This has couple of advantages. First and foremost the virResctrlAllocCreate() is no longer dependent on a data structure initialized in another part of the code and t= he data is automatically fresh. This couldn't be done previously since the co= de initializing that was in conf/. And it also makes more sense for functions= that parse sysfs files to be in util/. Last, but not least, the code doesn't duplicate any data or keep around stale information that needs to be recalculated anyway. Signed-off-by: Martin Kletzander --- src/conf/capabilities.c | 397 +++++++++---------------------- src/conf/capabilities.h | 21 +- src/libvirt_private.syms | 7 +- src/qemu/qemu_process.c | 26 +- src/util/virresctrl.c | 485 ++++++++++++++++++++++++++++++-------- src/util/virresctrl.h | 54 +++-- src/util/virresctrlpriv.h | 4 +- tests/virresctrltest.c | 18 +- 8 files changed, 560 insertions(+), 452 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 7a810efa6662..58769393e821 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -235,14 +235,10 @@ virCapsDispose(void *object) virCapabilitiesClearSecModel(&caps->host.secModels[i]); VIR_FREE(caps->host.secModels); =20 - for (i =3D 0; i < caps->host.ncaches; i++) - virCapsHostCacheBankFree(caps->host.caches[i]); - VIR_FREE(caps->host.caches); - VIR_FREE(caps->host.netprefix); VIR_FREE(caps->host.pagesSize); virCPUDefFree(caps->host.cpu); - virObjectUnref(caps->host.resctrl); + virObjectUnref(caps->host.caches); } =20 /** @@ -863,96 +859,135 @@ virCapabilitiesFormatNUMATopology(virBufferPtr buf, return 0; } =20 + static int -virCapabilitiesFormatCaches(virBufferPtr buf, - size_t ncaches, - virCapsHostCacheBankPtr *caches) +virCapabilitiesFormatCacheControlHelper(unsigned long long granularity, + unsigned long long min, + virCacheType scope, + unsigned int max_allocations, + void *opaque) { - size_t i =3D 0; - size_t j =3D 0; - virBuffer controlBuf =3D VIR_BUFFER_INITIALIZER; + virBufferPtr buf =3D opaque; + const char *unit; + const char *min_unit; + unsigned long long gran_short_size =3D virFormatIntPretty(granularity,= &unit); + unsigned long long min_short_size =3D virFormatIntPretty(min, &min_uni= t); + + /* Only use the smaller unit if they are different */ + if (min !=3D granularity) { + unsigned long long gran_div; + unsigned long long min_div; + + gran_div =3D granularity / gran_short_size; + min_div =3D min / min_short_size; + + if (min_div > gran_div) { + min_short_size *=3D min_div / gran_div; + } else if (min_div < gran_div) { + unit =3D min_unit; + gran_short_size *=3D gran_div / min_div; + } + } =20 - if (!ncaches) - return 0; + virBufferAsprintf(buf, + "\n"); - virBufferAdjustIndent(buf, 2); + if (min !=3D granularity) + virBufferAsprintf(buf, " min=3D'%llu'", min_short_size); =20 - for (i =3D 0; i < ncaches; i++) { - virCapsHostCacheBankPtr bank =3D caches[i]; - char *cpus_str =3D virBitmapFormat(bank->cpus); - const char *unit =3D NULL; - unsigned long long short_size =3D virFormatIntPretty(bank->size, &= unit); + virBufferAsprintf(buf, + " unit=3D'%s' type=3D'%s' maxAllocs=3D'%u'/>\n", + unit, + virCacheTypeToString(scope), + max_allocations); =20 - if (!cpus_str) - return -1; + return 0; +} =20 - /* - * Let's just *hope* the size is aligned to KiBs so that it does n= ot - * bite is back in the future - */ - virBufferAsprintf(buf, - "id, bank->level, - virCacheTypeToString(bank->type), - short_size, unit, cpus_str); - VIR_FREE(cpus_str); - - virBufferSetChildIndent(&controlBuf, buf); - for (j =3D 0; j < bank->ncontrols; j++) { - const char *min_unit; - virResctrlInfoPerCachePtr controls =3D bank->controls[j]; - unsigned long long gran_short_size =3D controls->granularity; - unsigned long long min_short_size =3D controls->min; - - gran_short_size =3D virFormatIntPretty(gran_short_size, &unit); - min_short_size =3D virFormatIntPretty(min_short_size, &min_uni= t); - - /* Only use the smaller unit if they are different */ - if (min_short_size) { - unsigned long long gran_div; - unsigned long long min_div; - - gran_div =3D controls->granularity / gran_short_size; - min_div =3D controls->min / min_short_size; - - if (min_div > gran_div) { - min_short_size *=3D min_div / gran_div; - } else if (min_div < gran_div) { - unit =3D min_unit; - gran_short_size *=3D gran_div / min_div; - } - } =20 - virBufferAsprintf(&controlBuf, - "= \n", - unit, - virCacheTypeToString(controls->scope), - controls->max_allocation); - } + virBufferAsprintf(buf, + "\n"); - virBufferAddBuffer(buf, &controlBuf); - virBufferAddLit(buf, "\n"); - } else { - virBufferAddLit(buf, "/>\n"); - } + if (virCacheControlForeach(caches, level, type, id, + virCapabilitiesFormatCacheControlHelper, + &controlBuf) < 0) + return -1; + + if (virBufferCheckError(&controlBuf) < 0) + return -1; + + if (virBufferUse(&controlBuf)) { + virBufferAddLit(buf, ">\n"); + virBufferAddBuffer(buf, &controlBuf); + virBufferAddLit(buf, "\n"); + } else { + virBufferAddLit(buf, "/>\n"); } =20 - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); + return 0; +} + + +int +virCapabilitiesInitCaches(virCapsPtr caps) +{ + if (caps->host.caches) + return 0; + + caps->host.caches =3D virCacheInfoNew(); + if (!caps->host.caches) + return -1; + + return 0; +} + + +static int +virCapabilitiesFormatCaches(virBufferPtr buf, + virCacheInfoPtr caches) +{ + virBuffer bankBuf =3D VIR_BUFFER_INITIALIZER; + + virBufferSetChildIndent(&bankBuf, buf); + + if (virCacheForeachBank(caches, + virCapabilitiesFormatCacheHelper, + &bankBuf) < 0) + return -1; + + if (virBufferCheckError(&bankBuf) < 0) + return -1; + + if (virBufferUse(&bankBuf)) { + virBufferAddLit(buf, "\n"); + virBufferAddBuffer(buf, &bankBuf); + virBufferAddLit(buf, "\n"); + } =20 return 0; } @@ -1056,8 +1091,7 @@ virCapabilitiesFormatXML(virCapsPtr caps) caps->host.numaCell) < 0) goto error; =20 - if (virCapabilitiesFormatCaches(&buf, caps->host.ncaches, - caps->host.caches) < 0) + if (virCapabilitiesFormatCaches(&buf, caps->host.caches) < 0) goto error; =20 for (i =3D 0; i < caps->host.nsecModels; i++) { @@ -1545,203 +1579,6 @@ virCapabilitiesInitPages(virCapsPtr caps) } =20 =20 -bool -virCapsHostCacheBankEquals(virCapsHostCacheBankPtr a, - virCapsHostCacheBankPtr b) -{ - return (a->id =3D=3D b->id && - a->level =3D=3D b->level && - a->type =3D=3D b->type && - a->size =3D=3D b->size && - virBitmapEqual(a->cpus, b->cpus)); -} - -void -virCapsHostCacheBankFree(virCapsHostCacheBankPtr ptr) -{ - size_t i; - - if (!ptr) - return; - - virBitmapFree(ptr->cpus); - for (i =3D 0; i < ptr->ncontrols; i++) - VIR_FREE(ptr->controls[i]); - VIR_FREE(ptr->controls); - VIR_FREE(ptr); -} - - -static int -virCapsHostCacheBankSorter(const void *a, - const void *b) -{ - virCapsHostCacheBankPtr ca =3D *(virCapsHostCacheBankPtr *)a; - virCapsHostCacheBankPtr cb =3D *(virCapsHostCacheBankPtr *)b; - - if (ca->level < cb->level) - return -1; - if (ca->level > cb->level) - return 1; - - return ca->id - cb->id; -} - - -static int -virCapabilitiesInitResctrl(virCapsPtr caps) -{ - if (caps->host.resctrl) - return 0; - - caps->host.resctrl =3D virResctrlInfoNew(); - if (!caps->host.resctrl) - return -1; - - return 0; -} - - -int -virCapabilitiesInitCaches(virCapsPtr caps) -{ - size_t i =3D 0; - virBitmapPtr cpus =3D NULL; - ssize_t pos =3D -1; - DIR *dirp =3D NULL; - int ret =3D -1; - char *path =3D NULL; - char *type =3D NULL; - struct dirent *ent =3D NULL; - virCapsHostCacheBankPtr bank =3D NULL; - - /* Minimum level to expose in capabilities. Can be lowered or removed= (with - * the appropriate code below), but should not be increased, because w= e'd - * lose information. */ - const int cache_min_level =3D 3; - - if (virCapabilitiesInitResctrl(caps) < 0) - return -1; - - /* offline CPUs don't provide cache info */ - if (virFileReadValueBitmap(&cpus, "%s/cpu/online", SYSFS_SYSTEM_PATH) = < 0) - return -1; - - while ((pos =3D virBitmapNextSetBit(cpus, pos)) >=3D 0) { - int rv =3D -1; - - VIR_FREE(path); - if (virAsprintf(&path, "%s/cpu/cpu%zd/cache/", SYSFS_SYSTEM_PATH, = pos) < 0) - goto cleanup; - - VIR_DIR_CLOSE(dirp); - - rv =3D virDirOpenIfExists(&dirp, path); - if (rv < 0) - goto cleanup; - - if (!dirp) - continue; - - while ((rv =3D virDirRead(dirp, &ent, path)) > 0) { - int kernel_type; - unsigned int level; - - if (!STRPREFIX(ent->d_name, "index")) - continue; - - if (virFileReadValueUint(&level, - "%s/cpu/cpu%zd/cache/%s/level", - SYSFS_SYSTEM_PATH, pos, ent->d_name) = < 0) - goto cleanup; - - if (level < cache_min_level) - continue; - - if (VIR_ALLOC(bank) < 0) - goto cleanup; - - bank->level =3D level; - - if (virFileReadValueUint(&bank->id, - "%s/cpu/cpu%zd/cache/%s/id", - SYSFS_SYSTEM_PATH, pos, ent->d_name) = < 0) - goto cleanup; - - if (virFileReadValueUint(&bank->level, - "%s/cpu/cpu%zd/cache/%s/level", - SYSFS_SYSTEM_PATH, pos, ent->d_name) = < 0) - goto cleanup; - - if (virFileReadValueString(&type, - "%s/cpu/cpu%zd/cache/%s/type", - SYSFS_SYSTEM_PATH, pos, ent->d_name= ) < 0) - goto cleanup; - - if (virFileReadValueScaledInt(&bank->size, - "%s/cpu/cpu%zd/cache/%s/size", - SYSFS_SYSTEM_PATH, pos, ent->d_n= ame) < 0) - goto cleanup; - - if (virFileReadValueBitmap(&bank->cpus, - "%s/cpu/cpu%zd/cache/%s/shared_cpu_= list", - SYSFS_SYSTEM_PATH, pos, ent->d_name= ) < 0) - goto cleanup; - - kernel_type =3D virCacheKernelTypeFromString(type); - if (kernel_type < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unknown cache type '%s'"), type); - goto cleanup; - } - - bank->type =3D kernel_type; - VIR_FREE(type); - - for (i =3D 0; i < caps->host.ncaches; i++) { - if (virCapsHostCacheBankEquals(bank, caps->host.caches[i])) - break; - } - if (i =3D=3D caps->host.ncaches) { - /* If it is a new cache, then update its resctrl informati= on. */ - if (virResctrlInfoGetCache(caps->host.resctrl, - bank->level, - bank->size, - &bank->ncontrols, - &bank->controls) < 0) - goto cleanup; - - if (VIR_APPEND_ELEMENT(caps->host.caches, - caps->host.ncaches, - bank) < 0) { - goto cleanup; - } - } - - virCapsHostCacheBankFree(bank); - bank =3D NULL; - } - if (rv < 0) - goto cleanup; - } - - /* Sort the array in order for the tests to be predictable. This way = we can - * still traverse the directory instead of guessing names (in case the= re is - * 'index1' and 'index3' but no 'index2'). */ - qsort(caps->host.caches, caps->host.ncaches, - sizeof(*caps->host.caches), virCapsHostCacheBankSorter); - - ret =3D 0; - cleanup: - VIR_FREE(type); - VIR_FREE(path); - VIR_DIR_CLOSE(dirp); - virCapsHostCacheBankFree(bank); - virBitmapFree(cpus); - return ret; -} - - void virCapabilitiesHostInitIOMMU(virCapsPtr caps) { diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index fe1b9ea45539..b617bb5df2f5 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -139,18 +139,6 @@ struct _virCapsHostSecModel { virCapsHostSecModelLabelPtr labels; }; =20 -typedef struct _virCapsHostCacheBank virCapsHostCacheBank; -typedef virCapsHostCacheBank *virCapsHostCacheBankPtr; -struct _virCapsHostCacheBank { - unsigned int id; - unsigned int level; /* 1=3DL1, 2=3DL2, 3=3DL3, etc. */ - unsigned long long size; /* B */ - virCacheType type; /* Data, Instruction or Unified */ - virBitmapPtr cpus; /* All CPUs that share this bank */ - size_t ncontrols; - virResctrlInfoPerCachePtr *controls; -}; - typedef struct _virCapsHost virCapsHost; typedef virCapsHost *virCapsHostPtr; struct _virCapsHost { @@ -170,10 +158,7 @@ struct _virCapsHost { size_t nnumaCell_max; virCapsHostNUMACellPtr *numaCell; =20 - virResctrlInfoPtr resctrl; - - size_t ncaches; - virCapsHostCacheBankPtr *caches; + virCacheInfoPtr caches; =20 size_t nsecModels; virCapsHostSecModelPtr secModels; @@ -322,10 +307,6 @@ int virCapabilitiesInitPages(virCapsPtr caps); =20 int virCapabilitiesInitNUMA(virCapsPtr caps); =20 -bool virCapsHostCacheBankEquals(virCapsHostCacheBankPtr a, - virCapsHostCacheBankPtr b); -void virCapsHostCacheBankFree(virCapsHostCacheBankPtr ptr); - int virCapabilitiesInitCaches(virCapsPtr caps); =20 void virCapabilitiesHostInitIOMMU(virCapsPtr caps); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a4a0c95b474d..07bf63489e20 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2619,8 +2619,9 @@ virRandomInt; =20 =20 # util/virresctrl.h -virCacheKernelTypeFromString; -virCacheKernelTypeToString; +virCacheControlForeach; +virCacheForeachBank; +virCacheInfoNew; virCacheTypeFromString; virCacheTypeToString; virResctrlAllocAddPID; @@ -2635,8 +2636,6 @@ virResctrlAllocNew; virResctrlAllocRemove; virResctrlAllocSetID; virResctrlAllocSetSize; -virResctrlInfoGetCache; -virResctrlInfoNew; =20 =20 # util/virrotatingfile.h diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 1606f4cfe931..d945f6177456 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2439,34 +2439,18 @@ qemuProcessSetupEmulator(virDomainObjPtr vm) =20 =20 static int -qemuProcessResctrlCreate(virQEMUDriverPtr driver, - virDomainObjPtr vm) +qemuProcessResctrlCreate(virDomainObjPtr vm) { - int ret =3D -1; size_t i =3D 0; - virCapsPtr caps =3D NULL; qemuDomainObjPrivatePtr priv =3D vm->privateData; =20 - if (!vm->def->ncachetunes) - return 0; - - /* Force capability refresh since resctrl info can change - * XXX: move cache info into virresctrl so caps are not needed */ - caps =3D virQEMUDriverGetCapabilities(driver, true); - if (!caps) - return -1; - for (i =3D 0; i < vm->def->ncachetunes; i++) { - if (virResctrlAllocCreate(caps->host.resctrl, - vm->def->cachetunes[i]->alloc, + if (virResctrlAllocCreate(vm->def->cachetunes[i]->alloc, priv->machineName) < 0) - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virObjectUnref(caps); - return ret; + return 0; } =20 =20 @@ -6227,7 +6211,7 @@ qemuProcessLaunch(virConnectPtr conn, goto cleanup; =20 VIR_DEBUG("Setting up resctrl"); - if (qemuProcessResctrlCreate(driver, vm) < 0) + if (qemuProcessResctrlCreate(vm) < 0) goto cleanup; =20 VIR_DEBUG("Setting up managed PR daemon"); diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 2b72a3b36bae..c41f90b94919 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -38,12 +38,16 @@ VIR_LOG_INIT("util.virresctrl") /* Resctrl is short for Resource Control. It might be implemented for var= ious * resources, but at the time of this writing this is only supported for c= ache * allocation technology (aka CAT). Hence the reson for leaving 'Cache' o= ut of - * all the structure and function names for now (can be added later if nee= ded. + * all the structure and function names for now (can be added later if nee= ded). + * + * We now have virCache structures and functions as well, they are suppose= d to + * cover all host cache information. */ =20 =20 /* Common definitions */ #define SYSFS_RESCTRL_PATH "/sys/fs/resctrl" +#define SYSFS_SYSTEM_PATH "/sys/devices/system" =20 =20 /* Following are three different enum implementations for the same enum. = Each @@ -52,6 +56,7 @@ VIR_LOG_INIT("util.virresctrl") * consistent in between all of them. */ =20 /* Cache name mapping for Linux kernel naming. */ +VIR_ENUM_DECL(virCacheKernel); VIR_ENUM_IMPL(virCacheKernel, VIR_CACHE_TYPE_LAST, "Unified", "Instruction", @@ -74,12 +79,18 @@ VIR_ENUM_IMPL(virResctrl, VIR_CACHE_TYPE_LAST, /* All private typedefs so that they exist for all later definitions. Thi= s way * structs can be included in one or another without reorganizing the code= every * time. */ +typedef struct _virCacheBank virCacheBank; +typedef virCacheBank *virCacheBankPtr; + typedef struct _virResctrlInfoPerType virResctrlInfoPerType; typedef virResctrlInfoPerType *virResctrlInfoPerTypePtr; =20 typedef struct _virResctrlInfoPerLevel virResctrlInfoPerLevel; typedef virResctrlInfoPerLevel *virResctrlInfoPerLevelPtr; =20 +typedef struct _virResctrlInfo virResctrlInfo; +typedef virResctrlInfo *virResctrlInfoPtr; + typedef struct _virResctrlAllocPerType virResctrlAllocPerType; typedef virResctrlAllocPerType *virResctrlAllocPerTypePtr; =20 @@ -88,28 +99,69 @@ typedef virResctrlAllocPerLevel *virResctrlAllocPerLeve= lPtr; =20 =20 /* Class definitions and initializations */ +static virClassPtr virCacheInfoClass; +static virClassPtr virCacheBankClass; static virClassPtr virResctrlInfoClass; static virClassPtr virResctrlAllocClass; =20 =20 +/* virCacheInfo */ +struct _virCacheInfo { + virObject parent; + + virCacheBankPtr *banks; + size_t nbanks; + + virResctrlInfoPtr resctrl; +}; + + +static void +virCacheInfoDispose(void *obj) +{ + size_t i =3D 0; + + virCacheInfoPtr ci =3D obj; + + for (i =3D 0; i < ci->nbanks; i++) + virObjectUnref(ci->banks[i]); + + virObjectUnref(ci->resctrl); + VIR_FREE(ci->banks); +} + + +/* virCacheBank */ +struct _virCacheBank { + virObject parent; + + unsigned int id; + unsigned int level; /* 1=3DL1, 2=3DL2, 3=3DL3, etc. */ + unsigned long long size; /* B */ + virCacheType type; /* Data, Instruction or Unified */ + virBitmapPtr cpus; /* All CPUs that share this bank */ +}; + + +static void +virCacheBankDispose(void *obj) +{ + virCacheBankPtr bank =3D obj; + + virBitmapFree(bank->cpus); +} + + /* virResctrlInfo */ struct _virResctrlInfoPerType { /* Kernel-provided information */ unsigned int min_cbm_bits; =20 - /* Our computed information from the above */ - unsigned int bits; - unsigned int max_cache_id; - - /* In order to be self-sufficient we need size information per cache. - * Funnily enough, one of the outcomes of the resctrl design is that it - * does not account for different sizes per cache on the same level. = So - * for the sake of easiness, let's copy that, for now. */ - unsigned long long size; + /* Number of bits in the cbm mask */ + size_t bits; =20 - /* Information that we will return upon request (this is public struct= ) as - * until now all the above is internal to this module */ - virResctrlInfoPerCache control; + /* Maximum number of simultaneous allocations */ + unsigned int max_allocations; }; =20 struct _virResctrlInfoPerLevel { @@ -261,6 +313,12 @@ virResctrlAllocDispose(void *obj) static int virResctrlOnceInit(void) { + if (!VIR_CLASS_NEW(virCacheInfo, virClassForObject())) + return -1; + + if (!VIR_CLASS_NEW(virCacheBank, virClassForObject())) + return -1; + if (!VIR_CLASS_NEW(virResctrlInfo, virClassForObject())) return -1; =20 @@ -357,9 +415,7 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl) if (VIR_ALLOC(i_type) < 0) goto cleanup; =20 - i_type->control.scope =3D type; - - rv =3D virFileReadValueUint(&i_type->control.max_allocation, + rv =3D virFileReadValueUint(&i_type->max_allocations, SYSFS_RESCTRL_PATH "/info/%s/num_closids= ", ent->d_name); if (rv =3D=3D -2) { @@ -443,13 +499,14 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl) =20 ret =3D 0; cleanup: + virBitmapFree(tmp_map); VIR_DIR_CLOSE(dirp); VIR_FREE(i_type); return ret; } =20 =20 -virResctrlInfoPtr +static virResctrlInfoPtr virResctrlInfoNew(void) { virResctrlInfoPtr ret =3D NULL; @@ -495,67 +552,289 @@ virResctrlInfoIsEmpty(virResctrlInfoPtr resctrl) } =20 =20 -int -virResctrlInfoGetCache(virResctrlInfoPtr resctrl, - unsigned int level, - unsigned long long size, - size_t *ncontrols, - virResctrlInfoPerCachePtr **controls) +/* virCacheBank-related definitions */ +static virCacheBankPtr +virCacheBankNew(void) +{ + if (virResctrlInitialize() < 0) + return NULL; + + return virObjectNew(virCacheBankClass); +} + + +static bool +virCacheBankEquals(virCacheBankPtr a, + virCacheBankPtr b) +{ + return (a->id =3D=3D b->id && + a->level =3D=3D b->level && + a->type =3D=3D b->type); +} + + +static int +virCacheBankSorter(const void *a, + const void *b) +{ + virCacheBankPtr ca =3D *(virCacheBankPtr *)a; + virCacheBankPtr cb =3D *(virCacheBankPtr *)b; + + if (ca->level < cb->level) + return -1; + if (ca->level > cb->level) + return 1; + + return ca->id - cb->id; +} + + +/* virCacheInfo-related definitions */ +static int +virCacheGetInfo(virCacheInfoPtr ci) { - virResctrlInfoPerLevelPtr i_level =3D NULL; - virResctrlInfoPerTypePtr i_type =3D NULL; size_t i =3D 0; + virBitmapPtr cpus =3D NULL; + ssize_t pos =3D -1; + DIR *dirp =3D NULL; int ret =3D -1; + char *path =3D NULL; + char *type =3D NULL; + struct dirent *ent =3D NULL; + virCacheBankPtr bank =3D NULL; =20 - if (virResctrlInfoIsEmpty(resctrl)) - return 0; + /* Minimum level to expose in capabilities. Can be lowered or removed= (with + * the appropriate code below), but should not be increased, because w= e'd + * lose information. */ + const int cache_min_level =3D 3; =20 - if (level >=3D resctrl->nlevels) - return 0; + ci->resctrl =3D virResctrlInfoNew(); + if (!ci->resctrl) + return -1; =20 - i_level =3D resctrl->levels[level]; - if (!i_level) - return 0; + /* offline CPUs don't provide cache info */ + if (virFileReadValueBitmap(&cpus, "%s/cpu/online", SYSFS_SYSTEM_PATH) = < 0) + return -1; =20 - for (i =3D 0; i < VIR_CACHE_TYPE_LAST; i++) { - i_type =3D i_level->types[i]; - if (!i_type) + while ((pos =3D virBitmapNextSetBit(cpus, pos)) >=3D 0) { + int rv =3D -1; + + VIR_FREE(path); + if (virAsprintf(&path, "%s/cpu/cpu%zd/cache/", SYSFS_SYSTEM_PATH, = pos) < 0) + goto cleanup; + + VIR_DIR_CLOSE(dirp); + + rv =3D virDirOpenIfExists(&dirp, path); + if (rv < 0) + goto cleanup; + + if (!dirp) continue; =20 - /* Let's take the opportunity to update our internal information a= bout - * the cache size */ - if (!i_type->size) { - i_type->size =3D size; - i_type->control.granularity =3D size / i_type->bits; - if (i_type->min_cbm_bits !=3D 1) - i_type->control.min =3D i_type->min_cbm_bits * i_type->con= trol.granularity; - } else { - if (i_type->size !=3D size) { + while ((rv =3D virDirRead(dirp, &ent, path)) > 0) { + int kernel_type; + unsigned int level; + + if (!STRPREFIX(ent->d_name, "index")) + continue; + + if (virFileReadValueUint(&level, + "%s/cpu/cpu%zd/cache/%s/level", + SYSFS_SYSTEM_PATH, pos, ent->d_name) = < 0) + goto cleanup; + + if (level < cache_min_level) + continue; + + bank =3D virCacheBankNew(); + if (!bank) + goto cleanup; + + bank->level =3D level; + + if (virFileReadValueUint(&bank->id, + "%s/cpu/cpu%zd/cache/%s/id", + SYSFS_SYSTEM_PATH, pos, ent->d_name) = < 0) + goto cleanup; + + if (virFileReadValueUint(&bank->level, + "%s/cpu/cpu%zd/cache/%s/level", + SYSFS_SYSTEM_PATH, pos, ent->d_name) = < 0) + goto cleanup; + + if (virFileReadValueString(&type, + "%s/cpu/cpu%zd/cache/%s/type", + SYSFS_SYSTEM_PATH, pos, ent->d_name= ) < 0) + goto cleanup; + + if (virFileReadValueScaledInt(&bank->size, + "%s/cpu/cpu%zd/cache/%s/size", + SYSFS_SYSTEM_PATH, pos, ent->d_n= ame) < 0) + goto cleanup; + + if (virFileReadValueBitmap(&bank->cpus, + "%s/cpu/cpu%zd/cache/%s/shared_cpu_= list", + SYSFS_SYSTEM_PATH, pos, ent->d_name= ) < 0) + goto cleanup; + + kernel_type =3D virCacheKernelTypeFromString(type); + if (kernel_type < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("level %u cache size %llu does not match " - "expected size %llu"), - level, i_type->size, size); - goto error; + _("Unknown cache type '%s'"), type); + goto cleanup; } - i_type->max_cache_id++; - } =20 - if (VIR_EXPAND_N(*controls, *ncontrols, 1) < 0) - goto error; - if (VIR_ALLOC((*controls)[*ncontrols - 1]) < 0) - goto error; + bank->type =3D kernel_type; + VIR_FREE(type); + + for (i =3D 0; i < ci->nbanks; i++) { + if (virCacheBankEquals(bank, ci->banks[i])) + break; + } + if (i =3D=3D ci->nbanks && + VIR_APPEND_ELEMENT(ci->banks, ci->nbanks, bank) < 0) =20 - memcpy((*controls)[*ncontrols - 1], &i_type->control, sizeof(i_typ= e->control)); + virObjectUnref(bank); + bank =3D NULL; + } + if (rv < 0) + goto cleanup; } =20 + /* Sort the array in order for the tests to be predictable. This way = we can + * still traverse the directory instead of guessing names (in case the= re is + * 'index1' and 'index3' but no 'index2'). */ + qsort(ci->banks, ci->nbanks, sizeof(*ci->banks), virCacheBankSorter); + ret =3D 0; cleanup: + VIR_FREE(type); + VIR_FREE(path); + VIR_DIR_CLOSE(dirp); + virObjectUnref(bank); + virBitmapFree(cpus); return ret; - error: - while (*ncontrols) - VIR_FREE((*controls)[--*ncontrols]); - VIR_FREE(*controls); - goto cleanup; +} + + +virCacheInfoPtr +virCacheInfoNew(void) +{ + virCacheInfoPtr ret =3D NULL; + + if (virResctrlInitialize() < 0) + return NULL; + + ret =3D virObjectNew(virCacheInfoClass); + if (!ret) + return NULL; + + if (virCacheGetInfo(ret) < 0) { + virObjectUnref(ret); + return NULL; + } + + return ret; +} + + +static virCacheBankPtr +virCacheInfoGetBankForType(virCacheInfoPtr ci, + unsigned int level, + unsigned int cache, + virCacheType type) +{ + size_t i =3D 0; + + for (i =3D 0; i < ci->nbanks; i++) { + virCacheBankPtr bank =3D ci->banks[i]; + + if (bank->level !=3D level) + continue; + + if (bank->id !=3D cache) + continue; + + /* + * We're looking for a particular type. If it is _BOTH we can only + * return that, but since CAT can support _CODE/_DATA allocation on + * cache with type _BOTH, we need to be able to find that as well. + * + * Think of this as a function that returns a particular cache that + * takes care of caching type @type on a level @level, but we're + * restricted to cache id @cache. Or rather don't think about sin= ce + * it's also confusing. + */ + if (bank->type =3D=3D type || bank->type =3D=3D VIR_CACHE_TYPE_BOT= H) + return bank; + } + + return NULL; +} + + +int +virCacheControlForeach(virCacheInfoPtr ci, + unsigned int level, + virCacheType type, + unsigned int id, + virCacheForeachControlCallback cb, + void *opaque) +{ + virResctrlInfoPerLevelPtr r_level =3D NULL; + size_t i =3D 0; + + if (!ci || + !ci->resctrl || + !ci->resctrl->levels || + level >=3D ci->resctrl->nlevels) + return 0; + + r_level =3D ci->resctrl->levels[level]; + if (!r_level || !r_level->types) + return 0; + + for (i =3D 0; i < VIR_CACHE_TYPE_LAST; i++) { + virResctrlInfoPerTypePtr r_type =3D r_level->types[i]; + virCacheBankPtr bank =3D virCacheInfoGetBankForType(ci, level, id,= type); + unsigned long long granularity; + unsigned long long min; + + if (!r_type || !bank) + continue; + + granularity =3D bank->size / r_type->bits; + min =3D r_type->min_cbm_bits * granularity; + + int rv =3D cb(granularity, min, i, r_type->max_allocations, opaque= ); + if (rv < 0) + return rv; + } + + return 0; +} + + +int +virCacheForeachBank(virCacheInfoPtr ci, + virCacheForeachBankCallback cb, + void *opaque) +{ + size_t i =3D 0; + + if (!ci) + return 0; + + for (i =3D 0; i < ci->nbanks; i++) { + virCacheBankPtr bank =3D ci->banks[i]; + int rv =3D cb(ci, bank->level, bank->type, bank->id, bank->size, b= ank->cpus, opaque); + + if (rv < 0) + return rv; + } + + return 0; } =20 =20 @@ -1107,25 +1386,25 @@ virResctrlAllocSubtract(virResctrlAllocPtr dst, =20 =20 static virResctrlAllocPtr -virResctrlAllocNewFromInfo(virResctrlInfoPtr info) +virResctrlAllocNewFromInfo(virCacheInfoPtr ci) { + size_t level =3D 0; + size_t type =3D 0; size_t i =3D 0; - size_t j =3D 0; - size_t k =3D 0; virResctrlAllocPtr ret =3D virResctrlAllocNew(); virBitmapPtr mask =3D NULL; =20 if (!ret) return NULL; =20 - for (i =3D 0; i < info->nlevels; i++) { - virResctrlInfoPerLevelPtr i_level =3D info->levels[i]; + for (level =3D 0; level < ci->resctrl->nlevels; level++) { + virResctrlInfoPerLevelPtr i_level =3D ci->resctrl->levels[level]; =20 if (!i_level) continue; =20 - for (j =3D 0; j < VIR_CACHE_TYPE_LAST; j++) { - virResctrlInfoPerTypePtr i_type =3D i_level->types[j]; + for (type =3D 0; type < VIR_CACHE_TYPE_LAST; type++) { + virResctrlInfoPerTypePtr i_type =3D i_level->types[type]; =20 if (!i_type) continue; @@ -1136,8 +1415,13 @@ virResctrlAllocNewFromInfo(virResctrlInfoPtr info) goto error; virBitmapSetAll(mask); =20 - for (k =3D 0; k <=3D i_type->max_cache_id; k++) { - if (virResctrlAllocUpdateMask(ret, i, j, k, mask) < 0) + for (i =3D 0; i < ci->nbanks; i++) { + virCacheBankPtr bank =3D ci->banks[i]; + + if (bank->level !=3D level) + continue; + + if (virResctrlAllocUpdateMask(ret, level, type, bank->id, = mask) < 0) goto error; } } @@ -1159,12 +1443,13 @@ virResctrlAllocNewFromInfo(virResctrlInfoPtr info) * scans for all allocations under /sys/fs/resctrl and subtracts each one = of * them from it. That way it can then return an allocation with only bit = set * being those that are not mentioned in any other allocation. It is used= for - * two things, a) calculating the masks when creating allocations and b) f= rom + * two things, a) calculating the masks when creating allocations and cb) = from * tests. */ virResctrlAllocPtr -virResctrlAllocGetUnused(virResctrlInfoPtr resctrl) +virResctrlAllocGetUnused(virCacheInfoPtr ci) { + virResctrlInfoPtr resctrl =3D ci->resctrl; virResctrlAllocPtr ret =3D NULL; virResctrlAllocPtr alloc =3D NULL; struct dirent *ent =3D NULL; @@ -1177,7 +1462,7 @@ virResctrlAllocGetUnused(virResctrlInfoPtr resctrl) return NULL; } =20 - ret =3D virResctrlAllocNewFromInfo(resctrl); + ret =3D virResctrlAllocNewFromInfo(ci); if (!ret) return NULL; =20 @@ -1239,13 +1524,15 @@ static int virResctrlAllocFindUnused(virResctrlAllocPtr alloc, virResctrlInfoPerTypePtr i_type, virResctrlAllocPerTypePtr f_type, + unsigned long long size, unsigned int level, unsigned int type, unsigned int cache) { - unsigned long long *size =3D alloc->levels[level]->types[type]->sizes[= cache]; + unsigned long long *need_size =3D alloc->levels[level]->types[type]->s= izes[cache]; virBitmapPtr a_mask =3D NULL; virBitmapPtr f_mask =3D NULL; + unsigned long long granularity =3D size / i_type->bits; unsigned long long need_bits; size_t i =3D 0; ssize_t pos =3D -1; @@ -1253,7 +1540,7 @@ virResctrlAllocFindUnused(virResctrlAllocPtr alloc, ssize_t last_pos =3D -1; int ret =3D -1; =20 - if (!size) + if (!need_size) return 0; =20 if (cache >=3D f_type->nmasks) { @@ -1272,30 +1559,30 @@ virResctrlAllocFindUnused(virResctrlAllocPtr alloc, return -1; } =20 - if (*size =3D=3D i_type->size) { + if (*need_size =3D=3D size) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Cache allocation for the whole cache is not " "possible, specify size smaller than %llu"), - i_type->size); + size); return -1; } =20 - need_bits =3D *size / i_type->control.granularity; - - if (*size % i_type->control.granularity) { + if (*need_size % granularity) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Cache allocation of size %llu is not " "divisible by granularity %llu"), - *size, i_type->control.granularity); + *need_size, granularity); return -1; } =20 + need_bits =3D *need_size / granularity; + if (need_bits < i_type->min_cbm_bits) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Cache allocation of size %llu is smaller " "than the minimum allowed allocation %llu"), - *size, - i_type->control.granularity * i_type->min_cbm_bits); + *need_size, + granularity * i_type->min_cbm_bits); return -1; } =20 @@ -1334,7 +1621,7 @@ virResctrlAllocFindUnused(virResctrlAllocPtr alloc, _("Not enough room for allocation of " "%llu bytes for level %u cache %u " "scope type '%s'"), - *size, level, cache, + *need_size, level, cache, virCacheTypeToString(type)); return -1; } @@ -1401,15 +1688,16 @@ virResctrlAllocCopyMasks(virResctrlAllocPtr dst, * transforming `sizes` into `masks`. */ int -virResctrlAllocMasksAssign(virResctrlInfoPtr resctrl, +virResctrlAllocMasksAssign(virCacheInfoPtr ci, virResctrlAllocPtr alloc) { int ret =3D -1; unsigned int level =3D 0; + virResctrlInfoPtr resctrl =3D ci->resctrl; virResctrlAllocPtr alloc_free =3D NULL; virResctrlAllocPtr alloc_default =3D NULL; =20 - alloc_free =3D virResctrlAllocGetUnused(resctrl); + alloc_free =3D virResctrlAllocGetUnused(ci); if (!alloc_free) return -1; =20 @@ -1457,8 +1745,18 @@ virResctrlAllocMasksAssign(virResctrlInfoPtr resctrl, for (cache =3D 0; cache < a_type->nsizes; cache++) { virResctrlInfoPerLevelPtr i_level =3D resctrl->levels[leve= l]; virResctrlInfoPerTypePtr i_type =3D i_level->types[type]; + virCacheBankPtr bank =3D virCacheInfoGetBankForType(ci, le= vel, cache, type); + + if (!bank) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Cache level %u id '%u' does not supp= ort tuning for " + "scope type '%s'"), + level, cache, virCacheTypeToString(type= )); + goto cleanup; + } =20 - if (virResctrlAllocFindUnused(alloc, i_type, f_type, level= , type, cache) < 0) + if (virResctrlAllocFindUnused(alloc, i_type, f_type, bank-= >size, + level, type, cache) < 0) goto cleanup; } } @@ -1494,10 +1792,10 @@ virResctrlAllocDeterminePath(virResctrlAllocPtr all= oc, /* This checks if the directory for the alloc exists. If not it tries to = create * it and apply appropriate alloc settings. */ int -virResctrlAllocCreate(virResctrlInfoPtr resctrl, - virResctrlAllocPtr alloc, +virResctrlAllocCreate(virResctrlAllocPtr alloc, const char *machinename) { + virCacheInfoPtr ci =3D NULL; char *schemata_path =3D NULL; char *alloc_str =3D NULL; int ret =3D -1; @@ -1506,14 +1804,16 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl, if (!alloc) return 0; =20 - if (virResctrlInfoIsEmpty(resctrl)) { + ci =3D virCacheInfoNew(); + + if (virResctrlInfoIsEmpty(ci->resctrl)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Resource control is not supported on this host")= ); - return -1; + goto cleanup; } =20 if (virResctrlAllocDeterminePath(alloc, machinename) < 0) - return -1; + goto cleanup; =20 if (virFileExists(alloc->path)) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1526,7 +1826,7 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl, if (lockfd < 0) goto cleanup; =20 - if (virResctrlAllocMasksAssign(resctrl, alloc) < 0) + if (virResctrlAllocMasksAssign(ci, alloc) < 0) goto cleanup; =20 alloc_str =3D virResctrlAllocFormat(alloc); @@ -1554,6 +1854,7 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl, =20 ret =3D 0; cleanup: + virObjectUnref(ci); virResctrlUnlock(lockfd); VIR_FREE(alloc_str); VIR_FREE(schemata_path); diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h index 9052a2b19a02..ef1fef8cf622 100644 --- a/src/util/virresctrl.h +++ b/src/util/virresctrl.h @@ -34,34 +34,43 @@ typedef enum { } virCacheType; =20 VIR_ENUM_DECL(virCache); -VIR_ENUM_DECL(virCacheKernel); =20 +typedef struct _virCacheInfo virCacheInfo; +typedef virCacheInfo *virCacheInfoPtr; =20 -typedef struct _virResctrlInfoPerCache virResctrlInfoPerCache; -typedef virResctrlInfoPerCache *virResctrlInfoPerCachePtr; -struct _virResctrlInfoPerCache { - /* Smallest possible increase of the allocation size in bytes */ - unsigned long long granularity; - /* Minimal allocatable size in bytes (if different from granularity) */ - unsigned long long min; - /* Type of the allocation */ - virCacheType scope; - /* Maximum number of simultaneous allocations */ - unsigned int max_allocation; -}; +virCacheInfoPtr +virCacheInfoNew(void); =20 -typedef struct _virResctrlInfo virResctrlInfo; -typedef virResctrlInfo *virResctrlInfoPtr; +typedef int virCacheForeachControlCallback(unsigned long long granularity, + unsigned long long min, + virCacheType scope, + unsigned int max_allocations, + void *opaque); =20 -virResctrlInfoPtr -virResctrlInfoNew(void); =20 int -virResctrlInfoGetCache(virResctrlInfoPtr resctrl, +virCacheControlForeach(virCacheInfoPtr ci, unsigned int level, - unsigned long long size, - size_t *ncontrols, - virResctrlInfoPerCachePtr **controls); + virCacheType type, + unsigned int id, + virCacheForeachControlCallback cb, + void *opaque); + + +typedef int virCacheForeachBankCallback(virCacheInfoPtr ci, + unsigned int level, + virCacheType type, + unsigned int id, + unsigned long long size, + virBitmapPtr cpus, + void *opaque); + + +int +virCacheForeachBank(virCacheInfoPtr ci, + virCacheForeachBankCallback cb, + void *opaque); + =20 /* Alloc-related things */ typedef struct _virResctrlAlloc virResctrlAlloc; @@ -105,8 +114,7 @@ virResctrlAllocDeterminePath(virResctrlAllocPtr alloc, const char *machinename); =20 int -virResctrlAllocCreate(virResctrlInfoPtr r_info, - virResctrlAllocPtr alloc, +virResctrlAllocCreate(virResctrlAllocPtr alloc, const char *machinename); =20 int diff --git a/src/util/virresctrlpriv.h b/src/util/virresctrlpriv.h index 80ddd4b875a3..258f3a0e3f74 100644 --- a/src/util/virresctrlpriv.h +++ b/src/util/virresctrlpriv.h @@ -22,10 +22,10 @@ # include "virresctrl.h" =20 virResctrlAllocPtr -virResctrlAllocGetUnused(virResctrlInfoPtr resctrl); +virResctrlAllocGetUnused(virCacheInfoPtr ci); =20 int -virResctrlAllocMasksAssign(virResctrlInfoPtr resctrl, +virResctrlAllocMasksAssign(virCacheInfoPtr ci, virResctrlAllocPtr alloc); =20 #endif /* __VIR_RESCTRL_PRIV_H__ */ diff --git a/tests/virresctrltest.c b/tests/virresctrltest.c index 99e20d5dec99..397e4f9a644e 100644 --- a/tests/virresctrltest.c +++ b/tests/virresctrltest.c @@ -18,13 +18,13 @@ static int test_virResctrlGetUnused(const void *opaque) { struct virResctrlData *data =3D (struct virResctrlData *) opaque; - char *system_dir =3D NULL; - char *resctrl_dir =3D NULL; - int ret =3D -1; + virCacheInfoPtr ci =3D NULL; virResctrlAllocPtr alloc =3D NULL; char *schemata_str =3D NULL; char *schemata_file; - virCapsPtr caps =3D NULL; + char *system_dir =3D NULL; + char *resctrl_dir =3D NULL; + int ret =3D -1; =20 if (virAsprintf(&system_dir, "%s/vircaps2xmldata/linux-%s/system", abs_srcdir, data->filename) < 0) @@ -41,13 +41,11 @@ test_virResctrlGetUnused(const void *opaque) virFileWrapperAddPrefix("/sys/devices/system", system_dir); virFileWrapperAddPrefix("/sys/fs/resctrl", resctrl_dir); =20 - caps =3D virCapabilitiesNew(VIR_ARCH_X86_64, false, false); - if (!caps || virCapabilitiesInitCaches(caps) < 0) { - fprintf(stderr, "Could not initialize capabilities"); + ci =3D virCacheInfoNew(); + if (!ci) goto cleanup; - } =20 - alloc =3D virResctrlAllocGetUnused(caps->host.resctrl); + alloc =3D virResctrlAllocGetUnused(ci); =20 virFileWrapperClearPrefixes(); =20 @@ -68,7 +66,7 @@ test_virResctrlGetUnused(const void *opaque) =20 ret =3D 0; cleanup: - virObjectUnref(caps); + virObjectUnref(ci); virObjectUnref(alloc); VIR_FREE(system_dir); VIR_FREE(resctrl_dir); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list