From 69c374f573b07441d589515e915a5f078fccadcc Mon Sep 17 00:00:00 2001 From: wanyaoqi <18528551+wanyaoqi@users.noreply.github.com> Date: Sun, 1 Feb 2026 20:25:02 +0800 Subject: [PATCH] fix(host): live migrate add timeout (#24127) --- pkg/hostman/guestman/guesttasks.go | 26 +++++++++++++++++++++++++- pkg/hostman/options/options.go | 6 ++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/pkg/hostman/guestman/guesttasks.go b/pkg/hostman/guestman/guesttasks.go index 95439a9059..e554c2fe8a 100644 --- a/pkg/hostman/guestman/guesttasks.go +++ b/pkg/hostman/guestman/guesttasks.go @@ -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 diff --git a/pkg/hostman/options/options.go b/pkg/hostman/options/options.go index 609998e69b..b0b60f5d1b 100644 --- a/pkg/hostman/options/options.go +++ b/pkg/hostman/options/options.go @@ -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"`