summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fsimpl/kernfs
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2020-08-28 21:35:00 +0000
committergVisor bot <gvisor-bot@google.com>2020-08-28 21:35:00 +0000
commit62daea73a85389e465e8b53a0dce9ac1f080e049 (patch)
tree1951814a20c0a868e3146dff0da000228f482785 /pkg/sentry/fsimpl/kernfs
parent91b955365d69946173b510f727d843103e8c79b6 (diff)
parentb4820e598681c61fbf0e8a7f4d3436d2599ce53c (diff)
Merge release-20200818.0-84-gb4820e598 (automated)
Diffstat (limited to 'pkg/sentry/fsimpl/kernfs')
-rw-r--r--pkg/sentry/fsimpl/kernfs/dentry_refs.go2
-rw-r--r--pkg/sentry/fsimpl/kernfs/dynamic_bytes_file.go1
-rw-r--r--pkg/sentry/fsimpl/kernfs/filesystem.go5
-rw-r--r--pkg/sentry/fsimpl/kernfs/inode_impl_util.go16
-rw-r--r--pkg/sentry/fsimpl/kernfs/kernfs.go5
-rw-r--r--pkg/sentry/fsimpl/kernfs/kernfs_state_autogen.go60
-rw-r--r--pkg/sentry/fsimpl/kernfs/static_directory_refs.go2
-rw-r--r--pkg/sentry/fsimpl/kernfs/symlink.go1
8 files changed, 57 insertions, 35 deletions
diff --git a/pkg/sentry/fsimpl/kernfs/dentry_refs.go b/pkg/sentry/fsimpl/kernfs/dentry_refs.go
index dd5325635..79863b3bc 100644
--- a/pkg/sentry/fsimpl/kernfs/dentry_refs.go
+++ b/pkg/sentry/fsimpl/kernfs/dentry_refs.go
@@ -2,11 +2,11 @@ package kernfs
import (
"fmt"
- refs_vfs1 "gvisor.dev/gvisor/pkg/refs"
"runtime"
"sync/atomic"
"gvisor.dev/gvisor/pkg/log"
+ refs_vfs1 "gvisor.dev/gvisor/pkg/refs"
)
// ownerType is used to customize logging. Note that we use a pointer to T so
diff --git a/pkg/sentry/fsimpl/kernfs/dynamic_bytes_file.go b/pkg/sentry/fsimpl/kernfs/dynamic_bytes_file.go
index 12adf727a..1ee089620 100644
--- a/pkg/sentry/fsimpl/kernfs/dynamic_bytes_file.go
+++ b/pkg/sentry/fsimpl/kernfs/dynamic_bytes_file.go
@@ -35,6 +35,7 @@ import (
// +stateify savable
type DynamicBytesFile struct {
InodeAttrs
+ InodeNoStatFS
InodeNoopRefCount
InodeNotDirectory
InodeNotSymlink
diff --git a/pkg/sentry/fsimpl/kernfs/filesystem.go b/pkg/sentry/fsimpl/kernfs/filesystem.go
index e5d6b5c35..0e3011689 100644
--- a/pkg/sentry/fsimpl/kernfs/filesystem.go
+++ b/pkg/sentry/fsimpl/kernfs/filesystem.go
@@ -721,14 +721,13 @@ func (fs *Filesystem) StatAt(ctx context.Context, rp *vfs.ResolvingPath, opts vf
// StatFSAt implements vfs.FilesystemImpl.StatFSAt.
func (fs *Filesystem) StatFSAt(ctx context.Context, rp *vfs.ResolvingPath) (linux.Statfs, error) {
fs.mu.RLock()
- _, _, err := fs.walkExistingLocked(ctx, rp)
+ _, inode, err := fs.walkExistingLocked(ctx, rp)
fs.mu.RUnlock()
fs.processDeferredDecRefs(ctx)
if err != nil {
return linux.Statfs{}, err
}
- // TODO(gvisor.dev/issue/1193): actually implement statfs.
- return linux.Statfs{}, syserror.ENOSYS
+ return inode.StatFS(ctx, fs.VFSFilesystem())
}
// SymlinkAt implements vfs.FilesystemImpl.SymlinkAt.
diff --git a/pkg/sentry/fsimpl/kernfs/inode_impl_util.go b/pkg/sentry/fsimpl/kernfs/inode_impl_util.go
index f442a5606..c0b863ba4 100644
--- a/pkg/sentry/fsimpl/kernfs/inode_impl_util.go
+++ b/pkg/sentry/fsimpl/kernfs/inode_impl_util.go
@@ -546,12 +546,13 @@ func (InodeSymlink) Open(ctx context.Context, rp *vfs.ResolvingPath, vfsd *vfs.D
//
// +stateify savable
type StaticDirectory struct {
- StaticDirectoryRefs
- InodeNotSymlink
- InodeDirectoryNoNewChildren
InodeAttrs
+ InodeDirectoryNoNewChildren
InodeNoDynamicLookup
+ InodeNoStatFS
+ InodeNotSymlink
OrderedChildren
+ StaticDirectoryRefs
locks vfs.FileLocks
fdOpts GenericDirectoryFDOptions
@@ -609,3 +610,12 @@ type AlwaysValid struct{}
func (*AlwaysValid) Valid(context.Context) bool {
return true
}
+
+// InodeNoStatFS partially implements the Inode interface, where the client
+// filesystem doesn't support statfs(2).
+type InodeNoStatFS struct{}
+
+// StatFS implements Inode.StatFS.
+func (*InodeNoStatFS) StatFS(context.Context, *vfs.Filesystem) (linux.Statfs, error) {
+ return linux.Statfs{}, syserror.ENOSYS
+}
diff --git a/pkg/sentry/fsimpl/kernfs/kernfs.go b/pkg/sentry/fsimpl/kernfs/kernfs.go
index ca3685800..88fcd54aa 100644
--- a/pkg/sentry/fsimpl/kernfs/kernfs.go
+++ b/pkg/sentry/fsimpl/kernfs/kernfs.go
@@ -320,6 +320,11 @@ type Inode interface {
// Precondition: rp.Done(). vfsd.Impl() must be the kernfs Dentry containing
// the inode on which Open() is being called.
Open(ctx context.Context, rp *vfs.ResolvingPath, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error)
+
+ // StatFS returns filesystem statistics for the client filesystem. This
+ // corresponds to vfs.FilesystemImpl.StatFSAt. If the client filesystem
+ // doesn't support statfs(2), this should return ENOSYS.
+ StatFS(ctx context.Context, fs *vfs.Filesystem) (linux.Statfs, error)
}
type inodeRefs interface {
diff --git a/pkg/sentry/fsimpl/kernfs/kernfs_state_autogen.go b/pkg/sentry/fsimpl/kernfs/kernfs_state_autogen.go
index 12aaf797f..cf480327f 100644
--- a/pkg/sentry/fsimpl/kernfs/kernfs_state_autogen.go
+++ b/pkg/sentry/fsimpl/kernfs/kernfs_state_autogen.go
@@ -36,6 +36,7 @@ func (x *DynamicBytesFile) StateTypeName() string {
func (x *DynamicBytesFile) StateFields() []string {
return []string{
"InodeAttrs",
+ "InodeNoStatFS",
"InodeNoopRefCount",
"InodeNotDirectory",
"InodeNotSymlink",
@@ -49,22 +50,24 @@ func (x *DynamicBytesFile) beforeSave() {}
func (x *DynamicBytesFile) StateSave(m state.Sink) {
x.beforeSave()
m.Save(0, &x.InodeAttrs)
- m.Save(1, &x.InodeNoopRefCount)
- m.Save(2, &x.InodeNotDirectory)
- m.Save(3, &x.InodeNotSymlink)
- m.Save(4, &x.locks)
- m.Save(5, &x.data)
+ m.Save(1, &x.InodeNoStatFS)
+ m.Save(2, &x.InodeNoopRefCount)
+ m.Save(3, &x.InodeNotDirectory)
+ m.Save(4, &x.InodeNotSymlink)
+ m.Save(5, &x.locks)
+ m.Save(6, &x.data)
}
func (x *DynamicBytesFile) afterLoad() {}
func (x *DynamicBytesFile) StateLoad(m state.Source) {
m.Load(0, &x.InodeAttrs)
- m.Load(1, &x.InodeNoopRefCount)
- m.Load(2, &x.InodeNotDirectory)
- m.Load(3, &x.InodeNotSymlink)
- m.Load(4, &x.locks)
- m.Load(5, &x.data)
+ m.Load(1, &x.InodeNoStatFS)
+ m.Load(2, &x.InodeNoopRefCount)
+ m.Load(3, &x.InodeNotDirectory)
+ m.Load(4, &x.InodeNotSymlink)
+ m.Load(5, &x.locks)
+ m.Load(6, &x.data)
}
func (x *DynamicBytesFD) StateTypeName() string {
@@ -108,12 +111,13 @@ func (x *StaticDirectory) StateTypeName() string {
func (x *StaticDirectory) StateFields() []string {
return []string{
- "StaticDirectoryRefs",
- "InodeNotSymlink",
- "InodeDirectoryNoNewChildren",
"InodeAttrs",
+ "InodeDirectoryNoNewChildren",
"InodeNoDynamicLookup",
+ "InodeNoStatFS",
+ "InodeNotSymlink",
"OrderedChildren",
+ "StaticDirectoryRefs",
"locks",
"fdOpts",
}
@@ -123,27 +127,29 @@ func (x *StaticDirectory) beforeSave() {}
func (x *StaticDirectory) StateSave(m state.Sink) {
x.beforeSave()
- m.Save(0, &x.StaticDirectoryRefs)
- m.Save(1, &x.InodeNotSymlink)
- m.Save(2, &x.InodeDirectoryNoNewChildren)
- m.Save(3, &x.InodeAttrs)
- m.Save(4, &x.InodeNoDynamicLookup)
+ m.Save(0, &x.InodeAttrs)
+ m.Save(1, &x.InodeDirectoryNoNewChildren)
+ m.Save(2, &x.InodeNoDynamicLookup)
+ m.Save(3, &x.InodeNoStatFS)
+ m.Save(4, &x.InodeNotSymlink)
m.Save(5, &x.OrderedChildren)
- m.Save(6, &x.locks)
- m.Save(7, &x.fdOpts)
+ m.Save(6, &x.StaticDirectoryRefs)
+ m.Save(7, &x.locks)
+ m.Save(8, &x.fdOpts)
}
func (x *StaticDirectory) afterLoad() {}
func (x *StaticDirectory) StateLoad(m state.Source) {
- m.Load(0, &x.StaticDirectoryRefs)
- m.Load(1, &x.InodeNotSymlink)
- m.Load(2, &x.InodeDirectoryNoNewChildren)
- m.Load(3, &x.InodeAttrs)
- m.Load(4, &x.InodeNoDynamicLookup)
+ m.Load(0, &x.InodeAttrs)
+ m.Load(1, &x.InodeDirectoryNoNewChildren)
+ m.Load(2, &x.InodeNoDynamicLookup)
+ m.Load(3, &x.InodeNoStatFS)
+ m.Load(4, &x.InodeNotSymlink)
m.Load(5, &x.OrderedChildren)
- m.Load(6, &x.locks)
- m.Load(7, &x.fdOpts)
+ m.Load(6, &x.StaticDirectoryRefs)
+ m.Load(7, &x.locks)
+ m.Load(8, &x.fdOpts)
}
func (x *slotList) StateTypeName() string {
diff --git a/pkg/sentry/fsimpl/kernfs/static_directory_refs.go b/pkg/sentry/fsimpl/kernfs/static_directory_refs.go
index 80513f6aa..478b04bdd 100644
--- a/pkg/sentry/fsimpl/kernfs/static_directory_refs.go
+++ b/pkg/sentry/fsimpl/kernfs/static_directory_refs.go
@@ -2,11 +2,11 @@ package kernfs
import (
"fmt"
- refs_vfs1 "gvisor.dev/gvisor/pkg/refs"
"runtime"
"sync/atomic"
"gvisor.dev/gvisor/pkg/log"
+ refs_vfs1 "gvisor.dev/gvisor/pkg/refs"
)
// ownerType is used to customize logging. Note that we use a pointer to T so
diff --git a/pkg/sentry/fsimpl/kernfs/symlink.go b/pkg/sentry/fsimpl/kernfs/symlink.go
index 2ab3f53fd..64731a3e4 100644
--- a/pkg/sentry/fsimpl/kernfs/symlink.go
+++ b/pkg/sentry/fsimpl/kernfs/symlink.go
@@ -28,6 +28,7 @@ type StaticSymlink struct {
InodeAttrs
InodeNoopRefCount
InodeSymlink
+ InodeNoStatFS
target string
}