2015-03-17 04:44:12 +03:00
|
|
|
// Copyright 2015 Google Inc. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package cachingfs_test
|
|
|
|
|
|
|
|
import (
|
2015-07-29 08:41:31 +03:00
|
|
|
"bytes"
|
|
|
|
"io/ioutil"
|
2015-03-17 04:58:25 +03:00
|
|
|
"os"
|
|
|
|
"path"
|
2015-03-17 08:24:15 +03:00
|
|
|
"runtime"
|
2015-03-17 05:55:04 +03:00
|
|
|
"syscall"
|
2015-03-17 04:44:12 +03:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2015-03-25 01:31:43 +03:00
|
|
|
"github.com/jacobsa/fuse/fuseutil"
|
2015-03-20 03:14:45 +03:00
|
|
|
"github.com/jacobsa/fuse/samples"
|
|
|
|
"github.com/jacobsa/fuse/samples/cachingfs"
|
2015-03-17 08:30:03 +03:00
|
|
|
. "github.com/jacobsa/oglematchers"
|
2015-03-17 04:44:12 +03:00
|
|
|
. "github.com/jacobsa/ogletest"
|
2015-06-15 01:11:28 +03:00
|
|
|
"github.com/jacobsa/timeutil"
|
2015-03-17 04:44:12 +03:00
|
|
|
)
|
|
|
|
|
2015-03-20 03:14:45 +03:00
|
|
|
func TestCachingFS(t *testing.T) { RunTests(t) }
|
2015-03-17 04:44:12 +03:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Boilerplate
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-03-17 05:58:56 +03:00
|
|
|
type cachingFSTest struct {
|
2015-03-20 03:14:45 +03:00
|
|
|
samples.SampleTest
|
|
|
|
|
2015-03-17 05:55:04 +03:00
|
|
|
fs cachingfs.CachingFS
|
|
|
|
initialMtime time.Time
|
2015-03-17 04:44:12 +03:00
|
|
|
}
|
|
|
|
|
2015-03-17 05:58:56 +03:00
|
|
|
var _ TearDownInterface = &cachingFSTest{}
|
2015-03-17 04:44:12 +03:00
|
|
|
|
2015-03-17 05:58:56 +03:00
|
|
|
func (t *cachingFSTest) setUp(
|
2015-03-20 03:14:45 +03:00
|
|
|
ti *TestInfo,
|
2015-03-17 04:44:12 +03:00
|
|
|
lookupEntryTimeout time.Duration,
|
2015-03-20 03:14:45 +03:00
|
|
|
getattrTimeout time.Duration) {
|
2015-03-17 04:44:12 +03:00
|
|
|
var err error
|
|
|
|
|
2015-08-12 05:35:41 +03:00
|
|
|
// We assert things about whether or not mtimes are cached, but writeback
|
|
|
|
// caching causes them to always be cached. Turn it off.
|
|
|
|
t.MountConfig.DisableWritebackCaching = true
|
|
|
|
|
2015-03-17 05:55:04 +03:00
|
|
|
// Create the file system.
|
|
|
|
t.fs, err = cachingfs.NewCachingFS(lookupEntryTimeout, getattrTimeout)
|
2015-03-17 04:44:12 +03:00
|
|
|
AssertEq(nil, err)
|
|
|
|
|
2015-03-25 01:31:43 +03:00
|
|
|
t.Server = fuseutil.NewFileSystemServer(t.fs)
|
2015-03-17 04:44:12 +03:00
|
|
|
|
2015-03-20 03:14:45 +03:00
|
|
|
// Mount it.
|
|
|
|
t.SampleTest.SetUp(ti)
|
2015-03-17 05:55:04 +03:00
|
|
|
|
|
|
|
// Set up the mtime.
|
|
|
|
t.initialMtime = time.Date(2012, 8, 15, 22, 56, 0, 0, time.Local)
|
|
|
|
t.fs.SetMtime(t.initialMtime)
|
2015-03-17 04:44:12 +03:00
|
|
|
}
|
|
|
|
|
2015-03-17 05:58:56 +03:00
|
|
|
func (t *cachingFSTest) statAll() (foo, dir, bar os.FileInfo) {
|
|
|
|
var err error
|
|
|
|
|
2015-03-20 03:14:45 +03:00
|
|
|
foo, err = os.Stat(path.Join(t.Dir, "foo"))
|
2015-03-17 05:58:56 +03:00
|
|
|
AssertEq(nil, err)
|
|
|
|
|
2015-03-20 03:14:45 +03:00
|
|
|
dir, err = os.Stat(path.Join(t.Dir, "dir"))
|
2015-03-17 05:58:56 +03:00
|
|
|
AssertEq(nil, err)
|
|
|
|
|
2015-03-20 03:14:45 +03:00
|
|
|
bar, err = os.Stat(path.Join(t.Dir, "dir/bar"))
|
2015-03-17 05:58:56 +03:00
|
|
|
AssertEq(nil, err)
|
|
|
|
|
2020-01-28 12:10:08 +03:00
|
|
|
return foo, dir, bar
|
2015-03-17 05:58:56 +03:00
|
|
|
}
|
|
|
|
|
2015-03-17 06:22:44 +03:00
|
|
|
func (t *cachingFSTest) openFiles() (foo, dir, bar *os.File) {
|
|
|
|
var err error
|
|
|
|
|
2015-03-20 03:14:45 +03:00
|
|
|
foo, err = os.Open(path.Join(t.Dir, "foo"))
|
2015-03-17 06:22:44 +03:00
|
|
|
AssertEq(nil, err)
|
|
|
|
|
2015-03-20 03:14:45 +03:00
|
|
|
dir, err = os.Open(path.Join(t.Dir, "dir"))
|
2015-03-17 06:22:44 +03:00
|
|
|
AssertEq(nil, err)
|
|
|
|
|
2015-03-20 03:14:45 +03:00
|
|
|
bar, err = os.Open(path.Join(t.Dir, "dir/bar"))
|
2015-03-17 06:22:44 +03:00
|
|
|
AssertEq(nil, err)
|
|
|
|
|
2020-01-28 12:10:08 +03:00
|
|
|
return foo, dir, bar
|
2015-03-17 06:22:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *cachingFSTest) statFiles(
|
|
|
|
f, g, h *os.File) (foo, dir, bar os.FileInfo) {
|
|
|
|
var err error
|
|
|
|
|
|
|
|
foo, err = f.Stat()
|
|
|
|
AssertEq(nil, err)
|
|
|
|
|
|
|
|
dir, err = g.Stat()
|
|
|
|
AssertEq(nil, err)
|
|
|
|
|
|
|
|
bar, err = h.Stat()
|
|
|
|
AssertEq(nil, err)
|
|
|
|
|
2020-01-28 12:10:08 +03:00
|
|
|
return foo, dir, bar
|
2015-03-17 06:22:44 +03:00
|
|
|
}
|
|
|
|
|
2015-03-17 05:55:04 +03:00
|
|
|
func getInodeID(fi os.FileInfo) uint64 {
|
|
|
|
return fi.Sys().(*syscall.Stat_t).Ino
|
|
|
|
}
|
|
|
|
|
2015-03-17 04:44:12 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
2015-03-17 04:50:58 +03:00
|
|
|
// Basics
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
type BasicsTest struct {
|
2015-03-17 05:58:56 +03:00
|
|
|
cachingFSTest
|
2015-03-17 04:50:58 +03:00
|
|
|
}
|
|
|
|
|
2015-03-17 04:56:56 +03:00
|
|
|
var _ SetUpInterface = &BasicsTest{}
|
|
|
|
|
2015-03-17 04:50:58 +03:00
|
|
|
func init() { RegisterTestSuite(&BasicsTest{}) }
|
|
|
|
|
2015-03-17 04:56:56 +03:00
|
|
|
func (t *BasicsTest) SetUp(ti *TestInfo) {
|
|
|
|
const (
|
|
|
|
lookupEntryTimeout = 0
|
|
|
|
getattrTimeout = 0
|
|
|
|
)
|
|
|
|
|
2015-03-20 03:14:45 +03:00
|
|
|
t.cachingFSTest.setUp(ti, lookupEntryTimeout, getattrTimeout)
|
2015-03-17 04:56:56 +03:00
|
|
|
}
|
|
|
|
|
2015-03-17 05:38:51 +03:00
|
|
|
func (t *BasicsTest) StatNonexistent() {
|
2015-03-17 05:38:07 +03:00
|
|
|
names := []string{
|
|
|
|
"blah",
|
2015-03-17 05:38:51 +03:00
|
|
|
"bar",
|
|
|
|
"dir/blah",
|
|
|
|
"dir/dir",
|
|
|
|
"dir/foo",
|
2015-03-17 05:38:07 +03:00
|
|
|
}
|
2015-03-17 05:36:23 +03:00
|
|
|
|
2015-03-17 05:38:07 +03:00
|
|
|
for _, n := range names {
|
2015-03-20 03:14:45 +03:00
|
|
|
_, err := os.Stat(path.Join(t.Dir, n))
|
2015-03-17 04:58:25 +03:00
|
|
|
|
2015-03-17 05:38:07 +03:00
|
|
|
AssertNe(nil, err)
|
|
|
|
ExpectTrue(os.IsNotExist(err), "n: %s, err: %v", n, err)
|
|
|
|
}
|
2015-03-17 04:50:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *BasicsTest) StatFoo() {
|
2015-03-20 03:14:45 +03:00
|
|
|
fi, err := os.Stat(path.Join(t.Dir, "foo"))
|
2015-03-17 05:40:11 +03:00
|
|
|
AssertEq(nil, err)
|
|
|
|
|
|
|
|
ExpectEq("foo", fi.Name())
|
|
|
|
ExpectEq(cachingfs.FooSize, fi.Size())
|
|
|
|
ExpectEq(0777, fi.Mode())
|
2015-03-17 05:55:42 +03:00
|
|
|
ExpectThat(fi.ModTime(), timeutil.TimeEq(t.initialMtime))
|
2015-03-17 05:40:11 +03:00
|
|
|
ExpectFalse(fi.IsDir())
|
2015-03-17 05:55:04 +03:00
|
|
|
ExpectEq(t.fs.FooID(), getInodeID(fi))
|
2015-03-18 06:07:26 +03:00
|
|
|
ExpectEq(1, fi.Sys().(*syscall.Stat_t).Nlink)
|
2015-03-17 04:50:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *BasicsTest) StatDir() {
|
2015-03-20 03:14:45 +03:00
|
|
|
fi, err := os.Stat(path.Join(t.Dir, "dir"))
|
2015-03-17 05:47:02 +03:00
|
|
|
AssertEq(nil, err)
|
|
|
|
|
|
|
|
ExpectEq("dir", fi.Name())
|
|
|
|
ExpectEq(os.ModeDir|0777, fi.Mode())
|
2015-03-17 05:55:42 +03:00
|
|
|
ExpectThat(fi.ModTime(), timeutil.TimeEq(t.initialMtime))
|
2015-03-17 05:47:02 +03:00
|
|
|
ExpectTrue(fi.IsDir())
|
2015-03-17 05:55:04 +03:00
|
|
|
ExpectEq(t.fs.DirID(), getInodeID(fi))
|
2015-03-18 06:07:26 +03:00
|
|
|
ExpectEq(1, fi.Sys().(*syscall.Stat_t).Nlink)
|
2015-03-17 04:50:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *BasicsTest) StatBar() {
|
2015-03-20 03:14:45 +03:00
|
|
|
fi, err := os.Stat(path.Join(t.Dir, "dir/bar"))
|
2015-03-17 05:47:02 +03:00
|
|
|
AssertEq(nil, err)
|
|
|
|
|
|
|
|
ExpectEq("bar", fi.Name())
|
|
|
|
ExpectEq(cachingfs.BarSize, fi.Size())
|
|
|
|
ExpectEq(0777, fi.Mode())
|
2015-03-17 05:55:42 +03:00
|
|
|
ExpectThat(fi.ModTime(), timeutil.TimeEq(t.initialMtime))
|
2015-03-17 05:47:02 +03:00
|
|
|
ExpectFalse(fi.IsDir())
|
2015-03-17 05:55:04 +03:00
|
|
|
ExpectEq(t.fs.BarID(), getInodeID(fi))
|
2015-03-18 06:07:26 +03:00
|
|
|
ExpectEq(1, fi.Sys().(*syscall.Stat_t).Nlink)
|
2015-03-17 04:50:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// No caching
|
2015-03-17 04:44:12 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-03-17 04:50:58 +03:00
|
|
|
type NoCachingTest struct {
|
2015-03-17 05:58:56 +03:00
|
|
|
cachingFSTest
|
2015-03-17 04:50:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ SetUpInterface = &NoCachingTest{}
|
|
|
|
|
|
|
|
func init() { RegisterTestSuite(&NoCachingTest{}) }
|
|
|
|
|
|
|
|
func (t *NoCachingTest) SetUp(ti *TestInfo) {
|
|
|
|
const (
|
|
|
|
lookupEntryTimeout = 0
|
|
|
|
getattrTimeout = 0
|
|
|
|
)
|
|
|
|
|
2015-03-20 03:14:45 +03:00
|
|
|
t.cachingFSTest.setUp(ti, lookupEntryTimeout, getattrTimeout)
|
2015-03-17 04:50:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *NoCachingTest) StatStat() {
|
2015-03-17 05:58:56 +03:00
|
|
|
fooBefore, dirBefore, barBefore := t.statAll()
|
|
|
|
fooAfter, dirAfter, barAfter := t.statAll()
|
2015-03-17 05:55:04 +03:00
|
|
|
|
|
|
|
// Make sure everything matches.
|
2015-03-17 05:56:37 +03:00
|
|
|
ExpectThat(fooAfter.ModTime(), timeutil.TimeEq(fooBefore.ModTime()))
|
|
|
|
ExpectThat(dirAfter.ModTime(), timeutil.TimeEq(dirBefore.ModTime()))
|
|
|
|
ExpectThat(barAfter.ModTime(), timeutil.TimeEq(barBefore.ModTime()))
|
2015-03-17 05:55:04 +03:00
|
|
|
|
|
|
|
ExpectEq(getInodeID(fooBefore), getInodeID(fooAfter))
|
|
|
|
ExpectEq(getInodeID(dirBefore), getInodeID(dirAfter))
|
|
|
|
ExpectEq(getInodeID(barBefore), getInodeID(barAfter))
|
2015-03-17 04:50:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *NoCachingTest) StatRenumberStat() {
|
2015-03-17 06:01:45 +03:00
|
|
|
t.statAll()
|
2015-03-17 05:59:48 +03:00
|
|
|
t.fs.RenumberInodes()
|
|
|
|
fooAfter, dirAfter, barAfter := t.statAll()
|
|
|
|
|
2015-03-17 06:01:45 +03:00
|
|
|
// We should see the new inode IDs, because the entries should not have been
|
|
|
|
// cached.
|
|
|
|
ExpectEq(t.fs.FooID(), getInodeID(fooAfter))
|
|
|
|
ExpectEq(t.fs.DirID(), getInodeID(dirAfter))
|
|
|
|
ExpectEq(t.fs.BarID(), getInodeID(barAfter))
|
2015-03-17 04:50:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *NoCachingTest) StatMtimeStat() {
|
2015-03-17 06:01:45 +03:00
|
|
|
newMtime := t.initialMtime.Add(time.Second)
|
|
|
|
|
|
|
|
t.statAll()
|
|
|
|
t.fs.SetMtime(newMtime)
|
|
|
|
fooAfter, dirAfter, barAfter := t.statAll()
|
|
|
|
|
|
|
|
// We should see the new mtimes, because the attributes should not have been
|
|
|
|
// cached.
|
|
|
|
ExpectThat(fooAfter.ModTime(), timeutil.TimeEq(newMtime))
|
|
|
|
ExpectThat(dirAfter.ModTime(), timeutil.TimeEq(newMtime))
|
|
|
|
ExpectThat(barAfter.ModTime(), timeutil.TimeEq(newMtime))
|
2015-03-17 04:50:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *NoCachingTest) StatRenumberMtimeStat() {
|
2015-03-17 06:02:16 +03:00
|
|
|
newMtime := t.initialMtime.Add(time.Second)
|
|
|
|
|
|
|
|
t.statAll()
|
|
|
|
t.fs.RenumberInodes()
|
|
|
|
t.fs.SetMtime(newMtime)
|
|
|
|
fooAfter, dirAfter, barAfter := t.statAll()
|
|
|
|
|
|
|
|
// We should see the new inode IDs and mtimes, because nothing should have
|
|
|
|
// been cached.
|
|
|
|
ExpectEq(t.fs.FooID(), getInodeID(fooAfter))
|
|
|
|
ExpectEq(t.fs.DirID(), getInodeID(dirAfter))
|
|
|
|
ExpectEq(t.fs.BarID(), getInodeID(barAfter))
|
|
|
|
|
|
|
|
ExpectThat(fooAfter.ModTime(), timeutil.TimeEq(newMtime))
|
|
|
|
ExpectThat(dirAfter.ModTime(), timeutil.TimeEq(newMtime))
|
|
|
|
ExpectThat(barAfter.ModTime(), timeutil.TimeEq(newMtime))
|
2015-03-17 04:44:12 +03:00
|
|
|
}
|
2015-03-17 06:07:49 +03:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Entry caching
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
type EntryCachingTest struct {
|
|
|
|
cachingFSTest
|
|
|
|
lookupEntryTimeout time.Duration
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ SetUpInterface = &EntryCachingTest{}
|
|
|
|
|
|
|
|
func init() { RegisterTestSuite(&EntryCachingTest{}) }
|
|
|
|
|
|
|
|
func (t *EntryCachingTest) SetUp(ti *TestInfo) {
|
|
|
|
t.lookupEntryTimeout = 250 * time.Millisecond
|
2015-03-20 03:14:45 +03:00
|
|
|
t.SampleTest.MountConfig.EnableVnodeCaching = true
|
2015-03-17 08:21:10 +03:00
|
|
|
|
2015-03-20 03:14:45 +03:00
|
|
|
t.cachingFSTest.setUp(ti, t.lookupEntryTimeout, 0)
|
2015-03-17 06:07:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *EntryCachingTest) StatStat() {
|
|
|
|
fooBefore, dirBefore, barBefore := t.statAll()
|
|
|
|
fooAfter, dirAfter, barAfter := t.statAll()
|
|
|
|
|
|
|
|
// Make sure everything matches.
|
|
|
|
ExpectThat(fooAfter.ModTime(), timeutil.TimeEq(fooBefore.ModTime()))
|
|
|
|
ExpectThat(dirAfter.ModTime(), timeutil.TimeEq(dirBefore.ModTime()))
|
|
|
|
ExpectThat(barAfter.ModTime(), timeutil.TimeEq(barBefore.ModTime()))
|
|
|
|
|
|
|
|
ExpectEq(getInodeID(fooBefore), getInodeID(fooAfter))
|
|
|
|
ExpectEq(getInodeID(dirBefore), getInodeID(dirAfter))
|
|
|
|
ExpectEq(getInodeID(barBefore), getInodeID(barAfter))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *EntryCachingTest) StatRenumberStat() {
|
|
|
|
fooBefore, dirBefore, barBefore := t.statAll()
|
|
|
|
t.fs.RenumberInodes()
|
|
|
|
fooAfter, dirAfter, barAfter := t.statAll()
|
|
|
|
|
|
|
|
// We should still see the old inode IDs, because the inode entries should
|
|
|
|
// have been cached.
|
|
|
|
ExpectEq(getInodeID(fooBefore), getInodeID(fooAfter))
|
|
|
|
ExpectEq(getInodeID(dirBefore), getInodeID(dirAfter))
|
|
|
|
ExpectEq(getInodeID(barBefore), getInodeID(barAfter))
|
|
|
|
|
|
|
|
// But after waiting for the entry cache to expire, we should see the new
|
|
|
|
// IDs.
|
2015-03-17 08:24:15 +03:00
|
|
|
//
|
|
|
|
// Note that the cache is not guaranteed to expire on darwin. See notes on
|
|
|
|
// fuse.MountConfig.EnableVnodeCaching.
|
|
|
|
if runtime.GOOS != "darwin" {
|
|
|
|
time.Sleep(2 * t.lookupEntryTimeout)
|
|
|
|
fooAfter, dirAfter, barAfter = t.statAll()
|
|
|
|
|
|
|
|
ExpectEq(t.fs.FooID(), getInodeID(fooAfter))
|
|
|
|
ExpectEq(t.fs.DirID(), getInodeID(dirAfter))
|
|
|
|
ExpectEq(t.fs.BarID(), getInodeID(barAfter))
|
|
|
|
}
|
2015-03-17 06:07:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *EntryCachingTest) StatMtimeStat() {
|
|
|
|
newMtime := t.initialMtime.Add(time.Second)
|
|
|
|
|
|
|
|
t.statAll()
|
|
|
|
t.fs.SetMtime(newMtime)
|
|
|
|
fooAfter, dirAfter, barAfter := t.statAll()
|
|
|
|
|
|
|
|
// We should see the new mtimes, because the attributes should not have been
|
|
|
|
// cached.
|
|
|
|
ExpectThat(fooAfter.ModTime(), timeutil.TimeEq(newMtime))
|
|
|
|
ExpectThat(dirAfter.ModTime(), timeutil.TimeEq(newMtime))
|
|
|
|
ExpectThat(barAfter.ModTime(), timeutil.TimeEq(newMtime))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *EntryCachingTest) StatRenumberMtimeStat() {
|
|
|
|
newMtime := t.initialMtime.Add(time.Second)
|
|
|
|
|
|
|
|
fooBefore, dirBefore, barBefore := t.statAll()
|
|
|
|
t.fs.RenumberInodes()
|
|
|
|
t.fs.SetMtime(newMtime)
|
|
|
|
fooAfter, dirAfter, barAfter := t.statAll()
|
|
|
|
|
|
|
|
// We should still see the old inode IDs, because the inode entries should
|
|
|
|
// have been cached. But the attributes should not have been.
|
|
|
|
ExpectEq(getInodeID(fooBefore), getInodeID(fooAfter))
|
|
|
|
ExpectEq(getInodeID(dirBefore), getInodeID(dirAfter))
|
|
|
|
ExpectEq(getInodeID(barBefore), getInodeID(barAfter))
|
|
|
|
|
|
|
|
ExpectThat(fooAfter.ModTime(), timeutil.TimeEq(newMtime))
|
|
|
|
ExpectThat(dirAfter.ModTime(), timeutil.TimeEq(newMtime))
|
|
|
|
ExpectThat(barAfter.ModTime(), timeutil.TimeEq(newMtime))
|
|
|
|
|
|
|
|
// After waiting for the entry cache to expire, we should see fresh
|
|
|
|
// everything.
|
2015-03-17 08:24:15 +03:00
|
|
|
//
|
|
|
|
// Note that the cache is not guaranteed to expire on darwin. See notes on
|
|
|
|
// fuse.MountConfig.EnableVnodeCaching.
|
|
|
|
if runtime.GOOS != "darwin" {
|
|
|
|
time.Sleep(2 * t.lookupEntryTimeout)
|
|
|
|
fooAfter, dirAfter, barAfter = t.statAll()
|
|
|
|
|
|
|
|
ExpectEq(t.fs.FooID(), getInodeID(fooAfter))
|
|
|
|
ExpectEq(t.fs.DirID(), getInodeID(dirAfter))
|
|
|
|
ExpectEq(t.fs.BarID(), getInodeID(barAfter))
|
|
|
|
|
|
|
|
ExpectThat(fooAfter.ModTime(), timeutil.TimeEq(newMtime))
|
|
|
|
ExpectThat(dirAfter.ModTime(), timeutil.TimeEq(newMtime))
|
|
|
|
ExpectThat(barAfter.ModTime(), timeutil.TimeEq(newMtime))
|
|
|
|
}
|
2015-03-17 06:07:49 +03:00
|
|
|
}
|
2015-03-17 06:11:27 +03:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Attribute caching
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
type AttributeCachingTest struct {
|
|
|
|
cachingFSTest
|
|
|
|
getattrTimeout time.Duration
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ SetUpInterface = &AttributeCachingTest{}
|
|
|
|
|
|
|
|
func init() { RegisterTestSuite(&AttributeCachingTest{}) }
|
|
|
|
|
|
|
|
func (t *AttributeCachingTest) SetUp(ti *TestInfo) {
|
|
|
|
t.getattrTimeout = 250 * time.Millisecond
|
2015-03-20 03:14:45 +03:00
|
|
|
t.cachingFSTest.setUp(ti, 0, t.getattrTimeout)
|
2015-03-17 06:11:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *AttributeCachingTest) StatStat() {
|
|
|
|
fooBefore, dirBefore, barBefore := t.statAll()
|
|
|
|
fooAfter, dirAfter, barAfter := t.statAll()
|
|
|
|
|
|
|
|
// Make sure everything matches.
|
|
|
|
ExpectThat(fooAfter.ModTime(), timeutil.TimeEq(fooBefore.ModTime()))
|
|
|
|
ExpectThat(dirAfter.ModTime(), timeutil.TimeEq(dirBefore.ModTime()))
|
|
|
|
ExpectThat(barAfter.ModTime(), timeutil.TimeEq(barBefore.ModTime()))
|
|
|
|
|
|
|
|
ExpectEq(getInodeID(fooBefore), getInodeID(fooAfter))
|
|
|
|
ExpectEq(getInodeID(dirBefore), getInodeID(dirAfter))
|
|
|
|
ExpectEq(getInodeID(barBefore), getInodeID(barAfter))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *AttributeCachingTest) StatRenumberStat() {
|
|
|
|
t.statAll()
|
|
|
|
t.fs.RenumberInodes()
|
|
|
|
fooAfter, dirAfter, barAfter := t.statAll()
|
|
|
|
|
|
|
|
// We should see the new inode IDs, because the entries should not have been
|
|
|
|
// cached.
|
|
|
|
ExpectEq(t.fs.FooID(), getInodeID(fooAfter))
|
|
|
|
ExpectEq(t.fs.DirID(), getInodeID(dirAfter))
|
|
|
|
ExpectEq(t.fs.BarID(), getInodeID(barAfter))
|
|
|
|
}
|
|
|
|
|
2015-03-17 08:14:37 +03:00
|
|
|
func (t *AttributeCachingTest) StatMtimeStat_ViaPath() {
|
2015-03-17 06:11:27 +03:00
|
|
|
newMtime := t.initialMtime.Add(time.Second)
|
|
|
|
|
2015-03-17 06:16:10 +03:00
|
|
|
t.statAll()
|
2015-03-17 06:11:27 +03:00
|
|
|
t.fs.SetMtime(newMtime)
|
|
|
|
fooAfter, dirAfter, barAfter := t.statAll()
|
|
|
|
|
2015-03-17 08:14:37 +03:00
|
|
|
// Since we don't have entry caching enabled, the call above had to look up
|
2015-03-17 08:30:03 +03:00
|
|
|
// the entry again. With the lookup we returned new attributes, so it's
|
|
|
|
// possible that the mtime will be fresh. On Linux it appears to be, and on
|
|
|
|
// OS X it appears to not be.
|
|
|
|
m := AnyOf(timeutil.TimeEq(newMtime), timeutil.TimeEq(t.initialMtime))
|
|
|
|
ExpectThat(fooAfter.ModTime(), m)
|
|
|
|
ExpectThat(dirAfter.ModTime(), m)
|
|
|
|
ExpectThat(barAfter.ModTime(), m)
|
2015-03-17 06:11:27 +03:00
|
|
|
}
|
|
|
|
|
2015-03-17 06:27:23 +03:00
|
|
|
func (t *AttributeCachingTest) StatMtimeStat_ViaFileDescriptor() {
|
|
|
|
newMtime := t.initialMtime.Add(time.Second)
|
|
|
|
|
|
|
|
// Open everything, fixing a particular inode number for each.
|
|
|
|
foo, dir, bar := t.openFiles()
|
|
|
|
defer func() {
|
|
|
|
foo.Close()
|
|
|
|
dir.Close()
|
|
|
|
bar.Close()
|
|
|
|
}()
|
|
|
|
|
|
|
|
fooBefore, dirBefore, barBefore := t.statFiles(foo, dir, bar)
|
|
|
|
t.fs.SetMtime(newMtime)
|
|
|
|
fooAfter, dirAfter, barAfter := t.statFiles(foo, dir, bar)
|
|
|
|
|
|
|
|
// We should still see the old cached mtime.
|
|
|
|
ExpectThat(fooAfter.ModTime(), timeutil.TimeEq(fooBefore.ModTime()))
|
|
|
|
ExpectThat(dirAfter.ModTime(), timeutil.TimeEq(dirBefore.ModTime()))
|
|
|
|
ExpectThat(barAfter.ModTime(), timeutil.TimeEq(barBefore.ModTime()))
|
|
|
|
|
|
|
|
// After waiting for the attribute cache to expire, we should see the fresh
|
|
|
|
// mtime.
|
|
|
|
time.Sleep(2 * t.getattrTimeout)
|
|
|
|
fooAfter, dirAfter, barAfter = t.statFiles(foo, dir, bar)
|
|
|
|
|
|
|
|
ExpectThat(fooAfter.ModTime(), timeutil.TimeEq(newMtime))
|
|
|
|
ExpectThat(dirAfter.ModTime(), timeutil.TimeEq(newMtime))
|
|
|
|
ExpectThat(barAfter.ModTime(), timeutil.TimeEq(newMtime))
|
|
|
|
}
|
|
|
|
|
2015-03-17 08:14:37 +03:00
|
|
|
func (t *AttributeCachingTest) StatRenumberMtimeStat_ViaPath() {
|
2015-03-17 06:11:27 +03:00
|
|
|
newMtime := t.initialMtime.Add(time.Second)
|
|
|
|
|
|
|
|
t.statAll()
|
|
|
|
t.fs.RenumberInodes()
|
|
|
|
t.fs.SetMtime(newMtime)
|
|
|
|
fooAfter, dirAfter, barAfter := t.statAll()
|
|
|
|
|
|
|
|
// We should see new everything, because this is the first time the new
|
|
|
|
// inodes have been encountered. Entries for the old ones should not have
|
2015-03-17 08:14:37 +03:00
|
|
|
// been cached, because we have entry caching disabled.
|
2015-03-17 06:11:27 +03:00
|
|
|
ExpectEq(t.fs.FooID(), getInodeID(fooAfter))
|
|
|
|
ExpectEq(t.fs.DirID(), getInodeID(dirAfter))
|
|
|
|
ExpectEq(t.fs.BarID(), getInodeID(barAfter))
|
|
|
|
|
|
|
|
ExpectThat(fooAfter.ModTime(), timeutil.TimeEq(newMtime))
|
|
|
|
ExpectThat(dirAfter.ModTime(), timeutil.TimeEq(newMtime))
|
|
|
|
ExpectThat(barAfter.ModTime(), timeutil.TimeEq(newMtime))
|
|
|
|
}
|
2015-03-17 06:22:44 +03:00
|
|
|
|
|
|
|
func (t *AttributeCachingTest) StatRenumberMtimeStat_ViaFileDescriptor() {
|
|
|
|
newMtime := t.initialMtime.Add(time.Second)
|
|
|
|
|
|
|
|
// Open everything, fixing a particular inode number for each.
|
|
|
|
foo, dir, bar := t.openFiles()
|
2015-03-17 06:24:13 +03:00
|
|
|
defer func() {
|
|
|
|
foo.Close()
|
|
|
|
dir.Close()
|
|
|
|
bar.Close()
|
|
|
|
}()
|
2015-03-17 06:22:44 +03:00
|
|
|
|
|
|
|
fooBefore, dirBefore, barBefore := t.statFiles(foo, dir, bar)
|
|
|
|
t.fs.RenumberInodes()
|
|
|
|
t.fs.SetMtime(newMtime)
|
|
|
|
fooAfter, dirAfter, barAfter := t.statFiles(foo, dir, bar)
|
|
|
|
|
|
|
|
// We should still see the old cached mtime with the old inode ID.
|
|
|
|
ExpectEq(getInodeID(fooBefore), getInodeID(fooAfter))
|
|
|
|
ExpectEq(getInodeID(dirBefore), getInodeID(dirAfter))
|
|
|
|
ExpectEq(getInodeID(barBefore), getInodeID(barAfter))
|
|
|
|
|
|
|
|
ExpectThat(fooAfter.ModTime(), timeutil.TimeEq(fooBefore.ModTime()))
|
|
|
|
ExpectThat(dirAfter.ModTime(), timeutil.TimeEq(dirBefore.ModTime()))
|
|
|
|
ExpectThat(barAfter.ModTime(), timeutil.TimeEq(barBefore.ModTime()))
|
|
|
|
|
|
|
|
// After waiting for the attribute cache to expire, we should see the fresh
|
|
|
|
// mtime, still with the old inode ID.
|
|
|
|
time.Sleep(2 * t.getattrTimeout)
|
2015-03-17 06:24:55 +03:00
|
|
|
fooAfter, dirAfter, barAfter = t.statFiles(foo, dir, bar)
|
2015-03-17 06:22:44 +03:00
|
|
|
|
|
|
|
ExpectEq(getInodeID(fooBefore), getInodeID(fooAfter))
|
|
|
|
ExpectEq(getInodeID(dirBefore), getInodeID(dirAfter))
|
|
|
|
ExpectEq(getInodeID(barBefore), getInodeID(barAfter))
|
|
|
|
|
|
|
|
ExpectThat(fooAfter.ModTime(), timeutil.TimeEq(newMtime))
|
|
|
|
ExpectThat(dirAfter.ModTime(), timeutil.TimeEq(newMtime))
|
|
|
|
ExpectThat(barAfter.ModTime(), timeutil.TimeEq(newMtime))
|
|
|
|
}
|
2015-07-29 08:37:55 +03:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Page cache
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
type PageCacheTest struct {
|
|
|
|
cachingFSTest
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ SetUpInterface = &PageCacheTest{}
|
|
|
|
|
|
|
|
func init() { RegisterTestSuite(&PageCacheTest{}) }
|
|
|
|
|
|
|
|
func (t *PageCacheTest) SetUp(ti *TestInfo) {
|
|
|
|
const (
|
|
|
|
lookupEntryTimeout = 0
|
|
|
|
getattrTimeout = 0
|
|
|
|
)
|
|
|
|
|
|
|
|
t.cachingFSTest.setUp(ti, lookupEntryTimeout, getattrTimeout)
|
|
|
|
}
|
|
|
|
|
2015-07-29 08:41:31 +03:00
|
|
|
func (t *PageCacheTest) SingleFileHandle_NoKeepCache() {
|
|
|
|
t.fs.SetKeepCache(false)
|
|
|
|
|
|
|
|
// Open the file.
|
|
|
|
f, err := os.Open(path.Join(t.Dir, "foo"))
|
|
|
|
AssertEq(nil, err)
|
|
|
|
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
// Read its contents once.
|
|
|
|
f.Seek(0, 0)
|
|
|
|
AssertEq(nil, err)
|
|
|
|
|
|
|
|
c1, err := ioutil.ReadAll(f)
|
|
|
|
AssertEq(nil, err)
|
|
|
|
AssertEq(cachingfs.FooSize, len(c1))
|
|
|
|
|
|
|
|
// And again.
|
|
|
|
f.Seek(0, 0)
|
|
|
|
AssertEq(nil, err)
|
|
|
|
|
|
|
|
c2, err := ioutil.ReadAll(f)
|
|
|
|
AssertEq(nil, err)
|
|
|
|
AssertEq(cachingfs.FooSize, len(c2))
|
|
|
|
|
|
|
|
// We should have seen the same contents each time.
|
|
|
|
ExpectTrue(bytes.Equal(c1, c2))
|
2015-07-29 08:37:55 +03:00
|
|
|
}
|
|
|
|
|
2015-07-29 08:41:31 +03:00
|
|
|
func (t *PageCacheTest) SingleFileHandle_KeepCache() {
|
2015-07-29 08:43:47 +03:00
|
|
|
t.fs.SetKeepCache(true)
|
|
|
|
|
|
|
|
// Open the file.
|
|
|
|
f, err := os.Open(path.Join(t.Dir, "foo"))
|
|
|
|
AssertEq(nil, err)
|
|
|
|
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
// Read its contents once.
|
|
|
|
f.Seek(0, 0)
|
|
|
|
AssertEq(nil, err)
|
|
|
|
|
|
|
|
c1, err := ioutil.ReadAll(f)
|
|
|
|
AssertEq(nil, err)
|
|
|
|
AssertEq(cachingfs.FooSize, len(c1))
|
|
|
|
|
|
|
|
// And again.
|
|
|
|
f.Seek(0, 0)
|
|
|
|
AssertEq(nil, err)
|
|
|
|
|
|
|
|
c2, err := ioutil.ReadAll(f)
|
|
|
|
AssertEq(nil, err)
|
|
|
|
AssertEq(cachingfs.FooSize, len(c2))
|
|
|
|
|
|
|
|
// We should have seen the same contents each time.
|
|
|
|
ExpectTrue(bytes.Equal(c1, c2))
|
2015-07-29 08:37:55 +03:00
|
|
|
}
|
|
|
|
|
2015-07-29 08:41:31 +03:00
|
|
|
func (t *PageCacheTest) TwoFileHandles_NoKeepCache() {
|
2015-07-29 08:46:13 +03:00
|
|
|
t.fs.SetKeepCache(false)
|
|
|
|
|
2015-07-29 09:24:47 +03:00
|
|
|
// SetKeepCache(false) doesn't work on OS X. See the notes on
|
|
|
|
// OpenFileOp.KeepPageCache.
|
|
|
|
if runtime.GOOS == "darwin" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-07-29 08:46:13 +03:00
|
|
|
// Open the file.
|
|
|
|
f1, err := os.Open(path.Join(t.Dir, "foo"))
|
|
|
|
AssertEq(nil, err)
|
|
|
|
|
|
|
|
defer f1.Close()
|
|
|
|
|
|
|
|
// Read its contents once.
|
|
|
|
f1.Seek(0, 0)
|
|
|
|
AssertEq(nil, err)
|
|
|
|
|
|
|
|
c1, err := ioutil.ReadAll(f1)
|
|
|
|
AssertEq(nil, err)
|
|
|
|
AssertEq(cachingfs.FooSize, len(c1))
|
|
|
|
|
|
|
|
// Open a second handle.
|
|
|
|
f2, err := os.Open(path.Join(t.Dir, "foo"))
|
|
|
|
AssertEq(nil, err)
|
|
|
|
|
|
|
|
defer f2.Close()
|
|
|
|
|
|
|
|
// We should see different contents if we read from that handle, due to the
|
|
|
|
// cache being invalidated at the time of opening.
|
|
|
|
f2.Seek(0, 0)
|
|
|
|
AssertEq(nil, err)
|
|
|
|
|
|
|
|
c2, err := ioutil.ReadAll(f2)
|
|
|
|
AssertEq(nil, err)
|
|
|
|
AssertEq(cachingfs.FooSize, len(c2))
|
|
|
|
|
|
|
|
ExpectFalse(bytes.Equal(c1, c2))
|
|
|
|
|
|
|
|
// Another read from the second handle should give the same result as the
|
|
|
|
// first one from that handle.
|
|
|
|
f2.Seek(0, 0)
|
|
|
|
AssertEq(nil, err)
|
|
|
|
|
|
|
|
c3, err := ioutil.ReadAll(f2)
|
|
|
|
AssertEq(nil, err)
|
|
|
|
AssertEq(cachingfs.FooSize, len(c3))
|
|
|
|
|
|
|
|
ExpectTrue(bytes.Equal(c2, c3))
|
|
|
|
|
|
|
|
// And another read from the first handle should give the same result yet
|
|
|
|
// again.
|
|
|
|
f1.Seek(0, 0)
|
|
|
|
AssertEq(nil, err)
|
|
|
|
|
|
|
|
c4, err := ioutil.ReadAll(f1)
|
|
|
|
AssertEq(nil, err)
|
|
|
|
AssertEq(cachingfs.FooSize, len(c4))
|
|
|
|
|
|
|
|
ExpectTrue(bytes.Equal(c2, c4))
|
2015-07-29 08:37:55 +03:00
|
|
|
}
|
|
|
|
|
2015-07-29 08:41:31 +03:00
|
|
|
func (t *PageCacheTest) TwoFileHandles_KeepCache() {
|
2015-07-29 08:47:18 +03:00
|
|
|
t.fs.SetKeepCache(true)
|
|
|
|
|
|
|
|
// Open the file.
|
|
|
|
f1, err := os.Open(path.Join(t.Dir, "foo"))
|
|
|
|
AssertEq(nil, err)
|
|
|
|
|
|
|
|
defer f1.Close()
|
|
|
|
|
|
|
|
// Read its contents once.
|
|
|
|
f1.Seek(0, 0)
|
|
|
|
AssertEq(nil, err)
|
|
|
|
|
|
|
|
c1, err := ioutil.ReadAll(f1)
|
|
|
|
AssertEq(nil, err)
|
|
|
|
AssertEq(cachingfs.FooSize, len(c1))
|
|
|
|
|
|
|
|
// Open a second handle.
|
|
|
|
f2, err := os.Open(path.Join(t.Dir, "foo"))
|
|
|
|
AssertEq(nil, err)
|
|
|
|
|
|
|
|
defer f2.Close()
|
|
|
|
|
|
|
|
// We should see the same contents when we read via the second handle.
|
|
|
|
f2.Seek(0, 0)
|
|
|
|
AssertEq(nil, err)
|
|
|
|
|
|
|
|
c2, err := ioutil.ReadAll(f2)
|
|
|
|
AssertEq(nil, err)
|
|
|
|
AssertEq(cachingfs.FooSize, len(c2))
|
|
|
|
|
|
|
|
ExpectTrue(bytes.Equal(c1, c2))
|
|
|
|
|
|
|
|
// Ditto if we read again from the first.
|
|
|
|
f1.Seek(0, 0)
|
|
|
|
AssertEq(nil, err)
|
|
|
|
|
|
|
|
c3, err := ioutil.ReadAll(f1)
|
|
|
|
AssertEq(nil, err)
|
|
|
|
AssertEq(cachingfs.FooSize, len(c3))
|
|
|
|
|
|
|
|
ExpectTrue(bytes.Equal(c1, c3))
|
2015-07-29 08:37:55 +03:00
|
|
|
}
|