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
This commit is contained in:
Nicolas Lacasse
2018-07-19 14:57:52 -07:00
committed by Shentubot
parent ea37103196
commit be431d0934
6 changed files with 14 additions and 12 deletions
+1 -1
View File
@@ -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
}
+1 -1
View File
@@ -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()
}
+1 -1
View File
@@ -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
}
+8 -6
View File
@@ -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
}
+2 -2
View File
@@ -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
+1 -1
View File
@@ -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
}