From nobody Tue May 14 05:47:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 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=1645432895; cv=none; d=zohomail.com; s=zohoarc; b=MSdoBCX58ojjsb8aN3TXNB72PURykNSo2IQoAoUnCwcIJ3xSTriqVA9QCgRLcn0WLlUAMwNCDx43Ru8Ihnb8yYNCnmTKd7slV3nfavMRnzfTGjHQVvmJ/W7w7HtRKXKd9J6HF30vP7o3V3v2bA0+kb0gD52C/uJudBAGcVTM47s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645432895; 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=SJj2HbH5okrDYWVHfZQR9dBI2UbRBslTy+xLBvjPAvk=; b=MQrTOI3EB+BasCgr3/J02g/iPqBx/3djLFToeziLbJ8PwgQhtKiOQlsioCA5YGKbixo9BS4pStR1ezkURfaI0jiTNs7+0UmjVgTF7YyWyHF934pgBNewRKCx7PwOi3JMuSnY5bcSOwT92v1OaDjiEDfChsMFdkldJrYH/uulDfc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1645432895381664.0928243365761; Mon, 21 Feb 2022 00:41:35 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-56-X8nWykyUPN6th7uoRAwp4Q-1; Mon, 21 Feb 2022 03:41:32 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4F244814249; Mon, 21 Feb 2022 08:41:27 +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 0153655797; Mon, 21 Feb 2022 08:41:27 +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 575A64BB7C; Mon, 21 Feb 2022 08:41:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21L8fMYC022001 for ; Mon, 21 Feb 2022 03:41:22 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5F22D7B6D8; Mon, 21 Feb 2022 08:41:22 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id B8E1A7B6E0 for ; Mon, 21 Feb 2022 08:41:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1645432895; 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=SJj2HbH5okrDYWVHfZQR9dBI2UbRBslTy+xLBvjPAvk=; b=QEOj8tp35XBZy8zkUJdDubU9r5HoX8ZR0lvLWJX2FD+xWXfKKw/KzFdxE44TMF8HkNcsBQ i77npfe/b9cCJbbEMd8+ifK8IBomqWbT5RjfNr0gihlYHe/WOl/S7HdjJIC3RPgrAveqcO 6X9Bz7JFBRWV9/Mc9vkfIprze/UIQGw= X-MC-Unique: X8nWykyUPN6th7uoRAwp4Q-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v2 1/4] virnetmessage: Introduce virNetMessageClearFDs Date: Mon, 21 Feb 2022 09:41:06 +0100 Message-Id: <178a053f2b52afc0231ed75184570f9bf42d535f.1645432719.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1645432908649100001 Content-Type: text/plain; charset="utf-8" The helper splits out the clearing of the FDs transacted inside a virNetMessage. APIs transacting FDs both from and to the client at the same time will need to clear the FDs stored in virNetMessage as the structure is re-used for the reply and without clearing the list of FDs we'd return the FDs sent by the client in addition to the new FDs sent by the API.t Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/libvirt_remote.syms | 1 + src/rpc/virnetmessage.c | 9 ++++++++- src/rpc/virnetmessage.h | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/libvirt_remote.syms b/src/libvirt_remote.syms index 2fa46e5e0c..f0f90815cf 100644 --- a/src/libvirt_remote.syms +++ b/src/libvirt_remote.syms @@ -102,6 +102,7 @@ virNetDaemonUpdateServices; # rpc/virnetmessage.h virNetMessageAddFD; virNetMessageClear; +virNetMessageClearFDs; virNetMessageClearPayload; virNetMessageDecodeHeader; virNetMessageDecodeLength; diff --git a/src/rpc/virnetmessage.c b/src/rpc/virnetmessage.c index ca11f1688e..221da7c59b 100644 --- a/src/rpc/virnetmessage.c +++ b/src/rpc/virnetmessage.c @@ -48,7 +48,7 @@ virNetMessage *virNetMessageNew(bool tracked) void -virNetMessageClearPayload(virNetMessage *msg) +virNetMessageClearFDs(virNetMessage *msg) { size_t i; @@ -58,6 +58,13 @@ virNetMessageClearPayload(virNetMessage *msg) msg->donefds =3D 0; msg->nfds =3D 0; VIR_FREE(msg->fds); +} + + +void +virNetMessageClearPayload(virNetMessage *msg) +{ + virNetMessageClearFDs(msg); msg->bufferOffset =3D 0; msg->bufferLength =3D 0; diff --git a/src/rpc/virnetmessage.h b/src/rpc/virnetmessage.h index aadf1b69b0..8f878962f8 100644 --- a/src/rpc/virnetmessage.h +++ b/src/rpc/virnetmessage.h @@ -49,6 +49,7 @@ struct _virNetMessage { virNetMessage *virNetMessageNew(bool tracked); +void virNetMessageClearFDs(virNetMessage *msg); void virNetMessageClearPayload(virNetMessage *msg); void virNetMessageClear(virNetMessage *); --=20 2.35.1 From nobody Tue May 14 05:47:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 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=1645432914; cv=none; d=zohomail.com; s=zohoarc; b=WRQiLlnExcAYq5qNH3xPkK6EC4ti0UxHi20/vG1R7gYM5KfwaRNBID1afrpyl1sU5a2qPIa+3UXsxIfbtDw0NixOLF4z1Pih1cLOKCp3bOCFhjkr1nwXMHTG6xgNRrUyXieMckxiKw+M5TK2Bh4oFwpkyheG/EmoiYHheDM7i4Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645432914; 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=QvUOnec8FPNwK3jmjE3mokg2iJeC6Geqp6Ke/YGvPr4=; b=TNGiF7JE1XarbfGUBxinJdAUJaUlMS4RjYE1rmrmzDNOx8uH+PCk++X5mjbLucdNuzOxhIInHj8zVXO/+dLLpn4S35khpylTZ6EiCe5sgIL78S3KQ/aLvqWCmzaVJn7gs+egWYTlhyKOaeneNjezNfCDmS07lwTkeEG8tMkSmPE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 16454329140811002.9580827053137; Mon, 21 Feb 2022 00:41:54 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-32-pxXfjQNZPQyG9aGaNCJeSQ-1; Mon, 21 Feb 2022 03:41:49 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 89C2818397BE; Mon, 21 Feb 2022 08:41:44 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 68F36105C88A; Mon, 21 Feb 2022 08:41:44 +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 357B9180BAAE; Mon, 21 Feb 2022 08:41:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21L8fNYU022008 for ; Mon, 21 Feb 2022 03:41:23 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7BDCA7B6DA; Mon, 21 Feb 2022 08:41:23 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id BEDE17B6D8 for ; Mon, 21 Feb 2022 08:41:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1645432912; 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=QvUOnec8FPNwK3jmjE3mokg2iJeC6Geqp6Ke/YGvPr4=; b=GQ72OeNqvncXd3/BGoj/3R2EvRi06RDSbaqxuTDUSYpk2wT6TZ5ZKQ41b9U/MvJKstK5Al PcyyxnY9Pn29UpvAnQ6IWLfXi/FBAstD5WNkiHR4ocr4CTNvRZaR918bUwGxj1O/QRiL8r C1qI0gbHyDCqiT225sRmikc+8d32TQE= X-MC-Unique: pxXfjQNZPQyG9aGaNCJeSQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v2 2/4] lib: Introduce 'virDomainQemuMonitorCommandWithFiles' Date: Mon, 21 Feb 2022 09:41:07 +0100 Message-Id: <4491146898e1c6dd11ce5eeefd07d7e4e2d29a6c.1645432719.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1645432916452100001 Content-Type: text/plain; charset="utf-8" This API has the same semantics as 'virDomainQemuMonitorCommand' but accepts file descriptors which are then forwarded to qemu. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- include/libvirt/libvirt-qemu.h | 8 +++ src/driver-hypervisor.h | 10 ++++ src/libvirt-qemu.c | 89 +++++++++++++++++++++++++++++ src/libvirt_qemu.syms | 5 ++ src/qemu_protocol-structs | 9 +++ src/remote/qemu_protocol.x | 20 ++++++- src/remote/remote_daemon_dispatch.c | 62 ++++++++++++++++++++ src/remote/remote_driver.c | 57 ++++++++++++++++++ 8 files changed, 259 insertions(+), 1 deletion(-) diff --git a/include/libvirt/libvirt-qemu.h b/include/libvirt/libvirt-qemu.h index 0cc2872821..98f2ac3823 100644 --- a/include/libvirt/libvirt-qemu.h +++ b/include/libvirt/libvirt-qemu.h @@ -37,6 +37,14 @@ typedef enum { int virDomainQemuMonitorCommand(virDomainPtr domain, const char *cmd, char **result, unsigned int flags); +int virDomainQemuMonitorCommandWithFiles(virDomainPtr domain, + const char *cmd, + unsigned int ninfiles, + int *infiles, + unsigned int *noutfiles, + int **outfiles, + char **result, + unsigned int flags); virDomainPtr virDomainQemuAttach(virConnectPtr domain, unsigned int pid_value, diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h index c83fb648a2..4423eb0885 100644 --- a/src/driver-hypervisor.h +++ b/src/driver-hypervisor.h @@ -874,6 +874,15 @@ typedef int const char *cmd, char **result, unsigned int flags); +typedef int +(*virDrvDomainQemuMonitorCommandWithFiles)(virDomainPtr domain, + const char *cmd, + unsigned int ninfiles, + int *infiles, + unsigned int *noutfiles, + int **outfiles, + char **result, + unsigned int flags); typedef char * (*virDrvDomainQemuAgentCommand)(virDomainPtr domain, @@ -1597,6 +1606,7 @@ struct _virHypervisorDriver { virDrvDomainRevertToSnapshot domainRevertToSnapshot; virDrvDomainSnapshotDelete domainSnapshotDelete; virDrvDomainQemuMonitorCommand domainQemuMonitorCommand; + virDrvDomainQemuMonitorCommandWithFiles domainQemuMonitorCommandWithFi= les; virDrvDomainQemuAttach domainQemuAttach; virDrvDomainQemuAgentCommand domainQemuAgentCommand; virDrvConnectDomainQemuMonitorEventRegister connectDomainQemuMonitorEv= entRegister; diff --git a/src/libvirt-qemu.c b/src/libvirt-qemu.c index 1afb5fe529..9e80577b56 100644 --- a/src/libvirt-qemu.c +++ b/src/libvirt-qemu.c @@ -96,6 +96,95 @@ virDomainQemuMonitorCommand(virDomainPtr domain, const c= har *cmd, } +/** + * virDomainQemuMonitorCommandWithFiles: + * @domain: a domain object + * @cmd: the qemu monitor command string + * @ninfiles: number of filedescriptors passed in @infiles + * @infiles: filedescriptors to be passed to qemu with the command + * @noutfiles: if non-NULL filled with number of returned file descriptors + * @outfiles: if non-NULL filled with an array of returned file descriptors + * @result: a string returned by @cmd + * @flags: bitwise-or of supported virDomainQemuMonitorCommandFlags + * + * This API is QEMU specific, so it will only work with hypervisor + * connections to the QEMU driver with local connections using the unix so= cket. + * + * Send an arbitrary monitor command @cmd with file descriptors @infiles to + * @domain through the qemu monitor and optionally return file descriptors= via + * @outfiles. There are several requirements to safely and successfully use + * this API: + * + * - A @cmd that queries state without making any modifications is safe + * - A @cmd that alters state that is also tracked by libvirt is unsafe, + * and may cause libvirtd to crash + * - A @cmd that alters state not tracked by the current version of + * libvirt is possible as a means to test new qemu features before + * they have support in libvirt, but no guarantees are made to safety + * + * If VIR_DOMAIN_QEMU_MONITOR_COMMAND_HMP is set, the command is + * considered to be a human monitor command and libvirt will automatically + * convert it into QMP if needed. In that case the @result will also + * be converted back from QMP. + * + * If successful, @result will be filled with the string output of the + * @cmd, and the caller must free this string. + * + * Returns 0 in case of success, -1 in case of failure + */ +int +virDomainQemuMonitorCommandWithFiles(virDomainPtr domain, + const char *cmd, + unsigned int ninfiles, + int *infiles, + unsigned int *noutfiles, + int **outfiles, + char **result, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain, + "cmd=3D%s, ninfiles=3D%u, infiles=3D%p, noutfiles=3D%= p, outfiles=3D%p, result=3D%p, flags=3D0x%x", + cmd, ninfiles, infiles, noutfiles, outfiles, result, = flags); + + virResetLastError(); + + virCheckDomainReturn(domain, -1); + conn =3D domain->conn; + + if (ninfiles > 0 || outfiles) { + int rc; + if ((rc =3D VIR_DRV_SUPPORTS_FEATURE(conn->driver, conn, + VIR_DRV_FEATURE_FD_PASSING) <= =3D 0)) { + if (rc =3D=3D 0) + virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", + _("fd passing is not supported by this conn= ection")); + goto error; + } + } + + virCheckNonNullArgGoto(result, error); + virCheckReadOnlyGoto(conn->flags, error); + + if (conn->driver->domainQemuMonitorCommandWithFiles) { + int ret; + ret =3D conn->driver->domainQemuMonitorCommandWithFiles(domain, cm= d, + ninfiles, in= files, + noutfiles, o= utfiles, + result, flag= s); + if (ret < 0) + goto error; + return ret; + } + + virReportUnsupportedError(); + + error: + virDispatchError(conn); + return -1; +} + /** * virDomainQemuAttach: * @conn: pointer to a hypervisor connection diff --git a/src/libvirt_qemu.syms b/src/libvirt_qemu.syms index 3a297e3a2b..019e545101 100644 --- a/src/libvirt_qemu.syms +++ b/src/libvirt_qemu.syms @@ -30,3 +30,8 @@ LIBVIRT_QEMU_1.2.3 { virConnectDomainQemuMonitorEventDeregister; virConnectDomainQemuMonitorEventRegister; } LIBVIRT_QEMU_0.10.0; + +LIBVIRT_QEMU_8.1.0 { + global: + virDomainQemuMonitorCommandWithFiles; +} LIBVIRT_QEMU_1.2.3; diff --git a/src/qemu_protocol-structs b/src/qemu_protocol-structs index 8501543cd9..ea0854385f 100644 --- a/src/qemu_protocol-structs +++ b/src/qemu_protocol-structs @@ -47,6 +47,14 @@ struct qemu_domain_monitor_event_msg { u_int micros; remote_string details; }; +struct qemu_domain_monitor_command_with_files_args { + remote_nonnull_domain dom; + remote_nonnull_string cmd; + u_int flags; +}; +struct qemu_domain_monitor_command_with_files_ret { + remote_nonnull_string result; +}; enum qemu_procedure { QEMU_PROC_DOMAIN_MONITOR_COMMAND =3D 1, QEMU_PROC_DOMAIN_ATTACH =3D 2, @@ -54,4 +62,5 @@ enum qemu_procedure { QEMU_PROC_CONNECT_DOMAIN_MONITOR_EVENT_REGISTER =3D 4, QEMU_PROC_CONNECT_DOMAIN_MONITOR_EVENT_DEREGISTER =3D 5, QEMU_PROC_DOMAIN_MONITOR_EVENT =3D 6, + QEMU_PROC_DOMAIN_MONITOR_COMMAND_WITH_FILES =3D 7, }; diff --git a/src/remote/qemu_protocol.x b/src/remote/qemu_protocol.x index 8ff5dc8568..c7f3abfcbf 100644 --- a/src/remote/qemu_protocol.x +++ b/src/remote/qemu_protocol.x @@ -79,6 +79,17 @@ struct qemu_domain_monitor_event_msg { remote_string details; }; +struct qemu_domain_monitor_command_with_files_args { + remote_nonnull_domain dom; + remote_nonnull_string cmd; + unsigned int flags; +}; + +struct qemu_domain_monitor_command_with_files_ret { + remote_nonnull_string result; +}; + + /* Define the program number, protocol version and procedure numbers here.= */ const QEMU_PROGRAM =3D 0x20008087; const QEMU_PROTOCOL_VERSION =3D 1; @@ -151,5 +162,12 @@ enum qemu_procedure { * @generate: both * @acl: none */ - QEMU_PROC_DOMAIN_MONITOR_EVENT =3D 6 + QEMU_PROC_DOMAIN_MONITOR_EVENT =3D 6, + + /** + * @generate: none + * @priority: low + * @acl: domain:write + */ + QEMU_PROC_DOMAIN_MONITOR_COMMAND_WITH_FILES =3D 7 }; diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index 587cc0b3a5..510856024c 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -4684,6 +4684,68 @@ qemuDispatchDomainMonitorCommand(virNetServer *serve= r G_GNUC_UNUSED, } +static int +qemuDispatchDomainMonitorCommandWithFiles(virNetServer *server G_GNUC_UNUS= ED, + virNetServerClient *client, + virNetMessage *msg, + struct virNetMessageError *rerr, + qemu_domain_monitor_command_with= _files_args *args, + qemu_domain_monitor_command_with= _files_ret *ret) +{ + virDomainPtr dom =3D NULL; + int *infiles =3D NULL; + unsigned int ninfiles =3D 0; + int *outfiles =3D NULL; + unsigned int noutfiles =3D 0; + int rv =3D -1; + virConnectPtr conn =3D remoteGetHypervisorConn(client); + size_t i; + + if (!conn) + goto cleanup; + + if (!(dom =3D get_nonnull_domain(conn, args->dom))) + goto cleanup; + + infiles =3D g_new0(int, msg->nfds); + for (i =3D 0; i < msg->nfds; i++) { + if ((infiles[i] =3D virNetMessageDupFD(msg, i)) < 0) + goto cleanup; + ninfiles++; + } + + /* This API can both receive FDs from the client and send FDs back, bu= t 'msg' + * is being reused. Thus we must clear the list of FDs in it to prevent + * us sending back the FDs client sent us. */ + virNetMessageClearFDs(msg); + + if (virDomainQemuMonitorCommandWithFiles(dom, args->cmd, ninfiles, inf= iles, + &noutfiles, &outfiles, + &ret->result, args->flags) < = 0) + goto cleanup; + + for (i =3D 0; i < noutfiles; i++) { + if (virNetMessageAddFD(msg, outfiles[i]) < 0) + goto cleanup; + } + + /* return 1 here to let virNetServerProgramDispatchCall know we are pa= ssing fds */ + if (noutfiles > 0) + rv =3D 1; + else + rv =3D 0; + + cleanup: + for (i =3D 0; i < noutfiles; i++) + VIR_FORCE_CLOSE(outfiles[i]); + + if (rv < 0) + virNetMessageSaveError(rerr); + virObjectUnref(dom); + return rv; +} + + static int remoteDispatchDomainMigrateBegin3(virNetServer *server G_GNUC_UNUSED, virNetServerClient *client, diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index d721da6d2d..4babfbaa94 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -5931,6 +5931,62 @@ remoteDomainQemuMonitorCommand(virDomainPtr domain, = const char *cmd, } +static int +remoteDomainQemuMonitorCommandWithFiles(virDomainPtr domain, + const char *cmd, + unsigned int ninfiles, + int *infiles, + unsigned int *noutfiles, + int **outfiles, + char **result, + unsigned int flags) +{ + int rv =3D -1; + qemu_domain_monitor_command_with_files_args args; + qemu_domain_monitor_command_with_files_ret ret; + struct private_data *priv =3D domain->conn->privateData; + size_t rpc_noutfiles =3D 0; + g_autofree int *rpc_outfiles =3D NULL; + size_t i; + + remoteDriverLock(priv); + + make_nonnull_domain(&args.dom, domain); + args.cmd =3D (char *)cmd; + args.flags =3D flags; + + memset(&ret, 0, sizeof(ret)); + if (callFull(domain->conn, priv, REMOTE_CALL_QEMU, + infiles, ninfiles, &rpc_outfiles, &rpc_noutfiles, + QEMU_PROC_DOMAIN_MONITOR_COMMAND_WITH_FILES, + (xdrproc_t) xdr_qemu_domain_monitor_command_with_files_ar= gs, (char *) &args, + (xdrproc_t) xdr_qemu_domain_monitor_command_with_files_re= t, (char *) &ret) =3D=3D -1) + goto done; + + if (outfiles) + *outfiles =3D g_steal_pointer(&rpc_outfiles); + + if (noutfiles) + *noutfiles =3D rpc_noutfiles; + + *result =3D g_strdup(ret.result); + + rv =3D 0; + + xdr_free((xdrproc_t) xdr_qemu_domain_monitor_command_with_files_ret, (= char *) &ret); + + done: + if (rpc_outfiles) { + for (i =3D 0; rpc_noutfiles < i; i++) { + VIR_FORCE_CLOSE(rpc_outfiles[i]); + } + } + + remoteDriverUnlock(priv); + return rv; +} + + static char * remoteDomainMigrateBegin3(virDomainPtr domain, const char *xmlin, @@ -8506,6 +8562,7 @@ static virHypervisorDriver hypervisor_driver =3D { .domainSnapshotHasMetadata =3D remoteDomainSnapshotHasMetadata, /* 0.9= .13 */ .domainSnapshotDelete =3D remoteDomainSnapshotDelete, /* 0.8.0 */ .domainQemuMonitorCommand =3D remoteDomainQemuMonitorCommand, /* 0.8.3= */ + .domainQemuMonitorCommandWithFiles =3D remoteDomainQemuMonitorCommandW= ithFiles, /* 8.1.0 */ .domainQemuAttach =3D remoteDomainQemuAttach, /* 0.9.4 */ .domainQemuAgentCommand =3D remoteDomainQemuAgentCommand, /* 0.10.0 */ .connectDomainQemuMonitorEventRegister =3D remoteConnectDomainQemuMoni= torEventRegister, /* 1.2.3 */ --=20 2.35.1 From nobody Tue May 14 05:47:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 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=1645432897; cv=none; d=zohomail.com; s=zohoarc; b=EjjASZC4Pn1m+EvM87lvy1Y/nERn213UXp4fDoYz4Y/jtYwyh2W2GEzpUHGDzbT6xaXOTrcmjAgLZkXyQNNm62aweg+pmiqeAr6Nugkw/2HIU3UnLVaVuS92ZiY9Pg6NcfCKZLMNHmq6jQQZ5x6xCAcKKZYcitMc6Tui+j6eKfQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645432897; 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=e4kc4VxSWusmW0otFpghDtLGMWwUqeAO6VghMKp09SY=; b=GHIrwR4DG8uMMCZ0J3H+Wr9OWiX6s4ZUw2AuslMIcO+Wzx6nF7aMODnWFd/YisWS8kzegZW4lXu9TYxVwoBwpyn0PgcEs+il3fmuJdS12rWsSnERxMauWrPEvHLMqCcRBc5N3pttRsCebX1LDsKQ2En5C9TMGpm9yVsp2r8KVeE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1645432897058436.82420206534346; Mon, 21 Feb 2022 00:41:37 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-619-02Z9JXdwNrex_Bz9vU2Ikw-1; Mon, 21 Feb 2022 03:41:32 -0500 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 82FA81006AA5; Mon, 21 Feb 2022 08:41:27 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3B6D162D72; Mon, 21 Feb 2022 08:41:27 +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 B45AF1809CAB; Mon, 21 Feb 2022 08:41:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21L8fOxP022018 for ; Mon, 21 Feb 2022 03:41:24 -0500 Received: by smtp.corp.redhat.com (Postfix) id 98D0C7B6DA; Mon, 21 Feb 2022 08:41:24 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id E937F7B6D8 for ; Mon, 21 Feb 2022 08:41:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1645432895; 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=e4kc4VxSWusmW0otFpghDtLGMWwUqeAO6VghMKp09SY=; b=aK0eAVlwDUDgTfVeY4rES6gET7QCoAKV56xVCOO7mgoSNncs/9xe29ZoHwG8mHtMVmUEq0 kPkPbjvtojeOvhBu6Vci8vCxcZWSAeNd4x8KM66rRixM9Sba6rYw1b2Qy++PRTDhPNiwme sDEkITMtHVhiMiNXGWBu1/VfLlhd/E4= X-MC-Unique: 02Z9JXdwNrex_Bz9vU2Ikw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v2 3/4] virsh: Implement support for virDomainQemuMonitorCommandWithFiles Date: Mon, 21 Feb 2022 09:41:08 +0100 Message-Id: <860cff221b6065519e0b37e5a971e5ecc0e7e00b.1645432719.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1645432898490100002 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- docs/manpages/virsh.rst | 6 +++++- tools/virsh-domain.c | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 429879d2dd..1e6914a438 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -7894,7 +7894,8 @@ qemu-monitor-command :: - qemu-monitor-command domain { [--hmp] | [--pretty] [--return-value] } c= ommand... + qemu-monitor-command domain { [--hmp] | [--pretty] [--return-value] } + [--pass-fds N,M,...] command... Send an arbitrary monitor command *command* to domain *domain* through the QEMU monitor. The results of the command will be printed on stdout. @@ -7927,6 +7928,9 @@ extracted rather than passing through the full reply = from QEMU. If *--hmp* is passed, the command is considered to be a human monitor comm= and and libvirt will automatically convert it into QMP and convert the result = back. +If *--pass-fds* is specified, the argument is a comma separated list +of open file descriptors which should be passed on to qemu along with the +command. qemu-agent-command ------------------ diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 433ea674b5..1ebfb3a567 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -9721,6 +9721,11 @@ static const vshCmdOptDef opts_qemu_monitor_command[= ] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("extract the value of the 'return' key from the returned= string") }, + {.name =3D "pass-fds", + .type =3D VSH_OT_STRING, + .completer =3D virshCompleteEmpty, + .help =3D N_("pass file descriptors N,M,... along with the command") + }, {.name =3D "cmd", .type =3D VSH_OT_ARGV, .flags =3D VSH_OFLAG_REQ, @@ -9819,6 +9824,8 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *= cmd) bool returnval =3D vshCommandOptBool(cmd, "return-value"); virJSONValue *formatjson; g_autofree char *jsonstr =3D NULL; + g_autofree int *fds =3D NULL; + size_t nfds =3D 0; VSH_EXCLUSIVE_OPTIONS("hmp", "pretty"); VSH_EXCLUSIVE_OPTIONS("hmp", "return-value"); @@ -9838,9 +9845,19 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd = *cmd) return NULL; } - if (virDomainQemuMonitorCommand(dom, monitor_cmd, &result, flags) < 0) + if (virshFetchPassFdsList(ctl, cmd, &nfds, &fds) < 0) return false; + if (fds) { + if (virDomainQemuMonitorCommandWithFiles(dom, monitor_cmd, nfds, f= ds, + NULL, NULL, + &result, flags) < 0) + return false; + } else { + if (virDomainQemuMonitorCommand(dom, monitor_cmd, &result, flags) = < 0) + return false; + } + if (returnval || pretty) { resultjson =3D virJSONValueFromString(result); --=20 2.35.1 From nobody Tue May 14 05:47:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 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=1645432912; cv=none; d=zohomail.com; s=zohoarc; b=O/FZkIhuJ91pvUM4Y8nl8iC1CC/2mxv3q/ayEsa9C2Ar0IXmUiWgPWZYj8ZyP731TYlxGeZ3a/CVOiYJ/Ga/VhbOhksxb9dQhqCk3nhTihvxFGw/ih8ZJ+JFEKN9bFrGq9Vb7sxMemKQSjaI62Ea42gJx3Uf8A+bF9mqwpsOyjw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645432912; 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=USIb2JuQN31baSi38k9Cl68ixaMLE8LUVjbSrxTsU2Q=; b=FHX9cw82R2SR0gS1r4LMVLEC+eTZV4pSf6teo7Gtcf05DbetAH2eNUjlwvEyCrzKPjWBN8Diuj4c45SumufTLlu6eJhAt5R6bsjF/EsjSfyqyAi60RJ12v+6Uy0WGN4sL4NhCjaSdumx6buH1fzaxu/1ewPKk950or50Rp4yGTw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1645432912050727.070672400217; Mon, 21 Feb 2022 00:41:52 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-572-UxVya9WyPbCBYBDaFrp65A-1; Mon, 21 Feb 2022 03:41:49 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1A02215720; Mon, 21 Feb 2022 08:41:44 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EE4B778DDA; Mon, 21 Feb 2022 08:41:43 +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 BC7CE180004C; Mon, 21 Feb 2022 08:41:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21L8fPFL022026 for ; Mon, 21 Feb 2022 03:41:25 -0500 Received: by smtp.corp.redhat.com (Postfix) id B65EA7B6DA; Mon, 21 Feb 2022 08:41:25 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 140827B6D8 for ; Mon, 21 Feb 2022 08:41:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1645432911; 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=USIb2JuQN31baSi38k9Cl68ixaMLE8LUVjbSrxTsU2Q=; b=WgM4x6qvfZGZ/JCquQPYhnGLP6ufoXffxzur6WbuREKeEBQiFHMIJUjLCkgSLVlscxV3cj xlUno98hH1FDlaKIbufs5jhBbcxtLJpeRX0B31siMQkSTFo2EMOAmY2OB7hhRLA4fvxbR/ yNW0IaqJx/xvhX42iRB4h3sKmMTY52w= X-MC-Unique: UxVya9WyPbCBYBDaFrp65A-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v2 4/4] qemu: Implement qemuDomainQemuMonitorCommandWithFiles Date: Mon, 21 Feb 2022 09:41:09 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1645432912410100001 Content-Type: text/plain; charset="utf-8" Add support for sending one FD from the client along with a monitor command so that it's possible to use 'getfd' and 'add-fd' to use FDs passed from the client with other QMP commands. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_driver.c | 42 ++++++++++++++++++++++++++++++++---- src/qemu/qemu_monitor.c | 7 +++--- src/qemu/qemu_monitor.h | 1 + src/qemu/qemu_monitor_json.c | 6 ++++-- src/qemu/qemu_monitor_json.h | 2 ++ src/qemu/qemu_monitor_text.c | 8 +++---- 6 files changed, 53 insertions(+), 13 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f1f708e511..706c47792c 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -13921,21 +13921,44 @@ qemuDomainBackupGetXMLDesc(virDomainPtr domain, } -static int qemuDomainQemuMonitorCommand(virDomainPtr domain, const char *c= md, - char **result, unsigned int flags) +static int +qemuDomainQemuMonitorCommandWithFiles(virDomainPtr domain, + const char *cmd, + unsigned int ninfds, + int *infds, + unsigned int *noutfds, + int **outfds, + char **result, + unsigned int flags) { virQEMUDriver *driver =3D domain->conn->privateData; virDomainObj *vm =3D NULL; int ret =3D -1; qemuDomainObjPrivate *priv; bool hmp; + int fd =3D -1; virCheckFlags(VIR_DOMAIN_QEMU_MONITOR_COMMAND_HMP, -1); + /* currently we don't pass back any fds */ + if (outfds) + *outfds =3D NULL; + if (noutfds) + *noutfds =3D 0; + + if (ninfds > 1) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("at most 1 fd can be passed to qemu along with a = command")); + return -1; + } + + if (ninfds =3D=3D 1) + fd =3D infds[0]; + if (!(vm =3D qemuDomainObjFromDomain(domain))) goto cleanup; - if (virDomainQemuMonitorCommandEnsureACL(domain->conn, vm->def) < 0) + if (virDomainQemuMonitorCommandWithFilesEnsureACL(domain->conn, vm->de= f) < 0) goto cleanup; if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_QUERY) < 0) @@ -13951,7 +13974,7 @@ static int qemuDomainQemuMonitorCommand(virDomainPt= r domain, const char *cmd, hmp =3D !!(flags & VIR_DOMAIN_QEMU_MONITOR_COMMAND_HMP); qemuDomainObjEnterMonitor(driver, vm); - ret =3D qemuMonitorArbitraryCommand(priv->mon, cmd, result, hmp); + ret =3D qemuMonitorArbitraryCommand(priv->mon, cmd, fd, result, hmp); qemuDomainObjExitMonitor(driver, vm); endjob: @@ -13963,6 +13986,16 @@ static int qemuDomainQemuMonitorCommand(virDomainP= tr domain, const char *cmd, } +static int +qemuDomainQemuMonitorCommand(virDomainPtr domain, + const char *cmd, + char **result, + unsigned int flags) +{ + return qemuDomainQemuMonitorCommandWithFiles(domain, cmd, 0, NULL, NUL= L, NULL, result, flags); +} + + static int qemuDomainOpenConsole(virDomainPtr dom, const char *dev_name, @@ -20873,6 +20906,7 @@ static virHypervisorDriver qemuHypervisorDriver =3D= { .domainRevertToSnapshot =3D qemuDomainRevertToSnapshot, /* 0.8.0 */ .domainSnapshotDelete =3D qemuDomainSnapshotDelete, /* 0.8.0 */ .domainQemuMonitorCommand =3D qemuDomainQemuMonitorCommand, /* 0.8.3 */ + .domainQemuMonitorCommandWithFiles =3D qemuDomainQemuMonitorCommandWit= hFiles, /* 8.1.0 */ .domainQemuAttach =3D NULL, /* 0.9.4 - 5.5.0 */ .domainQemuAgentCommand =3D qemuDomainQemuAgentCommand, /* 0.10.0 */ .connectDomainQemuMonitorEventRegister =3D qemuConnectDomainQemuMonito= rEventRegister, /* 1.2.3 */ diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index dc81e41783..4fcba588c7 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -3042,17 +3042,18 @@ qemuMonitorDrivePivot(qemuMonitor *mon, int qemuMonitorArbitraryCommand(qemuMonitor *mon, const char *cmd, + int fd, char **reply, bool hmp) { - VIR_DEBUG("cmd=3D%s, reply=3D%p, hmp=3D%d", cmd, reply, hmp); + VIR_DEBUG("cmd=3D%s, fd=3D%d, reply=3D%p, hmp=3D%d", cmd, fd, reply, h= mp); QEMU_CHECK_MONITOR(mon); if (hmp) - return qemuMonitorJSONHumanCommand(mon, cmd, reply); + return qemuMonitorJSONHumanCommand(mon, cmd, fd, reply); else - return qemuMonitorJSONArbitraryCommand(mon, cmd, reply); + return qemuMonitorJSONArbitraryCommand(mon, cmd, fd, reply); } diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 1d21183d82..c8e8036f26 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1088,6 +1088,7 @@ char *qemuMonitorDiskNameLookup(qemuMonitor *mon, int qemuMonitorArbitraryCommand(qemuMonitor *mon, const char *cmd, + int fd, char **reply, bool hmp); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 1de932f638..ad040e22c1 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -1462,6 +1462,7 @@ qemuMonitorJSONHandleGuestCrashloaded(qemuMonitor *mo= n, int qemuMonitorJSONHumanCommand(qemuMonitor *mon, const char *cmd_str, + int fd, char **reply_str) { g_autoptr(virJSONValue) cmd =3D NULL; @@ -1473,7 +1474,7 @@ qemuMonitorJSONHumanCommand(qemuMonitor *mon, "s:command-line", cmd_str, NULL); - if (!cmd || qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + if (!cmd || qemuMonitorJSONCommandWithFd(mon, cmd, fd, &reply) < 0) return -1; if (qemuMonitorJSONHasError(reply, "CommandNotFound")) { @@ -4495,6 +4496,7 @@ qemuMonitorJSONDiskNameLookup(qemuMonitor *mon, int qemuMonitorJSONArbitraryCommand(qemuMonitor *mon, const char *cmd_str, + int fd, char **reply_str) { g_autoptr(virJSONValue) cmd =3D NULL; @@ -4503,7 +4505,7 @@ int qemuMonitorJSONArbitraryCommand(qemuMonitor *mon, if (!(cmd =3D virJSONValueFromString(cmd_str))) return -1; - if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + if (qemuMonitorJSONCommandWithFd(mon, cmd, fd, &reply) < 0) return -1; if (!(*reply_str =3D virJSONValueToString(reply, false))) diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index eea3478af0..e34a30c889 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -43,6 +43,7 @@ qemuMonitorJSONIOProcess(qemuMonitor *mon, int qemuMonitorJSONHumanCommand(qemuMonitor *mon, const char *cmd, + int fd, char **reply); int @@ -369,6 +370,7 @@ qemuMonitorJSONDiskNameLookup(qemuMonitor *mon, int qemuMonitorJSONArbitraryCommand(qemuMonitor *mon, const char *cmd_str, + int fd, char **reply_str); int diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c index 0ca7f5a470..86af1e4975 100644 --- a/src/qemu/qemu_monitor_text.c +++ b/src/qemu/qemu_monitor_text.c @@ -43,7 +43,7 @@ int qemuMonitorTextAddDrive(qemuMonitor *mon, * address required when attaching drives to a controller */ cmd =3D g_strdup_printf("drive_add dummy %s", drivestr); - if (qemuMonitorJSONHumanCommand(mon, cmd, &reply) < 0) + if (qemuMonitorJSONHumanCommand(mon, cmd, -1, &reply) < 0) return -1; if (strstr(reply, "unknown command:")) { @@ -93,7 +93,7 @@ int qemuMonitorTextDriveDel(qemuMonitor *mon, cmd =3D g_strdup_printf("drive_del %s", drivestr); - if (qemuMonitorJSONHumanCommand(mon, cmd, &reply) < 0) + if (qemuMonitorJSONHumanCommand(mon, cmd, -1, &reply) < 0) return -1; if (strstr(reply, "unknown command:")) { @@ -124,7 +124,7 @@ qemuMonitorTextCreateSnapshot(qemuMonitor *mon, cmd =3D g_strdup_printf("savevm \"%s\"", name); - if (qemuMonitorJSONHumanCommand(mon, cmd, &reply)) + if (qemuMonitorJSONHumanCommand(mon, cmd, -1, &reply)) return -1; if (strstr(reply, "Error while creating snapshot") || @@ -150,7 +150,7 @@ int qemuMonitorTextDeleteSnapshot(qemuMonitor *mon, con= st char *name) g_autofree char *reply =3D NULL; cmd =3D g_strdup_printf("delvm \"%s\"", name); - if (qemuMonitorJSONHumanCommand(mon, cmd, &reply)) + if (qemuMonitorJSONHumanCommand(mon, cmd, -1, &reply)) return -1; if (strstr(reply, "No block device supports snapshots")) { --=20 2.35.1