diff options
Diffstat (limited to 'pkg/sentry/fsimpl/overlay')
-rw-r--r-- | pkg/sentry/fsimpl/overlay/BUILD | 41 | ||||
-rw-r--r-- | pkg/sentry/fsimpl/overlay/fstree.go | 46 | ||||
-rw-r--r-- | pkg/sentry/fsimpl/overlay/overlay_state_autogen.go | 288 |
3 files changed, 334 insertions, 41 deletions
diff --git a/pkg/sentry/fsimpl/overlay/BUILD b/pkg/sentry/fsimpl/overlay/BUILD deleted file mode 100644 index 8cf5b35d3..000000000 --- a/pkg/sentry/fsimpl/overlay/BUILD +++ /dev/null @@ -1,41 +0,0 @@ -load("//tools:defs.bzl", "go_library") -load("//tools/go_generics:defs.bzl", "go_template_instance") - -licenses(["notice"]) - -go_template_instance( - name = "fstree", - out = "fstree.go", - package = "overlay", - prefix = "generic", - template = "//pkg/sentry/vfs/genericfstree:generic_fstree", - types = { - "Dentry": "dentry", - }, -) - -go_library( - name = "overlay", - srcs = [ - "copy_up.go", - "directory.go", - "filesystem.go", - "fstree.go", - "non_directory.go", - "overlay.go", - ], - visibility = ["//pkg/sentry:internal"], - deps = [ - "//pkg/abi/linux", - "//pkg/context", - "//pkg/fspath", - "//pkg/sentry/fs/lock", - "//pkg/sentry/kernel/auth", - "//pkg/sentry/memmap", - "//pkg/sentry/socket/unix/transport", - "//pkg/sentry/vfs", - "//pkg/sync", - "//pkg/syserror", - "//pkg/usermem", - ], -) diff --git a/pkg/sentry/fsimpl/overlay/fstree.go b/pkg/sentry/fsimpl/overlay/fstree.go new file mode 100644 index 000000000..1fa1b4ad3 --- /dev/null +++ b/pkg/sentry/fsimpl/overlay/fstree.go @@ -0,0 +1,46 @@ +package overlay + +import ( + "gvisor.dev/gvisor/pkg/fspath" + "gvisor.dev/gvisor/pkg/sentry/vfs" +) + +// IsAncestorDentry returns true if d is an ancestor of d2; that is, d is +// either d2's parent or an ancestor of d2's parent. +func genericIsAncestorDentry(d, d2 *dentry) bool { + for d2 != nil { + if d2.parent == d { + return true + } + if d2.parent == d2 { + return false + } + d2 = d2.parent + } + return false +} + +// ParentOrSelf returns d.parent. If d.parent is nil, ParentOrSelf returns d. +func genericParentOrSelf(d *dentry) *dentry { + if d.parent != nil { + return d.parent + } + return d +} + +// PrependPath is a generic implementation of FilesystemImpl.PrependPath(). +func genericPrependPath(vfsroot vfs.VirtualDentry, mnt *vfs.Mount, d *dentry, b *fspath.Builder) error { + for { + if mnt == vfsroot.Mount() && &d.vfsd == vfsroot.Dentry() { + return vfs.PrependPathAtVFSRootError{} + } + if &d.vfsd == mnt.Root() { + return nil + } + if d.parent == nil { + return vfs.PrependPathAtNonMountRootError{} + } + b.PrependComponent(d.name) + d = d.parent + } +} diff --git a/pkg/sentry/fsimpl/overlay/overlay_state_autogen.go b/pkg/sentry/fsimpl/overlay/overlay_state_autogen.go new file mode 100644 index 000000000..d3e649672 --- /dev/null +++ b/pkg/sentry/fsimpl/overlay/overlay_state_autogen.go @@ -0,0 +1,288 @@ +// automatically generated by stateify. + +package overlay + +import ( + "gvisor.dev/gvisor/pkg/state" +) + +func (x *directoryFD) StateTypeName() string { + return "pkg/sentry/fsimpl/overlay.directoryFD" +} + +func (x *directoryFD) StateFields() []string { + return []string{ + "fileDescription", + "DirectoryFileDescriptionDefaultImpl", + "DentryMetadataFileDescriptionImpl", + "off", + "dirents", + } +} + +func (x *directoryFD) beforeSave() {} + +func (x *directoryFD) StateSave(m state.Sink) { + x.beforeSave() + m.Save(0, &x.fileDescription) + m.Save(1, &x.DirectoryFileDescriptionDefaultImpl) + m.Save(2, &x.DentryMetadataFileDescriptionImpl) + m.Save(3, &x.off) + m.Save(4, &x.dirents) +} + +func (x *directoryFD) afterLoad() {} + +func (x *directoryFD) StateLoad(m state.Source) { + m.Load(0, &x.fileDescription) + m.Load(1, &x.DirectoryFileDescriptionDefaultImpl) + m.Load(2, &x.DentryMetadataFileDescriptionImpl) + m.Load(3, &x.off) + m.Load(4, &x.dirents) +} + +func (x *nonDirectoryFD) StateTypeName() string { + return "pkg/sentry/fsimpl/overlay.nonDirectoryFD" +} + +func (x *nonDirectoryFD) StateFields() []string { + return []string{ + "fileDescription", + "copiedUp", + "cachedFD", + "cachedFlags", + } +} + +func (x *nonDirectoryFD) beforeSave() {} + +func (x *nonDirectoryFD) StateSave(m state.Sink) { + x.beforeSave() + m.Save(0, &x.fileDescription) + m.Save(1, &x.copiedUp) + m.Save(2, &x.cachedFD) + m.Save(3, &x.cachedFlags) +} + +func (x *nonDirectoryFD) afterLoad() {} + +func (x *nonDirectoryFD) StateLoad(m state.Source) { + m.Load(0, &x.fileDescription) + m.Load(1, &x.copiedUp) + m.Load(2, &x.cachedFD) + m.Load(3, &x.cachedFlags) +} + +func (x *FilesystemType) StateTypeName() string { + return "pkg/sentry/fsimpl/overlay.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 *FilesystemOptions) StateTypeName() string { + return "pkg/sentry/fsimpl/overlay.FilesystemOptions" +} + +func (x *FilesystemOptions) StateFields() []string { + return []string{ + "UpperRoot", + "LowerRoots", + } +} + +func (x *FilesystemOptions) beforeSave() {} + +func (x *FilesystemOptions) StateSave(m state.Sink) { + x.beforeSave() + m.Save(0, &x.UpperRoot) + m.Save(1, &x.LowerRoots) +} + +func (x *FilesystemOptions) afterLoad() {} + +func (x *FilesystemOptions) StateLoad(m state.Source) { + m.Load(0, &x.UpperRoot) + m.Load(1, &x.LowerRoots) +} + +func (x *filesystem) StateTypeName() string { + return "pkg/sentry/fsimpl/overlay.filesystem" +} + +func (x *filesystem) StateFields() []string { + return []string{ + "vfsfs", + "opts", + "creds", + "dirDevMinor", + "lowerDevMinors", + "lastDirIno", + } +} + +func (x *filesystem) beforeSave() {} + +func (x *filesystem) StateSave(m state.Sink) { + x.beforeSave() + m.Save(0, &x.vfsfs) + m.Save(1, &x.opts) + m.Save(2, &x.creds) + m.Save(3, &x.dirDevMinor) + m.Save(4, &x.lowerDevMinors) + m.Save(5, &x.lastDirIno) +} + +func (x *filesystem) afterLoad() {} + +func (x *filesystem) StateLoad(m state.Source) { + m.Load(0, &x.vfsfs) + m.Load(1, &x.opts) + m.Load(2, &x.creds) + m.Load(3, &x.dirDevMinor) + m.Load(4, &x.lowerDevMinors) + m.Load(5, &x.lastDirIno) +} + +func (x *dentry) StateTypeName() string { + return "pkg/sentry/fsimpl/overlay.dentry" +} + +func (x *dentry) StateFields() []string { + return []string{ + "vfsd", + "refs", + "fs", + "mode", + "uid", + "gid", + "copiedUp", + "parent", + "name", + "children", + "dirents", + "upperVD", + "lowerVDs", + "inlineLowerVDs", + "devMajor", + "devMinor", + "ino", + "mapsMu", + "lowerMappings", + "dataMu", + "wrappedMappable", + "isMappable", + "locks", + "watches", + } +} + +func (x *dentry) beforeSave() {} + +func (x *dentry) StateSave(m state.Sink) { + x.beforeSave() + m.Save(0, &x.vfsd) + m.Save(1, &x.refs) + m.Save(2, &x.fs) + m.Save(3, &x.mode) + m.Save(4, &x.uid) + m.Save(5, &x.gid) + m.Save(6, &x.copiedUp) + m.Save(7, &x.parent) + m.Save(8, &x.name) + m.Save(9, &x.children) + m.Save(10, &x.dirents) + m.Save(11, &x.upperVD) + m.Save(12, &x.lowerVDs) + m.Save(13, &x.inlineLowerVDs) + m.Save(14, &x.devMajor) + m.Save(15, &x.devMinor) + m.Save(16, &x.ino) + m.Save(17, &x.mapsMu) + m.Save(18, &x.lowerMappings) + m.Save(19, &x.dataMu) + m.Save(20, &x.wrappedMappable) + m.Save(21, &x.isMappable) + m.Save(22, &x.locks) + m.Save(23, &x.watches) +} + +func (x *dentry) afterLoad() {} + +func (x *dentry) StateLoad(m state.Source) { + m.Load(0, &x.vfsd) + m.Load(1, &x.refs) + m.Load(2, &x.fs) + m.Load(3, &x.mode) + m.Load(4, &x.uid) + m.Load(5, &x.gid) + m.Load(6, &x.copiedUp) + m.Load(7, &x.parent) + m.Load(8, &x.name) + m.Load(9, &x.children) + m.Load(10, &x.dirents) + m.Load(11, &x.upperVD) + m.Load(12, &x.lowerVDs) + m.Load(13, &x.inlineLowerVDs) + m.Load(14, &x.devMajor) + m.Load(15, &x.devMinor) + m.Load(16, &x.ino) + m.Load(17, &x.mapsMu) + m.Load(18, &x.lowerMappings) + m.Load(19, &x.dataMu) + m.Load(20, &x.wrappedMappable) + m.Load(21, &x.isMappable) + m.Load(22, &x.locks) + m.Load(23, &x.watches) +} + +func (x *fileDescription) StateTypeName() string { + return "pkg/sentry/fsimpl/overlay.fileDescription" +} + +func (x *fileDescription) StateFields() []string { + return []string{ + "vfsfd", + "FileDescriptionDefaultImpl", + "LockFD", + } +} + +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) +} + +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) +} + +func init() { + state.Register((*directoryFD)(nil)) + state.Register((*nonDirectoryFD)(nil)) + state.Register((*FilesystemType)(nil)) + state.Register((*FilesystemOptions)(nil)) + state.Register((*filesystem)(nil)) + state.Register((*dentry)(nil)) + state.Register((*fileDescription)(nil)) +} |