From nobody Wed Apr 24 10:11:36 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=1637842815; cv=none; d=zohomail.com; s=zohoarc; b=j2igr7c1z+1TWf42Zaqo8DhwY/X75sztHjhthwkTDwyCRHhlFlVU2dwW/AzOuWG9aHrV+vbL12LJD1Au8zpT1AOhhu0hAklQNbQZHELBOumnYLV0DwHhIXMwB2fz1l0mXLz8hbAmZ0wxvY7ukWdfpbx9viwYdjZhoX8z4W9KaaM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637842815; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=mat6V1zBqTY6lm3s+yxhbNpmjHg+ERtT/5c5CyqU4x0=; b=cjeAgpMUVulv0pmgpoG9vCYI7IE1q/Pd0WSTfDnhB8LQDlfP+qa8JEWlL/IheRz9qgNCKB29B4fDFEnC7CCzaSUAS0+8XEOGJxmZ/MBWDLxVhcP1QzYO7dLRgCgYUOpAl+aOYwgy8wbLOc6jNyjwCO6QwIMMXwziz5FwOxzMXs8= 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 163784281569417.04371520752568; Thu, 25 Nov 2021 04:20:15 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-96-HxdW8PGEMlKVqpu3SNEeIQ-1; Thu, 25 Nov 2021 07:20:11 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B4F5A36393; Thu, 25 Nov 2021 12:20:05 +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 A0763196E6; Thu, 25 Nov 2021 12:20:04 +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 186324BB7C; Thu, 25 Nov 2021 12:20:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1APCJxbK027756 for ; Thu, 25 Nov 2021 07:19:59 -0500 Received: by smtp.corp.redhat.com (Postfix) id D979110114AE; Thu, 25 Nov 2021 12:19:59 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 30AB0100AE22 for ; Thu, 25 Nov 2021 12:19:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637842814; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=mat6V1zBqTY6lm3s+yxhbNpmjHg+ERtT/5c5CyqU4x0=; b=aA8oNwYFY7wdl68l1KE8LKmW3eQSBsThQwzt0iPVa+MIDDBs55+SzwYUBQj9LTx6eWaPp/ xQGUzGl5yd5MeU4iLxPEhSO6lO20EaiMQGI5eLS6nIwbHoDlqAsITIMs3NBPLOueiLFgxc LpaP/J2S1aOJ/Mj6zgyW+we4nZwt6A4= X-MC-Unique: HxdW8PGEMlKVqpu3SNEeIQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH for 7.10] qemu: monitor: Fix usage of 'query-blockstats' Date: Thu, 25 Nov 2021 13:19:57 +0100 Message-Id: <0f4b6516c9d7821fb1b755de41c0bfc99d9b0b05.1637842731.git.pkrempa@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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: 1637842817360100001 Content-Type: text/plain; charset="utf-8" Commit bc24810c2cab modified code querying blockstats to use the 'query-nodes' parameter so that we can fetch stats also for images which are not attached to a frontend such as block copy and backup scratch images. Unfortunately that broke the old blockstats because if 'query-nodes' is enabled qemu doesn't output the 'qdev' parameter which our code used for matching to the disk and also qemu neglects to populate the frontend stats at all so we can't even switch to using nodenema for matching. To fix this we need to do two calls, one with 'query-nodes' disabled using the old logic to populate everything and then an aditional one which populates all the remaining images. Closes: https://gitlab.com/libvirt/libvirt/-/issues/246 Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko Tested-by: Erik Skultety --- src/qemu/qemu_monitor_json.c | 52 +++++++++++++++++++++++++++++++++--- tests/qemumonitorjsontest.c | 2 ++ 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 3030cff664..56f0b22b2a 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -2446,6 +2446,30 @@ qemuMonitorJSONGetOneBlockStatsInfo(virJSONValue *de= v, } +static int +qemuMonitorJSONGetOneBlockStatsNodeInfo(virJSONValue *dev, + GHashTable *hash) +{ + qemuBlockStats *bstats =3D NULL; + int nstats =3D 0; + const char *nodename =3D NULL; + + if (!(nodename =3D virJSONValueObjectGetString(dev, "node-name"))) + return 0; + + /* we already have the stats */ + if (g_hash_table_contains(hash, nodename)) + return 0; + + if (!(bstats =3D qemuMonitorJSONBlockStatsCollectData(dev, &nstats))) + return -1; + + g_hash_table_insert(hash, g_strdup(nodename), bstats); + + return nstats; +} + + virJSONValue * qemuMonitorJSONQueryBlockstats(qemuMonitor *mon, bool queryNodes) @@ -2475,13 +2499,14 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitor *mo= n, int nstats =3D 0; int rc; size_t i; - g_autoptr(virJSONValue) devices =3D NULL; + g_autoptr(virJSONValue) blockstatsDevices =3D NULL; + g_autoptr(virJSONValue) blockstatsNodes =3D NULL; - if (!(devices =3D qemuMonitorJSONQueryBlockstats(mon, true))) + if (!(blockstatsDevices =3D qemuMonitorJSONQueryBlockstats(mon, false)= )) return -1; - for (i =3D 0; i < virJSONValueArraySize(devices); i++) { - virJSONValue *dev =3D virJSONValueArrayGet(devices, i); + for (i =3D 0; i < virJSONValueArraySize(blockstatsDevices); i++) { + virJSONValue *dev =3D virJSONValueArrayGet(blockstatsDevices, i); const char *dev_name; if (!dev || virJSONValueGetType(dev) !=3D VIR_JSON_TYPE_OBJECT) { @@ -2505,6 +2530,25 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitor *mon, nstats =3D rc; } + if (!(blockstatsNodes =3D qemuMonitorJSONQueryBlockstats(mon, true))) + return -1; + + for (i =3D 0; i < virJSONValueArraySize(blockstatsNodes); i++) { + virJSONValue *dev =3D virJSONValueArrayGet(blockstatsNodes, i); + + if (!dev || virJSONValueGetType(dev) !=3D VIR_JSON_TYPE_OBJECT) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("blockstats device entry was not in expected = format")); + return -1; + } + + if ((rc =3D qemuMonitorJSONGetOneBlockStatsNodeInfo(dev, hash)) < = 0) + return -1; + + if (rc > nstats) + nstats =3D rc; + } + return nstats; } diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 0de523007b..bcf5caa9a4 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1615,6 +1615,8 @@ testQemuMonitorJSONqemuMonitorJSONGetAllBlockStatsInf= o(const void *opaque) if (qemuMonitorTestAddItem(test, "query-blockstats", reply) < 0) return -1; + if (qemuMonitorTestAddItem(test, "query-blockstats", reply) < 0) + return -1; #define CHECK0FULL(var, value, varformat, valformat) \ if (stats->var !=3D value) { \ --=20 2.31.1