Skip to content

Commit f599c51

Browse files
committed
Do not overwrite handlers in LoadSnapshot
As LoadSnapshot requires only a subset of the default handlers, it was implemented by assigning the FcInit handlers to a smaller list of handlers. However, this meant that it would overwrite the FcInit handlers given by the jailer. This PR fixes this behavior by just removing the unnecessary handlers, instead of overwriting them entirely. Signed-off-by: David Son <[email protected]>
1 parent 563df78 commit f599c51

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

handlers.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -315,24 +315,23 @@ var defaultFcInitHandlerList = HandlerList{}.Append(
315315
ConfigMmdsHandler,
316316
)
317317

318-
var loadSnapshotHandlerList = HandlerList{}.Append(
319-
SetupNetworkHandler,
320-
StartVMMHandler,
321-
CreateLogFilesHandler,
322-
BootstrapLoggingHandler,
323-
LoadSnapshotHandler,
324-
AddVsocksHandler,
325-
)
318+
// When the machine starts, these handlers cannot run
319+
// if we plan to load a snapshot. As these handlers are
320+
// included in defaultFcInitHandlerList, we must remove them
321+
// if WithSnapshot() has been specified.
322+
var loadSnapshotRemoveHandlerList = []Handler{
323+
SetupKernelArgsHandler,
324+
CreateMachineHandler,
325+
CreateBootSourceHandler,
326+
AttachDrivesHandler,
327+
CreateNetworkInterfacesHandler,
328+
ConfigMmdsHandler,
329+
}
326330

327331
var defaultValidationHandlerList = HandlerList{}.Append(
328332
NetworkConfigValidationHandler,
329333
)
330334

331-
var loadSnapshotValidationHandlerList = HandlerList{}.Append(
332-
NetworkConfigValidationHandler,
333-
LoadSnapshotConfigValidationHandler,
334-
)
335-
336335
var defaultHandlers = Handlers{
337336
Validation: defaultValidationHandlerList,
338337
FcInit: defaultFcInitHandlerList,

opts.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,19 @@ func WithSnapshot(memFilePath, snapshotPath string, opts ...WithSnapshotOpt) Opt
7171
opt(&m.Cfg.Snapshot)
7272
}
7373

74-
m.Handlers.Validation = loadSnapshotValidationHandlerList
75-
m.Handlers.FcInit = loadSnapshotHandlerList
74+
m.Handlers.Validation = m.Handlers.Validation.Append(LoadSnapshotConfigValidationHandler)
75+
m.Handlers.FcInit = modifyHandlersForLoadSnapshot(m.Handlers.FcInit)
7676
}
7777
}
7878

79+
func modifyHandlersForLoadSnapshot(l HandlerList) HandlerList {
80+
for _, h := range loadSnapshotRemoveHandlerList {
81+
l = l.Remove(h.Name)
82+
}
83+
l = l.Append(LoadSnapshotHandler)
84+
return l
85+
}
86+
7987
// WithMemoryBackend sets the memory backend to the given type, using the given
8088
// backing file path (a regular file for "File" type, or a UFFD socket path for
8189
// "Uffd" type).

0 commit comments

Comments
 (0)