From nobody Mon Feb 9 03:14:06 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 153417614158637.468835734607524; Mon, 13 Aug 2018 09:02:21 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 0AF82307CF20; Mon, 13 Aug 2018 16:02:19 +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 B96B126FCC; Mon, 13 Aug 2018 16:02:18 +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 D240712D9A; Mon, 13 Aug 2018 16:02:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w7DG1FJG001690 for ; Mon, 13 Aug 2018 12:01:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 479612166BA5; Mon, 13 Aug 2018 16:01:15 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id D908E2166BA0 for ; Mon, 13 Aug 2018 16:01:14 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Mon, 13 Aug 2018 18:00:22 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCHv2 48/62] qemu: monitor: Retrieve blockstats also by qdev and node-names 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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Mon, 13 Aug 2018 16:02:20 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" For use with -blockdev we need to be able to retrieve the stats by 'qdev' for the frontend device stats since 'device' will be empty. Note that for non-blockdev case qdev and 'device' with 'drive-' skipped would be the same. Additionally so that we can report the highest written offset we need to also be able to access them by node-name for backing chain purposes. In cases when 'device' is empty it does not make sense to gather them. Allow arranging the stats simultaneously in all the above dimensions. Signed-off-by: Peter Krempa --- src/qemu/qemu_monitor_json.c | 55 ++++++++++++++++++++++++++++++++++++++++= ---- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 3351d405f3..670147ddb6 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -2332,6 +2332,28 @@ qemuMonitorJSONBlockStatsCollectData(virJSONValuePtr= dev, } +static int +qemuMonitorJSONAddOneBlockStatsInfo(qemuBlockStatsPtr bstats, + const char *name, + virHashTablePtr stats) +{ + qemuBlockStatsPtr copy =3D NULL; + + if (VIR_ALLOC(copy) < 0) + return -1; + + if (bstats) + *copy =3D *bstats; + + if (virHashAddEntry(stats, name, copy) < 0) { + VIR_FREE(copy); + return -1; + } + + return 0; +} + + static int qemuMonitorJSONGetOneBlockStatsInfo(virJSONValuePtr dev, const char *dev_name, @@ -2342,18 +2364,38 @@ qemuMonitorJSONGetOneBlockStatsInfo(virJSONValuePtr= dev, qemuBlockStatsPtr bstats =3D NULL; int ret =3D -1; int nstats =3D 0; - char *entry_name =3D qemuDomainStorageAlias(dev_name, depth); + const char *qdevname =3D NULL; + const char *nodename =3D NULL; + char *devicename =3D NULL; virJSONValuePtr backing; - if (!entry_name) + if (dev_name && + !(devicename =3D qemuDomainStorageAlias(dev_name, depth))) goto cleanup; + qdevname =3D virJSONValueObjectGetString(dev, "qdev"); + nodename =3D virJSONValueObjectGetString(dev, "node-name"); + + if (!devicename && !qdevname && !nodename) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("blockstats device entry was not in expected form= at")); + goto cleanup; + } + if (!(bstats =3D qemuMonitorJSONBlockStatsCollectData(dev, &nstats))) goto cleanup; - if (virHashAddEntry(hash, entry_name, bstats) < 0) + if (devicename && + qemuMonitorJSONAddOneBlockStatsInfo(bstats, devicename, hash) < 0) + goto cleanup; + + if (qdevname && STRNEQ_NULLABLE(qdevname, devicename) && + qemuMonitorJSONAddOneBlockStatsInfo(bstats, qdevname, hash) < 0) + goto cleanup; + + if (nodename && + qemuMonitorJSONAddOneBlockStatsInfo(bstats, nodename, hash) < 0) goto cleanup; - bstats =3D NULL; if (backingChain && (backing =3D virJSONValueObjectGetObject(dev, "backing")) && @@ -2364,7 +2406,7 @@ qemuMonitorJSONGetOneBlockStatsInfo(virJSONValuePtr d= ev, ret =3D nstats; cleanup: VIR_FREE(bstats); - VIR_FREE(entry_name); + VIR_FREE(devicename); return ret; } @@ -2426,6 +2468,9 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mo= n, goto cleanup; } + if (*dev_name =3D=3D '\0') + dev_name =3D NULL; + rc =3D qemuMonitorJSONGetOneBlockStatsInfo(dev, dev_name, 0, hash, backingChain); --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list