fix(host): live migrate add timeout (#24127)

This commit is contained in:
wanyaoqi
2026-02-01 20:25:02 +08:00
committed by GitHub
parent 14ece0ba20
commit 69c374f573
2 changed files with 29 additions and 3 deletions
+25 -1
View File
@@ -1169,7 +1169,22 @@ func (s *SGuestLiveMigrateTask) onSetAutoConverge(res string) {
return
}
// https://wiki.qemu.org/Features/AutoconvergeLiveMigration
s.Monitor.MigrateSetParameter("cpu-throttle-initial", options.HostOptions.LiveMigrateCpuThrottleInitial, s.onSetCpuThrottleInitial)
}
func (s *SGuestLiveMigrateTask) onSetCpuThrottleInitial(res string) {
if strings.Contains(strings.ToLower(res), "error") {
s.migrateFailed(fmt.Sprintf("Migrate set params cpu-throttle-initial error: %s", res))
return
}
s.Monitor.MigrateSetParameter("cpu-throttle-increment", options.HostOptions.LiveMigrateCpuThrottleIncrement, s.onSetCpuThrottleIncrement)
}
func (s *SGuestLiveMigrateTask) onSetCpuThrottleIncrement(res string) {
if strings.Contains(strings.ToLower(res), "error") {
s.migrateFailed(fmt.Sprintf("Migrate set params cpu-throttle-increment error: %s", res))
return
}
s.Monitor.MigrateSetCapability("events", "on", s.onMigrateEnableEvents)
}
@@ -1355,6 +1370,7 @@ func (s *SGuestLiveMigrateTask) startMigrateStatusCheck(res string) {
s.migrateFailed(fmt.Sprintf("Migrate error: %s", res))
return
}
s.startRamMigrateTimeout()
s.c = make(chan struct{})
for s.c != nil {
@@ -1401,6 +1417,14 @@ func (s *SGuestLiveMigrateTask) onGetMigrateStatus(stats *monitor.MigrationInfo)
} else if status == "cancelled" {
s.migrateFailed(status)
} else if status == "active" {
if !s.doTimeoutMigrate && s.timeoutAt.Before(time.Now()) {
s.Monitor.SimpleCommand("stop", s.onMigrateStartPostcopy)
s.doTimeoutMigrate = true
}
if s.doTimeoutMigrate {
return
}
var (
ramRemain int64
mbps float64
+4 -2
View File
@@ -32,8 +32,10 @@ type SHostBaseOptions struct {
DisableSecurityGroup bool `help:"disable security group" default:"false"`
HostCpuPassthrough bool `default:"true" help:"if it is true, set qemu cpu type as -cpu host, otherwise, qemu64. default is true"`
LiveMigrateCpuThrottleMax int64 `default:"99" help:"live migrate auto converge cpu throttle max"`
HostCpuPassthrough bool `default:"true" help:"if it is true, set qemu cpu type as -cpu host, otherwise, qemu64. default is true"`
LiveMigrateCpuThrottleMax int64 `default:"99" help:"live migrate auto converge cpu throttle max"`
LiveMigrateCpuThrottleInitial int64 `default:"60" help:"live migrate auto convert cpu throttle initial"`
LiveMigrateCpuThrottleIncrement int64 `default:"20" help:"live migrate auto convert cpu throttle increment"`
DefaultQemuVersion string `help:"Default qemu version" default:"4.2.0"`
NoHpet bool `help:"Disable qemu hpet timer" default:"true"`