Commit b8458b82 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Run Gofmt.

parent 39d680ab
// The fuse package provides APIs to implement filesystems in
// userspace, using libfuse on Linux.
package fuse
import (
"os"
)
......@@ -23,7 +24,7 @@ type FileSystem interface {
Chmod(name string, mode uint32) (code Status)
Chown(name string, uid uint32, gid uint32) (code Status)
Utimens(name string, AtimeNs uint64, MtimeNs uint64) (code Status)
Truncate(name string, offset uint64) (code Status)
Access(name string, mode uint32) (code Status)
......@@ -50,13 +51,13 @@ type FileSystem interface {
// should be updated too.
Open(name string, flags uint32) (file File, code Status)
Create(name string, flags uint32, mode uint32) (file File, code Status)
// Flush() gets called as a file opened for read/write.
Flush(name string) Status
// Directory handling
OpenDir(name string) (stream chan DirEntry, code Status)
// Symlinks.
Symlink(value string, linkName string) (code Status)
Readlink(name string) (string, Status)
......@@ -89,7 +90,6 @@ type MountOptions struct {
EntryTimeout float64
AttrTimeout float64
NegativeTimeout float64
}
// DefaultFileSystem implements a FileSystem that returns ENOSYS for every operation.
......
......@@ -15,6 +15,7 @@ type BufferPool interface {
}
type GcBufferPool struct {
}
// NewGcBufferPool is just a fallback to the standard allocation routines.
......
package fuse
import (
"os"
"syscall"
......@@ -108,4 +109,3 @@ func (me *LoopbackFile) GetAttr() (*os.FileInfo, Status) {
}
return fi, OK
}
......@@ -11,7 +11,7 @@ import (
type MutableDataFile struct {
DefaultFile
data []byte
os.FileInfo
GetAttrCalled bool
......
......@@ -194,12 +194,12 @@ func (me *MountState) handleRequest(req *request) {
if req.status.Ok() && me.Debug {
log.Println(req.InputDebug())
}
if req.status.Ok() && req.handler.Func == nil {
log.Printf("Unimplemented opcode %v", req.inHeader.opcode)
req.status = ENOSYS
}
if req.status.Ok() {
req.handler.Func(me, req)
}
......@@ -219,7 +219,7 @@ func (me *MountState) write(req *request) {
if me.Debug {
log.Println(req.OutputDebug())
}
if me.LatencyMap != nil {
req.preWriteNs = time.Nanoseconds()
}
......
......@@ -664,4 +664,3 @@ func TestRecursiveMount(t *testing.T) {
ts.Cleanup()
}
......@@ -165,4 +165,4 @@ func ioctl(fd int, cmd int, arg uintptr) (int, int) {
val := int(r0)
errno := int(e1)
return val, errno
}
}
......@@ -198,7 +198,7 @@ type FileSystemConnector struct {
type fileBridge struct {
*mountData
*inode
Flags uint32
Flags uint32
Iface interface{}
}
......@@ -215,7 +215,7 @@ func (me *FileSystemConnector) Statistics() string {
len(me.openFiles), len(me.inodeMap))
}
func (me *FileSystemConnector) unregisterFile(node *inode, handle uint64) (interface{}) {
func (me *FileSystemConnector) unregisterFile(node *inode, handle uint64) interface{} {
me.fileLock.Lock()
defer me.fileLock.Unlock()
b, ok := me.openFiles[handle]
......@@ -233,9 +233,9 @@ func (me *FileSystemConnector) registerFile(node *inode, mount *mountData, f int
b := &fileBridge{
Iface: f,
inode: node,
inode: node,
mountData: mount,
Flags: flags,
Flags: flags,
}
h := uint64(uintptr(unsafe.Pointer(b)))
_, ok := me.openFiles[h]
......@@ -248,7 +248,7 @@ func (me *FileSystemConnector) registerFile(node *inode, mount *mountData, f int
return h
}
func (me *FileSystemConnector) decodeFileHandle(h uint64) (*fileBridge) {
func (me *FileSystemConnector) decodeFileHandle(h uint64) *fileBridge {
b := (*fileBridge)(unsafe.Pointer(uintptr(h)))
return b
}
......@@ -438,7 +438,7 @@ func (me *FileSystemConnector) Mount(mountPoint string, fs FileSystem, opts *Mou
log.Println("Could not find mountpoint?", mountPoint)
return ENOENT
}
if !node.IsDir() {
return EINVAL
}
......@@ -526,7 +526,7 @@ func (me *FileSystemConnector) GetPath(nodeid uint64) (path string, mount *mount
return p, m, n
}
func (me *FileSystemConnector) getOpenFileData(nodeid uint64, fh uint64) (f File, m *mountData, p string) {
func (me *FileSystemConnector) getOpenFileData(nodeid uint64, fh uint64) (f File, m *mountData, p string) {
if fh != 0 {
var bridge *fileBridge
f, bridge = me.getFile(fh)
......
......@@ -86,7 +86,7 @@ func (me *FileSystemConnector) GetAttr(header *InHeader, input *GetAttrIn) (out
if err != OK && err != ENOSYS {
return nil, err
}
if fi != nil {
out = &AttrOut{}
CopyFileInfo(fi, &out.Attr)
......@@ -383,9 +383,9 @@ func (me *FileSystemConnector) Release(header *InHeader, input *ReleaseIn) {
func (me *FileSystemConnector) Flush(input *FlushIn) Status {
f, b := me.getFile(input.Fh)
code := f.Flush()
if code.Ok() && b.Flags & O_ANYWRITE != 0 {
if code.Ok() && b.Flags&O_ANYWRITE != 0 {
// We only signal releases to the FS if the
// open could have changed things.
var path string
......@@ -469,7 +469,7 @@ func (me *FileSystemConnector) fileDebug(fh uint64, n *inode) {
}
func (me *FileSystemConnector) Write(input *WriteIn, data []byte) (written uint32, code Status) {
f, b := me.getFile(input.Fh)
f, b := me.getFile(input.Fh)
if me.Debug {
me.fileDebug(input.Fh, b.inode)
}
......@@ -491,4 +491,3 @@ func (me *FileSystemConnector) Ioctl(header *InHeader, input *IoctlIn) (out *Ioc
}
return f.Ioctl(input)
}
......@@ -11,16 +11,16 @@ type request struct {
inputBuf []byte
// These split up inputBuf.
inHeader *InHeader // generic header
inData unsafe.Pointer // per op data
arg []byte // flat data.
filenames []string // filename arguments
inHeader *InHeader // generic header
inData unsafe.Pointer // per op data
arg []byte // flat data.
filenames []string // filename arguments
// Unstructured data, a pointer to the relevant XxxxOut struct.
outData unsafe.Pointer
status Status
flatData []byte
// Header + structured data for what we send back to the kernel.
// May be followed by flatData.
outHeaderBytes []byte
......@@ -106,7 +106,7 @@ func (me *request) parse() {
}
count := me.handler.FileNames
if count > 0 {
if count > 0 {
if count == 1 {
me.filenames = []string{string(me.arg[:len(me.arg)-1])}
} else {
......
......@@ -453,5 +453,3 @@ type NotifyInvalEntryOut struct {
NameLen uint32
Padding uint32
}
......@@ -74,30 +74,30 @@ func (me *AutoUnionFs) addAutomaticFs(roots []string) {
}
}
func (me *AutoUnionFs) createFs(name string, roots []string) (*UnionFs, fuse.Status) {
me.lock.Lock()
defer me.lock.Unlock()
used := make(map[string]string)
for workspace, v := range me.knownFileSystems {
used[v.Roots()[0]] = workspace
}
workspace, ok := used[roots[0]]
if ok {
log.Printf("Already have a union FS for directory %s in workspace %s",
roots[0], workspace)
return nil, fuse.EBUSY
}
var gofs *UnionFs
if me.knownFileSystems[name] == nil {
log.Println("Adding UnionFs for roots", roots)
gofs = NewUnionFs(roots, me.options.UnionFsOptions)
me.knownFileSystems[name] = gofs
}
return gofs, fuse.OK
func (me *AutoUnionFs) createFs(name string, roots []string) (*UnionFs, fuse.Status) {
me.lock.Lock()
defer me.lock.Unlock()
used := make(map[string]string)
for workspace, v := range me.knownFileSystems {
used[v.Roots()[0]] = workspace
}
workspace, ok := used[roots[0]]
if ok {
log.Printf("Already have a union FS for directory %s in workspace %s",
roots[0], workspace)
return nil, fuse.EBUSY
}
var gofs *UnionFs
if me.knownFileSystems[name] == nil {
log.Println("Adding UnionFs for roots", roots)
gofs = NewUnionFs(roots, me.options.UnionFsOptions)
me.knownFileSystems[name] = gofs
}
return gofs, fuse.OK
}
func (me *AutoUnionFs) rmFs(name string) (code fuse.Status) {
......@@ -124,7 +124,7 @@ func (me *AutoUnionFs) addFs(name string, roots []string) (code fuse.Status) {
log.Println("Illegal name for overlay", roots)
return fuse.EINVAL
}
gofs, code := me.createFs(name, roots)
gofs, code := me.createFs(name, roots)
if gofs != nil {
me.connector.Mount("/"+name, gofs, &me.options.MountOptions)
}
......
......@@ -59,7 +59,7 @@ func setup(t *testing.T) (workdir string, cleanup func()) {
func TestAutoFsSymlink(t *testing.T) {
wd, clean := setup(t)
defer clean()
err := os.Mkdir(wd+"/store/foo", 0755)
CheckSuccess(err)
os.Symlink(wd+"/ro", wd+"/store/foo/READONLY")
......@@ -68,25 +68,25 @@ func TestAutoFsSymlink(t *testing.T) {
err = os.Symlink(wd+"/store/foo", wd+"/mount/config/bar")
CheckSuccess(err)
fi, err := os.Lstat(wd+"/mount/bar/file1")
fi, err := os.Lstat(wd + "/mount/bar/file1")
CheckSuccess(err)
err = os.Remove(wd+"/mount/config/bar")
err = os.Remove(wd + "/mount/config/bar")
CheckSuccess(err)
// Need time for the unmount to be noticed.
log.Println("sleeping...")
time.Sleep(entryTtl*2e9)
time.Sleep(entryTtl * 2e9)
fi, _ = os.Lstat(wd+"/mount/foo")
fi, _ = os.Lstat(wd + "/mount/foo")
if fi != nil {
t.Error("Should not have file:", fi)
}
_, err = ioutil.ReadDir(wd+"/mount/config")
_, err = ioutil.ReadDir(wd + "/mount/config")
CheckSuccess(err)
_, err = os.Lstat(wd+"/mount/foo/file1")
_, err = os.Lstat(wd + "/mount/foo/file1")
CheckSuccess(err)
}
......
......@@ -77,7 +77,7 @@ func getAttr(fs fuse.FileSystem, name string) *attrResponse {
func openFile(fs fuse.FileSystem, name string) (result *openResponse) {
result = &openResponse{}
flags := uint32(os.O_RDONLY)
f, code := fs.Open(name, flags)
if !code.Ok() {
result.Status = code
......@@ -88,9 +88,9 @@ func openFile(fs fuse.FileSystem, name string) (result *openResponse) {
buf := bytes.NewBuffer(nil)
input := fuse.ReadIn{
Offset: 0,
Size: 128 * (1<<10),
Flags: flags,
Offset: 0,
Size: 128 * (1 << 10),
Flags: flags,
}
bp := fuse.NewGcBufferPool()
......@@ -99,7 +99,7 @@ func openFile(fs fuse.FileSystem, name string) (result *openResponse) {
buf.Write(data)
if !status.Ok() {
result.Status = status
return
return
}
if len(data) < int(input.Size) {
break
......@@ -181,7 +181,7 @@ func (me *CachingFileSystem) OpenDir(name string) (stream chan fuse.DirEntry, st
// Caching file contents easily overflows available memory.
func (me *CachingFileSystem) DisabledOpen(name string, flags uint32) (f fuse.File, status fuse.Status) {
if flags & fuse.O_ANYWRITE != 0 {
if flags&fuse.O_ANYWRITE != 0 {
return nil, fuse.EPERM
}
......
......@@ -30,7 +30,7 @@ func modeMapEq(m1, m2 map[string]uint32) bool {
func TestCachingFs(t *testing.T) {
wd := fuse.MakeTempDir()
defer os.RemoveAll(wd)
fs := fuse.NewLoopbackFileSystem(wd)
cfs := NewCachingFileSystem(fs, 0)
......@@ -38,11 +38,11 @@ func TestCachingFs(t *testing.T) {
fi, code := cfs.GetAttr("orig")
if !code.Ok() {
t.Fatal("GetAttr failure", code)
}
}
if !fi.IsDirectory() {
t.Error("unexpected attr", fi)
}
os.Symlink("orig", wd+"/symlink")
val, code := cfs.Readlink("symlink")
......@@ -64,10 +64,9 @@ func TestCachingFs(t *testing.T) {
}
expected := map[string]uint32{
"symlink": syscall.S_IFLNK,
"orig": fuse.S_IFDIR,
"orig": fuse.S_IFDIR,
}
if !modeMapEq(results, expected) {
t.Error("Unexpected readdir result", results, expected)
}
}
......@@ -94,12 +94,12 @@ func (me *TimedCache) Purge() {
}
func (me *TimedCache) RecurringPurge() {
if (me.ttlNs <= 0) {
if me.ttlNs <= 0 {
return
}
me.Purge()
me.PurgeTimer = time.AfterFunc(me.ttlNs * 5,
me.PurgeTimer = time.AfterFunc(me.ttlNs*5,
func() { me.RecurringPurge() })
}
......
......@@ -371,7 +371,7 @@ func (me *UnionFs) Utimens(name string, atime uint64, mtime uint64) (code fuse.S
r.branch = 0
}
if code.Ok() {
code = me.fileSystems[0].Utimens(name, atime, mtime)
code = me.fileSystems[0].Utimens(name, atime, mtime)
}
if code.Ok() {
r.attr.Atime_ns = int64(atime)
......@@ -497,7 +497,7 @@ func (me *UnionFs) promoteDirsTo(filename string) fuse.Status {
if r.code != fuse.OK {
log.Println("path component does not exist", filename, dirName)
}
if r.attr.Mode & fuse.S_IFDIR == 0 {
if r.attr.Mode&fuse.S_IFDIR == 0 {
log.Println("path component is not a directory.", dirName, r)
return fuse.EPERM
}
......@@ -511,7 +511,7 @@ func (me *UnionFs) promoteDirsTo(filename string) fuse.Status {
}
for i, _ := range todo {
j := len(todo)-i-1
j := len(todo) - i - 1
d := todo[j]
log.Println("Promoting directory", d)
code := me.fileSystems[0].Mkdir(d, 0755)
......@@ -539,9 +539,9 @@ func (me *UnionFs) Create(name string, flags uint32, mode uint32) (fuseFile fuse
now := time.Nanoseconds()
a := os.FileInfo{
Mode: fuse.S_IFREG | mode,
Ctime_ns: now,
Mtime_ns: now,
Mode: fuse.S_IFREG | mode,
Ctime_ns: now,
Mtime_ns: now,
}
me.branchCache.Set(name, branchResult{&a, fuse.OK, 0})
}
......
......@@ -43,8 +43,8 @@ func setupUfs(t *testing.T) (workdir string, cleanup func()) {
ufs := NewUnionFs(roots, testOpts)
opts := &fuse.MountOptions{
EntryTimeout: entryTtl,
AttrTimeout: entryTtl,
EntryTimeout: entryTtl,
AttrTimeout: entryTtl,
NegativeTimeout: entryTtl,
}
......@@ -140,13 +140,13 @@ func TestChtimes(t *testing.T) {
defer clean()
writeToFile(wd+"/ro/file", "a")
err := os.Chtimes(wd + "/ro/file", 42e9, 43e9)
err := os.Chtimes(wd+"/ro/file", 42e9, 43e9)
CheckSuccess(err)
err = os.Chtimes(wd + "/mount/file", 82e9, 83e9)
err = os.Chtimes(wd+"/mount/file", 82e9, 83e9)
CheckSuccess(err)
fi, err := os.Lstat(wd +"/mount/file")
fi, err := os.Lstat(wd + "/mount/file")
if fi.Atime_ns != 82e9 || fi.Mtime_ns != 83e9 {
t.Error("Incorrect timestamp", fi)
}
......@@ -199,7 +199,7 @@ func TestBasic(t *testing.T) {
t.Errorf("missing file in rw layer", names)
}
contents := readFromFile(wd+"/mount/new")
contents := readFromFile(wd + "/mount/new")
if contents != "new contents" {
t.Errorf("read mismatch: '%v'", contents)
}
......@@ -297,7 +297,7 @@ func TestMkdirPromote(t *testing.T) {
err = os.Mkdir(wd+"/mount/subdir/subdir2/dir3", 0755)
CheckSuccess(err)
fi, _ := os.Lstat(wd+"/rw/subdir/subdir2/dir3")
fi, _ := os.Lstat(wd + "/rw/subdir/subdir2/dir3")
CheckSuccess(err)
if fi == nil || !fi.IsDirectory() {
t.Error("is not a directory: ", fi)
......@@ -409,13 +409,13 @@ func TestCopyChmod(t *testing.T) {
fi, err := os.Lstat(fn)
CheckSuccess(err)
if fi.Mode & 0111 == 0 {
if fi.Mode&0111 == 0 {
t.Errorf("1st attr error %o", fi.Mode)
}
time.Sleep(entryTtl * 1.1e9)
fi, err = os.Lstat(fn)
CheckSuccess(err)
if fi.Mode & 0111 == 0 {
if fi.Mode&0111 == 0 {
t.Errorf("uncached attr error %o", fi.Mode)
}
}
......@@ -423,7 +423,7 @@ func TestCopyChmod(t *testing.T) {
func abs(dt int64) int64 {
if dt >= 0 {
return dt
}
}
return -dt
}
......@@ -445,7 +445,7 @@ func TestTruncateTimestamp(t *testing.T) {
fi, err := os.Lstat(fn)
CheckSuccess(err)
if abs(truncTs - fi.Mtime_ns) > 0.1e9 {
if abs(truncTs-fi.Mtime_ns) > 0.1e9 {
t.Error("timestamp drift", truncTs, fi.Mtime_ns)
}
}
......@@ -17,11 +17,11 @@ func TestZipFs(t *testing.T) {
connector := fuse.NewFileSystemConnector(zfs, nil)
mountPoint := fuse.MakeTempDir()
defer os.RemoveAll(mountPoint)
state := fuse.NewMountState(connector)
state.Mount(mountPoint)
defer state.Unmount()
go state.Loop(false)
d, err := os.Open(mountPoint)
......
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