From e1c04108d7602133d74c815929df2c81178d8dde Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Fri, 24 Apr 2015 16:43:38 +0200 Subject: [PATCH] qemu: agent: Differentiate errors when the agent channel was hotplugged When the guest agent channel gets hotplugged to a VM, libvirt would still report that "QEMU guest agent is not configured" rather than stating that the connection was not established yet. Currently the code won't be able to connect to the agent after hotplug but that will change in a later patch. As the qemuFindAgentConfig() helper is quite helpful in this case move it to a more usable place and export it. --- src/qemu/qemu_domain.c | 45 +++++++++++++++++++++++++++++++++++++---- src/qemu/qemu_domain.h | 2 ++ src/qemu/qemu_process.c | 20 ------------------ 3 files changed, 43 insertions(+), 24 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 39973a9182..154a81ea71 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -2975,11 +2975,19 @@ qemuDomainAgentAvailable(virDomainObjPtr vm, return false; } if (!priv->agent) { - if (reportError) { - virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", - _("QEMU guest agent is not configured")); + if (qemuFindAgentConfig(vm->def)) { + if (reportError) { + virReportError(VIR_ERR_AGENT_UNRESPONSIVE, "%s", + _("QEMU guest agent is not connected")); + } + return false; + } else { + if (reportError) { + virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", + _("QEMU guest agent is not configured")); + } + return false; } - return false; } if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_RUNNING) { if (reportError) { @@ -3077,3 +3085,32 @@ qemuDomainSupportsBlockJobs(virDomainObjPtr vm, return 0; } + + +/** + * qemuFindAgentConfig: + * @def: domain definition + * + * Returns the pointer to the channel definition that is used to access the + * guest agent if the agent is configured or NULL otherwise. + */ +virDomainChrSourceDefPtr +qemuFindAgentConfig(virDomainDefPtr def) +{ + virDomainChrSourceDefPtr config = NULL; + size_t i; + + for (i = 0; i < def->nchannels; i++) { + virDomainChrDefPtr channel = def->channels[i]; + + if (channel->targetType != VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO) + continue; + + if (STREQ_NULLABLE(channel->target.name, "org.qemu.guest_agent.0")) { + config = &channel->source; + break; + } + } + + return config; +} diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index d550ae38fe..76a48195e2 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -439,4 +439,6 @@ bool qemuDomainDiskBlockJobIsActive(virDomainDiskDefPtr disk); int qemuDomainAlignMemorySizes(virDomainDefPtr def); void qemuDomainMemoryDeviceAlignSize(virDomainMemoryDefPtr mem); +virDomainChrSourceDefPtr qemuFindAgentConfig(virDomainDefPtr def); + #endif /* __QEMU_DOMAIN_H__ */ diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index fb83d51a5b..75ccb66ff5 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -201,26 +201,6 @@ static qemuAgentCallbacks agentCallbacks = { .errorNotify = qemuProcessHandleAgentError, }; -static virDomainChrSourceDefPtr -qemuFindAgentConfig(virDomainDefPtr def) -{ - virDomainChrSourceDefPtr config = NULL; - size_t i; - - for (i = 0; i < def->nchannels; i++) { - virDomainChrDefPtr channel = def->channels[i]; - - if (channel->targetType != VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO) - continue; - - if (STREQ_NULLABLE(channel->target.name, "org.qemu.guest_agent.0")) { - config = &channel->source; - break; - } - } - - return config; -} static int qemuConnectAgent(virQEMUDriverPtr driver, virDomainObjPtr vm) -- GitLab