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"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -256,6 +258,8 @@ type cloudHypervisor struct {
|
|||||||
vmconfig chclient.VmConfig
|
vmconfig chclient.VmConfig
|
||||||
state CloudHypervisorState
|
state CloudHypervisorState
|
||||||
config HypervisorConfig
|
config HypervisorConfig
|
||||||
|
stopped int32
|
||||||
|
mu sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
var clhKernelParams = []Param{
|
var clhKernelParams = []Param{
|
||||||
@ -1081,9 +1085,21 @@ func (clh *cloudHypervisor) ResumeVM(ctx context.Context) error {
|
|||||||
|
|
||||||
// StopVM will stop the Sandbox's VM.
|
// StopVM will stop the Sandbox's VM.
|
||||||
func (clh *cloudHypervisor) StopVM(ctx context.Context, waitOnly bool) (err error) {
|
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})
|
span, _ := katatrace.Trace(ctx, clh.Logger(), "StopVM", clhTracingTags, map[string]string{"sandbox_id": clh.id})
|
||||||
defer span.End()
|
defer span.End()
|
||||||
clh.Logger().WithField("function", "StopVM").Info("Stop Sandbox")
|
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)
|
return clh.terminate(ctx, waitOnly)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user