From nobody Sun Feb 8 23:41:34 2026 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 --- 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