summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fs/fsutil
diff options
context:
space:
mode:
authorMichael Pratt <mpratt@google.com>2019-05-20 13:34:06 -0700
committerShentubot <shentubot@google.com>2019-05-20 13:35:17 -0700
commit6588427451c605ee00c8b1a9b6cba06724627ccb (patch)
tree6aac9eb15f09f5bd485bd8f76787e4876aca6e55 /pkg/sentry/fs/fsutil
parent4a842836e560322bb3944b59ff43b9d60cc0f867 (diff)
Fix incorrect tmpfs timestamp updates
* Creation of files, directories (and other fs objects) in a directory should always update ctime. * Same for removal. * atime should not be updated on lookup, only readdir. I've also renamed some misleading functions that update mtime and ctime. PiperOrigin-RevId: 249115063 Change-Id: I30fa275fa7db96d01aa759ed64628c18bb3a7dc7
Diffstat (limited to 'pkg/sentry/fs/fsutil')
-rw-r--r--pkg/sentry/fs/fsutil/inode.go10
-rw-r--r--pkg/sentry/fs/fsutil/inode_cached.go28
2 files changed, 24 insertions, 14 deletions
diff --git a/pkg/sentry/fs/fsutil/inode.go b/pkg/sentry/fs/fsutil/inode.go
index 5e1bfeb58..a22b6ce9c 100644
--- a/pkg/sentry/fs/fsutil/inode.go
+++ b/pkg/sentry/fs/fsutil/inode.go
@@ -192,6 +192,16 @@ func (i *InodeSimpleAttributes) NotifyStatusChange(ctx context.Context) {
i.mu.Unlock()
}
+// NotifyModificationAndStatusChange updates the modification and status change
+// times.
+func (i *InodeSimpleAttributes) NotifyModificationAndStatusChange(ctx context.Context) {
+ i.mu.Lock()
+ now := ktime.NowFromContext(ctx)
+ i.unstable.ModificationTime = now
+ i.unstable.StatusChangeTime = now
+ i.mu.Unlock()
+}
+
// InodeSimpleExtendedAttributes implements
// fs.InodeOperations.{Get,Set,List}xattr.
//
diff --git a/pkg/sentry/fs/fsutil/inode_cached.go b/pkg/sentry/fs/fsutil/inode_cached.go
index bc0b8c744..7bee2eb5f 100644
--- a/pkg/sentry/fs/fsutil/inode_cached.go
+++ b/pkg/sentry/fs/fsutil/inode_cached.go
@@ -299,7 +299,7 @@ func (c *CachingInodeOperations) Truncate(ctx context.Context, inode *fs.Inode,
}
oldSize := c.attr.Size
c.attr.Size = size
- c.touchModificationTimeLocked(now)
+ c.touchModificationAndStatusChangeTimeLocked(now)
// We drop c.dataMu here so that we can lock c.mapsMu and invalidate
// mappings below. This allows concurrent calls to Read/Translate/etc.
@@ -360,7 +360,7 @@ func (c *CachingInodeOperations) Allocate(ctx context.Context, offset, length in
}
c.attr.Size = newSize
- c.touchModificationTimeLocked(now)
+ c.touchModificationAndStatusChangeTimeLocked(now)
return nil
}
@@ -394,19 +394,19 @@ func (c *CachingInodeOperations) WriteOut(ctx context.Context, inode *fs.Inode)
return c.backingFile.Sync(ctx)
}
-// IncLinks increases the link count and updates cached access time.
+// IncLinks increases the link count and updates cached modification time.
func (c *CachingInodeOperations) IncLinks(ctx context.Context) {
c.attrMu.Lock()
c.attr.Links++
- c.touchModificationTimeLocked(ktime.NowFromContext(ctx))
+ c.touchModificationAndStatusChangeTimeLocked(ktime.NowFromContext(ctx))
c.attrMu.Unlock()
}
-// DecLinks decreases the link count and updates cached access time.
+// DecLinks decreases the link count and updates cached modification time.
func (c *CachingInodeOperations) DecLinks(ctx context.Context) {
c.attrMu.Lock()
c.attr.Links--
- c.touchModificationTimeLocked(ktime.NowFromContext(ctx))
+ c.touchModificationAndStatusChangeTimeLocked(ktime.NowFromContext(ctx))
c.attrMu.Unlock()
}
@@ -432,19 +432,19 @@ func (c *CachingInodeOperations) touchAccessTimeLocked(now time.Time) {
c.dirtyAttr.AccessTime = true
}
-// TouchModificationTime updates the cached modification and status change time
-// in-place to the current time.
-func (c *CachingInodeOperations) TouchModificationTime(ctx context.Context) {
+// TouchModificationAndStatusChangeTime updates the cached modification and
+// status change times in-place to the current time.
+func (c *CachingInodeOperations) TouchModificationAndStatusChangeTime(ctx context.Context) {
c.attrMu.Lock()
- c.touchModificationTimeLocked(ktime.NowFromContext(ctx))
+ c.touchModificationAndStatusChangeTimeLocked(ktime.NowFromContext(ctx))
c.attrMu.Unlock()
}
-// touchModificationTimeLocked updates the cached modification and status
-// change time in-place to the current time.
+// touchModificationAndStatusChangeTimeLocked updates the cached modification
+// and status change times in-place to the current time.
//
// Preconditions: c.attrMu is locked for writing.
-func (c *CachingInodeOperations) touchModificationTimeLocked(now time.Time) {
+func (c *CachingInodeOperations) touchModificationAndStatusChangeTimeLocked(now time.Time) {
c.attr.ModificationTime = now
c.dirtyAttr.ModificationTime = true
c.attr.StatusChangeTime = now
@@ -554,7 +554,7 @@ func (c *CachingInodeOperations) Write(ctx context.Context, src usermem.IOSequen
c.attrMu.Lock()
// Compare Linux's mm/filemap.c:__generic_file_write_iter() => file_update_time().
- c.touchModificationTimeLocked(ktime.NowFromContext(ctx))
+ c.touchModificationAndStatusChangeTimeLocked(ktime.NowFromContext(ctx))
n, err := src.CopyInTo(ctx, &inodeReadWriter{ctx, c, offset})
c.attrMu.Unlock()
return n, err