From nobody Sat May 18 20:15:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1675354251; cv=none; d=zohomail.com; s=zohoarc; b=fDZxRv4pAe1sNYtQQIFrqQxOox0vxLmDSZ2zPWDstgdfIWouP+jvSK5RPKw4grtgK0W8DGiigcTmQFpKf+HMa3t+kzcr+iEOOobF/rlaD570PbRzTwXzGHj6hv1XYQP1UdfyBMJ3PqHjW8EdyJeJAjCL3UYUiScjiYjqYk0f64g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354251; 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=fHQ2EZWXSFAzLEYqs+OKeIQlRhp523arn6IZLc36QCI=; b=aX+EE8pnh49Kuij2ZuVFDgbTU2knacvB4Ae/R36GtQQ3vCAiIYu9FsHRQkZw28DziBkxPNPYrwPIaOlhiHf/RbxYGtQAiG1GlBvoXrBO5SjRUUm6NLNAMgOcLJPNvv8ZGhTUOybinpBYTNaHqARDAAyXda/W2pWbgecNVFVes2k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1675354251463418.30621312899063; Thu, 2 Feb 2023 08:10:51 -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-561-Jr67vhxcPR-Ya5jLkAf3JA-1; Thu, 02 Feb 2023 11:10:44 -0500 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4B6B318E004F; Thu, 2 Feb 2023 16:10:37 +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 345FC492C3E; Thu, 2 Feb 2023 16:10:37 +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 068F3194658C; Thu, 2 Feb 2023 16:10:37 +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 74F5B1946586 for ; Thu, 2 Feb 2023 16:10:36 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 541CF404BEC1; Thu, 2 Feb 2023 16:10:36 +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 C43C7404BEC0 for ; Thu, 2 Feb 2023 16:10:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354250; 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=fHQ2EZWXSFAzLEYqs+OKeIQlRhp523arn6IZLc36QCI=; b=RTRkdMYxp8CMA5yRjVhwJJYU3SqYJ5mr4R8gXk0vZR6pDbSXaf2i8DQMAHmCRNA9sV4xMm DJDP3hjEu6IiYbExwYlxu1polD9pka5pdCf0t4goJYc+u27l3dztNWXMFkXYDZWqD3yL3C +VJQNGQkbYxil6Nz/sU4T22e0KvUtzs= X-MC-Unique: Jr67vhxcPR-Ya5jLkAf3JA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/5] virbitmap: Allow NULL bitmap in functions returning index of a set/clear bit Date: Thu, 2 Feb 2023 17:10:29 +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.10 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: 1675354253069100001 Content-Type: text/plain; charset="utf-8" virBitmapNextSetBit/virBitmapLastSetBit/virBitmapNextClearBit can be used for iteration of a bitmap. Allow NULL bitmap so that iteration of a bitmap can be simplified in certain cases. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/util/virbitmap.c | 9 +++++++++ src/util/virbitmap.h | 9 +++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index 5b9204cbd7..690ac592ba 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -824,6 +824,9 @@ virBitmapNextSetBit(virBitmap *bitmap, size_t nb; unsigned long bits; + if (!bitmap) + return -1; + if (pos < 0) pos =3D -1; @@ -863,6 +866,9 @@ virBitmapLastSetBit(virBitmap *bitmap) ssize_t sz; unsigned long bits; + if (!bitmap) + return -1; + /* If bitmap is empty then there is no set bit */ if (bitmap->map_len =3D=3D 0) return -1; @@ -916,6 +922,9 @@ virBitmapNextClearBit(virBitmap *bitmap, size_t nb; unsigned long bits; + if (!bitmap) + return -1; + if (pos < 0) pos =3D -1; diff --git a/src/util/virbitmap.h b/src/util/virbitmap.h index e2314904b0..9f954f5ee7 100644 --- a/src/util/virbitmap.h +++ b/src/util/virbitmap.h @@ -111,14 +111,11 @@ bool virBitmapIsAllSet(virBitmap *bitmap) bool virBitmapIsAllClear(virBitmap *bitmap) ATTRIBUTE_NONNULL(1); -ssize_t virBitmapNextSetBit(virBitmap *bitmap, ssize_t pos) - ATTRIBUTE_NONNULL(1); +ssize_t virBitmapNextSetBit(virBitmap *bitmap, ssize_t pos); -ssize_t virBitmapLastSetBit(virBitmap *bitmap) - ATTRIBUTE_NONNULL(1); +ssize_t virBitmapLastSetBit(virBitmap *bitmap); -ssize_t virBitmapNextClearBit(virBitmap *bitmap, ssize_t pos) - ATTRIBUTE_NONNULL(1); +ssize_t virBitmapNextClearBit(virBitmap *bitmap, ssize_t pos); size_t virBitmapCountBits(virBitmap *bitmap) ATTRIBUTE_NONNULL(1); --=20 2.39.1 From nobody Sat May 18 20:15:38 2024 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 Reviewed-by: Michal Privoznik --- 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 From nobody Sat May 18 20:15:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1675354253; cv=none; d=zohomail.com; s=zohoarc; b=bCgw/hCT2eBDHpJirix2gzRWyiqqThOJ4tvfkzJiik7DpcPVqb+t9CgRKKB+NeNVJfiHczDB9KePK+No0BYegV23u4ZC+HOMUupbBLSUTL00B0L8P6qUtHm8K0gsA2+GCBBbNqCGVJHs75VHD0kd/jUgoghp93MHHvEEGWoOSz8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354253; 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=LVZQ09YQtCKs3Pigy6IYozRxyM1VgspLHqbgU27beZw=; b=SdwZqUUfumYTHeqRXKBYTZ0pXD5YPSWPzRW7OrCGJyXo8fdhcq5YNjuxjqUnT3HKaF1pSvlJ3NKgw3/2CVPGNB7qiAJNGwf/oQKa+l0AE3KqyQfob4qRkpabEXs5sh6tKqMajejxX6hBDUrN09ND/svPshb4LxyWYomuvdx9HxA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1675354253687593.9400325752783; Thu, 2 Feb 2023 08:10:53 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-161-crO9cFb4Oj-d857N4xoU4A-1; Thu, 02 Feb 2023 11:10:48 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 689AB1C07565; Thu, 2 Feb 2023 16:10:40 +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 51FE5112132D; Thu, 2 Feb 2023 16:10:40 +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 3F62A194658C; Thu, 2 Feb 2023 16:10:40 +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 042191946586 for ; Thu, 2 Feb 2023 16:10:39 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id ECB80404BEC2; Thu, 2 Feb 2023 16:10:38 +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 A705A404BEC0 for ; Thu, 2 Feb 2023 16:10:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354252; 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=LVZQ09YQtCKs3Pigy6IYozRxyM1VgspLHqbgU27beZw=; b=K5uUdY29w4BLQACfvlb4d6JiGWlj8ixozflvbKnl2bCtBCKREvIIHAlz8//gem4V1czO8z RR4c8kWykPqU7PKB+yaHjUbzHLaBnwFaVEsk0PD+e1Q5i0rZjo3LLcDKOw47x6ey2Ecwig 443XZwQYcL4iXZY+QFbyDcv0ynrlqOo= X-MC-Unique: crO9cFb4Oj-d857N4xoU4A-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 3/5] qemu_monitor_json: Replace simplify fetching Array from JSON object Date: Thu, 2 Feb 2023 17:10:31 +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.3 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: 1675354255060100003 Content-Type: text/plain; charset="utf-8" Replace instances of virJSONValueObjectGet + virJSONValueIsArray by virJSONValueObjectGetArray. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_monitor_json.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 01e2aaa2cf..d05ca2932f 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -3634,11 +3634,9 @@ qemuMonitorJSONQueryRxFilterParse(virJSONValue *msg, "in query-rx-filter response")); return -1; } - if ((!(table =3D virJSONValueObjectGet(entry, "unicast-table"))) || - (!virJSONValueIsArray(table))) { + if ((!(table =3D virJSONValueObjectGetArray(entry, "unicast-table"))))= { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Missing or invalid 'unicast-table' array " - "in query-rx-filter response")); + _("Missing or invalid 'unicast-table' array in quer= y-rx-filter response")); return -1; } nTable =3D virJSONValueArraySize(table); @@ -3675,11 +3673,9 @@ qemuMonitorJSONQueryRxFilterParse(virJSONValue *msg, "in query-rx-filter response")); return -1; } - if ((!(table =3D virJSONValueObjectGet(entry, "multicast-table"))) || - (!virJSONValueIsArray(table))) { + if ((!(table =3D virJSONValueObjectGetArray(entry, "multicast-table"))= )) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Missing or invalid 'multicast-table' array " - "in query-rx-filter response")); + _("Missing or invalid 'multicast-table' array in qu= ery-rx-filter response")); return -1; } nTable =3D virJSONValueArraySize(table); @@ -3709,11 +3705,9 @@ qemuMonitorJSONQueryRxFilterParse(virJSONValue *msg, "in query-rx-filter response")); return -1; } - if ((!(table =3D virJSONValueObjectGet(entry, "vlan-table"))) || - (!virJSONValueIsArray(table))) { + if ((!(table =3D virJSONValueObjectGetArray(entry, "vlan-table")))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Missing or invalid 'vlan-table' array " - "in query-rx-filter response")); + _("Missing or invalid 'vlan-table' array in query-r= x-filter response")); return -1; } nTable =3D virJSONValueArraySize(table); @@ -8722,9 +8716,7 @@ qemuMonitorJSONExtractQueryStatsSchema(virJSONValue *= json) if (!virJSONValueIsObject(obj)) continue; - stats =3D virJSONValueObjectGetArray(obj, "stats"); - - if (!virJSONValueIsArray(stats)) + if (!(stats =3D virJSONValueObjectGetArray(obj, "stats"))) continue; target_str =3D virJSONValueObjectGetString(obj, "target"); --=20 2.39.1 From nobody Sat May 18 20:15:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1675354255; cv=none; d=zohomail.com; s=zohoarc; b=fBm1B8gDhrowQQokFiKdlZ/IU5HM8P1LtYf5SkLeIfiFcCdk6MYpzd2LZWpVSVdQYtL1lXirfmhtRkWKMPptNIi40m9UX3vmMkqkHisa/7cS5/Ahg3bbgouqg9ldOUmBqt9oxAsHw3tCI492czufzwj3OYWqWIIVhcVUzhbMFfw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354255; 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=mqE2hLbTLakmb495/r1EBDLxWnOvy3aKV2+sAFQvvOs=; b=J/ejJQdROb9OpOX1biN1x+hGLIl3kYuXlpKDcfFjaZp6JXtwugSHnZsJOEs+uAjBQ7ez4Zf4Q7v8q2kpDRvvJK/s5pvj0yYr9hasCu0M7Bjax6OriSkjKpXIrPZy2aQeGK/3RD3ZPpL8TcRRTbiwUJv+KuFAol/yUDYDCiIzaA0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1675354255603953.9731575110261; Thu, 2 Feb 2023 08:10:55 -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-393--NZDH-VnMNOtDf9Nt4K-Ug-1; Thu, 02 Feb 2023 11:10:52 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A3F37800DAA; Thu, 2 Feb 2023 16:10:42 +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 89260112132C; Thu, 2 Feb 2023 16:10:42 +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 79BBF194658C; Thu, 2 Feb 2023 16:10:42 +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 AD9CD19465A3 for ; Thu, 2 Feb 2023 16:10:40 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 924D4404BEC2; Thu, 2 Feb 2023 16:10:40 +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 AB046404BEC0 for ; Thu, 2 Feb 2023 16:10:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354254; 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=mqE2hLbTLakmb495/r1EBDLxWnOvy3aKV2+sAFQvvOs=; b=NO6kDycRC4NKMpJU3pGQv5Zh8sF8FB1ersKGP1D0Lj6xEgm7jI/aAFzvZSTrHhWsTAOWpO Qo+Awc2xqUqJ5ThzYYeZhUbBHJPIHEsV2DNMP5glQlq5UNw/57kOSybKW5MREaBFCN8JhK X4jFFe90ZpGBdMNMBrN8rKFDtQzxFIo= X-MC-Unique: -NZDH-VnMNOtDf9Nt4K-Ug-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 4/5] qemu: agent: Use virJSONValueObjectGetArray Date: Thu, 2 Feb 2023 17:10:32 +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.3 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: 1675354257056100007 Content-Type: text/plain; charset="utf-8" Replace virJSONValueObjectGet + virJSONValueIsArray by the single API which returns only an array. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_agent.c | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index fa2c0bf915..f20bc4e6a7 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -1789,12 +1789,6 @@ qemuAgentGetFSInfoFillDisks(virJSONValue *jsondisks, size_t ndisks; size_t i; - if (!virJSONValueIsArray(jsondisks)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Malformed guest-get-fsinfo 'disk' data array")); - return -1; - } - ndisks =3D virJSONValueArraySize(jsondisks); if (ndisks) @@ -1846,15 +1840,9 @@ qemuAgentGetFSInfo(qemuAgent *agent, report_unsupported)) < 0) return rc; - if (!(data =3D virJSONValueObjectGet(reply, "return"))) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("guest-get-fsinfo reply was missing return data")= ); - goto cleanup; - } - - if (!virJSONValueIsArray(data)) { + if (!(data =3D virJSONValueObjectGetArray(reply, "return"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Malformed guest-get-fsinfo data array")); + _("guest-get-fsinfo reply was missing or not an arr= ay")); goto cleanup; } @@ -1934,9 +1922,9 @@ qemuAgentGetFSInfo(qemuAgent *agent, info_ret[i]->total_bytes =3D -1; } - if (!(disk =3D virJSONValueObjectGet(entry, "disk"))) { + if (!(disk =3D virJSONValueObjectGetArray(entry, "disk"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("'disk' missing in reply of guest-get-fsinfo"= )); + _("'disk' missing or not an array in reply of g= uest-get-fsinfo")); goto cleanup; } @@ -2067,16 +2055,9 @@ qemuAgentGetInterfaceAddresses(virDomainInterfacePtr= **ifaces_ret, /* as well as IP address which - moreover - * can be presented multiple times */ - ip_addr_arr =3D virJSONValueObjectGet(iface_obj, "ip-addresses"); - if (!ip_addr_arr) + if (!(ip_addr_arr =3D virJSONValueObjectGetArray(iface_obj, "ip-addres= ses"))) return 0; - if (!virJSONValueIsArray(ip_addr_arr)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Malformed ip-addresses array")); - return -1; - } - /* If current iface already exists, continue with the count */ addrs_count =3D iface->naddrs; --=20 2.39.1 From nobody Sat May 18 20:15:38 2024 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=1675354277; cv=none; d=zohomail.com; s=zohoarc; b=gvjz92OOojsFYwAi5Ek7VzUz/9SDynjXK8UX9IreYIeR2uwdR1MbKU7bBn2OpU8hQ4+iS0+P1/oCmbrmmReasCTY10cSuBjBrr4ryy/pBg4LkY7BvqsszkTVWSf8DnAi7Z0+IdJ4wd8XWZ9YUKT9gdH/YujCowu0mhIaRzSiy6E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354277; 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=0xG44Txhfm30AcGOki+QWNay1Rdbos3xcny3fCCAIsU=; b=N9m/CinGARinDM9a6MHqztPAdFhRPgPX/er8wJ7caVrdIF0Lxc7j3j4Rq+XKL4y6v8OUgPMlizKkAzJ/zhPyH7SZQ31LOwgwdAQwp/c2xjYXygRNvEiRkpdrI1BaYvAkwIQbWI+n8diw9RsWreSVsZhLQNT0zYZxZfZADVUYsWM= 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 1675354277280650.8137292789721; Thu, 2 Feb 2023 08:11:17 -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-376-xafStXkRN42W6nTXmP3EzQ-1; Thu, 02 Feb 2023 11:11:10 -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 331711064C07; Thu, 2 Feb 2023 16:10:54 +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 1F0C52166B37; Thu, 2 Feb 2023 16:10:54 +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 78403194658C; Thu, 2 Feb 2023 16:10:43 +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 E68A51946586 for ; Thu, 2 Feb 2023 16:10:41 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id D9554404BEC2; Thu, 2 Feb 2023 16:10:41 +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 154C2404BEC0 for ; Thu, 2 Feb 2023 16:10:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354275; 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=0xG44Txhfm30AcGOki+QWNay1Rdbos3xcny3fCCAIsU=; b=E/rGi/i9UZShXJB5GjVN8bvb8PW1rVTdSIV0klL1/Isvbg4+Sk5xKkGTnsIeJG13gSKWtE 5JPK5qDfLtQMTH2yZejjhiAAKxhLME7LrxBdfQeurWpOq4vFCv/hKYU15pKZVny1DPeqCr NVS9h3IVBHT7EjGNdwApeYrh5S40A+s= X-MC-Unique: xafStXkRN42W6nTXmP3EzQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 5/5] qemuDomainGetStatsVcpu: Refactor cleanup Date: Thu, 2 Feb 2023 17:10:33 +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: 1675354279367100001 Content-Type: text/plain; charset="utf-8" Automatically free 'cpuinfo' and remove the cleanup label and ret variable. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_driver.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f3f64d3411..6154fe9bfe 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -17585,8 +17585,7 @@ qemuDomainGetStatsVcpu(virQEMUDriver *driver G_GNUC= _UNUSED, virDomainVcpuDef *vcpu; qemuDomainVcpuPrivate *vcpupriv; size_t i; - int ret =3D -1; - virVcpuInfoPtr cpuinfo =3D NULL; + g_autofree virVcpuInfoPtr cpuinfo =3D NULL; g_autofree unsigned long long *cpuwait =3D NULL; g_autofree unsigned long long *cpudelay =3D NULL; qemuDomainObjPrivate *priv =3D dom->privateData; @@ -17615,8 +17614,7 @@ qemuDomainGetStatsVcpu(virQEMUDriver *driver G_GNUC= _UNUSED, virDomainDefGetVcpus(dom->def), NULL, 0) < 0) { virResetLastError(); - ret =3D 0; /* it's ok to be silent and go ahead */ - goto cleanup; + return 0; } if (HAVE_JOB(privflags) && qemuDomainRefreshStatsSchema(dom) =3D=3D 0)= { @@ -17634,7 +17632,7 @@ qemuDomainGetStatsVcpu(virQEMUDriver *driver G_GNUC= _UNUSED, if (virTypedParamListAddInt(params, cpuinfo[i].state, "vcpu.%u.state", cpuinfo[i].number) < = 0) - goto cleanup; + return -1; /* stats below are available only if the VM is alive */ if (!virDomainObjIsActive(dom)) @@ -17642,15 +17640,15 @@ qemuDomainGetStatsVcpu(virQEMUDriver *driver G_GN= UC_UNUSED, if (virTypedParamListAddULLong(params, cpuinfo[i].cpuTime, "vcpu.%u.time", cpuinfo[i].number) = < 0) - goto cleanup; + return -1; if (virTypedParamListAddULLong(params, cpuwait[i], "vcpu.%u.wait", cpuinfo[i].number) = < 0) - goto cleanup; + return -1; if (virTypedParamListAddULLong(params, cpudelay[i], "vcpu.%u.delay", cpuinfo[i].number= ) < 0) - goto cleanup; + return -1; /* state below is extracted from the individual vcpu structs */ if (!(vcpu =3D virDomainDefGetVcpu(dom->def, cpuinfo[i].number))) @@ -17663,7 +17661,7 @@ qemuDomainGetStatsVcpu(virQEMUDriver *driver G_GNUC= _UNUSED, vcpupriv->halted =3D=3D VIR_TR= ISTATE_BOOL_YES, "vcpu.%u.halted", cpuinfo[i].number) < 0) - goto cleanup; + return -1; } if (!queried_stats) @@ -17675,11 +17673,7 @@ qemuDomainGetStatsVcpu(virQEMUDriver *driver G_GNU= C_UNUSED, qemuDomainAddStatsFromHashTable(stats, priv->statsSchema, prefix, = params); } - ret =3D 0; - - cleanup: - VIR_FREE(cpuinfo); - return ret; + return 0; } #define QEMU_ADD_NET_PARAM(params, num, name, value) \ --=20 2.39.1