Restore listening connections when netstack s/r is enabled.

This CL restores the listening connections when netstack s/r is enabled.
The changes include:
- New method as a workaround to replace the new routes and nics to the loaded
stack after restore.
- New Restore() for transport layer protocols to restore the protocol level
background workers.
- Adds afterLoad() method for fdbased processors.
- Adds a test to verify listening connection is restored after checkpointing
with netstack s/r enabled.
- Few other changes to save restore fields to enable netstack s/r.

PiperOrigin-RevId: 698453124
This commit is contained in:
Nayana Bidari
2024-11-20 11:13:57 -08:00
committed by gVisor bot
parent 488d5d2f48
commit df9ba5fb67
22 changed files with 259 additions and 69 deletions
+1 -1
View File
@@ -34,7 +34,7 @@ func (s *sock) loadTimestamp(_ context.Context, nsec int64) {
}
func (s *Stack) saveStack() *stack.Stack {
if s.shouldSaveRestoreStack {
if s.IsSaveRestoreEnabled() {
return s.Stack
}
+1 -1
View File
@@ -22,7 +22,7 @@ import (
// afterLoad is invoked by stateify.
func (s *Stack) afterLoad(ctx context.Context) {
if s.shouldSaveRestoreStack {
if s.IsSaveRestoreEnabled() {
// This indicates that netstack s/r is enabled and the stack
// should not be replaced with the new stack from context.
return
+18 -3
View File
@@ -40,16 +40,23 @@ import (
//
// +stateify savable
type Stack struct {
Stack *stack.Stack `state:".(*stack.Stack)"`
shouldSaveRestoreStack bool
Stack *stack.Stack `state:".(*stack.Stack)"`
}
// EnableSaveRestore enables netstack s/r.
func (s *Stack) EnableSaveRestore() error {
s.shouldSaveRestoreStack = true
s.Stack.EnableSaveRestore()
return nil
}
// IsSaveRestoreEnabled implements inet.Stack.IsSaveRestoreEnabled.
func (s *Stack) IsSaveRestoreEnabled() bool {
if s.Stack == nil {
return false
}
return s.Stack.IsSaveRestoreEnabled()
}
// Destroy implements inet.Stack.Destroy.
func (s *Stack) Destroy() {
s.Stack.Close()
@@ -912,6 +919,14 @@ func (s *Stack) Restore() {
s.Stack.Restore()
}
// ReplaceConfig implements inet.Stack.ReplaceConfig.
func (s *Stack) ReplaceConfig(st inet.Stack) {
if _, ok := st.(*Stack); !ok {
panic("netstack.Stack cannot be nil when netstack s/r is enabled")
}
s.Stack.ReplaceConfig(st.(*Stack).Stack)
}
// Resume implements inet.Stack.Resume.
func (s *Stack) Resume() {
s.Stack.Resume()