mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-27 15:57:09 +00:00
qemu: early exit from Check if the process was stopped
Fixes: #5625 Signed-off-by: Alexandru Matei <alexandru.matei@uipath.com>
This commit is contained in:
parent
7e481f2179
commit
a04afab74d
@ -21,6 +21,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
@ -109,7 +110,7 @@ type qemu struct {
|
|||||||
|
|
||||||
nvdimmCount int
|
nvdimmCount int
|
||||||
|
|
||||||
stopped bool
|
stopped int32
|
||||||
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
}
|
}
|
||||||
@ -976,7 +977,7 @@ func (q *qemu) StopVM(ctx context.Context, waitOnly bool) (err error) {
|
|||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
q.Logger().Info("Stopping Sandbox")
|
q.Logger().Info("Stopping Sandbox")
|
||||||
if q.stopped {
|
if atomic.LoadInt32(&q.stopped) != 0 {
|
||||||
q.Logger().Info("Already stopped")
|
q.Logger().Info("Already stopped")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -984,7 +985,7 @@ func (q *qemu) StopVM(ctx context.Context, waitOnly bool) (err error) {
|
|||||||
defer func() {
|
defer func() {
|
||||||
q.cleanupVM()
|
q.cleanupVM()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
q.stopped = true
|
atomic.StoreInt32(&q.stopped, 1)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -2570,7 +2571,7 @@ func (q *qemu) toGrpc(ctx context.Context) ([]byte, error) {
|
|||||||
func (q *qemu) Save() (s hv.HypervisorState) {
|
func (q *qemu) Save() (s hv.HypervisorState) {
|
||||||
|
|
||||||
// If QEMU isn't even running, there isn't any state to Save
|
// If QEMU isn't even running, there isn't any state to Save
|
||||||
if q.stopped {
|
if atomic.LoadInt32(&q.stopped) != 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2621,6 +2622,10 @@ func (q *qemu) Load(s hv.HypervisorState) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (q *qemu) Check() error {
|
func (q *qemu) Check() error {
|
||||||
|
if atomic.LoadInt32(&q.stopped) != 0 {
|
||||||
|
return fmt.Errorf("qemu is not running")
|
||||||
|
}
|
||||||
|
|
||||||
q.memoryDumpFlag.Lock()
|
q.memoryDumpFlag.Lock()
|
||||||
defer q.memoryDumpFlag.Unlock()
|
defer q.memoryDumpFlag.Unlock()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user