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

Use go style receiver names.

parent 30e96b91
...@@ -31,45 +31,45 @@ func (me FileMode) String() string { ...@@ -31,45 +31,45 @@ func (me FileMode) String() string {
return "0" return "0"
} }
func (me FileMode) IsFifo() bool { return (uint32(me) & syscall.S_IFMT) == syscall.S_IFIFO } func (m FileMode) IsFifo() bool { return (uint32(m) & syscall.S_IFMT) == syscall.S_IFIFO }
// IsChar reports whether the FileInfo describes a character special file. // IsChar reports whether the FileInfo describes a character special file.
func (me FileMode) IsChar() bool { return (uint32(me) & syscall.S_IFMT) == syscall.S_IFCHR } func (m FileMode) IsChar() bool { return (uint32(m) & syscall.S_IFMT) == syscall.S_IFCHR }
// IsDir reports whether the FileInfo describes a directory. // IsDir reports whether the FileInfo describes a directory.
func (me FileMode) IsDir() bool { return (uint32(me) & syscall.S_IFMT) == syscall.S_IFDIR } func (m FileMode) IsDir() bool { return (uint32(m) & syscall.S_IFMT) == syscall.S_IFDIR }
// IsBlock reports whether the FileInfo describes a block special file. // IsBlock reports whether the FileInfo describes a block special file.
func (me FileMode) IsBlock() bool { return (uint32(me) & syscall.S_IFMT) == syscall.S_IFBLK } func (m FileMode) IsBlock() bool { return (uint32(m) & syscall.S_IFMT) == syscall.S_IFBLK }
// IsRegular reports whether the FileInfo describes a regular file. // IsRegular reports whether the FileInfo describes a regular file.
func (me FileMode) IsRegular() bool { return (uint32(me) & syscall.S_IFMT) == syscall.S_IFREG } func (m FileMode) IsRegular() bool { return (uint32(m) & syscall.S_IFMT) == syscall.S_IFREG }
// IsSymlink reports whether the FileInfo describes a symbolic link. // IsSymlink reports whether the FileInfo describes a symbolic link.
func (me FileMode) IsSymlink() bool { return (uint32(me) & syscall.S_IFMT) == syscall.S_IFLNK } func (m FileMode) IsSymlink() bool { return (uint32(m) & syscall.S_IFMT) == syscall.S_IFLNK }
// IsSocket reports whether the FileInfo describes a socket. // IsSocket reports whether the FileInfo describes a socket.
func (me FileMode) IsSocket() bool { return (uint32(me) & syscall.S_IFMT) == syscall.S_IFSOCK } func (m FileMode) IsSocket() bool { return (uint32(m) & syscall.S_IFMT) == syscall.S_IFSOCK }
func (me *Attr) IsFifo() bool { return (uint32(me.Mode) & syscall.S_IFMT) == syscall.S_IFIFO } func (a *Attr) IsFifo() bool { return (uint32(a.Mode) & syscall.S_IFMT) == syscall.S_IFIFO }
// IsChar reports whether the FileInfo describes a character special file. // IsChar reports whether the FileInfo describes a character special file.
func (me *Attr) IsChar() bool { return (uint32(me.Mode) & syscall.S_IFMT) == syscall.S_IFCHR } func (a *Attr) IsChar() bool { return (uint32(a.Mode) & syscall.S_IFMT) == syscall.S_IFCHR }
// IsDir reports whether the FileInfo describes a directory. // IsDir reports whether the FileInfo describes a directory.
func (me *Attr) IsDir() bool { return (uint32(me.Mode) & syscall.S_IFMT) == syscall.S_IFDIR } func (a *Attr) IsDir() bool { return (uint32(a.Mode) & syscall.S_IFMT) == syscall.S_IFDIR }
// IsBlock reports whether the FileInfo describes a block special file. // IsBlock reports whether the FileInfo describes a block special file.
func (me *Attr) IsBlock() bool { return (uint32(me.Mode) & syscall.S_IFMT) == syscall.S_IFBLK } func (a *Attr) IsBlock() bool { return (uint32(a.Mode) & syscall.S_IFMT) == syscall.S_IFBLK }
// IsRegular reports whether the FileInfo describes a regular file. // IsRegular reports whether the FileInfo describes a regular file.
func (me *Attr) IsRegular() bool { return (uint32(me.Mode) & syscall.S_IFMT) == syscall.S_IFREG } func (a *Attr) IsRegular() bool { return (uint32(a.Mode) & syscall.S_IFMT) == syscall.S_IFREG }
// IsSymlink reports whether the FileInfo describes a symbolic link. // IsSymlink reports whether the FileInfo describes a symbolic link.
func (me *Attr) IsSymlink() bool { return (uint32(me.Mode) & syscall.S_IFMT) == syscall.S_IFLNK } func (a *Attr) IsSymlink() bool { return (uint32(a.Mode) & syscall.S_IFMT) == syscall.S_IFLNK }
// IsSocket reports whether the FileInfo describes a socket. // IsSocket reports whether the FileInfo describes a socket.
func (me *Attr) IsSocket() bool { return (uint32(me.Mode) & syscall.S_IFMT) == syscall.S_IFSOCK } func (a *Attr) IsSocket() bool { return (uint32(a.Mode) & syscall.S_IFMT) == syscall.S_IFSOCK }
func (a *Attr) Atimens() int64 { func (a *Attr) Atimens() int64 {
return int64(1e9*a.Atime) + int64(a.Atimensec) return int64(1e9*a.Atime) + int64(a.Atimensec)
......
...@@ -24,11 +24,11 @@ func NewGcBufferPool() *GcBufferPool { ...@@ -24,11 +24,11 @@ func NewGcBufferPool() *GcBufferPool {
return &GcBufferPool{} return &GcBufferPool{}
} }
func (me *GcBufferPool) AllocBuffer(size uint32) []byte { func (p *GcBufferPool) AllocBuffer(size uint32) []byte {
return make([]byte, size) return make([]byte, size)
} }
func (me *GcBufferPool) FreeBuffer(slice []byte) { func (p *GcBufferPool) FreeBuffer(slice []byte) {
} }
// BufferPool implements a pool of buffers that returns slices with // BufferPool implements a pool of buffers that returns slices with
...@@ -55,27 +55,27 @@ func NewBufferPool() *BufferPoolImpl { ...@@ -55,27 +55,27 @@ func NewBufferPool() *BufferPoolImpl {
return bp return bp
} }
func (me *BufferPoolImpl) String() string { func (p *BufferPoolImpl) String() string {
me.lock.Lock() p.lock.Lock()
defer me.lock.Unlock() defer p.lock.Unlock()
result := []string{} result := []string{}
for exp, bufs := range me.buffersBySize { for exp, bufs := range p.buffersBySize {
if len(bufs) > 0 { if len(bufs) > 0 {
result = append(result, fmt.Sprintf("%d=%d", exp, len(bufs))) result = append(result, fmt.Sprintf("%d=%d", exp, len(bufs)))
} }
} }
return fmt.Sprintf("created: %d, outstanding %d. Sizes: %s", return fmt.Sprintf("created: %d, outstanding %d. Sizes: %s",
me.createdBuffers, len(me.outstandingBuffers), p.createdBuffers, len(p.outstandingBuffers),
strings.Join(result, ", ")) strings.Join(result, ", "))
} }
func (me *BufferPoolImpl) getBuffer(pageCount int) []byte { func (p *BufferPoolImpl) getBuffer(pageCount int) []byte {
for ; pageCount < len(me.buffersBySize); pageCount++ { for ; pageCount < len(p.buffersBySize); pageCount++ {
bufferList := me.buffersBySize[pageCount] bufferList := p.buffersBySize[pageCount]
if len(bufferList) > 0 { if len(bufferList) > 0 {
result := bufferList[len(bufferList)-1] result := bufferList[len(bufferList)-1]
me.buffersBySize[pageCount] = me.buffersBySize[pageCount][:len(bufferList)-1] p.buffersBySize[pageCount] = p.buffersBySize[pageCount][:len(bufferList)-1]
return result return result
} }
} }
...@@ -83,16 +83,16 @@ func (me *BufferPoolImpl) getBuffer(pageCount int) []byte { ...@@ -83,16 +83,16 @@ func (me *BufferPoolImpl) getBuffer(pageCount int) []byte {
return nil return nil
} }
func (me *BufferPoolImpl) addBuffer(slice []byte, pages int) { func (p *BufferPoolImpl) addBuffer(slice []byte, pages int) {
for len(me.buffersBySize) <= int(pages) { for len(p.buffersBySize) <= int(pages) {
me.buffersBySize = append(me.buffersBySize, make([][]byte, 0)) p.buffersBySize = append(p.buffersBySize, make([][]byte, 0))
} }
me.buffersBySize[pages] = append(me.buffersBySize[pages], slice) p.buffersBySize[pages] = append(p.buffersBySize[pages], slice)
} }
// AllocBuffer creates a buffer of at least the given size. After use, // AllocBuffer creates a buffer of at least the given size. After use,
// it should be deallocated with FreeBuffer(). // it should be deallocated with FreeBuffer().
func (me *BufferPoolImpl) AllocBuffer(size uint32) []byte { func (p *BufferPoolImpl) AllocBuffer(size uint32) []byte {
sz := int(size) sz := int(size)
if sz < PAGESIZE { if sz < PAGESIZE {
sz = PAGESIZE sz = PAGESIZE
...@@ -103,23 +103,23 @@ func (me *BufferPoolImpl) AllocBuffer(size uint32) []byte { ...@@ -103,23 +103,23 @@ func (me *BufferPoolImpl) AllocBuffer(size uint32) []byte {
} }
psz := sz / PAGESIZE psz := sz / PAGESIZE
me.lock.Lock() p.lock.Lock()
defer me.lock.Unlock() defer p.lock.Unlock()
var b []byte var b []byte
b = me.getBuffer(psz) b = p.getBuffer(psz)
if b == nil { if b == nil {
me.createdBuffers++ p.createdBuffers++
b = make([]byte, size, psz*PAGESIZE) b = make([]byte, size, psz*PAGESIZE)
} else { } else {
b = b[:size] b = b[:size]
} }
me.outstandingBuffers[uintptr(unsafe.Pointer(&b[0]))] = true p.outstandingBuffers[uintptr(unsafe.Pointer(&b[0]))] = true
// For testing should not have more than 20 buffers outstanding. // For testing should not have more than 20 buffers outstanding.
if paranoia && (me.createdBuffers > 50 || len(me.outstandingBuffers) > 50) { if paranoia && (p.createdBuffers > 50 || len(p.outstandingBuffers) > 50) {
panic("Leaking buffers") panic("Leaking buffers")
} }
...@@ -129,7 +129,7 @@ func (me *BufferPoolImpl) AllocBuffer(size uint32) []byte { ...@@ -129,7 +129,7 @@ func (me *BufferPoolImpl) AllocBuffer(size uint32) []byte {
// FreeBuffer takes back a buffer if it was allocated through // FreeBuffer takes back a buffer if it was allocated through
// AllocBuffer. It is not an error to call FreeBuffer() on a slice // AllocBuffer. It is not an error to call FreeBuffer() on a slice
// obtained elsewhere. // obtained elsewhere.
func (me *BufferPoolImpl) FreeBuffer(slice []byte) { func (p *BufferPoolImpl) FreeBuffer(slice []byte) {
if slice == nil { if slice == nil {
return return
} }
...@@ -140,11 +140,11 @@ func (me *BufferPoolImpl) FreeBuffer(slice []byte) { ...@@ -140,11 +140,11 @@ func (me *BufferPoolImpl) FreeBuffer(slice []byte) {
slice = slice[:psz] slice = slice[:psz]
key := uintptr(unsafe.Pointer(&slice[0])) key := uintptr(unsafe.Pointer(&slice[0]))
me.lock.Lock() p.lock.Lock()
defer me.lock.Unlock() defer p.lock.Unlock()
ok := me.outstandingBuffers[key] ok := p.outstandingBuffers[key]
if ok { if ok {
me.addBuffer(slice, psz) p.addBuffer(slice, psz)
delete(me.outstandingBuffers, key) delete(p.outstandingBuffers, key)
} }
} }
...@@ -16,8 +16,8 @@ type cacheFs struct { ...@@ -16,8 +16,8 @@ type cacheFs struct {
*LoopbackFileSystem *LoopbackFileSystem
} }
func (me *cacheFs) Open(name string, flags uint32, context *Context) (fuseFile File, status Status) { func (fs *cacheFs) Open(name string, flags uint32, context *Context) (fuseFile File, status Status) {
f, c := me.LoopbackFileSystem.Open(name, flags, context) f, c := fs.LoopbackFileSystem.Open(name, flags, context)
if !c.Ok() { if !c.Ok() {
return f, c return f, c
} }
...@@ -96,19 +96,19 @@ type nonseekFs struct { ...@@ -96,19 +96,19 @@ type nonseekFs struct {
Length int Length int
} }
func (me *nonseekFs) GetAttr(name string, context *Context) (fi *Attr, status Status) { func (fs *nonseekFs) GetAttr(name string, context *Context) (fi *Attr, status Status) {
if name == "file" { if name == "file" {
return &Attr{Mode: S_IFREG | 0644}, OK return &Attr{Mode: S_IFREG | 0644}, OK
} }
return nil, ENOENT return nil, ENOENT
} }
func (me *nonseekFs) Open(name string, flags uint32, context *Context) (fuseFile File, status Status) { func (fs *nonseekFs) Open(name string, flags uint32, context *Context) (fuseFile File, status Status) {
if name != "file" { if name != "file" {
return nil, ENOENT return nil, ENOENT
} }
data := bytes.Repeat([]byte{42}, me.Length) data := bytes.Repeat([]byte{42}, fs.Length)
f := NewDataFile(data) f := NewDataFile(data)
return &WithFlags{ return &WithFlags{
File: f, File: f,
......
...@@ -3,100 +3,100 @@ package fuse ...@@ -3,100 +3,100 @@ package fuse
import () import ()
// DefaultFileSystem // DefaultFileSystem
func (me *DefaultFileSystem) GetAttr(name string, context *Context) (*Attr, Status) { func (fs *DefaultFileSystem) GetAttr(name string, context *Context) (*Attr, Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (me *DefaultFileSystem) GetXAttr(name string, attr string, context *Context) ([]byte, Status) { func (fs *DefaultFileSystem) GetXAttr(name string, attr string, context *Context) ([]byte, Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (me *DefaultFileSystem) SetXAttr(name string, attr string, data []byte, flags int, context *Context) Status { func (fs *DefaultFileSystem) SetXAttr(name string, attr string, data []byte, flags int, context *Context) Status {
return ENOSYS return ENOSYS
} }
func (me *DefaultFileSystem) ListXAttr(name string, context *Context) ([]string, Status) { func (fs *DefaultFileSystem) ListXAttr(name string, context *Context) ([]string, Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (me *DefaultFileSystem) RemoveXAttr(name string, attr string, context *Context) Status { func (fs *DefaultFileSystem) RemoveXAttr(name string, attr string, context *Context) Status {
return ENOSYS return ENOSYS
} }
func (me *DefaultFileSystem) Readlink(name string, context *Context) (string, Status) { func (fs *DefaultFileSystem) Readlink(name string, context *Context) (string, Status) {
return "", ENOSYS return "", ENOSYS
} }
func (me *DefaultFileSystem) Mknod(name string, mode uint32, dev uint32, context *Context) Status { func (fs *DefaultFileSystem) Mknod(name string, mode uint32, dev uint32, context *Context) Status {
return ENOSYS return ENOSYS
} }
func (me *DefaultFileSystem) Mkdir(name string, mode uint32, context *Context) Status { func (fs *DefaultFileSystem) Mkdir(name string, mode uint32, context *Context) Status {
return ENOSYS return ENOSYS
} }
func (me *DefaultFileSystem) Unlink(name string, context *Context) (code Status) { func (fs *DefaultFileSystem) Unlink(name string, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
func (me *DefaultFileSystem) Rmdir(name string, context *Context) (code Status) { func (fs *DefaultFileSystem) Rmdir(name string, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
func (me *DefaultFileSystem) Symlink(value string, linkName string, context *Context) (code Status) { func (fs *DefaultFileSystem) Symlink(value string, linkName string, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
func (me *DefaultFileSystem) Rename(oldName string, newName string, context *Context) (code Status) { func (fs *DefaultFileSystem) Rename(oldName string, newName string, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
func (me *DefaultFileSystem) Link(oldName string, newName string, context *Context) (code Status) { func (fs *DefaultFileSystem) Link(oldName string, newName string, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
func (me *DefaultFileSystem) Chmod(name string, mode uint32, context *Context) (code Status) { func (fs *DefaultFileSystem) Chmod(name string, mode uint32, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
func (me *DefaultFileSystem) Chown(name string, uid uint32, gid uint32, context *Context) (code Status) { func (fs *DefaultFileSystem) Chown(name string, uid uint32, gid uint32, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
func (me *DefaultFileSystem) Truncate(name string, offset uint64, context *Context) (code Status) { func (fs *DefaultFileSystem) Truncate(name string, offset uint64, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
func (me *DefaultFileSystem) Open(name string, flags uint32, context *Context) (file File, code Status) { func (fs *DefaultFileSystem) Open(name string, flags uint32, context *Context) (file File, code Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (me *DefaultFileSystem) OpenDir(name string, context *Context) (stream chan DirEntry, status Status) { func (fs *DefaultFileSystem) OpenDir(name string, context *Context) (stream chan DirEntry, status Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (me *DefaultFileSystem) OnMount(nodeFs *PathNodeFs) { func (fs *DefaultFileSystem) OnMount(nodeFs *PathNodeFs) {
} }
func (me *DefaultFileSystem) OnUnmount() { func (fs *DefaultFileSystem) OnUnmount() {
} }
func (me *DefaultFileSystem) Access(name string, mode uint32, context *Context) (code Status) { func (fs *DefaultFileSystem) Access(name string, mode uint32, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
func (me *DefaultFileSystem) Create(name string, flags uint32, mode uint32, context *Context) (file File, code Status) { func (fs *DefaultFileSystem) Create(name string, flags uint32, mode uint32, context *Context) (file File, code Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (me *DefaultFileSystem) Utimens(name string, AtimeNs int64, CtimeNs int64, context *Context) (code Status) { func (fs *DefaultFileSystem) Utimens(name string, AtimeNs int64, CtimeNs int64, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
func (me *DefaultFileSystem) String() string { func (fs *DefaultFileSystem) String() string {
return "DefaultFileSystem" return "DefaultFileSystem"
} }
func (me *DefaultFileSystem) StatFs(name string) *StatfsOut { func (fs *DefaultFileSystem) StatFs(name string) *StatfsOut {
return nil return nil
} }
...@@ -8,57 +8,57 @@ import ( ...@@ -8,57 +8,57 @@ import (
var _ = log.Println var _ = log.Println
func (me *DefaultFile) SetInode(*Inode) { func (f *DefaultFile) SetInode(*Inode) {
} }
func (me *DefaultFile) InnerFile() File { func (f *DefaultFile) InnerFile() File {
return nil return nil
} }
func (me *DefaultFile) String() string { func (f *DefaultFile) String() string {
return "DefaultFile" return "DefaultFile"
} }
func (me *DefaultFile) Read(*ReadIn, BufferPool) ([]byte, Status) { func (f *DefaultFile) Read(*ReadIn, BufferPool) ([]byte, Status) {
return []byte(""), ENOSYS return []byte(""), ENOSYS
} }
func (me *DefaultFile) Write(*WriteIn, []byte) (uint32, Status) { func (f *DefaultFile) Write(*WriteIn, []byte) (uint32, Status) {
return 0, ENOSYS return 0, ENOSYS
} }
func (me *DefaultFile) Flush() Status { func (f *DefaultFile) Flush() Status {
return OK return OK
} }
func (me *DefaultFile) Release() { func (f *DefaultFile) Release() {
} }
func (me *DefaultFile) GetAttr() (*Attr, Status) { func (f *DefaultFile) GetAttr() (*Attr, Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (me *DefaultFile) Fsync(flags int) (code Status) { func (f *DefaultFile) Fsync(flags int) (code Status) {
return ENOSYS return ENOSYS
} }
func (me *DefaultFile) Utimens(atimeNs int64, mtimeNs int64) Status { func (f *DefaultFile) Utimens(atimeNs int64, mtimeNs int64) Status {
return ENOSYS return ENOSYS
} }
func (me *DefaultFile) Truncate(size uint64) Status { func (f *DefaultFile) Truncate(size uint64) Status {
return ENOSYS return ENOSYS
} }
func (me *DefaultFile) Chown(uid uint32, gid uint32) Status { func (f *DefaultFile) Chown(uid uint32, gid uint32) Status {
return ENOSYS return ENOSYS
} }
func (me *DefaultFile) Chmod(perms uint32) Status { func (f *DefaultFile) Chmod(perms uint32) Status {
return ENOSYS return ENOSYS
} }
func (me *DefaultFile) Ioctl(input *raw.IoctlIn) (output *raw.IoctlOut, data []byte, code Status) { func (f *DefaultFile) Ioctl(input *raw.IoctlIn) (output *raw.IoctlOut, data []byte, code Status) {
return nil, nil, ENOSYS return nil, nil, ENOSYS
} }
...@@ -9,18 +9,18 @@ var _ = log.Println ...@@ -9,18 +9,18 @@ var _ = log.Println
type DefaultNodeFileSystem struct { type DefaultNodeFileSystem struct {
} }
func (me *DefaultNodeFileSystem) OnUnmount() { func (fs *DefaultNodeFileSystem) OnUnmount() {
} }
func (me *DefaultNodeFileSystem) OnMount(conn *FileSystemConnector) { func (fs *DefaultNodeFileSystem) OnMount(conn *FileSystemConnector) {
} }
func (me *DefaultNodeFileSystem) Root() FsNode { func (fs *DefaultNodeFileSystem) Root() FsNode {
return new(DefaultFsNode) return new(DefaultFsNode)
} }
func (me *DefaultNodeFileSystem) String() string { func (fs *DefaultNodeFileSystem) String() string {
return "DefaultNodeFileSystem" return "DefaultNodeFileSystem"
} }
...@@ -31,81 +31,81 @@ type DefaultFsNode struct { ...@@ -31,81 +31,81 @@ type DefaultFsNode struct {
inode *Inode inode *Inode
} }
func (me *DefaultFsNode) StatFs() *StatfsOut { func (n *DefaultFsNode) StatFs() *StatfsOut {
return nil return nil
} }
func (me *DefaultFsNode) SetInode(node *Inode) { func (n *DefaultFsNode) SetInode(node *Inode) {
if me.inode != nil { if n.inode != nil {
panic("already have Inode") panic("already have Inode")
} }
if node == nil { if node == nil {
panic("SetInode called with nil Inode.") panic("SetInode called with nil Inode.")
} }
me.inode = node n.inode = node
} }
func (me *DefaultFsNode) Deletable() bool { func (n *DefaultFsNode) Deletable() bool {
return true return true
} }
func (me *DefaultFsNode) Inode() *Inode { func (n *DefaultFsNode) Inode() *Inode {
return me.inode return n.inode
} }
func (me *DefaultFsNode) OnForget() { func (n *DefaultFsNode) OnForget() {
} }
func (me *DefaultFsNode) Lookup(name string, context *Context) (fi *Attr, node FsNode, code Status) { func (n *DefaultFsNode) Lookup(name string, context *Context) (fi *Attr, node FsNode, code Status) {
return nil, nil, ENOENT return nil, nil, ENOENT
} }
func (me *DefaultFsNode) Access(mode uint32, context *Context) (code Status) { func (n *DefaultFsNode) Access(mode uint32, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
func (me *DefaultFsNode) Readlink(c *Context) ([]byte, Status) { func (n *DefaultFsNode) Readlink(c *Context) ([]byte, Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (me *DefaultFsNode) Mknod(name string, mode uint32, dev uint32, context *Context) (fi *Attr, newNode FsNode, code Status) { func (n *DefaultFsNode) Mknod(name string, mode uint32, dev uint32, context *Context) (fi *Attr, newNode FsNode, code Status) {
return nil, nil, ENOSYS return nil, nil, ENOSYS
} }
func (me *DefaultFsNode) Mkdir(name string, mode uint32, context *Context) (fi *Attr, newNode FsNode, code Status) { func (n *DefaultFsNode) Mkdir(name string, mode uint32, context *Context) (fi *Attr, newNode FsNode, code Status) {
return nil, nil, ENOSYS return nil, nil, ENOSYS
} }
func (me *DefaultFsNode) Unlink(name string, context *Context) (code Status) { func (n *DefaultFsNode) Unlink(name string, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
func (me *DefaultFsNode) Rmdir(name string, context *Context) (code Status) { func (n *DefaultFsNode) Rmdir(name string, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
func (me *DefaultFsNode) Symlink(name string, content string, context *Context) (fi *Attr, newNode FsNode, code Status) { func (n *DefaultFsNode) Symlink(name string, content string, context *Context) (fi *Attr, newNode FsNode, code Status) {
return nil, nil, ENOSYS return nil, nil, ENOSYS
} }
func (me *DefaultFsNode) Rename(oldName string, newParent FsNode, newName string, context *Context) (code Status) { func (n *DefaultFsNode) Rename(oldName string, newParent FsNode, newName string, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
func (me *DefaultFsNode) Link(name string, existing FsNode, context *Context) (fi *Attr, newNode FsNode, code Status) { func (n *DefaultFsNode) Link(name string, existing FsNode, context *Context) (fi *Attr, newNode FsNode, code Status) {
return nil, nil, ENOSYS return nil, nil, ENOSYS
} }
func (me *DefaultFsNode) Create(name string, flags uint32, mode uint32, context *Context) (file File, fi *Attr, newNode FsNode, code Status) { func (n *DefaultFsNode) Create(name string, flags uint32, mode uint32, context *Context) (file File, fi *Attr, newNode FsNode, code Status) {
return nil, nil, nil, ENOSYS return nil, nil, nil, ENOSYS
} }
func (me *DefaultFsNode) Open(flags uint32, context *Context) (file File, code Status) { func (n *DefaultFsNode) Open(flags uint32, context *Context) (file File, code Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (me *DefaultFsNode) Flush(file File, openFlags uint32, context *Context) (code Status) { func (n *DefaultFsNode) Flush(file File, openFlags uint32, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
func (me *DefaultFsNode) OpenDir(context *Context) (chan DirEntry, Status) { func (n *DefaultFsNode) OpenDir(context *Context) (chan DirEntry, Status) {
ch := me.Inode().Children() ch := n.Inode().Children()
s := make(chan DirEntry, len(ch)) s := make(chan DirEntry, len(ch))
for name, child := range ch { for name, child := range ch {
fi, code := child.FsNode().GetAttr(nil, context) fi, code := child.FsNode().GetAttr(nil, context)
...@@ -117,41 +117,41 @@ func (me *DefaultFsNode) OpenDir(context *Context) (chan DirEntry, Status) { ...@@ -117,41 +117,41 @@ func (me *DefaultFsNode) OpenDir(context *Context) (chan DirEntry, Status) {
return s, OK return s, OK
} }
func (me *DefaultFsNode) GetXAttr(attribute string, context *Context) (data []byte, code Status) { func (n *DefaultFsNode) GetXAttr(attribute string, context *Context) (data []byte, code Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (me *DefaultFsNode) RemoveXAttr(attr string, context *Context) Status { func (n *DefaultFsNode) RemoveXAttr(attr string, context *Context) Status {
return ENOSYS return ENOSYS
} }
func (me *DefaultFsNode) SetXAttr(attr string, data []byte, flags int, context *Context) Status { func (n *DefaultFsNode) SetXAttr(attr string, data []byte, flags int, context *Context) Status {
return ENOSYS return ENOSYS
} }
func (me *DefaultFsNode) ListXAttr(context *Context) (attrs []string, code Status) { func (n *DefaultFsNode) ListXAttr(context *Context) (attrs []string, code Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (me *DefaultFsNode) GetAttr(file File, context *Context) (fi *Attr, code Status) { func (n *DefaultFsNode) GetAttr(file File, context *Context) (fi *Attr, code Status) {
if me.Inode().IsDir() { if n.Inode().IsDir() {
return &Attr{Mode: S_IFDIR | 0755}, OK return &Attr{Mode: S_IFDIR | 0755}, OK
} }
return &Attr{Mode: S_IFREG | 0644}, OK return &Attr{Mode: S_IFREG | 0644}, OK
} }
func (me *DefaultFsNode) Chmod(file File, perms uint32, context *Context) (code Status) { func (n *DefaultFsNode) Chmod(file File, perms uint32, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
func (me *DefaultFsNode) Chown(file File, uid uint32, gid uint32, context *Context) (code Status) { func (n *DefaultFsNode) Chown(file File, uid uint32, gid uint32, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
func (me *DefaultFsNode) Truncate(file File, size uint64, context *Context) (code Status) { func (n *DefaultFsNode) Truncate(file File, size uint64, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
func (me *DefaultFsNode) Utimens(file File, atime int64, mtime int64, context *Context) (code Status) { func (n *DefaultFsNode) Utimens(file File, atime int64, mtime int64, context *Context) (code Status) {
return ENOSYS return ENOSYS
} }
...@@ -4,134 +4,134 @@ import ( ...@@ -4,134 +4,134 @@ import (
"github.com/hanwen/go-fuse/raw" "github.com/hanwen/go-fuse/raw"
) )
func (me *DefaultRawFileSystem) Init(init *RawFsInit) { func (fs *DefaultRawFileSystem) Init(init *RawFsInit) {
} }
func (me *DefaultRawFileSystem) StatFs(h *raw.InHeader) *StatfsOut { func (fs *DefaultRawFileSystem) StatFs(h *raw.InHeader) *StatfsOut {
return nil return nil
} }
func (me *DefaultRawFileSystem) Lookup(h *raw.InHeader, name string) (out *raw.EntryOut, code Status) { func (fs *DefaultRawFileSystem) Lookup(h *raw.InHeader, name string) (out *raw.EntryOut, code Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (me *DefaultRawFileSystem) Forget(nodeID, nlookup uint64) { func (fs *DefaultRawFileSystem) Forget(nodeID, nlookup uint64) {
} }
func (me *DefaultRawFileSystem) GetAttr(header *raw.InHeader, input *raw.GetAttrIn) (out *raw.AttrOut, code Status) { func (fs *DefaultRawFileSystem) GetAttr(header *raw.InHeader, input *raw.GetAttrIn) (out *raw.AttrOut, code Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (me *DefaultRawFileSystem) Open(header *raw.InHeader, input *raw.OpenIn) (flags uint32, handle uint64, status Status) { func (fs *DefaultRawFileSystem) Open(header *raw.InHeader, input *raw.OpenIn) (flags uint32, handle uint64, status Status) {
return 0, 0, OK return 0, 0, OK
} }
func (me *DefaultRawFileSystem) SetAttr(header *raw.InHeader, input *raw.SetAttrIn) (out *raw.AttrOut, code Status) { func (fs *DefaultRawFileSystem) SetAttr(header *raw.InHeader, input *raw.SetAttrIn) (out *raw.AttrOut, code Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (me *DefaultRawFileSystem) Readlink(header *raw.InHeader) (out []byte, code Status) { func (fs *DefaultRawFileSystem) Readlink(header *raw.InHeader) (out []byte, code Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (me *DefaultRawFileSystem) Mknod(header *raw.InHeader, input *raw.MknodIn, name string) (out *raw.EntryOut, code Status) { func (fs *DefaultRawFileSystem) Mknod(header *raw.InHeader, input *raw.MknodIn, name string) (out *raw.EntryOut, code Status) {
return new(raw.EntryOut), ENOSYS return new(raw.EntryOut), ENOSYS
} }
func (me *DefaultRawFileSystem) Mkdir(header *raw.InHeader, input *raw.MkdirIn, name string) (out *raw.EntryOut, code Status) { func (fs *DefaultRawFileSystem) Mkdir(header *raw.InHeader, input *raw.MkdirIn, name string) (out *raw.EntryOut, code Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (me *DefaultRawFileSystem) Unlink(header *raw.InHeader, name string) (code Status) { func (fs *DefaultRawFileSystem) Unlink(header *raw.InHeader, name string) (code Status) {
return ENOSYS return ENOSYS
} }
func (me *DefaultRawFileSystem) Rmdir(header *raw.InHeader, name string) (code Status) { func (fs *DefaultRawFileSystem) Rmdir(header *raw.InHeader, name string) (code Status) {
return ENOSYS return ENOSYS
} }
func (me *DefaultRawFileSystem) Symlink(header *raw.InHeader, pointedTo string, linkName string) (out *raw.EntryOut, code Status) { func (fs *DefaultRawFileSystem) Symlink(header *raw.InHeader, pointedTo string, linkName string) (out *raw.EntryOut, code Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (me *DefaultRawFileSystem) Rename(header *raw.InHeader, input *raw.RenameIn, oldName string, newName string) (code Status) { func (fs *DefaultRawFileSystem) Rename(header *raw.InHeader, input *raw.RenameIn, oldName string, newName string) (code Status) {
return ENOSYS return ENOSYS
} }
func (me *DefaultRawFileSystem) Link(header *raw.InHeader, input *raw.LinkIn, name string) (out *raw.EntryOut, code Status) { func (fs *DefaultRawFileSystem) Link(header *raw.InHeader, input *raw.LinkIn, name string) (out *raw.EntryOut, code Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (me *DefaultRawFileSystem) GetXAttrSize(header *raw.InHeader, attr string) (size int, code Status) { func (fs *DefaultRawFileSystem) GetXAttrSize(header *raw.InHeader, attr string) (size int, code Status) {
return 0, ENOSYS return 0, ENOSYS
} }
func (me *DefaultRawFileSystem) GetXAttrData(header *raw.InHeader, attr string) (data []byte, code Status) { func (fs *DefaultRawFileSystem) GetXAttrData(header *raw.InHeader, attr string) (data []byte, code Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (me *DefaultRawFileSystem) SetXAttr(header *raw.InHeader, input *raw.SetXAttrIn, attr string, data []byte) Status { func (fs *DefaultRawFileSystem) SetXAttr(header *raw.InHeader, input *raw.SetXAttrIn, attr string, data []byte) Status {
return ENOSYS return ENOSYS
} }
func (me *DefaultRawFileSystem) ListXAttr(header *raw.InHeader) (data []byte, code Status) { func (fs *DefaultRawFileSystem) ListXAttr(header *raw.InHeader) (data []byte, code Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (me *DefaultRawFileSystem) RemoveXAttr(header *raw.InHeader, attr string) Status { func (fs *DefaultRawFileSystem) RemoveXAttr(header *raw.InHeader, attr string) Status {
return ENOSYS return ENOSYS
} }
func (me *DefaultRawFileSystem) Access(header *raw.InHeader, input *raw.AccessIn) (code Status) { func (fs *DefaultRawFileSystem) Access(header *raw.InHeader, input *raw.AccessIn) (code Status) {
return ENOSYS return ENOSYS
} }
func (me *DefaultRawFileSystem) Create(header *raw.InHeader, input *raw.CreateIn, name string) (flags uint32, handle uint64, out *raw.EntryOut, code Status) { func (fs *DefaultRawFileSystem) Create(header *raw.InHeader, input *raw.CreateIn, name string) (flags uint32, handle uint64, out *raw.EntryOut, code Status) {
return 0, 0, nil, ENOSYS return 0, 0, nil, ENOSYS
} }
func (me *DefaultRawFileSystem) Bmap(header *raw.InHeader, input *raw.BmapIn) (out *raw.BmapOut, code Status) { func (fs *DefaultRawFileSystem) Bmap(header *raw.InHeader, input *raw.BmapIn) (out *raw.BmapOut, code Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (me *DefaultRawFileSystem) Poll(header *raw.InHeader, input *raw.PollIn) (out *raw.PollOut, code Status) { func (fs *DefaultRawFileSystem) Poll(header *raw.InHeader, input *raw.PollIn) (out *raw.PollOut, code Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (me *DefaultRawFileSystem) OpenDir(header *raw.InHeader, input *raw.OpenIn) (flags uint32, handle uint64, status Status) { func (fs *DefaultRawFileSystem) OpenDir(header *raw.InHeader, input *raw.OpenIn) (flags uint32, handle uint64, status Status) {
return 0, 0, ENOSYS return 0, 0, ENOSYS
} }
func (me *DefaultRawFileSystem) Read(header *raw.InHeader, input *ReadIn, bp BufferPool) ([]byte, Status) { func (fs *DefaultRawFileSystem) Read(header *raw.InHeader, input *ReadIn, bp BufferPool) ([]byte, Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (me *DefaultRawFileSystem) Release(header *raw.InHeader, input *raw.ReleaseIn) { func (fs *DefaultRawFileSystem) Release(header *raw.InHeader, input *raw.ReleaseIn) {
} }
func (me *DefaultRawFileSystem) Write(header *raw.InHeader, input *WriteIn, data []byte) (written uint32, code Status) { func (fs *DefaultRawFileSystem) Write(header *raw.InHeader, input *WriteIn, data []byte) (written uint32, code Status) {
return 0, ENOSYS return 0, ENOSYS
} }
func (me *DefaultRawFileSystem) Flush(header *raw.InHeader, input *raw.FlushIn) Status { func (fs *DefaultRawFileSystem) Flush(header *raw.InHeader, input *raw.FlushIn) Status {
return OK return OK
} }
func (me *DefaultRawFileSystem) Fsync(header *raw.InHeader, input *raw.FsyncIn) (code Status) { func (fs *DefaultRawFileSystem) Fsync(header *raw.InHeader, input *raw.FsyncIn) (code Status) {
return ENOSYS return ENOSYS
} }
func (me *DefaultRawFileSystem) ReadDir(header *raw.InHeader, input *ReadIn) (*DirEntryList, Status) { func (fs *DefaultRawFileSystem) ReadDir(header *raw.InHeader, input *ReadIn) (*DirEntryList, Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (me *DefaultRawFileSystem) ReleaseDir(header *raw.InHeader, input *raw.ReleaseIn) { func (fs *DefaultRawFileSystem) ReleaseDir(header *raw.InHeader, input *raw.ReleaseIn) {
} }
func (me *DefaultRawFileSystem) FsyncDir(header *raw.InHeader, input *raw.FsyncIn) (code Status) { func (fs *DefaultRawFileSystem) FsyncDir(header *raw.InHeader, input *raw.FsyncIn) (code Status) {
return ENOSYS return ENOSYS
} }
func (me *DefaultRawFileSystem) Ioctl(header *raw.InHeader, input *raw.IoctlIn) (output *raw.IoctlOut, data []byte, code Status) { func (fs *DefaultRawFileSystem) Ioctl(header *raw.InHeader, input *raw.IoctlIn) (output *raw.IoctlOut, data []byte, code Status) {
return nil, nil, ENOSYS return nil, nil, ENOSYS
} }
...@@ -29,46 +29,46 @@ func NewDirEntryList(max int, off *uint64) *DirEntryList { ...@@ -29,46 +29,46 @@ func NewDirEntryList(max int, off *uint64) *DirEntryList {
return &DirEntryList{maxSize: max, offset: off} return &DirEntryList{maxSize: max, offset: off}
} }
func (me *DirEntryList) AddString(name string, inode uint64, mode uint32) bool { func (l *DirEntryList) AddString(name string, inode uint64, mode uint32) bool {
return me.Add([]byte(name), inode, mode) return l.Add([]byte(name), inode, mode)
} }
func (me *DirEntryList) AddDirEntry(e DirEntry) bool { func (l *DirEntryList) AddDirEntry(e DirEntry) bool {
return me.Add([]byte(e.Name), uint64(raw.FUSE_UNKNOWN_INO), e.Mode) return l.Add([]byte(e.Name), uint64(raw.FUSE_UNKNOWN_INO), e.Mode)
} }
func (me *DirEntryList) Add(name []byte, inode uint64, mode uint32) bool { func (l *DirEntryList) Add(name []byte, inode uint64, mode uint32) bool {
lastLen := me.buf.Len() lastLen := l.buf.Len()
(*me.offset)++ (*l.offset)++
dirent := raw.Dirent{ dirent := raw.Dirent{
Off: *me.offset, Off: *l.offset,
Ino: inode, Ino: inode,
NameLen: uint32(len(name)), NameLen: uint32(len(name)),
Typ: ModeToType(mode), Typ: ModeToType(mode),
} }
_, err := me.buf.Write(asSlice(unsafe.Pointer(&dirent), unsafe.Sizeof(raw.Dirent{}))) _, err := l.buf.Write(asSlice(unsafe.Pointer(&dirent), unsafe.Sizeof(raw.Dirent{})))
if err != nil { if err != nil {
panic("Serialization of Dirent failed") panic("Serialization of Dirent failed")
} }
me.buf.Write(name) l.buf.Write(name)
padding := 8 - len(name)&7 padding := 8 - len(name)&7
if padding < 8 { if padding < 8 {
me.buf.Write(make([]byte, padding)) l.buf.Write(make([]byte, padding))
} }
if me.buf.Len() > me.maxSize { if l.buf.Len() > l.maxSize {
me.buf.Truncate(lastLen) l.buf.Truncate(lastLen)
(*me.offset)-- (*l.offset)--
return false return false
} }
return true return true
} }
func (me *DirEntryList) Bytes() []byte { func (l *DirEntryList) Bytes() []byte {
return me.buf.Bytes() return l.buf.Bytes()
} }
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
...@@ -85,36 +85,36 @@ type connectorDir struct { ...@@ -85,36 +85,36 @@ type connectorDir struct {
lastOffset uint64 lastOffset uint64
} }
func (me *connectorDir) ReadDir(input *ReadIn) (*DirEntryList, Status) { func (d *connectorDir) ReadDir(input *ReadIn) (*DirEntryList, Status) {
if me.stream == nil && len(me.extra) == 0 { if d.stream == nil && len(d.extra) == 0 {
return nil, OK return nil, OK
} }
list := NewDirEntryList(int(input.Size), &me.lastOffset) list := NewDirEntryList(int(input.Size), &d.lastOffset)
if me.leftOver.Name != "" { if d.leftOver.Name != "" {
success := list.AddDirEntry(me.leftOver) success := list.AddDirEntry(d.leftOver)
if !success { if !success {
panic("No space for single entry.") panic("No space for single entry.")
} }
me.leftOver.Name = "" d.leftOver.Name = ""
} }
for len(me.extra) > 0 { for len(d.extra) > 0 {
e := me.extra[len(me.extra)-1] e := d.extra[len(d.extra)-1]
me.extra = me.extra[:len(me.extra)-1] d.extra = d.extra[:len(d.extra)-1]
success := list.AddDirEntry(e) success := list.AddDirEntry(e)
if !success { if !success {
me.leftOver = e d.leftOver = e
return list, OK return list, OK
} }
} }
for { for {
d, isOpen := <-me.stream de, isOpen := <-d.stream
if !isOpen { if !isOpen {
me.stream = nil d.stream = nil
break break
} }
if !list.AddDirEntry(d) { if !list.AddDirEntry(de) {
me.leftOver = d d.leftOver = de
break break
} }
} }
...@@ -122,9 +122,9 @@ func (me *connectorDir) ReadDir(input *ReadIn) (*DirEntryList, Status) { ...@@ -122,9 +122,9 @@ func (me *connectorDir) ReadDir(input *ReadIn) (*DirEntryList, Status) {
} }
// Read everything so we make goroutines exit. // Read everything so we make goroutines exit.
func (me *connectorDir) Release() { func (d *connectorDir) Release() {
for ok := true; ok && me.stream != nil; { for ok := true; ok && d.stream != nil; {
_, ok = <-me.stream _, ok = <-d.stream
if !ok { if !ok {
break break
} }
......
...@@ -17,17 +17,17 @@ type DataFile struct { ...@@ -17,17 +17,17 @@ type DataFile struct {
DefaultFile DefaultFile
} }
func (me *DataFile) String() string { func (f *DataFile) String() string {
l := len(me.data) l := len(f.data)
if l > 10 { if l > 10 {
l = 10 l = 10
} }
return fmt.Sprintf("DataFile(%x)", me.data[:l]) return fmt.Sprintf("DataFile(%x)", f.data[:l])
} }
func (me *DataFile) GetAttr() (*Attr, Status) { func (f *DataFile) GetAttr() (*Attr, Status) {
return &Attr{Mode: S_IFREG | 0644, Size: uint64(len(me.data))}, OK return &Attr{Mode: S_IFREG | 0644, Size: uint64(len(f.data))}, OK
} }
func NewDataFile(data []byte) *DataFile { func NewDataFile(data []byte) *DataFile {
...@@ -36,13 +36,13 @@ func NewDataFile(data []byte) *DataFile { ...@@ -36,13 +36,13 @@ func NewDataFile(data []byte) *DataFile {
return f return f
} }
func (me *DataFile) Read(input *ReadIn, bp BufferPool) ([]byte, Status) { func (f *DataFile) Read(input *ReadIn, bp BufferPool) ([]byte, Status) {
end := int(input.Offset) + int(input.Size) end := int(input.Offset) + int(input.Size)
if end > len(me.data) { if end > len(f.data) {
end = len(me.data) end = len(f.data)
} }
return me.data[input.Offset:end], OK return f.data[input.Offset:end], OK
} }
//////////////// ////////////////
...@@ -56,27 +56,27 @@ func NewDevNullFile() *DevNullFile { ...@@ -56,27 +56,27 @@ func NewDevNullFile() *DevNullFile {
return new(DevNullFile) return new(DevNullFile)
} }
func (me *DevNullFile) String() string { func (f *DevNullFile) String() string {
return "DevNullFile" return "DevNullFile"
} }
func (me *DevNullFile) Read(input *ReadIn, bp BufferPool) ([]byte, Status) { func (f *DevNullFile) Read(input *ReadIn, bp BufferPool) ([]byte, Status) {
return []byte{}, OK return []byte{}, OK
} }
func (me *DevNullFile) Write(input *WriteIn, content []byte) (uint32, Status) { func (f *DevNullFile) Write(input *WriteIn, content []byte) (uint32, Status) {
return uint32(len(content)), OK return uint32(len(content)), OK
} }
func (me *DevNullFile) Flush() Status { func (f *DevNullFile) Flush() Status {
return OK return OK
} }
func (me *DevNullFile) Fsync(flags int) (code Status) { func (f *DevNullFile) Fsync(flags int) (code Status) {
return OK return OK
} }
func (me *DevNullFile) Truncate(size uint64) (code Status) { func (f *DevNullFile) Truncate(size uint64) (code Status) {
return OK return OK
} }
...@@ -89,54 +89,54 @@ type LoopbackFile struct { ...@@ -89,54 +89,54 @@ type LoopbackFile struct {
DefaultFile DefaultFile
} }
func (me *LoopbackFile) String() string { func (f *LoopbackFile) String() string {
return fmt.Sprintf("LoopbackFile(%s)", me.File.Name()) return fmt.Sprintf("LoopbackFile(%s)", f.File.Name())
} }
func (me *LoopbackFile) Read(input *ReadIn, buffers BufferPool) ([]byte, Status) { func (f *LoopbackFile) Read(input *ReadIn, buffers BufferPool) ([]byte, Status) {
slice := buffers.AllocBuffer(input.Size) slice := buffers.AllocBuffer(input.Size)
n, err := me.File.ReadAt(slice, int64(input.Offset)) n, err := f.File.ReadAt(slice, int64(input.Offset))
if err == io.EOF { if err == io.EOF {
err = nil err = nil
} }
return slice[:n], ToStatus(err) return slice[:n], ToStatus(err)
} }
func (me *LoopbackFile) Write(input *WriteIn, data []byte) (uint32, Status) { func (f *LoopbackFile) Write(input *WriteIn, data []byte) (uint32, Status) {
n, err := me.File.WriteAt(data, int64(input.Offset)) n, err := f.File.WriteAt(data, int64(input.Offset))
return uint32(n), ToStatus(err) return uint32(n), ToStatus(err)
} }
func (me *LoopbackFile) Release() { func (f *LoopbackFile) Release() {
me.File.Close() f.File.Close()
} }
func (me *LoopbackFile) Flush() Status { func (f *LoopbackFile) Flush() Status {
return OK return OK
} }
func (me *LoopbackFile) Fsync(flags int) (code Status) { func (f *LoopbackFile) Fsync(flags int) (code Status) {
return ToStatus(syscall.Fsync(int(me.File.Fd()))) return ToStatus(syscall.Fsync(int(f.File.Fd())))
} }
func (me *LoopbackFile) Truncate(size uint64) Status { func (f *LoopbackFile) Truncate(size uint64) Status {
return ToStatus(syscall.Ftruncate(int(me.File.Fd()), int64(size))) return ToStatus(syscall.Ftruncate(int(f.File.Fd()), int64(size)))
} }
// futimens missing from 6g runtime. // futimens missing from 6g runtime.
func (me *LoopbackFile) Chmod(mode uint32) Status { func (f *LoopbackFile) Chmod(mode uint32) Status {
return ToStatus(me.File.Chmod(os.FileMode(mode))) return ToStatus(f.File.Chmod(os.FileMode(mode)))
} }
func (me *LoopbackFile) Chown(uid uint32, gid uint32) Status { func (f *LoopbackFile) Chown(uid uint32, gid uint32) Status {
return ToStatus(me.File.Chown(int(uid), int(gid))) return ToStatus(f.File.Chown(int(uid), int(gid)))
} }
func (me *LoopbackFile) GetAttr() (*Attr, Status) { func (f *LoopbackFile) GetAttr() (*Attr, Status) {
st := syscall.Stat_t{} st := syscall.Stat_t{}
err := syscall.Fstat(int(me.File.Fd()), &st) err := syscall.Fstat(int(f.File.Fd()), &st)
if err != nil { if err != nil {
return nil, ToStatus(err) return nil, ToStatus(err)
} }
...@@ -152,26 +152,26 @@ type ReadOnlyFile struct { ...@@ -152,26 +152,26 @@ type ReadOnlyFile struct {
File File
} }
func (me *ReadOnlyFile) String() string { func (f *ReadOnlyFile) String() string {
return fmt.Sprintf("ReadOnlyFile(%s)", me.File.String()) return fmt.Sprintf("ReadOnlyFile(%s)", f.File.String())
} }
func (me *ReadOnlyFile) Write(input *WriteIn, data []byte) (uint32, Status) { func (f *ReadOnlyFile) Write(input *WriteIn, data []byte) (uint32, Status) {
return 0, EPERM return 0, EPERM
} }
func (me *ReadOnlyFile) Fsync(flag int) (code Status) { func (f *ReadOnlyFile) Fsync(flag int) (code Status) {
return OK return OK
} }
func (me *ReadOnlyFile) Truncate(size uint64) Status { func (f *ReadOnlyFile) Truncate(size uint64) Status {
return EPERM return EPERM
} }
func (me *ReadOnlyFile) Chmod(mode uint32) Status { func (f *ReadOnlyFile) Chmod(mode uint32) Status {
return EPERM return EPERM
} }
func (me *ReadOnlyFile) Chown(uid uint32, gid uint32) Status { func (f *ReadOnlyFile) Chown(uid uint32, gid uint32) Status {
return EPERM return EPERM
} }
...@@ -53,36 +53,36 @@ func NewFileSystemOptions() *FileSystemOptions { ...@@ -53,36 +53,36 @@ func NewFileSystemOptions() *FileSystemOptions {
} }
} }
func NewFileSystemConnector(nodeFs NodeFileSystem, opts *FileSystemOptions) (me *FileSystemConnector) { func NewFileSystemConnector(nodeFs NodeFileSystem, opts *FileSystemOptions) (c *FileSystemConnector) {
me = new(FileSystemConnector) c = new(FileSystemConnector)
if opts == nil { if opts == nil {
opts = NewFileSystemOptions() opts = NewFileSystemOptions()
} }
me.inodeMap = NewHandleMap(opts.PortableInodes) c.inodeMap = NewHandleMap(opts.PortableInodes)
me.rootNode = newInode(true, nodeFs.Root()) c.rootNode = newInode(true, nodeFs.Root())
me.verify() c.verify()
me.MountRoot(nodeFs, opts) c.MountRoot(nodeFs, opts)
// FUSE does not issue a LOOKUP for 1 (obviously), but it does // FUSE does not issue a LOOKUP for 1 (obviously), but it does
// issue a forget. This lookupUpdate is to make the counts match. // issue a forget. This lookupUpdate is to make the counts match.
me.lookupUpdate(me.rootNode) c.lookupUpdate(c.rootNode)
return me return c
} }
func (me *FileSystemConnector) verify() { func (c *FileSystemConnector) verify() {
if !paranoia { if !paranoia {
return return
} }
root := me.rootNode root := c.rootNode
root.verify(me.rootNode.mountPoint) root.verify(c.rootNode.mountPoint)
} }
// Generate EntryOut and increase the lookup count for an inode. // Generate EntryOut and increase the lookup count for an inode.
func (me *FileSystemConnector) childLookup(fi *raw.Attr, fsi FsNode) (out *raw.EntryOut) { func (c *FileSystemConnector) childLookup(fi *raw.Attr, fsi FsNode) (out *raw.EntryOut) {
n := fsi.Inode() n := fsi.Inode()
out = n.mount.attrToEntry(fi) out = n.mount.attrToEntry(fi)
out.Ino = me.lookupUpdate(n) out.Ino = c.lookupUpdate(n)
out.NodeId = out.Ino out.NodeId = out.Ino
if out.Nlink == 0 { if out.Nlink == 0 {
// With Nlink == 0, newer kernels will refuse link // With Nlink == 0, newer kernels will refuse link
...@@ -92,7 +92,7 @@ func (me *FileSystemConnector) childLookup(fi *raw.Attr, fsi FsNode) (out *raw.E ...@@ -92,7 +92,7 @@ func (me *FileSystemConnector) childLookup(fi *raw.Attr, fsi FsNode) (out *raw.E
return out return out
} }
func (me *FileSystemConnector) findMount(parent *Inode, name string) (mount *fileSystemMount) { func (c *FileSystemConnector) findMount(parent *Inode, name string) (mount *fileSystemMount) {
parent.treeLock.RLock() parent.treeLock.RLock()
defer parent.treeLock.RUnlock() defer parent.treeLock.RUnlock()
if parent.mounts == nil { if parent.mounts == nil {
...@@ -102,61 +102,61 @@ func (me *FileSystemConnector) findMount(parent *Inode, name string) (mount *fil ...@@ -102,61 +102,61 @@ func (me *FileSystemConnector) findMount(parent *Inode, name string) (mount *fil
return parent.mounts[name] return parent.mounts[name]
} }
func (me *FileSystemConnector) toInode(nodeid uint64) *Inode { func (c *FileSystemConnector) toInode(nodeid uint64) *Inode {
if nodeid == raw.FUSE_ROOT_ID { if nodeid == raw.FUSE_ROOT_ID {
return me.rootNode return c.rootNode
} }
i := (*Inode)(unsafe.Pointer(me.inodeMap.Decode(nodeid))) i := (*Inode)(unsafe.Pointer(c.inodeMap.Decode(nodeid)))
return i return i
} }
// Must run outside treeLock. Returns the nodeId. // Must run outside treeLock. Returns the nodeId.
func (me *FileSystemConnector) lookupUpdate(node *Inode) uint64 { func (c *FileSystemConnector) lookupUpdate(node *Inode) uint64 {
node.treeLock.Lock() node.treeLock.Lock()
defer node.treeLock.Unlock() defer node.treeLock.Unlock()
if node.lookupCount == 0 { if node.lookupCount == 0 {
node.nodeId = me.inodeMap.Register(&node.handled, node) node.nodeId = c.inodeMap.Register(&node.handled, node)
} }
node.lookupCount += 1 node.lookupCount += 1
return node.nodeId return node.nodeId
} }
// Must run outside treeLock. // Must run outside treeLock.
func (me *FileSystemConnector) forgetUpdate(node *Inode, forgetCount int) { func (c *FileSystemConnector) forgetUpdate(node *Inode, forgetCount int) {
defer me.verify() defer c.verify()
node.treeLock.Lock() node.treeLock.Lock()
defer node.treeLock.Unlock() defer node.treeLock.Unlock()
node.lookupCount -= forgetCount node.lookupCount -= forgetCount
if node.lookupCount == 0 { if node.lookupCount == 0 {
me.inodeMap.Forget(node.nodeId) c.inodeMap.Forget(node.nodeId)
node.nodeId = 0 node.nodeId = 0
} else if node.lookupCount < 0 { } else if node.lookupCount < 0 {
log.Panicf("lookupCount underflow: %d: %v", node.lookupCount, me) log.Panicf("lookupCount underflow: %d: %v", node.lookupCount, c)
} }
me.recursiveConsiderDropInode(node) c.recursiveConsiderDropInode(node)
} }
// InodeCount returns the number of inodes registered with the kernel. // InodeCount returns the number of inodes registered with the kernel.
func (me *FileSystemConnector) InodeHandleCount() int { func (c *FileSystemConnector) InodeHandleCount() int {
return me.inodeMap.Count() return c.inodeMap.Count()
} }
func (me *FileSystemConnector) considerDropInode(node *Inode) { func (c *FileSystemConnector) considerDropInode(node *Inode) {
node.treeLock.Lock() node.treeLock.Lock()
defer node.treeLock.Unlock() defer node.treeLock.Unlock()
me.recursiveConsiderDropInode(node) c.recursiveConsiderDropInode(node)
} }
// Must hold treeLock. // Must hold treeLock.
func (me *FileSystemConnector) recursiveConsiderDropInode(n *Inode) (drop bool) { func (c *FileSystemConnector) recursiveConsiderDropInode(n *Inode) (drop bool) {
delChildren := []string{} delChildren := []string{}
for k, v := range n.children { for k, v := range n.children {
// Only consider children from the same mount, or // Only consider children from the same mount, or
// already unmounted mountpoints. // already unmounted mountpoints.
if v.mountPoint == nil && me.recursiveConsiderDropInode(v) { if v.mountPoint == nil && c.recursiveConsiderDropInode(v) {
delChildren = append(delChildren, k) delChildren = append(delChildren, k)
} }
} }
...@@ -171,7 +171,7 @@ func (me *FileSystemConnector) recursiveConsiderDropInode(n *Inode) (drop bool) ...@@ -171,7 +171,7 @@ func (me *FileSystemConnector) recursiveConsiderDropInode(n *Inode) (drop bool)
if len(n.children) > 0 || n.lookupCount > 0 || !n.FsNode().Deletable() { if len(n.children) > 0 || n.lookupCount > 0 || !n.FsNode().Deletable() {
return false return false
} }
if n == me.rootNode || n.mountPoint != nil { if n == c.rootNode || n.mountPoint != nil {
return false return false
} }
...@@ -183,9 +183,9 @@ func (me *FileSystemConnector) recursiveConsiderDropInode(n *Inode) (drop bool) ...@@ -183,9 +183,9 @@ func (me *FileSystemConnector) recursiveConsiderDropInode(n *Inode) (drop bool)
// Finds a node within the currently known inodes, returns the last // Finds a node within the currently known inodes, returns the last
// known node and the remaining unknown path components. If parent is // known node and the remaining unknown path components. If parent is
// nil, start from FUSE mountpoint. // nil, start from FUSE mountpoint.
func (me *FileSystemConnector) Node(parent *Inode, fullPath string) (*Inode, []string) { func (c *FileSystemConnector) Node(parent *Inode, fullPath string) (*Inode, []string) {
if parent == nil { if parent == nil {
parent = me.rootNode parent = c.rootNode
} }
if fullPath == "" { if fullPath == "" {
return parent, nil return parent, nil
...@@ -221,13 +221,13 @@ func (me *FileSystemConnector) Node(parent *Inode, fullPath string) (*Inode, []s ...@@ -221,13 +221,13 @@ func (me *FileSystemConnector) Node(parent *Inode, fullPath string) (*Inode, []s
return node, nil return node, nil
} }
func (me *FileSystemConnector) LookupNode(parent *Inode, path string) *Inode { func (c *FileSystemConnector) LookupNode(parent *Inode, path string) *Inode {
if path == "" { if path == "" {
return parent return parent
} }
components := strings.Split(path, "/") components := strings.Split(path, "/")
for _, r := range components { for _, r := range components {
_, child, _ := me.internalLookup(parent, r, nil) _, child, _ := c.internalLookup(parent, r, nil)
if child == nil { if child == nil {
return nil return nil
} }
...@@ -240,11 +240,11 @@ func (me *FileSystemConnector) LookupNode(parent *Inode, path string) *Inode { ...@@ -240,11 +240,11 @@ func (me *FileSystemConnector) LookupNode(parent *Inode, path string) *Inode {
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
func (me *FileSystemConnector) MountRoot(nodeFs NodeFileSystem, opts *FileSystemOptions) { func (c *FileSystemConnector) MountRoot(nodeFs NodeFileSystem, opts *FileSystemOptions) {
me.rootNode.mountFs(nodeFs, opts) c.rootNode.mountFs(nodeFs, opts)
me.rootNode.mount.connector = me c.rootNode.mount.connector = c
nodeFs.OnMount(me) nodeFs.OnMount(c)
me.verify() c.verify()
} }
// Mount() generates a synthetic directory node, and mounts the file // Mount() generates a synthetic directory node, and mounts the file
...@@ -258,7 +258,7 @@ func (me *FileSystemConnector) MountRoot(nodeFs NodeFileSystem, opts *FileSystem ...@@ -258,7 +258,7 @@ func (me *FileSystemConnector) MountRoot(nodeFs NodeFileSystem, opts *FileSystem
// ENOENT: the directory containing the mount point does not exist. // ENOENT: the directory containing the mount point does not exist.
// //
// EBUSY: the intended mount point already exists. // EBUSY: the intended mount point already exists.
func (me *FileSystemConnector) Mount(parent *Inode, name string, nodeFs NodeFileSystem, opts *FileSystemOptions) Status { func (c *FileSystemConnector) Mount(parent *Inode, name string, nodeFs NodeFileSystem, opts *FileSystemOptions) Status {
parent.treeLock.Lock() parent.treeLock.Lock()
defer parent.treeLock.Unlock() defer parent.treeLock.Unlock()
node := parent.children[name] node := parent.children[name]
...@@ -268,11 +268,11 @@ func (me *FileSystemConnector) Mount(parent *Inode, name string, nodeFs NodeFile ...@@ -268,11 +268,11 @@ func (me *FileSystemConnector) Mount(parent *Inode, name string, nodeFs NodeFile
node = newInode(true, nodeFs.Root()) node = newInode(true, nodeFs.Root())
if opts == nil { if opts == nil {
opts = me.rootNode.mountPoint.options opts = c.rootNode.mountPoint.options
} }
node.mountFs(nodeFs, opts) node.mountFs(nodeFs, opts)
node.mount.connector = me node.mount.connector = c
parent.addChild(name, node) parent.addChild(name, node)
if parent.mounts == nil { if parent.mounts == nil {
...@@ -280,12 +280,12 @@ func (me *FileSystemConnector) Mount(parent *Inode, name string, nodeFs NodeFile ...@@ -280,12 +280,12 @@ func (me *FileSystemConnector) Mount(parent *Inode, name string, nodeFs NodeFile
} }
parent.mounts[name] = node.mountPoint parent.mounts[name] = node.mountPoint
node.mountPoint.parentInode = parent node.mountPoint.parentInode = parent
if me.Debug { if c.Debug {
log.Println("Mount: ", nodeFs, "on subdir", name, log.Println("Mount: ", nodeFs, "on subdir", name,
"parent", parent.nodeId) "parent", parent.nodeId)
} }
me.verify() c.verify()
nodeFs.OnMount(me) nodeFs.OnMount(c)
return OK return OK
} }
...@@ -296,7 +296,7 @@ func (me *FileSystemConnector) Mount(parent *Inode, name string, nodeFs NodeFile ...@@ -296,7 +296,7 @@ func (me *FileSystemConnector) Mount(parent *Inode, name string, nodeFs NodeFile
// EINVAL: path does not exist, or is not a mount point. // EINVAL: path does not exist, or is not a mount point.
// //
// EBUSY: there are open files, or submounts below this node. // EBUSY: there are open files, or submounts below this node.
func (me *FileSystemConnector) Unmount(node *Inode) Status { func (c *FileSystemConnector) Unmount(node *Inode) Status {
if node.mountPoint == nil { if node.mountPoint == nil {
log.Println("not a mountpoint:", node.nodeId) log.Println("not a mountpoint:", node.nodeId)
return EINVAL return EINVAL
...@@ -325,14 +325,14 @@ func (me *FileSystemConnector) Unmount(node *Inode) Status { ...@@ -325,14 +325,14 @@ func (me *FileSystemConnector) Unmount(node *Inode) Status {
delete(parentNode.children, name) delete(parentNode.children, name)
mount.fs.OnUnmount() mount.fs.OnUnmount()
me.EntryNotify(parentNode, name) c.EntryNotify(parentNode, name)
return OK return OK
} }
func (me *FileSystemConnector) FileNotify(node *Inode, off int64, length int64) Status { func (c *FileSystemConnector) FileNotify(node *Inode, off int64, length int64) Status {
n := node.nodeId n := node.nodeId
if node == me.rootNode { if node == c.rootNode {
n = raw.FUSE_ROOT_ID n = raw.FUSE_ROOT_ID
} }
if n == 0 { if n == 0 {
...@@ -343,16 +343,16 @@ func (me *FileSystemConnector) FileNotify(node *Inode, off int64, length int64) ...@@ -343,16 +343,16 @@ func (me *FileSystemConnector) FileNotify(node *Inode, off int64, length int64)
Off: off, Off: off,
Ino: n, Ino: n,
} }
return me.fsInit.InodeNotify(&out) return c.fsInit.InodeNotify(&out)
} }
func (me *FileSystemConnector) EntryNotify(dir *Inode, name string) Status { func (c *FileSystemConnector) EntryNotify(dir *Inode, name string) Status {
n := dir.nodeId n := dir.nodeId
if dir == me.rootNode { if dir == c.rootNode {
n = raw.FUSE_ROOT_ID n = raw.FUSE_ROOT_ID
} }
if n == 0 { if n == 0 {
return OK return OK
} }
return me.fsInit.EntryNotify(n, name) return c.fsInit.EntryNotify(n, name)
} }
...@@ -18,62 +18,62 @@ type MutableDataFile struct { ...@@ -18,62 +18,62 @@ type MutableDataFile struct {
GetAttrCalled bool GetAttrCalled bool
} }
func (me *MutableDataFile) String() string { func (f *MutableDataFile) String() string {
return "MutableDataFile" return "MutableDataFile"
} }
func (me *MutableDataFile) Read(r *ReadIn, bp BufferPool) ([]byte, Status) { func (f *MutableDataFile) Read(r *ReadIn, bp BufferPool) ([]byte, Status) {
return me.data[r.Offset : r.Offset+uint64(r.Size)], OK return f.data[r.Offset : r.Offset+uint64(r.Size)], OK
} }
func (me *MutableDataFile) Write(w *WriteIn, d []byte) (uint32, Status) { func (f *MutableDataFile) Write(w *WriteIn, d []byte) (uint32, Status) {
end := uint64(w.Size) + w.Offset end := uint64(w.Size) + w.Offset
if int(end) > len(me.data) { if int(end) > len(f.data) {
data := make([]byte, len(me.data), end) data := make([]byte, len(f.data), end)
copy(data, me.data) copy(data, f.data)
me.data = data f.data = data
} }
copy(me.data[w.Offset:end], d) copy(f.data[w.Offset:end], d)
return w.Size, OK return w.Size, OK
} }
func (me *MutableDataFile) Flush() Status { func (f *MutableDataFile) Flush() Status {
return OK return OK
} }
func (me *MutableDataFile) Release() { func (f *MutableDataFile) Release() {
} }
func (me *MutableDataFile) getAttr() *Attr { func (f *MutableDataFile) getAttr() *Attr {
f := me.Attr a := f.Attr
f.Size = uint64(len(me.data)) a.Size = uint64(len(f.data))
return &f return &a
} }
func (me *MutableDataFile) GetAttr() (*Attr, Status) { func (f *MutableDataFile) GetAttr() (*Attr, Status) {
me.GetAttrCalled = true f.GetAttrCalled = true
return me.getAttr(), OK return f.getAttr(), OK
} }
func (me *MutableDataFile) Utimens(atimeNs int64, mtimeNs int64) Status { func (f *MutableDataFile) Utimens(atimeNs int64, mtimeNs int64) Status {
me.Attr.SetNs(atimeNs, mtimeNs, -1) f.Attr.SetNs(atimeNs, mtimeNs, -1)
return OK return OK
} }
func (me *MutableDataFile) Truncate(size uint64) Status { func (f *MutableDataFile) Truncate(size uint64) Status {
me.data = me.data[:size] f.data = f.data[:size]
return OK return OK
} }
func (me *MutableDataFile) Chown(uid uint32, gid uint32) Status { func (f *MutableDataFile) Chown(uid uint32, gid uint32) Status {
me.Attr.Uid = uid f.Attr.Uid = uid
me.Attr.Gid = gid f.Attr.Gid = gid
return OK return OK
} }
func (me *MutableDataFile) Chmod(perms uint32) Status { func (f *MutableDataFile) Chmod(perms uint32) Status {
me.Attr.Mode = (me.Attr.Mode &^ 07777) | perms f.Attr.Mode = (f.Attr.Mode &^ 07777) | perms
return OK return OK
} }
...@@ -84,34 +84,34 @@ type FSetAttrFs struct { ...@@ -84,34 +84,34 @@ type FSetAttrFs struct {
file *MutableDataFile file *MutableDataFile
} }
func (me *FSetAttrFs) GetXAttr(name string, attr string, context *Context) ([]byte, Status) { func (fs *FSetAttrFs) GetXAttr(name string, attr string, context *Context) ([]byte, Status) {
return nil, ENODATA return nil, ENODATA
} }
func (me *FSetAttrFs) GetAttr(name string, context *Context) (*Attr, Status) { func (fs *FSetAttrFs) GetAttr(name string, context *Context) (*Attr, Status) {
if name == "" { if name == "" {
return &Attr{Mode: S_IFDIR | 0700}, OK return &Attr{Mode: S_IFDIR | 0700}, OK
} }
if name == "file" && me.file != nil { if name == "file" && fs.file != nil {
a := me.file.getAttr() a := fs.file.getAttr()
a.Mode |= S_IFREG a.Mode |= S_IFREG
return a, OK return a, OK
} }
return nil, ENOENT return nil, ENOENT
} }
func (me *FSetAttrFs) Open(name string, flags uint32, context *Context) (File, Status) { func (fs *FSetAttrFs) Open(name string, flags uint32, context *Context) (File, Status) {
if name == "file" { if name == "file" {
return me.file, OK return fs.file, OK
} }
return nil, ENOENT return nil, ENOENT
} }
func (me *FSetAttrFs) Create(name string, flags uint32, mode uint32, context *Context) (File, Status) { func (fs *FSetAttrFs) Create(name string, flags uint32, mode uint32, context *Context) (File, Status) {
if name == "file" { if name == "file" {
f := NewFile() f := NewFile()
me.file = f fs.file = f
me.file.Attr.Mode = mode fs.file.Attr.Mode = mode
return f, OK return f, OK
} }
return nil, ENOENT return nil, ENOENT
......
...@@ -45,9 +45,9 @@ type fileSystemMount struct { ...@@ -45,9 +45,9 @@ type fileSystemMount struct {
} }
// Must called with lock for parent held. // Must called with lock for parent held.
func (me *fileSystemMount) mountName() string { func (m *fileSystemMount) mountName() string {
for k, v := range me.parentInode.mounts { for k, v := range m.parentInode.mounts {
if me == v { if m == v {
return k return k
} }
} }
...@@ -55,44 +55,44 @@ func (me *fileSystemMount) mountName() string { ...@@ -55,44 +55,44 @@ func (me *fileSystemMount) mountName() string {
return "" return ""
} }
func (me *fileSystemMount) setOwner(attr *raw.Attr) { func (m *fileSystemMount) setOwner(attr *raw.Attr) {
if me.options.Owner != nil { if m.options.Owner != nil {
attr.Owner = *(*raw.Owner)(me.options.Owner) attr.Owner = *(*raw.Owner)(m.options.Owner)
} }
} }
func (me *fileSystemMount) attrToEntry(attr *raw.Attr) (out *raw.EntryOut) { func (m *fileSystemMount) attrToEntry(attr *raw.Attr) (out *raw.EntryOut) {
out = &raw.EntryOut{} out = &raw.EntryOut{}
out.Attr = *attr out.Attr = *attr
splitDuration(me.options.EntryTimeout, &out.EntryValid, &out.EntryValidNsec) splitDuration(m.options.EntryTimeout, &out.EntryValid, &out.EntryValidNsec)
splitDuration(me.options.AttrTimeout, &out.AttrValid, &out.AttrValidNsec) splitDuration(m.options.AttrTimeout, &out.AttrValid, &out.AttrValidNsec)
me.setOwner(&out.Attr) m.setOwner(&out.Attr)
if attr.Mode & S_IFDIR == 0 && attr.Nlink == 0 { if attr.Mode & S_IFDIR == 0 && attr.Nlink == 0 {
out.Nlink = 1 out.Nlink = 1
} }
return out return out
} }
func (me *fileSystemMount) fillAttr(a *raw.Attr, nodeId uint64) (out *raw.AttrOut) { func (m *fileSystemMount) fillAttr(a *raw.Attr, nodeId uint64) (out *raw.AttrOut) {
out = &raw.AttrOut{} out = &raw.AttrOut{}
out.Attr = *a out.Attr = *a
splitDuration(me.options.AttrTimeout, &out.AttrValid, &out.AttrValidNsec) splitDuration(m.options.AttrTimeout, &out.AttrValid, &out.AttrValidNsec)
me.setOwner(&out.Attr) m.setOwner(&out.Attr)
out.Ino = nodeId out.Ino = nodeId
return out return out
} }
func (me *fileSystemMount) getOpenedFile(h uint64) *openedFile { func (m *fileSystemMount) getOpenedFile(h uint64) *openedFile {
b := (*openedFile)(unsafe.Pointer(me.openFiles.Decode(h))) b := (*openedFile)(unsafe.Pointer(m.openFiles.Decode(h)))
if me.connector.Debug && b.WithFlags.Description != "" { if m.connector.Debug && b.WithFlags.Description != "" {
log.Printf("File %d = %q", h, b.WithFlags.Description) log.Printf("File %d = %q", h, b.WithFlags.Description)
} }
return b return b
} }
func (me *fileSystemMount) unregisterFileHandle(handle uint64, node *Inode) *openedFile { func (m *fileSystemMount) unregisterFileHandle(handle uint64, node *Inode) *openedFile {
obj := me.openFiles.Forget(handle) obj := m.openFiles.Forget(handle)
opened := (*openedFile)(unsafe.Pointer(obj)) opened := (*openedFile)(unsafe.Pointer(obj))
node.openFilesMutex.Lock() node.openFilesMutex.Lock()
defer node.openFilesMutex.Unlock() defer node.openFilesMutex.Unlock()
...@@ -112,7 +112,7 @@ func (me *fileSystemMount) unregisterFileHandle(handle uint64, node *Inode) *ope ...@@ -112,7 +112,7 @@ func (me *fileSystemMount) unregisterFileHandle(handle uint64, node *Inode) *ope
return opened return opened
} }
func (me *fileSystemMount) registerFileHandle(node *Inode, dir rawDir, f File, flags uint32) (uint64, *openedFile) { func (m *fileSystemMount) registerFileHandle(node *Inode, dir rawDir, f File, flags uint32) (uint64, *openedFile) {
node.openFilesMutex.Lock() node.openFilesMutex.Lock()
defer node.openFilesMutex.Unlock() defer node.openFilesMutex.Unlock()
b := &openedFile{ b := &openedFile{
...@@ -139,16 +139,16 @@ func (me *fileSystemMount) registerFileHandle(node *Inode, dir rawDir, f File, f ...@@ -139,16 +139,16 @@ func (me *fileSystemMount) registerFileHandle(node *Inode, dir rawDir, f File, f
b.WithFlags.File.SetInode(node) b.WithFlags.File.SetInode(node)
} }
node.openFiles = append(node.openFiles, b) node.openFiles = append(node.openFiles, b)
handle := me.openFiles.Register(&b.Handled, b) handle := m.openFiles.Register(&b.Handled, b)
return handle, b return handle, b
} }
// Creates a return entry for a non-existent path. // Creates a return entry for a non-existent path.
func (me *fileSystemMount) negativeEntry() (*raw.EntryOut, Status) { func (m *fileSystemMount) negativeEntry() (*raw.EntryOut, Status) {
if me.options.NegativeTimeout > 0.0 { if m.options.NegativeTimeout > 0.0 {
out := new(raw.EntryOut) out := new(raw.EntryOut)
out.NodeId = 0 out.NodeId = 0
splitDuration(me.options.NegativeTimeout, &out.EntryValid, &out.EntryValidNsec) splitDuration(m.options.NegativeTimeout, &out.EntryValid, &out.EntryValidNsec)
return out, OK return out, OK
} }
return nil, ENOENT return nil, ENOENT
......
This diff is collapsed.
...@@ -43,26 +43,26 @@ type portableHandleMap struct { ...@@ -43,26 +43,26 @@ type portableHandleMap struct {
handles map[uint64]*Handled handles map[uint64]*Handled
} }
func (me *portableHandleMap) Register(obj *Handled, asInt interface{}) uint64 { func (m *portableHandleMap) Register(obj *Handled, asInt interface{}) uint64 {
if obj.check != 0 { if obj.check != 0 {
panic(_ALREADY_MSG) panic(_ALREADY_MSG)
} }
me.Lock() m.Lock()
defer me.Unlock() defer m.Unlock()
for { for {
h := uint64(me.nextFree) h := uint64(m.nextFree)
me.nextFree++ m.nextFree++
// HACK - we make sure we start with 1, so we always // HACK - we make sure we start with 1, so we always
// assign root to 1. // assign root to 1.
if h < 1 { if h < 1 {
continue continue
} }
old := me.handles[h] old := m.handles[h]
if old != nil { if old != nil {
continue continue
} }
me.handles[h] = obj m.handles[h] = obj
obj.check = 0xbaabbaab obj.check = 0xbaabbaab
return h return h
} }
...@@ -70,31 +70,31 @@ func (me *portableHandleMap) Register(obj *Handled, asInt interface{}) uint64 { ...@@ -70,31 +70,31 @@ func (me *portableHandleMap) Register(obj *Handled, asInt interface{}) uint64 {
return 0 return 0
} }
func (me *portableHandleMap) Count() int { func (m *portableHandleMap) Count() int {
me.RLock() m.RLock()
defer me.RUnlock() defer m.RUnlock()
return len(me.handles) return len(m.handles)
} }
func (me *portableHandleMap) Decode(h uint64) *Handled { func (m *portableHandleMap) Decode(h uint64) *Handled {
me.RLock() m.RLock()
defer me.RUnlock() defer m.RUnlock()
return me.handles[h] return m.handles[h]
} }
func (me *portableHandleMap) Forget(h uint64) *Handled { func (m *portableHandleMap) Forget(h uint64) *Handled {
me.Lock() m.Lock()
defer me.Unlock() defer m.Unlock()
v := me.handles[h] v := m.handles[h]
v.check = 0 v.check = 0
delete(me.handles, h) delete(m.handles, h)
return v return v
} }
func (me *portableHandleMap) Has(h uint64) bool { func (m *portableHandleMap) Has(h uint64) bool {
me.RLock() m.RLock()
defer me.RUnlock() defer m.RUnlock()
return me.handles[h] != nil return m.handles[h] != nil
} }
// 32 bits version of HandleMap // 32 bits version of HandleMap
...@@ -103,37 +103,37 @@ type int32HandleMap struct { ...@@ -103,37 +103,37 @@ type int32HandleMap struct {
handles map[uint32]*Handled handles map[uint32]*Handled
} }
func (me *int32HandleMap) Register(obj *Handled, asInt interface{}) uint64 { func (m *int32HandleMap) Register(obj *Handled, asInt interface{}) uint64 {
me.mutex.Lock() m.mutex.Lock()
defer me.mutex.Unlock() defer m.mutex.Unlock()
handle := uint32(uintptr(unsafe.Pointer(obj))) handle := uint32(uintptr(unsafe.Pointer(obj)))
me.handles[handle] = obj m.handles[handle] = obj
return uint64(handle) return uint64(handle)
} }
func (me *int32HandleMap) Has(h uint64) bool { func (m *int32HandleMap) Has(h uint64) bool {
me.mutex.Lock() m.mutex.Lock()
defer me.mutex.Unlock() defer m.mutex.Unlock()
return me.handles[uint32(h)] != nil return m.handles[uint32(h)] != nil
} }
func (me *int32HandleMap) Count() int { func (m *int32HandleMap) Count() int {
me.mutex.Lock() m.mutex.Lock()
defer me.mutex.Unlock() defer m.mutex.Unlock()
return len(me.handles) return len(m.handles)
} }
func (me *int32HandleMap) Forget(handle uint64) *Handled { func (m *int32HandleMap) Forget(handle uint64) *Handled {
val := me.Decode(handle) val := m.Decode(handle)
me.mutex.Lock() m.mutex.Lock()
defer me.mutex.Unlock() defer m.mutex.Unlock()
val.check = 0 val.check = 0
delete(me.handles, uint32(handle)) delete(m.handles, uint32(handle))
return val return val
} }
func (me *int32HandleMap) Decode(handle uint64) *Handled { func (m *int32HandleMap) Decode(handle uint64) *Handled {
val := (*Handled)(unsafe.Pointer(uintptr(handle & ((1 << 32) - 1)))) val := (*Handled)(unsafe.Pointer(uintptr(handle & ((1 << 32) - 1))))
return val return val
} }
...@@ -147,15 +147,15 @@ type int64HandleMap struct { ...@@ -147,15 +147,15 @@ type int64HandleMap struct {
var baseAddress uint64 var baseAddress uint64
func (me *int64HandleMap) verify() { func (m *int64HandleMap) verify() {
if !paranoia { if !paranoia {
return return
} }
me.mutex.Lock() m.mutex.Lock()
defer me.mutex.Unlock() defer m.mutex.Unlock()
for k, v := range me.handles { for k, v := range m.handles {
if me.Decode(k) != v { if m.Decode(k) != v {
panic("handle map out of sync") panic("handle map out of sync")
} }
} }
...@@ -188,17 +188,17 @@ func NewHandleMap(portable bool) (hm HandleMap) { ...@@ -188,17 +188,17 @@ func NewHandleMap(portable bool) (hm HandleMap) {
return nil return nil
} }
func (me *int64HandleMap) Count() int { func (m *int64HandleMap) Count() int {
me.mutex.Lock() m.mutex.Lock()
defer me.mutex.Unlock() defer m.mutex.Unlock()
return len(me.handles) return len(m.handles)
} }
func (me *int64HandleMap) Register(obj *Handled, asInterface interface{}) (handle uint64) { func (m *int64HandleMap) Register(obj *Handled, asInterface interface{}) (handle uint64) {
defer me.verify() defer m.verify()
me.mutex.Lock() m.mutex.Lock()
defer me.mutex.Unlock() defer m.mutex.Unlock()
handle = uint64(uintptr(unsafe.Pointer(obj))) handle = uint64(uintptr(unsafe.Pointer(obj)))
...@@ -212,9 +212,9 @@ func (me *int64HandleMap) Register(obj *Handled, asInterface interface{}) (handl ...@@ -212,9 +212,9 @@ func (me *int64HandleMap) Register(obj *Handled, asInterface interface{}) (handl
handle -= baseAddress handle -= baseAddress
handle >>= 3 handle >>= 3
check := me.nextFree check := m.nextFree
me.nextFree++ m.nextFree++
me.nextFree = me.nextFree & (1<<(64-48+3) - 1) m.nextFree = m.nextFree & (1<<(64-48+3) - 1)
handle |= uint64(check) << (48 - 3) handle |= uint64(check) << (48 - 3)
if obj.check != 0 { if obj.check != 0 {
...@@ -223,29 +223,29 @@ func (me *int64HandleMap) Register(obj *Handled, asInterface interface{}) (handl ...@@ -223,29 +223,29 @@ func (me *int64HandleMap) Register(obj *Handled, asInterface interface{}) (handl
obj.check = check obj.check = check
obj.object = asInterface obj.object = asInterface
me.handles[handle] = obj m.handles[handle] = obj
return handle return handle
} }
func (me *int64HandleMap) Forget(handle uint64) (val *Handled) { func (m *int64HandleMap) Forget(handle uint64) (val *Handled) {
defer me.verify() defer m.verify()
val = me.Decode(handle) val = m.Decode(handle)
me.mutex.Lock() m.mutex.Lock()
defer me.mutex.Unlock() defer m.mutex.Unlock()
delete(me.handles, handle) delete(m.handles, handle)
val.check = 0 val.check = 0
return val return val
} }
func (me *int64HandleMap) Has(handle uint64) bool { func (m *int64HandleMap) Has(handle uint64) bool {
me.mutex.Lock() m.mutex.Lock()
defer me.mutex.Unlock() defer m.mutex.Unlock()
return me.handles[handle] != nil return m.handles[handle] != nil
} }
func (me *int64HandleMap) Decode(handle uint64) (val *Handled) { func (m *int64HandleMap) Decode(handle uint64) (val *Handled) {
ptrBits := uintptr(handle & (1<<45 - 1)) ptrBits := uintptr(handle & (1<<45 - 1))
check := uint32(handle >> 45) check := uint32(handle >> 45)
val = (*Handled)(unsafe.Pointer(ptrBits<<3 + uintptr(baseAddress))) val = (*Handled)(unsafe.Pointer(ptrBits<<3 + uintptr(baseAddress)))
......
...@@ -73,11 +73,11 @@ func newInode(isDir bool, fsNode FsNode) *Inode { ...@@ -73,11 +73,11 @@ func newInode(isDir bool, fsNode FsNode) *Inode {
// public methods. // public methods.
// Returns any open file, preferably a r/w one. // Returns any open file, preferably a r/w one.
func (me *Inode) AnyFile() (file File) { func (n *Inode) AnyFile() (file File) {
me.openFilesMutex.Lock() n.openFilesMutex.Lock()
defer me.openFilesMutex.Unlock() defer n.openFilesMutex.Unlock()
for _, f := range me.openFiles { for _, f := range n.openFiles {
if file == nil || f.WithFlags.OpenFlags&O_ANYWRITE != 0 { if file == nil || f.WithFlags.OpenFlags&O_ANYWRITE != 0 {
file = f.WithFlags.File file = f.WithFlags.File
} }
...@@ -85,12 +85,12 @@ func (me *Inode) AnyFile() (file File) { ...@@ -85,12 +85,12 @@ func (me *Inode) AnyFile() (file File) {
return file return file
} }
func (me *Inode) Children() (out map[string]*Inode) { func (n *Inode) Children() (out map[string]*Inode) {
me.treeLock.RLock() n.treeLock.RLock()
defer me.treeLock.RUnlock() defer n.treeLock.RUnlock()
out = map[string]*Inode{} out = map[string]*Inode{}
for k, v := range me.children { for k, v := range n.children {
out[k] = v out[k] = v
} }
return out return out
...@@ -98,29 +98,29 @@ func (me *Inode) Children() (out map[string]*Inode) { ...@@ -98,29 +98,29 @@ func (me *Inode) Children() (out map[string]*Inode) {
// FsChildren returns all the children from the same filesystem. It // FsChildren returns all the children from the same filesystem. It
// will skip mountpoints. // will skip mountpoints.
func (me *Inode) FsChildren() (out map[string]*Inode) { func (n *Inode) FsChildren() (out map[string]*Inode) {
me.treeLock.RLock() n.treeLock.RLock()
defer me.treeLock.RUnlock() defer n.treeLock.RUnlock()
out = map[string]*Inode{} out = map[string]*Inode{}
for k, v := range me.children { for k, v := range n.children {
if v.mount == me.mount { if v.mount == n.mount {
out[k] = v out[k] = v
} }
} }
return out return out
} }
func (me *Inode) FsNode() FsNode { func (n *Inode) FsNode() FsNode {
return me.fsInode return n.fsInode
} }
// Files() returns an opens file that have bits in common with the // Files() returns an opens file that have bits in common with the
// give mask. Use mask==0 to return all files. // give mask. Use mask==0 to return all files.
func (me *Inode) Files(mask uint32) (files []WithFlags) { func (n *Inode) Files(mask uint32) (files []WithFlags) {
me.openFilesMutex.Lock() n.openFilesMutex.Lock()
defer me.openFilesMutex.Unlock() defer n.openFilesMutex.Unlock()
for _, f := range me.openFiles { for _, f := range n.openFiles {
if mask == 0 || f.WithFlags.OpenFlags&mask != 0 { if mask == 0 || f.WithFlags.OpenFlags&mask != 0 {
files = append(files, f.WithFlags) files = append(files, f.WithFlags)
} }
...@@ -128,77 +128,77 @@ func (me *Inode) Files(mask uint32) (files []WithFlags) { ...@@ -128,77 +128,77 @@ func (me *Inode) Files(mask uint32) (files []WithFlags) {
return files return files
} }
func (me *Inode) IsDir() bool { func (n *Inode) IsDir() bool {
return me.children != nil return n.children != nil
} }
func (me *Inode) New(isDir bool, fsi FsNode) *Inode { func (n *Inode) New(isDir bool, fsi FsNode) *Inode {
ch := newInode(isDir, fsi) ch := newInode(isDir, fsi)
ch.mount = me.mount ch.mount = n.mount
ch.treeLock = me.treeLock ch.treeLock = n.treeLock
return ch return ch
} }
func (me *Inode) GetChild(name string) (child *Inode) { func (n *Inode) GetChild(name string) (child *Inode) {
me.treeLock.RLock() n.treeLock.RLock()
defer me.treeLock.RUnlock() defer n.treeLock.RUnlock()
return me.children[name] return n.children[name]
} }
func (me *Inode) AddChild(name string, child *Inode) { func (n *Inode) AddChild(name string, child *Inode) {
if child == nil { if child == nil {
log.Panicf("adding nil child as %q", name) log.Panicf("adding nil child as %q", name)
} }
me.treeLock.Lock() n.treeLock.Lock()
defer me.treeLock.Unlock() defer n.treeLock.Unlock()
me.addChild(name, child) n.addChild(name, child)
} }
func (me *Inode) RmChild(name string) (ch *Inode) { func (n *Inode) RmChild(name string) (ch *Inode) {
me.treeLock.Lock() n.treeLock.Lock()
defer me.treeLock.Unlock() defer n.treeLock.Unlock()
return me.rmChild(name) return n.rmChild(name)
} }
////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////
// private // private
// Must be called with treeLock for the mount held. // Must be called with treeLock for the mount held.
func (me *Inode) addChild(name string, child *Inode) { func (n *Inode) addChild(name string, child *Inode) {
if paranoia { if paranoia {
ch := me.children[name] ch := n.children[name]
if ch != nil { if ch != nil {
log.Panicf("Already have an Inode with same name: %v: %v", name, ch) log.Panicf("Already have an Inode with same name: %v: %v", name, ch)
} }
} }
me.children[name] = child n.children[name] = child
} }
// Must be called with treeLock for the mount held. // Must be called with treeLock for the mount held.
func (me *Inode) rmChild(name string) (ch *Inode) { func (n *Inode) rmChild(name string) (ch *Inode) {
ch = me.children[name] ch = n.children[name]
if ch != nil { if ch != nil {
delete(me.children, name) delete(n.children, name)
} }
return ch return ch
} }
// Can only be called on untouched inodes. // Can only be called on untouched inodes.
func (me *Inode) mountFs(fs NodeFileSystem, opts *FileSystemOptions) { func (n *Inode) mountFs(fs NodeFileSystem, opts *FileSystemOptions) {
me.mountPoint = &fileSystemMount{ n.mountPoint = &fileSystemMount{
fs: fs, fs: fs,
openFiles: NewHandleMap(false), openFiles: NewHandleMap(false),
mountInode: me, mountInode: n,
options: opts, options: opts,
} }
me.mount = me.mountPoint n.mount = n.mountPoint
me.treeLock = &me.mountPoint.treeLock n.treeLock = &n.mountPoint.treeLock
} }
// Must be called with treeLock held. // Must be called with treeLock held.
func (me *Inode) canUnmount() bool { func (n *Inode) canUnmount() bool {
for _, v := range me.children { for _, v := range n.children {
if v.mountPoint != nil { if v.mountPoint != nil {
// This access may be out of date, but it is no // This access may be out of date, but it is no
// problem to err on the safe side. // problem to err on the safe side.
...@@ -209,16 +209,16 @@ func (me *Inode) canUnmount() bool { ...@@ -209,16 +209,16 @@ func (me *Inode) canUnmount() bool {
} }
} }
me.openFilesMutex.Lock() n.openFilesMutex.Lock()
defer me.openFilesMutex.Unlock() defer n.openFilesMutex.Unlock()
return len(me.openFiles) == 0 return len(n.openFiles) == 0
} }
func (me *Inode) getMountDirEntries() (out []DirEntry) { func (n *Inode) getMountDirEntries() (out []DirEntry) {
me.treeLock.RLock() n.treeLock.RLock()
defer me.treeLock.RUnlock() defer n.treeLock.RUnlock()
for k := range me.mounts { for k := range n.mounts {
out = append(out, DirEntry{ out = append(out, DirEntry{
Name: k, Name: k,
Mode: S_IFDIR, Mode: S_IFDIR,
...@@ -229,33 +229,33 @@ func (me *Inode) getMountDirEntries() (out []DirEntry) { ...@@ -229,33 +229,33 @@ func (me *Inode) getMountDirEntries() (out []DirEntry) {
const initDirSize = 20 const initDirSize = 20
func (me *Inode) verify(cur *fileSystemMount) { func (n *Inode) verify(cur *fileSystemMount) {
if me.lookupCount < 0 { if n.lookupCount < 0 {
log.Panicf("negative lookup count %d on node %d", me.lookupCount, me.nodeId) log.Panicf("negative lookup count %d on node %d", n.lookupCount, n.nodeId)
} }
if (me.lookupCount == 0) != (me.nodeId == 0) { if (n.lookupCount == 0) != (n.nodeId == 0) {
log.Panicf("kernel registration mismatch: lookup %d id %d", me.lookupCount, me.nodeId) log.Panicf("kernel registration mismatch: lookup %d id %d", n.lookupCount, n.nodeId)
} }
if me.mountPoint != nil { if n.mountPoint != nil {
if me != me.mountPoint.mountInode { if n != n.mountPoint.mountInode {
log.Panicf("mountpoint mismatch %v %v", me, me.mountPoint.mountInode) log.Panicf("mountpoint mismatch %v %v", n, n.mountPoint.mountInode)
} }
cur = me.mountPoint cur = n.mountPoint
} }
if me.mount != cur { if n.mount != cur {
log.Panicf("me.mount not set correctly %v %v", me.mount, cur) log.Panicf("n.mount not set correctly %v %v", n.mount, cur)
} }
for name, m := range me.mounts { for name, m := range n.mounts {
if m.mountInode != me.children[name] { if m.mountInode != n.children[name] {
log.Panicf("mountpoint parent mismatch: node:%v name:%v ch:%v", log.Panicf("mountpoint parent mismatch: node:%v name:%v ch:%v",
me.mountPoint, name, me.children) n.mountPoint, name, n.children)
} }
} }
for n, ch := range me.children { for nm, ch := range n.children {
if ch == nil { if ch == nil {
log.Panicf("Found nil child: %q", n) log.Panicf("Found nil child: %q", nm)
} }
ch.verify(cur) ch.verify(cur)
} }
......
...@@ -30,43 +30,43 @@ func NewLatencyMap() *LatencyMap { ...@@ -30,43 +30,43 @@ func NewLatencyMap() *LatencyMap {
return m return m
} }
func (me *LatencyMap) AddMany(args []LatencyArg) { func (m *LatencyMap) AddMany(args []LatencyArg) {
me.Mutex.Lock() m.Mutex.Lock()
defer me.Mutex.Unlock() defer m.Mutex.Unlock()
for _, v := range args { for _, v := range args {
me.add(v.Name, v.Arg, v.DtNs) m.add(v.Name, v.Arg, v.DtNs)
} }
} }
func (me *LatencyMap) Add(name string, arg string, dtNs int64) { func (m *LatencyMap) Add(name string, arg string, dtNs int64) {
me.Mutex.Lock() m.Mutex.Lock()
defer me.Mutex.Unlock() defer m.Mutex.Unlock()
me.add(name, arg, dtNs) m.add(name, arg, dtNs)
} }
func (me *LatencyMap) add(name string, arg string, dtNs int64) { func (m *LatencyMap) add(name string, arg string, dtNs int64) {
e := me.stats[name] e := m.stats[name]
if e == nil { if e == nil {
e = new(latencyMapEntry) e = new(latencyMapEntry)
me.stats[name] = e m.stats[name] = e
} }
e.count++ e.count++
e.ns += dtNs e.ns += dtNs
if arg != "" { if arg != "" {
m, ok := me.secondaryStats[name] _, ok := m.secondaryStats[name]
if !ok { if !ok {
m = make(map[string]int64) m.secondaryStats[name] = make(map[string]int64)
me.secondaryStats[name] = m
} }
// TODO - do something with secondaryStats[name]
} }
} }
func (me *LatencyMap) Counts() map[string]int { func (m *LatencyMap) Counts() map[string]int {
me.Mutex.Lock() m.Mutex.Lock()
defer me.Mutex.Unlock() defer m.Mutex.Unlock()
r := make(map[string]int) r := make(map[string]int)
for k, v := range me.stats { for k, v := range m.stats {
r[k] = v.count r[k] = v.count
} }
return r return r
...@@ -74,24 +74,24 @@ func (me *LatencyMap) Counts() map[string]int { ...@@ -74,24 +74,24 @@ func (me *LatencyMap) Counts() map[string]int {
// Latencies returns a map. Use 1e-3 for unit to get ms // Latencies returns a map. Use 1e-3 for unit to get ms
// results. // results.
func (me *LatencyMap) Latencies(unit float64) map[string]float64 { func (m *LatencyMap) Latencies(unit float64) map[string]float64 {
me.Mutex.Lock() m.Mutex.Lock()
defer me.Mutex.Unlock() defer m.Mutex.Unlock()
r := make(map[string]float64) r := make(map[string]float64)
mult := 1 / (1e9 * unit) mult := 1 / (1e9 * unit)
for key, ent := range me.stats { for key, ent := range m.stats {
lat := mult * float64(ent.ns) / float64(ent.count) lat := mult * float64(ent.ns) / float64(ent.count)
r[key] = lat r[key] = lat
} }
return r return r
} }
func (me *LatencyMap) TopArgs(name string) []string { func (m *LatencyMap) TopArgs(name string) []string {
me.Mutex.Lock() m.Mutex.Lock()
defer me.Mutex.Unlock() defer m.Mutex.Unlock()
counts := me.secondaryStats[name] counts := m.secondaryStats[name]
results := make([]string, 0, len(counts)) results := make([]string, 0, len(counts))
for k, v := range counts { for k, v := range counts {
results = append(results, fmt.Sprintf("% 9d %s", v, k)) results = append(results, fmt.Sprintf("% 9d %s", v, k))
......
This diff is collapsed.
...@@ -32,12 +32,12 @@ func NewLoopbackFileSystem(root string) (out *LoopbackFileSystem) { ...@@ -32,12 +32,12 @@ func NewLoopbackFileSystem(root string) (out *LoopbackFileSystem) {
return out return out
} }
func (me *LoopbackFileSystem) GetPath(relPath string) string { func (fs *LoopbackFileSystem) GetPath(relPath string) string {
return filepath.Join(me.Root, relPath) return filepath.Join(fs.Root, relPath)
} }
func (me *LoopbackFileSystem) GetAttr(name string, context *Context) (a *Attr, code Status) { func (fs *LoopbackFileSystem) GetAttr(name string, context *Context) (a *Attr, code Status) {
fullPath := me.GetPath(name) fullPath := fs.GetPath(name)
var err error = nil var err error = nil
st := syscall.Stat_t{} st := syscall.Stat_t{}
if name == "" { if name == "" {
...@@ -55,10 +55,10 @@ func (me *LoopbackFileSystem) GetAttr(name string, context *Context) (a *Attr, c ...@@ -55,10 +55,10 @@ func (me *LoopbackFileSystem) GetAttr(name string, context *Context) (a *Attr, c
return a, OK return a, OK
} }
func (me *LoopbackFileSystem) OpenDir(name string, context *Context) (stream chan DirEntry, status Status) { func (fs *LoopbackFileSystem) OpenDir(name string, context *Context) (stream chan DirEntry, status Status) {
// What other ways beyond O_RDONLY are there to open // What other ways beyond O_RDONLY are there to open
// directories? // directories?
f, err := os.Open(me.GetPath(name)) f, err := os.Open(fs.GetPath(name))
if err != nil { if err != nil {
return nil, ToStatus(err) return nil, ToStatus(err)
} }
...@@ -94,99 +94,99 @@ func (me *LoopbackFileSystem) OpenDir(name string, context *Context) (stream cha ...@@ -94,99 +94,99 @@ func (me *LoopbackFileSystem) OpenDir(name string, context *Context) (stream cha
return output, OK return output, OK
} }
func (me *LoopbackFileSystem) Open(name string, flags uint32, context *Context) (fuseFile File, status Status) { func (fs *LoopbackFileSystem) Open(name string, flags uint32, context *Context) (fuseFile File, status Status) {
f, err := os.OpenFile(me.GetPath(name), int(flags), 0) f, err := os.OpenFile(fs.GetPath(name), int(flags), 0)
if err != nil { if err != nil {
return nil, ToStatus(err) return nil, ToStatus(err)
} }
return &LoopbackFile{File: f}, OK return &LoopbackFile{File: f}, OK
} }
func (me *LoopbackFileSystem) Chmod(path string, mode uint32, context *Context) (code Status) { func (fs *LoopbackFileSystem) Chmod(path string, mode uint32, context *Context) (code Status) {
err := os.Chmod(me.GetPath(path), os.FileMode(mode)) err := os.Chmod(fs.GetPath(path), os.FileMode(mode))
return ToStatus(err) return ToStatus(err)
} }
func (me *LoopbackFileSystem) Chown(path string, uid uint32, gid uint32, context *Context) (code Status) { func (fs *LoopbackFileSystem) Chown(path string, uid uint32, gid uint32, context *Context) (code Status) {
return ToStatus(os.Chown(me.GetPath(path), int(uid), int(gid))) return ToStatus(os.Chown(fs.GetPath(path), int(uid), int(gid)))
} }
func (me *LoopbackFileSystem) Truncate(path string, offset uint64, context *Context) (code Status) { func (fs *LoopbackFileSystem) Truncate(path string, offset uint64, context *Context) (code Status) {
return ToStatus(os.Truncate(me.GetPath(path), int64(offset))) return ToStatus(os.Truncate(fs.GetPath(path), int64(offset)))
} }
func (me *LoopbackFileSystem) Utimens(path string, AtimeNs int64, MtimeNs int64, context *Context) (code Status) { func (fs *LoopbackFileSystem) Utimens(path string, AtimeNs int64, MtimeNs int64, context *Context) (code Status) {
return ToStatus(os.Chtimes(me.GetPath(path), time.Unix(0, AtimeNs), time.Unix(0, MtimeNs))) return ToStatus(os.Chtimes(fs.GetPath(path), time.Unix(0, AtimeNs), time.Unix(0, MtimeNs)))
} }
func (me *LoopbackFileSystem) Readlink(name string, context *Context) (out string, code Status) { func (fs *LoopbackFileSystem) Readlink(name string, context *Context) (out string, code Status) {
f, err := os.Readlink(me.GetPath(name)) f, err := os.Readlink(fs.GetPath(name))
return f, ToStatus(err) return f, ToStatus(err)
} }
func (me *LoopbackFileSystem) Mknod(name string, mode uint32, dev uint32, context *Context) (code Status) { func (fs *LoopbackFileSystem) Mknod(name string, mode uint32, dev uint32, context *Context) (code Status) {
return ToStatus(syscall.Mknod(me.GetPath(name), mode, int(dev))) return ToStatus(syscall.Mknod(fs.GetPath(name), mode, int(dev)))
} }
func (me *LoopbackFileSystem) Mkdir(path string, mode uint32, context *Context) (code Status) { func (fs *LoopbackFileSystem) Mkdir(path string, mode uint32, context *Context) (code Status) {
return ToStatus(os.Mkdir(me.GetPath(path), os.FileMode(mode))) return ToStatus(os.Mkdir(fs.GetPath(path), os.FileMode(mode)))
} }
// Don't use os.Remove, it removes twice (unlink followed by rmdir). // Don't use os.Remove, it removes twice (unlink followed by rmdir).
func (me *LoopbackFileSystem) Unlink(name string, context *Context) (code Status) { func (fs *LoopbackFileSystem) Unlink(name string, context *Context) (code Status) {
return ToStatus(syscall.Unlink(me.GetPath(name))) return ToStatus(syscall.Unlink(fs.GetPath(name)))
} }
func (me *LoopbackFileSystem) Rmdir(name string, context *Context) (code Status) { func (fs *LoopbackFileSystem) Rmdir(name string, context *Context) (code Status) {
return ToStatus(syscall.Rmdir(me.GetPath(name))) return ToStatus(syscall.Rmdir(fs.GetPath(name)))
} }
func (me *LoopbackFileSystem) Symlink(pointedTo string, linkName string, context *Context) (code Status) { func (fs *LoopbackFileSystem) Symlink(pointedTo string, linkName string, context *Context) (code Status) {
return ToStatus(os.Symlink(pointedTo, me.GetPath(linkName))) return ToStatus(os.Symlink(pointedTo, fs.GetPath(linkName)))
} }
func (me *LoopbackFileSystem) Rename(oldPath string, newPath string, context *Context) (code Status) { func (fs *LoopbackFileSystem) Rename(oldPath string, newPath string, context *Context) (code Status) {
err := os.Rename(me.GetPath(oldPath), me.GetPath(newPath)) err := os.Rename(fs.GetPath(oldPath), fs.GetPath(newPath))
return ToStatus(err) return ToStatus(err)
} }
func (me *LoopbackFileSystem) Link(orig string, newName string, context *Context) (code Status) { func (fs *LoopbackFileSystem) Link(orig string, newName string, context *Context) (code Status) {
return ToStatus(os.Link(me.GetPath(orig), me.GetPath(newName))) return ToStatus(os.Link(fs.GetPath(orig), fs.GetPath(newName)))
} }
func (me *LoopbackFileSystem) Access(name string, mode uint32, context *Context) (code Status) { func (fs *LoopbackFileSystem) Access(name string, mode uint32, context *Context) (code Status) {
return ToStatus(syscall.Access(me.GetPath(name), mode)) return ToStatus(syscall.Access(fs.GetPath(name), mode))
} }
func (me *LoopbackFileSystem) Create(path string, flags uint32, mode uint32, context *Context) (fuseFile File, code Status) { func (fs *LoopbackFileSystem) Create(path string, flags uint32, mode uint32, context *Context) (fuseFile File, code Status) {
f, err := os.OpenFile(me.GetPath(path), int(flags)|os.O_CREATE, os.FileMode(mode)) f, err := os.OpenFile(fs.GetPath(path), int(flags)|os.O_CREATE, os.FileMode(mode))
return &LoopbackFile{File: f}, ToStatus(err) return &LoopbackFile{File: f}, ToStatus(err)
} }
func (me *LoopbackFileSystem) GetXAttr(name string, attr string, context *Context) ([]byte, Status) { func (fs *LoopbackFileSystem) GetXAttr(name string, attr string, context *Context) ([]byte, Status) {
data := make([]byte, 1024) data := make([]byte, 1024)
data, errNo := GetXAttr(me.GetPath(name), attr, data) data, errNo := GetXAttr(fs.GetPath(name), attr, data)
return data, Status(errNo) return data, Status(errNo)
} }
func (me *LoopbackFileSystem) ListXAttr(name string, context *Context) ([]string, Status) { func (fs *LoopbackFileSystem) ListXAttr(name string, context *Context) ([]string, Status) {
data, errNo := ListXAttr(me.GetPath(name)) data, errNo := ListXAttr(fs.GetPath(name))
return data, Status(errNo) return data, Status(errNo)
} }
func (me *LoopbackFileSystem) RemoveXAttr(name string, attr string, context *Context) Status { func (fs *LoopbackFileSystem) RemoveXAttr(name string, attr string, context *Context) Status {
return Status(Removexattr(me.GetPath(name), attr)) return Status(Removexattr(fs.GetPath(name), attr))
} }
func (me *LoopbackFileSystem) String() string { func (fs *LoopbackFileSystem) String() string {
return fmt.Sprintf("LoopbackFileSystem(%s)", me.Root) return fmt.Sprintf("LoopbackFileSystem(%s)", fs.Root)
} }
func (me *LoopbackFileSystem) StatFs(name string) *StatfsOut { func (fs *LoopbackFileSystem) StatFs(name string) *StatfsOut {
s := syscall.Statfs_t{} s := syscall.Statfs_t{}
err := syscall.Statfs(me.GetPath(name), &s) err := syscall.Statfs(fs.GetPath(name), &s)
if err == nil { if err == nil {
return &StatfsOut{ return &StatfsOut{
raw.Kstatfs{ raw.Kstatfs{
......
This diff is collapsed.
...@@ -19,25 +19,25 @@ type MemNodeFs struct { ...@@ -19,25 +19,25 @@ type MemNodeFs struct {
nextFree int nextFree int
} }
func (me *MemNodeFs) String() string { func (fs *MemNodeFs) String() string {
return fmt.Sprintf("MemNodeFs(%s)", me.backingStorePrefix) return fmt.Sprintf("MemNodeFs(%s)", fs.backingStorePrefix)
} }
func (me *MemNodeFs) Root() FsNode { func (fs *MemNodeFs) Root() FsNode {
return me.root return fs.root
} }
func (me *MemNodeFs) newNode() *memNode { func (fs *MemNodeFs) newNode() *memNode {
me.mutex.Lock() fs.mutex.Lock()
defer me.mutex.Unlock() defer fs.mutex.Unlock()
n := &memNode{ n := &memNode{
fs: me, fs: fs,
id: me.nextFree, id: fs.nextFree,
} }
now := time.Now().UnixNano() now := time.Now().UnixNano()
n.info.SetNs(now, now, now) n.info.SetNs(now, now, now)
n.info.Mode = S_IFDIR | 0777 n.info.Mode = S_IFDIR | 0777
me.nextFree++ fs.nextFree++
return n return n
} }
...@@ -48,7 +48,7 @@ func NewMemNodeFs(prefix string) *MemNodeFs { ...@@ -48,7 +48,7 @@ func NewMemNodeFs(prefix string) *MemNodeFs {
return me return me
} }
func (me *MemNodeFs) Filename(n *Inode) string { func (fs *MemNodeFs) Filename(n *Inode) string {
mn := n.FsNode().(*memNode) mn := n.FsNode().(*memNode)
return mn.filename() return mn.filename()
} }
...@@ -62,75 +62,75 @@ type memNode struct { ...@@ -62,75 +62,75 @@ type memNode struct {
info Attr info Attr
} }
func (me *memNode) newNode(isdir bool) *memNode { func (n *memNode) newNode(isdir bool) *memNode {
n := me.fs.newNode() newNode := n.fs.newNode()
me.Inode().New(isdir, n) n.Inode().New(isdir, newNode)
return n return newNode
} }
func (me *memNode) filename() string { func (n *memNode) filename() string {
return fmt.Sprintf("%s%d", me.fs.backingStorePrefix, me.id) return fmt.Sprintf("%s%d", n.fs.backingStorePrefix, n.id)
} }
func (me *memNode) Deletable() bool { func (n *memNode) Deletable() bool {
return false return false
} }
func (me *memNode) Readlink(c *Context) ([]byte, Status) { func (n *memNode) Readlink(c *Context) ([]byte, Status) {
return []byte(me.link), OK return []byte(n.link), OK
} }
func (me *memNode) Mkdir(name string, mode uint32, context *Context) (fi *Attr, newNode FsNode, code Status) { func (n *memNode) Mkdir(name string, mode uint32, context *Context) (fi *Attr, newNode FsNode, code Status) {
n := me.newNode(true) ch := n.newNode(true)
n.info.Mode = mode | S_IFDIR ch.info.Mode = mode | S_IFDIR
me.Inode().AddChild(name, n.Inode()) n.Inode().AddChild(name, ch.Inode())
return &n.info, n, OK return &ch.info, ch, OK
} }
func (me *memNode) Unlink(name string, context *Context) (code Status) { func (n *memNode) Unlink(name string, context *Context) (code Status) {
ch := me.Inode().RmChild(name) ch := n.Inode().RmChild(name)
if ch == nil { if ch == nil {
return ENOENT return ENOENT
} }
return OK return OK
} }
func (me *memNode) Rmdir(name string, context *Context) (code Status) { func (n *memNode) Rmdir(name string, context *Context) (code Status) {
return me.Unlink(name, context) return n.Unlink(name, context)
} }
func (me *memNode) Symlink(name string, content string, context *Context) (fi *Attr, newNode FsNode, code Status) { func (n *memNode) Symlink(name string, content string, context *Context) (fi *Attr, newNode FsNode, code Status) {
n := me.newNode(false) ch := n.newNode(false)
n.info.Mode = S_IFLNK | 0777 ch.info.Mode = S_IFLNK | 0777
n.link = content ch.link = content
me.Inode().AddChild(name, n.Inode()) n.Inode().AddChild(name, ch.Inode())
return &n.info, n, OK return &ch.info, ch, OK
} }
func (me *memNode) Rename(oldName string, newParent FsNode, newName string, context *Context) (code Status) { func (n *memNode) Rename(oldName string, newParent FsNode, newName string, context *Context) (code Status) {
ch := me.Inode().RmChild(oldName) ch := n.Inode().RmChild(oldName)
newParent.Inode().RmChild(newName) newParent.Inode().RmChild(newName)
newParent.Inode().AddChild(newName, ch) newParent.Inode().AddChild(newName, ch)
return OK return OK
} }
func (me *memNode) Link(name string, existing FsNode, context *Context) (fi *Attr, newNode FsNode, code Status) { func (n *memNode) Link(name string, existing FsNode, context *Context) (fi *Attr, newNode FsNode, code Status) {
me.Inode().AddChild(name, existing.Inode()) n.Inode().AddChild(name, existing.Inode())
fi, code = existing.GetAttr(nil, context) fi, code = existing.GetAttr(nil, context)
return fi, existing, code return fi, existing, code
} }
func (me *memNode) Create(name string, flags uint32, mode uint32, context *Context) (file File, fi *Attr, newNode FsNode, code Status) { func (n *memNode) Create(name string, flags uint32, mode uint32, context *Context) (file File, fi *Attr, newNode FsNode, code Status) {
n := me.newNode(false) ch := n.newNode(false)
n.info.Mode = mode | S_IFREG ch.info.Mode = mode | S_IFREG
f, err := os.Create(n.filename()) f, err := os.Create(n.filename())
if err != nil { if err != nil {
return nil, nil, nil, ToStatus(err) return nil, nil, nil, ToStatus(err)
} }
me.Inode().AddChild(name, n.Inode()) n.Inode().AddChild(name, ch.Inode())
return n.newFile(f), &n.info, n, OK return ch.newFile(f), &ch.info, ch, OK
} }
type memNodeFile struct { type memNodeFile struct {
...@@ -138,71 +138,71 @@ type memNodeFile struct { ...@@ -138,71 +138,71 @@ type memNodeFile struct {
node *memNode node *memNode
} }
func (me *memNodeFile) String() string { func (n *memNodeFile) String() string {
return fmt.Sprintf("memNodeFile(%s)", me.LoopbackFile.String()) return fmt.Sprintf("memNodeFile(%s)", n.LoopbackFile.String())
} }
func (me *memNodeFile) InnerFile() File { func (n *memNodeFile) InnerFile() File {
return &me.LoopbackFile return &n.LoopbackFile
} }
func (me *memNodeFile) Flush() Status { func (n *memNodeFile) Flush() Status {
code := me.LoopbackFile.Flush() code := n.LoopbackFile.Flush()
fi, _ := me.LoopbackFile.GetAttr() fi, _ := n.LoopbackFile.GetAttr()
me.node.info.Size = fi.Size n.node.info.Size = fi.Size
me.node.info.Blocks = fi.Blocks n.node.info.Blocks = fi.Blocks
return code return code
} }
func (me *memNode) newFile(f *os.File) File { func (n *memNode) newFile(f *os.File) File {
return &memNodeFile{ return &memNodeFile{
LoopbackFile: LoopbackFile{File: f}, LoopbackFile: LoopbackFile{File: f},
node: me, node: n,
} }
} }
func (me *memNode) Open(flags uint32, context *Context) (file File, code Status) { func (n *memNode) Open(flags uint32, context *Context) (file File, code Status) {
f, err := os.OpenFile(me.filename(), int(flags), 0666) f, err := os.OpenFile(n.filename(), int(flags), 0666)
if err != nil { if err != nil {
return nil, ToStatus(err) return nil, ToStatus(err)
} }
return me.newFile(f), OK return n.newFile(f), OK
} }
func (me *memNode) GetAttr(file File, context *Context) (fi *Attr, code Status) { func (n *memNode) GetAttr(file File, context *Context) (fi *Attr, code Status) {
return &me.info, OK return &n.info, OK
} }
func (me *memNode) Truncate(file File, size uint64, context *Context) (code Status) { func (n *memNode) Truncate(file File, size uint64, context *Context) (code Status) {
if file != nil { if file != nil {
code = file.Truncate(size) code = file.Truncate(size)
} else { } else {
err := os.Truncate(me.filename(), int64(size)) err := os.Truncate(n.filename(), int64(size))
code = ToStatus(err) code = ToStatus(err)
} }
if code.Ok() { if code.Ok() {
me.info.SetNs(-1, -1, time.Now().UnixNano()) n.info.SetNs(-1, -1, time.Now().UnixNano())
// TODO - should update mtime too? // TODO - should update mtime too?
me.info.Size = size n.info.Size = size
} }
return code return code
} }
func (me *memNode) Utimens(file File, atime int64, mtime int64, context *Context) (code Status) { func (n *memNode) Utimens(file File, atime int64, mtime int64, context *Context) (code Status) {
me.info.SetNs(int64(atime), int64(mtime), time.Now().UnixNano()) n.info.SetNs(int64(atime), int64(mtime), time.Now().UnixNano())
return OK return OK
} }
func (me *memNode) Chmod(file File, perms uint32, context *Context) (code Status) { func (n *memNode) Chmod(file File, perms uint32, context *Context) (code Status) {
me.info.Mode = (me.info.Mode ^ 07777) | perms n.info.Mode = (n.info.Mode ^ 07777) | perms
me.info.SetNs(-1, -1, time.Now().UnixNano()) n.info.SetNs(-1, -1, time.Now().UnixNano())
return OK return OK
} }
func (me *memNode) Chown(file File, uid uint32, gid uint32, context *Context) (code Status) { func (n *memNode) Chown(file File, uid uint32, gid uint32, context *Context) (code Status) {
me.info.Uid = uid n.info.Uid = uid
me.info.Gid = gid n.info.Gid = gid
me.info.SetNs(-1, -1, time.Now().UnixNano()) n.info.SetNs(-1, -1, time.Now().UnixNano())
return OK return OK
} }
...@@ -37,16 +37,16 @@ type MountState struct { ...@@ -37,16 +37,16 @@ type MountState struct {
kernelSettings raw.InitIn kernelSettings raw.InitIn
} }
func (me *MountState) KernelSettings() raw.InitIn { func (ms *MountState) KernelSettings() raw.InitIn {
return me.kernelSettings return ms.kernelSettings
} }
func (me *MountState) MountPoint() string { func (ms *MountState) MountPoint() string {
return me.mountPoint return ms.mountPoint
} }
// Mount filesystem on mountPoint. // Mount filesystem on mountPoint.
func (me *MountState) Mount(mountPoint string, opts *MountOptions) error { func (ms *MountState) Mount(mountPoint string, opts *MountOptions) error {
if opts == nil { if opts == nil {
opts = &MountOptions{ opts = &MountOptions{
MaxBackground: _DEFAULT_BACKGROUND_TASKS, MaxBackground: _DEFAULT_BACKGROUND_TASKS,
...@@ -63,7 +63,7 @@ func (me *MountState) Mount(mountPoint string, opts *MountOptions) error { ...@@ -63,7 +63,7 @@ func (me *MountState) Mount(mountPoint string, opts *MountOptions) error {
o.MaxWrite = MAX_KERNEL_WRITE o.MaxWrite = MAX_KERNEL_WRITE
} }
opts = &o opts = &o
me.opts = &o ms.opts = &o
optStrs := opts.Options optStrs := opts.Options
if opts.AllowOther { if opts.AllowOther {
...@@ -76,33 +76,33 @@ func (me *MountState) Mount(mountPoint string, opts *MountOptions) error { ...@@ -76,33 +76,33 @@ func (me *MountState) Mount(mountPoint string, opts *MountOptions) error {
} }
initParams := RawFsInit{ initParams := RawFsInit{
InodeNotify: func(n *raw.NotifyInvalInodeOut) Status { InodeNotify: func(n *raw.NotifyInvalInodeOut) Status {
return me.writeInodeNotify(n) return ms.writeInodeNotify(n)
}, },
EntryNotify: func(parent uint64, n string) Status { EntryNotify: func(parent uint64, n string) Status {
return me.writeEntryNotify(parent, n) return ms.writeEntryNotify(parent, n)
}, },
} }
me.fileSystem.Init(&initParams) ms.fileSystem.Init(&initParams)
me.mountPoint = mp ms.mountPoint = mp
me.mountFile = file ms.mountFile = file
return nil return nil
} }
func (me *MountState) SetRecordStatistics(record bool) { func (ms *MountState) SetRecordStatistics(record bool) {
if record { if record {
me.latencies = NewLatencyMap() ms.latencies = NewLatencyMap()
} else { } else {
me.latencies = nil ms.latencies = nil
} }
} }
func (me *MountState) Unmount() (err error) { func (ms *MountState) Unmount() (err error) {
if me.mountPoint == "" { if ms.mountPoint == "" {
return nil return nil
} }
delay := time.Duration(0) delay := time.Duration(0)
for try := 0; try < 5; try++ { for try := 0; try < 5; try++ {
err = unmount(me.mountPoint) err = unmount(ms.mountPoint)
if err == nil { if err == nil {
break break
} }
...@@ -113,50 +113,50 @@ func (me *MountState) Unmount() (err error) { ...@@ -113,50 +113,50 @@ func (me *MountState) Unmount() (err error) {
delay = 2*delay + 5*time.Millisecond delay = 2*delay + 5*time.Millisecond
time.Sleep(delay) time.Sleep(delay)
} }
me.mountPoint = "" ms.mountPoint = ""
return err return err
} }
func NewMountState(fs RawFileSystem) *MountState { func NewMountState(fs RawFileSystem) *MountState {
me := new(MountState) ms := new(MountState)
me.mountPoint = "" ms.mountPoint = ""
me.fileSystem = fs ms.fileSystem = fs
me.buffers = NewBufferPool() ms.buffers = NewBufferPool()
return me return ms
} }
func (me *MountState) Latencies() map[string]float64 { func (ms *MountState) Latencies() map[string]float64 {
if me.latencies == nil { if ms.latencies == nil {
return nil return nil
} }
return me.latencies.Latencies(1e-3) return ms.latencies.Latencies(1e-3)
} }
func (me *MountState) OperationCounts() map[string]int { func (ms *MountState) OperationCounts() map[string]int {
if me.latencies == nil { if ms.latencies == nil {
return nil return nil
} }
return me.latencies.Counts() return ms.latencies.Counts()
} }
func (me *MountState) BufferPoolStats() string { func (ms *MountState) BufferPoolStats() string {
return me.buffers.String() return ms.buffers.String()
} }
func (me *MountState) newRequest() *request { func (ms *MountState) newRequest() *request {
r := &request{ r := &request{
pool: me.buffers, pool: ms.buffers,
} }
return r return r
} }
func (me *MountState) recordStats(req *request) { func (ms *MountState) recordStats(req *request) {
if me.latencies != nil { if ms.latencies != nil {
endNs := time.Now().UnixNano() endNs := time.Now().UnixNano()
dt := endNs - req.startNs dt := endNs - req.startNs
opname := operationName(req.inHeader.Opcode) opname := operationName(req.inHeader.Opcode)
me.latencies.AddMany( ms.latencies.AddMany(
[]LatencyArg{ []LatencyArg{
{opname, "", dt}, {opname, "", dt},
{opname + "-write", "", endNs - req.preWriteNs}}) {opname + "-write", "", endNs - req.preWriteNs}})
...@@ -168,20 +168,20 @@ func (me *MountState) recordStats(req *request) { ...@@ -168,20 +168,20 @@ func (me *MountState) recordStats(req *request) {
// goroutine. // goroutine.
// //
// Each filesystem operation executes in a separate goroutine. // Each filesystem operation executes in a separate goroutine.
func (me *MountState) Loop() { func (ms *MountState) Loop() {
me.loop() ms.loop()
me.mountFile.Close() ms.mountFile.Close()
me.mountFile = nil ms.mountFile = nil
} }
func (me *MountState) loop() { func (ms *MountState) loop() {
var dest []byte var dest []byte
for { for {
if dest == nil { if dest == nil {
dest = me.buffers.AllocBuffer(uint32(me.opts.MaxWrite + 4096)) dest = ms.buffers.AllocBuffer(uint32(ms.opts.MaxWrite + 4096))
} }
n, err := me.mountFile.Read(dest) n, err := ms.mountFile.Read(dest)
if err != nil { if err != nil {
errNo := ToStatus(err) errNo := ToStatus(err)
...@@ -199,8 +199,8 @@ func (me *MountState) loop() { ...@@ -199,8 +199,8 @@ func (me *MountState) loop() {
break break
} }
req := me.newRequest() req := ms.newRequest()
if me.latencies != nil { if ms.latencies != nil {
req.startNs = time.Now().UnixNano() req.startNs = time.Now().UnixNano()
} }
if req.setInput(dest[:n]) { if req.setInput(dest[:n]) {
...@@ -213,21 +213,21 @@ func (me *MountState) loop() { ...@@ -213,21 +213,21 @@ func (me *MountState) loop() {
// which will lock up the FS if the daemon has too // which will lock up the FS if the daemon has too
// many blocking calls. // many blocking calls.
go func(r *request) { go func(r *request) {
me.handleRequest(r) ms.handleRequest(r)
r.Discard() r.Discard()
}(req) }(req)
} }
} }
func (me *MountState) handleRequest(req *request) { func (ms *MountState) handleRequest(req *request) {
defer me.recordStats(req) defer ms.recordStats(req)
req.parse() req.parse()
if req.handler == nil { if req.handler == nil {
req.status = ENOSYS req.status = ENOSYS
} }
if req.status.Ok() && me.Debug { if req.status.Ok() && ms.Debug {
log.Println(req.InputDebug()) log.Println(req.InputDebug())
} }
...@@ -237,28 +237,28 @@ func (me *MountState) handleRequest(req *request) { ...@@ -237,28 +237,28 @@ func (me *MountState) handleRequest(req *request) {
} }
if req.status.Ok() { if req.status.Ok() {
req.handler.Func(me, req) req.handler.Func(ms, req)
} }
errNo := me.write(req) errNo := ms.write(req)
if errNo != 0 { if errNo != 0 {
log.Printf("writer: Write/Writev %v failed, err: %v. opcode: %v", log.Printf("writer: Write/Writev %v failed, err: %v. opcode: %v",
req.outHeaderBytes, errNo, operationName(req.inHeader.Opcode)) req.outHeaderBytes, errNo, operationName(req.inHeader.Opcode))
} }
} }
func (me *MountState) write(req *request) Status { func (ms *MountState) write(req *request) Status {
// Forget does not wait for reply. // Forget does not wait for reply.
if req.inHeader.Opcode == _OP_FORGET || req.inHeader.Opcode == _OP_BATCH_FORGET { if req.inHeader.Opcode == _OP_FORGET || req.inHeader.Opcode == _OP_BATCH_FORGET {
return OK return OK
} }
req.serialize() req.serialize()
if me.Debug { if ms.Debug {
log.Println(req.OutputDebug()) log.Println(req.OutputDebug())
} }
if me.latencies != nil { if ms.latencies != nil {
req.preWriteNs = time.Now().UnixNano() req.preWriteNs = time.Now().UnixNano()
} }
...@@ -268,16 +268,16 @@ func (me *MountState) write(req *request) Status { ...@@ -268,16 +268,16 @@ func (me *MountState) write(req *request) Status {
var err error var err error
if req.flatData == nil { if req.flatData == nil {
_, err = me.mountFile.Write(req.outHeaderBytes) _, err = ms.mountFile.Write(req.outHeaderBytes)
} else { } else {
_, err = Writev(int(me.mountFile.Fd()), _, err = Writev(int(ms.mountFile.Fd()),
[][]byte{req.outHeaderBytes, req.flatData}) [][]byte{req.outHeaderBytes, req.flatData})
} }
return ToStatus(err) return ToStatus(err)
} }
func (me *MountState) writeInodeNotify(entry *raw.NotifyInvalInodeOut) Status { func (ms *MountState) writeInodeNotify(entry *raw.NotifyInvalInodeOut) Status {
req := request{ req := request{
inHeader: &raw.InHeader{ inHeader: &raw.InHeader{
Opcode: _OP_NOTIFY_INODE, Opcode: _OP_NOTIFY_INODE,
...@@ -287,15 +287,15 @@ func (me *MountState) writeInodeNotify(entry *raw.NotifyInvalInodeOut) Status { ...@@ -287,15 +287,15 @@ func (me *MountState) writeInodeNotify(entry *raw.NotifyInvalInodeOut) Status {
} }
req.outData = unsafe.Pointer(entry) req.outData = unsafe.Pointer(entry)
req.serialize() req.serialize()
result := me.write(&req) result := ms.write(&req)
if me.Debug { if ms.Debug {
log.Println("Response: INODE_NOTIFY", result) log.Println("Response: INODE_NOTIFY", result)
} }
return result return result
} }
func (me *MountState) writeEntryNotify(parent uint64, name string) Status { func (ms *MountState) writeEntryNotify(parent uint64, name string) Status {
req := request{ req := request{
inHeader: &raw.InHeader{ inHeader: &raw.InHeader{
Opcode: _OP_NOTIFY_ENTRY, Opcode: _OP_NOTIFY_ENTRY,
...@@ -314,9 +314,9 @@ func (me *MountState) writeEntryNotify(parent uint64, name string) Status { ...@@ -314,9 +314,9 @@ func (me *MountState) writeEntryNotify(parent uint64, name string) Status {
req.outData = unsafe.Pointer(entry) req.outData = unsafe.Pointer(entry)
req.flatData = nameBytes req.flatData = nameBytes
req.serialize() req.serialize()
result := me.write(&req) result := ms.write(&req)
if me.Debug { if ms.Debug {
log.Printf("Response: ENTRY_NOTIFY: %v", result) log.Printf("Response: ENTRY_NOTIFY: %v", result)
} }
return result return result
......
...@@ -16,12 +16,12 @@ type NotifyFs struct { ...@@ -16,12 +16,12 @@ type NotifyFs struct {
exist bool exist bool
} }
func (me *NotifyFs) GetAttr(name string, context *Context) (*Attr, Status) { func (fs *NotifyFs) GetAttr(name string, context *Context) (*Attr, Status) {
if name == "" { if name == "" {
return &Attr{Mode: S_IFDIR | 0755}, OK return &Attr{Mode: S_IFDIR | 0755}, OK
} }
if name == "file" || (name == "dir/file" && me.exist) { if name == "file" || (name == "dir/file" && fs.exist) {
return &Attr{Mode: S_IFREG | 0644, Size: me.size}, OK return &Attr{Mode: S_IFREG | 0644, Size: fs.size}, OK
} }
if name == "dir" { if name == "dir" {
return &Attr{Mode: S_IFDIR | 0755}, OK return &Attr{Mode: S_IFDIR | 0755}, OK
...@@ -29,7 +29,7 @@ func (me *NotifyFs) GetAttr(name string, context *Context) (*Attr, Status) { ...@@ -29,7 +29,7 @@ func (me *NotifyFs) GetAttr(name string, context *Context) (*Attr, Status) {
return nil, ENOENT return nil, ENOENT
} }
func (me *NotifyFs) Open(name string, f uint32, context *Context) (File, Status) { func (fs *NotifyFs) Open(name string, f uint32, context *Context) (File, Status) {
return NewDataFile([]byte{42}), OK return NewDataFile([]byte{42}), OK
} }
...@@ -63,10 +63,10 @@ func NewNotifyTest() *NotifyTest { ...@@ -63,10 +63,10 @@ func NewNotifyTest() *NotifyTest {
return me return me
} }
func (me *NotifyTest) Clean() { func (t *NotifyTest) Clean() {
err := me.state.Unmount() err := t.state.Unmount()
if err == nil { if err == nil {
os.RemoveAll(me.dir) os.RemoveAll(t.dir)
} }
} }
......
...@@ -13,7 +13,7 @@ type ownerFs struct { ...@@ -13,7 +13,7 @@ type ownerFs struct {
const _RANDOM_OWNER = 31415265 const _RANDOM_OWNER = 31415265
func (me *ownerFs) GetAttr(name string, context *Context) (*Attr, Status) { func (fs *ownerFs) GetAttr(name string, context *Context) (*Attr, Status) {
if name == "" { if name == "" {
return &Attr{ return &Attr{
Mode: S_IFDIR | 0755, Mode: S_IFDIR | 0755,
......
This diff is collapsed.
...@@ -11,102 +11,102 @@ type PrefixFileSystem struct { ...@@ -11,102 +11,102 @@ type PrefixFileSystem struct {
Prefix string Prefix string
} }
func (me *PrefixFileSystem) prefixed(n string) string { func (fs *PrefixFileSystem) prefixed(n string) string {
return filepath.Join(me.Prefix, n) return filepath.Join(fs.Prefix, n)
} }
func (me *PrefixFileSystem) GetAttr(name string, context *Context) (*Attr, Status) { func (fs *PrefixFileSystem) GetAttr(name string, context *Context) (*Attr, Status) {
return me.FileSystem.GetAttr(me.prefixed(name), context) return fs.FileSystem.GetAttr(fs.prefixed(name), context)
} }
func (me *PrefixFileSystem) Readlink(name string, context *Context) (string, Status) { func (fs *PrefixFileSystem) Readlink(name string, context *Context) (string, Status) {
return me.FileSystem.Readlink(me.prefixed(name), context) return fs.FileSystem.Readlink(fs.prefixed(name), context)
} }
func (me *PrefixFileSystem) Mknod(name string, mode uint32, dev uint32, context *Context) Status { func (fs *PrefixFileSystem) Mknod(name string, mode uint32, dev uint32, context *Context) Status {
return me.FileSystem.Mknod(me.prefixed(name), mode, dev, context) return fs.FileSystem.Mknod(fs.prefixed(name), mode, dev, context)
} }
func (me *PrefixFileSystem) Mkdir(name string, mode uint32, context *Context) Status { func (fs *PrefixFileSystem) Mkdir(name string, mode uint32, context *Context) Status {
return me.FileSystem.Mkdir(me.prefixed(name), mode, context) return fs.FileSystem.Mkdir(fs.prefixed(name), mode, context)
} }
func (me *PrefixFileSystem) Unlink(name string, context *Context) (code Status) { func (fs *PrefixFileSystem) Unlink(name string, context *Context) (code Status) {
return me.FileSystem.Unlink(me.prefixed(name), context) return fs.FileSystem.Unlink(fs.prefixed(name), context)
} }
func (me *PrefixFileSystem) Rmdir(name string, context *Context) (code Status) { func (fs *PrefixFileSystem) Rmdir(name string, context *Context) (code Status) {
return me.FileSystem.Rmdir(me.prefixed(name), context) return fs.FileSystem.Rmdir(fs.prefixed(name), context)
} }
func (me *PrefixFileSystem) Symlink(value string, linkName string, context *Context) (code Status) { func (fs *PrefixFileSystem) Symlink(value string, linkName string, context *Context) (code Status) {
return me.FileSystem.Symlink(value, me.prefixed(linkName), context) return fs.FileSystem.Symlink(value, fs.prefixed(linkName), context)
} }
func (me *PrefixFileSystem) Rename(oldName string, newName string, context *Context) (code Status) { func (fs *PrefixFileSystem) Rename(oldName string, newName string, context *Context) (code Status) {
return me.FileSystem.Rename(me.prefixed(oldName), me.prefixed(newName), context) return fs.FileSystem.Rename(fs.prefixed(oldName), fs.prefixed(newName), context)
} }
func (me *PrefixFileSystem) Link(oldName string, newName string, context *Context) (code Status) { func (fs *PrefixFileSystem) Link(oldName string, newName string, context *Context) (code Status) {
return me.FileSystem.Link(me.prefixed(oldName), me.prefixed(newName), context) return fs.FileSystem.Link(fs.prefixed(oldName), fs.prefixed(newName), context)
} }
func (me *PrefixFileSystem) Chmod(name string, mode uint32, context *Context) (code Status) { func (fs *PrefixFileSystem) Chmod(name string, mode uint32, context *Context) (code Status) {
return me.FileSystem.Chmod(me.prefixed(name), mode, context) return fs.FileSystem.Chmod(fs.prefixed(name), mode, context)
} }
func (me *PrefixFileSystem) Chown(name string, uid uint32, gid uint32, context *Context) (code Status) { func (fs *PrefixFileSystem) Chown(name string, uid uint32, gid uint32, context *Context) (code Status) {
return me.FileSystem.Chown(me.prefixed(name), uid, gid, context) return fs.FileSystem.Chown(fs.prefixed(name), uid, gid, context)
} }
func (me *PrefixFileSystem) Truncate(name string, offset uint64, context *Context) (code Status) { func (fs *PrefixFileSystem) Truncate(name string, offset uint64, context *Context) (code Status) {
return me.FileSystem.Truncate(me.prefixed(name), offset, context) return fs.FileSystem.Truncate(fs.prefixed(name), offset, context)
} }
func (me *PrefixFileSystem) Open(name string, flags uint32, context *Context) (file File, code Status) { func (fs *PrefixFileSystem) Open(name string, flags uint32, context *Context) (file File, code Status) {
return me.FileSystem.Open(me.prefixed(name), flags, context) return fs.FileSystem.Open(fs.prefixed(name), flags, context)
} }
func (me *PrefixFileSystem) OpenDir(name string, context *Context) (stream chan DirEntry, status Status) { func (fs *PrefixFileSystem) OpenDir(name string, context *Context) (stream chan DirEntry, status Status) {
return me.FileSystem.OpenDir(me.prefixed(name), context) return fs.FileSystem.OpenDir(fs.prefixed(name), context)
} }
func (me *PrefixFileSystem) OnMount(nodeFs *PathNodeFs) { func (fs *PrefixFileSystem) OnMount(nodeFs *PathNodeFs) {
me.FileSystem.OnMount(nodeFs) fs.FileSystem.OnMount(nodeFs)
} }
func (me *PrefixFileSystem) OnUnmount() { func (fs *PrefixFileSystem) OnUnmount() {
me.FileSystem.OnUnmount() fs.FileSystem.OnUnmount()
} }
func (me *PrefixFileSystem) Access(name string, mode uint32, context *Context) (code Status) { func (fs *PrefixFileSystem) Access(name string, mode uint32, context *Context) (code Status) {
return me.FileSystem.Access(me.prefixed(name), mode, context) return fs.FileSystem.Access(fs.prefixed(name), mode, context)
} }
func (me *PrefixFileSystem) Create(name string, flags uint32, mode uint32, context *Context) (file File, code Status) { func (fs *PrefixFileSystem) Create(name string, flags uint32, mode uint32, context *Context) (file File, code Status) {
return me.FileSystem.Create(me.prefixed(name), flags, mode, context) return fs.FileSystem.Create(fs.prefixed(name), flags, mode, context)
} }
func (me *PrefixFileSystem) Utimens(name string, AtimeNs int64, CtimeNs int64, context *Context) (code Status) { func (fs *PrefixFileSystem) Utimens(name string, AtimeNs int64, CtimeNs int64, context *Context) (code Status) {
return me.FileSystem.Utimens(me.prefixed(name), AtimeNs, CtimeNs, context) return fs.FileSystem.Utimens(fs.prefixed(name), AtimeNs, CtimeNs, context)
} }
func (me *PrefixFileSystem) GetXAttr(name string, attr string, context *Context) ([]byte, Status) { func (fs *PrefixFileSystem) GetXAttr(name string, attr string, context *Context) ([]byte, Status) {
return me.FileSystem.GetXAttr(me.prefixed(name), attr, context) return fs.FileSystem.GetXAttr(fs.prefixed(name), attr, context)
} }
func (me *PrefixFileSystem) SetXAttr(name string, attr string, data []byte, flags int, context *Context) Status { func (fs *PrefixFileSystem) SetXAttr(name string, attr string, data []byte, flags int, context *Context) Status {
return me.FileSystem.SetXAttr(me.prefixed(name), attr, data, flags, context) return fs.FileSystem.SetXAttr(fs.prefixed(name), attr, data, flags, context)
} }
func (me *PrefixFileSystem) ListXAttr(name string, context *Context) ([]string, Status) { func (fs *PrefixFileSystem) ListXAttr(name string, context *Context) ([]string, Status) {
return me.FileSystem.ListXAttr(me.prefixed(name), context) return fs.FileSystem.ListXAttr(fs.prefixed(name), context)
} }
func (me *PrefixFileSystem) RemoveXAttr(name string, attr string, context *Context) Status { func (fs *PrefixFileSystem) RemoveXAttr(name string, attr string, context *Context) Status {
return me.FileSystem.RemoveXAttr(me.prefixed(name), attr, context) return fs.FileSystem.RemoveXAttr(fs.prefixed(name), attr, context)
} }
func (me *PrefixFileSystem) String() string { func (fs *PrefixFileSystem) String() string {
return fmt.Sprintf("PrefixFileSystem(%s,%s)", me.FileSystem.String(), me.Prefix) return fmt.Sprintf("PrefixFileSystem(%s,%s)", fs.FileSystem.String(), fs.Prefix)
} }
This diff is collapsed.
This diff is collapsed.
...@@ -18,7 +18,7 @@ func init() { ...@@ -18,7 +18,7 @@ func init() {
} }
} }
func (me *Attr) String() string { func (a *Attr) String() string {
return fmt.Sprintf( return fmt.Sprintf(
"{M0%o S=%d L=%d "+ "{M0%o S=%d L=%d "+
"%d:%d "+ "%d:%d "+
...@@ -26,11 +26,11 @@ func (me *Attr) String() string { ...@@ -26,11 +26,11 @@ func (me *Attr) String() string {
"A %d.%09d "+ "A %d.%09d "+
"M %d.%09d "+ "M %d.%09d "+
"C %d.%09d}", "C %d.%09d}",
me.Mode, me.Size, me.Nlink, a.Mode, a.Size, a.Nlink,
me.Uid, me.Gid, a.Uid, a.Gid,
me.Blocks, me.Blksize, a.Blocks, a.Blksize,
me.Rdev, me.Ino, me.Atime, me.Atimensec, me.Mtime, me.Mtimensec, a.Rdev, a.Ino, a.Atime, a.Atimensec, a.Mtime, a.Mtimensec,
me.Ctime, me.Ctimensec) a.Ctime, a.Ctimensec)
} }
func (me *ReadIn) String() string { func (me *ReadIn) String() string {
......
This diff is collapsed.
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