Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
qemu: make saveSandbox wait for migration completion
Browse files Browse the repository at this point in the history
Then we can remove the arbitrary sleep waiting for migration
completion when creating a tempalte vm.

Fixes: #728

Signed-off-by: Peng Tao <[email protected]>
  • Loading branch information
bergwolf committed Oct 9, 2018
1 parent c3cfe82 commit eb77a41
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
4 changes: 0 additions & 4 deletions virtcontainers/factory/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ type template struct {

var templateProxyType = vc.KataBuiltInProxyType
var templateWaitForAgent = 2 * time.Second
var templateWaitForMigration = 1 * time.Second

// Fetch finds and returns a pre-built template factory.
// TODO: save template metadata and fetch from storage.
Expand Down Expand Up @@ -145,9 +144,6 @@ func (t *template) createTemplateVM(ctx context.Context) error {
return err
}

// qemu QMP does not wait for migration to finish...
time.Sleep(templateWaitForMigration)

return nil
}

Expand Down
1 change: 0 additions & 1 deletion virtcontainers/factory/template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
func TestTemplateFactory(t *testing.T) {
assert := assert.New(t)

templateWaitForMigration = 1 * time.Microsecond
templateWaitForAgent = 1 * time.Microsecond

testDir, _ := ioutil.TempDir("", "vmfactory-tmp-")
Expand Down
24 changes: 24 additions & 0 deletions virtcontainers/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const (
qmpCapErrMsg = "Failed to negoatiate QMP capabilities"
qmpCapMigrationBypassSharedMemory = "bypass-shared-memory"
qmpExecCatCmd = "exec:cat"
qmpMigrationWaitTimeout = 5 * time.Second

scsiControllerID = "scsi0"
rngID = "rng0"
Expand Down Expand Up @@ -1181,6 +1182,29 @@ func (q *qemu) saveSandbox() error {
return err
}

t := time.NewTimer(qmpMigrationWaitTimeout)
defer t.Stop()
for {
status, err := q.qmpMonitorCh.qmp.ExecuteQueryMigration(q.qmpMonitorCh.ctx)
if err != nil {
q.Logger().WithError(err).Error("failed to query migration status")
return err
}
if status.Status == "completed" {
break
}

select {
case <-t.C:
q.Logger().WithField("migration-status", status).Error("timeout waiting for qemu migration")
return fmt.Errorf("timed out after %d seconds waiting for qemu migration", qmpMigrationWaitTimeout)
default:
// migration in progress
q.Logger().WithField("migration-status", status).Debug("migration in progress")
time.Sleep(100 * time.Millisecond)
}
}

return nil
}

Expand Down

0 comments on commit eb77a41

Please sign in to comment.