Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. diff --git a/virtcontainers/qemu.go b/virtcontainers/qemu.go
  2. index 8560df9..45441c7 100644
  3. --- a/virtcontainers/qemu.go
  4. +++ b/virtcontainers/qemu.go
  5. @@ -96,6 +96,8 @@ const (
  6. qmpCapErrMsg = "Failed to negoatiate QMP capabilities"
  7. qmpExecCatCmd = "exec:cat"
  8.  
  9. + qemuExitWaitSeconds = 5
  10. +
  11. scsiControllerID = "scsi0"
  12. rngID = "rng0"
  13. vsockKernelOption = "agent.use_vsock"
  14. @@ -749,7 +751,7 @@ func (q *qemu) stopSandbox() error {
  15. return err
  16. }
  17.  
  18. - return nil
  19. + return q.waitQemuDown(qemuExitWaitSeconds)
  20. }
  21.  
  22. func (q *qemu) cleanupVM() error {
  23. @@ -850,6 +852,37 @@ func (q *qemu) qmpShutdown() {
  24. }
  25. }
  26.  
  27. +// waitQemuDown will watch for the QMP monitor socket to disappear indicating
  28. +// that QEMU process has actually exited. This can take 10-100ms sometimes
  29. +func (q *qemu) waitQemuDown(timeout int) error {
  30. + q.Logger().Debug("Waiting for qmp socket to disappear: %s", q.qmpMonitorCh.path)
  31. + q.qmpShutdown()
  32. + timeStart := time.Now()
  33. + for {
  34. + _, err := os.Stat(q.qmpMonitorCh.path)
  35. +
  36. + if err != nil {
  37. + if os.IsNotExist(err) { // happy path
  38. + q.Logger().Debug("No longer able to access %s, QEMU appears to have exited", q.qmpMonitorCh.path)
  39. + break
  40. + } else {
  41. + q.Logger().WithError(err).Error("Unexpected error checking for QMP socket on %s", q.qmpMonitorCh.path)
  42. + return fmt.Errorf("Unexpected error checking for QMP socket on %s: %v", q.qmpMonitorCh.path, err)
  43. + }
  44. +
  45. + }
  46. +
  47. + if int(time.Now().Sub(timeStart).Seconds()) > timeout {
  48. + return fmt.Errorf("QEMU still active(timeout %ds)", timeout)
  49. + }
  50. +
  51. + time.Sleep(time.Duration(50) * time.Millisecond)
  52. + }
  53. +
  54. + return nil
  55. +
  56. +}
  57. +
  58. func (q *qemu) addDeviceToBridge(ID string) (string, types.PCIBridge, error) {
  59. var err error
  60. var addr uint32
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement