[PATCH 0/2] bhyve: guest agent bugfixes
Roman Bogorodskiy (2): bhyve: process: properly handle misconfigured agent bhyve: fix domainQemuAgentCommand src/bhyve/bhyve_driver.c | 35 +---------------------------------- src/bhyve/bhyve_process.c | 11 +++++++---- 2 files changed, 8 insertions(+), 38 deletions(-) -- 2.52.0
Currently, bhyveDomainEnsureAgent() returns successfully (with 0 return value) even in cases when the agent is not configured. That happens because the bhyveConnectAgent() function does not fail if it cannot find the agent configuration. This might result in accessing the agent point at NULL. Fix by making bhyveConnectAgent() failing if the agent is not configured. Additionally, only call bhyveFindAgentConfig() when the agent is not configured to avoid unnecessary checks every time the agent is needed. Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com> --- src/bhyve/bhyve_process.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/bhyve/bhyve_process.c b/src/bhyve/bhyve_process.c index 92665419d4..e92bdeb416 100644 --- a/src/bhyve/bhyve_process.c +++ b/src/bhyve/bhyve_process.c @@ -243,14 +243,17 @@ bhyveConnectAgent(struct _bhyveConn *driver G_GNUC_UNUSED, virDomainObj *vm) { bhyveDomainObjPrivate *priv = vm->privateData; qemuAgent *agent = NULL; - virDomainChrDef *config = bhyveFindAgentConfig(vm->def); - - if (!config) - return 0; + virDomainChrDef *config = NULL; if (priv->agent) return 0; + if (!(config = bhyveFindAgentConfig(vm->def))) { + virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", + _("QEMU guest agent is not configured")); + return -1; + } + agent = qemuAgentOpen(vm, config->source, virEventThreadGetContext(priv->eventThread), -- 2.52.0
Currently, bhyveDomainQemuAgentCommand() uses bhyveDomainAgentAvailable() which works only if the agent was already initialized. It should use bhyveDomainEnsureAgent() instead. Also, remove the bhyveDomainAgentAvailable() function, there are no cases when it should be used instead of bhyveDomainEnsureAgent(). Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com> --- src/bhyve/bhyve_driver.c | 35 +---------------------------------- 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 2e7a534396..7bd0cbadb0 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -123,39 +123,6 @@ bhyveDomainObjExitAgent(virDomainObj *obj, qemuAgent *agent) } -static bool -bhyveDomainAgentAvailable(virDomainObj *vm, - bool reportError) -{ - bhyveDomainObjPrivate *priv = vm->privateData; - - if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_RUNNING) { - if (reportError) { - virReportError(VIR_ERR_OPERATION_INVALID, "%s", - _("domain is not running")); - } - return false; - } - - if (!priv->agent) { - if (bhyveFindAgentConfig(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 true; -} - - static int bhyveDomainEnsureAgent(virDomainObj *vm, bool reportError) @@ -2060,7 +2027,7 @@ bhyveDomainQemuAgentCommand(virDomainPtr domain, if (virDomainObjCheckActive(vm) < 0) goto endjob; - if (!bhyveDomainAgentAvailable(vm, true)) + if (bhyveDomainEnsureAgent(vm, true) < 0) goto endjob; agent = bhyveDomainObjEnterAgent(vm); -- 2.52.0
On 6/6/26 09:02, Roman Bogorodskiy wrote:
Roman Bogorodskiy (2): bhyve: process: properly handle misconfigured agent bhyve: fix domainQemuAgentCommand
src/bhyve/bhyve_driver.c | 35 +---------------------------------- src/bhyve/bhyve_process.c | 11 +++++++---- 2 files changed, 8 insertions(+), 38 deletions(-)
Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Michal
participants (2)
-
Michal Prívozník -
Roman Bogorodskiy