summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fs
diff options
context:
space:
mode:
authorNicolas Lacasse <nlacasse@google.com>2018-07-19 14:56:42 -0700
committerShentubot <shentubot@google.com>2018-07-19 14:57:52 -0700
commitbe431d0934b8d33dcb1909527e0f9ed7eb504b6f (patch)
tree4071eb98e3ecdfa6abd77552c7e5426469027cd8 /pkg/sentry/fs
parentea371031968095209793ea39007cfdf5a9d66d10 (diff)
fs: Pass context to Revalidate() function.
The current revalidation logic is very simple and does not do much introspection of the dirent being revalidated (other than looking at the type of file). Fancier revalidation logic is coming soon, and we need to be able to look at the cached and uncached attributes of a given dirent, and we need a context to perform some of these operations. PiperOrigin-RevId: 205307351 Change-Id: If17ea1c631d8f9489c0e05a263e23d7a8a3bf159
Diffstat (limited to 'pkg/sentry/fs')
-rw-r--r--pkg/sentry/fs/dirent.go2
-rw-r--r--pkg/sentry/fs/gofer/session.go2
-rw-r--r--pkg/sentry/fs/mock.go2
-rw-r--r--pkg/sentry/fs/mount.go14
-rw-r--r--pkg/sentry/fs/mount_overlay.go4
-rw-r--r--pkg/sentry/fs/tty/fs.go2
6 files changed, 14 insertions, 12 deletions
diff --git a/pkg/sentry/fs/dirent.go b/pkg/sentry/fs/dirent.go
index 5eaa2189a..f9bf2fba6 100644
--- a/pkg/sentry/fs/dirent.go
+++ b/pkg/sentry/fs/dirent.go
@@ -488,7 +488,7 @@ func (d *Dirent) walk(ctx context.Context, root *Dirent, name string, walkMayUnl
//
// We never allow the file system to revalidate mounts, that could cause them
// to unexpectedly drop out before umount.
- if cd.mounted || !cd.Inode.MountSource.Revalidate(cd) {
+ if cd.mounted || !cd.Inode.MountSource.Revalidate(ctx, cd) {
// Good to go. This is the fast-path.
return cd, nil
}
diff --git a/pkg/sentry/fs/gofer/session.go b/pkg/sentry/fs/gofer/session.go
index 21dc5e08d..b6841526a 100644
--- a/pkg/sentry/fs/gofer/session.go
+++ b/pkg/sentry/fs/gofer/session.go
@@ -121,7 +121,7 @@ func (s *session) Destroy() {
}
// Revalidate returns true if the cache policy is does not allow for VFS caching.
-func (s *session) Revalidate(*fs.Dirent) bool {
+func (s *session) Revalidate(ctx context.Context, d *fs.Dirent) bool {
return s.cachePolicy.revalidateDirent()
}
diff --git a/pkg/sentry/fs/mock.go b/pkg/sentry/fs/mock.go
index b3bfa5268..dc82a2002 100644
--- a/pkg/sentry/fs/mock.go
+++ b/pkg/sentry/fs/mock.go
@@ -68,7 +68,7 @@ func NewMockMountSource(cache *DirentCache) *MountSource {
}
// Revalidate implements fs.MountSourceOperations.Revalidate.
-func (n *MockMountSourceOps) Revalidate(*Dirent) bool {
+func (n *MockMountSourceOps) Revalidate(context.Context, *Dirent) bool {
return n.revalidate
}
diff --git a/pkg/sentry/fs/mount.go b/pkg/sentry/fs/mount.go
index 1d05a36a7..eb1897174 100644
--- a/pkg/sentry/fs/mount.go
+++ b/pkg/sentry/fs/mount.go
@@ -21,17 +21,19 @@ import (
"sync/atomic"
"gvisor.googlesource.com/gvisor/pkg/refs"
+ "gvisor.googlesource.com/gvisor/pkg/sentry/context"
)
// DirentOperations provide file systems greater control over how long a Dirent stays pinned
// in core. Implementations must not take Dirent.mu.
type DirentOperations interface {
- // Revalidate returns true if the Dirent is stale and its InodeOperations needs to be reloaded. Revalidate
- // will never be called on a Dirent that is mounted.
- Revalidate(dirent *Dirent) bool
+ // Revalidate returns true if the Dirent is stale and its
+ // InodeOperations needs to be reloaded. Revalidate will never be
+ // called on a Dirent that is mounted.
+ Revalidate(ctx context.Context, dirent *Dirent) bool
- // Keep returns true if the Dirent should be kept in memory for as long as possible
- // beyond any active references.
+ // Keep returns true if the Dirent should be kept in memory for as long
+ // as possible beyond any active references.
Keep(dirent *Dirent) bool
}
@@ -263,7 +265,7 @@ type SimpleMountSourceOperations struct {
}
// Revalidate implements MountSourceOperations.Revalidate.
-func (*SimpleMountSourceOperations) Revalidate(*Dirent) bool {
+func (*SimpleMountSourceOperations) Revalidate(context.Context, *Dirent) bool {
return false
}
diff --git a/pkg/sentry/fs/mount_overlay.go b/pkg/sentry/fs/mount_overlay.go
index 343202400..1be81e3a1 100644
--- a/pkg/sentry/fs/mount_overlay.go
+++ b/pkg/sentry/fs/mount_overlay.go
@@ -34,8 +34,8 @@ func newOverlayMountSource(upper, lower *MountSource, flags MountSourceFlags) *M
// Revalidate panics if the upper or lower MountSource require that dirent be
// revalidated. Otherwise always returns false.
-func (o *overlayMountSourceOperations) Revalidate(dirent *Dirent) bool {
- if o.upper.Revalidate(dirent) || o.lower.Revalidate(dirent) {
+func (o *overlayMountSourceOperations) Revalidate(ctx context.Context, dirent *Dirent) bool {
+ if o.upper.Revalidate(ctx, dirent) || o.lower.Revalidate(ctx, dirent) {
panic("an overlay cannot revalidate file objects")
}
return false
diff --git a/pkg/sentry/fs/tty/fs.go b/pkg/sentry/fs/tty/fs.go
index 1ef1a85e3..dbaffe95e 100644
--- a/pkg/sentry/fs/tty/fs.go
+++ b/pkg/sentry/fs/tty/fs.go
@@ -78,7 +78,7 @@ type superOperations struct{}
// Slave entries are dropped from dir when their master is closed, so an
// existing slave Dirent in the tree is not sufficient to guarantee that it
// still exists on the filesystem.
-func (superOperations) Revalidate(*fs.Dirent) bool {
+func (superOperations) Revalidate(context.Context, *fs.Dirent) bool {
return true
}