Skip to content
Open
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
5 changes: 5 additions & 0 deletions pkg/sentry/platform/kvm/kvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ func (k *KVM) NewContext(pkgcontext.Context) platform.Context {
}
}

// Name implements platform.Platform.Name.
func (*KVM) Name() string {
return "kvm"
}

type constructor struct{}

func (*constructor) New(opts platform.Options) (platform.Platform, error) {
Expand Down
3 changes: 3 additions & 0 deletions pkg/sentry/platform/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ type Platform interface {
// in parallel. Concurrent calls to Context.Switch() beyond
// ConcurrencyCount() may block until previous calls have returned.
ConcurrencyCount() int

// Name returns the name of the platform.
Name() string
}

// NoCPUPreemptionDetection implements Platform.DetectsCPUPreemption and
Expand Down
5 changes: 5 additions & 0 deletions pkg/sentry/platform/ptrace/ptrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ func (*PTrace) ConcurrencyCount() int {
return math.MaxInt
}

// Name implements platform.Platform.Name.
func (*PTrace) Name() string {
return "ptrace"
}

type constructor struct{}

func (*constructor) New(platform.Options) (platform.Platform, error) {
Expand Down
5 changes: 5 additions & 0 deletions pkg/sentry/platform/systrap/systrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,11 @@ func (*Systrap) ConcurrencyCount() int {
return maxSysmsgThreads
}

// Name implements platform.Platform.Name.
func (*Systrap) Name() string {
return "systrap"
}

type constructor struct{}

func (*constructor) New(opts platform.Options) (platform.Platform, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/sentry/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (opts SaveOpts) Save(ctx context.Context, k *kernel.Kernel, w *watchdog.Wat
if opts.Metadata == nil {
opts.Metadata = make(map[string]string)
}
addSaveMetadata(opts.Metadata)
addSaveMetadata(opts.Metadata, k.Platform.Name())

// Open the statefile.
wc, err := statefile.NewWriter(opts.Destination, opts.Key, opts.Metadata)
Expand Down
7 changes: 5 additions & 2 deletions pkg/sentry/state/state_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ import (
"gvisor.dev/gvisor/pkg/log"
)

// The save metadata keys for timestamp.
// The save metadata keys for timestamp and platform.
const (
cpuUsage = "cpu_usage"
metadataTimestamp = "timestamp"
MetadataPlatform = "platform"
)

func addSaveMetadata(m map[string]string) {
func addSaveMetadata(m map[string]string, platform string) {
t, err := CPUTime()
if err != nil {
log.Warningf("Error getting cpu time: %v", err)
Expand All @@ -45,4 +46,6 @@ func addSaveMetadata(m map[string]string) {
m[cpuUsage] = t.String()

m[metadataTimestamp] = fmt.Sprintf("%v", time.Now())

m[MetadataPlatform] = platform
}
5 changes: 5 additions & 0 deletions runsc/boot/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,11 @@ func (cm *containerManager) Restore(o *RestoreOpts, _ *struct{}) error {
if checkpointVersion != currentVersion {
return fmt.Errorf("runsc version does not match across checkpoint restore, checkpoint: %v current: %v", checkpointVersion, currentVersion)
}
checkpointPlatform := metadata[state.MetadataPlatform]
currentPlatform := cm.l.k.Platform.Name()
if checkpointPlatform != currentPlatform {
return fmt.Errorf("platform does not match across checkpoint restore, checkpoint: %v current: %v", checkpointPlatform, currentPlatform)
}
return cm.restorer.restoreContainerInfo(cm.l, &cm.l.root, timer.Fork("cont:root"))
}

Expand Down