summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fsimpl/host
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2020-09-24 17:19:53 +0000
committergVisor bot <gvisor-bot@google.com>2020-09-24 17:19:53 +0000
commit61cc049caaa2317eda73e66f65f82b5099dd2bc2 (patch)
tree352bfc9c114c181e052a9656be9f3b2acd5f7b33 /pkg/sentry/fsimpl/host
parent3102024707dc370e025f1b46fa2be12eade2f9cb (diff)
parent0a7075f38a4870ded687e117a299ac4996c0673e (diff)
Merge release-20200914.0-152-g0a7075f38 (automated)
Diffstat (limited to 'pkg/sentry/fsimpl/host')
-rw-r--r--pkg/sentry/fsimpl/host/host.go12
-rw-r--r--pkg/sentry/fsimpl/host/host_state_autogen.go209
-rw-r--r--pkg/sentry/fsimpl/host/mmap.go6
-rw-r--r--pkg/sentry/fsimpl/host/tty.go2
4 files changed, 225 insertions, 4 deletions
diff --git a/pkg/sentry/fsimpl/host/host.go b/pkg/sentry/fsimpl/host/host.go
index c0cef3453..ffe4ddb32 100644
--- a/pkg/sentry/fsimpl/host/host.go
+++ b/pkg/sentry/fsimpl/host/host.go
@@ -137,6 +137,8 @@ func ImportFD(ctx context.Context, mnt *vfs.Mount, hostFD int, isTTY bool) (*vfs
}
// filesystemType implements vfs.FilesystemType.
+//
+// +stateify savable
type filesystemType struct{}
// GetFilesystem implements vfs.FilesystemType.GetFilesystem.
@@ -166,6 +168,8 @@ func NewFilesystem(vfsObj *vfs.VirtualFilesystem) (*vfs.Filesystem, error) {
}
// filesystem implements vfs.FilesystemImpl.
+//
+// +stateify savable
type filesystem struct {
kernfs.Filesystem
@@ -185,6 +189,8 @@ func (fs *filesystem) PrependPath(ctx context.Context, vfsroot, vd vfs.VirtualDe
}
// inode implements kernfs.Inode.
+//
+// +stateify savable
type inode struct {
kernfs.InodeNoStatFS
kernfs.InodeNotDirectory
@@ -233,7 +239,7 @@ type inode struct {
canMap bool
// mapsMu protects mappings.
- mapsMu sync.Mutex
+ mapsMu sync.Mutex `state:"nosave"`
// If canMap is true, mappings tracks mappings of hostFD into
// memmap.MappingSpaces.
@@ -511,6 +517,8 @@ func (i *inode) open(ctx context.Context, d *kernfs.Dentry, mnt *vfs.Mount, flag
}
// fileDescription is embedded by host fd implementations of FileDescriptionImpl.
+//
+// +stateify savable
type fileDescription struct {
vfsfd vfs.FileDescription
vfs.FileDescriptionDefaultImpl
@@ -525,7 +533,7 @@ type fileDescription struct {
inode *inode
// offsetMu protects offset.
- offsetMu sync.Mutex
+ offsetMu sync.Mutex `state:"nosave"`
// offset specifies the current file offset. It is only meaningful when
// inode.seekable is true.
diff --git a/pkg/sentry/fsimpl/host/host_state_autogen.go b/pkg/sentry/fsimpl/host/host_state_autogen.go
index 400320c78..c97fa7212 100644
--- a/pkg/sentry/fsimpl/host/host_state_autogen.go
+++ b/pkg/sentry/fsimpl/host/host_state_autogen.go
@@ -29,6 +29,148 @@ func (x *ConnectedEndpointRefs) StateLoad(m state.Source) {
m.Load(0, &x.refCount)
}
+func (x *filesystemType) StateTypeName() string {
+ return "pkg/sentry/fsimpl/host.filesystemType"
+}
+
+func (x *filesystemType) StateFields() []string {
+ return []string{}
+}
+
+func (x *filesystemType) beforeSave() {}
+
+func (x *filesystemType) StateSave(m state.Sink) {
+ x.beforeSave()
+}
+
+func (x *filesystemType) afterLoad() {}
+
+func (x *filesystemType) StateLoad(m state.Source) {
+}
+
+func (x *filesystem) StateTypeName() string {
+ return "pkg/sentry/fsimpl/host.filesystem"
+}
+
+func (x *filesystem) StateFields() []string {
+ return []string{
+ "Filesystem",
+ "devMinor",
+ }
+}
+
+func (x *filesystem) beforeSave() {}
+
+func (x *filesystem) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.Filesystem)
+ m.Save(1, &x.devMinor)
+}
+
+func (x *filesystem) afterLoad() {}
+
+func (x *filesystem) StateLoad(m state.Source) {
+ m.Load(0, &x.Filesystem)
+ m.Load(1, &x.devMinor)
+}
+
+func (x *inode) StateTypeName() string {
+ return "pkg/sentry/fsimpl/host.inode"
+}
+
+func (x *inode) StateFields() []string {
+ return []string{
+ "InodeNoStatFS",
+ "InodeNotDirectory",
+ "InodeNotSymlink",
+ "locks",
+ "inodeRefs",
+ "hostFD",
+ "ino",
+ "isTTY",
+ "seekable",
+ "wouldBlock",
+ "queue",
+ "canMap",
+ "mappings",
+ "pf",
+ }
+}
+
+func (x *inode) beforeSave() {}
+
+func (x *inode) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.InodeNoStatFS)
+ m.Save(1, &x.InodeNotDirectory)
+ m.Save(2, &x.InodeNotSymlink)
+ m.Save(3, &x.locks)
+ m.Save(4, &x.inodeRefs)
+ m.Save(5, &x.hostFD)
+ m.Save(6, &x.ino)
+ m.Save(7, &x.isTTY)
+ m.Save(8, &x.seekable)
+ m.Save(9, &x.wouldBlock)
+ m.Save(10, &x.queue)
+ m.Save(11, &x.canMap)
+ m.Save(12, &x.mappings)
+ m.Save(13, &x.pf)
+}
+
+func (x *inode) afterLoad() {}
+
+func (x *inode) StateLoad(m state.Source) {
+ m.Load(0, &x.InodeNoStatFS)
+ m.Load(1, &x.InodeNotDirectory)
+ m.Load(2, &x.InodeNotSymlink)
+ m.Load(3, &x.locks)
+ m.Load(4, &x.inodeRefs)
+ m.Load(5, &x.hostFD)
+ m.Load(6, &x.ino)
+ m.Load(7, &x.isTTY)
+ m.Load(8, &x.seekable)
+ m.Load(9, &x.wouldBlock)
+ m.Load(10, &x.queue)
+ m.Load(11, &x.canMap)
+ m.Load(12, &x.mappings)
+ m.Load(13, &x.pf)
+}
+
+func (x *fileDescription) StateTypeName() string {
+ return "pkg/sentry/fsimpl/host.fileDescription"
+}
+
+func (x *fileDescription) StateFields() []string {
+ return []string{
+ "vfsfd",
+ "FileDescriptionDefaultImpl",
+ "LockFD",
+ "inode",
+ "offset",
+ }
+}
+
+func (x *fileDescription) beforeSave() {}
+
+func (x *fileDescription) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.vfsfd)
+ m.Save(1, &x.FileDescriptionDefaultImpl)
+ m.Save(2, &x.LockFD)
+ m.Save(3, &x.inode)
+ m.Save(4, &x.offset)
+}
+
+func (x *fileDescription) afterLoad() {}
+
+func (x *fileDescription) StateLoad(m state.Source) {
+ m.Load(0, &x.vfsfd)
+ m.Load(1, &x.FileDescriptionDefaultImpl)
+ m.Load(2, &x.LockFD)
+ m.Load(3, &x.inode)
+ m.Load(4, &x.offset)
+}
+
func (x *inodeRefs) StateTypeName() string {
return "pkg/sentry/fsimpl/host.inodeRefs"
}
@@ -52,6 +194,35 @@ func (x *inodeRefs) StateLoad(m state.Source) {
m.Load(0, &x.refCount)
}
+func (x *inodePlatformFile) StateTypeName() string {
+ return "pkg/sentry/fsimpl/host.inodePlatformFile"
+}
+
+func (x *inodePlatformFile) StateFields() []string {
+ return []string{
+ "inode",
+ "fdRefs",
+ "fileMapper",
+ }
+}
+
+func (x *inodePlatformFile) beforeSave() {}
+
+func (x *inodePlatformFile) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.inode)
+ m.Save(1, &x.fdRefs)
+ m.Save(2, &x.fileMapper)
+}
+
+func (x *inodePlatformFile) afterLoad() {}
+
+func (x *inodePlatformFile) StateLoad(m state.Source) {
+ m.Load(0, &x.inode)
+ m.Load(1, &x.fdRefs)
+ m.Load(2, &x.fileMapper)
+}
+
func (x *ConnectedEndpoint) StateTypeName() string {
return "pkg/sentry/fsimpl/host.ConnectedEndpoint"
}
@@ -84,8 +255,46 @@ func (x *ConnectedEndpoint) StateLoad(m state.Source) {
m.Load(3, &x.stype)
}
+func (x *TTYFileDescription) StateTypeName() string {
+ return "pkg/sentry/fsimpl/host.TTYFileDescription"
+}
+
+func (x *TTYFileDescription) StateFields() []string {
+ return []string{
+ "fileDescription",
+ "session",
+ "fgProcessGroup",
+ "termios",
+ }
+}
+
+func (x *TTYFileDescription) beforeSave() {}
+
+func (x *TTYFileDescription) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.fileDescription)
+ m.Save(1, &x.session)
+ m.Save(2, &x.fgProcessGroup)
+ m.Save(3, &x.termios)
+}
+
+func (x *TTYFileDescription) afterLoad() {}
+
+func (x *TTYFileDescription) StateLoad(m state.Source) {
+ m.Load(0, &x.fileDescription)
+ m.Load(1, &x.session)
+ m.Load(2, &x.fgProcessGroup)
+ m.Load(3, &x.termios)
+}
+
func init() {
state.Register((*ConnectedEndpointRefs)(nil))
+ state.Register((*filesystemType)(nil))
+ state.Register((*filesystem)(nil))
+ state.Register((*inode)(nil))
+ state.Register((*fileDescription)(nil))
state.Register((*inodeRefs)(nil))
+ state.Register((*inodePlatformFile)(nil))
state.Register((*ConnectedEndpoint)(nil))
+ state.Register((*TTYFileDescription)(nil))
}
diff --git a/pkg/sentry/fsimpl/host/mmap.go b/pkg/sentry/fsimpl/host/mmap.go
index 65d3af38c..b51a17bed 100644
--- a/pkg/sentry/fsimpl/host/mmap.go
+++ b/pkg/sentry/fsimpl/host/mmap.go
@@ -27,11 +27,13 @@ import (
// cannot implement both kernfs.Inode.IncRef and memmap.File.IncRef.
//
// inodePlatformFile should only be used if inode.canMap is true.
+//
+// +stateify savable
type inodePlatformFile struct {
*inode
// fdRefsMu protects fdRefs.
- fdRefsMu sync.Mutex
+ fdRefsMu sync.Mutex `state:"nosave"`
// fdRefs counts references on memmap.File offsets. It is used solely for
// memory accounting.
@@ -41,7 +43,7 @@ type inodePlatformFile struct {
fileMapper fsutil.HostFileMapper
// fileMapperInitOnce is used to lazily initialize fileMapper.
- fileMapperInitOnce sync.Once
+ fileMapperInitOnce sync.Once `state:"nosave"` // FIXME(gvisor.dev/issue/1663): not yet supported.
}
// IncRef implements memmap.File.IncRef.
diff --git a/pkg/sentry/fsimpl/host/tty.go b/pkg/sentry/fsimpl/host/tty.go
index e02b9b8f6..f5c596fec 100644
--- a/pkg/sentry/fsimpl/host/tty.go
+++ b/pkg/sentry/fsimpl/host/tty.go
@@ -30,6 +30,8 @@ import (
// TTYFileDescription implements vfs.FileDescriptionImpl for a host file
// descriptor that wraps a TTY FD.
+//
+// +stateify savable
type TTYFileDescription struct {
fileDescription