From nobody Sun Feb 8 07:01:26 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 172664638076482.6106337376093; Wed, 18 Sep 2024 00:59:40 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id CDFE81B47; Wed, 18 Sep 2024 03:59:39 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id E5C101980; Wed, 18 Sep 2024 03:55:48 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E657B1AC6; Wed, 18 Sep 2024 03:55:44 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 0ACC01A61 for ; Wed, 18 Sep 2024 03:55:34 -0400 (EDT) Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-152-GsFk3uAKMXeaqHhkpD1xvg-1; Wed, 18 Sep 2024 03:55:32 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 85A721956096 for ; Wed, 18 Sep 2024 07:55:31 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.5]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 972B819560A3 for ; Wed, 18 Sep 2024 07:55:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726646133; h=from:from: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; bh=7CmuX971tf4jIRhmktw0E7AtJQTSCIESfMiu0orfmIk=; b=AK39S1OxL8S+Vv2MQRxdDibD65x7JB6eSwguRc3uaQJ6jV3NuD3S0TuNVquZGrWT47Wmi/ DhZ/VbTZcqbw+GWIlq4clroJS+TyFv1pCWvAmN8Rh6Y9RHQ+WvdD6lHCDiwkgK7epfBmI9 ZAONg6rLIPugnBQDxguG6ojidX3y17k= X-MC-Unique: GsFk3uAKMXeaqHhkpD1xvg-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 7/8] qemu: Use the new chardev backend JSON props generator also in the monitor Date: Wed, 18 Sep 2024 09:55:17 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: IWQZK64APE6JWJUH4TZVOS6PAFXGNQU6 X-Message-ID-Hash: IWQZK64APE6JWJUH4TZVOS6PAFXGNQU6 X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1726646381250116600 Content-Type: text/plain; charset="utf-8" Now that we have a unified generator of chardev backend which is also validated against the QMP schema we can replace the old generator with it. This patch modifies the monitor code to take virJSONValue 'props' instead of the chardev definition and adds the conversion from the chardev definition to JSON on higher levels. The monitor code now also attempts to extract the returned 'pty' if returned from qemu, so higher level code needs to report the error if the path is needed and missing. The current monitor generator is for now abandoned in place and will be removed later. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_block.c | 9 ++++++++- src/qemu/qemu_hotplug.c | 22 +++++++++++++++++++++- src/qemu/qemu_monitor.c | 8 +++----- src/qemu/qemu_monitor.h | 4 ++-- src/qemu/qemu_monitor_json.c | 32 ++++++++++---------------------- src/qemu/qemu_monitor_json.h | 4 ++-- tests/qemumonitorjsontest.c | 17 +++++++++++------ 7 files changed, 57 insertions(+), 39 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 6e90bae9f2..9bdec92697 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -24,6 +24,7 @@ #include "qemu_alias.h" #include "qemu_security.h" #include "qemu_process.h" +#include "qemu_chardev.h" #include "storage_source.h" #include "viralloc.h" @@ -1682,7 +1683,13 @@ qemuBlockStorageSourceAttachApply(qemuMonitor *mon, return -1; if (data->chardevDef) { - if (qemuMonitorAttachCharDev(mon, data->chardevAlias, data->charde= vDef) < 0) + g_autoptr(virJSONValue) props =3D NULL; + + if (qemuChardevGetBackendProps(data->chardevDef, false, + data->chardevAlias, NULL, &props) <= 0) + return -1; + + if (qemuMonitorAttachCharDev(mon, &props, NULL) < 0) return -1; data->chardevAdded =3D true; diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index a58c1446e9..c1070d2562 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -37,6 +37,7 @@ #include "qemu_block.h" #include "qemu_snapshot.h" #include "qemu_virtiofs.h" +#include "qemu_chardev.h" #include "domain_audit.h" #include "domain_cgroup.h" #include "domain_interface.h" @@ -243,6 +244,9 @@ qemuHotplugChardevAttach(qemuMonitor *mon, const char *alias, virDomainChrSourceDef *def) { + g_autoptr(virJSONValue) props =3D NULL; + g_autofree char *ptypath =3D NULL; + switch ((virDomainChrType) def->type) { case VIR_DOMAIN_CHR_TYPE_NULL: case VIR_DOMAIN_CHR_TYPE_VC: @@ -272,7 +276,23 @@ qemuHotplugChardevAttach(qemuMonitor *mon, return -1; } - return qemuMonitorAttachCharDev(mon, alias, def); + if (qemuChardevGetBackendProps(def, false, alias, NULL, &props) < 0) + return -1; + + if (qemuMonitorAttachCharDev(mon, &props, &ptypath) < 0) + return -1; + + if (def->type =3D=3D VIR_DOMAIN_CHR_TYPE_PTY) { + if (!ptypath) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("chardev-add reply was missing pty path")); + return -1; + } + + def->data.file.path =3D g_steal_pointer(&ptypath); + } + + return 0; } diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 7f65c23748..ada3de474f 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -3523,14 +3523,12 @@ qemuMonitorGetTPMTypes(qemuMonitor *mon, int qemuMonitorAttachCharDev(qemuMonitor *mon, - const char *chrID, - virDomainChrSourceDef *chr) + virJSONValue **props, + char **ptypath) { - VIR_DEBUG("chrID=3D%s chr=3D%p", chrID, chr); - QEMU_CHECK_MONITOR(mon); - return qemuMonitorJSONAttachCharDev(mon, chrID, chr); + return qemuMonitorJSONAttachCharDev(mon, props, ptypath); } diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 57d1b45bf5..2bb64dd53f 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1212,8 +1212,8 @@ int qemuMonitorGetTPMTypes(qemuMonitor *mon, char ***tpmtypes); int qemuMonitorAttachCharDev(qemuMonitor *mon, - const char *chrID, - virDomainChrSourceDef *chr); + virJSONValue **props, + char **ptypath); int qemuMonitorDetachCharDev(qemuMonitor *mon, const char *chrID); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 2db38c1007..f3a353a13b 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -6342,7 +6342,7 @@ int qemuMonitorJSONGetTPMTypes(qemuMonitor *mon, } -static virJSONValue * +static G_GNUC_UNUSED virJSONValue * qemuMonitorJSONAttachCharDevGetProps(const char *chrID, const virDomainChrSourceDef *chr) { @@ -6571,41 +6571,29 @@ qemuMonitorJSONAttachCharDevGetProps(const char *ch= rID, int qemuMonitorJSONAttachCharDev(qemuMonitor *mon, - const char *chrID, - virDomainChrSourceDef *chr) + virJSONValue **props, + char **ptypath) { g_autoptr(virJSONValue) cmd =3D NULL; g_autoptr(virJSONValue) reply =3D NULL; - g_autoptr(virJSONValue) props =3D NULL; - - if (!(props =3D qemuMonitorJSONAttachCharDevGetProps(chrID, chr))) - return -1; + virJSONValue *data; - if (!(cmd =3D qemuMonitorJSONMakeCommandInternal("chardev-add", &props= ))) + if (!(cmd =3D qemuMonitorJSONMakeCommandInternal("chardev-add", props)= )) return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) return -1; - if (chr->type =3D=3D VIR_DOMAIN_CHR_TYPE_PTY) { - virJSONValue *data; - - if (!(data =3D qemuMonitorJSONGetReply(cmd, reply, VIR_JSON_TYPE_O= BJECT))) - return -1; + if (!(data =3D qemuMonitorJSONGetReply(cmd, reply, VIR_JSON_TYPE_OBJEC= T))) + return -1; - if (!(chr->data.file.path =3D g_strdup(virJSONValueObjectGetString= (data, "pty")))) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("chardev-add reply was missing pty path")); - return -1; - } - } else { - if (qemuMonitorJSONCheckError(cmd, reply) < 0) - return -1; - } + if (ptypath) + *ptypath =3D g_strdup(virJSONValueObjectGetString(data, "pty")); return 0; } + int qemuMonitorJSONDetachCharDev(qemuMonitor *mon, const char *chrID) diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index 921dd34ed2..fef81fd911 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -584,8 +584,8 @@ qemuMonitorJSONGetTPMTypes(qemuMonitor *mon, int qemuMonitorJSONAttachCharDev(qemuMonitor *mon, - const char *chrID, - virDomainChrSourceDef *chr); + virJSONValue **props, + char **ptypath); int qemuMonitorJSONDetachCharDev(qemuMonitor *mon, const char *chrID); diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 2249787ba7..ab2c445289 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -28,6 +28,7 @@ #include "qemu/qemu_monitor_json.h" #include "qemu/qemu_qapi.h" #include "qemu/qemu_alias.h" +#include "qemu/qemu_chardev.h" #include "virerror.h" #include "cpu/cpu.h" #include "qemu/qemu_monitor.h" @@ -553,6 +554,8 @@ testQemuMonitorJSONAttachChardev(const void *opaque) { const struct qemuMonitorJSONTestAttachChardevData *data =3D opaque; g_autoptr(qemuMonitorTest) test =3D qemuMonitorTestNewSchema(data->xml= opt, data->schema); + g_autoptr(virJSONValue) props =3D NULL; + g_autofree char *ptypath =3D NULL; int rc; if (!test) @@ -575,20 +578,20 @@ testQemuMonitorJSONAttachChardev(const void *opaque) return -1; } - if ((rc =3D qemuMonitorAttachCharDev(qemuMonitorTestGetMonitor(test), - "alias", data->chr)) < 0) + if (qemuChardevGetBackendProps(data->chr, false, "alias", NULL, &props= ) < 0) + return -1; + + if ((rc =3D qemuMonitorAttachCharDev(qemuMonitorTestGetMonitor(test), = &props, &ptypath)) < 0) goto cleanup; if (data->chr->type =3D=3D VIR_DOMAIN_CHR_TYPE_PTY) { - if (STRNEQ_NULLABLE(data->expectPty, data->chr->data.file.path)) { + if (STRNEQ_NULLABLE(data->expectPty, ptypath)) { virReportError(VIR_ERR_INTERNAL_ERROR, "expected PTY path: %s got: %s", NULLSTR(data->expectPty), NULLSTR(data->chr->data.file.path)); rc =3D -1; } - - VIR_FREE(data->chr->data.file.path); } cleanup: @@ -653,7 +656,9 @@ qemuMonitorJSONTestAttachChardev(virDomainXMLOption *xm= lopt, "'data':{'type':'vdagent'}}}"); chr->type =3D VIR_DOMAIN_CHR_TYPE_PTY; - CHECK("pty missing path", true, + /* Higher level code regards the missing path as error, but we sim= ply + * check here what we've parsed */ + CHECK("pty missing path", false, "{'id':'alias','backend':{'type':'pty','data':{}}}"); if (qemuMonitorJSONTestAttachOneChardev(xmlopt, schema, "pty", chr, "{'id':'alias'," --=20 2.46.0