From nobody Sun Feb 8 21:48: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 1533651848296191.22275233978644; Tue, 7 Aug 2018 07:24:08 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 35B763081D8F; Tue, 7 Aug 2018 14:24: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 E95255C20D; Tue, 7 Aug 2018 14:24: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 963C312DE5; Tue, 7 Aug 2018 14:24:04 +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 w77ENHTM010443 for ; Tue, 7 Aug 2018 10:23:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id AD7482166BA2; Tue, 7 Aug 2018 14:23:17 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4B6152166BA0 for ; Tue, 7 Aug 2018 14:23:17 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 7 Aug 2018 16:22:32 +0200 Message-Id: <9588d7ee74a74fc3a304372a03586bd09111ee7a.1533651617.git.pkrempa@redhat.com> 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] [PATCH 41/55] 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.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Tue, 07 Aug 2018 14:24:06 +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 NULL. 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 105f6f78ac..24e3d61699 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -2324,6 +2324,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, @@ -2334,18 +2356,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 && + 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")) && @@ -2356,7 +2398,7 @@ qemuMonitorJSONGetOneBlockStatsInfo(virJSONValuePtr d= ev, ret =3D nstats; cleanup: VIR_FREE(bstats); - VIR_FREE(entry_name); + VIR_FREE(devicename); return ret; } @@ -2418,6 +2460,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