Commit 6267f14d authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

nodefs: rename File => FileHandle

Suggestion by Kirill Smelkov.
parent ac4ae29a
...@@ -84,6 +84,15 @@ type Operations interface { ...@@ -84,6 +84,15 @@ type Operations interface {
inode() *Inode inode() *Inode
setInode(*Inode) setInode(*Inode)
// File locking
GetLk(ctx context.Context, f FileHandle, owner uint64, lk *fuse.FileLock, flags uint32, out *fuse.FileLock) (code fuse.Status)
SetLk(ctx context.Context, f FileHandle, owner uint64, lk *fuse.FileLock, flags uint32) (code fuse.Status)
SetLkw(ctx context.Context, f FileHandle, owner uint64, lk *fuse.FileLock, flags uint32) (code fuse.Status)
// The methods below may be called on closed files, due to
// concurrency. In that case, you should return EBADF.
GetAttr(ctx context.Context, f FileHandle, out *fuse.AttrOut) fuse.Status
// Lookup should find a direct child of the node by child name. // Lookup should find a direct child of the node by child name.
// //
// VFS makes sure to call Lookup only once for particular (node, name) // VFS makes sure to call Lookup only once for particular (node, name)
...@@ -95,36 +104,26 @@ type Operations interface { ...@@ -95,36 +104,26 @@ type Operations interface {
Rmdir(ctx context.Context, name string) fuse.Status Rmdir(ctx context.Context, name string) fuse.Status
Unlink(ctx context.Context, name string) fuse.Status Unlink(ctx context.Context, name string) fuse.Status
Rename(ctx context.Context, name string, newParent Operations, newName string, flags uint32) fuse.Status Rename(ctx context.Context, name string, newParent Operations, newName string, flags uint32) fuse.Status
Create(ctx context.Context, name string, flags uint32, mode uint32) (node *Inode, fh FileHandle, fuseFlags uint32, code fuse.Status)
Open(ctx context.Context, flags uint32) (fh File, fuseFlags uint32, code fuse.Status) Open(ctx context.Context, flags uint32) (fh FileHandle, fuseFlags uint32, code fuse.Status)
Create(ctx context.Context, name string, flags uint32, mode uint32) (node *Inode, fh File, fuseFlags uint32, code fuse.Status)
Read(ctx context.Context, f File, dest []byte, off int64) (fuse.ReadResult, fuse.Status) Read(ctx context.Context, f FileHandle, dest []byte, off int64) (fuse.ReadResult, fuse.Status)
Write(ctx context.Context, f File, data []byte, off int64) (written uint32, code fuse.Status) Write(ctx context.Context, f FileHandle, data []byte, off int64) (written uint32, code fuse.Status)
Fsync(ctx context.Context, f File, flags uint32) (code fuse.Status) Fsync(ctx context.Context, f FileHandle, flags uint32) (code fuse.Status)
// File locking
GetLk(ctx context.Context, f File, owner uint64, lk *fuse.FileLock, flags uint32, out *fuse.FileLock) (code fuse.Status)
SetLk(ctx context.Context, f File, owner uint64, lk *fuse.FileLock, flags uint32) (code fuse.Status)
SetLkw(ctx context.Context, f File, owner uint64, lk *fuse.FileLock, flags uint32) (code fuse.Status)
// Flush is called for close() call on a file descriptor. In // Flush is called for close() call on a file descriptor. In
// case of duplicated descriptor, it may be called more than // case of duplicated descriptor, it may be called more than
// once for a file. // once for a file.
Flush(ctx context.Context, f File) fuse.Status Flush(ctx context.Context, f FileHandle) fuse.Status
// This is called to before the file handle is forgotten. This // This is called to before the file handle is forgotten. This
// method has no return value, so nothing can synchronizes on // method has no return value, so nothing can synchronizes on
// the call. Any cleanup that requires specific synchronization or // the call. Any cleanup that requires specific synchronization or
// could fail with I/O errors should happen in Flush instead. // could fail with I/O errors should happen in Flush instead.
Release(ctx context.Context, f File) Release(ctx context.Context, f FileHandle)
// The methods below may be called on closed files, due to
// concurrency. In that case, you should return EBADF.
GetAttr(ctx context.Context, f File, out *fuse.AttrOut) fuse.Status
/* /*
NOSUBMIT - fold into a setattr method, or expand methods? NOSUBMIT - fold into a setattr method, or expand methods?
...@@ -133,14 +132,14 @@ type Operations interface { ...@@ -133,14 +132,14 @@ type Operations interface {
types as args, we can't take apart SetAttr for the caller types as args, we can't take apart SetAttr for the caller
*/ */
Truncate(ctx context.Context, f File, size uint64) fuse.Status Truncate(ctx context.Context, f FileHandle, size uint64) fuse.Status
Chown(ctx context.Context, f File, uid uint32, gid uint32) fuse.Status Chown(ctx context.Context, f FileHandle, uid uint32, gid uint32) fuse.Status
Chmod(ctx context.Context, f File, perms uint32) fuse.Status Chmod(ctx context.Context, f FileHandle, perms uint32) fuse.Status
Utimens(ctx context.Context, f File, atime *time.Time, mtime *time.Time) fuse.Status Utimens(ctx context.Context, f FileHandle, atime *time.Time, mtime *time.Time) fuse.Status
Allocate(ctx context.Context, f File, off uint64, size uint64, mode uint32) (code fuse.Status) Allocate(ctx context.Context, f FileHandle, off uint64, size uint64, mode uint32) (code fuse.Status)
} }
type File interface { type FileHandle interface {
Read(ctx context.Context, dest []byte, off int64) (fuse.ReadResult, fuse.Status) Read(ctx context.Context, dest []byte, off int64) (fuse.ReadResult, fuse.Status)
Write(ctx context.Context, data []byte, off int64) (written uint32, code fuse.Status) Write(ctx context.Context, data []byte, off int64) (written uint32, code fuse.Status)
......
...@@ -15,7 +15,7 @@ import ( ...@@ -15,7 +15,7 @@ import (
) )
type fileEntry struct { type fileEntry struct {
file File file FileHandle
// space to hold directory stuff // space to hold directory stuff
} }
...@@ -197,7 +197,7 @@ func (b *rawBridge) Mknod(input *fuse.MknodIn, name string, out *fuse.EntryOut) ...@@ -197,7 +197,7 @@ func (b *rawBridge) Mknod(input *fuse.MknodIn, name string, out *fuse.EntryOut)
} }
// addNewChild inserts the child into the tree. Returns file handle if file != nil. // addNewChild inserts the child into the tree. Returns file handle if file != nil.
func (b *rawBridge) addNewChild(parent *Inode, name string, child *Inode, file File, out *fuse.EntryOut) uint64 { func (b *rawBridge) addNewChild(parent *Inode, name string, child *Inode, file FileHandle, out *fuse.EntryOut) uint64 {
lockNodes(parent, child) lockNodes(parent, child)
parent.setEntry(name, child) parent.setEntry(name, child)
b.mu.Lock() b.mu.Lock()
...@@ -423,7 +423,7 @@ func (b *rawBridge) Open(input *fuse.OpenIn, out *fuse.OpenOut) (status fuse.Sta ...@@ -423,7 +423,7 @@ func (b *rawBridge) Open(input *fuse.OpenIn, out *fuse.OpenOut) (status fuse.Sta
} }
// registerFile hands out a file handle. Must have bridge.mu // registerFile hands out a file handle. Must have bridge.mu
func (b *rawBridge) registerFile(f File) uint64 { func (b *rawBridge) registerFile(f FileHandle) uint64 {
var fh uint64 var fh uint64
if len(b.freeFiles) > 0 { if len(b.freeFiles) > 0 {
last := uint64(len(b.freeFiles) - 1) last := uint64(len(b.freeFiles) - 1)
......
...@@ -50,21 +50,21 @@ func (n *DefaultOperations) Rename(ctx context.Context, name string, newParent O ...@@ -50,21 +50,21 @@ func (n *DefaultOperations) Rename(ctx context.Context, name string, newParent O
return fuse.ENOSYS return fuse.ENOSYS
} }
func (n *DefaultOperations) Read(ctx context.Context, f File, dest []byte, off int64) (fuse.ReadResult, fuse.Status) { func (n *DefaultOperations) Read(ctx context.Context, f FileHandle, dest []byte, off int64) (fuse.ReadResult, fuse.Status) {
if f != nil { if f != nil {
return f.Read(ctx, dest, off) return f.Read(ctx, dest, off)
} }
return nil, fuse.ENOSYS return nil, fuse.ENOSYS
} }
func (n *DefaultOperations) Fsync(ctx context.Context, f File, flags uint32) fuse.Status { func (n *DefaultOperations) Fsync(ctx context.Context, f FileHandle, flags uint32) fuse.Status {
if f != nil { if f != nil {
return f.Fsync(ctx, flags) return f.Fsync(ctx, flags)
} }
return fuse.ENOSYS return fuse.ENOSYS
} }
func (n *DefaultOperations) Write(ctx context.Context, f File, data []byte, off int64) (written uint32, code fuse.Status) { func (n *DefaultOperations) Write(ctx context.Context, f FileHandle, data []byte, off int64) (written uint32, code fuse.Status) {
if f != nil { if f != nil {
return f.Write(ctx, data, off) return f.Write(ctx, data, off)
} }
...@@ -72,7 +72,7 @@ func (n *DefaultOperations) Write(ctx context.Context, f File, data []byte, off ...@@ -72,7 +72,7 @@ func (n *DefaultOperations) Write(ctx context.Context, f File, data []byte, off
return 0, fuse.ENOSYS return 0, fuse.ENOSYS
} }
func (n *DefaultOperations) GetLk(ctx context.Context, f File, owner uint64, lk *fuse.FileLock, flags uint32, out *fuse.FileLock) (code fuse.Status) { func (n *DefaultOperations) GetLk(ctx context.Context, f FileHandle, owner uint64, lk *fuse.FileLock, flags uint32, out *fuse.FileLock) (code fuse.Status) {
if f != nil { if f != nil {
return f.GetLk(ctx, owner, lk, flags, out) return f.GetLk(ctx, owner, lk, flags, out)
} }
...@@ -80,7 +80,7 @@ func (n *DefaultOperations) GetLk(ctx context.Context, f File, owner uint64, lk ...@@ -80,7 +80,7 @@ func (n *DefaultOperations) GetLk(ctx context.Context, f File, owner uint64, lk
return fuse.ENOSYS return fuse.ENOSYS
} }
func (n *DefaultOperations) SetLk(ctx context.Context, f File, owner uint64, lk *fuse.FileLock, flags uint32) (code fuse.Status) { func (n *DefaultOperations) SetLk(ctx context.Context, f FileHandle, owner uint64, lk *fuse.FileLock, flags uint32) (code fuse.Status) {
if f != nil { if f != nil {
return f.SetLk(ctx, owner, lk, flags) return f.SetLk(ctx, owner, lk, flags)
} }
...@@ -88,14 +88,14 @@ func (n *DefaultOperations) SetLk(ctx context.Context, f File, owner uint64, lk ...@@ -88,14 +88,14 @@ func (n *DefaultOperations) SetLk(ctx context.Context, f File, owner uint64, lk
return fuse.ENOSYS return fuse.ENOSYS
} }
func (n *DefaultOperations) SetLkw(ctx context.Context, f File, owner uint64, lk *fuse.FileLock, flags uint32) (code fuse.Status) { func (n *DefaultOperations) SetLkw(ctx context.Context, f FileHandle, owner uint64, lk *fuse.FileLock, flags uint32) (code fuse.Status) {
if f != nil { if f != nil {
return f.SetLkw(ctx, owner, lk, flags) return f.SetLkw(ctx, owner, lk, flags)
} }
return fuse.ENOSYS return fuse.ENOSYS
} }
func (n *DefaultOperations) Flush(ctx context.Context, f File) fuse.Status { func (n *DefaultOperations) Flush(ctx context.Context, f FileHandle) fuse.Status {
if f != nil { if f != nil {
return f.Flush(ctx) return f.Flush(ctx)
} }
...@@ -103,13 +103,13 @@ func (n *DefaultOperations) Flush(ctx context.Context, f File) fuse.Status { ...@@ -103,13 +103,13 @@ func (n *DefaultOperations) Flush(ctx context.Context, f File) fuse.Status {
return fuse.ENOSYS return fuse.ENOSYS
} }
func (n *DefaultOperations) Release(ctx context.Context, f File) { func (n *DefaultOperations) Release(ctx context.Context, f FileHandle) {
if f != nil { if f != nil {
f.Release(ctx) f.Release(ctx)
} }
} }
func (n *DefaultOperations) Allocate(ctx context.Context, f File, off uint64, size uint64, mode uint32) (code fuse.Status) { func (n *DefaultOperations) Allocate(ctx context.Context, f FileHandle, off uint64, size uint64, mode uint32) (code fuse.Status) {
if f != nil { if f != nil {
return f.Allocate(ctx, off, size, mode) return f.Allocate(ctx, off, size, mode)
} }
...@@ -117,7 +117,7 @@ func (n *DefaultOperations) Allocate(ctx context.Context, f File, off uint64, si ...@@ -117,7 +117,7 @@ func (n *DefaultOperations) Allocate(ctx context.Context, f File, off uint64, si
return fuse.ENOSYS return fuse.ENOSYS
} }
func (n *DefaultOperations) GetAttr(ctx context.Context, f File, out *fuse.AttrOut) fuse.Status { func (n *DefaultOperations) GetAttr(ctx context.Context, f FileHandle, out *fuse.AttrOut) fuse.Status {
if f != nil { if f != nil {
f.GetAttr(ctx, out) f.GetAttr(ctx, out)
} }
...@@ -125,7 +125,7 @@ func (n *DefaultOperations) GetAttr(ctx context.Context, f File, out *fuse.AttrO ...@@ -125,7 +125,7 @@ func (n *DefaultOperations) GetAttr(ctx context.Context, f File, out *fuse.AttrO
return fuse.ENOSYS return fuse.ENOSYS
} }
func (n *DefaultOperations) Truncate(ctx context.Context, f File, size uint64) fuse.Status { func (n *DefaultOperations) Truncate(ctx context.Context, f FileHandle, size uint64) fuse.Status {
if f != nil { if f != nil {
return f.Truncate(ctx, size) return f.Truncate(ctx, size)
} }
...@@ -133,7 +133,7 @@ func (n *DefaultOperations) Truncate(ctx context.Context, f File, size uint64) f ...@@ -133,7 +133,7 @@ func (n *DefaultOperations) Truncate(ctx context.Context, f File, size uint64) f
return fuse.ENOSYS return fuse.ENOSYS
} }
func (n *DefaultOperations) Chown(ctx context.Context, f File, uid uint32, gid uint32) fuse.Status { func (n *DefaultOperations) Chown(ctx context.Context, f FileHandle, uid uint32, gid uint32) fuse.Status {
if f != nil { if f != nil {
return f.Chown(ctx, uid, gid) return f.Chown(ctx, uid, gid)
} }
...@@ -141,7 +141,7 @@ func (n *DefaultOperations) Chown(ctx context.Context, f File, uid uint32, gid u ...@@ -141,7 +141,7 @@ func (n *DefaultOperations) Chown(ctx context.Context, f File, uid uint32, gid u
return fuse.ENOSYS return fuse.ENOSYS
} }
func (n *DefaultOperations) Chmod(ctx context.Context, f File, perms uint32) fuse.Status { func (n *DefaultOperations) Chmod(ctx context.Context, f FileHandle, perms uint32) fuse.Status {
if f != nil { if f != nil {
return f.Chmod(ctx, perms) return f.Chmod(ctx, perms)
} }
...@@ -149,7 +149,7 @@ func (n *DefaultOperations) Chmod(ctx context.Context, f File, perms uint32) fus ...@@ -149,7 +149,7 @@ func (n *DefaultOperations) Chmod(ctx context.Context, f File, perms uint32) fus
return fuse.ENOSYS return fuse.ENOSYS
} }
func (n *DefaultOperations) Utimens(ctx context.Context, f File, atime *time.Time, mtime *time.Time) fuse.Status { func (n *DefaultOperations) Utimens(ctx context.Context, f FileHandle, atime *time.Time, mtime *time.Time) fuse.Status {
if f != nil { if f != nil {
return f.Utimens(ctx, atime, mtime) return f.Utimens(ctx, atime, mtime)
} }
...@@ -157,18 +157,18 @@ func (n *DefaultOperations) Utimens(ctx context.Context, f File, atime *time.Tim ...@@ -157,18 +157,18 @@ func (n *DefaultOperations) Utimens(ctx context.Context, f File, atime *time.Tim
return fuse.ENOSYS return fuse.ENOSYS
} }
func (n *DefaultOperations) Open(ctx context.Context, flags uint32) (fh File, fuseFlags uint32, code fuse.Status) { func (n *DefaultOperations) Open(ctx context.Context, flags uint32) (fh FileHandle, fuseFlags uint32, code fuse.Status) {
return nil, 0, fuse.ENOSYS return nil, 0, fuse.ENOSYS
} }
func (n *DefaultOperations) Create(ctx context.Context, name string, flags uint32, mode uint32) (node *Inode, fh File, fuseFlags uint32, code fuse.Status) { func (n *DefaultOperations) Create(ctx context.Context, name string, flags uint32, mode uint32) (node *Inode, fh FileHandle, fuseFlags uint32, code fuse.Status) {
return nil, nil, 0, fuse.ENOSYS return nil, nil, 0, fuse.ENOSYS
} }
type DefaultFile struct { type DefaultFile struct {
} }
var _ = File((*DefaultFile)(nil)) var _ = FileHandle((*DefaultFile)(nil))
func (f *DefaultFile) Read(ctx context.Context, dest []byte, off int64) (fuse.ReadResult, fuse.Status) { func (f *DefaultFile) Read(ctx context.Context, dest []byte, off int64) (fuse.ReadResult, fuse.Status) {
return nil, fuse.ENOSYS return nil, fuse.ENOSYS
......
...@@ -43,7 +43,7 @@ func (r *interruptRoot) Lookup(ctx context.Context, name string, out *fuse.Entry ...@@ -43,7 +43,7 @@ func (r *interruptRoot) Lookup(ctx context.Context, name string, out *fuse.Entry
return ch, fuse.OK return ch, fuse.OK
} }
func (o *interruptOps) GetAttr(ctx context.Context, f File, out *fuse.AttrOut) fuse.Status { func (o *interruptOps) GetAttr(ctx context.Context, f FileHandle, out *fuse.AttrOut) fuse.Status {
out.Mode = fuse.S_IFREG | 0644 out.Mode = fuse.S_IFREG | 0644
out.Size = uint64(len(o.Data)) out.Size = uint64(len(o.Data))
return fuse.OK return fuse.OK
...@@ -57,11 +57,11 @@ func (f *interruptFile) Flush(ctx context.Context) fuse.Status { ...@@ -57,11 +57,11 @@ func (f *interruptFile) Flush(ctx context.Context) fuse.Status {
return fuse.OK return fuse.OK
} }
func (o *interruptOps) Open(ctx context.Context, flags uint32) (File, uint32, fuse.Status) { func (o *interruptOps) Open(ctx context.Context, flags uint32) (FileHandle, uint32, fuse.Status) {
return &interruptFile{}, 0, fuse.OK return &interruptFile{}, 0, fuse.OK
} }
func (o *interruptOps) Read(ctx context.Context, f File, dest []byte, off int64) (fuse.ReadResult, fuse.Status) { func (o *interruptOps) Read(ctx context.Context, f FileHandle, dest []byte, off int64) (fuse.ReadResult, fuse.Status) {
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
end := int(off) + len(dest) end := int(off) + len(dest)
if end > len(o.Data) { if end > len(o.Data) {
......
...@@ -27,7 +27,7 @@ func (n *loopbackRoot) newLoopbackNode() *loopbackNode { ...@@ -27,7 +27,7 @@ func (n *loopbackRoot) newLoopbackNode() *loopbackNode {
} }
} }
func (n *loopbackRoot) GetAttr(ctx context.Context, f File, out *fuse.AttrOut) fuse.Status { func (n *loopbackRoot) GetAttr(ctx context.Context, f FileHandle, out *fuse.AttrOut) fuse.Status {
var err error = nil var err error = nil
st := syscall.Stat_t{} st := syscall.Stat_t{}
err = syscall.Stat(n.root, &st) err = syscall.Stat(n.root, &st)
...@@ -47,7 +47,7 @@ type loopbackNode struct { ...@@ -47,7 +47,7 @@ type loopbackNode struct {
openFiles map[*loopbackFile]struct{} openFiles map[*loopbackFile]struct{}
} }
func (n *loopbackNode) Release(ctx context.Context, f File) { func (n *loopbackNode) Release(ctx context.Context, f FileHandle) {
if f != nil { if f != nil {
n.mu.Lock() n.mu.Lock()
defer n.mu.Unlock() defer n.mu.Unlock()
...@@ -158,7 +158,7 @@ func idFromStat(st *syscall.Stat_t) FileID { ...@@ -158,7 +158,7 @@ func idFromStat(st *syscall.Stat_t) FileID {
} }
} }
func (n *loopbackNode) Create(ctx context.Context, name string, flags uint32, mode uint32) (inode *Inode, fh File, fuseFlags uint32, code fuse.Status) { func (n *loopbackNode) Create(ctx context.Context, name string, flags uint32, mode uint32) (inode *Inode, fh FileHandle, fuseFlags uint32, code fuse.Status) {
p := filepath.Join(n.path(), name) p := filepath.Join(n.path(), name)
f, err := os.OpenFile(p, int(flags)|os.O_CREATE, os.FileMode(mode)) f, err := os.OpenFile(p, int(flags)|os.O_CREATE, os.FileMode(mode))
...@@ -181,7 +181,7 @@ func (n *loopbackNode) Create(ctx context.Context, name string, flags uint32, mo ...@@ -181,7 +181,7 @@ func (n *loopbackNode) Create(ctx context.Context, name string, flags uint32, mo
return ch, lf, 0, fuse.OK return ch, lf, 0, fuse.OK
} }
func (n *loopbackNode) Open(ctx context.Context, flags uint32) (fh File, fuseFlags uint32, code fuse.Status) { func (n *loopbackNode) Open(ctx context.Context, flags uint32) (fh FileHandle, fuseFlags uint32, code fuse.Status) {
p := n.path() p := n.path()
f, err := os.OpenFile(p, int(flags), 0) f, err := os.OpenFile(p, int(flags), 0)
if err != nil { if err != nil {
...@@ -205,7 +205,7 @@ func (n *loopbackNode) fGetAttr(ctx context.Context, out *fuse.AttrOut) (fuse.St ...@@ -205,7 +205,7 @@ func (n *loopbackNode) fGetAttr(ctx context.Context, out *fuse.AttrOut) (fuse.St
return fuse.EBADF, false return fuse.EBADF, false
} }
func (n *loopbackNode) GetAttr(ctx context.Context, f File, out *fuse.AttrOut) fuse.Status { func (n *loopbackNode) GetAttr(ctx context.Context, f FileHandle, out *fuse.AttrOut) fuse.Status {
if f != nil { if f != nil {
// this never happens because the kernel never sends FH on getattr. // this never happens because the kernel never sends FH on getattr.
return f.GetAttr(ctx, out) return f.GetAttr(ctx, out)
......
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