On Thu, Sep 25, 2025 at 07:30:23PM +0200, Roman Bogorodskiy wrote:
When the virBhyveProcessStart() fails early, make sure to execute
the "stopped" and "release" hooks.

Spotted while running TCK hooks tests against the bhyve driver.

Signed-off-by: Roman Bogorodskiy <[email protected]>
---
src/bhyve/bhyve_process.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/bhyve/bhyve_process.c b/src/bhyve/bhyve_process.c
index 4bfd511bae..4fb7e642e1 100644
--- a/src/bhyve/bhyve_process.c
+++ b/src/bhyve/bhyve_process.c
@@ -413,18 +413,24 @@ virBhyveProcessStart(bhyveConn *driver,
{
    /* Run an early hook to setup missing devices. */
    if (bhyveProcessStartHook(driver, vm, VIR_HOOK_BHYVE_OP_PREPARE) < 0)
-        return -1;
+        goto cleanup;

    if (flags & VIR_BHYVE_PROCESS_START_AUTODESTROY)
        virCloseCallbacksDomainAdd(vm, conn, bhyveProcessAutoDestroy);

    if (bhyveProcessPrepareDomain(driver, vm, flags) < 0)
-        return -1;
+        goto cleanup;

    if (bhyveProcessPrepareHost(driver, vm->def, flags) < 0)
-        return -1;
+        goto cleanup;


I wanted to suggest that if you want to avoid the goto's, then just
stick the above in a "StartPrep" function and call it here and then the
stop hooks if it fails.  In the end the diff was larger than what you
suggested =)

So whichever you like more,

Reviewed-by: Martin Kletzander <[email protected]>

and safe for freeze.

    return virBhyveProcessStartImpl(driver, vm, reason);
+
+ cleanup:
+    bhyveProcessStopHook(driver, vm, VIR_HOOK_BHYVE_OP_STOPPED);
+    bhyveProcessStopHook(driver, vm, VIR_HOOK_BHYVE_OP_RELEASE);
+
+    return -1;
}

static void
--
2.51.0

Attachment: signature.asc
Description: PGP signature

Reply via email to