From nobody Sat Apr 20 08:21:54 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=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1560224069; cv=none; d=zoho.com; s=zohoarc; b=Fdck3JTnFb6sLVJgOD061adtx/CpKNZBUZ+3/0/QyxmhrOGedUoMvs8ZT8ZA2CeCiUCk3nD43JRyZVVa7xbm+aquMa4P0YLze2eApp87i4fY+yoMDXZYR/DZNLMJRmjA0ip7NxtnPUiybDNau/z5bBXsO+WdaGbRo2QG6gs87nU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560224069; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=j6YJcz99AhQt5A+z8F9vosacrMaYurNlyOzpcPYXEks=; b=GgyI/gYLt/oPJlO6g7cl13x2oPXo5FIvzokhkeA9XQVt0FP2QUKnPixN4dTOHYnRlpqenQjQdfz850p2UwikJ3w7CiTYhdUR+OM8tH6MNvj9YmGFyq9guXCc3MSioZ9qc/YAY5Uqoi/izoKEcQNoi1ECDO5iE/r2nsmWBQLmYjM= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 156022406991099.90513258381634; Mon, 10 Jun 2019 20:34:29 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2804830821F4; Tue, 11 Jun 2019 03:34:28 +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 F3CE52B32C; Tue, 11 Jun 2019 03:34:27 +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 BDE821806B20; Tue, 11 Jun 2019 03:34:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5B3Xwev022256 for ; Mon, 10 Jun 2019 23:33:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id AF9C0426D; Tue, 11 Jun 2019 03:33:58 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AA5F05DA2E for ; Tue, 11 Jun 2019 03:33:56 +0000 (UTC) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3976BC057EC6 for ; Tue, 11 Jun 2019 03:33:49 +0000 (UTC) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Jun 2019 20:33:48 -0700 Received: from david-unc.bj.intel.com ([10.238.145.63]) by fmsmga001.fm.intel.com with ESMTP; 10 Jun 2019 20:33:47 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 From: Wang Huaqiang To: libvir-list@redhat.com Date: Tue, 11 Jun 2019 11:31:16 +0800 Message-Id: <1560223876-28816-12-git-send-email-huaqiang.wang@intel.com> In-Reply-To: <1560223876-28816-1-git-send-email-huaqiang.wang@intel.com> References: <1560223876-28816-1-git-send-email-huaqiang.wang@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 11 Jun 2019 03:33:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 11 Jun 2019 03:33:49 +0000 (UTC) for IP:'134.134.136.31' DOMAIN:'mga06.intel.com' HELO:'mga06.intel.com' FROM:'huaqiang.wang@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 134.134.136.31 mga06.intel.com 134.134.136.31 mga06.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: huaqiang.wang@intel.com, tao.su@intel.com Subject: [libvirt] [PATCHv2 11/11] conf: Refactor and rename the function to validate a new resctrl monitor 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.47]); Tue, 11 Jun 2019 03:34:28 +0000 (UTC) Content-Type: text/plain; charset="utf-8" A new algorithm for detecting the vcpus and monitor type conflicts between new monitor an existing allocation and monitor groups. After refactoring, since we are verifying both @vcpus and monitor type @tag at the same time, the validating function name has been renamed from virDomainResctrlMonValidateVcpus to virDomainResctrlValidateMonitor. Signed-off-by: Wang Huaqiang --- src/conf/domain_conf.c | 62 +++++++++++++++++++++++++++++++---------------= ---- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 676a2ac..2af81c0 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19085,29 +19085,32 @@ virDomainCachetuneDefParseCache(xmlXPathContextPt= r ctxt, } =20 =20 -/* Checking if the monitor's vcpus is conflicted with existing allocation - * and monitors. +/* Checking if the monitor's vcpus and tag is conflicted with existing + * allocation and monitors. * - * Returns 1 if @vcpus equals to @resctrl->vcpus, then the monitor will - * share the underlying resctrl group with @resctrl->alloc. Returns - 1 - * if any conflict found. Returns 0 if no conflict and @vcpus is not equal - * to @resctrl->vcpus. + * Returns 1 if @monitor->vcpus equals to @resctrl->vcpus, then the monitor + * will share the underlying resctrl group with @resctrl->alloc. Returns -1 + * if any conflict found. Returns 0 if no conflict and @monitor->vcpus is + * not equal to @resctrl->vcpus. */ static int -virDomainResctrlMonValidateVcpus(virDomainResctrlDefPtr resctrl, - virBitmapPtr vcpus) +virDomainResctrlValidateMonitor(virDomainResctrlDefPtr resctrl, + virDomainResctrlMonDefPtr monitor) { size_t i =3D 0; int vcpu =3D -1; - size_t mons_same_alloc_vcpus =3D 0; + bool vcpus_overlap_any =3D false; + bool vcpus_equal_to_resctrl =3D false; + bool vcpus_overlap_no_resctrl =3D false; + bool default_alloc_monitor =3D virResctrlAllocIsEmpty(resctrl->alloc); =20 - if (virBitmapIsAllClear(vcpus)) { + if (virBitmapIsAllClear(monitor->vcpus)) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("vcpus is empty")); return -1; } =20 - while ((vcpu =3D virBitmapNextSetBit(vcpus, vcpu)) >=3D 0) { + while ((vcpu =3D virBitmapNextSetBit(monitor->vcpus, vcpu)) >=3D 0) { if (!virBitmapIsBitSet(resctrl->vcpus, vcpu)) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("Monitor vcpus conflicts with allocation")); @@ -19115,29 +19118,40 @@ virDomainResctrlMonValidateVcpus(virDomainResctrl= DefPtr resctrl, } } =20 - if (virBitmapEqual(vcpus, resctrl->vcpus)) - return 1; + vcpus_equal_to_resctrl =3D virBitmapEqual(monitor->vcpus, resctrl->vcp= us); =20 for (i =3D 0; i < resctrl->nmonitors; i++) { - if (virBitmapEqual(resctrl->vcpus, resctrl->monitors[i]->vcpus)) { - mons_same_alloc_vcpus++; - continue; + if (virBitmapEqual(monitor->vcpus, resctrl->monitors[i]->vcpus)) { + if (monitor->tag !=3D resctrl->monitors[i]->tag) { + continue; + } else { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("Identical vcpus found in same type monit= ors")); + return -1; + } } =20 - if (virBitmapOverlaps(vcpus, resctrl->monitors[i]->vcpus)) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("Monitor vcpus conflicts with monitors")); + if (virBitmapOverlaps(monitor->vcpus, resctrl->monitors[i]->vcpus)) + vcpus_overlap_any =3D true; =20 - return -1; - } + if (vcpus_equal_to_resctrl || + virBitmapEqual(resctrl->monitors[i]->vcpus, resctrl->vcpus)) + continue; + + if (virBitmapOverlaps(monitor->vcpus, resctrl->monitors[i]->vcpus)) + vcpus_overlap_no_resctrl =3D true; } =20 - if (mons_same_alloc_vcpus > 1) { + if (vcpus_overlap_no_resctrl || + (default_alloc_monitor && vcpus_overlap_any)) { virReportError(VIR_ERR_INVALID_ARG, "%s", - _("Too many monitors have the same vcpu as allocati= on")); + _("vcpus overlaps in resctrl groups")); return -1; } =20 + if (vcpus_equal_to_resctrl && !default_alloc_monitor) + return 1; + return 0; } =20 @@ -19211,7 +19225,7 @@ virDomainResctrlMonDefParse(virDomainDefPtr def, if (virDomainResctrlParseVcpus(def, nodes[i], &domresmon->vcpus) <= 0) goto cleanup; =20 - rv =3D virDomainResctrlMonValidateVcpus(resctrl, domresmon->vcpus); + rv =3D virDomainResctrlValidateMonitor(resctrl, domresmon); if (rv < 0) goto cleanup; =20 --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list