From nobody Wed May 15 20:00:09 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=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 Reviewed-by: J=C3=A1n Tomko --- 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 From nobody Wed May 15 20:00:09 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=1643899957; cv=none; d=zohomail.com; s=zohoarc; b=HNaPw+xOXTIA840mT0mwMGL6HV2zPgMakreR6RR/HgJL6vqABZxRFvtk/IygQxBq4XlhRXURaR7pYYFfqNuJst1lph21nBP+6xDjTHUHTBB3FsDXMzotMeveNSkOok0gDLsVGfNqOGEzAcFEwSmuCWKv4oh3pu0nnrOHKWG75Q8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1643899957; 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=SdZuBI1s/i9n2dvMQcmWO3kk/wFd0OAMqjHZCOKYaJY=; b=hsixsBlOrGFKQMkuZuf5Aek58eFqZlIwM5G/EZB50C6SQGGmhHNNRLyWc01pXj9IEiB94mgCr+pbZ7vevISMX+/jWGe1wsCKXwM7rrrB8xwxy0qpYb0YPSFa2HCyuVCeilOfGG+KtWAoO5a43K5kq46lanuGRfbTIVJu0xOz6rs= 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 1643899957212799.1358821936267; Thu, 3 Feb 2022 06:52: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-450-3imyVOmDOhKW43p2mokIeg-1; Thu, 03 Feb 2022 09:52:27 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AD1B181424D; Thu, 3 Feb 2022 14:52:21 +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 8954222E10; Thu, 3 Feb 2022 14:52:21 +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 574C51809CB8; Thu, 3 Feb 2022 14:52:21 +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 213EqAKi029432 for ; Thu, 3 Feb 2022 09:52:10 -0500 Received: by smtp.corp.redhat.com (Postfix) id E0AED70D30; Thu, 3 Feb 2022 14:52:10 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 402B070D3D for ; Thu, 3 Feb 2022 14:52:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643899956; 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=SdZuBI1s/i9n2dvMQcmWO3kk/wFd0OAMqjHZCOKYaJY=; b=XOjMQsxDD2Sn10zgXpSfOE4i+T9kVl8dxm52qSAggPzR2Uckxdyv7chMKM+JwlenmAXZK+ zq8u9z3GXRmyr3NttbE5D129fZqXtjRK3LgXaxt6uZacnSzlp4PL323wtB6KQvafDTyvxa vHMG1IbnK3Ocg0+pf9fkv7GiUKrf6Aw= X-MC-Unique: 3imyVOmDOhKW43p2mokIeg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/5] cmdStartGetFDs: Modernize Date: Thu, 3 Feb 2022 15:51:56 +0100 Message-Id: <8fa4fe86750f3951941492ec9033441f381066c1.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.84 on 10.5.11.23 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: 1643899959166100001 Content-Type: text/plain; charset="utf-8" Calculate the length of the FD list beforehand to avoid multiple expansions and mainly simplify the code and use automatic freeing to remove the error code path. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/virsh-domain.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 43d310f2af..b4cb7193a7 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -4021,7 +4021,7 @@ cmdStartGetFDs(vshControl *ctl, { const char *fdopt; g_auto(GStrv) fdlist =3D NULL; - int *fds =3D NULL; + g_autofree int *fds =3D NULL; size_t nfds =3D 0; size_t i; @@ -4036,23 +4036,19 @@ cmdStartGetFDs(vshControl *ctl, return -1; } + nfds =3D g_strv_length(fdlist); + fds =3D g_new0(int, nfds); + for (i =3D 0; fdlist[i] !=3D NULL; i++) { - int fd; - if (virStrToLong_i(fdlist[i], NULL, 10, &fd) < 0) { + if (virStrToLong_i(fdlist[i], NULL, 10, fds + i) < 0) { vshError(ctl, _("Unable to parse FD number '%s'"), fdlist[i]); - goto error; + return -1; } - VIR_EXPAND_N(fds, nfds, 1); - fds[nfds - 1] =3D fd; } - *fdsret =3D fds; + *fdsret =3D g_steal_pointer(&fds); *nfdsret =3D nfds; return 0; - - error: - VIR_FREE(fds); - return -1; } static bool --=20 2.34.1 From nobody Wed May 15 20:00:09 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=1643899952; cv=none; d=zohomail.com; s=zohoarc; b=cW2SUqXw8QgweqktisxR260sqG3kQlWSPWogUbCbF9CjW4YumvHuP1lA5U4Ub+aRDayTqz5tlPCX4+GJ9hBFRLO9v7f9I285KRvX73UnCp2gcEFmwZBN4hGge6+OyRiDG1MRukd3t2i645GyosNkPUgKOXx79oPF7d7fUCWbjsg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1643899952; 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=iGKvT+NDzAJRn6wxyDNYBILdyuPx/qKiqk3CL+/LWlM=; b=Jf2HVvEHCTA7QZRqTLx6LroNT+E0s9JMfdWD2DxSNeonvlk2JTfWvJnqYuzOffma1zEz3qUxiQyyRIhX/i3tXoBB2X3yOeEadiJ9xo5HjpYjbV6PqfiwakRe8XEortZ6ZFOezwAVzlIBLustQXJd5e9TH7BIE/v+1xsGfVi0l7Q= 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 1643899952881137.5588868109436; Thu, 3 Feb 2022 06:52:32 -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-73-29WgSQTtOmGQh61QtzcsvA-1; Thu, 03 Feb 2022 09:52:30 -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 6715283DC22; Thu, 3 Feb 2022 14:52:25 +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 1CF2B747B3; Thu, 3 Feb 2022 14:52:25 +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 D80D31809CBA; Thu, 3 Feb 2022 14:52:24 +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 213EqCsP029437 for ; Thu, 3 Feb 2022 09:52:12 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6450270D35; Thu, 3 Feb 2022 14:52:12 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9707370D33 for ; Thu, 3 Feb 2022 14:52:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643899952; 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=iGKvT+NDzAJRn6wxyDNYBILdyuPx/qKiqk3CL+/LWlM=; b=B149dSa+z2YjniMW3IDlawkqI0jWrMiwcsiesFSJ5AswKgxk5fI20QYKdLqVknS0hRnoo7 bfdDD021Z+bk/IC/KzTpH8dSUhhJXygus0L5VWiV0LWsO95XAL92wpkgx3dIhDc/KRqLuG poOt2PAjiewu4MuxuyqKCI8XeiludsM= X-MC-Unique: 29WgSQTtOmGQh61QtzcsvA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 3/5] virsh-domain: Move and rename cmdStartGetFDs to virshFetchPassFdsList Date: Thu, 3 Feb 2022 15:51:57 +0100 Message-Id: <9be807b9f838d0c242d4520fa4961eaba0905af6.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.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: 1643899954418100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/virsh-domain.c | 86 +++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 40 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index b4cb7193a7..0bf4bb8dad 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -225,6 +225,50 @@ virshAddressFormat(virBuffer *buf, } +/** + * virshFetchPassFdsList + * + * Helper to process the 'pass-fds' argument. + */ +static int +virshFetchPassFdsList(vshControl *ctl, + const vshCmd *cmd, + size_t *nfdsret, + int **fdsret) +{ + const char *fdopt; + g_auto(GStrv) fdlist =3D NULL; + g_autofree int *fds =3D NULL; + size_t nfds =3D 0; + size_t i; + + *nfdsret =3D 0; + *fdsret =3D NULL; + + if (vshCommandOptStringQuiet(ctl, cmd, "pass-fds", &fdopt) <=3D 0) + return 0; + + if (!(fdlist =3D g_strsplit(fdopt, ",", -1))) { + vshError(ctl, _("Unable to split FD list '%s'"), fdopt); + return -1; + } + + nfds =3D g_strv_length(fdlist); + fds =3D g_new0(int, nfds); + + for (i =3D 0; fdlist[i] !=3D NULL; i++) { + if (virStrToLong_i(fdlist[i], NULL, 10, fds + i) < 0) { + vshError(ctl, _("Unable to parse FD number '%s'"), fdlist[i]); + return -1; + } + } + + *fdsret =3D g_steal_pointer(&fds); + *nfdsret =3D nfds; + return 0; +} + + #define VIRSH_COMMON_OPT_DOMAIN_PERSISTENT \ {.name =3D "persistent", \ .type =3D VSH_OT_BOOL, \ @@ -4013,44 +4057,6 @@ static const vshCmdOptDef opts_start[] =3D { {.name =3D NULL} }; -static int -cmdStartGetFDs(vshControl *ctl, - const vshCmd *cmd, - size_t *nfdsret, - int **fdsret) -{ - const char *fdopt; - g_auto(GStrv) fdlist =3D NULL; - g_autofree int *fds =3D NULL; - size_t nfds =3D 0; - size_t i; - - *nfdsret =3D 0; - *fdsret =3D NULL; - - if (vshCommandOptStringQuiet(ctl, cmd, "pass-fds", &fdopt) <=3D 0) - return 0; - - if (!(fdlist =3D g_strsplit(fdopt, ",", -1))) { - vshError(ctl, _("Unable to split FD list '%s'"), fdopt); - return -1; - } - - nfds =3D g_strv_length(fdlist); - fds =3D g_new0(int, nfds); - - for (i =3D 0; fdlist[i] !=3D NULL; i++) { - if (virStrToLong_i(fdlist[i], NULL, 10, fds + i) < 0) { - vshError(ctl, _("Unable to parse FD number '%s'"), fdlist[i]); - return -1; - } - } - - *fdsret =3D g_steal_pointer(&fds); - *nfdsret =3D nfds; - return 0; -} - static bool cmdStart(vshControl *ctl, const vshCmd *cmd) { @@ -4072,7 +4078,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) return false; } - if (cmdStartGetFDs(ctl, cmd, &nfds, &fds) < 0) + if (virshFetchPassFdsList(ctl, cmd, &nfds, &fds) < 0) return false; if (vshCommandOptBool(cmd, "paused")) @@ -8112,7 +8118,7 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) return false; - if (cmdStartGetFDs(ctl, cmd, &nfds, &fds) < 0) + if (virshFetchPassFdsList(ctl, cmd, &nfds, &fds) < 0) return false; if (vshCommandOptBool(cmd, "paused")) --=20 2.34.1 From nobody Wed May 15 20:00:09 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=1643899947; cv=none; d=zohomail.com; s=zohoarc; b=OGmrsGSxqjnOerwgzqRzNJktex91ycM1DJFqJdJk/qC1YuRwNYTBepWh8ttDEPPHIvaTBdDjU17wFYsaa0KFifhokzChkdMx8bVP82mgHTOIB8/8MNTI7dPdpYC9uZvXcCDkbXOzigijZq1+DUgkKde+JOWRLbt1dFA5o2C+lJQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1643899947; 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=acIEeWg5FwPvumnEHlgCC2HrQGiS5noPvA1ms2ysBLs=; b=FQKTpSWur7bfsjVGXEGpWSU50puTT8eQ6COswZ/BpTM6GW8dMo+26+vymYdtOEi/pR05V9rza0Fh4y4X+oKORBShi50qu3zof61+f+4siPrMeF1uITMerPHtZbPt7Jarey+M+Nqg6E+hKQ/ae6ty68gzYXc3cFSOA2RMS9DlNT0= 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 1643899947762444.03410782125036; Thu, 3 Feb 2022 06:52:27 -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-379-HI0giJWbPDy9PCXC4uhi2g-1; Thu, 03 Feb 2022 09:52:25 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 39D5F105251B; Thu, 3 Feb 2022 14:52:17 +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 5B8BA22E00; Thu, 3 Feb 2022 14:52:16 +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 F08801809CB9; Thu, 3 Feb 2022 14:52:15 +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 213EqDbj029447 for ; Thu, 3 Feb 2022 09:52:13 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9883770D34; Thu, 3 Feb 2022 14:52:13 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id E04746E1EE for ; Thu, 3 Feb 2022 14:52:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643899947; 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=acIEeWg5FwPvumnEHlgCC2HrQGiS5noPvA1ms2ysBLs=; b=XBuvh4/RUYWtcxWGzDQuHk4VPI3UyB8M/CFy36zQQ2Oi8Bw1dPV/rPEDziwEQ3r8os2CHl cSHQ2v4CBH0FwCn/BR0hmfaTiJs2NX3rOeIhENTlBHF+W1RwaYZRTbyz//IOO7CrG5d+9j 56aCfufNyyzVoau8H6mwVkG/njWaWJc= X-MC-Unique: HI0giJWbPDy9PCXC4uhi2g-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 4/5] virsh: Implement support for virDomainQemuMonitorCommandWithFiles Date: Thu, 3 Feb 2022 15:51:58 +0100 Message-Id: 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.84 on 10.5.11.23 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: 1643899948827100001 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 | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index e28927ed6c..82a759a636 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -7881,7 +7881,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. @@ -7914,6 +7915,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 0bf4bb8dad..6cd031f8c3 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -9703,6 +9703,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, @@ -9801,6 +9806,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"); @@ -9820,9 +9827,18 @@ 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, + &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.34.1 From nobody Wed May 15 20:00:09 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=1643899950; cv=none; d=zohomail.com; s=zohoarc; b=MjpTTLv2mCPuFOgIBpIJfwi+juG3v8SsXr0SD6FyNKVcMA4+svI33p4c6DIyPWxKdbsnpQOvKBF75MTawNTvF7B7haP+t1sbqgt6fap5IbbetrduJAUhfntDQWxzdryUk3+WktrYEmneEeMAvODxnjwtu+VdSQpaqCNc5N73M1M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1643899950; 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=VpsveF0fCTq0UOt4kRcYx8IeJ67w6Y9K45/ZjxPCHkw=; b=A7ZGzN0sZ7OOEUUtnp4yeYenDSuNfAni3LTMDHjSSHawNAg63YcBMilazp/gRTTSHZVFYEJs/Cn2xkBz4J/jLn5yyl5Y/cNvatI6mPMHzd2FvZ2l+QhG7OCCSpKXoU0M/nrdrxFAclYtC0YaPggOdrwdc0u+CVbsi7I4veMY/NQ= 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 1643899950144108.48296316196365; Thu, 3 Feb 2022 06:52:30 -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-528-rLcbOXGkNtaRXux0DMJI_Q-1; Thu, 03 Feb 2022 09:52:28 -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 89341101AFD3; Thu, 3 Feb 2022 14:52:19 +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 236D870D39; Thu, 3 Feb 2022 14:52:19 +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 DA39C4CA93; Thu, 3 Feb 2022 14:52:18 +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 213EqESn029457 for ; Thu, 3 Feb 2022 09:52:14 -0500 Received: by smtp.corp.redhat.com (Postfix) id C919B70D33; Thu, 3 Feb 2022 14:52:14 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06EF970D30 for ; Thu, 3 Feb 2022 14:52:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643899949; 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=VpsveF0fCTq0UOt4kRcYx8IeJ67w6Y9K45/ZjxPCHkw=; b=A2lxFjO31t0SFJ6jPjmFONdUmsF4KrzLsSn6pxCy+AnJ5jbsOnX8AcgQX55hYQSCBDZJ0q onyifIWJXce4OMp/HZCjDnnITmMVpu+/DvSeM2iI2VkJpUFIKbfYsfYv0kFblXgGz2/mq5 kBQ3gEJhg6Y9eJxtCMUWIQxg/x34WAA= X-MC-Unique: rLcbOXGkNtaRXux0DMJI_Q-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 5/5] qemu: Implement qemuDomainQemuMonitorCommandWithFiles Date: Thu, 3 Feb 2022 15:51:59 +0100 Message-Id: <4c749f03d12db46158c271a1ec67864287cb49c4.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: 1643899951526100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_driver.c | 34 ++++++++++++++++++++++++++++++---- 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, 45 insertions(+), 13 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 698f57f00e..d10d1556a7 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -13897,21 +13897,36 @@ 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 nfds, + int *fds, + 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); + if (nfds > 1) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("at most 1 fd can be passed to qemu along with a = command")); + return -1; + } + + if (nfds =3D=3D 1) + fd =3D fds[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) @@ -13927,7 +13942,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: @@ -13939,6 +13954,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, res= ult, flags); +} + + static int qemuDomainOpenConsole(virDomainPtr dom, const char *dev_name, @@ -20849,6 +20874,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 babf9e62fb..6359a05155 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -3104,17 +3104,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 9b2e4e1421..b7ed8d9bae 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1108,6 +1108,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 b0b513683b..9ab07bb29a 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -1461,6 +1461,7 @@ qemuMonitorJSONHandleGuestCrashloaded(qemuMonitor *mo= n, int qemuMonitorJSONHumanCommand(qemuMonitor *mon, const char *cmd_str, + int fd, char **reply_str) { g_autoptr(virJSONValue) cmd =3D NULL; @@ -1472,7 +1473,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")) { @@ -4497,6 +4498,7 @@ qemuMonitorJSONDiskNameLookup(qemuMonitor *mon, int qemuMonitorJSONArbitraryCommand(qemuMonitor *mon, const char *cmd_str, + int fd, char **reply_str) { g_autoptr(virJSONValue) cmd =3D NULL; @@ -4505,7 +4507,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 64d9ebdaa3..c57f54e040 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.34.1