Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,24 +315,23 @@ var defaultFcInitHandlerList = HandlerList{}.Append(
ConfigMmdsHandler,
)

var loadSnapshotHandlerList = HandlerList{}.Append(
SetupNetworkHandler,
StartVMMHandler,
CreateLogFilesHandler,
BootstrapLoggingHandler,
LoadSnapshotHandler,
AddVsocksHandler,
)
// When the machine starts, these handlers cannot run
// if we plan to load a snapshot. As these handlers are
// included in defaultFcInitHandlerList, we must remove them
// if WithSnapshot() has been specified.
var loadSnapshotRemoveHandlerList = []Handler{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a comment here for future reference on why we need to have a filter list?

SetupKernelArgsHandler,
CreateMachineHandler,
CreateBootSourceHandler,
AttachDrivesHandler,
CreateNetworkInterfacesHandler,
ConfigMmdsHandler,
}

var defaultValidationHandlerList = HandlerList{}.Append(
NetworkConfigValidationHandler,
)

var loadSnapshotValidationHandlerList = HandlerList{}.Append(
NetworkConfigValidationHandler,
LoadSnapshotConfigValidationHandler,
)

var defaultHandlers = Handlers{
Validation: defaultValidationHandlerList,
FcInit: defaultFcInitHandlerList,
Expand Down
12 changes: 10 additions & 2 deletions opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,19 @@ func WithSnapshot(memFilePath, snapshotPath string, opts ...WithSnapshotOpt) Opt
opt(&m.Cfg.Snapshot)
}

m.Handlers.Validation = loadSnapshotValidationHandlerList
m.Handlers.FcInit = loadSnapshotHandlerList
m.Handlers.Validation = m.Handlers.Validation.Append(LoadSnapshotConfigValidationHandler)
m.Handlers.FcInit = modifyHandlersForLoadSnapshot(m.Handlers.FcInit)
}
}

func modifyHandlersForLoadSnapshot(l HandlerList) HandlerList {
for _, h := range loadSnapshotRemoveHandlerList {
l = l.Remove(h.Name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Remove handle the case when h.Name is not present in the Handler list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
l = l.Append(LoadSnapshotHandler)
return l
}

// WithMemoryBackend sets the memory backend to the given type, using the given
// backing file path (a regular file for "File" type, or a UFFD socket path for
// "Uffd" type).
Expand Down
Loading