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

Commit

Permalink
qemu: Fix disconnectCh issue and simplify it
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Sebastien Boeuf committed Nov 16, 2017
1 parent 711783f commit eeacf8b
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ import (
)

type qmpChannel struct {
ctx context.Context
path string
disconnectCh chan struct{}
wg sync.WaitGroup
qmp *ciaoQemu.QMP
ctx context.Context
path string
wg sync.WaitGroup
qmp *ciaoQemu.QMP
}

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

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

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

timeStart := time.Now()
for {
disconnectCh := make(chan struct{})
qmp, ver, err = ciaoQemu.QMPStart(q.qmpMonitorCh.ctx, q.qmpMonitorCh.path, cfg, disconnectCh)
if err == nil {
break
Expand Down Expand Up @@ -803,11 +802,11 @@ func (q *qemu) waitPod(timeout int) error {
// stopPod will stop the Pod's VM.
func (q *qemu) stopPod() error {
cfg := ciaoQemu.QMPConfig{Logger: newQMPLogger()}
q.qmpControlCh.disconnectCh = make(chan struct{})
disconnectCh := make(chan struct{})
const timeout = time.Duration(10) * time.Second

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

// Wait for the VM disconnection notification
select {
case <-q.qmpControlCh.disconnectCh:
case <-disconnectCh:
break
case <-time.After(timeout):
return fmt.Errorf("Did not receive the VM disconnection notification (timeout %ds)", timeout)
Expand Down

0 comments on commit eeacf8b

Please sign in to comment.