From b2a7eea4a74093790f98a191115757f644399828 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 3 Mar 2022 19:23:22 +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 Backports: #3823 Signed-off-by: Fabiano FidĂȘncio --- src/runtime/virtcontainers/clh.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/runtime/virtcontainers/clh.go b/src/runtime/virtcontainers/clh.go index c89b18a1a..ca0474dca 100644 --- a/src/runtime/virtcontainers/clh.go +++ b/src/runtime/virtcontainers/clh.go @@ -405,15 +405,20 @@ func (clh *cloudHypervisor) StartVM(ctx context.Context, timeout int) error { return err } clh.state.VirtiofsdPID = pid + + defer func() { + if err != nil { + if shutdownErr := clh.virtiofsd.Stop(ctx); shutdownErr != nil { + clh.Logger().WithError(shutdownErr).Warn("error shutting down VirtiofsDaemon") + } + } + }() } else { return errors.New("cloud-hypervisor only supports virtio based file sharing") } pid, err := clh.launchClh() if err != nil { - if shutdownErr := clh.virtiofsd.Stop(ctx); shutdownErr != nil { - clh.Logger().WithError(shutdownErr).Warn("error shutting down Virtiofsd") - } return fmt.Errorf("failed to launch cloud-hypervisor: %q", err) } clh.state.PID = pid