From nobody Sun May 5 03:42:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 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=1573682790; cv=none; d=zoho.com; s=zohoarc; b=ZCIKy6sIlf2eGQqRx7Akyn1Rnu8ytAgQWu63AhmaW8fQb544En7Tzx29ajm+8o8eewqtQLqGq3GmwJnmK5xC4yM7+8wpcoZr3h7+S70PDwwuz4mz0MqUn0dGdWQopVf3Z88p8/ZTeRtDFvgnhcFiot1dQtTndqCpEnYIpD+R1QA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573682790; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=eGFWbKxvfQHdewfyoXriUVsSvp7MoRRIj82EvPgY5tA=; b=fl5pCer3KoEl6Q5BVVCcr8wAz2oxox3yT3q5TzPeiFgzq0m44yEQl2kRyVfkQeEmVf5W9n+KYpyfJRIw3lyCgLGukVCO75wwMUK7e2Ms8yT9+8rFmqDa+ZM9WR9kaEavlK3XbenOR4ZyZX6FqK+jHxNnv9d+kx/IIYjmP0Zg5mk= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 157368279002685.1556463995729; Wed, 13 Nov 2019 14:06:30 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-183-zUGL5vjcO7iH8vFYLJjyuw-1; Wed, 13 Nov 2019 17:06:26 -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 79A1E1007270; Wed, 13 Nov 2019 22:06: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 C9C77348A2; Wed, 13 Nov 2019 22:06:17 +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 B07824BB65; Wed, 13 Nov 2019 22:06:14 +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 xADM6Cau006904 for ; Wed, 13 Nov 2019 17:06:12 -0500 Received: by smtp.corp.redhat.com (Postfix) id E2BD369320; Wed, 13 Nov 2019 22:06:12 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-116-153.phx2.redhat.com [10.3.116.153]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5F08F75E4B; Wed, 13 Nov 2019 22:06:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573682788; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=eGFWbKxvfQHdewfyoXriUVsSvp7MoRRIj82EvPgY5tA=; b=Z47qLTBUmZX8CRRPzOErr7+kFfanDqZz/MLjaalGVaZoy6JBYraO44U9n0h/3i0HRRSFMx B8Aq20oyxPFAGCyOxvFfaVzBACIYjcZ84mEcE78dZPKQNey/gI/gQXxy2eJsJuLkjG20lp p55OVp+Jem/s2r9DBj9PUnzc8chZ9cY= From: Jonathon Jongsma To: libvir-list@redhat.com Date: Wed, 13 Nov 2019 16:06:09 -0600 Message-Id: <20191113220609.19129-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: mprivozn@redhat.com, tgolembi@redhat.com Subject: [libvirt] [PATCH v3] Add API to change qemu agent response timeout 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 X-MC-Unique: zUGL5vjcO7iH8vFYLJjyuw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Some layered products such as oVirt have requested a way to avoid being blocked by guest agent commands when querying a loaded vm. For example, many guest agent commands are polled periodically to monitor changes, and rather than blocking the calling process, they'd prefer to simply time out when an agent query is taking too long. This patch adds a way for the user to specify a custom agent timeout that is applied to all agent commands. One special case to note here is the 'guest-sync' command. 'guest-sync' is issued internally prior to calling any other command. (For example, when libvirt wants to call 'guest-get-fsinfo', we first call 'guest-sync' and then call 'guest-get-fsinfo'). Previously, the 'guest-sync' command used a 5-second timeout (VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT), whereas the actual command that followed always blocked indefinitely (VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK). As part of this patch, if a custom timeout is specified that is shorter than 5 seconds, this new timeout is also used for 'guest-sync'. If there is no custom timeout or if the custom timeout is longer than 5 seconds, we will continue to use the 5-second timeout. Signed-off-by: Jonathon Jongsma Reviewed-by: Michal Privoznik --- Changes in v3: - Changed enum names per Daniel's suggestion - incorporated Michal's review and fixup patches - As discussed on the mailing list, this patch does not acquire any jobs, = but simply uses mutex locking for data integrity - libvirt release versions updated - format and parse private agentTimeout data in status xml include/libvirt/libvirt-domain.h | 10 +++ include/libvirt/libvirt-qemu.h | 8 +-- src/driver-hypervisor.h | 6 ++ src/libvirt-domain.c | 49 +++++++++++++ src/libvirt_public.syms | 5 ++ src/qemu/qemu_agent.c | 70 ++++++++++--------- src/qemu/qemu_agent.h | 3 + src/qemu/qemu_domain.c | 6 ++ src/qemu/qemu_domain.h | 1 + src/qemu/qemu_driver.c | 47 +++++++++++++ src/remote/remote_driver.c | 1 + src/remote/remote_protocol.x | 18 ++++- src/remote_protocol-structs | 9 +++ .../blockjob-blockdev-in.xml | 1 + .../blockjob-mirror-in.xml | 1 + .../disk-secinfo-upgrade-out.xml | 1 + .../migration-in-params-in.xml | 1 + .../migration-out-nbd-out.xml | 1 + .../migration-out-nbd-tls-out.xml | 1 + .../migration-out-params-in.xml | 1 + tests/qemustatusxml2xmldata/modern-in.xml | 1 + .../qemustatusxml2xmldata/vcpus-multi-in.xml | 1 + tools/virsh-domain.c | 52 ++++++++++++++ 23 files changed, 257 insertions(+), 37 deletions(-) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index 22277b0a84..a2f007568c 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -4916,4 +4916,14 @@ int virDomainGetGuestInfo(virDomainPtr domain, int *nparams, unsigned int flags); =20 +typedef enum { + VIR_DOMAIN_AGENT_RESPONSE_TIMEOUT_BLOCK =3D -2, + VIR_DOMAIN_AGENT_RESPONSE_TIMEOUT_DEFAULT =3D -1, + VIR_DOMAIN_AGENT_RESPONSE_TIMEOUT_NOWAIT =3D 0, +} virDomainAgentResponseTimeoutValues; + +int virDomainAgentSetResponseTimeout(virDomainPtr domain, + int timeout, + unsigned int flags); + #endif /* LIBVIRT_DOMAIN_H */ diff --git a/include/libvirt/libvirt-qemu.h b/include/libvirt/libvirt-qemu.h index 891617443f..0cc2872821 100644 --- a/include/libvirt/libvirt-qemu.h +++ b/include/libvirt/libvirt-qemu.h @@ -43,10 +43,10 @@ virDomainPtr virDomainQemuAttach(virConnectPtr domain, unsigned int flags); =20 typedef enum { - VIR_DOMAIN_QEMU_AGENT_COMMAND_MIN =3D -2, - VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK =3D -2, - VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT =3D -1, - VIR_DOMAIN_QEMU_AGENT_COMMAND_NOWAIT =3D 0, + VIR_DOMAIN_QEMU_AGENT_COMMAND_MIN =3D VIR_DOMAIN_AGENT_RESPONSE_TIMEOU= T_BLOCK, + VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK =3D VIR_DOMAIN_AGENT_RESPONSE_TIME= OUT_BLOCK, + VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT =3D VIR_DOMAIN_AGENT_RESPONSE_TI= MEOUT_DEFAULT, + VIR_DOMAIN_QEMU_AGENT_COMMAND_NOWAIT =3D VIR_DOMAIN_AGENT_RESPONSE_TIM= EOUT_NOWAIT, VIR_DOMAIN_QEMU_AGENT_COMMAND_SHUTDOWN =3D 60, } virDomainQemuAgentCommandTimeoutValues; =20 diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h index 015b2cd01c..4afd8f6ec5 100644 --- a/src/driver-hypervisor.h +++ b/src/driver-hypervisor.h @@ -1372,6 +1372,11 @@ typedef int int *nparams, unsigned int flags); =20 +typedef int +(*virDrvDomainAgentSetResponseTimeout)(virDomainPtr domain, + int timeout, + unsigned int flags); + typedef struct _virHypervisorDriver virHypervisorDriver; typedef virHypervisorDriver *virHypervisorDriverPtr; =20 @@ -1632,4 +1637,5 @@ struct _virHypervisorDriver { virDrvDomainCheckpointGetParent domainCheckpointGetParent; virDrvDomainCheckpointDelete domainCheckpointDelete; virDrvDomainGetGuestInfo domainGetGuestInfo; + virDrvDomainAgentSetResponseTimeout domainAgentSetResponseTimeout; }; diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index dcab179e6e..02622cb2ca 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -12497,3 +12497,52 @@ int virDomainGetLaunchSecurityInfo(virDomainPtr do= main, virDispatchError(domain->conn); return -1; } + + +/** + * virDomainAgentSetResponseTimeout: + * @domain: a domain object + * @timeout: timeout in seconds + * @flags: extra flags; not used yet, so callers should always pass 0 + * + * Set how long to wait for a response from guest agent commands. By defau= lt, + * agent commands block forever waiting for a response. + * + * @timeout must be a value from virDomainAgentCommandTimeoutValues or + * positive: + * + * VIR_DOMAIN_AGENT_COMMAND_TIMEOUT_BLOCK(-2): meaning to block forever + * waiting for a result. + * VIR_DOMAIN_AGENT_COMMAND_TIMEOUT_DEFAULT(-1): use default timeout val= ue. + * VIR_DOMAIN_AGENT_COMMAND_TIMEOUT_NOWAIT(0): does not wait. + * positive value: wait for @timeout seconds + * + * Returns 0 on success, -1 on failure + */ +int +virDomainAgentSetResponseTimeout(virDomainPtr domain, + int timeout, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain, "timeout=3D%i, flags=3D0x%x", + timeout, flags); + + virResetLastError(); + + virCheckDomainReturn(domain, -1); + conn =3D domain->conn; + + if (conn->driver->domainAgentSetResponseTimeout) { + if (conn->driver->domainAgentSetResponseTimeout(domain, timeout, f= lags) < 0) + goto error; + return 0; + } + + virReportUnsupportedError(); + + error: + virDispatchError(conn); + return -1; +} diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index f88a77892f..c92f083758 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -862,4 +862,9 @@ LIBVIRT_5.8.0 { virConnectSetIdentity; } LIBVIRT_5.7.0; =20 +LIBVIRT_5.10.0 { + global: + virDomainAgentSetResponseTimeout; +} LIBVIRT_5.8.0; + # .... define new API here using predicted next version number .... diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 5a50f7f3be..7905a74f90 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -30,6 +30,7 @@ #include =20 #include "qemu_agent.h" +#include "qemu_domain.h" #include "viralloc.h" #include "virlog.h" #include "virerror.h" @@ -127,6 +128,7 @@ struct _qemuAgent { * but fire up an event on qemu monitor instead. * Take that as indication of successful completion */ qemuAgentEvent await_event; + int timeout; }; =20 static virClassPtr qemuAgentClass; @@ -695,6 +697,7 @@ qemuAgentOpen(virDomainObjPtr vm, if (!(mon =3D virObjectLockableNew(qemuAgentClass))) return NULL; =20 + mon->timeout =3D QEMU_DOMAIN_PRIVATE(vm)->agentTimeout; mon->fd =3D -1; if (virCondInit(&mon->notify) < 0) { virReportSystemError(errno, "%s", @@ -907,6 +910,12 @@ qemuAgentGuestSync(qemuAgentPtr mon) int send_ret; unsigned long long id; qemuAgentMessage sync_msg; + int timeout =3D VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT; + + /* if user specified a custom agent timeout that is lower than the + * default timeout, use the shorter timeout instead */ + if ((mon->timeout >=3D 0) && (mon->timeout < timeout)) + timeout =3D mon->timeout; =20 memset(&sync_msg, 0, sizeof(sync_msg)); /* set only on first sync */ @@ -925,8 +934,7 @@ qemuAgentGuestSync(qemuAgentPtr mon) =20 VIR_DEBUG("Sending guest-sync command with ID: %llu", id); =20 - send_ret =3D qemuAgentSend(mon, &sync_msg, - VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT); + send_ret =3D qemuAgentSend(mon, &sync_msg, timeout); =20 VIR_DEBUG("qemuAgentSend returned: %d", send_ret); =20 @@ -1301,8 +1309,7 @@ int qemuAgentFSFreeze(qemuAgentPtr mon, const char **= mountpoints, if (!cmd) goto cleanup; =20 - if (qemuAgentCommand(mon, cmd, &reply, true, - VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0) + if (qemuAgentCommand(mon, cmd, &reply, true, mon->timeout) < 0) goto cleanup; =20 if (virJSONValueObjectGetNumberInt(reply, "return", &ret) < 0) { @@ -1339,8 +1346,7 @@ int qemuAgentFSThaw(qemuAgentPtr mon) if (!cmd) return -1; =20 - if (qemuAgentCommand(mon, cmd, &reply, true, - VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0) + if (qemuAgentCommand(mon, cmd, &reply, true, mon->timeout) < 0) goto cleanup; =20 if (virJSONValueObjectGetNumberInt(reply, "return", &ret) < 0) { @@ -1377,8 +1383,7 @@ qemuAgentSuspend(qemuAgentPtr mon, return -1; =20 mon->await_event =3D QEMU_AGENT_EVENT_SUSPEND; - ret =3D qemuAgentCommand(mon, cmd, &reply, false, - VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK); + ret =3D qemuAgentCommand(mon, cmd, &reply, false, mon->timeout); =20 virJSONValueFree(cmd); virJSONValueFree(reply); @@ -1434,8 +1439,7 @@ qemuAgentFSTrim(qemuAgentPtr mon, if (!cmd) return ret; =20 - ret =3D qemuAgentCommand(mon, cmd, &reply, false, - VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK); + ret =3D qemuAgentCommand(mon, cmd, &reply, false, mon->timeout); =20 virJSONValueFree(cmd); virJSONValueFree(reply); @@ -1456,8 +1460,7 @@ qemuAgentGetVCPUs(qemuAgentPtr mon, if (!(cmd =3D qemuAgentMakeCommand("guest-get-vcpus", NULL))) return -1; =20 - if (qemuAgentCommand(mon, cmd, &reply, true, - VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0) + if (qemuAgentCommand(mon, cmd, &reply, true, mon->timeout) < 0) goto cleanup; =20 if (!(data =3D virJSONValueObjectGetArray(reply, "return"))) { @@ -1572,8 +1575,7 @@ qemuAgentSetVCPUsCommand(qemuAgentPtr mon, NULL))) goto cleanup; =20 - if (qemuAgentCommand(mon, cmd, &reply, true, - VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0) + if (qemuAgentCommand(mon, cmd, &reply, true, mon->timeout) < 0) goto cleanup; =20 /* All negative values are invalid. Return of 0 is bogus since we woul= dn't @@ -1728,8 +1730,7 @@ qemuAgentGetHostname(qemuAgentPtr mon, if (!cmd) return ret; =20 - if (qemuAgentCommand(mon, cmd, &reply, true, - VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0) { + if (qemuAgentCommand(mon, cmd, &reply, true, mon->timeout) < 0) { if (qemuAgentErrorCommandUnsupported(reply)) ret =3D -2; goto cleanup; @@ -1773,8 +1774,7 @@ qemuAgentGetTime(qemuAgentPtr mon, if (!cmd) return ret; =20 - if (qemuAgentCommand(mon, cmd, &reply, true, - VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0) + if (qemuAgentCommand(mon, cmd, &reply, true, mon->timeout) < 0) goto cleanup; =20 if (virJSONValueObjectGetNumberUlong(reply, "return", &json_time) < 0)= { @@ -1839,8 +1839,7 @@ qemuAgentSetTime(qemuAgentPtr mon, if (!cmd) return ret; =20 - if (qemuAgentCommand(mon, cmd, &reply, true, - VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0) + if (qemuAgentCommand(mon, cmd, &reply, true, mon->timeout) < 0) goto cleanup; =20 ret =3D 0; @@ -2043,8 +2042,7 @@ qemuAgentGetFSInfoInternal(qemuAgentPtr mon, if (!cmd) return ret; =20 - if (qemuAgentCommand(mon, cmd, &reply, true, - VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0) { + if (qemuAgentCommand(mon, cmd, &reply, true, mon->timeout) < 0) { if (qemuAgentErrorCommandUnsupported(reply)) ret =3D -2; goto cleanup; @@ -2333,8 +2331,7 @@ qemuAgentGetInterfaces(qemuAgentPtr mon, if (!(cmd =3D qemuAgentMakeCommand("guest-network-get-interfaces", NUL= L))) goto cleanup; =20 - if (qemuAgentCommand(mon, cmd, &reply, true, - VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0) + if (qemuAgentCommand(mon, cmd, &reply, true, mon->timeout) < 0) goto cleanup; =20 if (!(ret_array =3D virJSONValueObjectGet(reply, "return"))) { @@ -2511,8 +2508,7 @@ qemuAgentSetUserPassword(qemuAgentPtr mon, NULL))) goto cleanup; =20 - if (qemuAgentCommand(mon, cmd, &reply, true, - VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0) + if (qemuAgentCommand(mon, cmd, &reply, true, mon->timeout) < 0) goto cleanup; =20 ret =3D 0; @@ -2543,8 +2539,7 @@ qemuAgentGetUsers(qemuAgentPtr mon, if (!(cmd =3D qemuAgentMakeCommand("guest-get-users", NULL))) return -1; =20 - if (qemuAgentCommand(mon, cmd, &reply, true, - VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0) { + if (qemuAgentCommand(mon, cmd, &reply, true, mon->timeout) < 0) { if (qemuAgentErrorCommandUnsupported(reply)) return -2; return -1; @@ -2633,8 +2628,7 @@ qemuAgentGetOSInfo(qemuAgentPtr mon, if (!(cmd =3D qemuAgentMakeCommand("guest-get-osinfo", NULL))) return -1; =20 - if (qemuAgentCommand(mon, cmd, &reply, true, - VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0) { + if (qemuAgentCommand(mon, cmd, &reply, true, mon->timeout) < 0) { if (qemuAgentErrorCommandUnsupported(reply)) return -2; return -1; @@ -2689,8 +2683,7 @@ qemuAgentGetTimezone(qemuAgentPtr mon, if (!(cmd =3D qemuAgentMakeCommand("guest-get-timezone", NULL))) return -1; =20 - if (qemuAgentCommand(mon, cmd, &reply, true, - VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0) { + if (qemuAgentCommand(mon, cmd, &reply, true, mon->timeout) < 0) { if (qemuAgentErrorCommandUnsupported(reply)) return -2; return -1; @@ -2719,3 +2712,16 @@ qemuAgentGetTimezone(qemuAgentPtr mon, =20 return 0; } + +/* qemuAgentSetResponseTimeout: + * mon: agent monitor + * timeout: number of seconds to wait for agent response + * + * The agent object must be locked prior to calling this function. + */ +void +qemuAgentSetResponseTimeout(qemuAgentPtr mon, + int timeout) +{ + mon->timeout =3D timeout; +} diff --git a/src/qemu/qemu_agent.h b/src/qemu/qemu_agent.h index 78e648992a..85e436cf68 100644 --- a/src/qemu/qemu_agent.h +++ b/src/qemu/qemu_agent.h @@ -140,3 +140,6 @@ int qemuAgentGetTimezone(qemuAgentPtr mon, virTypedParameterPtr *params, int *nparams, int *maxparams); + +void qemuAgentSetResponseTimeout(qemuAgentPtr mon, + int timeout); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 54dde34f15..86358341d5 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -2093,6 +2093,8 @@ qemuDomainObjPrivateAlloc(void *opaque) if (!(priv->dbusVMStates =3D virHashCreate(5, dbusVMStateHashFree))) goto error; =20 + /* agent commands block by default, user can choose different behavior= */ + priv->agentTimeout =3D VIR_DOMAIN_AGENT_RESPONSE_TIMEOUT_BLOCK; priv->migMaxBandwidth =3D QEMU_DOMAIN_MIG_BANDWIDTH_MAX; priv->driver =3D opaque; =20 @@ -2875,6 +2877,8 @@ qemuDomainObjPrivateXMLFormat(virBufferPtr buf, if (qemuDomainObjPrivateXMLFormatSlirp(buf, vm) < 0) return -1; =20 + virBufferAsprintf(buf, "%i\n", priv->agen= tTimeout); + return 0; } =20 @@ -3672,6 +3676,8 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, =20 priv->memPrealloc =3D virXPathBoolean("boolean(./memPrealloc)", ctxt) = =3D=3D 1; =20 + virXPathInt("string(./agentTimeout)", ctxt, &priv->agentTimeout); + return 0; =20 error: diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index ab00b25789..98a9540275 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -293,6 +293,7 @@ struct _qemuDomainObjPrivate { virDomainChrSourceDefPtr monConfig; bool monError; unsigned long long monStart; + int agentTimeout; =20 qemuAgentPtr agent; bool agentError; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index c969a3d463..77a26ccf2e 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -22666,6 +22666,52 @@ qemuDomainGetGuestInfo(virDomainPtr dom, return ret; } =20 + +static int +qemuDomainAgentSetResponseTimeout(virDomainPtr dom, + int timeout, + unsigned int flags) +{ + virDomainObjPtr vm =3D NULL; + int ret =3D -1; + + virCheckFlags(0, -1); + + if (timeout < VIR_DOMAIN_QEMU_AGENT_COMMAND_MIN) { + virReportError(VIR_ERR_INVALID_ARG, + _("guest agent timeout '%d' is " + "less than the minimum '%d'"), + timeout, VIR_DOMAIN_QEMU_AGENT_COMMAND_MIN); + return -1; + } + + if (!(vm =3D qemuDomainObjFromDomain(dom))) + return -1; + + if (virDomainAgentSetResponseTimeoutEnsureACL(dom->conn, vm->def) < 0) + goto cleanup; + + /* If domain has an agent, change its timeout. Otherwise just save the + * request so that we can set the timeout when the agent appears */ + if (qemuDomainAgentAvailable(vm, false)) { + /* We don't need to acquire a job since we're not interacting with= the + * agent or the qemu monitor. We're only setting a struct member, = so + * just acquire the mutex lock. Worst case, any in-process agent + * commands will use the newly-set agent timeout. */ + virObjectLock(QEMU_DOMAIN_PRIVATE(vm)->agent); + qemuAgentSetResponseTimeout(QEMU_DOMAIN_PRIVATE(vm)->agent, timeou= t); + virObjectUnlock(QEMU_DOMAIN_PRIVATE(vm)->agent); + } + + QEMU_DOMAIN_PRIVATE(vm)->agentTimeout =3D timeout; + ret =3D 0; + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + + static virHypervisorDriver qemuHypervisorDriver =3D { .name =3D QEMU_DRIVER_NAME, .connectURIProbe =3D qemuConnectURIProbe, @@ -22902,6 +22948,7 @@ static virHypervisorDriver qemuHypervisorDriver =3D= { .domainCheckpointGetParent =3D qemuDomainCheckpointGetParent, /* 5.6.0= */ .domainCheckpointDelete =3D qemuDomainCheckpointDelete, /* 5.6.0 */ .domainGetGuestInfo =3D qemuDomainGetGuestInfo, /* 5.7.0 */ + .domainAgentSetResponseTimeout =3D qemuDomainAgentSetResponseTimeout, = /* 5.10.0 */ }; =20 =20 diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 503f49a902..a1384fc655 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -8701,6 +8701,7 @@ static virHypervisorDriver hypervisor_driver =3D { .domainCheckpointGetParent =3D remoteDomainCheckpointGetParent, /* 5.6= .0 */ .domainCheckpointDelete =3D remoteDomainCheckpointDelete, /* 5.6.0 */ .domainGetGuestInfo =3D remoteDomainGetGuestInfo, /* 5.7.0 */ + .domainAgentSetResponseTimeout =3D remoteDomainAgentSetResponseTimeout= , /* 5.10.0 */ }; =20 static virNetworkDriver network_driver =3D { diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index f4e3392212..23e42d17b1 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -3744,6 +3744,16 @@ struct remote_connect_set_identity_args { unsigned int flags; }; =20 +struct remote_domain_agent_set_response_timeout_args { + remote_nonnull_domain dom; + int timeout; + unsigned int flags; +}; + +struct remote_domain_agent_set_response_timeout_ret { + int result; +}; + /*----- Protocol. -----*/ =20 /* Define the program number, protocol version and procedure numbers here.= */ @@ -6617,5 +6627,11 @@ enum remote_procedure { * @generate: client * @acl: connect:write */ - REMOTE_PROC_CONNECT_SET_IDENTITY =3D 419 + REMOTE_PROC_CONNECT_SET_IDENTITY =3D 419, + + /** + * @generate: both + * @acl: domain:write + */ + REMOTE_PROC_DOMAIN_AGENT_SET_RESPONSE_TIMEOUT =3D 420 }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 51606e7473..9ad7a857e0 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -3114,6 +3114,14 @@ struct remote_connect_set_identity_args { } params; u_int flags; }; +struct remote_domain_agent_set_response_timeout_args { + remote_nonnull_domain dom; + int timeout; + u_int flags; +}; +struct remote_domain_agent_set_response_timeout_ret { + int result; +}; enum remote_procedure { REMOTE_PROC_CONNECT_OPEN =3D 1, REMOTE_PROC_CONNECT_CLOSE =3D 2, @@ -3534,4 +3542,5 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_CHECKPOINT_DELETE =3D 417, REMOTE_PROC_DOMAIN_GET_GUEST_INFO =3D 418, REMOTE_PROC_CONNECT_SET_IDENTITY =3D 419, + REMOTE_PROC_DOMAIN_AGENT_SET_RESPONSE_TIMEOUT =3D 420, }; diff --git a/tests/qemustatusxml2xmldata/blockjob-blockdev-in.xml b/tests/q= emustatusxml2xmldata/blockjob-blockdev-in.xml index e9031b7087..4f6930001e 100644 --- a/tests/qemustatusxml2xmldata/blockjob-blockdev-in.xml +++ b/tests/qemustatusxml2xmldata/blockjob-blockdev-in.xml @@ -338,6 +338,7 @@ + -2 copy 0439a4a8-db56-4933-9183-d8681d7b0746 diff --git a/tests/qemustatusxml2xmldata/blockjob-mirror-in.xml b/tests/qem= ustatusxml2xmldata/blockjob-mirror-in.xml index 0fba3b69e7..abd9f62965 100644 --- a/tests/qemustatusxml2xmldata/blockjob-mirror-in.xml +++ b/tests/qemustatusxml2xmldata/blockjob-mirror-in.xml @@ -23,6 +23,7 @@ + -2 QEMUGuest1 c7a5fdbd-edaf-9455-926a-d65c16db1809 diff --git a/tests/qemustatusxml2xmldata/disk-secinfo-upgrade-out.xml b/tes= ts/qemustatusxml2xmldata/disk-secinfo-upgrade-out.xml index 3d5e8f1438..5d3287606f 100644 --- a/tests/qemustatusxml2xmldata/disk-secinfo-upgrade-out.xml +++ b/tests/qemustatusxml2xmldata/disk-secinfo-upgrade-out.xml @@ -258,6 +258,7 @@ + -2 upstream dcf47dbd-46d1-4d5b-b442-262a806a333a diff --git a/tests/qemustatusxml2xmldata/migration-in-params-in.xml b/tests= /qemustatusxml2xmldata/migration-in-params-in.xml index 80cc4b4666..fdc2d39173 100644 --- a/tests/qemustatusxml2xmldata/migration-in-params-in.xml +++ b/tests/qemustatusxml2xmldata/migration-in-params-in.xml @@ -257,6 +257,7 @@ + -2 nest 994cee0d-2a70-4937-9693-0431e39d20f7 diff --git a/tests/qemustatusxml2xmldata/migration-out-nbd-out.xml b/tests/= qemustatusxml2xmldata/migration-out-nbd-out.xml index 455c30be85..304fb1b77f 100644 --- a/tests/qemustatusxml2xmldata/migration-out-nbd-out.xml +++ b/tests/qemustatusxml2xmldata/migration-out-nbd-out.xml @@ -260,6 +260,7 @@ + -2 upstream dcf47dbd-46d1-4d5b-b442-262a806a333a diff --git a/tests/qemustatusxml2xmldata/migration-out-nbd-tls-out.xml b/te= sts/qemustatusxml2xmldata/migration-out-nbd-tls-out.xml index 409e97a918..d69796e029 100644 --- a/tests/qemustatusxml2xmldata/migration-out-nbd-tls-out.xml +++ b/tests/qemustatusxml2xmldata/migration-out-nbd-tls-out.xml @@ -289,6 +289,7 @@ + -2 upstream dcf47dbd-46d1-4d5b-b442-262a806a333a diff --git a/tests/qemustatusxml2xmldata/migration-out-params-in.xml b/test= s/qemustatusxml2xmldata/migration-out-params-in.xml index 4a660281d2..1956eac120 100644 --- a/tests/qemustatusxml2xmldata/migration-out-params-in.xml +++ b/tests/qemustatusxml2xmldata/migration-out-params-in.xml @@ -271,6 +271,7 @@ + -2 nest 994cee0d-2a70-4937-9693-0431e39d20f7 diff --git a/tests/qemustatusxml2xmldata/modern-in.xml b/tests/qemustatusxm= l2xmldata/modern-in.xml index 2125b899f4..8a2718293f 100644 --- a/tests/qemustatusxml2xmldata/modern-in.xml +++ b/tests/qemustatusxml2xmldata/modern-in.xml @@ -261,6 +261,7 @@ + -2 upstream dcf47dbd-46d1-4d5b-b442-262a806a333a diff --git a/tests/qemustatusxml2xmldata/vcpus-multi-in.xml b/tests/qemusta= tusxml2xmldata/vcpus-multi-in.xml index b8ec650714..11ec74ecf8 100644 --- a/tests/qemustatusxml2xmldata/vcpus-multi-in.xml +++ b/tests/qemustatusxml2xmldata/vcpus-multi-in.xml @@ -309,6 +309,7 @@ + -2 QEMUGuest1 c7a5fdbd-edaf-9455-926a-d65c16db1809 diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 0feb21ef17..def4107d27 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -9832,6 +9832,52 @@ cmdQemuAgentCommand(vshControl *ctl, const vshCmd *c= md) =20 return ret; } +/* + * "guest-agent-timeout" command + */ +static const vshCmdInfo info_guest_agent_timeout[] =3D { + {.name =3D "help", + .data =3D N_("Set the guest agent timeout") + }, + {.name =3D "desc", + .data =3D N_("Set the number of seconds to wait for a response from t= he guest agent.") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_guest_agent_timeout[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "timeout", + .type =3D VSH_OT_INT, + .flags =3D VSH_OFLAG_REQ_OPT, + .help =3D N_("timeout seconds.") + }, + {.name =3D NULL} +}; + +static bool +cmdGuestAgentTimeout(vshControl *ctl, const vshCmd *cmd) +{ + virDomainPtr dom =3D NULL; + int timeout; + const unsigned int flags =3D 0; + bool ret =3D false; + + dom =3D virshCommandOptDomain(ctl, cmd, NULL); + if (dom =3D=3D NULL) + goto cleanup; + + if (vshCommandOptInt(ctl, cmd, "timeout", &timeout) < 0) + goto cleanup; + + if (virDomainAgentSetResponseTimeout(dom, timeout, flags) < 0) + goto cleanup; + + ret =3D true; + cleanup: + virshDomainFree(dom); + return ret; +} =20 /* * "lxc-enter-namespace" namespace @@ -14492,6 +14538,12 @@ const vshCmdDef domManagementCmds[] =3D { .info =3D info_qemu_agent_command, .flags =3D 0 }, + {.name =3D "guest-agent-timeout", + .handler =3D cmdGuestAgentTimeout, + .opts =3D opts_guest_agent_timeout, + .info =3D info_guest_agent_timeout, + .flags =3D 0 + }, {.name =3D "reboot", .handler =3D cmdReboot, .opts =3D opts_reboot, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list