From af8047349687efff662c831577b00fcbebced4ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 3 Mar 2022 19:10:37 +0100 Subject: [PATCH] clh: stop virtofsd if clh fails to boot up the vm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If, for some reason, we're able to launch cloud hypervisor but not able to boot the VM up, the virtiofsd process would be left behind. Let's ensure, via defer, that we stop virtiofsd in case of errors. Fixes: #3819 Signed-off-by: Fabiano FidĂȘncio --- src/runtime/virtcontainers/clh.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/runtime/virtcontainers/clh.go b/src/runtime/virtcontainers/clh.go index c77ce15309..95642dd396 100644 --- a/src/runtime/virtcontainers/clh.go +++ b/src/runtime/virtcontainers/clh.go @@ -565,12 +565,16 @@ func (clh *cloudHypervisor) StartVM(ctx context.Context, timeout int) error { if err != nil { return err } + defer func() { + if err != nil { + if shutdownErr := clh.stopVirtiofsDaemon(ctx); shutdownErr != nil { + clh.Logger().WithError(shutdownErr).Warn("error shutting down VirtiofsDaemon") + } + } + }() pid, err := clh.launchClh() if err != nil { - if shutdownErr := clh.stopVirtiofsDaemon(ctx); shutdownErr != nil { - clh.Logger().WithError(shutdownErr).Warn("error shutting down VirtiofsDaemon") - } return fmt.Errorf("failed to launch cloud-hypervisor: %q", err) } clh.state.PID = pid