From nobody Mon Feb 9 07:38:17 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=1643899941; cv=none; d=zohomail.com; s=zohoarc; b=DSSNC9NQw076r5yRJ6axfdIuwYmc05Dp14F641vCC+DP6C7UHhdloVnSQje+VNILIkmYD+mBB+4YEINHsD6LKIwQITd6u7q/bUNvwCKaIUqY7Yg34wOCZeNcE7derPNDBL4JXwNj4S0KD3FgT9BQ9BLbnxBuPwCh/EwNCLZbuSk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1643899941; 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=/r0VgI57Pj4L8gEMRfit1fvi0gPtUxIlxBNG0O5uRv8=; b=LZeDEhCt8lV5QwR/bBIX2NnqVQRny1SOfSSturfxl4PH6bjRf+VwKaXMm0zMX9mGgl44TfnyGvOhhvziDqB8HMThYNPpdstz1/GoHccFj0wGL151uWTNQioD5JjEmgQ6vQ6ACa6IAnDcyun4CbXkZAey2UJEnYF/VD8CMnI/UGo= 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 1643899941449102.57265237203558; Thu, 3 Feb 2022 06:52:21 -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-620-mYd8EbNEOaGH7Nd37Hu2Lw-1; Thu, 03 Feb 2022 09:52:17 -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 2B6398145F4; Thu, 3 Feb 2022 14:52:11 +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 F3FD670D34; Thu, 3 Feb 2022 14:52:10 +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 963B81809CB8; Thu, 3 Feb 2022 14:52:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 213Eq9k1029422 for ; Thu, 3 Feb 2022 09:52:09 -0500 Received: by smtp.corp.redhat.com (Postfix) id B277770D30; Thu, 3 Feb 2022 14:52:09 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 127986E1EE for ; Thu, 3 Feb 2022 14:52:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643899940; 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=/r0VgI57Pj4L8gEMRfit1fvi0gPtUxIlxBNG0O5uRv8=; b=Ijnw7RRCgPixGU8AlF6tzujkjd0rM0uWxqVSmLsuiULr6OtnrQ+avckxQ/zgxhZw5umyPJ 54b1RLc/JhFOisJC1CKu45BYuNceFThID/d+cykMMeALUfx05KhlZxkuHj9LG/JEtuVv9h 9q6GvayQ3row5c7LdrYfjoLyppy96r4= X-MC-Unique: mYd8EbNEOaGH7Nd37Hu2Lw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/5] lib: Introduce 'virDomainQemuMonitorCommandWithFiles' Date: Thu, 3 Feb 2022 15:51:55 +0100 Message-Id: <760a47acf1bb56c954460d4e0cca5557dc008544.1643899820.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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: 1643899943246100003 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 --- include/libvirt/libvirt-qemu.h | 6 +++ src/driver-hypervisor.h | 8 ++++ src/libvirt-qemu.c | 71 +++++++++++++++++++++++++++++ src/libvirt_qemu.syms | 5 ++ src/qemu_protocol-structs | 9 ++++ src/remote/qemu_protocol.x | 20 +++++++- src/remote/remote_daemon_dispatch.c | 42 +++++++++++++++++ src/remote/remote_driver.c | 40 ++++++++++++++++ 8 files changed, 200 insertions(+), 1 deletion(-) diff --git a/include/libvirt/libvirt-qemu.h b/include/libvirt/libvirt-qemu.h index 0cc2872821..eed691ec91 100644 --- a/include/libvirt/libvirt-qemu.h +++ b/include/libvirt/libvirt-qemu.h @@ -37,6 +37,12 @@ typedef enum { int virDomainQemuMonitorCommand(virDomainPtr domain, const char *cmd, char **result, unsigned int flags); +int virDomainQemuMonitorCommandWithFiles(virDomainPtr domain, + const char *cmd, + unsigned int nfiles, + int *files, + 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..b3e55cf4ac 100644 --- a/src/driver-hypervisor.h +++ b/src/driver-hypervisor.h @@ -874,6 +874,13 @@ typedef int const char *cmd, char **result, unsigned int flags); +typedef int +(*virDrvDomainQemuMonitorCommandWithFiles)(virDomainPtr domain, + const char *cmd, + unsigned int nfiles, + int *files, + char **result, + unsigned int flags); typedef char * (*virDrvDomainQemuAgentCommand)(virDomainPtr domain, @@ -1597,6 +1604,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..1dbe0cba54 100644 --- a/src/libvirt-qemu.c +++ b/src/libvirt-qemu.c @@ -96,6 +96,77 @@ virDomainQemuMonitorCommand(virDomainPtr domain, const c= har *cmd, } +/** + * virDomainQemuMonitorCommandWithFiles: + * @domain: a domain object + * @cmd: the qemu monitor command string + * @nfiles: number of filedescriptors passed in @files + * @files: filedescriptors to be passed to qemu with the command + * @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 @files to + * @domain through the qemu monitor. There are several requirements to saf= ely + * 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 nfiles, + int *files, + char **result, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain, "cmd=3D%s, nfiles=3D%u, files=3D%p, result=3D= %p, flags=3D0x%x", + cmd, nfiles, files, result, flags); + + virResetLastError(); + + virCheckDomainReturn(domain, -1); + conn =3D domain->conn; + + virCheckNonNullArgGoto(result, error); + virCheckReadOnlyGoto(conn->flags, error); + + if (conn->driver->domainQemuMonitorCommandWithFiles) { + int ret; + ret =3D conn->driver->domainQemuMonitorCommandWithFiles(domain, cm= d, + nfiles, file= s, + 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 689001889e..5f967abed0 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -4689,6 +4689,48 @@ 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 *files =3D NULL; + unsigned int nfiles =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; + + files =3D g_new0(int, msg->nfds); + for (i =3D 0; i < msg->nfds; i++) { + if ((files[i] =3D virNetMessageDupFD(msg, i)) < 0) + goto cleanup; + nfiles++; + } + + if (virDomainQemuMonitorCommandWithFiles(dom, args->cmd, nfiles, files, + &ret->result, args->flags) < = 0) + goto cleanup; + + rv =3D 0; + + cleanup: + 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 5b7ccfaebd..ee3f4e4e63 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -5938,6 +5938,45 @@ remoteDomainQemuMonitorCommand(virDomainPtr domain, = const char *cmd, } +static int +remoteDomainQemuMonitorCommandWithFiles(virDomainPtr domain, + const char *cmd, + unsigned int nfiles, + int *files, + 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; + + 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, + files, nfiles, NULL, NULL, + 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; + + *result =3D g_strdup(ret.result); + + rv =3D 0; + + xdr_free((xdrproc_t) xdr_qemu_domain_monitor_command_ret, (char *) &re= t); + + done: + remoteDriverUnlock(priv); + return rv; +} + + static char * remoteDomainMigrateBegin3(virDomainPtr domain, const char *xmlin, @@ -8513,6 +8552,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.34.1