Skip to content

FcInit modified by Jailer overwriten when SnapshotLoad #627

@JooyoungPark73

Description

@JooyoungPark73

If I start a Firecracker instance from snapshot with NewNaiveChrootStrategy with WithSnapshot and WithMemoryBackend option like below,

instance, err := firecracker.NewMachine(ctx, cfg,
		firecracker.WithSnapshot("", "snapshot.snapshot",
			firecracker.WithMemoryBackend("File",
				"snapshot.mem",
			),
		),
		firecracker.WithLogger(log.StandardLogger().WithContext(vmcs.Context)),
	)
...
err = instance.Start(ctx)

instance.Handlers.FcInit modified by Jailer is overwritten to loadSnapshotHandlerList by opt

func NewMachine(ctx context.Context, cfg Config, opts ...Opt) (*Machine, error) {
...
	if cfg.JailerCfg != nil {
		m.Handlers.Validation = m.Handlers.Validation.Append(JailerConfigValidationHandler)
		if err := jail(ctx, m, &cfg); err != nil {
			return nil, err
		}
	} else {
...

	for _, opt := range opts {
		opt(m)
func WithSnapshot(memFilePath, snapshotPath string, opts ...WithSnapshotOpt) Opt {
	return func(m *Machine) {
		...
		m.Handlers.Validation = loadSnapshotValidationHandlerList
		m.Handlers.FcInit = loadSnapshotHandlerList
	}
}

I did a workaround by manually inserting the handler after NewMachine() is initialized.
Is there any other way to do it the way it is intended?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions