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
12 changes: 12 additions & 0 deletions pkg/sentry/state/checkpointfiles/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("//tools:defs.bzl", "go_library")

package(
default_applicable_licenses = ["//:license"],
licenses = ["notice"],
)

go_library(
name = "checkpointfiles",
srcs = ["checkpointfiles.go"],
visibility = ["//pkg/sentry:internal"],
)
31 changes: 31 additions & 0 deletions pkg/sentry/state/checkpointfiles/checkpointfiles.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2025 The gVisor Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package checkpointfiles defines constants used when sentry state is
// checkpointed to multiple files in a directory rather than to an opaque FD.
package checkpointfiles

const (
// StateFileName is the file in an image-path directory which contains the
// sentry object graph.
StateFileName = "checkpoint.img"

// PagesMetadataFileName is the file in an image-path directory containing
// MemoryFile metadata.
PagesMetadataFileName = "pages_meta.img"

// PagesFileName is the file in an image-path directory containing
// MemoryFile page contents.
PagesFileName = "pages.img"
)
9 changes: 0 additions & 9 deletions runsc/boot/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,6 @@ import (
)

const (
// CheckpointStateFileName is the file within the given image-path's
// directory which contains the container's saved state.
CheckpointStateFileName = "checkpoint.img"
// CheckpointPagesMetadataFileName is the file within the given image-path's
// directory containing the container's MemoryFile metadata.
CheckpointPagesMetadataFileName = "pages_meta.img"
// CheckpointPagesFileName is the file within the given image-path's
// directory containing the container's MemoryFile pages.
CheckpointPagesFileName = "pages.img"
// VersionKey is the key used to save runsc version in the save metadata and compare
// it across checkpoint restore.
VersionKey = "runsc_version"
Expand Down
1 change: 1 addition & 0 deletions runsc/sandbox/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ go_library(
"//pkg/sentry/platform",
"//pkg/sentry/seccheck",
"//pkg/sentry/socket/plugin",
"//pkg/sentry/state/checkpointfiles",
"//pkg/state/statefile",
"//pkg/sync",
"//pkg/tcpip/header",
Expand Down
13 changes: 7 additions & 6 deletions runsc/sandbox/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (
"gvisor.dev/gvisor/pkg/sentry/fsimpl/erofs"
"gvisor.dev/gvisor/pkg/sentry/platform"
"gvisor.dev/gvisor/pkg/sentry/seccheck"
"gvisor.dev/gvisor/pkg/sentry/state/checkpointfiles"
"gvisor.dev/gvisor/pkg/state/statefile"
"gvisor.dev/gvisor/pkg/sync"
"gvisor.dev/gvisor/pkg/urpc"
Expand Down Expand Up @@ -501,7 +502,7 @@ func (s *Sandbox) Restore(conf *config.Config, spec *specs.Spec, cid string, ima

log.Debugf("Restore sandbox %q from path %q", s.ID, imagePath)

stateFileName := path.Join(imagePath, boot.CheckpointStateFileName)
stateFileName := path.Join(imagePath, checkpointfiles.StateFileName)
sf, err := os.Open(stateFileName)
if err != nil {
return fmt.Errorf("opening state file %q failed: %v", stateFileName, err)
Expand All @@ -516,15 +517,15 @@ func (s *Sandbox) Restore(conf *config.Config, spec *specs.Spec, cid string, ima
}

// If the pages file exists, we must pass it in.
pagesFileName := path.Join(imagePath, boot.CheckpointPagesFileName)
pagesFileName := path.Join(imagePath, checkpointfiles.PagesFileName)
pagesReadFlags := os.O_RDONLY
if direct {
// The contents are page-aligned, so it can be opened with O_DIRECT.
pagesReadFlags |= syscall.O_DIRECT
}
if pf, err := os.OpenFile(pagesFileName, pagesReadFlags, 0); err == nil {
defer pf.Close()
pagesMetadataFileName := path.Join(imagePath, boot.CheckpointPagesMetadataFileName)
pagesMetadataFileName := path.Join(imagePath, checkpointfiles.PagesMetadataFileName)
pmf, err := os.Open(pagesMetadataFileName)
if err != nil {
return fmt.Errorf("opening restore image file %q failed: %v", pagesMetadataFileName, err)
Expand Down Expand Up @@ -1537,7 +1538,7 @@ func (s *Sandbox) Checkpoint(cid string, imagePath string, opts CheckpointOpts)
func createSaveFiles(path string, direct bool, compression statefile.CompressionLevel) ([]*os.File, error) {
var files []*os.File

stateFilePath := filepath.Join(path, boot.CheckpointStateFileName)
stateFilePath := filepath.Join(path, checkpointfiles.StateFileName)
f, err := os.OpenFile(stateFilePath, os.O_CREATE|os.O_EXCL|os.O_RDWR, 0644)
if err != nil {
return nil, fmt.Errorf("creating checkpoint state file %q: %w", stateFilePath, err)
Expand All @@ -1548,14 +1549,14 @@ func createSaveFiles(path string, direct bool, compression statefile.Compression
// It is beneficial to store them separately so certain optimizations can be
// applied during restore. See Restore().
if compression == statefile.CompressionLevelNone {
pagesMetadataFilePath := filepath.Join(path, boot.CheckpointPagesMetadataFileName)
pagesMetadataFilePath := filepath.Join(path, checkpointfiles.PagesMetadataFileName)
f, err = os.OpenFile(pagesMetadataFilePath, os.O_CREATE|os.O_EXCL|os.O_RDWR, 0644)
if err != nil {
return nil, fmt.Errorf("creating checkpoint pages metadata file %q: %w", pagesMetadataFilePath, err)
}
files = append(files, f)

pagesFilePath := filepath.Join(path, boot.CheckpointPagesFileName)
pagesFilePath := filepath.Join(path, checkpointfiles.PagesFileName)
pagesWriteFlags := os.O_CREATE | os.O_EXCL | os.O_RDWR
if direct {
// The writes will be page-aligned, so it can be opened with O_DIRECT.
Expand Down
Loading