Skip to content

Commit

Permalink
fix(host): guest switch to backup (#18835)
Browse files Browse the repository at this point in the history
  • Loading branch information
wanyaoqi authored Nov 30, 2023
1 parent b58cd52 commit 1e33fcf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
18 changes: 11 additions & 7 deletions pkg/hostman/guestman/qemu-kvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,13 +541,6 @@ func (s *SKVMGuestInstance) asyncScriptStart(ctx context.Context, params interfa
return nil, errors.Wrap(err, "fuse mount")
}

if jsonutils.QueryBoolean(data, "need_migrate", false) || s.Desc.IsSlave {
migratePort := s.manager.GetLiveMigrateFreePort()
defer s.manager.unsetPort(migratePort)
migratePortInt64 := int64(migratePort)
s.LiveMigrateDestPort = &migratePortInt64
}

if jsonutils.QueryBoolean(data, "need_migrate", false) {
var sourceDesc = new(desc.SGuestDesc)
err = data.Unmarshal(sourceDesc, "src_desc")
Expand All @@ -558,6 +551,16 @@ func (s *SKVMGuestInstance) asyncScriptStart(ctx context.Context, params interfa
} else {
err = s.updateGuestDesc()
}

// init live migrate listen port
if jsonutils.QueryBoolean(data, "need_migrate", false) || s.Desc.IsSlave {
log.Infof("backup guest alloc dest port %v", s.LiveMigrateDestPort)
migratePort := s.manager.GetLiveMigrateFreePort()
defer s.manager.unsetPort(migratePort)
migratePortInt64 := int64(migratePort)
s.LiveMigrateDestPort = &migratePortInt64
}

if err != nil {
if ctx != nil && len(appctx.AppContextTaskId(ctx)) >= 0 {
hostutils.TaskFailed(ctx, fmt.Sprintf("Async start server failed: %s", err))
Expand Down Expand Up @@ -1829,6 +1832,7 @@ func (s *SKVMGuestInstance) ExitCleanup(clear bool) {
s.Monitor.Disconnect()
s.Monitor = nil
}
s.LiveMigrateDestPort = nil
}

func (s *SKVMGuestInstance) CleanupCpuset() {
Expand Down
1 change: 1 addition & 0 deletions pkg/hostman/guestman/qemu-kvmhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ function nic_mtu() {
s.LiveMigrateUseTls = false
}
} else if s.Desc.IsSlave {
log.Infof("backup guest with dest port %v", s.LiveMigrateDestPort)
input.LiveMigratePort = uint(*s.LiveMigrateDestPort)
}

Expand Down

0 comments on commit 1e33fcf

Please sign in to comment.