summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fs
diff options
context:
space:
mode:
authorMichael Pratt <mpratt@google.com>2018-08-01 19:56:12 -0700
committerShentubot <shentubot@google.com>2018-08-01 19:57:32 -0700
commit60add78980737a7330100d98bf6a214892dee3c0 (patch)
tree14433da4615d2010a5d34ade91ff94b938c5a9b5 /pkg/sentry/fs
parentb9e1cf8404ce1263176643dee1a1cc835c9d1448 (diff)
Automated rollback of changelist 207007153
PiperOrigin-RevId: 207037226 Change-Id: I8b5f1a056d4f3eab17846f2e0193bb737ecb5428
Diffstat (limited to 'pkg/sentry/fs')
-rw-r--r--pkg/sentry/fs/BUILD36
-rw-r--r--pkg/sentry/fs/ashmem/BUILD17
-rw-r--r--pkg/sentry/fs/ashmem/area.go8
-rw-r--r--pkg/sentry/fs/ashmem/device.go22
-rw-r--r--pkg/sentry/fs/ashmem/pin_board.go2
-rw-r--r--pkg/sentry/fs/attr.go12
-rw-r--r--pkg/sentry/fs/binder/BUILD13
-rw-r--r--pkg/sentry/fs/binder/binder.go26
-rw-r--r--pkg/sentry/fs/dentry.go4
-rw-r--r--pkg/sentry/fs/dev/BUILD20
-rw-r--r--pkg/sentry/fs/dev/dev.go2
-rw-r--r--pkg/sentry/fs/dev/fs.go2
-rw-r--r--pkg/sentry/fs/dev/full.go2
-rw-r--r--pkg/sentry/fs/dev/null.go3
-rw-r--r--pkg/sentry/fs/dev/random.go1
-rw-r--r--pkg/sentry/fs/dirent.go2
-rw-r--r--pkg/sentry/fs/dirent_cache.go2
-rw-r--r--pkg/sentry/fs/fdpipe/BUILD31
-rw-r--r--pkg/sentry/fs/fdpipe/pipe.go2
-rw-r--r--pkg/sentry/fs/file.go2
-rw-r--r--pkg/sentry/fs/file_overlay.go4
-rw-r--r--pkg/sentry/fs/filesystems.go2
-rw-r--r--pkg/sentry/fs/filetest/BUILD18
-rw-r--r--pkg/sentry/fs/flags.go2
-rw-r--r--pkg/sentry/fs/fsutil/BUILD20
-rw-r--r--pkg/sentry/fs/fsutil/dirty_set.go2
-rw-r--r--pkg/sentry/fs/fsutil/handle.go2
-rw-r--r--pkg/sentry/fs/fsutil/host_file_mapper.go2
-rw-r--r--pkg/sentry/fs/fsutil/inode.go6
-rw-r--r--pkg/sentry/fs/fsutil/inode_cached.go2
-rw-r--r--pkg/sentry/fs/gofer/BUILD23
-rw-r--r--pkg/sentry/fs/gofer/file.go2
-rw-r--r--pkg/sentry/fs/gofer/fs.go2
-rw-r--r--pkg/sentry/fs/gofer/inode.go4
-rw-r--r--pkg/sentry/fs/gofer/session.go3
-rw-r--r--pkg/sentry/fs/host/BUILD27
-rw-r--r--pkg/sentry/fs/host/descriptor.go2
-rw-r--r--pkg/sentry/fs/host/file.go2
-rw-r--r--pkg/sentry/fs/host/fs.go6
-rw-r--r--pkg/sentry/fs/host/inode.go4
-rw-r--r--pkg/sentry/fs/inode.go4
-rw-r--r--pkg/sentry/fs/inode_inotify.go2
-rw-r--r--pkg/sentry/fs/inotify.go2
-rw-r--r--pkg/sentry/fs/inotify_event.go2
-rw-r--r--pkg/sentry/fs/inotify_watch.go2
-rw-r--r--pkg/sentry/fs/lock/BUILD15
-rw-r--r--pkg/sentry/fs/lock/lock.go6
-rw-r--r--pkg/sentry/fs/mount.go4
-rw-r--r--pkg/sentry/fs/mount_overlay.go4
-rw-r--r--pkg/sentry/fs/mounts.go2
-rw-r--r--pkg/sentry/fs/overlay.go2
-rw-r--r--pkg/sentry/fs/proc/BUILD34
-rw-r--r--pkg/sentry/fs/proc/cpuinfo.go2
-rw-r--r--pkg/sentry/fs/proc/exec_args.go2
-rw-r--r--pkg/sentry/fs/proc/fds.go6
-rw-r--r--pkg/sentry/fs/proc/file.go1
-rw-r--r--pkg/sentry/fs/proc/filesystems.go2
-rw-r--r--pkg/sentry/fs/proc/fs.go2
-rw-r--r--pkg/sentry/fs/proc/loadavg.go2
-rw-r--r--pkg/sentry/fs/proc/meminfo.go2
-rw-r--r--pkg/sentry/fs/proc/mounts.go4
-rw-r--r--pkg/sentry/fs/proc/proc.go4
-rw-r--r--pkg/sentry/fs/proc/seqfile/BUILD30
-rw-r--r--pkg/sentry/fs/proc/seqfile/seqfile.go4
-rw-r--r--pkg/sentry/fs/proc/stat.go2
-rw-r--r--pkg/sentry/fs/proc/sys.go5
-rw-r--r--pkg/sentry/fs/proc/sys_net.go2
-rw-r--r--pkg/sentry/fs/proc/task.go20
-rw-r--r--pkg/sentry/fs/proc/uid_gid_map.go3
-rw-r--r--pkg/sentry/fs/proc/uptime.go2
-rw-r--r--pkg/sentry/fs/proc/version.go2
-rw-r--r--pkg/sentry/fs/ramfs/BUILD21
-rw-r--r--pkg/sentry/fs/ramfs/dir.go2
-rw-r--r--pkg/sentry/fs/ramfs/ramfs.go2
-rw-r--r--pkg/sentry/fs/ramfs/socket.go2
-rw-r--r--pkg/sentry/fs/ramfs/symlink.go2
-rw-r--r--pkg/sentry/fs/ramfs/test/BUILD18
-rw-r--r--pkg/sentry/fs/sys/BUILD14
-rw-r--r--pkg/sentry/fs/sys/fs.go2
-rw-r--r--pkg/sentry/fs/sys/sys.go5
-rw-r--r--pkg/sentry/fs/timerfd/BUILD18
-rw-r--r--pkg/sentry/fs/timerfd/timerfd.go4
-rw-r--r--pkg/sentry/fs/tmpfs/BUILD17
-rw-r--r--pkg/sentry/fs/tmpfs/file_regular.go2
-rw-r--r--pkg/sentry/fs/tmpfs/fs.go2
-rw-r--r--pkg/sentry/fs/tmpfs/inode_file.go2
-rw-r--r--pkg/sentry/fs/tmpfs/tmpfs.go8
-rw-r--r--pkg/sentry/fs/tty/BUILD20
-rw-r--r--pkg/sentry/fs/tty/dir.go18
-rw-r--r--pkg/sentry/fs/tty/fs.go4
-rw-r--r--pkg/sentry/fs/tty/inode.go2
-rw-r--r--pkg/sentry/fs/tty/line_discipline.go6
-rw-r--r--pkg/sentry/fs/tty/master.go4
-rw-r--r--pkg/sentry/fs/tty/queue.go4
-rw-r--r--pkg/sentry/fs/tty/slave.go4
-rw-r--r--pkg/sentry/fs/tty/terminal.go2
96 files changed, 404 insertions, 301 deletions
diff --git a/pkg/sentry/fs/BUILD b/pkg/sentry/fs/BUILD
index 18cd5ae8e..e3c9a9b70 100644
--- a/pkg/sentry/fs/BUILD
+++ b/pkg/sentry/fs/BUILD
@@ -1,7 +1,40 @@
package(licenses = ["notice"]) # Apache 2.0
load("//tools/go_generics:defs.bzl", "go_template_instance")
-load("//tools/go_stateify:defs.bzl", "go_library", "go_test")
+load("//tools/go_stateify:defs.bzl", "go_library", "go_stateify", "go_test")
+
+go_stateify(
+ name = "fs_state",
+ srcs = [
+ "attr.go",
+ "dentry.go",
+ "dirent.go",
+ "dirent_cache.go",
+ "dirent_list.go",
+ "dirent_state.go",
+ "file.go",
+ "file_overlay.go",
+ "file_state.go",
+ "filesystems.go",
+ "flags.go",
+ "inode.go",
+ "inode_inotify.go",
+ "inode_operations.go",
+ "inode_overlay.go",
+ "inotify.go",
+ "inotify_event.go",
+ "inotify_watch.go",
+ "mock.go",
+ "mount.go",
+ "mount_overlay.go",
+ "mount_state.go",
+ "mounts.go",
+ "overlay.go",
+ "path.go",
+ ],
+ out = "fs_state.go",
+ package = "fs",
+)
go_library(
name = "fs",
@@ -21,6 +54,7 @@ go_library(
"filesystems.go",
"flags.go",
"fs.go",
+ "fs_state.go",
"inode.go",
"inode_inotify.go",
"inode_operations.go",
diff --git a/pkg/sentry/fs/ashmem/BUILD b/pkg/sentry/fs/ashmem/BUILD
index dc893d22f..9f166799a 100644
--- a/pkg/sentry/fs/ashmem/BUILD
+++ b/pkg/sentry/fs/ashmem/BUILD
@@ -1,12 +1,26 @@
package(licenses = ["notice"]) # Apache 2.0
-load("//tools/go_stateify:defs.bzl", "go_library", "go_test")
+load("//tools/go_stateify:defs.bzl", "go_library", "go_stateify", "go_test")
load("//tools/go_generics:defs.bzl", "go_template_instance")
+go_stateify(
+ name = "ashmem_state",
+ srcs = [
+ "area.go",
+ "device.go",
+ "pin_board.go",
+ "uint64_range.go",
+ "uint64_set.go",
+ ],
+ out = "ashmem_state.go",
+ package = "ashmem",
+)
+
go_library(
name = "ashmem",
srcs = [
"area.go",
+ "ashmem_state.go",
"device.go",
"pin_board.go",
"uint64_range.go",
@@ -27,6 +41,7 @@ go_library(
"//pkg/sentry/platform",
"//pkg/sentry/usage",
"//pkg/sentry/usermem",
+ "//pkg/state",
"//pkg/syserror",
"//pkg/tcpip/transport/unix",
],
diff --git a/pkg/sentry/fs/ashmem/area.go b/pkg/sentry/fs/ashmem/area.go
index bfd7f2762..e4f76f0d0 100644
--- a/pkg/sentry/fs/ashmem/area.go
+++ b/pkg/sentry/fs/ashmem/area.go
@@ -39,12 +39,10 @@ const (
)
// Area implements fs.FileOperations.
-//
-// +stateify savable
type Area struct {
- fsutil.NoFsync `state:"nosave"`
- fsutil.DeprecatedFileOperations `state:"nosave"`
- fsutil.NotDirReaddir `state:"nosave"`
+ fsutil.NoFsync
+ fsutil.DeprecatedFileOperations
+ fsutil.NotDirReaddir
ad *Device
diff --git a/pkg/sentry/fs/ashmem/device.go b/pkg/sentry/fs/ashmem/device.go
index d0986fa11..c5b51d4a7 100644
--- a/pkg/sentry/fs/ashmem/device.go
+++ b/pkg/sentry/fs/ashmem/device.go
@@ -27,19 +27,17 @@ import (
)
// Device implements fs.InodeOperations.
-//
-// +stateify savable
type Device struct {
- fsutil.DeprecatedFileOperations `state:"nosave"`
- fsutil.InodeNoExtendedAttributes `state:"nosave"`
- fsutil.InodeNotDirectory `state:"nosave"`
- fsutil.InodeNotRenameable `state:"nosave"`
- fsutil.InodeNotSocket `state:"nosave"`
- fsutil.InodeNotSymlink `state:"nosave"`
- fsutil.NoFsync `state:"nosave"`
- fsutil.NoMappable `state:"nosave"`
- fsutil.NoopWriteOut `state:"nosave"`
- fsutil.NotDirReaddir `state:"nosave"`
+ fsutil.DeprecatedFileOperations
+ fsutil.InodeNoExtendedAttributes
+ fsutil.InodeNotDirectory
+ fsutil.InodeNotRenameable
+ fsutil.InodeNotSocket
+ fsutil.InodeNotSymlink
+ fsutil.NoFsync
+ fsutil.NoMappable
+ fsutil.NoopWriteOut
+ fsutil.NotDirReaddir
mu sync.Mutex `state:"nosave"`
unstable fs.UnstableAttr
diff --git a/pkg/sentry/fs/ashmem/pin_board.go b/pkg/sentry/fs/ashmem/pin_board.go
index ecba395a0..c7fb3822c 100644
--- a/pkg/sentry/fs/ashmem/pin_board.go
+++ b/pkg/sentry/fs/ashmem/pin_board.go
@@ -56,8 +56,6 @@ func (setFunctions) Split(Range, noValue, uint64) (noValue, noValue) {
// segment.Set is used for implementation where segments represent
// ranges of pinned bytes, while gaps represent ranges of unpinned
// bytes. All ranges are page-aligned.
-//
-// +stateify savable
type PinBoard struct {
Set
}
diff --git a/pkg/sentry/fs/attr.go b/pkg/sentry/fs/attr.go
index 4178f18b2..56a2ad6f7 100644
--- a/pkg/sentry/fs/attr.go
+++ b/pkg/sentry/fs/attr.go
@@ -91,8 +91,6 @@ func (n InodeType) String() string {
// StableAttr contains Inode attributes that will be stable throughout the
// lifetime of the Inode.
-//
-// +stateify savable
type StableAttr struct {
// Type is the InodeType of a InodeOperations.
Type InodeType
@@ -152,8 +150,6 @@ func IsCharDevice(s StableAttr) bool {
// UnstableAttr contains Inode attributes that may change over the lifetime
// of the Inode.
-//
-// +stateify savable
type UnstableAttr struct {
// Size is the file size in bytes.
Size int64
@@ -190,8 +186,6 @@ func WithCurrentTime(ctx context.Context, u UnstableAttr) UnstableAttr {
}
// AttrMask contains fields to mask StableAttr and UnstableAttr.
-//
-// +stateify savable
type AttrMask struct {
Type bool
DeviceID bool
@@ -233,8 +227,6 @@ func (a AttrMask) Union(b AttrMask) AttrMask {
}
// PermMask are file access permissions.
-//
-// +stateify savable
type PermMask struct {
// Read indicates reading is permitted.
Read bool
@@ -288,8 +280,6 @@ func (p PermMask) SupersetOf(other PermMask) bool {
// FilePermissions represents the permissions of a file, with
// Read/Write/Execute bits for user, group, and other.
-//
-// +stateify savable
type FilePermissions struct {
User PermMask
Group PermMask
@@ -380,8 +370,6 @@ func (f FilePermissions) AnyRead() bool {
}
// FileOwner represents ownership of a file.
-//
-// +stateify savable
type FileOwner struct {
UID auth.KUID
GID auth.KGID
diff --git a/pkg/sentry/fs/binder/BUILD b/pkg/sentry/fs/binder/BUILD
index a077b91d2..ec3928baf 100644
--- a/pkg/sentry/fs/binder/BUILD
+++ b/pkg/sentry/fs/binder/BUILD
@@ -1,16 +1,25 @@
package(licenses = ["notice"]) # Apache 2.0
-load("//tools/go_stateify:defs.bzl", "go_library")
+load("//tools/go_stateify:defs.bzl", "go_library", "go_stateify")
+
+go_stateify(
+ name = "binder_state",
+ srcs = ["binder.go"],
+ out = "binder_state.go",
+ package = "binder",
+)
go_library(
name = "binder",
srcs = [
"binder.go",
+ "binder_state.go",
],
importpath = "gvisor.googlesource.com/gvisor/pkg/sentry/fs/binder",
visibility = ["//pkg/sentry:internal"],
deps = [
"//pkg/abi/linux",
+ "//pkg/log",
"//pkg/sentry/arch",
"//pkg/sentry/context",
"//pkg/sentry/fs",
@@ -21,6 +30,8 @@ go_library(
"//pkg/sentry/platform",
"//pkg/sentry/usage",
"//pkg/sentry/usermem",
+ "//pkg/state",
"//pkg/syserror",
+ "//pkg/tcpip/transport/unix",
],
)
diff --git a/pkg/sentry/fs/binder/binder.go b/pkg/sentry/fs/binder/binder.go
index 502a262dd..3f87b6b08 100644
--- a/pkg/sentry/fs/binder/binder.go
+++ b/pkg/sentry/fs/binder/binder.go
@@ -40,17 +40,15 @@ const (
)
// Device implements fs.InodeOperations.
-//
-// +stateify savable
type Device struct {
- fsutil.InodeNoExtendedAttributes `state:"nosave"`
- fsutil.InodeNotDirectory `state:"nosave"`
- fsutil.InodeNotRenameable `state:"nosave"`
- fsutil.InodeNotSocket `state:"nosave"`
- fsutil.InodeNotSymlink `state:"nosave"`
- fsutil.NoMappable `state:"nosave"`
- fsutil.NoopWriteOut `state:"nosave"`
- fsutil.DeprecatedFileOperations `state:"nosave"`
+ fsutil.InodeNoExtendedAttributes
+ fsutil.InodeNotDirectory
+ fsutil.InodeNotRenameable
+ fsutil.InodeNotSocket
+ fsutil.InodeNotSymlink
+ fsutil.NoMappable
+ fsutil.NoopWriteOut
+ fsutil.DeprecatedFileOperations
// mu protects unstable.
mu sync.Mutex `state:"nosave"`
@@ -188,12 +186,10 @@ func (bd *Device) StatFS(context.Context) (fs.Info, error) {
}
// Proc implements fs.FileOperations and fs.IoctlGetter.
-//
-// +stateify savable
type Proc struct {
- fsutil.NoFsync `state:"nosave"`
- fsutil.DeprecatedFileOperations `state:"nosave"`
- fsutil.NotDirReaddir `state:"nosave"`
+ fsutil.NoFsync
+ fsutil.DeprecatedFileOperations
+ fsutil.NotDirReaddir
bd *Device
task *kernel.Task
diff --git a/pkg/sentry/fs/dentry.go b/pkg/sentry/fs/dentry.go
index b347468ff..d42e8da81 100644
--- a/pkg/sentry/fs/dentry.go
+++ b/pkg/sentry/fs/dentry.go
@@ -21,8 +21,6 @@ import (
)
// DentAttr is the metadata of a directory entry. It is a subset of StableAttr.
-//
-// +stateify savable
type DentAttr struct {
// Type is the InodeType of an Inode.
Type InodeType
@@ -156,8 +154,6 @@ func GenericReaddir(ctx *DirCtx, s *SortedDentryMap) (int, error) {
}
// SortedDentryMap is a sorted map of names and fs.DentAttr entries.
-//
-// +stateify savable
type SortedDentryMap struct {
// names is always kept in sorted-order.
names []string
diff --git a/pkg/sentry/fs/dev/BUILD b/pkg/sentry/fs/dev/BUILD
index fc069bb5f..ea41615fd 100644
--- a/pkg/sentry/fs/dev/BUILD
+++ b/pkg/sentry/fs/dev/BUILD
@@ -1,11 +1,25 @@
package(licenses = ["notice"]) # Apache 2.0
-load("//tools/go_stateify:defs.bzl", "go_library")
+load("//tools/go_stateify:defs.bzl", "go_library", "go_stateify")
+
+go_stateify(
+ name = "dev_state",
+ srcs = [
+ "dev.go",
+ "fs.go",
+ "full.go",
+ "null.go",
+ "random.go",
+ ],
+ out = "dev_state.go",
+ package = "dev",
+)
go_library(
name = "dev",
srcs = [
"dev.go",
+ "dev_state.go",
"device.go",
"fs.go",
"full.go",
@@ -16,6 +30,8 @@ go_library(
visibility = ["//pkg/sentry:internal"],
deps = [
"//pkg/abi/linux",
+ "//pkg/amutex",
+ "//pkg/log",
"//pkg/rand",
"//pkg/sentry/context",
"//pkg/sentry/device",
@@ -29,7 +45,9 @@ go_library(
"//pkg/sentry/mm",
"//pkg/sentry/platform",
"//pkg/sentry/safemem",
+ "//pkg/sentry/usage",
"//pkg/sentry/usermem",
+ "//pkg/state",
"//pkg/syserror",
],
)
diff --git a/pkg/sentry/fs/dev/dev.go b/pkg/sentry/fs/dev/dev.go
index 3f4f2a40a..36c61bfc2 100644
--- a/pkg/sentry/fs/dev/dev.go
+++ b/pkg/sentry/fs/dev/dev.go
@@ -27,8 +27,6 @@ import (
)
// Dev is the root node.
-//
-// +stateify savable
type Dev struct {
ramfs.Dir
}
diff --git a/pkg/sentry/fs/dev/fs.go b/pkg/sentry/fs/dev/fs.go
index 2ae49be4e..3c79f3782 100644
--- a/pkg/sentry/fs/dev/fs.go
+++ b/pkg/sentry/fs/dev/fs.go
@@ -29,8 +29,6 @@ const binderEnabledKey = "binder_enabled"
const ashmemEnabledKey = "ashmem_enabled"
// filesystem is a devtmpfs.
-//
-// +stateify savable
type filesystem struct{}
func init() {
diff --git a/pkg/sentry/fs/dev/full.go b/pkg/sentry/fs/dev/full.go
index 492b8eb3a..e13eb6c03 100644
--- a/pkg/sentry/fs/dev/full.go
+++ b/pkg/sentry/fs/dev/full.go
@@ -26,8 +26,6 @@ import (
)
// fullDevice is used to implement /dev/full.
-//
-// +stateify savable
type fullDevice struct {
ramfs.Entry
}
diff --git a/pkg/sentry/fs/dev/null.go b/pkg/sentry/fs/dev/null.go
index 2977c8670..66b8ba967 100644
--- a/pkg/sentry/fs/dev/null.go
+++ b/pkg/sentry/fs/dev/null.go
@@ -29,7 +29,6 @@ import (
"gvisor.googlesource.com/gvisor/pkg/sentry/usermem"
)
-// +stateify savable
type nullDevice struct {
ramfs.Entry
}
@@ -55,7 +54,6 @@ func (n *nullDevice) Truncate(context.Context, *fs.Inode, int64) error {
return nil
}
-// +stateify savable
type zeroDevice struct {
nullDevice
}
@@ -82,7 +80,6 @@ func (zd *zeroDevice) GetFile(ctx context.Context, dirent *fs.Dirent, flags fs.F
}), nil
}
-// +stateify savable
type zeroFileOperations struct {
fs.FileOperations
}
diff --git a/pkg/sentry/fs/dev/random.go b/pkg/sentry/fs/dev/random.go
index 47b76218f..33a045a05 100644
--- a/pkg/sentry/fs/dev/random.go
+++ b/pkg/sentry/fs/dev/random.go
@@ -24,7 +24,6 @@ import (
"gvisor.googlesource.com/gvisor/pkg/sentry/usermem"
)
-// +stateify savable
type randomDevice struct {
ramfs.Entry
}
diff --git a/pkg/sentry/fs/dirent.go b/pkg/sentry/fs/dirent.go
index 4658d044f..f9bf2fba6 100644
--- a/pkg/sentry/fs/dirent.go
+++ b/pkg/sentry/fs/dirent.go
@@ -81,8 +81,6 @@ var renameMu sync.RWMutex
//
// Dirents currently do not attempt to free entries that lack application references under
// memory pressure.
-//
-// +stateify savable
type Dirent struct {
// AtomicRefCount is our reference count.
refs.AtomicRefCount
diff --git a/pkg/sentry/fs/dirent_cache.go b/pkg/sentry/fs/dirent_cache.go
index c680e4828..e786e4f65 100644
--- a/pkg/sentry/fs/dirent_cache.go
+++ b/pkg/sentry/fs/dirent_cache.go
@@ -25,8 +25,6 @@ import (
//
// A nil DirentCache corresponds to a cache with size 0. All methods can be
// called, but nothing is actually cached.
-//
-// +stateify savable
type DirentCache struct {
// Maximum size of the cache. This must be saved manually, to handle the case
// when cache is nil.
diff --git a/pkg/sentry/fs/fdpipe/BUILD b/pkg/sentry/fs/fdpipe/BUILD
index ffe4204bc..4fcb06f1f 100644
--- a/pkg/sentry/fs/fdpipe/BUILD
+++ b/pkg/sentry/fs/fdpipe/BUILD
@@ -1,27 +1,54 @@
package(licenses = ["notice"]) # Apache 2.0
-load("//tools/go_stateify:defs.bzl", "go_library", "go_test")
+load("//tools/go_stateify:defs.bzl", "go_library", "go_stateify", "go_test")
+
+go_stateify(
+ name = "pipe_state",
+ srcs = [
+ "pipe.go",
+ "pipe_state.go",
+ ],
+ out = "pipe_autogen_state.go",
+ imports = ["gvisor.googlesource.com/gvisor/pkg/sentry/fs"],
+ package = "fdpipe",
+)
go_library(
name = "fdpipe",
srcs = [
"pipe.go",
+ "pipe_autogen_state.go",
"pipe_opener.go",
"pipe_state.go",
],
importpath = "gvisor.googlesource.com/gvisor/pkg/sentry/fs/fdpipe",
- imports = ["gvisor.googlesource.com/gvisor/pkg/sentry/fs"],
visibility = ["//pkg/sentry:internal"],
deps = [
+ "//pkg/abi/linux",
+ "//pkg/amutex",
"//pkg/fd",
"//pkg/log",
+ "//pkg/metric",
+ "//pkg/p9",
+ "//pkg/refs",
"//pkg/secio",
"//pkg/sentry/context",
+ "//pkg/sentry/device",
"//pkg/sentry/fs",
"//pkg/sentry/fs/fsutil",
+ "//pkg/sentry/fs/lock",
+ "//pkg/sentry/kernel/auth",
+ "//pkg/sentry/kernel/time",
+ "//pkg/sentry/memmap",
+ "//pkg/sentry/platform",
"//pkg/sentry/safemem",
+ "//pkg/sentry/uniqueid",
"//pkg/sentry/usermem",
+ "//pkg/state",
"//pkg/syserror",
+ "//pkg/tcpip",
+ "//pkg/tcpip/transport/unix",
+ "//pkg/unet",
"//pkg/waiter",
"//pkg/waiter/fdnotifier",
],
diff --git a/pkg/sentry/fs/fdpipe/pipe.go b/pkg/sentry/fs/fdpipe/pipe.go
index 2e34604e6..7b318e35f 100644
--- a/pkg/sentry/fs/fdpipe/pipe.go
+++ b/pkg/sentry/fs/fdpipe/pipe.go
@@ -34,8 +34,6 @@ import (
)
// pipeOperations are the fs.FileOperations of a host pipe.
-//
-// +stateify savable
type pipeOperations struct {
fsutil.PipeSeek `state:"nosave"`
fsutil.NotDirReaddir `state:"nosave"`
diff --git a/pkg/sentry/fs/file.go b/pkg/sentry/fs/file.go
index 8e535a618..6d93ef760 100644
--- a/pkg/sentry/fs/file.go
+++ b/pkg/sentry/fs/file.go
@@ -47,8 +47,6 @@ const FileMaxOffset = math.MaxInt64
// and write(2).
//
// FIXME: Split synchronization from cancellation.
-//
-// +stateify savable
type File struct {
refs.AtomicRefCount
diff --git a/pkg/sentry/fs/file_overlay.go b/pkg/sentry/fs/file_overlay.go
index 113962368..36b2cf75e 100644
--- a/pkg/sentry/fs/file_overlay.go
+++ b/pkg/sentry/fs/file_overlay.go
@@ -60,8 +60,6 @@ func overlayFile(ctx context.Context, inode *Inode, flags FileFlags) (*File, err
}
// overlayFileOperations implements FileOperations for a file in an overlay.
-//
-// +stateify savable
type overlayFileOperations struct {
// upperMu protects upper below. In contrast lower is stable.
upperMu sync.Mutex `state:"nosave"`
@@ -377,8 +375,6 @@ func readdirOne(ctx context.Context, d *Dirent) (map[string]DentAttr, error) {
// overlayMappingIdentity wraps a MappingIdentity, and also holds a reference
// on a file during its lifetime.
-//
-// +stateify savable
type overlayMappingIdentity struct {
refs.AtomicRefCount
id memmap.MappingIdentity
diff --git a/pkg/sentry/fs/filesystems.go b/pkg/sentry/fs/filesystems.go
index 5a1e7a270..200e792f4 100644
--- a/pkg/sentry/fs/filesystems.go
+++ b/pkg/sentry/fs/filesystems.go
@@ -125,8 +125,6 @@ func GetFilesystems() []Filesystem {
}
// MountSourceFlags represents all mount option flags as a struct.
-//
-// +stateify savable
type MountSourceFlags struct {
// ReadOnly corresponds to mount(2)'s "MS_RDONLY" and indicates that
// the filesystem should be mounted read-only.
diff --git a/pkg/sentry/fs/filetest/BUILD b/pkg/sentry/fs/filetest/BUILD
index d137fee4c..f481c57fb 100644
--- a/pkg/sentry/fs/filetest/BUILD
+++ b/pkg/sentry/fs/filetest/BUILD
@@ -1,20 +1,34 @@
package(licenses = ["notice"]) # Apache 2.0
-load("//tools/go_stateify:defs.bzl", "go_library")
+load("//tools/go_stateify:defs.bzl", "go_library", "go_stateify")
+
+go_stateify(
+ name = "filetest_state",
+ srcs = [
+ "filetest.go",
+ ],
+ out = "filetest_state.go",
+ package = "filetest",
+)
go_library(
name = "filetest",
testonly = 1,
- srcs = ["filetest.go"],
+ srcs = [
+ "filetest.go",
+ "filetest_state.go",
+ ],
importpath = "gvisor.googlesource.com/gvisor/pkg/sentry/fs/filetest",
visibility = ["//pkg/sentry:internal"],
deps = [
+ "//pkg/refs",
"//pkg/sentry/context",
"//pkg/sentry/context/contexttest",
"//pkg/sentry/fs",
"//pkg/sentry/fs/anon",
"//pkg/sentry/fs/fsutil",
"//pkg/sentry/usermem",
+ "//pkg/state",
"//pkg/waiter",
],
)
diff --git a/pkg/sentry/fs/flags.go b/pkg/sentry/fs/flags.go
index 1aa271560..da0ff58af 100644
--- a/pkg/sentry/fs/flags.go
+++ b/pkg/sentry/fs/flags.go
@@ -19,8 +19,6 @@ import (
)
// FileFlags encodes file flags.
-//
-// +stateify savable
type FileFlags struct {
// Direct indicates that I/O should be done directly.
Direct bool
diff --git a/pkg/sentry/fs/fsutil/BUILD b/pkg/sentry/fs/fsutil/BUILD
index 3512bae6f..6eea64298 100644
--- a/pkg/sentry/fs/fsutil/BUILD
+++ b/pkg/sentry/fs/fsutil/BUILD
@@ -1,7 +1,24 @@
package(licenses = ["notice"]) # Apache 2.0
load("//tools/go_generics:defs.bzl", "go_template_instance")
-load("//tools/go_stateify:defs.bzl", "go_library", "go_test")
+load("//tools/go_stateify:defs.bzl", "go_library", "go_stateify", "go_test")
+
+go_stateify(
+ name = "fsutil_state",
+ srcs = [
+ "dirty_set_impl.go",
+ "file.go",
+ "file_range_set_impl.go",
+ "frame_ref_set_impl.go",
+ "handle.go",
+ "host_file_mapper.go",
+ "host_file_mapper_state.go",
+ "inode.go",
+ "inode_cached.go",
+ ],
+ out = "fsutil_state.go",
+ package = "fsutil",
+)
go_template_instance(
name = "dirty_set_impl",
@@ -67,6 +84,7 @@ go_library(
"frame_ref_set.go",
"frame_ref_set_impl.go",
"fsutil.go",
+ "fsutil_state.go",
"handle.go",
"host_file_mapper.go",
"host_file_mapper_state.go",
diff --git a/pkg/sentry/fs/fsutil/dirty_set.go b/pkg/sentry/fs/fsutil/dirty_set.go
index 8e31e48fd..9c6c98542 100644
--- a/pkg/sentry/fs/fsutil/dirty_set.go
+++ b/pkg/sentry/fs/fsutil/dirty_set.go
@@ -32,8 +32,6 @@ import (
// DirtyInfo is the value type of DirtySet, and represents information about a
// Mappable offset that is dirty (the cached data for that offset is newer than
// its source).
-//
-// +stateify savable
type DirtyInfo struct {
// Keep is true if the represented offset is concurrently writable, such
// that writing the data for that offset back to the source does not
diff --git a/pkg/sentry/fs/fsutil/handle.go b/pkg/sentry/fs/fsutil/handle.go
index e7efd3c0f..149c0f84a 100644
--- a/pkg/sentry/fs/fsutil/handle.go
+++ b/pkg/sentry/fs/fsutil/handle.go
@@ -27,8 +27,6 @@ import (
//
// FIXME: Remove Handle entirely in favor of individual fs.File
// implementations using simple generic utilities.
-//
-// +stateify savable
type Handle struct {
NoopRelease `state:"nosave"`
NoIoctl `state:"nosave"`
diff --git a/pkg/sentry/fs/fsutil/host_file_mapper.go b/pkg/sentry/fs/fsutil/host_file_mapper.go
index 9c1e2f76f..d0a27fc1c 100644
--- a/pkg/sentry/fs/fsutil/host_file_mapper.go
+++ b/pkg/sentry/fs/fsutil/host_file_mapper.go
@@ -29,8 +29,6 @@ import (
// HostFileMapper caches mappings of an arbitrary host file descriptor. It is
// used by implementations of memmap.Mappable that represent a host file
// descriptor.
-//
-// +stateify savable
type HostFileMapper struct {
// HostFile conceptually breaks the file into pieces called chunks, of
// size and alignment chunkSize, and caches mappings of the file on a chunk
diff --git a/pkg/sentry/fs/fsutil/inode.go b/pkg/sentry/fs/fsutil/inode.go
index 177396fdc..e1ad07df2 100644
--- a/pkg/sentry/fs/fsutil/inode.go
+++ b/pkg/sentry/fs/fsutil/inode.go
@@ -31,8 +31,6 @@ func NewSimpleInodeOperations(i InodeSimpleAttributes) fs.InodeOperations {
}
// simpleInodeOperations is a simple implementation of Inode.
-//
-// +stateify savable
type simpleInodeOperations struct {
DeprecatedFileOperations `state:"nosave"`
InodeNotDirectory `state:"nosave"`
@@ -50,8 +48,6 @@ type simpleInodeOperations struct {
// InodeSimpleAttributes implements a subset of the Inode interface. It provides
// read-only access to attributes.
-//
-// +stateify savable
type InodeSimpleAttributes struct {
// FSType is the filesystem type reported by StatFS.
FSType uint64
@@ -114,8 +110,6 @@ func (*InodeSimpleAttributes) Truncate(context.Context, *fs.Inode, int64) error
//
// Users need not initialize Xattrs to non-nil (it will be initialized
// when the first extended attribute is set.
-//
-// +stateify savable
type InMemoryAttributes struct {
Unstable fs.UnstableAttr
Xattrs map[string][]byte
diff --git a/pkg/sentry/fs/fsutil/inode_cached.go b/pkg/sentry/fs/fsutil/inode_cached.go
index 0a320e2d8..cba642a8f 100644
--- a/pkg/sentry/fs/fsutil/inode_cached.go
+++ b/pkg/sentry/fs/fsutil/inode_cached.go
@@ -55,8 +55,6 @@ import (
//
// Implementations of InodeOperations.WriteOut must call Sync to write out
// in-memory modifications of data and metadata to the CachedFileObject.
-//
-// +stateify savable
type CachingInodeOperations struct {
// backingFile is a handle to a cached file object.
backingFile CachedFileObject
diff --git a/pkg/sentry/fs/gofer/BUILD b/pkg/sentry/fs/gofer/BUILD
index cb17339c9..1277379e7 100644
--- a/pkg/sentry/fs/gofer/BUILD
+++ b/pkg/sentry/fs/gofer/BUILD
@@ -1,6 +1,21 @@
package(licenses = ["notice"]) # Apache 2.0
-load("//tools/go_stateify:defs.bzl", "go_library", "go_test")
+load("//tools/go_stateify:defs.bzl", "go_library", "go_stateify", "go_test")
+
+go_stateify(
+ name = "gofer_state",
+ srcs = [
+ "file.go",
+ "file_state.go",
+ "fs.go",
+ "inode.go",
+ "inode_state.go",
+ "session.go",
+ "session_state.go",
+ ],
+ out = "gofer_state.go",
+ package = "gofer",
+)
go_library(
name = "gofer",
@@ -12,6 +27,7 @@ go_library(
"file.go",
"file_state.go",
"fs.go",
+ "gofer_state.go",
"handles.go",
"inode.go",
"inode_state.go",
@@ -25,6 +41,7 @@ go_library(
visibility = ["//pkg/sentry:internal"],
deps = [
"//pkg/abi/linux",
+ "//pkg/amutex",
"//pkg/fd",
"//pkg/log",
"//pkg/metric",
@@ -37,11 +54,15 @@ go_library(
"//pkg/sentry/fs/fdpipe",
"//pkg/sentry/fs/fsutil",
"//pkg/sentry/fs/host",
+ "//pkg/sentry/fs/lock",
"//pkg/sentry/kernel/auth",
"//pkg/sentry/kernel/time",
"//pkg/sentry/memmap",
+ "//pkg/sentry/platform",
"//pkg/sentry/safemem",
+ "//pkg/sentry/uniqueid",
"//pkg/sentry/usermem",
+ "//pkg/state",
"//pkg/syserror",
"//pkg/tcpip",
"//pkg/tcpip/transport/unix",
diff --git a/pkg/sentry/fs/gofer/file.go b/pkg/sentry/fs/gofer/file.go
index 46a6bbd5d..039618808 100644
--- a/pkg/sentry/fs/gofer/file.go
+++ b/pkg/sentry/fs/gofer/file.go
@@ -33,8 +33,6 @@ import (
var openedWX = metric.MustCreateNewUint64Metric("/gofer/opened_write_execute_file", true /* sync */, "Number of times a writable+executable file was opened from a gofer.")
// fileOperations implements fs.FileOperations for a remote file system.
-//
-// +stateify savable
type fileOperations struct {
fsutil.NoIoctl `state:"nosave"`
waiter.AlwaysReady `state:"nosave"`
diff --git a/pkg/sentry/fs/gofer/fs.go b/pkg/sentry/fs/gofer/fs.go
index 3ae93f059..dd5d43c47 100644
--- a/pkg/sentry/fs/gofer/fs.go
+++ b/pkg/sentry/fs/gofer/fs.go
@@ -83,8 +83,6 @@ var (
)
// filesystem is a 9p client.
-//
-// +stateify savable
type filesystem struct{}
func init() {
diff --git a/pkg/sentry/fs/gofer/inode.go b/pkg/sentry/fs/gofer/inode.go
index 7fc8f77b0..df584c382 100644
--- a/pkg/sentry/fs/gofer/inode.go
+++ b/pkg/sentry/fs/gofer/inode.go
@@ -35,8 +35,6 @@ import (
)
// inodeOperations implements fs.InodeOperations.
-//
-// +stateify savable
type inodeOperations struct {
fsutil.InodeNotVirtual `state:"nosave"`
fsutil.InodeNoExtendedAttributes `state:"nosave"`
@@ -70,8 +68,6 @@ type inodeOperations struct {
// circular load dependency between it and inodeOperations). Even with
// lazy loading, this approach defines the dependencies between objects
// and the expected load behavior more concretely.
-//
-// +stateify savable
type inodeFileState struct {
// s is common file system state for Gofers.
s *session `state:"wait"`
diff --git a/pkg/sentry/fs/gofer/session.go b/pkg/sentry/fs/gofer/session.go
index 648a11435..b6841526a 100644
--- a/pkg/sentry/fs/gofer/session.go
+++ b/pkg/sentry/fs/gofer/session.go
@@ -27,7 +27,6 @@ import (
"gvisor.googlesource.com/gvisor/pkg/unet"
)
-// +stateify savable
type endpointMap struct {
mu sync.RWMutex `state:"nosave"`
// TODO: Make map with private unix sockets savable.
@@ -64,8 +63,6 @@ func (e *endpointMap) get(key device.MultiDeviceKey) unix.BoundEndpoint {
}
// session holds state for each 9p session established during sys_mount.
-//
-// +stateify savable
type session struct {
refs.AtomicRefCount
diff --git a/pkg/sentry/fs/host/BUILD b/pkg/sentry/fs/host/BUILD
index 29c79284a..23ec66f50 100644
--- a/pkg/sentry/fs/host/BUILD
+++ b/pkg/sentry/fs/host/BUILD
@@ -1,6 +1,23 @@
package(licenses = ["notice"]) # Apache 2.0
-load("//tools/go_stateify:defs.bzl", "go_library", "go_test")
+load("//tools/go_stateify:defs.bzl", "go_library", "go_stateify", "go_test")
+
+go_stateify(
+ name = "host_state",
+ srcs = [
+ "control.go",
+ "descriptor.go",
+ "descriptor_state.go",
+ "file.go",
+ "fs.go",
+ "inode.go",
+ "inode_state.go",
+ "socket.go",
+ "socket_state.go",
+ ],
+ out = "host_state.go",
+ package = "host",
+)
go_library(
name = "host",
@@ -11,6 +28,7 @@ go_library(
"device.go",
"file.go",
"fs.go",
+ "host_state.go",
"inode.go",
"inode_state.go",
"ioctl_unsafe.go",
@@ -24,6 +42,7 @@ go_library(
visibility = ["//pkg/sentry:internal"],
deps = [
"//pkg/abi/linux",
+ "//pkg/amutex",
"//pkg/fd",
"//pkg/log",
"//pkg/refs",
@@ -33,14 +52,20 @@ go_library(
"//pkg/sentry/device",
"//pkg/sentry/fs",
"//pkg/sentry/fs/fsutil",
+ "//pkg/sentry/fs/lock",
"//pkg/sentry/kernel",
"//pkg/sentry/kernel/auth",
"//pkg/sentry/kernel/time",
"//pkg/sentry/memmap",
+ "//pkg/sentry/platform",
"//pkg/sentry/safemem",
+ "//pkg/sentry/socket",
"//pkg/sentry/socket/control",
"//pkg/sentry/socket/unix",
+ "//pkg/sentry/uniqueid",
+ "//pkg/sentry/usage",
"//pkg/sentry/usermem",
+ "//pkg/state",
"//pkg/syserror",
"//pkg/tcpip",
"//pkg/tcpip/link/rawfile",
diff --git a/pkg/sentry/fs/host/descriptor.go b/pkg/sentry/fs/host/descriptor.go
index 3aee4d11c..613bd06e8 100644
--- a/pkg/sentry/fs/host/descriptor.go
+++ b/pkg/sentry/fs/host/descriptor.go
@@ -25,8 +25,6 @@ import (
)
// descriptor wraps a host fd.
-//
-// +stateify savable
type descriptor struct {
// donated is true if the host fd was donated by another process.
donated bool
diff --git a/pkg/sentry/fs/host/file.go b/pkg/sentry/fs/host/file.go
index f9bef6d93..bdf844337 100644
--- a/pkg/sentry/fs/host/file.go
+++ b/pkg/sentry/fs/host/file.go
@@ -37,8 +37,6 @@ import (
)
// fileOperations implements fs.FileOperations for a host file descriptor.
-//
-// +stateify savable
type fileOperations struct {
fsutil.NoopRelease `state:"nosave"`
diff --git a/pkg/sentry/fs/host/fs.go b/pkg/sentry/fs/host/fs.go
index e46ae433c..974700636 100644
--- a/pkg/sentry/fs/host/fs.go
+++ b/pkg/sentry/fs/host/fs.go
@@ -51,8 +51,6 @@ const maxTraversals = 10
// to lock down the configurations. This filesystem should only be mounted at root.
//
// Think twice before exposing this to applications.
-//
-// +stateify savable
type Filesystem struct {
// whitelist is a set of host paths to whitelist.
paths []string
@@ -268,10 +266,8 @@ func newMountSource(ctx context.Context, root string, mounter fs.FileOwner, file
}
// superOperations implements fs.MountSourceOperations.
-//
-// +stateify savable
type superOperations struct {
- fs.SimpleMountSourceOperations
+ fs.SimpleMountSourceOperations `state:"nosave"`
// root is the path of the mount point. All inode mappings
// are relative to this root.
diff --git a/pkg/sentry/fs/host/inode.go b/pkg/sentry/fs/host/inode.go
index 761ccde33..226bc5164 100644
--- a/pkg/sentry/fs/host/inode.go
+++ b/pkg/sentry/fs/host/inode.go
@@ -34,8 +34,6 @@ import (
// inodeOperations implements fs.InodeOperations for an fs.Inodes backed
// by a host file descriptor.
-//
-// +stateify savable
type inodeOperations struct {
fsutil.InodeNotVirtual `state:"nosave"`
fsutil.InodeNoExtendedAttributes `state:"nosave"`
@@ -67,8 +65,6 @@ type inodeOperations struct {
// circular load dependency between it and inodeOperations). Even with
// lazy loading, this approach defines the dependencies between objects
// and the expected load behavior more concretely.
-//
-// +stateify savable
type inodeFileState struct {
// Common file system state.
mops *superOperations `state:"wait"`
diff --git a/pkg/sentry/fs/inode.go b/pkg/sentry/fs/inode.go
index d0dbce5dd..6c8e6f188 100644
--- a/pkg/sentry/fs/inode.go
+++ b/pkg/sentry/fs/inode.go
@@ -28,8 +28,6 @@ import (
// Inode is a file system object that can be simultaneously referenced by different
// components of the VFS (Dirent, fs.File, etc).
-//
-// +stateify savable
type Inode struct {
// AtomicRefCount is our reference count.
refs.AtomicRefCount
@@ -60,8 +58,6 @@ type Inode struct {
// Note that in Linux fcntl(2) and flock(2) locks are _not_ cooperative, because race and
// deadlock conditions make merging them prohibitive. We do the same and keep them oblivious
// to each other but provide a "context" as a convenient container.
-//
-// +stateify savable
type LockCtx struct {
// Posix is a set of POSIX-style regional advisory locks, see fcntl(2).
Posix lock.Locks
diff --git a/pkg/sentry/fs/inode_inotify.go b/pkg/sentry/fs/inode_inotify.go
index 683140afe..358bbecdf 100644
--- a/pkg/sentry/fs/inode_inotify.go
+++ b/pkg/sentry/fs/inode_inotify.go
@@ -20,8 +20,6 @@ import (
)
// Watches is the collection of inotify watches on an inode.
-//
-// +stateify savable
type Watches struct {
// mu protects the fields below.
mu sync.RWMutex `state:"nosave"`
diff --git a/pkg/sentry/fs/inotify.go b/pkg/sentry/fs/inotify.go
index 2aabdded8..6f5e8ce5e 100644
--- a/pkg/sentry/fs/inotify.go
+++ b/pkg/sentry/fs/inotify.go
@@ -34,8 +34,6 @@ import (
//
// Lock ordering:
// Inotify.mu -> Inode.Watches.mu -> Watch.mu -> Inotify.evMu
-//
-// +stateify savable
type Inotify struct {
// Unique identifier for this inotify instance. We don't just reuse the
// inotify fd because fds can be duped. These should not be exposed to the
diff --git a/pkg/sentry/fs/inotify_event.go b/pkg/sentry/fs/inotify_event.go
index e9b5e0f56..217915ba4 100644
--- a/pkg/sentry/fs/inotify_event.go
+++ b/pkg/sentry/fs/inotify_event.go
@@ -28,8 +28,6 @@ import (
const inotifyEventBaseSize = 16
// Event represents a struct inotify_event from linux.
-//
-// +stateify savable
type Event struct {
ilist.Entry
diff --git a/pkg/sentry/fs/inotify_watch.go b/pkg/sentry/fs/inotify_watch.go
index 3e1959e83..8904ef544 100644
--- a/pkg/sentry/fs/inotify_watch.go
+++ b/pkg/sentry/fs/inotify_watch.go
@@ -27,8 +27,6 @@ import (
// holding an extra ref on each dirent known (by inotify) to point to the
// inode. These are known as pins. For a full discussion, see
// fs/g3doc/inotify.md.
-//
-// +stateify savable
type Watch struct {
// Inotify instance which owns this watch.
owner *Inotify
diff --git a/pkg/sentry/fs/lock/BUILD b/pkg/sentry/fs/lock/BUILD
index 3159ff1da..2607d7ed3 100644
--- a/pkg/sentry/fs/lock/BUILD
+++ b/pkg/sentry/fs/lock/BUILD
@@ -1,7 +1,18 @@
package(licenses = ["notice"]) # Apache 2.0
load("//tools/go_generics:defs.bzl", "go_template_instance")
-load("//tools/go_stateify:defs.bzl", "go_library", "go_test")
+load("//tools/go_stateify:defs.bzl", "go_library", "go_stateify", "go_test")
+
+go_stateify(
+ name = "lock_state",
+ srcs = [
+ "lock.go",
+ "lock_range.go",
+ "lock_set.go",
+ ],
+ out = "lock_state.go",
+ package = "lock",
+)
go_template_instance(
name = "lock_range",
@@ -38,11 +49,13 @@ go_library(
"lock_range.go",
"lock_set.go",
"lock_set_functions.go",
+ "lock_state.go",
],
importpath = "gvisor.googlesource.com/gvisor/pkg/sentry/fs/lock",
visibility = ["//pkg/sentry:internal"],
deps = [
"//pkg/log",
+ "//pkg/state",
"//pkg/waiter",
],
)
diff --git a/pkg/sentry/fs/lock/lock.go b/pkg/sentry/fs/lock/lock.go
index e9b376eb6..24d54c989 100644
--- a/pkg/sentry/fs/lock/lock.go
+++ b/pkg/sentry/fs/lock/lock.go
@@ -88,8 +88,6 @@ const LockEOF = math.MaxUint64
//
// A Lock may be downgraded from a write lock to a read lock only if
// the write lock's uid is the same as the read lock.
-//
-// +stateify savable
type Lock struct {
// Readers are the set of read lock holders identified by UniqueID.
// If len(Readers) > 0 then HasWriter must be false.
@@ -105,8 +103,6 @@ type Lock struct {
}
// Locks is a thread-safe wrapper around a LockSet.
-//
-// +stateify savable
type Locks struct {
// mu protects locks below.
mu sync.Mutex `state:"nosave"`
@@ -115,7 +111,7 @@ type Locks struct {
locks LockSet
// blockedQueue is the queue of waiters that are waiting on a lock.
- blockedQueue waiter.Queue `state:"zerovalue"`
+ blockedQueue waiter.Queue
}
// Blocker is the interface used for blocking locks. Passing a nil Blocker
diff --git a/pkg/sentry/fs/mount.go b/pkg/sentry/fs/mount.go
index 4ede767f9..eb1897174 100644
--- a/pkg/sentry/fs/mount.go
+++ b/pkg/sentry/fs/mount.go
@@ -101,8 +101,6 @@ func (i InodeMappings) String() string {
// (e.g. cannot be mounted at different locations).
//
// TODO: Move mount-specific information out of MountSource.
-//
-// +stateify savable
type MountSource struct {
refs.AtomicRefCount
@@ -262,8 +260,6 @@ func NewNonCachingMountSource(filesystem Filesystem, flags MountSourceFlags) *Mo
}
// SimpleMountSourceOperations implements MountSourceOperations.
-//
-// +stateify savable
type SimpleMountSourceOperations struct {
keep bool
}
diff --git a/pkg/sentry/fs/mount_overlay.go b/pkg/sentry/fs/mount_overlay.go
index d135e8a37..1be81e3a1 100644
--- a/pkg/sentry/fs/mount_overlay.go
+++ b/pkg/sentry/fs/mount_overlay.go
@@ -18,8 +18,6 @@ import "gvisor.googlesource.com/gvisor/pkg/sentry/context"
// overlayMountSourceOperations implements MountSourceOperations for an overlay
// mount point.
-//
-// +stateify savable
type overlayMountSourceOperations struct {
upper *MountSource
lower *MountSource
@@ -74,8 +72,6 @@ func (o *overlayMountSourceOperations) Destroy() {
}
// type overlayFilesystem is the filesystem for overlay mounts.
-//
-// +stateify savable
type overlayFilesystem struct{}
// Name implements Filesystem.Name.
diff --git a/pkg/sentry/fs/mounts.go b/pkg/sentry/fs/mounts.go
index 144d3427d..87da4ee0e 100644
--- a/pkg/sentry/fs/mounts.go
+++ b/pkg/sentry/fs/mounts.go
@@ -32,8 +32,6 @@ import (
const DefaultTraversalLimit = 10
// MountNamespace defines a collection of mounts.
-//
-// +stateify savable
type MountNamespace struct {
refs.AtomicRefCount
diff --git a/pkg/sentry/fs/overlay.go b/pkg/sentry/fs/overlay.go
index af13dc8c7..7357d6401 100644
--- a/pkg/sentry/fs/overlay.go
+++ b/pkg/sentry/fs/overlay.go
@@ -145,8 +145,6 @@ func newOverlayInode(ctx context.Context, o *overlayEntry, msrc *MountSource) *I
}
// overlayEntry is the overlay metadata of an Inode. It implements Mappable.
-//
-// +stateify savable
type overlayEntry struct {
// lowerExists is true if an Inode exists for this file in the lower
// filesystem. If lowerExists is true, then the overlay must create
diff --git a/pkg/sentry/fs/proc/BUILD b/pkg/sentry/fs/proc/BUILD
index 2d9f07f2f..870df47b2 100644
--- a/pkg/sentry/fs/proc/BUILD
+++ b/pkg/sentry/fs/proc/BUILD
@@ -1,6 +1,32 @@
package(licenses = ["notice"]) # Apache 2.0
-load("//tools/go_stateify:defs.bzl", "go_library", "go_test")
+load("//tools/go_stateify:defs.bzl", "go_library", "go_stateify", "go_test")
+
+go_stateify(
+ name = "proc_state",
+ srcs = [
+ "cpuinfo.go",
+ "exec_args.go",
+ "fds.go",
+ "file.go",
+ "filesystems.go",
+ "fs.go",
+ "loadavg.go",
+ "meminfo.go",
+ "mounts.go",
+ "net.go",
+ "proc.go",
+ "stat.go",
+ "sys.go",
+ "sys_net.go",
+ "task.go",
+ "uid_gid_map.go",
+ "uptime.go",
+ "version.go",
+ ],
+ out = "proc_state.go",
+ package = "proc",
+)
go_library(
name = "proc",
@@ -16,6 +42,7 @@ go_library(
"mounts.go",
"net.go",
"proc.go",
+ "proc_state.go",
"rpcinet_proc.go",
"stat.go",
"sys.go",
@@ -29,6 +56,9 @@ go_library(
visibility = ["//pkg/sentry:internal"],
deps = [
"//pkg/abi/linux",
+ "//pkg/amutex",
+ "//pkg/log",
+ "//pkg/sentry/arch",
"//pkg/sentry/context",
"//pkg/sentry/fs",
"//pkg/sentry/fs/proc/device",
@@ -43,6 +73,8 @@ go_library(
"//pkg/sentry/socket/rpcinet",
"//pkg/sentry/usage",
"//pkg/sentry/usermem",
+ "//pkg/state",
+ "//pkg/syserr",
"//pkg/syserror",
],
)
diff --git a/pkg/sentry/fs/proc/cpuinfo.go b/pkg/sentry/fs/proc/cpuinfo.go
index 4dfec03a4..f80aaa5b1 100644
--- a/pkg/sentry/fs/proc/cpuinfo.go
+++ b/pkg/sentry/fs/proc/cpuinfo.go
@@ -27,8 +27,6 @@ import (
// cpuinfo is a file describing the CPU capabilities.
//
// Presently cpuinfo never changes, so it doesn't need to be a SeqFile.
-//
-// +stateify savable
type cpuinfo struct {
ramfs.Entry
diff --git a/pkg/sentry/fs/proc/exec_args.go b/pkg/sentry/fs/proc/exec_args.go
index a69cbaa0e..0e1523bf1 100644
--- a/pkg/sentry/fs/proc/exec_args.go
+++ b/pkg/sentry/fs/proc/exec_args.go
@@ -37,8 +37,6 @@ const (
// execArgFile is a file containing the exec args (either cmdline or environ)
// for a given task.
-//
-// +stateify savable
type execArgFile struct {
ramfs.Entry
diff --git a/pkg/sentry/fs/proc/fds.go b/pkg/sentry/fs/proc/fds.go
index cca8f874c..194a9c12a 100644
--- a/pkg/sentry/fs/proc/fds.go
+++ b/pkg/sentry/fs/proc/fds.go
@@ -138,8 +138,6 @@ func (f *fd) Close() error {
}
// fdDir implements /proc/TID/fd.
-//
-// +stateify savable
type fdDir struct {
ramfs.Dir
@@ -199,8 +197,6 @@ func (f *fdDir) DeprecatedReaddir(ctx context.Context, dirCtx *fs.DirCtx, offset
}
// fdInfo is a single file in /proc/TID/fdinfo/.
-//
-// +stateify savable
type fdInfo struct {
ramfs.File
@@ -233,8 +229,6 @@ func (*fdInfo) Truncate(ctx context.Context, inode *fs.Inode, size int64) error
// fdInfoDir implements /proc/TID/fdinfo. It embeds an fdDir, but overrides
// Lookup and Readdir.
-//
-// +stateify savable
type fdInfoDir struct {
ramfs.Dir
diff --git a/pkg/sentry/fs/proc/file.go b/pkg/sentry/fs/proc/file.go
index 4b2d08e75..9a433cdf8 100644
--- a/pkg/sentry/fs/proc/file.go
+++ b/pkg/sentry/fs/proc/file.go
@@ -22,7 +22,6 @@ import (
"gvisor.googlesource.com/gvisor/pkg/sentry/usermem"
)
-// +stateify savable
type file struct {
fs.InodeOperations
diff --git a/pkg/sentry/fs/proc/filesystems.go b/pkg/sentry/fs/proc/filesystems.go
index 49b92fd8a..37db9cf9c 100644
--- a/pkg/sentry/fs/proc/filesystems.go
+++ b/pkg/sentry/fs/proc/filesystems.go
@@ -24,8 +24,6 @@ import (
)
// filesystemsData backs /proc/filesystems.
-//
-// +stateify savable
type filesystemsData struct{}
// NeedsUpdate returns true on the first generation. The set of registered file
diff --git a/pkg/sentry/fs/proc/fs.go b/pkg/sentry/fs/proc/fs.go
index 061824b8c..3aadd6ac4 100644
--- a/pkg/sentry/fs/proc/fs.go
+++ b/pkg/sentry/fs/proc/fs.go
@@ -22,8 +22,6 @@ import (
)
// filesystem is a procfs.
-//
-// +stateify savable
type filesystem struct{}
func init() {
diff --git a/pkg/sentry/fs/proc/loadavg.go b/pkg/sentry/fs/proc/loadavg.go
index 6fac251d2..7583b6ccd 100644
--- a/pkg/sentry/fs/proc/loadavg.go
+++ b/pkg/sentry/fs/proc/loadavg.go
@@ -23,8 +23,6 @@ import (
)
// loadavgData backs /proc/loadavg.
-//
-// +stateify savable
type loadavgData struct{}
// NeedsUpdate implements seqfile.SeqSource.NeedsUpdate.
diff --git a/pkg/sentry/fs/proc/meminfo.go b/pkg/sentry/fs/proc/meminfo.go
index 53dfd59ef..49cb0faed 100644
--- a/pkg/sentry/fs/proc/meminfo.go
+++ b/pkg/sentry/fs/proc/meminfo.go
@@ -26,8 +26,6 @@ import (
)
// meminfoData backs /proc/meminfo.
-//
-// +stateify savable
type meminfoData struct {
// k is the owning Kernel.
k *kernel.Kernel
diff --git a/pkg/sentry/fs/proc/mounts.go b/pkg/sentry/fs/proc/mounts.go
index 2b8167c28..108432f4e 100644
--- a/pkg/sentry/fs/proc/mounts.go
+++ b/pkg/sentry/fs/proc/mounts.go
@@ -71,8 +71,6 @@ func forEachMountSource(t *kernel.Task, fn func(string, *fs.MountSource)) {
}
// mountInfoFile is used to implement /proc/[pid]/mountinfo.
-//
-// +stateify savable
type mountInfoFile struct {
t *kernel.Task
}
@@ -154,8 +152,6 @@ func (mif *mountInfoFile) ReadSeqFileData(ctx context.Context, handle seqfile.Se
}
// mountsFile is used to implement /proc/[pid]/mountinfo.
-//
-// +stateify savable
type mountsFile struct {
t *kernel.Task
}
diff --git a/pkg/sentry/fs/proc/proc.go b/pkg/sentry/fs/proc/proc.go
index 07029a7bb..b2a8d639c 100644
--- a/pkg/sentry/fs/proc/proc.go
+++ b/pkg/sentry/fs/proc/proc.go
@@ -33,8 +33,6 @@ import (
)
// proc is a root proc node.
-//
-// +stateify savable
type proc struct {
ramfs.Dir
@@ -49,8 +47,6 @@ type proc struct {
// stubProcFSFile is a file type that can be used to return file contents
// which are constant. This file is not writable and will always have mode
// 0444.
-//
-// +stateify savable
type stubProcFSFile struct {
ramfs.Entry
diff --git a/pkg/sentry/fs/proc/seqfile/BUILD b/pkg/sentry/fs/proc/seqfile/BUILD
index 53c475652..c84f7e20d 100644
--- a/pkg/sentry/fs/proc/seqfile/BUILD
+++ b/pkg/sentry/fs/proc/seqfile/BUILD
@@ -1,10 +1,22 @@
package(licenses = ["notice"]) # Apache 2.0
-load("//tools/go_stateify:defs.bzl", "go_library", "go_test")
+load("//tools/go_stateify:defs.bzl", "go_library", "go_stateify", "go_test")
+
+go_stateify(
+ name = "seqfile_state",
+ srcs = [
+ "seqfile.go",
+ ],
+ out = "seqfile_state.go",
+ package = "seqfile",
+)
go_library(
name = "seqfile",
- srcs = ["seqfile.go"],
+ srcs = [
+ "seqfile.go",
+ "seqfile_state.go",
+ ],
importpath = "gvisor.googlesource.com/gvisor/pkg/sentry/fs/proc/seqfile",
visibility = ["//pkg/sentry:internal"],
deps = [
@@ -14,16 +26,26 @@ go_library(
"//pkg/sentry/fs/ramfs",
"//pkg/sentry/kernel/time",
"//pkg/sentry/usermem",
+ "//pkg/state",
],
)
+go_stateify(
+ name = "seqfile_test_state",
+ srcs = ["seqfile_test.go"],
+ out = "seqfile_test_state.go",
+ package = "seqfile",
+)
+
go_test(
name = "seqfile_test",
size = "small",
- srcs = ["seqfile_test.go"],
+ srcs = [
+ "seqfile_test.go",
+ "seqfile_test_state.go",
+ ],
embed = [":seqfile"],
deps = [
- "//pkg/sentry/context",
"//pkg/sentry/context/contexttest",
"//pkg/sentry/fs",
"//pkg/sentry/fs/ramfs/test",
diff --git a/pkg/sentry/fs/proc/seqfile/seqfile.go b/pkg/sentry/fs/proc/seqfile/seqfile.go
index 51cae5e37..c08565f8a 100644
--- a/pkg/sentry/fs/proc/seqfile/seqfile.go
+++ b/pkg/sentry/fs/proc/seqfile/seqfile.go
@@ -30,8 +30,6 @@ import (
type SeqHandle interface{}
// SeqData holds the data for one unit in the file.
-//
-// +stateify savable
type SeqData struct {
// The data to be returned to the user.
Buf []byte
@@ -84,8 +82,6 @@ func (s *SeqGenerationCounter) IsCurrent(generation int64) bool {
}
// SeqFile is used to provide dynamic files that can be ordered by record.
-//
-// +stateify savable
type SeqFile struct {
ramfs.Entry
diff --git a/pkg/sentry/fs/proc/stat.go b/pkg/sentry/fs/proc/stat.go
index bf7650211..284f3e52b 100644
--- a/pkg/sentry/fs/proc/stat.go
+++ b/pkg/sentry/fs/proc/stat.go
@@ -25,8 +25,6 @@ import (
)
// statData backs /proc/stat.
-//
-// +stateify savable
type statData struct {
// k is the owning Kernel.
k *kernel.Kernel
diff --git a/pkg/sentry/fs/proc/sys.go b/pkg/sentry/fs/proc/sys.go
index a2d36ca23..aab891c53 100644
--- a/pkg/sentry/fs/proc/sys.go
+++ b/pkg/sentry/fs/proc/sys.go
@@ -28,8 +28,6 @@ import (
)
// hostname is a file containing the system hostname.
-//
-// +stateify savable
type hostname struct {
ramfs.Entry
}
@@ -54,8 +52,6 @@ func (p *proc) newHostname(ctx context.Context, msrc *fs.MountSource) *fs.Inode
}
// mmapMinAddrData backs /proc/sys/vm/mmap_min_addr.
-//
-// +stateify savable
type mmapMinAddrData struct {
k *kernel.Kernel
}
@@ -78,7 +74,6 @@ func (d *mmapMinAddrData) ReadSeqFileData(ctx context.Context, h seqfile.SeqHand
}, 0
}
-// +stateify savable
type overcommitMemory struct{}
func (*overcommitMemory) NeedsUpdate(generation int64) bool {
diff --git a/pkg/sentry/fs/proc/sys_net.go b/pkg/sentry/fs/proc/sys_net.go
index beb25be20..f3a5043f8 100644
--- a/pkg/sentry/fs/proc/sys_net.go
+++ b/pkg/sentry/fs/proc/sys_net.go
@@ -33,7 +33,6 @@ const (
tcpWMem
)
-// +stateify savable
type tcpMem struct {
ramfs.Entry
s inet.Stack
@@ -101,7 +100,6 @@ func (m *tcpMem) DeprecatedPwritev(ctx context.Context, src usermem.IOSequence,
return n, cperr
}
-// +stateify savable
type tcpSack struct {
ramfs.Entry
s inet.Stack
diff --git a/pkg/sentry/fs/proc/task.go b/pkg/sentry/fs/proc/task.go
index 748ca4320..efc635946 100644
--- a/pkg/sentry/fs/proc/task.go
+++ b/pkg/sentry/fs/proc/task.go
@@ -52,8 +52,6 @@ func getTaskMM(t *kernel.Task) (*mm.MemoryManager, error) {
}
// taskDir represents a task-level directory.
-//
-// +stateify savable
type taskDir struct {
ramfs.Dir
@@ -94,8 +92,6 @@ func newTaskDir(t *kernel.Task, msrc *fs.MountSource, pidns *kernel.PIDNamespace
}
// subtasks represents a /proc/TID/task directory.
-//
-// +stateify savable
type subtasks struct {
ramfs.Dir
@@ -171,8 +167,6 @@ func (s *subtasks) DeprecatedReaddir(ctx context.Context, dirCtx *fs.DirCtx, off
}
// exe is an fs.InodeOperations symlink for the /proc/PID/exe file.
-//
-// +stateify savable
type exe struct {
ramfs.Symlink
@@ -232,8 +226,6 @@ func (e *exe) Readlink(ctx context.Context, inode *fs.Inode) (string, error) {
// namespaceFile represents a file in the namespacefs, such as the files in
// /proc/<pid>/ns.
-//
-// +stateify savable
type namespaceFile struct {
ramfs.Symlink
@@ -282,8 +274,6 @@ func newNamespaceDir(t *kernel.Task, msrc *fs.MountSource) *fs.Inode {
}
// mapsData implements seqfile.SeqSource for /proc/[pid]/maps.
-//
-// +stateify savable
type mapsData struct {
t *kernel.Task
}
@@ -321,7 +311,6 @@ func (md *mapsData) ReadSeqFileData(ctx context.Context, h seqfile.SeqHandle) ([
return []seqfile.SeqData{}, 0
}
-// +stateify savable
type taskStatData struct {
t *kernel.Task
@@ -402,8 +391,6 @@ func (s *taskStatData) ReadSeqFileData(ctx context.Context, h seqfile.SeqHandle)
}
// statmData implements seqfile.SeqSource for /proc/[pid]/statm.
-//
-// +stateify savable
type statmData struct {
t *kernel.Task
}
@@ -438,8 +425,6 @@ func (s *statmData) ReadSeqFileData(ctx context.Context, h seqfile.SeqHandle) ([
}
// statusData implements seqfile.SeqSource for /proc/[pid]/status.
-//
-// +stateify savable
type statusData struct {
t *kernel.Task
pidns *kernel.PIDNamespace
@@ -505,7 +490,6 @@ type ioUsage interface {
IOUsage() *usage.IO
}
-// +stateify savable
type ioData struct {
ioUsage
}
@@ -546,8 +530,6 @@ func (i *ioData) ReadSeqFileData(ctx context.Context, h seqfile.SeqHandle) ([]se
// On Linux, /proc/[pid]/comm is writable, and writing to the comm file changes
// the thread name. We don't implement this yet as there are no known users of
// this feature.
-//
-// +stateify savable
type comm struct {
ramfs.Entry
@@ -577,8 +559,6 @@ func (c *comm) DeprecatedPreadv(ctx context.Context, dst usermem.IOSequence, off
}
// auxvec is a file containing the auxiliary vector for a task.
-//
-// +stateify savable
type auxvec struct {
ramfs.Entry
diff --git a/pkg/sentry/fs/proc/uid_gid_map.go b/pkg/sentry/fs/proc/uid_gid_map.go
index 9811d9c9d..85acb5163 100644
--- a/pkg/sentry/fs/proc/uid_gid_map.go
+++ b/pkg/sentry/fs/proc/uid_gid_map.go
@@ -29,8 +29,6 @@ import (
// An idMapSeqSource is a seqfile.SeqSource that returns UID or GID mappings
// from a task's user namespace.
-//
-// +stateify savable
type idMapSeqSource struct {
t *kernel.Task
gids bool
@@ -72,7 +70,6 @@ type idMapSeqHandle struct {
value int
}
-// +stateify savable
type idMapSeqFile struct {
seqfile.SeqFile
}
diff --git a/pkg/sentry/fs/proc/uptime.go b/pkg/sentry/fs/proc/uptime.go
index f3a9b81df..4679d5821 100644
--- a/pkg/sentry/fs/proc/uptime.go
+++ b/pkg/sentry/fs/proc/uptime.go
@@ -27,8 +27,6 @@ import (
)
// uptime is a file containing the system uptime.
-//
-// +stateify savable
type uptime struct {
ramfs.Entry
diff --git a/pkg/sentry/fs/proc/version.go b/pkg/sentry/fs/proc/version.go
index 00f6a2afd..c0f2e87e3 100644
--- a/pkg/sentry/fs/proc/version.go
+++ b/pkg/sentry/fs/proc/version.go
@@ -23,8 +23,6 @@ import (
)
// versionData backs /proc/version.
-//
-// +stateify savable
type versionData struct {
// k is the owning Kernel.
k *kernel.Kernel
diff --git a/pkg/sentry/fs/ramfs/BUILD b/pkg/sentry/fs/ramfs/BUILD
index 5230157fe..d84f2c624 100644
--- a/pkg/sentry/fs/ramfs/BUILD
+++ b/pkg/sentry/fs/ramfs/BUILD
@@ -1,6 +1,19 @@
package(licenses = ["notice"]) # Apache 2.0
-load("//tools/go_stateify:defs.bzl", "go_library", "go_test")
+load("//tools/go_stateify:defs.bzl", "go_library", "go_stateify", "go_test")
+
+go_stateify(
+ name = "ramfs_state",
+ srcs = [
+ "dir.go",
+ "file.go",
+ "ramfs.go",
+ "socket.go",
+ "symlink.go",
+ ],
+ out = "ramfs_state.go",
+ package = "ramfs",
+)
go_library(
name = "ramfs",
@@ -8,6 +21,7 @@ go_library(
"dir.go",
"file.go",
"ramfs.go",
+ "ramfs_state.go",
"socket.go",
"symlink.go",
"tree.go",
@@ -15,8 +29,12 @@ go_library(
importpath = "gvisor.googlesource.com/gvisor/pkg/sentry/fs/ramfs",
visibility = ["//pkg/sentry:internal"],
deps = [
+ "//pkg/amutex",
+ "//pkg/log",
+ "//pkg/refs",
"//pkg/secio",
"//pkg/sentry/context",
+ "//pkg/sentry/device",
"//pkg/sentry/fs",
"//pkg/sentry/fs/anon",
"//pkg/sentry/fs/fsutil",
@@ -24,6 +42,7 @@ go_library(
"//pkg/sentry/memmap",
"//pkg/sentry/safemem",
"//pkg/sentry/usermem",
+ "//pkg/state",
"//pkg/syserror",
"//pkg/tcpip/transport/unix",
"//pkg/waiter",
diff --git a/pkg/sentry/fs/ramfs/dir.go b/pkg/sentry/fs/ramfs/dir.go
index 04432f28c..19d5612ed 100644
--- a/pkg/sentry/fs/ramfs/dir.go
+++ b/pkg/sentry/fs/ramfs/dir.go
@@ -44,8 +44,6 @@ type CreateOps struct {
}
// Dir represents a single directory in the filesystem.
-//
-// +stateify savable
type Dir struct {
Entry
diff --git a/pkg/sentry/fs/ramfs/ramfs.go b/pkg/sentry/fs/ramfs/ramfs.go
index 13e72e775..d6cfaf753 100644
--- a/pkg/sentry/fs/ramfs/ramfs.go
+++ b/pkg/sentry/fs/ramfs/ramfs.go
@@ -60,8 +60,6 @@ var (
// Entry represents common internal state for file and directory nodes.
// This may be used by other packages to easily create ramfs files.
-//
-// +stateify savable
type Entry struct {
waiter.AlwaysReady `state:"nosave"`
fsutil.NoMappable `state:"nosave"`
diff --git a/pkg/sentry/fs/ramfs/socket.go b/pkg/sentry/fs/ramfs/socket.go
index 93427a1ff..b0c79325f 100644
--- a/pkg/sentry/fs/ramfs/socket.go
+++ b/pkg/sentry/fs/ramfs/socket.go
@@ -21,8 +21,6 @@ import (
)
// Socket represents a socket.
-//
-// +stateify savable
type Socket struct {
Entry
diff --git a/pkg/sentry/fs/ramfs/symlink.go b/pkg/sentry/fs/ramfs/symlink.go
index 1c54d9991..9bbf78619 100644
--- a/pkg/sentry/fs/ramfs/symlink.go
+++ b/pkg/sentry/fs/ramfs/symlink.go
@@ -22,8 +22,6 @@ import (
)
// Symlink represents a symlink.
-//
-// +stateify savable
type Symlink struct {
Entry
diff --git a/pkg/sentry/fs/ramfs/test/BUILD b/pkg/sentry/fs/ramfs/test/BUILD
index 187eac49d..57fee45e2 100644
--- a/pkg/sentry/fs/ramfs/test/BUILD
+++ b/pkg/sentry/fs/ramfs/test/BUILD
@@ -1,16 +1,30 @@
package(licenses = ["notice"]) # Apache 2.0
-load("//tools/go_stateify:defs.bzl", "go_library")
+load("//tools/go_stateify:defs.bzl", "go_library", "go_stateify")
+
+go_stateify(
+ name = "test_state",
+ srcs = [
+ "test.go",
+ ],
+ out = "test_state.go",
+ package = "test",
+)
go_library(
name = "test",
testonly = 1,
- srcs = ["test.go"],
+ srcs = [
+ "test.go",
+ "test_state.go",
+ ],
importpath = "gvisor.googlesource.com/gvisor/pkg/sentry/fs/ramfs/test",
visibility = ["//pkg/sentry:internal"],
deps = [
"//pkg/sentry/context",
+ "//pkg/sentry/device",
"//pkg/sentry/fs",
"//pkg/sentry/fs/ramfs",
+ "//pkg/state",
],
)
diff --git a/pkg/sentry/fs/sys/BUILD b/pkg/sentry/fs/sys/BUILD
index bc24e980e..095ff1f25 100644
--- a/pkg/sentry/fs/sys/BUILD
+++ b/pkg/sentry/fs/sys/BUILD
@@ -1,6 +1,16 @@
package(licenses = ["notice"]) # Apache 2.0
-load("//tools/go_stateify:defs.bzl", "go_library")
+load("//tools/go_stateify:defs.bzl", "go_library", "go_stateify")
+
+go_stateify(
+ name = "sys_state",
+ srcs = [
+ "fs.go",
+ "sys.go",
+ ],
+ out = "sys_state.go",
+ package = "sys",
+)
go_library(
name = "sys",
@@ -8,6 +18,7 @@ go_library(
"device.go",
"fs.go",
"sys.go",
+ "sys_state.go",
],
importpath = "gvisor.googlesource.com/gvisor/pkg/sentry/fs/sys",
visibility = ["//pkg/sentry:internal"],
@@ -17,5 +28,6 @@ go_library(
"//pkg/sentry/fs",
"//pkg/sentry/fs/ramfs",
"//pkg/sentry/usermem",
+ "//pkg/state",
],
)
diff --git a/pkg/sentry/fs/sys/fs.go b/pkg/sentry/fs/sys/fs.go
index 625525540..c6d5f7fd8 100644
--- a/pkg/sentry/fs/sys/fs.go
+++ b/pkg/sentry/fs/sys/fs.go
@@ -20,8 +20,6 @@ import (
)
// filesystem is a sysfs.
-//
-// +stateify savable
type filesystem struct{}
func init() {
diff --git a/pkg/sentry/fs/sys/sys.go b/pkg/sentry/fs/sys/sys.go
index b9b2fb4a1..ccf56f644 100644
--- a/pkg/sentry/fs/sys/sys.go
+++ b/pkg/sentry/fs/sys/sys.go
@@ -22,13 +22,12 @@ import (
"gvisor.googlesource.com/gvisor/pkg/sentry/usermem"
)
-// +stateify savable
-type dir struct {
+type Dir struct {
ramfs.Dir
}
func newDir(ctx context.Context, msrc *fs.MountSource, contents map[string]*fs.Inode) *fs.Inode {
- d := &dir{}
+ d := &Dir{}
d.InitDir(ctx, contents, fs.RootOwner, fs.FilePermsFromMode(0555))
return fs.NewInode(d, msrc, fs.StableAttr{
DeviceID: sysfsDevice.DeviceID(),
diff --git a/pkg/sentry/fs/timerfd/BUILD b/pkg/sentry/fs/timerfd/BUILD
index ffdd7e0dc..8b1b7872e 100644
--- a/pkg/sentry/fs/timerfd/BUILD
+++ b/pkg/sentry/fs/timerfd/BUILD
@@ -1,19 +1,33 @@
package(licenses = ["notice"]) # Apache 2.0
-load("//tools/go_stateify:defs.bzl", "go_library")
+load("//tools/go_stateify:defs.bzl", "go_library", "go_stateify")
+
+go_stateify(
+ name = "timerfd_state",
+ srcs = [
+ "timerfd.go",
+ ],
+ out = "timerfd_state.go",
+ package = "timerfd",
+)
go_library(
name = "timerfd",
- srcs = ["timerfd.go"],
+ srcs = [
+ "timerfd.go",
+ "timerfd_state.go",
+ ],
importpath = "gvisor.googlesource.com/gvisor/pkg/sentry/fs/timerfd",
visibility = ["//pkg/sentry:internal"],
deps = [
+ "//pkg/refs",
"//pkg/sentry/context",
"//pkg/sentry/fs",
"//pkg/sentry/fs/anon",
"//pkg/sentry/fs/fsutil",
"//pkg/sentry/kernel/time",
"//pkg/sentry/usermem",
+ "//pkg/state",
"//pkg/syserror",
"//pkg/waiter",
],
diff --git a/pkg/sentry/fs/timerfd/timerfd.go b/pkg/sentry/fs/timerfd/timerfd.go
index 767db95a0..ae58f6fd7 100644
--- a/pkg/sentry/fs/timerfd/timerfd.go
+++ b/pkg/sentry/fs/timerfd/timerfd.go
@@ -30,8 +30,6 @@ import (
)
// TimerOperations implements fs.FileOperations for timerfds.
-//
-// +stateify savable
type TimerOperations struct {
fsutil.ZeroSeek `state:"nosave"`
fsutil.NotDirReaddir `state:"nosave"`
@@ -40,7 +38,7 @@ type TimerOperations struct {
fsutil.NoMMap `state:"nosave"`
fsutil.NoIoctl `state:"nosave"`
- events waiter.Queue `state:"zerovalue"`
+ events waiter.Queue `state:"nosave"`
timer *ktime.Timer
// val is the number of timer expirations since the last successful call to
diff --git a/pkg/sentry/fs/tmpfs/BUILD b/pkg/sentry/fs/tmpfs/BUILD
index cfe11ab02..473ab4296 100644
--- a/pkg/sentry/fs/tmpfs/BUILD
+++ b/pkg/sentry/fs/tmpfs/BUILD
@@ -1,6 +1,18 @@
package(licenses = ["notice"]) # Apache 2.0
-load("//tools/go_stateify:defs.bzl", "go_library", "go_test")
+load("//tools/go_stateify:defs.bzl", "go_library", "go_stateify", "go_test")
+
+go_stateify(
+ name = "tmpfs_state",
+ srcs = [
+ "file_regular.go",
+ "fs.go",
+ "inode_file.go",
+ "tmpfs.go",
+ ],
+ out = "tmpfs_state.go",
+ package = "tmpfs",
+)
go_library(
name = "tmpfs",
@@ -10,11 +22,13 @@ go_library(
"fs.go",
"inode_file.go",
"tmpfs.go",
+ "tmpfs_state.go",
],
importpath = "gvisor.googlesource.com/gvisor/pkg/sentry/fs/tmpfs",
visibility = ["//pkg/sentry:internal"],
deps = [
"//pkg/abi/linux",
+ "//pkg/log",
"//pkg/sentry/context",
"//pkg/sentry/device",
"//pkg/sentry/fs",
@@ -27,6 +41,7 @@ go_library(
"//pkg/sentry/safemem",
"//pkg/sentry/usage",
"//pkg/sentry/usermem",
+ "//pkg/state",
"//pkg/tcpip/transport/unix",
"//pkg/waiter",
],
diff --git a/pkg/sentry/fs/tmpfs/file_regular.go b/pkg/sentry/fs/tmpfs/file_regular.go
index 342688f81..9811d90bc 100644
--- a/pkg/sentry/fs/tmpfs/file_regular.go
+++ b/pkg/sentry/fs/tmpfs/file_regular.go
@@ -25,8 +25,6 @@ import (
// regularFileOperations implements fs.FileOperations for a regular
// tmpfs file.
-//
-// +stateify savable
type regularFileOperations struct {
waiter.AlwaysReady `state:"nosave"`
fsutil.NoopRelease `state:"nosave"`
diff --git a/pkg/sentry/fs/tmpfs/fs.go b/pkg/sentry/fs/tmpfs/fs.go
index ca620e65e..5bd9ade52 100644
--- a/pkg/sentry/fs/tmpfs/fs.go
+++ b/pkg/sentry/fs/tmpfs/fs.go
@@ -47,8 +47,6 @@ const (
var modeRegexp = regexp.MustCompile("0[0-7][0-7][0-7]")
// Filesystem is a tmpfs.
-//
-// +stateify savable
type Filesystem struct{}
func init() {
diff --git a/pkg/sentry/fs/tmpfs/inode_file.go b/pkg/sentry/fs/tmpfs/inode_file.go
index 1e4fe47d2..4e803c9ff 100644
--- a/pkg/sentry/fs/tmpfs/inode_file.go
+++ b/pkg/sentry/fs/tmpfs/inode_file.go
@@ -43,8 +43,6 @@ import (
// include an InvalidatorRegion associated with that reference. When the
// referenced portion of the file is removed (with Truncate), the associated
// InvalidatorRegion is invalidated.
-//
-// +stateify savable
type fileInodeOperations struct {
fsutil.DeprecatedFileOperations `state:"nosave"`
fsutil.InodeNotDirectory `state:"nosave"`
diff --git a/pkg/sentry/fs/tmpfs/tmpfs.go b/pkg/sentry/fs/tmpfs/tmpfs.go
index 10cb5451d..1cc7ae491 100644
--- a/pkg/sentry/fs/tmpfs/tmpfs.go
+++ b/pkg/sentry/fs/tmpfs/tmpfs.go
@@ -49,8 +49,6 @@ func rename(ctx context.Context, oldParent *fs.Inode, oldName string, newParent
}
// Dir is a directory.
-//
-// +stateify savable
type Dir struct {
ramfs.Dir
@@ -124,8 +122,6 @@ func (*Dir) StatFS(context.Context) (fs.Info, error) {
}
// Symlink is a symlink.
-//
-// +stateify savable
type Symlink struct {
ramfs.Symlink
}
@@ -153,8 +149,6 @@ func (s *Symlink) StatFS(context.Context) (fs.Info, error) {
}
// Socket is a socket.
-//
-// +stateify savable
type Socket struct {
ramfs.Socket
}
@@ -182,8 +176,6 @@ func (s *Socket) StatFS(context.Context) (fs.Info, error) {
}
// Fifo is a tmpfs named pipe.
-//
-// +stateify savable
type Fifo struct {
ramfs.Entry
}
diff --git a/pkg/sentry/fs/tty/BUILD b/pkg/sentry/fs/tty/BUILD
index 3c446eef4..363897b2c 100644
--- a/pkg/sentry/fs/tty/BUILD
+++ b/pkg/sentry/fs/tty/BUILD
@@ -1,6 +1,22 @@
package(licenses = ["notice"]) # Apache 2.0
-load("//tools/go_stateify:defs.bzl", "go_library", "go_test")
+load("//tools/go_stateify:defs.bzl", "go_library", "go_stateify", "go_test")
+
+go_stateify(
+ name = "tty_state",
+ srcs = [
+ "dir.go",
+ "fs.go",
+ "inode.go",
+ "line_discipline.go",
+ "master.go",
+ "queue.go",
+ "slave.go",
+ "terminal.go",
+ ],
+ out = "tty_state.go",
+ package = "tty",
+)
go_library(
name = "tty",
@@ -13,6 +29,7 @@ go_library(
"queue.go",
"slave.go",
"terminal.go",
+ "tty_state.go",
],
importpath = "gvisor.googlesource.com/gvisor/pkg/sentry/fs/tty",
visibility = ["//pkg/sentry:internal"],
@@ -27,6 +44,7 @@ go_library(
"//pkg/sentry/kernel/auth",
"//pkg/sentry/kernel/time",
"//pkg/sentry/usermem",
+ "//pkg/state",
"//pkg/syserror",
"//pkg/tcpip/transport/unix",
"//pkg/waiter",
diff --git a/pkg/sentry/fs/tty/dir.go b/pkg/sentry/fs/tty/dir.go
index c91091db4..2c5b2aed6 100644
--- a/pkg/sentry/fs/tty/dir.go
+++ b/pkg/sentry/fs/tty/dir.go
@@ -49,16 +49,14 @@ import (
// corresponding Dirents hold on their parent (this directory).
//
// dirInodeOperations implements fs.InodeOperations.
-//
-// +stateify savable
type dirInodeOperations struct {
- fsutil.DeprecatedFileOperations `state:"nosave"`
- fsutil.InodeNotSocket `state:"nosave"`
- fsutil.InodeNotRenameable `state:"nosave"`
- fsutil.InodeNotSymlink `state:"nosave"`
- fsutil.InodeNoExtendedAttributes `state:"nosave"`
- fsutil.NoMappable `state:"nosave"`
- fsutil.NoopWriteOut `state:"nosave"`
+ fsutil.DeprecatedFileOperations
+ fsutil.InodeNotSocket
+ fsutil.InodeNotRenameable
+ fsutil.InodeNotSymlink
+ fsutil.InodeNoExtendedAttributes
+ fsutil.NoMappable
+ fsutil.NoopWriteOut
// msrc is the super block this directory is on.
//
@@ -350,8 +348,6 @@ func (d *dirInodeOperations) masterClose(t *Terminal) {
//
// This is nearly identical to fsutil.DirFileOperations, except that it takes
// df.di.mu in IterateDir.
-//
-// +stateify savable
type dirFileOperations struct {
waiter.AlwaysReady `state:"nosave"`
fsutil.NoopRelease `state:"nosave"`
diff --git a/pkg/sentry/fs/tty/fs.go b/pkg/sentry/fs/tty/fs.go
index e28635607..dbaffe95e 100644
--- a/pkg/sentry/fs/tty/fs.go
+++ b/pkg/sentry/fs/tty/fs.go
@@ -28,8 +28,6 @@ var ptsDevice = device.NewAnonDevice()
//
// This devpts is always in the new "multi-instance" mode. i.e., it contains a
// ptmx device tied to this mount.
-//
-// +stateify savable
type filesystem struct{}
func init() {
@@ -71,8 +69,6 @@ func (f *filesystem) Mount(ctx context.Context, device string, flags fs.MountSou
}
// superOperations implements fs.MountSourceOperations, preventing caching.
-//
-// +stateify savable
type superOperations struct{}
// Revalidate implements fs.DirentOperations.Revalidate.
diff --git a/pkg/sentry/fs/tty/inode.go b/pkg/sentry/fs/tty/inode.go
index c0fa2b407..04b9a7727 100644
--- a/pkg/sentry/fs/tty/inode.go
+++ b/pkg/sentry/fs/tty/inode.go
@@ -31,8 +31,6 @@ import (
//
// * fs.InodeOperations.Release
// * fs.InodeOperations.GetFile
-//
-// +stateify savable
type inodeOperations struct {
fsutil.DeprecatedFileOperations `state:"nosave"`
fsutil.InodeNoExtendedAttributes `state:"nosave"`
diff --git a/pkg/sentry/fs/tty/line_discipline.go b/pkg/sentry/fs/tty/line_discipline.go
index d243ee40e..f094635f5 100644
--- a/pkg/sentry/fs/tty/line_discipline.go
+++ b/pkg/sentry/fs/tty/line_discipline.go
@@ -72,8 +72,6 @@ const (
// termiosMu
// inQueue.mu
// outQueue.mu
-//
-// +stateify savable
type lineDiscipline struct {
// inQueue is the input queue of the terminal.
inQueue queue
@@ -185,8 +183,6 @@ type transformer interface {
// outputQueueTransformer implements transformer. It performs line discipline
// transformations on the output queue.
-//
-// +stateify savable
type outputQueueTransformer struct{}
// transform does output processing for one end of the pty. See
@@ -258,8 +254,6 @@ func (*outputQueueTransformer) transform(l *lineDiscipline, q *queue, buf []byte
// inputQueueTransformer implements transformer. It performs line discipline
// transformations on the input queue.
-//
-// +stateify savable
type inputQueueTransformer struct{}
// transform does input processing for one end of the pty. Characters read are
diff --git a/pkg/sentry/fs/tty/master.go b/pkg/sentry/fs/tty/master.go
index c7198e218..74cdbe874 100644
--- a/pkg/sentry/fs/tty/master.go
+++ b/pkg/sentry/fs/tty/master.go
@@ -27,8 +27,6 @@ import (
// masterInodeOperations are the fs.InodeOperations for the master end of the
// Terminal (ptmx file).
-//
-// +stateify savable
type masterInodeOperations struct {
inodeOperations
@@ -98,8 +96,6 @@ func (mi *masterInodeOperations) GetFile(ctx context.Context, d *fs.Dirent, flag
}
// masterFileOperations are the fs.FileOperations for the master end of a terminal.
-//
-// +stateify savable
type masterFileOperations struct {
fsutil.PipeSeek `state:"nosave"`
fsutil.NotDirReaddir `state:"nosave"`
diff --git a/pkg/sentry/fs/tty/queue.go b/pkg/sentry/fs/tty/queue.go
index 42c105abc..026d5e077 100644
--- a/pkg/sentry/fs/tty/queue.go
+++ b/pkg/sentry/fs/tty/queue.go
@@ -32,13 +32,11 @@ import (
// processed (i.e. undergo termios transformations) as they are added to the
// read buffer. The read buffer is readable when its length is nonzero and
// readable is true.
-//
-// +stateify savable
type queue struct {
// mu protects everything in queue.
mu sync.Mutex `state:"nosave"`
- waiter.Queue `state:"zerovalue"`
+ waiter.Queue `state:"nosave"`
// readBuf is buffer of data ready to be read when readable is true.
// This data has been processed.
diff --git a/pkg/sentry/fs/tty/slave.go b/pkg/sentry/fs/tty/slave.go
index 1c562b172..f5eec726e 100644
--- a/pkg/sentry/fs/tty/slave.go
+++ b/pkg/sentry/fs/tty/slave.go
@@ -27,8 +27,6 @@ import (
// slaveInodeOperations are the fs.InodeOperations for the slave end of the
// Terminal (pts file).
-//
-// +stateify savable
type slaveInodeOperations struct {
inodeOperations
@@ -88,8 +86,6 @@ func (si *slaveInodeOperations) GetFile(ctx context.Context, d *fs.Dirent, flags
}
// slaveFileOperations are the fs.FileOperations for the slave end of a terminal.
-//
-// +stateify savable
type slaveFileOperations struct {
fsutil.PipeSeek `state:"nosave"`
fsutil.NotDirReaddir `state:"nosave"`
diff --git a/pkg/sentry/fs/tty/terminal.go b/pkg/sentry/fs/tty/terminal.go
index 3cb135124..fa5b00409 100644
--- a/pkg/sentry/fs/tty/terminal.go
+++ b/pkg/sentry/fs/tty/terminal.go
@@ -21,8 +21,6 @@ import (
)
// Terminal is a pseudoterminal.
-//
-// +stateify savable
type Terminal struct {
refs.AtomicRefCount