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

In debug, print filename for file operations too.

parent b3dbf510
...@@ -189,14 +189,15 @@ type FileSystemConnector struct { ...@@ -189,14 +189,15 @@ type FileSystemConnector struct {
rootNode *inode rootNode *inode
// Open files/directories. // Open files/directories.
openFiles map[uint64]*interfaceBridge openFiles map[uint64]*fileBridge
// Protects openFiles and OpenCount in all of the nodes. // Protects openFiles and OpenCount in all of the nodes.
fileLock sync.RWMutex fileLock sync.RWMutex
} }
type interfaceBridge struct { type fileBridge struct {
*mountData *mountData
*inode
Iface interface{} Iface interface{}
} }
...@@ -229,8 +230,9 @@ func (me *FileSystemConnector) registerFile(node *inode, mount *mountData, f int ...@@ -229,8 +230,9 @@ func (me *FileSystemConnector) registerFile(node *inode, mount *mountData, f int
me.fileLock.Lock() me.fileLock.Lock()
defer me.fileLock.Unlock() defer me.fileLock.Unlock()
b := &interfaceBridge{ b := &fileBridge{
Iface: f, Iface: f,
inode: node,
mountData: mount, mountData: mount,
} }
h := uint64(uintptr(unsafe.Pointer(b))) h := uint64(uintptr(unsafe.Pointer(b)))
...@@ -244,9 +246,9 @@ func (me *FileSystemConnector) registerFile(node *inode, mount *mountData, f int ...@@ -244,9 +246,9 @@ func (me *FileSystemConnector) registerFile(node *inode, mount *mountData, f int
return h return h
} }
func (me *FileSystemConnector) decodeFileHandle(h uint64) (interface{}, *mountData) { func (me *FileSystemConnector) decodeFileHandle(h uint64) (interface{}, *mountData, *inode) {
b := (*interfaceBridge)(unsafe.Pointer(uintptr(h))) b := (*fileBridge)(unsafe.Pointer(uintptr(h)))
return b.Iface, b.mountData return b.Iface, b.mountData, b.inode
} }
type rawDir interface { type rawDir interface {
...@@ -254,14 +256,14 @@ type rawDir interface { ...@@ -254,14 +256,14 @@ type rawDir interface {
Release() Release()
} }
func (me *FileSystemConnector) getDir(h uint64) (rawDir, *mountData) { func (me *FileSystemConnector) getDir(h uint64) (rawDir, *mountData, *inode) {
f, m := me.decodeFileHandle(h) f, m, n := me.decodeFileHandle(h)
return f.(rawDir), m return f.(rawDir), m, n
} }
func (me *FileSystemConnector) getFile(h uint64) (File, *mountData) { func (me *FileSystemConnector) getFile(h uint64) (File, *mountData, *inode) {
f, m := me.decodeFileHandle(h) f, m, n := me.decodeFileHandle(h)
return f.(File), m return f.(File), m, n
} }
func (me *FileSystemConnector) verify() { func (me *FileSystemConnector) verify() {
...@@ -409,7 +411,7 @@ func (me *FileSystemConnector) findInode(fullPath string) *inode { ...@@ -409,7 +411,7 @@ func (me *FileSystemConnector) findInode(fullPath string) *inode {
func EmptyFileSystemConnector() (out *FileSystemConnector) { func EmptyFileSystemConnector() (out *FileSystemConnector) {
out = new(FileSystemConnector) out = new(FileSystemConnector)
out.inodeMap = make(map[uint64]*inode) out.inodeMap = make(map[uint64]*inode)
out.openFiles = make(map[uint64]*interfaceBridge) out.openFiles = make(map[uint64]*fileBridge)
rootData := out.newInode(true, true) rootData := out.newInode(true, true)
rootData.Children = make(map[string]*inode, initDirSize) rootData.Children = make(map[string]*inode, initDirSize)
...@@ -524,7 +526,7 @@ func (me *FileSystemConnector) GetPath(nodeid uint64) (path string, mount *mount ...@@ -524,7 +526,7 @@ func (me *FileSystemConnector) GetPath(nodeid uint64) (path string, mount *mount
func (me *FileSystemConnector) getOpenFileData(nodeid uint64, fh uint64) (f File, m *mountData, p string) { func (me *FileSystemConnector) getOpenFileData(nodeid uint64, fh uint64) (f File, m *mountData, p string) {
if fh != 0 { if fh != 0 {
f, m = me.getFile(fh) f, m, _ = me.getFile(fh)
} }
me.treeLock.RLock() me.treeLock.RLock()
defer me.treeLock.RUnlock() defer me.treeLock.RUnlock()
......
...@@ -5,6 +5,7 @@ package fuse ...@@ -5,6 +5,7 @@ package fuse
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"log"
"path/filepath" "path/filepath"
"time" "time"
) )
...@@ -75,7 +76,7 @@ func (me *FileSystemConnector) Forget(h *InHeader, input *ForgetIn) { ...@@ -75,7 +76,7 @@ func (me *FileSystemConnector) Forget(h *InHeader, input *ForgetIn) {
func (me *FileSystemConnector) GetAttr(header *InHeader, input *GetAttrIn) (out *AttrOut, code Status) { func (me *FileSystemConnector) GetAttr(header *InHeader, input *GetAttrIn) (out *AttrOut, code Status) {
if input.Flags&FUSE_GETATTR_FH != 0 { if input.Flags&FUSE_GETATTR_FH != 0 {
f, mount := me.getFile(input.Fh) f, mount, _ := me.getFile(input.Fh)
attr, err := f.GetAttr() attr, err := f.GetAttr()
if err != OK && err != ENOSYS { if err != OK && err != ENOSYS {
return nil, err return nil, err
...@@ -131,7 +132,7 @@ func (me *FileSystemConnector) OpenDir(header *InHeader, input *OpenIn) (flags u ...@@ -131,7 +132,7 @@ func (me *FileSystemConnector) OpenDir(header *InHeader, input *OpenIn) (flags u
} }
func (me *FileSystemConnector) ReadDir(header *InHeader, input *ReadIn) (*DirEntryList, Status) { func (me *FileSystemConnector) ReadDir(header *InHeader, input *ReadIn) (*DirEntryList, Status) {
d, _ := me.getDir(input.Fh) d, _, _ := me.getDir(input.Fh)
de, code := d.ReadDir(input) de, code := d.ReadDir(input)
if code != OK { if code != OK {
return nil, code return nil, code
...@@ -156,7 +157,6 @@ func (me *FileSystemConnector) Open(header *InHeader, input *OpenIn) (flags uint ...@@ -156,7 +157,6 @@ func (me *FileSystemConnector) Open(header *InHeader, input *OpenIn) (flags uint
} }
func (me *FileSystemConnector) SetAttr(header *InHeader, input *SetAttrIn) (out *AttrOut, code Status) { func (me *FileSystemConnector) SetAttr(header *InHeader, input *SetAttrIn) (out *AttrOut, code Status) {
var err Status = OK var err Status = OK
var getAttrIn GetAttrIn var getAttrIn GetAttrIn
fh := uint64(0) fh := uint64(0)
...@@ -455,18 +455,32 @@ func (me *FileSystemConnector) ListXAttr(header *InHeader) (data []byte, code St ...@@ -455,18 +455,32 @@ func (me *FileSystemConnector) ListXAttr(header *InHeader) (data []byte, code St
return b.Bytes(), code return b.Bytes(), code
} }
func (me *FileSystemConnector) fileDebug(fh uint64, n *inode) {
p, _, _ := me.GetPath(n.NodeId)
log.Printf("Fh %d = %s", fh, p)
}
func (me *FileSystemConnector) Write(input *WriteIn, data []byte) (written uint32, code Status) { func (me *FileSystemConnector) Write(input *WriteIn, data []byte) (written uint32, code Status) {
f, _ := me.getFile(input.Fh) f, _, n := me.getFile(input.Fh)
if me.Debug {
me.fileDebug(input.Fh, n)
}
return f.Write(input, data) return f.Write(input, data)
} }
func (me *FileSystemConnector) Read(input *ReadIn, bp *BufferPool) ([]byte, Status) { func (me *FileSystemConnector) Read(input *ReadIn, bp *BufferPool) ([]byte, Status) {
f, _ := me.getFile(input.Fh) f, _, n := me.getFile(input.Fh)
if me.Debug {
me.fileDebug(input.Fh, n)
}
return f.Read(input, bp) return f.Read(input, bp)
} }
func (me *FileSystemConnector) Ioctl(header *InHeader, input *IoctlIn) (out *IoctlOut, data []byte, code Status) { func (me *FileSystemConnector) Ioctl(header *InHeader, input *IoctlIn) (out *IoctlOut, data []byte, code Status) {
f, _ := me.getFile(input.Fh) f, _, n := me.getFile(input.Fh)
if me.Debug {
me.fileDebug(input.Fh, n)
}
return f.Ioctl(input) return f.Ioctl(input)
} }
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