summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fs/fsutil/inode_cached_test.go
diff options
context:
space:
mode:
authorFabricio Voznika <fvoznika@google.com>2019-02-01 17:50:32 -0800
committerShentubot <shentubot@google.com>2019-02-01 17:51:48 -0800
commit2d20b121d710fda3ad3382b66cd6c936e20a1119 (patch)
tree04f51106fe354275dc151a188550c2fd1ad1f36a /pkg/sentry/fs/fsutil/inode_cached_test.go
parent92e85623a0cd7b2043a79b757e1874a67796dea9 (diff)
CachingInodeOperations was over-dirtying cached attributes
Dirty should be set only when the attribute is changed in the cache only. Instances where the change was also sent to the backing file doesn't need to dirty the attribute. Also remove size update during WriteOut as writing dirty page would naturaly grow the file if needed. RELNOTES: relnotes is needed for the parent CL. PiperOrigin-RevId: 232068978 Change-Id: I00ba54693a2c7adc06efa9e030faf8f2e8e7f188
Diffstat (limited to 'pkg/sentry/fs/fsutil/inode_cached_test.go')
-rw-r--r--pkg/sentry/fs/fsutil/inode_cached_test.go39
1 files changed, 11 insertions, 28 deletions
diff --git a/pkg/sentry/fs/fsutil/inode_cached_test.go b/pkg/sentry/fs/fsutil/inode_cached_test.go
index 9c9391511..2a8a1639c 100644
--- a/pkg/sentry/fs/fsutil/inode_cached_test.go
+++ b/pkg/sentry/fs/fsutil/inode_cached_test.go
@@ -17,7 +17,6 @@ package fsutil
import (
"bytes"
"io"
- "reflect"
"testing"
"gvisor.googlesource.com/gvisor/pkg/sentry/context"
@@ -66,9 +65,6 @@ func TestSetPermissions(t *testing.T) {
}
// Did permissions change?
- if !iops.dirtyAttr.Perms {
- t.Fatalf("got perms not dirty, want dirty")
- }
if iops.attr.Perms != perms {
t.Fatalf("got perms +%v, want +%v", iops.attr.Perms, perms)
}
@@ -85,9 +81,9 @@ func TestSetPermissions(t *testing.T) {
func TestSetTimestamps(t *testing.T) {
ctx := contexttest.Context(t)
for _, test := range []struct {
- desc string
- ts fs.TimeSpec
- wantDirty fs.AttrMask
+ desc string
+ ts fs.TimeSpec
+ wantChanged fs.AttrMask
}{
{
desc: "noop",
@@ -95,7 +91,7 @@ func TestSetTimestamps(t *testing.T) {
ATimeOmit: true,
MTimeOmit: true,
},
- wantDirty: fs.AttrMask{},
+ wantChanged: fs.AttrMask{},
},
{
desc: "access time only",
@@ -103,9 +99,8 @@ func TestSetTimestamps(t *testing.T) {
ATime: ktime.NowFromContext(ctx),
MTimeOmit: true,
},
- wantDirty: fs.AttrMask{
- AccessTime: true,
- StatusChangeTime: true,
+ wantChanged: fs.AttrMask{
+ AccessTime: true,
},
},
{
@@ -114,9 +109,8 @@ func TestSetTimestamps(t *testing.T) {
ATimeOmit: true,
MTime: ktime.NowFromContext(ctx),
},
- wantDirty: fs.AttrMask{
+ wantChanged: fs.AttrMask{
ModificationTime: true,
- StatusChangeTime: true,
},
},
{
@@ -125,10 +119,9 @@ func TestSetTimestamps(t *testing.T) {
ATime: ktime.NowFromContext(ctx),
MTime: ktime.NowFromContext(ctx),
},
- wantDirty: fs.AttrMask{
+ wantChanged: fs.AttrMask{
AccessTime: true,
ModificationTime: true,
- StatusChangeTime: true,
},
},
{
@@ -137,10 +130,9 @@ func TestSetTimestamps(t *testing.T) {
ATimeSetSystemTime: true,
MTimeSetSystemTime: true,
},
- wantDirty: fs.AttrMask{
+ wantChanged: fs.AttrMask{
AccessTime: true,
ModificationTime: true,
- StatusChangeTime: true,
},
},
} {
@@ -159,10 +151,7 @@ func TestSetTimestamps(t *testing.T) {
if err := iops.SetTimestamps(ctx, nil, test.ts); err != nil {
t.Fatalf("SetTimestamps got error %v, want nil", err)
}
- if !reflect.DeepEqual(iops.dirtyAttr, test.wantDirty) {
- t.Fatalf("dirty got %+v, want %+v", iops.dirtyAttr, test.wantDirty)
- }
- if iops.dirtyAttr.AccessTime {
+ if test.wantChanged.AccessTime {
if !iops.attr.AccessTime.After(uattr.AccessTime) {
t.Fatalf("diritied access time did not advance, want %v > %v", iops.attr.AccessTime, uattr.AccessTime)
}
@@ -173,7 +162,7 @@ func TestSetTimestamps(t *testing.T) {
t.Fatalf("dirtied status change time did not advance")
}
}
- if iops.dirtyAttr.ModificationTime {
+ if test.wantChanged.ModificationTime {
if !iops.attr.ModificationTime.After(uattr.ModificationTime) {
t.Fatalf("diritied modification time did not advance")
}
@@ -200,16 +189,10 @@ func TestTruncate(t *testing.T) {
if err := iops.Truncate(ctx, nil, uattr.Size); err != nil {
t.Fatalf("Truncate got error %v, want nil", err)
}
- if iops.dirtyAttr.Size {
- t.Fatalf("Truncate caused size to be dirtied")
- }
var size int64 = 4096
if err := iops.Truncate(ctx, nil, size); err != nil {
t.Fatalf("Truncate got error %v, want nil", err)
}
- if !iops.dirtyAttr.Size {
- t.Fatalf("Truncate caused size to not be dirtied")
- }
if iops.attr.Size != size {
t.Fatalf("Truncate got %d, want %d", iops.attr.Size, size)
}