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
3 changes: 1 addition & 2 deletions hypervisor/baseconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"time"

"github.com/cocoonstack/cocoon/config"
"github.com/cocoonstack/cocoon/types"
"github.com/cocoonstack/cocoon/utils"
)

Expand Down Expand Up @@ -76,7 +75,7 @@ func (c *BaseConfig) LoadAndValidateMeta(dir string) (*SnapshotMeta, error) {
}

// PreflightRestore runs the shared restore preflight against this backend's managed roots.
func (c *BaseConfig) PreflightRestore(srcDir string, rec *VMRecord, integrity func(srcDir string, sidecar []*types.StorageConfig) error) (*SnapshotMeta, error) {
func (c *BaseConfig) PreflightRestore(srcDir string, rec *VMRecord, integrity IntegrityCheck) (*SnapshotMeta, error) {
return PreflightRestore(srcDir, c.RootDir, c.Config.RunDir, rec, integrity)
}

Expand Down
27 changes: 27 additions & 0 deletions hypervisor/firecracker/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,33 @@ func (b *broadcaster) readLoop() {
}
}

// cloneLeaseControl is the parent's half of the relay lease protocol; a nil control (no leases held) no-ops.
type cloneLeaseControl struct {
commands *os.File
responses *os.File
}

func (c *cloneLeaseControl) close() {
if c == nil {
return
}
closeFile(c.commands)
closeFile(c.responses)
c.commands = nil
c.responses = nil
}

func (c *cloneLeaseControl) commit() error {
if c == nil {
return nil
}
defer c.close()
if _, err := c.commands.Write([]byte{relayCommitLeasesCommand}); err != nil {
return err
}
return waitRelayLeaseResponse(c.responses, relayLeaseCommitAck, "commit")
}

// IsRelayMode returns true when the process was started as a console relay.
func IsRelayMode() bool {
return os.Getenv(relayEnvKey) == "1"
Expand Down
27 changes: 0 additions & 27 deletions hypervisor/firecracker/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,33 +122,6 @@ func (fc *Firecracker) configureVM(ctx context.Context, hc *http.Client, rec *hy
return nil
}

// cloneLeaseControl is the parent's half of the relay lease protocol; a nil control (no leases held) no-ops.
type cloneLeaseControl struct {
commands *os.File
responses *os.File
}

func (c *cloneLeaseControl) close() {
if c == nil {
return
}
closeFile(c.commands)
closeFile(c.responses)
c.commands = nil
c.responses = nil
}

func (c *cloneLeaseControl) commit() error {
if c == nil {
return nil
}
defer c.close()
if _, err := c.commands.Write([]byte{relayCommitLeasesCommand}); err != nil {
return err
}
return waitRelayLeaseResponse(c.responses, relayLeaseCommitAck, "commit")
}

func (fc *Firecracker) launchProcess(ctx context.Context, rec *hypervisor.VMRecord, sockPath, netnsPath string, deferQuota bool) (int, error) {
pid, _, err := fc.launchProcessWithLeases(ctx, rec, sockPath, netnsPath, nil, deferQuota)
return pid, err
Expand Down
5 changes: 4 additions & 1 deletion hypervisor/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ type SnapshotMeta struct {
BootConfig *types.BootConfig `json:"boot_config,omitempty"`
}

// IntegrityCheck verifies the snapshot files under srcDir against the sidecar's storage configs.
type IntegrityCheck func(srcDir string, sidecar []*types.StorageConfig) error

// RecordSnapshot generates a snapshot ID and records it on the VM's record.
func (b *Backend) RecordSnapshot(ctx context.Context, vmID string) (string, error) {
snapID := utils.GenerateID()
Expand Down Expand Up @@ -235,7 +238,7 @@ func PopulateFromSrc(runDir, srcDir string, clean func(string) error, clone func
}

// PreflightRestore loads and validates the sidecar, runs the backend integrity check and asserts the snapshot role sequence prefixes rec; the validated meta is returned so later phases skip re-reading it.
func PreflightRestore(srcDir, rootDir, runDir string, rec *VMRecord, integrity func(srcDir string, sidecar []*types.StorageConfig) error) (*SnapshotMeta, error) {
func PreflightRestore(srcDir, rootDir, runDir string, rec *VMRecord, integrity IntegrityCheck) (*SnapshotMeta, error) {
meta, err := LoadAndValidateMeta(srcDir, rootDir, runDir)
if err != nil {
return nil, err
Expand Down