mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-05-01 05:04:26 +00:00
clh: don't try to stop clh multiple times
Avoid executing StopVM concurrently when virtiofs dies as a result of clh being stopped in StopVM. Fixes: #5622 Signed-off-by: Alexandru Matei <alexandru.matei@uipath.com>
This commit is contained in:
parent
56641bc230
commit
2631b08ff1
@ -24,6 +24,8 @@ import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
@ -256,6 +258,8 @@ type cloudHypervisor struct {
|
||||
vmconfig chclient.VmConfig
|
||||
state CloudHypervisorState
|
||||
config HypervisorConfig
|
||||
stopped int32
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
var clhKernelParams = []Param{
|
||||
@ -1081,9 +1085,21 @@ func (clh *cloudHypervisor) ResumeVM(ctx context.Context) error {
|
||||
|
||||
// StopVM will stop the Sandbox's VM.
|
||||
func (clh *cloudHypervisor) StopVM(ctx context.Context, waitOnly bool) (err error) {
|
||||
clh.mu.Lock()
|
||||
defer func() {
|
||||
if err == nil {
|
||||
atomic.StoreInt32(&clh.stopped, 1)
|
||||
}
|
||||
clh.mu.Unlock()
|
||||
}()
|
||||
span, _ := katatrace.Trace(ctx, clh.Logger(), "StopVM", clhTracingTags, map[string]string{"sandbox_id": clh.id})
|
||||
defer span.End()
|
||||
clh.Logger().WithField("function", "StopVM").Info("Stop Sandbox")
|
||||
if atomic.LoadInt32(&clh.stopped) != 0 {
|
||||
clh.Logger().Info("Already stopped")
|
||||
return nil
|
||||
}
|
||||
|
||||
return clh.terminate(ctx, waitOnly)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user