Merge pull request #12995 from swordqiu/hotfix/qj-migrate-timeout-error

fix: 1. migration timeout applicable to shared storage migrate only
This commit is contained in:
Zexi Li
2021-12-23 09:58:21 +08:00
committed by GitHub
6 changed files with 46 additions and 19 deletions
+10 -5
View File
@@ -103,6 +103,11 @@ func (self *GuestMigrateTask) SaveScheduleResult(ctx context.Context, obj ISched
body := jsonutils.NewDict()
body.Set("target_host_id", jsonutils.NewString(targetHostId))
// for params notes
body.Set("target_host_name", jsonutils.NewString(targetHost.Name))
srcHost := models.HostManager.FetchHostById(guest.HostId)
body.Set("source_host_name", jsonutils.NewString(srcHost.Name))
body.Set("source_host_id", jsonutils.NewString(srcHost.Id))
disks, _ := guest.GetGuestDisks()
disk := disks[0].GetDisk()
@@ -184,7 +189,7 @@ func (self *GuestMigrateTask) OnCachedCdromComplete(ctx context.Context, guest *
if !jsonutils.QueryBoolean(self.Params, "is_rescue_mode", false) {
host, _ := guest.GetHost()
url := fmt.Sprintf("%s/servers/%s/src-prepare-migrate", host.ManagerUri, guest.Id)
self.SetStage("OnSrcPrepareComplete", nil)
self.SetStage("OnSrcPrepareComplete", body)
_, _, err := httputils.JSONRequest(httputils.GetDefaultClient(), ctx, "POST",
url, header, body, false)
if err != nil {
@@ -230,7 +235,7 @@ func (self *GuestMigrateTask) OnSrcPrepareComplete(ctx context.Context, guest *m
headers := self.GetTaskRequestHeader()
url := fmt.Sprintf("%s/servers/%s/dest-prepare-migrate", targetHost.ManagerUri, guest.Id)
self.SetStage("OnMigrateConfAndDiskComplete", nil)
self.SetStage("OnMigrateConfAndDiskComplete", body)
_, _, err = httputils.JSONRequest(httputils.GetDefaultClient(),
ctx, "POST", url, headers, body, false)
if err != nil {
@@ -472,7 +477,7 @@ func (self *GuestLiveMigrateTask) OnGuestSyncStatus(ctx context.Context, guest *
func (self *GuestMigrateTask) TaskComplete(ctx context.Context, guest *models.SGuest) {
self.SetStageComplete(ctx, nil)
db.OpsLog.LogEvent(guest, db.ACT_MIGRATE, "Migrate success", self.UserCred)
logclient.AddActionLogWithContext(ctx, guest, logclient.ACT_MIGRATE, "", self.UserCred, true)
logclient.AddActionLogWithContext(ctx, guest, logclient.ACT_MIGRATE, self.Params, self.UserCred, true)
}
func (self *GuestMigrateTask) TaskFailed(ctx context.Context, guest *models.SGuest, reason jsonutils.JSONObject) {
@@ -505,7 +510,7 @@ func (self *ManagedGuestMigrateTask) MigrateStart(ctx context.Context, guest *mo
func (self *ManagedGuestMigrateTask) OnMigrateComplete(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
guest := obj.(*models.SGuest)
logclient.AddActionLogWithContext(ctx, guest, logclient.ACT_MIGRATE, data, self.UserCred, true)
logclient.AddActionLogWithContext(ctx, guest, logclient.ACT_MIGRATE, self.Params, self.UserCred, true)
db.OpsLog.LogEvent(guest, db.ACT_MIGRATE, guest.GetShortDesc(ctx), self.UserCred)
if jsonutils.QueryBoolean(self.Params, "auto_start", false) {
self.SetStage("OnGuestStartSucc", nil)
@@ -558,7 +563,7 @@ func (self *ManagedGuestLiveMigrateTask) MigrateStart(ctx context.Context, guest
func (self *ManagedGuestLiveMigrateTask) OnMigrateComplete(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) {
self.SetStage("OnGuestSyncStatus", nil)
db.OpsLog.LogEvent(guest, db.ACT_MIGRATE, guest.GetShortDesc(ctx), self.UserCred)
logclient.AddActionLogWithContext(ctx, guest, logclient.ACT_MIGRATE, data, self.UserCred, true)
logclient.AddActionLogWithContext(ctx, guest, logclient.ACT_MIGRATE, self.Params, self.UserCred, true)
guest.StartSyncstatus(ctx, self.UserCred, self.GetTaskId())
}
+14 -6
View File
@@ -55,13 +55,21 @@ func AddDownloadHandler(prefix string, app *appsrv.Application) {
nil, "snapshot_download", nil)
customizeHandlerInfo(hi)
app.AddHandler("HEAD", fmt.Sprintf("%s/%s/disks/<storageId>/<diskId>",
prefix, kerword), auth.Authenticate(diskHead))
app.AddHandler("HEAD",
hi = app.AddHandler2("HEAD", fmt.Sprintf("%s/%s/disks/<storageId>/<diskId>",
prefix, kerword), auth.Authenticate(diskHead),
nil, "head_disk_download", nil)
customizeHandlerInfo(hi)
hi = app.AddHandler2("HEAD",
fmt.Sprintf("%s/%s/snapshots/<storageId>/<diskId>/<snapshotId>",
prefix, kerword), auth.Authenticate(snapshotHead))
app.AddHandler("HEAD",
fmt.Sprintf("%s/%s/images/<id>", prefix, kerword), auth.Authenticate(imageCacheHead))
prefix, kerword), auth.Authenticate(snapshotHead),
nil, "head_snapshot_download", nil)
customizeHandlerInfo(hi)
hi = app.AddHandler2("HEAD",
fmt.Sprintf("%s/%s/images/<id>", prefix, kerword), auth.Authenticate(imageCacheHead),
nil, "head_image", nil)
customizeHandlerInfo(hi)
}
}
+3 -3
View File
@@ -514,8 +514,8 @@ func (s *SGuestLiveMigrateTask) startMigrate(res string) {
if migSeconds < options.HostOptions.MinMigrateTimeoutSeconds {
migSeconds = options.HostOptions.MinMigrateTimeoutSeconds
}
log.Infof("migrate timeout seconds: %d", migSeconds)
s.timeoutAt = time.Now().Add(time.Second * time.Duration(migSeconds))
log.Infof("migrate timeout seconds: %d now: %v expectfinial: %v", migSeconds, time.Now(), s.timeoutAt)
var copyIncremental = false
if s.params.IsLocal {
copyIncremental = true
@@ -550,8 +550,8 @@ func (s *SGuestLiveMigrateTask) onGetMigrateStatus(status string) {
s.migrateTask = nil
close(s.c)
hostutils.TaskFailed(s.ctx, fmt.Sprintf("Query migrate got status: %s", status))
} else if !s.doTimeoutMigrate {
if s.timeoutAt.After(time.Now()) {
} else if !s.params.IsLocal && !s.doTimeoutMigrate {
if s.timeoutAt.Before(time.Now()) {
log.Warningf("migrate timeout, force stop to finish migrate")
// timeout, start memory postcopy
// https://wiki.qemu.org/Features/PostCopyLiveMigration
+4 -2
View File
@@ -167,9 +167,11 @@ function nic_mtu() {
// warning: Number of hotpluggable cpus requested (128)
// exceeds the recommended cpus supported by KVM (32)
cmd += fmt.Sprintf(" -smp %d,maxcpus=32", cpu)
cmd += fmt.Sprintf(" -smp cpus=%d,sockets=2,cores=64,maxcpus=128", cpu)
cmd += fmt.Sprintf(" -name %s", name)
cmd += fmt.Sprintf(" -uuid %s", uuid)
if options.HostOptions.EnableVmUuid {
cmd += fmt.Sprintf(" -uuid %s", uuid)
}
cmd += fmt.Sprintf(" -m %dM,slots=4,maxmem=262144M", mem)
if options.HostOptions.HugepagesOption == "native" {
+13 -3
View File
@@ -163,6 +163,14 @@ func (s *SKVMGuestInstance) disablePvpanicDev() bool {
return val == "true"
}
func isLocalStorage(disk api.GuestdiskJsonDesc) bool {
if disk.StorageType == api.STORAGE_LOCAL || len(disk.StorageType) == 0 {
return true
} else {
return false
}
}
func (s *SKVMGuestInstance) getDriveDesc(disk api.GuestdiskJsonDesc, isArm bool) string {
format := disk.Format
diskIndex := disk.Index
@@ -179,13 +187,13 @@ func (s *SKVMGuestInstance) getDriveDesc(disk api.GuestdiskJsonDesc, isArm bool)
cmd += ",format=raw"
}
cmd += fmt.Sprintf(",cache=%s", cacheMode)
if disk.StorageType == api.STORAGE_LOCAL {
if isLocalStorage(disk) {
cmd += fmt.Sprintf(",aio=%s", aioMode)
}
if len(disk.Url) > 0 { // # a remote file backed image
cmd += ",copy-on-read=on"
}
if disk.StorageType == api.STORAGE_LOCAL {
if isLocalStorage(disk) {
cmd += ",file.locking=off"
}
// #cmd += ",media=disk"
@@ -548,7 +556,9 @@ function nic_mtu() {
// #cmd += " -g 800x600"
cmd += fmt.Sprintf(" -smp cpus=%d,sockets=2,cores=64,maxcpus=128", cpu)
cmd += fmt.Sprintf(" -name %s", name)
cmd += fmt.Sprintf(" -uuid %s", uuid)
if options.HostOptions.EnableVmUuid {
cmd += fmt.Sprintf(" -uuid %s", uuid)
}
cmd += fmt.Sprintf(" -m %dM,slots=4,maxmem=524288M", mem)
if s.manager.host.IsHugepagesEnabled() {
+2
View File
@@ -155,6 +155,8 @@ type SHostOptions struct {
DisableGPU bool `help:"force disable GPU" default:"false" json:"disable_gpu"`
EthtoolEnableGso bool `help:"use ethtool to turn on or off GSO(generic segment offloading)" default:"false" json:"ethtool_enable_gso"`
EnableVmUuid bool `help:"enable vm UUID" default:"true" json:"enable_vm_uuid"`
}
var (