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