From nobody Tue May 13 18:59:25 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532921763500683.5135433849796; Sun, 29 Jul 2018 20:36:03 -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 496D381DF7; Mon, 30 Jul 2018 03:36: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 02BF9308BDB2; Mon, 30 Jul 2018 03:36:01 +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 59A863F7FE; Mon, 30 Jul 2018 03:36:00 +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 w6U3ZTMM002770 for ; Sun, 29 Jul 2018 23:35:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7FC876E721; Mon, 30 Jul 2018 03:35:29 +0000 (UTC) Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DCB886EE26 for ; Mon, 30 Jul 2018 03:35:28 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (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 5A1DF1555C for ; Mon, 30 Jul 2018 03:35:27 +0000 (UTC) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jul 2018 20:35:27 -0700 Received: from bing-i9.bj.intel.com ([172.16.182.85]) by fmsmga004.fm.intel.com with ESMTP; 29 Jul 2018 20:35:25 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,421,1526367600"; d="scan'208";a="75613705" From: bing.niu@intel.com To: libvir-list@redhat.com Date: Mon, 30 Jul 2018 11:12:27 +0800 Message-Id: <1532920361-24737-4-git-send-email-bing.niu@intel.com> In-Reply-To: <1532920361-24737-1-git-send-email-bing.niu@intel.com> References: <1532920361-24737-1-git-send-email-bing.niu@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 209 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 30 Jul 2018 03:35:27 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 30 Jul 2018 03:35:27 +0000 (UTC) for IP:'192.55.52.151' DOMAIN:'mga17.intel.com' HELO:'mga17.intel.com' FROM:'bing.niu@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 192.55.52.151 mga17.intel.com 192.55.52.151 mga17.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: shaohe.feng@intel.com, huaqiang.wang@intel.com, Bing Niu , jian-feng.ding@intel.com, rui.zang@yandex.com Subject: [libvirt] [PATCH v2 RESEND 03/17] util: Refactor virResctrlAllocFormat 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.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.25]); Mon, 30 Jul 2018 03:36:02 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Bing Niu Refactor virResctrlAllocFormat so that it is easy to support other resource allocation technologies. Signed-off-by: Bing Niu Reviewed-by: John Ferlan --- src/util/virresctrl.c | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 313f964..a38c926 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -849,17 +849,14 @@ virResctrlAllocGetID(virResctrlAllocPtr alloc) } =20 =20 -char * -virResctrlAllocFormat(virResctrlAllocPtr alloc) +static int +virResctrlAllocFormatCache(virResctrlAllocPtr alloc, + virBufferPtr buf) { - virBuffer buf =3D VIR_BUFFER_INITIALIZER; unsigned int level =3D 0; unsigned int type =3D 0; unsigned int cache =3D 0; =20 - if (!alloc) - return NULL; - for (level =3D 0; level < alloc->nlevels; level++) { virResctrlAllocPerLevelPtr a_level =3D alloc->levels[level]; =20 @@ -872,7 +869,7 @@ virResctrlAllocFormat(virResctrlAllocPtr alloc) if (!a_type) continue; =20 - virBufferAsprintf(&buf, "L%u%s:", level, virResctrlTypeToStrin= g(type)); + virBufferAsprintf(buf, "L%u%s:", level, virResctrlTypeToString= (type)); =20 for (cache =3D 0; cache < a_type->nmasks; cache++) { virBitmapPtr mask =3D a_type->masks[cache]; @@ -882,21 +879,35 @@ virResctrlAllocFormat(virResctrlAllocPtr alloc) continue; =20 mask_str =3D virBitmapToString(mask, false, true); - if (!mask_str) { - virBufferFreeAndReset(&buf); - return NULL; - } + if (!mask_str) + return -1; =20 - virBufferAsprintf(&buf, "%u=3D%s;", cache, mask_str); + virBufferAsprintf(buf, "%u=3D%s;", cache, mask_str); VIR_FREE(mask_str); } =20 - virBufferTrim(&buf, ";", 1); - virBufferAddChar(&buf, '\n'); + virBufferTrim(buf, ";", 1); + virBufferAddChar(buf, '\n'); } } =20 - virBufferCheckError(&buf); + return virBufferCheckError(buf); +} + + +char * +virResctrlAllocFormat(virResctrlAllocPtr alloc) +{ + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + + if (!alloc) + return NULL; + + if (virResctrlAllocFormatCache(alloc, &buf) < 0) { + virBufferFreeAndReset(&buf); + return NULL; + } + return virBufferContentAndReset(&buf); } =20 --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list