From nobody Sun Feb 8 23:26:43 2026 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=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532534355894699.8521872226801; Wed, 25 Jul 2018 08:59:15 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0FE5D81DFC; Wed, 25 Jul 2018 15:59:13 +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 C5D325D6A8; Wed, 25 Jul 2018 15:59:12 +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 68FB714B0C; Wed, 25 Jul 2018 15:59:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6PFwjMj025871 for ; Wed, 25 Jul 2018 11:58:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id A3B9E7C56; Wed, 25 Jul 2018 15:58:45 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2671C1687E; Wed, 25 Jul 2018 15:58:45 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 25 Jul 2018 17:58:04 +0200 Message-Id: <652fe83a42ad0d1218c7198ad05a87550a3cc9cd.1532533587.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH RFC 33/39] qemu: monitor: Add API to retrieve blockstats by nodenames 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 25 Jul 2018 15:59:15 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add workers that allow collecting the 'blockstats' from qemu by nodename. This will replace the old usage when using -blockdev as query-blockstats does not report anything when using the old approach. Signed-off-by: Peter Krempa --- src/qemu/qemu_monitor.c | 25 ++++++++++++++++ src/qemu/qemu_monitor.h | 6 ++++ src/qemu/qemu_monitor_json.c | 69 ++++++++++++++++++++++++++++++++++++++++= ++++ src/qemu/qemu_monitor_json.h | 4 +++ 4 files changed, 104 insertions(+) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 9d58217376..bc9c7d53b0 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -2300,6 +2300,31 @@ qemuMonitorGetAllBlockStatsInfo(qemuMonitorPtr mon, } +int +qemuMonitorGetBlockStatsInfo(qemuMonitorPtr mon, + virHashTablePtr *ret_stats, + int *nstats) +{ + virHashTablePtr hash =3D NULL; + int ret =3D -1; + + QEMU_CHECK_MONITOR(mon); + + if (!(hash =3D virHashCreate(10, virHashValueFree))) + goto cleanup; + + if (qemuMonitorJSONGetBlockStatsInfo(mon, hash, nstats) < 0) + goto cleanup; + + VIR_STEAL_PTR(*ret_stats, hash); + ret =3D 0; + + cleanup: + virHashFree(hash); + return ret; +} + + /* Updates "stats" to fill virtual and physical size of the image */ int qemuMonitorBlockStatsUpdateCapacity(qemuMonitorPtr mon, diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 3e902e1e8b..8ede11c82c 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -592,6 +592,12 @@ int qemuMonitorGetAllBlockStatsInfo(qemuMonitorPtr mon, bool backingChain) ATTRIBUTE_NONNULL(2); +int +qemuMonitorGetBlockStatsInfo(qemuMonitorPtr mon, + virHashTablePtr *ret_stats, + int *nstats) + ATTRIBUTE_NONNULL(2); + int qemuMonitorBlockStatsUpdateCapacity(qemuMonitorPtr mon, virHashTablePtr stats, bool backingChain) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 6d76f4a2d5..02a3f09a8b 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -2467,6 +2467,75 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr m= on, } +struct qemuMonitorJSONGetBlockstatsInfoArrayWorkerData { + virHashTablePtr hash; + int nstats; +}; + + +static int +qemuMonitorJSONGetBlockStatsInfoArrayWorker(size_t pos ATTRIBUTE_UNUSED, + virJSONValuePtr val, + void *opaque) +{ + struct qemuMonitorJSONGetBlockstatsInfoArrayWorkerData *data =3D opaqu= e; + qemuBlockStatsPtr bstats =3D NULL; + const char *nodename; + int nstats =3D 0; + int ret =3D -1; + + if (!(nodename =3D virJSONValueObjectGetString(val, "node-name"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("missing node name in query-blockstats reply")); + return -1; + } + + if (!(bstats =3D qemuMonitorJSONBlockStatsCollectData(val, &nstats))) + goto cleanup; + + if (nstats > data->nstats) + data->nstats =3D nstats; + + if (virHashAddEntry(data->hash, nodename, bstats) < 0) + goto cleanup; + bstats =3D NULL; + + ret =3D 1; /* we don't want to steal the value from the JSON array */ + + cleanup: + VIR_FREE(bstats); + return ret; +} + + +int +qemuMonitorJSONGetBlockStatsInfo(qemuMonitorPtr mon, + virHashTablePtr hash, + int *nstats) +{ + struct qemuMonitorJSONGetBlockstatsInfoArrayWorkerData data =3D { hash= , 0 }; + virJSONValuePtr devices; + int ret =3D -1; + + if (!(devices =3D qemuMonitorJSONQueryBlockstats(mon, true))) + return -1; + + if (virJSONValueArrayForeachSteal(devices, + qemuMonitorJSONGetBlockStatsInfoArra= yWorker, + &data) < 0) + goto cleanup; + + if (nstats) + *nstats =3D data.nstats; + + ret =3D 0; + + cleanup: + virJSONValueFree(devices); + return ret; +} + + static int qemuMonitorJSONBlockStatsUpdateCapacityData(virJSONValuePtr image, const char *name, diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index 7cdec6e231..6042f7161f 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -95,6 +95,10 @@ int qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr m= on, int qemuMonitorJSONBlockStatsUpdateCapacity(qemuMonitorPtr mon, virHashTablePtr stats, bool backingChain); +int qemuMonitorJSONGetBlockStatsInfo(qemuMonitorPtr mon, + virHashTablePtr hash, + int *nstats); + int qemuMonitorJSONBlockResize(qemuMonitorPtr mon, const char *devce, unsigned long long size); --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list