Commit ad6d7f35 authored by Kirill Smelkov's avatar Kirill Smelkov

Merge branch 'y/nodefs-cancel' into t

* y/nodefs-cancel:
  Y nodefs: Propagate context to File methods
  fs: add a test verifying that forget drops nodes
  nodefs: Allow for several Lookup requests to be served simultaneously
  tests: fs: TestOpenDirectIO: move to /var/tmp
  Travis CI: disable output buffering using "go test -p 1"
  go.mod: upgrade to Go 1.13
  tests: fix data race in TestDeletedInodePath
  Travis CI: upgrade to Ubuntu 18.04
parents e93dea2d 79855bd6
sudo: required
# Ubuntu 18.04 "Bionic", https://docs.travis-ci.com/user/reference/bionic/
# Kernel 5.0.0-1026-gcp
dist: bionic
language: go
go_import_path: github.com/hanwen/go-fuse
......@@ -33,6 +36,6 @@ install:
# as backup, triggering 1 minute later.
script:
- set -e # fail fast
- timeout -s QUIT -k 10s 90s go test -failfast -timeout 1m -v ./fs
- timeout -s QUIT -k 10s 6m go test -failfast -timeout 5m -v ./...
- timeout -s QUIT -k 10s 90s go test -failfast -timeout 1m -p 1 -v ./fs
- timeout -s QUIT -k 10s 6m go test -failfast -timeout 5m -p 1 -v ./...
- set +e # restore
......@@ -9,6 +9,7 @@ import (
"log"
"os"
"strings"
"sync/atomic"
"syscall"
"testing"
"unsafe"
......@@ -155,7 +156,7 @@ func TestDeletedInodePath(t *testing.T) {
if err != nil {
t.Fatal(err)
}
rootNode.deleted = true
atomic.StoreInt32(&rootNode.deleted, 1)
// Our Getattr implementation `testDeletedIno.Getattr` should return
// ENFILE when everything looks ok, EILSEQ otherwise.
......@@ -169,11 +170,12 @@ func TestDeletedInodePath(t *testing.T) {
type testDeletedIno struct {
Inode
deleted bool
deleted int32
}
func (n *testDeletedIno) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*Inode, syscall.Errno) {
if n.Root().Operations().(*testDeletedIno).deleted {
ino := n.Root().Operations().(*testDeletedIno)
if atomic.LoadInt32(&ino.deleted) == 1 {
return nil, syscall.ENOENT
}
if name != "dir" {
......
// Copyright 2020 the Go-FUSE Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package fs
import (
"context"
"fmt"
"io/ioutil"
"log"
"os"
"os/user"
"path/filepath"
"syscall"
"testing"
"time"
"github.com/hanwen/go-fuse/v2/fuse"
"github.com/hanwen/go-fuse/v2/internal/testutil"
)
type allChildrenNode struct {
Inode
depth int
}
var _ = (NodeLookuper)((*allChildrenNode)(nil))
var _ = (NodeReaddirer)((*allChildrenNode)(nil))
func (n *allChildrenNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*Inode, syscall.Errno) {
if n.depth == 0 {
return nil, syscall.ENOENT
}
stable := StableAttr{
Mode: syscall.S_IFDIR,
}
if n.depth == 1 {
stable.Mode = syscall.S_IFREG
}
childFN := &allChildrenNode{
depth: n.depth - 1,
}
child := n.NewInode(ctx, childFN, stable)
return child, 0
}
func (n *allChildrenNode) Readdir(ctx context.Context) (DirStream, syscall.Errno) {
var list []fuse.DirEntry
var m uint32 = syscall.S_IFDIR
if n.depth == 1 {
m = syscall.S_IFREG
}
for i := 0; i < 100; i++ {
list = append(list, fuse.DirEntry{
Name: fmt.Sprintf("%d", i),
Mode: m,
})
}
return NewListDirStream(list), 0
}
func TestForget(t *testing.T) {
u, err := user.Current()
if err != nil {
t.Fatal(err)
}
if u.Uid != "0" {
t.Skip("must run test as root")
}
root := &allChildrenNode{
depth: 2,
}
sec := time.Second
options := &Options{
FirstAutomaticIno: 1,
EntryTimeout: &sec,
}
options.Debug = testutil.VerboseTest()
dir, err := ioutil.TempDir("", "TestForget")
if err != nil {
t.Fatal(err)
}
rawFS := NewNodeFS(root, options)
server, err := fuse.NewServer(rawFS, dir, &options.MountOptions)
if err != nil {
t.Fatal(err)
}
go server.Serve()
if err := server.WaitMount(); err != nil {
t.Fatal(err)
}
nop := func(path string, info os.FileInfo, err error) error {
return nil
}
if err := filepath.Walk(dir, nop); err != nil {
t.Fatal(err)
}
log.Println("dropping cache")
if err := ioutil.WriteFile("/proc/sys/vm/drop_caches", []byte("2"), 0644); err != nil {
}
time.Sleep(time.Second)
bridge := rawFS.(*rawBridge)
bridge.mu.Lock()
l := len(bridge.nodes)
bridge.mu.Unlock()
if l != 1 {
t.Fatalf("got %d live nodes, want 1", l)
}
}
......@@ -365,9 +365,9 @@ func TestPosix(t *testing.T) {
func TestOpenDirectIO(t *testing.T) {
// Apparently, tmpfs does not allow O_DIRECT, so try to create
// a test temp directory in the home directory.
ext4Dir := filepath.Join(os.Getenv("HOME"), ".go-fuse-test")
if err := os.MkdirAll(ext4Dir, 0755); err != nil {
// a test temp directory in /var/tmp.
ext4Dir, err := ioutil.TempDir("/var/tmp", "go-fuse.TestOpenDirectIO")
if err != nil {
t.Fatalf("MkdirAll: %v", err)
}
defer os.RemoveAll(ext4Dir)
......
......@@ -5,3 +5,5 @@ require (
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522
)
go 1.13
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment