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