Merge pull request #745 from bergwolf/query-migrate

qemu: query migrate status
This commit is contained in:
Peng Tao 2018-10-30 08:50:21 +08:00 committed by GitHub
commit 381ea37d86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 5 deletions

View File

@ -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.
@ -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
}

View File

@ -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-")

View File

@ -81,6 +81,7 @@ const (
qmpCapErrMsg = "Failed to negoatiate QMP capabilities"
qmpCapMigrationBypassSharedMemory = "bypass-shared-memory"
qmpExecCatCmd = "exec:cat"
qmpMigrationWaitTimeout = 5 * time.Second
scsiControllerID = "scsi0"
rngID = "rng0"
@ -1203,6 +1204,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
}