Skip to content
This repository was archived by the owner on Apr 3, 2018. It is now read-only.

Commit eeacf8b

Browse files
author
Sebastien Boeuf
committed
qemu: Fix disconnectCh issue and simplify it
The fact that waitPod() implementation for QEMU tries to connect to the VM from a loop, means that every time QMPStart() returns, the disconnect channel is closed. We need a new channel to be setup every time we call QMPStart() again. Also, this commit takes care of removing disconnectCh field from qmpChannel structure since this is not used. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
1 parent 711783f commit eeacf8b

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

qemu.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@ import (
3232
)
3333

3434
type qmpChannel struct {
35-
ctx context.Context
36-
path string
37-
disconnectCh chan struct{}
38-
wg sync.WaitGroup
39-
qmp *ciaoQemu.QMP
35+
ctx context.Context
36+
path string
37+
wg sync.WaitGroup
38+
qmp *ciaoQemu.QMP
4039
}
4140

4241
// QemuState keeps Qemu's state
@@ -762,7 +761,6 @@ func (q *qemu) waitPod(timeout int) error {
762761
return fmt.Errorf("Invalid timeout %ds", timeout)
763762
}
764763

765-
disconnectCh := make(chan struct{})
766764
cfg := ciaoQemu.QMPConfig{Logger: newQMPLogger()}
767765

768766
var qmp *ciaoQemu.QMP
@@ -771,6 +769,7 @@ func (q *qemu) waitPod(timeout int) error {
771769

772770
timeStart := time.Now()
773771
for {
772+
disconnectCh := make(chan struct{})
774773
qmp, ver, err = ciaoQemu.QMPStart(q.qmpMonitorCh.ctx, q.qmpMonitorCh.path, cfg, disconnectCh)
775774
if err == nil {
776775
break
@@ -803,11 +802,11 @@ func (q *qemu) waitPod(timeout int) error {
803802
// stopPod will stop the Pod's VM.
804803
func (q *qemu) stopPod() error {
805804
cfg := ciaoQemu.QMPConfig{Logger: newQMPLogger()}
806-
q.qmpControlCh.disconnectCh = make(chan struct{})
805+
disconnectCh := make(chan struct{})
807806
const timeout = time.Duration(10) * time.Second
808807

809808
q.Logger().Info("Stopping Pod")
810-
qmp, _, err := ciaoQemu.QMPStart(q.qmpControlCh.ctx, q.qmpControlCh.path, cfg, q.qmpControlCh.disconnectCh)
809+
qmp, _, err := ciaoQemu.QMPStart(q.qmpControlCh.ctx, q.qmpControlCh.path, cfg, disconnectCh)
811810
if err != nil {
812811
q.Logger().WithError(err).Error("Failed to connect to QEMU instance")
813812
return err
@@ -825,7 +824,7 @@ func (q *qemu) stopPod() error {
825824

826825
// Wait for the VM disconnection notification
827826
select {
828-
case <-q.qmpControlCh.disconnectCh:
827+
case <-disconnectCh:
829828
break
830829
case <-time.After(timeout):
831830
return fmt.Errorf("Did not receive the VM disconnection notification (timeout %ds)", timeout)

0 commit comments

Comments
 (0)