From nobody Thu May 2 07:56:35 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1517391723574792.8893010266421; Wed, 31 Jan 2018 01:42:03 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 70140641C6; Wed, 31 Jan 2018 09:42:01 +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 9B0DC620DE; Wed, 31 Jan 2018 09:42:00 +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 57A8241FAE; Wed, 31 Jan 2018 09:41:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0V9fuc6025406 for ; Wed, 31 Jan 2018 04:41:56 -0500 Received: by smtp.corp.redhat.com (Postfix) id DE79E60649; Wed, 31 Jan 2018 09:41:56 +0000 (UTC) Received: from caroline.localdomain (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ADEC5620AE for ; Wed, 31 Jan 2018 09:41:51 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.usersys.redhat.com [127.0.0.1]) by caroline.localdomain (Postfix) with ESMTP id 73888120470 for ; Wed, 31 Jan 2018 10:41:50 +0100 (CET) From: Martin Kletzander To: libvir-list@redhat.com Date: Wed, 31 Jan 2018 10:41:39 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/8] util: Add helpers for getting resctrl group allocs X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 31 Jan 2018 09:42:02 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Martin Kletzander --- src/util/virresctrl.c | 79 +++++++++++++++++++++++++++++++++--------------= ---- 1 file changed, 52 insertions(+), 27 deletions(-) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 42876c6e2b9b..fa7c28e9b45e 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -1041,6 +1041,53 @@ virResctrlAllocParse(virResctrlInfoPtr resctrl, } =20 =20 +static int +virResctrlAllocGetGroup(virResctrlInfoPtr resctrl, + const char *groupname, + virResctrlAllocPtr *alloc) +{ + char *schemata =3D NULL; + int rv =3D virFileReadValueString(&schemata, + SYSFS_RESCTRL_PATH + "/%s/schemata", + groupname); + + if (rv < 0) + return rv; + + *alloc =3D virResctrlAllocNew(); + if (!*alloc) + goto error; + + if (virResctrlAllocParse(resctrl, *alloc, schemata) < 0) + goto error; + + VIR_FREE(schemata); + return 0; + + error: + VIR_FREE(schemata); + virObjectUnref(*alloc); + *alloc =3D NULL; + return -1; +} + + +static virResctrlAllocPtr +virResctrlAllocGetDefault(virResctrlInfoPtr resctrl) +{ + virResctrlAllocPtr ret =3D NULL; + + if (virResctrlAllocGetGroup(resctrl, ".", &ret) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not read schemata file for the default gro= up")); + return NULL; + } + + return ret; +} + + static void virResctrlAllocSubtractPerType(virResctrlAllocPerTypePtr dst, virResctrlAllocPerTypePtr src) @@ -1141,7 +1188,6 @@ virResctrlAllocGetUnused(virResctrlInfoPtr resctrl) virResctrlAllocPtr alloc =3D NULL; struct dirent *ent =3D NULL; DIR *dirp =3D NULL; - char *schemata =3D NULL; int rv =3D -1; =20 if (virResctrlInfoIsEmpty(resctrl)) { @@ -1154,22 +1200,12 @@ virResctrlAllocGetUnused(virResctrlInfoPtr resctrl) if (!ret) return NULL; =20 - if (virFileReadValueString(&schemata, - SYSFS_RESCTRL_PATH - "/schemata") < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Could not read schemata file for the default gro= up")); - goto error; - } - - alloc =3D virResctrlAllocNew(); + alloc =3D virResctrlAllocGetDefault(resctrl); if (!alloc) goto error; =20 - if (virResctrlAllocParse(resctrl, alloc, schemata) < 0) - goto error; - virResctrlAllocSubtract(ret, alloc); + virObjectUnref(alloc); =20 if (virDirOpen(&dirp, SYSFS_RESCTRL_PATH) < 0) goto error; @@ -1178,11 +1214,7 @@ virResctrlAllocGetUnused(virResctrlInfoPtr resctrl) if (STREQ(ent->d_name, "info")) continue; =20 - VIR_FREE(schemata); - rv =3D virFileReadValueString(&schemata, - SYSFS_RESCTRL_PATH - "/%s/schemata", - ent->d_name); + rv =3D virResctrlAllocGetGroup(resctrl, ent->d_name, &alloc); if (rv =3D=3D -2) continue; =20 @@ -1193,15 +1225,9 @@ virResctrlAllocGetUnused(virResctrlInfoPtr resctrl) goto error; } =20 - virObjectUnref(alloc); - alloc =3D virResctrlAllocNew(); - if (!alloc) - goto error; - - if (virResctrlAllocParse(resctrl, alloc, schemata) < 0) - goto error; - virResctrlAllocSubtract(ret, alloc); + virObjectUnref(alloc); + alloc =3D NULL; } if (rv < 0) goto error; @@ -1209,7 +1235,6 @@ virResctrlAllocGetUnused(virResctrlInfoPtr resctrl) cleanup: virObjectUnref(alloc); VIR_DIR_CLOSE(dirp); - VIR_FREE(schemata); return ret; =20 error: --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 07:56:35 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1517391745232539.3342697172666; Wed, 31 Jan 2018 01:42:25 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E4D19272B2; Wed, 31 Jan 2018 09:42:23 +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 B2F32609D3; Wed, 31 Jan 2018 09:42:23 +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 7D7513FB19; Wed, 31 Jan 2018 09:42:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0V9fxp3025425 for ; Wed, 31 Jan 2018 04:41:59 -0500 Received: by smtp.corp.redhat.com (Postfix) id 27C4060BE7; Wed, 31 Jan 2018 09:41:59 +0000 (UTC) Received: from caroline.localdomain (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C302460BEC for ; Wed, 31 Jan 2018 09:41:51 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.usersys.redhat.com [127.0.0.1]) by caroline.localdomain (Postfix) with ESMTP id 7F14C120479 for ; Wed, 31 Jan 2018 10:41:50 +0100 (CET) From: Martin Kletzander To: libvir-list@redhat.com Date: Wed, 31 Jan 2018 10:41:40 +0100 Message-Id: <2caef0171f4cf6a8858e0345fe59d88b9b53f96c.1517391519.git.mkletzan@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/8] util: Use default group's mask for unspecified resctrl allocations 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 31 Jan 2018 09:42:24 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Introduce virResctrlAllocCopyMasks() and use that to initially copy the def= ault group schemata to the allocation before reserving any parts of the cache. = The reason for this is that when new group is created the schemata will have un= known data in it. If there was previously group with the same CLoS ID, it will h= ave the previous valies, if not it will have all bits set. And we need to set = all unspecified (in the XML) allocations to the same one as the default group. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1289368 Signed-off-by: Martin Kletzander --- src/util/virresctrl.c | 64 ++++++++++++++++++++++++++++++++++++++---------= ---- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index fa7c28e9b45e..2bdca5455783 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -1296,23 +1296,8 @@ virResctrlAllocFindUnused(virResctrlAllocPerTypePtr = a_type, ssize_t last_bits =3D 0; ssize_t last_pos =3D -1; =20 - /* If there is no reservation requested we need to set all bits. That= 's due - * to weird interface of the resctrl sysfs. It's also the reason why = we - * cannot reserve the whole cache in one allocation. */ - if (!size) { - a_mask =3D virBitmapNew(i_type->bits); - if (!a_mask) - return -1; - - virBitmapSetAll(a_mask); - - if (virResctrlAllocSetMask(a_type, cache, a_mask) < 0) { - virBitmapFree(a_mask); - return -1; - } - + if (!size) return 0; - } =20 if (cache >=3D f_type->nmasks) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -1415,6 +1400,44 @@ virResctrlAllocFindUnused(virResctrlAllocPerTypePtr = a_type, } =20 =20 +static int +virResctrlAllocCopyMasks(virResctrlAllocPtr dst, + virResctrlAllocPtr src) +{ + unsigned int level =3D 0; + + for (level =3D 0; level < src->nlevels; level++) { + virResctrlAllocPerLevelPtr s_level =3D src->levels[level]; + unsigned int type =3D 0; + + if (!s_level) + continue; + + for (type =3D 0; type < VIR_CACHE_TYPE_LAST; type++) { + virResctrlAllocPerTypePtr s_type =3D s_level->types[type]; + virResctrlAllocPerTypePtr d_type =3D NULL; + unsigned int cache =3D 0; + + if (!s_type) + continue; + + d_type =3D virResctrlAllocGetType(dst, level, type); + if (!d_type) + return -1; + + for (cache =3D 0; cache < s_type->nmasks; cache++) { + virBitmapPtr mask =3D s_type->masks[cache]; + + if (mask && virResctrlAllocUpdateMask(dst, level, type, ca= che, mask) < 0) + return -1; + } + } + } + + return 0; +} + + /* * This function is called when creating an allocation in the system. Wha= t it * does is that it gets all the unused bits using virResctrlAllocGetUnused= () and @@ -1428,11 +1451,19 @@ virResctrlAllocMasksAssign(virResctrlInfoPtr resctr= l, int ret =3D -1; unsigned int level =3D 0; virResctrlAllocPtr alloc_free =3D NULL; + virResctrlAllocPtr alloc_default =3D NULL; =20 alloc_free =3D virResctrlAllocGetUnused(resctrl); if (!alloc_free) return -1; =20 + alloc_default =3D virResctrlAllocGetDefault(resctrl); + if (!alloc_default) + return -1; + + if (virResctrlAllocCopyMasks(alloc, alloc_default) < 0) + return -1; + for (level =3D 0; level < alloc->nlevels; level++) { virResctrlAllocPerLevelPtr a_level =3D alloc->levels[level]; virResctrlAllocPerLevelPtr f_level =3D NULL; @@ -1480,6 +1511,7 @@ virResctrlAllocMasksAssign(virResctrlInfoPtr resctrl, ret =3D 0; cleanup: virObjectUnref(alloc_free); + virObjectUnref(alloc_default); return ret; } =20 --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 07:56:35 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1517391741832661.5041109189665; Wed, 31 Jan 2018 01:42:21 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 04A06780F7; Wed, 31 Jan 2018 09:42:20 +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 C5BE160CAB; Wed, 31 Jan 2018 09:42:19 +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 7EC2018033DE; Wed, 31 Jan 2018 09:42:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0V9fwZP025420 for ; Wed, 31 Jan 2018 04:41:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id B6BB85C26A; Wed, 31 Jan 2018 09:41:58 +0000 (UTC) Received: from caroline.localdomain (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5732618029 for ; Wed, 31 Jan 2018 09:41:51 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.usersys.redhat.com [127.0.0.1]) by caroline.localdomain (Postfix) with ESMTP id 8A6E8120480 for ; Wed, 31 Jan 2018 10:41:50 +0100 (CET) From: Martin Kletzander To: libvir-list@redhat.com Date: Wed, 31 Jan 2018 10:41:41 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/8] util: Don't overwrite mask in virResctrlAllocFindUnused 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 31 Jan 2018 09:42:20 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Due to confusing naming the pointer to the mask got copied which must not happen, so use UpdateMask instead of SetMask. That also means we can get completely rid of SetMask. Also don't clear the free bits since it is not used again (leftover from previous versions). Signed-off-by: Martin Kletzander --- src/util/virresctrl.c | 41 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 2bdca5455783..14a3c459ffd3 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -1255,22 +1255,6 @@ virResctrlAllocGetUnused(virResctrlInfoPtr resctrl A= TTRIBUTE_UNUSED) =20 #endif /* ! __linux__ */ =20 -static int -virResctrlAllocSetMask(virResctrlAllocPerTypePtr a_type, - unsigned int cache, - virBitmapPtr mask) -{ - if (a_type->nmasks <=3D cache && - VIR_EXPAND_N(a_type->masks, a_type->nmasks, - cache - a_type->nmasks + 1) < 0) - return -1; - - virBitmapFree(a_type->masks[cache]); - a_type->masks[cache] =3D mask; - - return 0; -} - =20 /* * Given the information about requested allocation type `a_type`, the host @@ -1278,16 +1262,19 @@ virResctrlAllocSetMask(virResctrlAllocPerTypePtr a_= type, * this function tries to find the smallest free space in which the alloca= tion * for cache id `cache` would fit. We're looking for the smallest place in * order to minimize fragmentation and maximize the possibility of succeed= ing. + * + * Per-cache allocation for the @level, @type and @cache must already be + * allocated for @alloc (does not have to exist though). */ static int -virResctrlAllocFindUnused(virResctrlAllocPerTypePtr a_type, +virResctrlAllocFindUnused(virResctrlAllocPtr alloc, virResctrlInfoPerTypePtr i_type, virResctrlAllocPerTypePtr f_type, unsigned int level, unsigned int type, unsigned int cache) { - unsigned long long *size =3D a_type->sizes[cache]; + unsigned long long *size =3D alloc->levels[level]->types[type]->sizes[= cache]; virBitmapPtr a_mask =3D NULL; virBitmapPtr f_mask =3D NULL; unsigned long long need_bits; @@ -1295,6 +1282,7 @@ virResctrlAllocFindUnused(virResctrlAllocPerTypePtr a= _type, ssize_t pos =3D -1; ssize_t last_bits =3D 0; ssize_t last_pos =3D -1; + int ret =3D -1; =20 if (!size) return 0; @@ -1386,17 +1374,16 @@ virResctrlAllocFindUnused(virResctrlAllocPerTypePtr= a_type, if (!a_mask) return -1; =20 - for (i =3D last_pos; i < last_pos + need_bits; i++) { + for (i =3D last_pos; i < last_pos + need_bits; i++) ignore_value(virBitmapSetBit(a_mask, i)); - ignore_value(virBitmapClearBit(f_mask, i)); - } =20 - if (virResctrlAllocSetMask(a_type, cache, a_mask) < 0) { - virBitmapFree(a_mask); - return -1; - } + if (virResctrlAllocUpdateMask(alloc, level, type, cache, a_mask) < 0) + goto cleanup; =20 - return 0; + ret =3D 0; + cleanup: + virBitmapFree(a_mask); + return ret; } =20 =20 @@ -1502,7 +1489,7 @@ virResctrlAllocMasksAssign(virResctrlInfoPtr resctrl, virResctrlInfoPerLevelPtr i_level =3D resctrl->levels[leve= l]; virResctrlInfoPerTypePtr i_type =3D i_level->types[type]; =20 - if (virResctrlAllocFindUnused(a_type, i_type, f_type, leve= l, type, cache) < 0) + if (virResctrlAllocFindUnused(alloc, i_type, f_type, level= , type, cache) < 0) goto cleanup; } } --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 07:56:35 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 151739174843598.74990217902621; Wed, 31 Jan 2018 01:42:28 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EFBFE2CE945; Wed, 31 Jan 2018 09:42:26 +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 C19AA60C8A; Wed, 31 Jan 2018 09:42:26 +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 8D0D418033DD; Wed, 31 Jan 2018 09:42:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0V9g6oZ025581 for ; Wed, 31 Jan 2018 04:42:06 -0500 Received: by smtp.corp.redhat.com (Postfix) id A854F5D6B7; Wed, 31 Jan 2018 09:42:06 +0000 (UTC) Received: from caroline.localdomain (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7036C5EDEE for ; Wed, 31 Jan 2018 09:41:51 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.usersys.redhat.com [127.0.0.1]) by caroline.localdomain (Postfix) with ESMTP id 95BEF120487 for ; Wed, 31 Jan 2018 10:41:50 +0100 (CET) From: Martin Kletzander To: libvir-list@redhat.com Date: Wed, 31 Jan 2018 10:41:42 +0100 Message-Id: <5d2666ddd3fef039284964028f19313025dd0533.1517391519.git.mkletzan@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/8] qemu: Restore machinename even without cgroups 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 31 Jan 2018 09:42:27 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The virresctrl will use this as well and we need to have that info after re= start to properly clean up /sys/fs/resctrl. Signed-off-by: Martin Kletzander --- src/qemu/qemu_cgroup.c | 4 ---- src/qemu/qemu_process.c | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index fbf79a6d8f33..b604edb31c0d 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -986,10 +986,6 @@ qemuConnectCgroup(virDomainObjPtr vm) if (!virCgroupAvailable()) goto done; =20 - priv->machineName =3D qemuDomainGetMachineName(vm); - if (!priv->machineName) - goto cleanup; - virCgroupFree(&priv->cgroup); =20 if (virCgroupNewDetectMachine(vm->def->name, diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 0577f4c35d08..239798fa5d7c 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7198,6 +7198,10 @@ qemuProcessReconnect(void *opaque) if (qemuHostdevUpdateActiveDomainDevices(driver, obj->def) < 0) goto error; =20 + priv->machineName =3D qemuDomainGetMachineName(obj); + if (!priv->machineName) + goto error; + if (qemuConnectCgroup(obj) < 0) goto error; =20 --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 07:56:35 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 151739173350443.23564882109861; Wed, 31 Jan 2018 01:42:13 -0800 (PST) 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 8A35068557; Wed, 31 Jan 2018 09:42:11 +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 4C9F060BF3; Wed, 31 Jan 2018 09:42:11 +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 0B0723FC73; Wed, 31 Jan 2018 09:42:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0V9g8KQ025641 for ; Wed, 31 Jan 2018 04:42:08 -0500 Received: by smtp.corp.redhat.com (Postfix) id 04A9118843; Wed, 31 Jan 2018 09:42:08 +0000 (UTC) Received: from caroline.localdomain (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CA86B6A02E for ; Wed, 31 Jan 2018 09:41:58 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.usersys.redhat.com [127.0.0.1]) by caroline.localdomain (Postfix) with ESMTP id A12F112048D for ; Wed, 31 Jan 2018 10:41:50 +0100 (CET) From: Martin Kletzander To: libvir-list@redhat.com Date: Wed, 31 Jan 2018 10:41:43 +0100 Message-Id: <4e851286b27406619941900ca52ca0067984380f.1517391519.git.mkletzan@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/8] util: Extract path formatting into virResctrlAllocDeterminePath 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.28]); Wed, 31 Jan 2018 09:42:12 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We can use this from more places later, so just a future code de-duplicatio= n. Signed-off-by: Martin Kletzander --- src/libvirt_private.syms | 1 + src/util/virresctrl.c | 29 ++++++++++++++++++++--------- src/util/virresctrl.h | 4 ++++ 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 792fb60568bd..9339c2c3259d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2560,6 +2560,7 @@ virCacheTypeFromString; virCacheTypeToString; virResctrlAllocAddPID; virResctrlAllocCreate; +virResctrlAllocDeterminePath; virResctrlAllocForeachSize; virResctrlAllocFormat; virResctrlAllocGetID; diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 14a3c459ffd3..fefca32a6710 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -1503,6 +1503,25 @@ virResctrlAllocMasksAssign(virResctrlInfoPtr resctrl, } =20 =20 +int +virResctrlAllocDeterminePath(virResctrlAllocPtr alloc, + const char *machinename) +{ + if (!alloc->id) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Resctrl Allocation ID must be set before creatio= n")); + return -1; + } + + if (!alloc->path && + virAsprintf(&alloc->path, "%s/%s-%s", + SYSFS_RESCTRL_PATH, machinename, alloc->id) < 0) + return -1; + + return 0; +} + + /* This checks if the directory for the alloc exists. If not it tries to = create * it and apply appropriate alloc settings. */ int @@ -1524,15 +1543,7 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl, return -1; } =20 - if (!alloc->id) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Resctrl Allocation ID must be set before creatio= n")); - return -1; - } - - if (!alloc->path && - virAsprintf(&alloc->path, "%s/%s-%s", - SYSFS_RESCTRL_PATH, machinename, alloc->id) < 0) + if (virResctrlAllocDeterminePath(alloc, machinename) < 0) return -1; =20 if (virFileExists(alloc->path)) { diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h index 63a954feaad1..5368ba211924 100644 --- a/src/util/virresctrl.h +++ b/src/util/virresctrl.h @@ -102,6 +102,10 @@ virResctrlAllocGetID(virResctrlAllocPtr alloc); char * virResctrlAllocFormat(virResctrlAllocPtr alloc); =20 +int +virResctrlAllocDeterminePath(virResctrlAllocPtr alloc, + const char *machinename); + int virResctrlAllocCreate(virResctrlInfoPtr r_info, virResctrlAllocPtr alloc, --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 07:56:35 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 151739175132795.48685577545723; Wed, 31 Jan 2018 01:42:31 -0800 (PST) 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 1DA342812D; Wed, 31 Jan 2018 09:42:30 +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 C0A0818C5D; Wed, 31 Jan 2018 09:42:29 +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 849F138B0; Wed, 31 Jan 2018 09:42:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0V9g60g025580 for ; Wed, 31 Jan 2018 04:42:06 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9EE136B44B; Wed, 31 Jan 2018 09:42:06 +0000 (UTC) Received: from caroline.localdomain (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6D7F95EDE2 for ; Wed, 31 Jan 2018 09:41:58 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.usersys.redhat.com [127.0.0.1]) by caroline.localdomain (Postfix) with ESMTP id AC608120492 for ; Wed, 31 Jan 2018 10:41:50 +0100 (CET) From: Martin Kletzander To: libvir-list@redhat.com Date: Wed, 31 Jan 2018 10:41:44 +0100 Message-Id: <3d20c4bb1439da59360cdd4de2eebb0ede6a0e26.1517391519.git.mkletzan@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 6/8] qemu: Restore resctrl alloc data after restart 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.30]); Wed, 31 Jan 2018 09:42:30 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" During reconnect we need to reconstruct the paths of all cachetunes so that= they get cleaned up when the domain is stopped. Signed-off-by: Martin Kletzander --- src/qemu/qemu_process.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 239798fa5d7c..bcd4ac8ad699 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -77,6 +77,7 @@ #include "configmake.h" #include "nwfilter_conf.h" #include "netdev_bandwidth_conf.h" +#include "virresctrl.h" =20 #define VIR_FROM_THIS VIR_FROM_QEMU =20 @@ -7332,6 +7333,12 @@ qemuProcessReconnect(void *opaque) if (qemuConnectAgent(driver, obj) < 0) goto error; =20 + for (i =3D 0; i < obj->def->ncachetunes; i++) { + if (virResctrlAllocDeterminePath(obj->def->cachetunes[i]->alloc, + priv->machineName) < 0) + goto error; + } + /* update domain state XML with possibly updated state in virDomainObj= */ if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, obj, driver->ca= ps) < 0) goto error; --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 07:56:35 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 151739175496761.11950464806716; Wed, 31 Jan 2018 01:42:34 -0800 (PST) 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 8A46EC05B00E; Wed, 31 Jan 2018 09:42:33 +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 525245D6B7; Wed, 31 Jan 2018 09:42:33 +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 150A418033E2; Wed, 31 Jan 2018 09:42:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0V9g71S025615 for ; Wed, 31 Jan 2018 04:42:07 -0500 Received: by smtp.corp.redhat.com (Postfix) id 49FE15EDEE; Wed, 31 Jan 2018 09:42:07 +0000 (UTC) Received: from caroline.localdomain (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7138F61F41 for ; Wed, 31 Jan 2018 09:41:59 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.usersys.redhat.com [127.0.0.1]) by caroline.localdomain (Postfix) with ESMTP id B8233120497 for ; Wed, 31 Jan 2018 10:41:50 +0100 (CET) From: Martin Kletzander To: libvir-list@redhat.com Date: Wed, 31 Jan 2018 10:41:45 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 7/8] util: Reorder functions in virresctrl to minimize stubs 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.31]); Wed, 31 Jan 2018 09:42:34 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" If we reorder the functions properly, we only need to have few stub functio= ns for non-Linux platforms and it is also nicer to look at and read if they ar= e in one place with only one preprocessor condition. The order after this patch= is: - Class allocation and Static functions (used by everything, static depende= ncies) - Linux-only functions - Non-Linux stubs - Exported functions (as they rely on all previous functions) Signed-off-by: Martin Kletzander --- src/libvirt_linux.syms | 3 + src/libvirt_private.syms | 1 - src/util/virresctrl.c | 939 +++++++++++++++++++++++--------------------= ---- 3 files changed, 459 insertions(+), 484 deletions(-) diff --git a/src/libvirt_linux.syms b/src/libvirt_linux.syms index 5fa2c790efc1..27425e4bbebb 100644 --- a/src/libvirt_linux.syms +++ b/src/libvirt_linux.syms @@ -9,6 +9,9 @@ virHostCPUGetSiblingsList; virHostCPUGetSocket; virHostCPUGetStatsLinux; =20 +# util/virresctrl.h +virResctrlAllocGetUnused; + # Let emacs know we want case-insensitive sorting # Local Variables: # sort-fold-case: t diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 9339c2c3259d..21ec8d8c8c34 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2564,7 +2564,6 @@ virResctrlAllocDeterminePath; virResctrlAllocForeachSize; virResctrlAllocFormat; virResctrlAllocGetID; -virResctrlAllocGetUnused; virResctrlAllocNew; virResctrlAllocRemove; virResctrlAllocSetID; diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index fefca32a6710..cab7570f7b8e 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -294,346 +294,6 @@ virResctrlAllocNew(void) } =20 =20 -/* Common functions */ -#ifdef __linux__ -static int -virResctrlLockInternal(int op) -{ - int fd =3D open(SYSFS_RESCTRL_PATH, O_DIRECTORY | O_CLOEXEC); - - if (fd < 0) { - virReportSystemError(errno, "%s", _("Cannot open resctrl")); - return -1; - } - - if (flock(fd, op) < 0) { - virReportSystemError(errno, "%s", _("Cannot lock resctrl")); - VIR_FORCE_CLOSE(fd); - return -1; - } - - return fd; -} - - -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; - -#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")); - - /* Trying to save the already broken */ - if (flock(fd, LOCK_UN) < 0) - virReportSystemError(errno, "%s", _("Cannot unlock resctrl")); - return -1; - } -#endif /* ! __linux__ */ - - return 0; -} - - -/* 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; -} - - -#ifdef __linux__ - -int -virResctrlGetInfo(virResctrlInfoPtr resctrl) -{ - DIR *dirp =3D NULL; - char *endptr =3D NULL; - char *tmp_str =3D NULL; - int ret =3D -1; - int rv =3D -1; - int type =3D 0; - struct dirent *ent =3D NULL; - unsigned int level =3D 0; - virResctrlInfoPerLevelPtr i_level =3D NULL; - virResctrlInfoPerTypePtr i_type =3D NULL; - - rv =3D virDirOpenIfExists(&dirp, SYSFS_RESCTRL_PATH "/info"); - if (rv <=3D 0) { - ret =3D rv; - goto cleanup; - } - - while ((rv =3D virDirRead(dirp, &ent, SYSFS_RESCTRL_PATH "/info")) > 0= ) { - VIR_DEBUG("Parsing info type '%s'", ent->d_name); - if (ent->d_name[0] !=3D 'L') - continue; - - if (virStrToLong_uip(ent->d_name + 1, &endptr, 10, &level) < 0) { - VIR_DEBUG("Cannot parse resctrl cache info level '%s'", ent->d= _name + 1); - continue; - } - - type =3D virResctrlTypeFromString(endptr); - if (type < 0) { - VIR_DEBUG("Cannot parse resctrl cache info type '%s'", endptr); - continue; - } - - if (VIR_ALLOC(i_type) < 0) - goto cleanup; - - i_type->control.scope =3D type; - - rv =3D virFileReadValueUint(&i_type->control.max_allocation, - SYSFS_RESCTRL_PATH "/info/%s/num_closids= ", - ent->d_name); - if (rv =3D=3D -2) { - /* The file doesn't exist, so it's unusable for us, - * but we can scan further */ - VIR_WARN("The path '" SYSFS_RESCTRL_PATH "/info/%s/num_closids= ' " - "does not exist", - ent->d_name); - } else if (rv < 0) { - /* Other failures are fatal, so just quit */ - goto cleanup; - } - - rv =3D virFileReadValueString(&i_type->cbm_mask, - SYSFS_RESCTRL_PATH - "/info/%s/cbm_mask", - ent->d_name); - if (rv =3D=3D -2) { - /* If the previous file exists, so should this one. Hence -2 = is - * fatal in this case as well (errors out in next condition) -= the - * kernel interface might've changed too much or something els= e is - * wrong. */ - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot get cbm_mask from resctrl cache info"= )); - } - if (rv < 0) - goto cleanup; - - virStringTrimOptionalNewline(i_type->cbm_mask); - - rv =3D virFileReadValueUint(&i_type->min_cbm_bits, - SYSFS_RESCTRL_PATH "/info/%s/min_cbm_bit= s", - ent->d_name); - if (rv =3D=3D -2) - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot get min_cbm_bits from resctrl cache i= nfo")); - if (rv < 0) - goto cleanup; - - if (resctrl->nlevels <=3D level && - VIR_EXPAND_N(resctrl->levels, resctrl->nlevels, - level - resctrl->nlevels + 1) < 0) - goto cleanup; - - if (!resctrl->levels[level]) { - virResctrlInfoPerTypePtr *types =3D NULL; - - if (VIR_ALLOC_N(types, VIR_CACHE_TYPE_LAST) < 0) - goto cleanup; - - if (VIR_ALLOC(resctrl->levels[level]) < 0) { - VIR_FREE(types); - goto cleanup; - } - resctrl->levels[level]->types =3D types; - } - - i_level =3D resctrl->levels[level]; - - if (i_level->types[type]) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Duplicate cache type in resctrl for level %u= "), - level); - goto cleanup; - } - - 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); - } - - ret =3D 0; - cleanup: - VIR_DIR_CLOSE(dirp); - if (i_type) - VIR_FREE(i_type->cbm_mask); - VIR_FREE(i_type); - return ret; -} - -#else /* ! __linux__ */ - -int -virResctrlGetInfo(virResctrlInfoPtr resctrl ATTRIBUTE_UNUSED) -{ - virReportSystemError(ENOSYS, "%s", - _("Cache tune not supported on this platform")); - return -1; -} - -#endif /* ! __linux__ */ - - -int -virResctrlInfoGetCache(virResctrlInfoPtr resctrl, - unsigned int level, - unsigned long long size, - size_t *ncontrols, - virResctrlInfoPerCachePtr **controls) -{ - virResctrlInfoPerLevelPtr i_level =3D NULL; - virResctrlInfoPerTypePtr i_type =3D NULL; - size_t i =3D 0; - int ret =3D -1; - - if (virResctrlInfoIsEmpty(resctrl)) - return 0; - - if (level >=3D resctrl->nlevels) - return 0; - - i_level =3D resctrl->levels[level]; - if (!i_level) - return 0; - - for (i =3D 0; i < VIR_CACHE_TYPE_LAST; i++) { - i_type =3D i_level->types[i]; - if (!i_type) - continue; - - /* 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) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("level %u cache size %llu does not match " - "expected size %llu"), - level, i_type->size, size); - goto error; - } - i_type->max_cache_id++; - } - - if (VIR_EXPAND_N(*controls, *ncontrols, 1) < 0) - goto error; - if (VIR_ALLOC((*controls)[*ncontrols - 1]) < 0) - goto error; - - memcpy((*controls)[*ncontrols - 1], &i_type->control, sizeof(i_typ= e->control)); - } - - ret =3D 0; - cleanup: - return ret; - error: - while (*ncontrols) - VIR_FREE((*controls)[--*ncontrols]); - VIR_FREE(*controls); - goto cleanup; -} - - -/* Alloc-related functions */ -bool -virResctrlAllocIsEmpty(virResctrlAllocPtr resctrl) -{ - size_t i =3D 0; - size_t j =3D 0; - size_t k =3D 0; - - if (!resctrl) - return true; - - for (i =3D 0; i < resctrl->nlevels; i++) { - virResctrlAllocPerLevelPtr a_level =3D resctrl->levels[i]; - - if (!a_level) - continue; - - for (j =3D 0; j < VIR_CACHE_TYPE_LAST; j++) { - virResctrlAllocPerTypePtr a_type =3D a_level->types[j]; - - if (!a_type) - continue; - - for (k =3D 0; k < a_type->nsizes; k++) { - if (a_type->sizes[k]) - return false; - } - - for (k =3D 0; k < a_type->nmasks; k++) { - if (a_type->masks[k]) - return false; - } - } - } - - return true; -} - - static virResctrlAllocPerTypePtr virResctrlAllocGetType(virResctrlAllocPtr resctrl, unsigned int level, @@ -667,38 +327,6 @@ virResctrlAllocGetType(virResctrlAllocPtr resctrl, } =20 =20 -#ifdef __linux__ - -static int -virResctrlAllocUpdateMask(virResctrlAllocPtr resctrl, - unsigned int level, - virCacheType type, - unsigned int cache, - virBitmapPtr mask) -{ - virResctrlAllocPerTypePtr a_type =3D virResctrlAllocGetType(resctrl, l= evel, type); - - if (!a_type) - return -1; - - if (a_type->nmasks <=3D cache && - VIR_EXPAND_N(a_type->masks, a_type->nmasks, - cache - a_type->nmasks + 1) < 0) - return -1; - - if (!a_type->masks[cache]) { - a_type->masks[cache] =3D virBitmapNew(virBitmapSize(mask)); - - if (!a_type->masks[cache]) - return -1; - } - - return virBitmapCopy(a_type->masks[cache], mask); -} - -#endif - - static int virResctrlAllocUpdateSize(virResctrlAllocPtr resctrl, unsigned int level, @@ -725,6 +353,31 @@ virResctrlAllocUpdateSize(virResctrlAllocPtr resctrl, } =20 =20 +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; +} + + /* * Check if there is an allocation for this level/type/cache already. Cal= led * before updating the structure. VIR_CACHE_TYPE_BOTH collides with any t= ype, @@ -775,150 +428,223 @@ virResctrlAllocCheckCollision(virResctrlAllocPtr al= loc, } else { a_type =3D a_level->types[type]; =20 - if (a_type && a_type->nsizes > cache && a_type->sizes[cache]) - return true; + if (a_type && a_type->nsizes > cache && a_type->sizes[cache]) + return true; + } + + return false; +} + + +#ifdef __linux__ + +static int +virResctrlLockInternal(int op) +{ + int fd =3D open(SYSFS_RESCTRL_PATH, O_DIRECTORY | O_CLOEXEC); + + if (fd < 0) { + virReportSystemError(errno, "%s", _("Cannot open resctrl")); + return -1; + } + + if (flock(fd, op) < 0) { + virReportSystemError(errno, "%s", _("Cannot lock resctrl")); + VIR_FORCE_CLOSE(fd); + return -1; } =20 - return false; + return fd; } =20 =20 -int -virResctrlAllocSetSize(virResctrlAllocPtr resctrl, - unsigned int level, - virCacheType type, - unsigned int cache, - unsigned long long size) +static inline int +virResctrlLockWrite(void) { - if (virResctrlAllocCheckCollision(resctrl, level, type, cache)) { - virReportError(VIR_ERR_XML_ERROR, - _("Colliding cache allocations for cache " - "level '%u' id '%u', type '%s'"), - level, cache, virCacheTypeToString(type)); + return virResctrlLockInternal(LOCK_EX); +} + + +static int +virResctrlUnlock(int fd) +{ + if (fd =3D=3D -1) + return 0; + + /* 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")); + + /* Trying to save the already broken */ + if (flock(fd, LOCK_UN) < 0) + virReportSystemError(errno, "%s", _("Cannot unlock resctrl")); return -1; } =20 - return virResctrlAllocUpdateSize(resctrl, level, type, cache, size); + return 0; } =20 =20 int -virResctrlAllocForeachSize(virResctrlAllocPtr resctrl, - virResctrlAllocForeachSizeCallback cb, - void *opaque) +virResctrlGetInfo(virResctrlInfoPtr resctrl) { - int ret =3D 0; + DIR *dirp =3D NULL; + char *endptr =3D NULL; + char *tmp_str =3D NULL; + int ret =3D -1; + int rv =3D -1; + int type =3D 0; + struct dirent *ent =3D NULL; unsigned int level =3D 0; - unsigned int type =3D 0; - unsigned int cache =3D 0; - - if (!resctrl) - return 0; + virResctrlInfoPerLevelPtr i_level =3D NULL; + virResctrlInfoPerTypePtr i_type =3D NULL; =20 - for (level =3D 0; level < resctrl->nlevels; level++) { - virResctrlAllocPerLevelPtr a_level =3D resctrl->levels[level]; + rv =3D virDirOpenIfExists(&dirp, SYSFS_RESCTRL_PATH "/info"); + if (rv <=3D 0) { + ret =3D rv; + goto cleanup; + } =20 - if (!a_level) + while ((rv =3D virDirRead(dirp, &ent, SYSFS_RESCTRL_PATH "/info")) > 0= ) { + VIR_DEBUG("Parsing info type '%s'", ent->d_name); + if (ent->d_name[0] !=3D 'L') continue; =20 - for (type =3D 0; type < VIR_CACHE_TYPE_LAST; type++) { - virResctrlAllocPerTypePtr a_type =3D a_level->types[type]; + if (virStrToLong_uip(ent->d_name + 1, &endptr, 10, &level) < 0) { + VIR_DEBUG("Cannot parse resctrl cache info level '%s'", ent->d= _name + 1); + continue; + } =20 - if (!a_type) - continue; + type =3D virResctrlTypeFromString(endptr); + if (type < 0) { + VIR_DEBUG("Cannot parse resctrl cache info type '%s'", endptr); + continue; + } =20 - for (cache =3D 0; cache < a_type->nsizes; cache++) { - unsigned long long *size =3D a_type->sizes[cache]; + if (VIR_ALLOC(i_type) < 0) + goto cleanup; =20 - if (!size) - continue; + i_type->control.scope =3D type; =20 - ret =3D cb(level, type, cache, *size, opaque); - if (ret < 0) - return ret; - } + rv =3D virFileReadValueUint(&i_type->control.max_allocation, + SYSFS_RESCTRL_PATH "/info/%s/num_closids= ", + ent->d_name); + if (rv =3D=3D -2) { + /* The file doesn't exist, so it's unusable for us, + * but we can scan further */ + VIR_WARN("The path '" SYSFS_RESCTRL_PATH "/info/%s/num_closids= ' " + "does not exist", + ent->d_name); + } else if (rv < 0) { + /* Other failures are fatal, so just quit */ + goto cleanup; } - } =20 - return 0; -} + rv =3D virFileReadValueString(&i_type->cbm_mask, + SYSFS_RESCTRL_PATH + "/info/%s/cbm_mask", + ent->d_name); + if (rv =3D=3D -2) { + /* If the previous file exists, so should this one. Hence -2 = is + * fatal in this case as well (errors out in next condition) -= the + * kernel interface might've changed too much or something els= e is + * wrong. */ + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot get cbm_mask from resctrl cache info"= )); + } + if (rv < 0) + goto cleanup; =20 + virStringTrimOptionalNewline(i_type->cbm_mask); =20 -int -virResctrlAllocSetID(virResctrlAllocPtr alloc, - const char *id) -{ - if (!id) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Resctrl allocation 'id' cannot be NULL")); - return -1; - } + rv =3D virFileReadValueUint(&i_type->min_cbm_bits, + SYSFS_RESCTRL_PATH "/info/%s/min_cbm_bit= s", + ent->d_name); + if (rv =3D=3D -2) + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot get min_cbm_bits from resctrl cache i= nfo")); + if (rv < 0) + goto cleanup; =20 - return VIR_STRDUP(alloc->id, id); -} + if (resctrl->nlevels <=3D level && + VIR_EXPAND_N(resctrl->levels, resctrl->nlevels, + level - resctrl->nlevels + 1) < 0) + goto cleanup; =20 + if (!resctrl->levels[level]) { + virResctrlInfoPerTypePtr *types =3D NULL; =20 -const char * -virResctrlAllocGetID(virResctrlAllocPtr alloc) -{ - return alloc->id; -} + if (VIR_ALLOC_N(types, VIR_CACHE_TYPE_LAST) < 0) + goto cleanup; =20 + if (VIR_ALLOC(resctrl->levels[level]) < 0) { + VIR_FREE(types); + goto cleanup; + } + resctrl->levels[level]->types =3D types; + } =20 -char * -virResctrlAllocFormat(virResctrlAllocPtr resctrl) -{ - virBuffer buf =3D VIR_BUFFER_INITIALIZER; - unsigned int level =3D 0; - unsigned int type =3D 0; - unsigned int cache =3D 0; + i_level =3D resctrl->levels[level]; =20 - if (!resctrl) - return NULL; + if (i_level->types[type]) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Duplicate cache type in resctrl for level %u= "), + level); + goto cleanup; + } =20 - for (level =3D 0; level < resctrl->nlevels; level++) { - virResctrlAllocPerLevelPtr a_level =3D resctrl->levels[level]; + 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; + } =20 - if (!a_level) - continue; + i_type->bits +=3D count_one_bits(virHexToBin(*tmp_str)); + } =20 - for (type =3D 0; type < VIR_CACHE_TYPE_LAST; type++) { - virResctrlAllocPerTypePtr a_type =3D a_level->types[type]; + VIR_STEAL_PTR(i_level->types[type], i_type); + } =20 - if (!a_type) - continue; + ret =3D 0; + cleanup: + VIR_DIR_CLOSE(dirp); + if (i_type) + VIR_FREE(i_type->cbm_mask); + VIR_FREE(i_type); + return ret; +} =20 - virBufferAsprintf(&buf, "L%u%s:", level, virResctrlTypeToStrin= g(type)); =20 - for (cache =3D 0; cache < a_type->nmasks; cache++) { - virBitmapPtr mask =3D a_type->masks[cache]; - char *mask_str =3D NULL; +static int +virResctrlAllocUpdateMask(virResctrlAllocPtr resctrl, + unsigned int level, + virCacheType type, + unsigned int cache, + virBitmapPtr mask) +{ + virResctrlAllocPerTypePtr a_type =3D virResctrlAllocGetType(resctrl, l= evel, type); =20 - if (!mask) - continue; + if (!a_type) + return -1; =20 - mask_str =3D virBitmapToString(mask, false, true); - if (!mask_str) { - virBufferFreeAndReset(&buf); - return NULL; - } + if (a_type->nmasks <=3D cache && + VIR_EXPAND_N(a_type->masks, a_type->nmasks, + cache - a_type->nmasks + 1) < 0) + return -1; =20 - virBufferAsprintf(&buf, "%u=3D%s;", cache, mask_str); - VIR_FREE(mask_str); - } + if (!a_type->masks[cache]) { + a_type->masks[cache] =3D virBitmapNew(virBitmapSize(mask)); =20 - virBufferTrim(&buf, ";", 1); - virBufferAddChar(&buf, '\n'); - } + if (!a_type->masks[cache]) + return -1; } =20 - virBufferCheckError(&buf); - return virBufferContentAndReset(&buf); + return virBitmapCopy(a_type->masks[cache], mask); } =20 =20 -#ifdef __linux__ - static int virResctrlAllocParseProcessCache(virResctrlInfoPtr resctrl, virResctrlAllocPtr alloc, @@ -1171,6 +897,7 @@ virResctrlAllocNewFromInfo(virResctrlInfoPtr info) goto cleanup; } =20 + /* * This function creates an allocation that represents all unused parts of= all * caches in the system. It uses virResctrlInfo for creating a new full @@ -1238,23 +965,11 @@ virResctrlAllocGetUnused(virResctrlInfoPtr resctrl) return ret; =20 error: - virObjectUnref(ret); - ret =3D NULL; - goto cleanup; -} - -#else /* ! __linux__ */ - -virResctrlAllocPtr -virResctrlAllocGetUnused(virResctrlInfoPtr resctrl ATTRIBUTE_UNUSED) -{ - virReportSystemError(ENOSYS, "%s", - _("Cache tune not supported on this platform")); - return NULL; + virObjectUnref(ret); + ret =3D NULL; + goto cleanup; } =20 -#endif /* ! __linux__ */ - =20 /* * Given the information about requested allocation type `a_type`, the host @@ -1591,6 +1306,264 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl, return ret; } =20 +#else /* ! __linux__ */ + +int +virResctrlGetInfo(virResctrlInfoPtr resctrl ATTRIBUTE_UNUSED) +{ + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Resource control is not supported on this host")); + return -1; +} + +int +virResctrlAllocCreate(virResctrlInfoPtr resctrl ATTRIBUTE_UNUSED, + virResctrlAllocPtr alloc ATTRIBUTE_UNUSED, + const char *machinename ATTRIBUTE_UNUSED) +{ + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Resource control is not supported on this host")); + return -1; +} + +#endif /* ! __linux__ */ + + +int +virResctrlInfoGetCache(virResctrlInfoPtr resctrl, + unsigned int level, + unsigned long long size, + size_t *ncontrols, + virResctrlInfoPerCachePtr **controls) +{ + virResctrlInfoPerLevelPtr i_level =3D NULL; + virResctrlInfoPerTypePtr i_type =3D NULL; + size_t i =3D 0; + int ret =3D -1; + + if (virResctrlInfoIsEmpty(resctrl)) + return 0; + + if (level >=3D resctrl->nlevels) + return 0; + + i_level =3D resctrl->levels[level]; + if (!i_level) + return 0; + + for (i =3D 0; i < VIR_CACHE_TYPE_LAST; i++) { + i_type =3D i_level->types[i]; + if (!i_type) + continue; + + /* 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) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("level %u cache size %llu does not match " + "expected size %llu"), + level, i_type->size, size); + goto error; + } + i_type->max_cache_id++; + } + + if (VIR_EXPAND_N(*controls, *ncontrols, 1) < 0) + goto error; + if (VIR_ALLOC((*controls)[*ncontrols - 1]) < 0) + goto error; + + memcpy((*controls)[*ncontrols - 1], &i_type->control, sizeof(i_typ= e->control)); + } + + ret =3D 0; + cleanup: + return ret; + error: + while (*ncontrols) + VIR_FREE((*controls)[--*ncontrols]); + VIR_FREE(*controls); + goto cleanup; +} + + +bool +virResctrlAllocIsEmpty(virResctrlAllocPtr resctrl) +{ + size_t i =3D 0; + size_t j =3D 0; + size_t k =3D 0; + + if (!resctrl) + return true; + + for (i =3D 0; i < resctrl->nlevels; i++) { + virResctrlAllocPerLevelPtr a_level =3D resctrl->levels[i]; + + if (!a_level) + continue; + + for (j =3D 0; j < VIR_CACHE_TYPE_LAST; j++) { + virResctrlAllocPerTypePtr a_type =3D a_level->types[j]; + + if (!a_type) + continue; + + for (k =3D 0; k < a_type->nsizes; k++) { + if (a_type->sizes[k]) + return false; + } + + for (k =3D 0; k < a_type->nmasks; k++) { + if (a_type->masks[k]) + return false; + } + } + } + + return true; +} + + +int +virResctrlAllocSetSize(virResctrlAllocPtr resctrl, + unsigned int level, + virCacheType type, + unsigned int cache, + unsigned long long size) +{ + if (virResctrlAllocCheckCollision(resctrl, level, type, cache)) { + virReportError(VIR_ERR_XML_ERROR, + _("Colliding cache allocations for cache " + "level '%u' id '%u', type '%s'"), + level, cache, virCacheTypeToString(type)); + return -1; + } + + return virResctrlAllocUpdateSize(resctrl, level, type, cache, size); +} + + +int +virResctrlAllocForeachSize(virResctrlAllocPtr resctrl, + virResctrlAllocForeachSizeCallback cb, + void *opaque) +{ + int ret =3D 0; + unsigned int level =3D 0; + unsigned int type =3D 0; + unsigned int cache =3D 0; + + if (!resctrl) + return 0; + + for (level =3D 0; level < resctrl->nlevels; level++) { + virResctrlAllocPerLevelPtr a_level =3D resctrl->levels[level]; + + if (!a_level) + continue; + + for (type =3D 0; type < VIR_CACHE_TYPE_LAST; type++) { + virResctrlAllocPerTypePtr a_type =3D a_level->types[type]; + + if (!a_type) + continue; + + for (cache =3D 0; cache < a_type->nsizes; cache++) { + unsigned long long *size =3D a_type->sizes[cache]; + + if (!size) + continue; + + ret =3D cb(level, type, cache, *size, opaque); + if (ret < 0) + return ret; + } + } + } + + return 0; +} + + +int +virResctrlAllocSetID(virResctrlAllocPtr alloc, + const char *id) +{ + if (!id) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Resctrl allocation 'id' cannot be NULL")); + return -1; + } + + return VIR_STRDUP(alloc->id, id); +} + + +const char * +virResctrlAllocGetID(virResctrlAllocPtr alloc) +{ + return alloc->id; +} + + +char * +virResctrlAllocFormat(virResctrlAllocPtr resctrl) +{ + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + unsigned int level =3D 0; + unsigned int type =3D 0; + unsigned int cache =3D 0; + + if (!resctrl) + return NULL; + + for (level =3D 0; level < resctrl->nlevels; level++) { + virResctrlAllocPerLevelPtr a_level =3D resctrl->levels[level]; + + if (!a_level) + continue; + + for (type =3D 0; type < VIR_CACHE_TYPE_LAST; type++) { + virResctrlAllocPerTypePtr a_type =3D a_level->types[type]; + + if (!a_type) + continue; + + virBufferAsprintf(&buf, "L%u%s:", level, virResctrlTypeToStrin= g(type)); + + for (cache =3D 0; cache < a_type->nmasks; cache++) { + virBitmapPtr mask =3D a_type->masks[cache]; + char *mask_str =3D NULL; + + if (!mask) + continue; + + mask_str =3D virBitmapToString(mask, false, true); + if (!mask_str) { + virBufferFreeAndReset(&buf); + return NULL; + } + + virBufferAsprintf(&buf, "%u=3D%s;", cache, mask_str); + VIR_FREE(mask_str); + } + + virBufferTrim(&buf, ";", 1); + virBufferAddChar(&buf, '\n'); + } + } + + virBufferCheckError(&buf); + return virBufferContentAndReset(&buf); +} + =20 int virResctrlAllocAddPID(virResctrlAllocPtr alloc, --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 07:56:35 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1517391739413302.92283235761874; Wed, 31 Jan 2018 01:42:19 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A53A943A31; Wed, 31 Jan 2018 09:42:17 +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 7545A620D1; Wed, 31 Jan 2018 09:42:17 +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 E6F2C18033DB; Wed, 31 Jan 2018 09:42:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0V9g8nf025642 for ; Wed, 31 Jan 2018 04:42:08 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0541F18854; Wed, 31 Jan 2018 09:42:08 +0000 (UTC) Received: from caroline.localdomain (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C980F60BF3 for ; Wed, 31 Jan 2018 09:41:59 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.usersys.redhat.com [127.0.0.1]) by caroline.localdomain (Postfix) with ESMTP id C3A27120499 for ; Wed, 31 Jan 2018 10:41:50 +0100 (CET) From: Martin Kletzander To: libvir-list@redhat.com Date: Wed, 31 Jan 2018 10:41:46 +0100 Message-Id: <9336d8ccb289ca38c6f8aad4b9cd7951229eec63.1517391519.git.mkletzan@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 8/8] util: Rename resctrl to alloc in virResctrlAllocUpdateMask to be consistent X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 31 Jan 2018 09:42:18 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This was just forgotten when doing more renames in the past when working in= the reviews, I believe. Signed-off-by: Martin Kletzander --- src/util/virresctrl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index cab7570f7b8e..2948f2b9569c 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -618,13 +618,13 @@ virResctrlGetInfo(virResctrlInfoPtr 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; --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list