From nobody Mon Feb 9 06:26:34 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1588831118; cv=none; d=zohomail.com; s=zohoarc; b=J5uD5U02GSnLvTUHe68h0OcwEWhP5dAfGozsOq9YZ3na5Ulff64VuNCYjkSCjSFCauGOfS7e0I39Wk+/ryuyrdBKDd71Edh3vtgmm0xLS7RGgYNAmW2mtIxixHP0hbha8NP3/3pkoUYUpCHw2WVo/7SLPRdj4jUVm1CYLQOGB78= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588831118; 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=qQAHmaBcRrACWD9gO89KuSpgKZ/uzT1SsOasXG/7nRs=; b=ZOCKgiYiVbqvmx9I9n193L/0pFfi+SXDIrB4NzYQNu67DefQ8KmdsBtZrs80Sz2k6Y6Y9BV3jqT0fpi3At1inxxNvWGOBmbgeqSd1yPSL0Vi7OrqrCvcYRc1+/Op+oJ12l6/+fOp0Pr+K5UwpjasUFUf5guVrCxStKQiN0NvLb0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1588831118379461.59060626794997; Wed, 6 May 2020 22:58:38 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-267-ORZ0DrROPKO9Rj_Bty9THA-1; Thu, 07 May 2020 01:58:34 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 866C6464; Thu, 7 May 2020 05:58:29 +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 60BA063F61; Thu, 7 May 2020 05:58:29 +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 144E04CAA0; Thu, 7 May 2020 05:58:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0475wDuO015408 for ; Thu, 7 May 2020 01:58:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 020AE5D9DA; Thu, 7 May 2020 05:58:13 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.208.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7217F5D9C5 for ; Thu, 7 May 2020 05:58:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588831116; 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=qQAHmaBcRrACWD9gO89KuSpgKZ/uzT1SsOasXG/7nRs=; b=R9/RsOzd7ahHnUjgpnz9OIuQyeX33EGTDBKyHhYmzQVn75rrS90D+T+i+HwIckcL+IDgcM pa2U+7RhXaTeGBsn3CLl+MrQyOnPT5oq8QPMXRiVt7CZlysg8H9L3Oj+R/uFpF1pAJh2XG RdWcQsT+Q+mKudfwQq2KyDtHHodcOBA= X-MC-Unique: ORZ0DrROPKO9Rj_Bty9THA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 5/8] qemuMonitorGetDeviceProps: Return data in a hash table Date: Thu, 7 May 2020 07:58:00 +0200 Message-Id: <5d4cf574d3b3c4f4796a33fa49f17e8002aa4968.1588830947.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Create a hash table of device property names which also stores the corresponding JSON object so that the detection code can look at the recently added 'default-value' field and possibly others. Signed-off-by: Peter Krempa --- src/qemu/qemu_capabilities.c | 18 ++++++++------ src/qemu/qemu_monitor.c | 11 ++++----- src/qemu/qemu_monitor.h | 5 ++-- src/qemu/qemu_monitor_json.c | 46 +++++++++++++++++++++++++++++------- src/qemu/qemu_monitor_json.h | 7 +++--- 5 files changed, 58 insertions(+), 29 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 42425fabbd..ae1f0853f1 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2580,20 +2580,24 @@ virQEMUCapsProbeQMPDeviceProperties(virQEMUCapsPtr = qemuCaps, for (i =3D 0; i < G_N_ELEMENTS(virQEMUCapsDeviceProps); i++) { virQEMUCapsObjectTypeProps *device =3D virQEMUCapsDeviceProps + i; - VIR_AUTOSTRINGLIST values =3D NULL; - int nvalues; + g_autoptr(virHashTable) qemuprops =3D NULL; + size_t j; if (device->capsCondition >=3D 0 && !virQEMUCapsGet(qemuCaps, device->capsCondition)) continue; - if ((nvalues =3D qemuMonitorGetDeviceProps(mon, device->type, &val= ues)) < 0) + if (!(qemuprops =3D qemuMonitorGetDeviceProps(mon, device->type))) return -1; - virQEMUCapsProcessStringFlags(qemuCaps, - device->nprops, - device->props, - nvalues, values); + for (j =3D 0; j < device->nprops; j++) { + virJSONValuePtr entry =3D virHashLookup(qemuprops, device->pro= ps[j].value); + + if (!entry) + continue; + + virQEMUCapsSet(qemuCaps, device->props[j].flag); + } } return 0; diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 339facfad3..9c853ccb93 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -3764,16 +3764,15 @@ qemuMonitorGetObjectTypes(qemuMonitorPtr mon, } -int +virHashTablePtr qemuMonitorGetDeviceProps(qemuMonitorPtr mon, - const char *device, - char ***props) + const char *device) { - VIR_DEBUG("device=3D%s props=3D%p", device, props); + VIR_DEBUG("device=3D%s", device); - QEMU_CHECK_MONITOR(mon); + QEMU_CHECK_MONITOR_NULL(mon); - return qemuMonitorJSONGetDeviceProps(mon, device, props); + return qemuMonitorJSONGetDeviceProps(mon, device); } diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 68e21dcaee..2e35d94bda 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1203,9 +1203,8 @@ int qemuMonitorGetKVMState(qemuMonitorPtr mon, int qemuMonitorGetObjectTypes(qemuMonitorPtr mon, char ***types); -int qemuMonitorGetDeviceProps(qemuMonitorPtr mon, - const char *device, - char ***props); +virHashTablePtr qemuMonitorGetDeviceProps(qemuMonitorPtr mon, + const char *device); int qemuMonitorGetObjectProps(qemuMonitorPtr mon, const char *object, char ***props); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 9d1db07ccd..505b31a78a 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -6745,28 +6745,56 @@ qemuMonitorJSONParsePropsList(virJSONValuePtr cmd, } -int +static int +qemuMonitorJSONGetDevicePropsWorker(size_t pos G_GNUC_UNUSED, + virJSONValuePtr item, + void *opaque) +{ + const char *name =3D virJSONValueObjectGetString(item, "name"); + virHashTablePtr devices =3D opaque; + + if (!name) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("reply data was missing 'name'")); + return -1; + } + + if (virHashAddEntry(devices, name, item) < 0) + return -1; + + return 0; +} + + +virHashTablePtr qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon, - const char *device, - char ***props) + const char *device) { + g_autoptr(virHashTable) props =3D virHashNew(virJSONValueHashFree); g_autoptr(virJSONValue) cmd =3D NULL; g_autoptr(virJSONValue) reply =3D NULL; - *props =3D NULL; - if (!(cmd =3D qemuMonitorJSONMakeCommand("device-list-properties", "s:typename", device, NULL))) - return -1; + return NULL; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - return -1; + return NULL; + /* return empty hash */ if (qemuMonitorJSONHasError(reply, "DeviceNotFound")) - return 0; + return g_steal_pointer(&props); + + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) + return NULL; + + if (virJSONValueArrayForeachSteal(virJSONValueObjectGetArray(reply, "r= eturn"), + qemuMonitorJSONGetDevicePropsWorker, + props) < 0) + return NULL; - return qemuMonitorJSONParsePropsList(cmd, reply, NULL, props); + return g_steal_pointer(&props); } diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index 05a46b4fe2..d3d46ec2f7 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -487,10 +487,9 @@ int qemuMonitorJSONSetObjectProperty(qemuMonitorPtr mo= n, qemuMonitorJSONObjectPropertyPtr prop) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4); -int qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon, - const char *device, - char ***props) - ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); +virHashTablePtr qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon, + const char *device) + ATTRIBUTE_NONNULL(2); int qemuMonitorJSONGetObjectProps(qemuMonitorPtr mon, const char *object, char ***props) --=20 2.26.2