Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/virtcontainers/qemu.go b/virtcontainers/qemu.go
- index 8560df9..45441c7 100644
- --- a/virtcontainers/qemu.go
- +++ b/virtcontainers/qemu.go
- @@ -96,6 +96,8 @@ const (
- qmpCapErrMsg = "Failed to negoatiate QMP capabilities"
- qmpExecCatCmd = "exec:cat"
- + qemuExitWaitSeconds = 5
- +
- scsiControllerID = "scsi0"
- rngID = "rng0"
- vsockKernelOption = "agent.use_vsock"
- @@ -749,7 +751,7 @@ func (q *qemu) stopSandbox() error {
- return err
- }
- - return nil
- + return q.waitQemuDown(qemuExitWaitSeconds)
- }
- func (q *qemu) cleanupVM() error {
- @@ -850,6 +852,37 @@ func (q *qemu) qmpShutdown() {
- }
- }
- +// waitQemuDown will watch for the QMP monitor socket to disappear indicating
- +// that QEMU process has actually exited. This can take 10-100ms sometimes
- +func (q *qemu) waitQemuDown(timeout int) error {
- + q.Logger().Debug("Waiting for qmp socket to disappear: %s", q.qmpMonitorCh.path)
- + q.qmpShutdown()
- + timeStart := time.Now()
- + for {
- + _, err := os.Stat(q.qmpMonitorCh.path)
- +
- + if err != nil {
- + if os.IsNotExist(err) { // happy path
- + q.Logger().Debug("No longer able to access %s, QEMU appears to have exited", q.qmpMonitorCh.path)
- + break
- + } else {
- + q.Logger().WithError(err).Error("Unexpected error checking for QMP socket on %s", q.qmpMonitorCh.path)
- + return fmt.Errorf("Unexpected error checking for QMP socket on %s: %v", q.qmpMonitorCh.path, err)
- + }
- +
- + }
- +
- + if int(time.Now().Sub(timeStart).Seconds()) > timeout {
- + return fmt.Errorf("QEMU still active(timeout %ds)", timeout)
- + }
- +
- + time.Sleep(time.Duration(50) * time.Millisecond)
- + }
- +
- + return nil
- +
- +}
- +
- func (q *qemu) addDeviceToBridge(ID string) (string, types.PCIBridge, error) {
- var err error
- var addr uint32
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement