From 647331ace6b12b5238c9333dda94eda0a0207e51 Mon Sep 17 00:00:00 2001 From: Bo Chen Date: Tue, 1 Dec 2020 17:23:54 -0800 Subject: [PATCH] runtime: clh: Enforce to call 'cleanupVM' for 'stopSandbox' We should always cleanup the vm directory when doing `stopSandbox`, while we are skipping the cleanup process on some error code paths when using cloud-hypervisor driver. Fixes: #1098 Signed-off-by: Bo Chen --- src/runtime/virtcontainers/clh.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/runtime/virtcontainers/clh.go b/src/runtime/virtcontainers/clh.go index 6125d16795..794c9ffad4 100644 --- a/src/runtime/virtcontainers/clh.go +++ b/src/runtime/virtcontainers/clh.go @@ -764,7 +764,14 @@ func (clh *cloudHypervisor) terminate() (err error) { pidRunning = false } - clh.Logger().WithField("PID", pid).Info("Stopping Cloud Hypervisor") + defer func() { + clh.Logger().Debug("cleanup VM") + if err1 := clh.cleanupVM(true); err1 != nil { + clh.Logger().WithError(err1).Error("failed to cleanupVM") + } + }() + + clh.Logger().Debug("Stopping Cloud Hypervisor") if pidRunning { clhRunning, _ := clh.isClhRunning(clhStopSandboxTimeout) @@ -808,11 +815,12 @@ func (clh *cloudHypervisor) terminate() (err error) { return errors.New("virtiofsd config is nil, failed to stop it") } - if err := clh.cleanupVM(true); err != nil { - return err + clh.Logger().Debug("stop virtiofsd") + if err = clh.virtiofsd.Stop(); err != nil { + clh.Logger().Error("failed to stop virtiofsd") } - return clh.virtiofsd.Stop() + return } func (clh *cloudHypervisor) reset() {