From nobody Mon Feb 9 12:11:33 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675354247; cv=none; d=zohomail.com; s=zohoarc; b=nfjJCN1vn+/Un+XKDqazZFvv9xd/yJIP02vINanx88l7IsVBowH3H+jLtFyXl7c5n0P5+uTBxm/6W45Huk2TrPxbF3rcPy+QoY45obQPbXszjPhzWcjf5V+PAEHZsqmkXqz9gQF5SJE1Km8WtQErd9+FfpAwPCOrdOX7/l3OrzE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354247; h=Content-Type:Content-Transfer-Encoding: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; bh=soL9MwnQSCkI/Z8HPOztHQOp5z5naE5O1NVjq4T9M0A=; b=Yl4q7SMb7I+4w3pkEjlX+T3Pnw07XiCnydbEd3CwiAzYxUk9pSMGkIQW7jUsGOPUG46xv3BdoG/eXNIb0Kk4rlFEIoLePk91VDG0YvJm22rEOyi5FSILtNewYude8z/YyPyRypRiuajWtNeR9vgaoWXH5vGkLmuFV+DbZdM9ocg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 167535424782352.64034877759411; Thu, 2 Feb 2023 08:10:47 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-136-Tn2Wvtf0NYijOZJlfRkGHg-1; Thu, 02 Feb 2023 11:10:42 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D607E18E0933; Thu, 2 Feb 2023 16:10:38 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A7722166B33; Thu, 2 Feb 2023 16:10:38 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 4463F194658C; Thu, 2 Feb 2023 16:10:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 4B92D1946586 for ; Thu, 2 Feb 2023 16:10:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 3DF71404BEC1; Thu, 2 Feb 2023 16:10:37 +0000 (UTC) Received: from speedmetal.lan (ovpn-208-29.brq.redhat.com [10.40.208.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id A8292404BEC0 for ; Thu, 2 Feb 2023 16:10:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354246; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=soL9MwnQSCkI/Z8HPOztHQOp5z5naE5O1NVjq4T9M0A=; b=AWNrm1edd3UPgXVvjv0qxnMeoV+JgH5luvPRXdIicKOUMlMtpohDFO6nx2YCLTkDuds0y+ yyAcl5TJprzXrXWm6ZFzkc+3mHf0qErRSc4twaqWdP/JxsCYHD9VahjaetjqxBvXTntJgI yMT+vg/+44MdsYTfF47gIbP9P6jdJsE= X-MC-Unique: Tn2Wvtf0NYijOZJlfRkGHg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/5] qemuMonitorJSONQueryStats: Simplify logic to construct 'provider_list' Date: Thu, 2 Feb 2023 17:10:30 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675354249027100001 Content-Type: text/plain; charset="utf-8" Simplify construction of a single provider by using virJSONValueObjectAdd and restructuring the code. Signed-off-by: Peter Krempa --- src/qemu/qemu_monitor_json.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index db99017555..01e2aaa2cf 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -8828,36 +8828,32 @@ qemuMonitorJSONQueryStats(qemuMonitor *mon, g_autoptr(virJSONValue) reply =3D NULL; g_autoptr(virJSONValue) vcpu_list =3D NULL; g_autoptr(virJSONValue) provider_list =3D NULL; - size_t i; if (providers) { provider_list =3D virJSONValueNewArray(); for (i =3D 0; i < providers->len; i++) { - g_autoptr(virJSONValue) provider_obj =3D virJSONValueNewObject= (); qemuMonitorQueryStatsProvider *provider =3D providers->pdata[i= ]; - const char *type_str =3D qemuMonitorQueryStatsProviderTypeToSt= ring(provider->type); - virBitmap *names =3D provider->names; - - if (virJSONValueObjectAppendString(provider_obj, "provider", t= ype_str) < 0) - return NULL; - - if (!virBitmapIsAllClear(names)) { - g_autoptr(virJSONValue) provider_names =3D virJSONValueNew= Array(); - ssize_t curBit =3D -1; + g_autoptr(virJSONValue) provider_obj =3D NULL; + g_autoptr(virJSONValue) provider_names =3D NULL; + ssize_t curBit =3D -1; - while ((curBit =3D virBitmapNextSetBit(names, curBit)) != =3D -1) { - const char *name =3D qemuMonitorQueryStatsNameTypeToSt= ring(curBit); + while ((curBit =3D virBitmapNextSetBit(provider->names, curBit= )) !=3D -1) { + if (!provider_names) + provider_names =3D virJSONValueNewArray(); - if (virJSONValueArrayAppendString(provider_names, name= ) < 0) - return NULL; - } - - if (virJSONValueObjectAppend(provider_obj, "names", &provi= der_names) < 0) + if (virJSONValueArrayAppendString(provider_names, + qemuMonitorQueryStatsNam= eTypeToString(curBit)) < 0) return NULL; } + if (virJSONValueObjectAdd(&provider_obj, + "s:provider", qemuMonitorQueryStatsP= roviderTypeToString(provider->type), + "A:names", &provider_names, + NULL) < 0) + return NULL; + if (virJSONValueArrayAppend(provider_list, &provider_obj) < 0) return NULL; } --=20 2.39.1