Commit 4df83d57 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

fs: reorganize code

Change-Id: I91a375cc2956b2ead0ad3a4a5b2a0c66a4c327e2
parent e0a0b09a
...@@ -422,13 +422,12 @@ func (b *rawBridge) Unlink(cancel <-chan struct{}, header *fuse.InHeader, name s ...@@ -422,13 +422,12 @@ func (b *rawBridge) Unlink(cancel <-chan struct{}, header *fuse.InHeader, name s
func (b *rawBridge) Mkdir(cancel <-chan struct{}, input *fuse.MkdirIn, name string, out *fuse.EntryOut) fuse.Status { func (b *rawBridge) Mkdir(cancel <-chan struct{}, input *fuse.MkdirIn, name string, out *fuse.EntryOut) fuse.Status {
parent, _ := b.inode(input.NodeId, 0) parent, _ := b.inode(input.NodeId, 0)
var child *Inode ctx := &fuse.Context{Caller: input.Caller, Cancel: cancel}
var errno syscall.Errno mops, ok := parent.ops.(NodeMkdirer)
if mops, ok := parent.ops.(NodeMkdirer); ok { if !ok {
child, errno = mops.Mkdir(&fuse.Context{Caller: input.Caller, Cancel: cancel}, name, input.Mode, out)
} else {
return fuse.ENOTSUP return fuse.ENOTSUP
} }
child, errno := mops.Mkdir(ctx, name, input.Mode, out)
if errno != 0 { if errno != 0 {
return errnoToStatus(errno) return errnoToStatus(errno)
...@@ -451,14 +450,12 @@ func (b *rawBridge) Mkdir(cancel <-chan struct{}, input *fuse.MkdirIn, name stri ...@@ -451,14 +450,12 @@ func (b *rawBridge) Mkdir(cancel <-chan struct{}, input *fuse.MkdirIn, name stri
func (b *rawBridge) Mknod(cancel <-chan struct{}, input *fuse.MknodIn, name string, out *fuse.EntryOut) fuse.Status { func (b *rawBridge) Mknod(cancel <-chan struct{}, input *fuse.MknodIn, name string, out *fuse.EntryOut) fuse.Status {
parent, _ := b.inode(input.NodeId, 0) parent, _ := b.inode(input.NodeId, 0)
var child *Inode mops, ok := parent.ops.(NodeMknoder)
var errno syscall.Errno if !ok {
if mops, ok := parent.ops.(NodeMknoder); ok {
child, errno = mops.Mknod(&fuse.Context{Caller: input.Caller, Cancel: cancel}, name, input.Mode, input.Rdev, out)
} else {
return fuse.ENOTSUP return fuse.ENOTSUP
} }
ctx := &fuse.Context{Caller: input.Caller, Cancel: cancel}
child, errno := mops.Mknod(ctx, name, input.Mode, input.Rdev, out)
if errno != 0 { if errno != 0 {
return errnoToStatus(errno) return errnoToStatus(errno)
} }
...@@ -470,18 +467,14 @@ func (b *rawBridge) Mknod(cancel <-chan struct{}, input *fuse.MknodIn, name stri ...@@ -470,18 +467,14 @@ func (b *rawBridge) Mknod(cancel <-chan struct{}, input *fuse.MknodIn, name stri
} }
func (b *rawBridge) Create(cancel <-chan struct{}, input *fuse.CreateIn, name string, out *fuse.CreateOut) fuse.Status { func (b *rawBridge) Create(cancel <-chan struct{}, input *fuse.CreateIn, name string, out *fuse.CreateOut) fuse.Status {
ctx := &fuse.Context{Caller: input.Caller, Cancel: cancel}
parent, _ := b.inode(input.NodeId, 0) parent, _ := b.inode(input.NodeId, 0)
var child *Inode mops, ok := parent.ops.(NodeCreater)
var errno syscall.Errno if !ok {
var f FileHandle
var flags uint32
if mops, ok := parent.ops.(NodeCreater); ok {
child, f, flags, errno = mops.Create(ctx, name, input.Flags, input.Mode, &out.EntryOut)
} else {
return fuse.EROFS return fuse.EROFS
} }
ctx := &fuse.Context{Caller: input.Caller, Cancel: cancel}
child, f, flags, errno := mops.Create(ctx, name, input.Flags, input.Mode, &out.EntryOut)
if errno != 0 { if errno != 0 {
if b.options.NegativeTimeout != nil { if b.options.NegativeTimeout != nil {
...@@ -632,51 +625,56 @@ func (b *rawBridge) Link(cancel <-chan struct{}, input *fuse.LinkIn, name string ...@@ -632,51 +625,56 @@ func (b *rawBridge) Link(cancel <-chan struct{}, input *fuse.LinkIn, name string
parent, _ := b.inode(input.NodeId, 0) parent, _ := b.inode(input.NodeId, 0)
target, _ := b.inode(input.Oldnodeid, 0) target, _ := b.inode(input.Oldnodeid, 0)
if mops, ok := parent.ops.(NodeLinker); ok { mops, ok := parent.ops.(NodeLinker)
child, errno := mops.Link(&fuse.Context{Caller: input.Caller, Cancel: cancel}, target.ops, name, out) if !ok {
if errno != 0 { return fuse.ENOTSUP
return errnoToStatus(errno) }
}
child, _ = b.addNewChild(parent, name, child, nil, 0, out) ctx := &fuse.Context{Caller: input.Caller, Cancel: cancel}
child.setEntryOut(out) child, errno := mops.Link(ctx, target.ops, name, out)
b.setEntryOutTimeout(out) if errno != 0 {
return fuse.OK return errnoToStatus(errno)
} }
return fuse.ENOTSUP
child, _ = b.addNewChild(parent, name, child, nil, 0, out)
child.setEntryOut(out)
b.setEntryOutTimeout(out)
return fuse.OK
} }
func (b *rawBridge) Symlink(cancel <-chan struct{}, header *fuse.InHeader, target string, name string, out *fuse.EntryOut) fuse.Status { func (b *rawBridge) Symlink(cancel <-chan struct{}, header *fuse.InHeader, target string, name string, out *fuse.EntryOut) fuse.Status {
parent, _ := b.inode(header.NodeId, 0) parent, _ := b.inode(header.NodeId, 0)
if mops, ok := parent.ops.(NodeSymlinker); ok { mops, ok := parent.ops.(NodeSymlinker)
child, status := mops.Symlink(&fuse.Context{Caller: header.Caller, Cancel: cancel}, target, name, out) if !ok {
if status != 0 { return fuse.ENOTSUP
return errnoToStatus(status)
}
child, _ = b.addNewChild(parent, name, child, nil, syscall.O_EXCL, out)
child.setEntryOut(out)
b.setEntryOutTimeout(out)
return fuse.OK
} }
return fuse.ENOTSUP ctx := &fuse.Context{Caller: header.Caller, Cancel: cancel}
child, status := mops.Symlink(ctx, target, name, out)
if status != 0 {
return errnoToStatus(status)
}
child, _ = b.addNewChild(parent, name, child, nil, syscall.O_EXCL, out)
child.setEntryOut(out)
b.setEntryOutTimeout(out)
return fuse.OK
} }
func (b *rawBridge) Readlink(cancel <-chan struct{}, header *fuse.InHeader) (out []byte, status fuse.Status) { func (b *rawBridge) Readlink(cancel <-chan struct{}, header *fuse.InHeader) (out []byte, status fuse.Status) {
n, _ := b.inode(header.NodeId, 0) n, _ := b.inode(header.NodeId, 0)
if linker, ok := n.ops.(NodeReadlinker); ok { linker, ok := n.ops.(NodeReadlinker)
result, errno := linker.Readlink(&fuse.Context{Caller: header.Caller, Cancel: cancel}) if !ok {
if errno != 0 { return nil, fuse.ENOTSUP
return nil, errnoToStatus(errno) }
} ctx := &fuse.Context{Caller: header.Caller, Cancel: cancel}
result, errno := linker.Readlink(ctx)
return result, fuse.OK if errno != 0 {
return nil, errnoToStatus(errno)
} }
return nil, fuse.ENOTSUP return result, fuse.OK
} }
func (b *rawBridge) Access(cancel <-chan struct{}, input *fuse.AccessIn) fuse.Status { func (b *rawBridge) Access(cancel <-chan struct{}, input *fuse.AccessIn) fuse.Status {
...@@ -742,25 +740,25 @@ func (b *rawBridge) RemoveXAttr(cancel <-chan struct{}, header *fuse.InHeader, a ...@@ -742,25 +740,25 @@ func (b *rawBridge) RemoveXAttr(cancel <-chan struct{}, header *fuse.InHeader, a
func (b *rawBridge) Open(cancel <-chan struct{}, input *fuse.OpenIn, out *fuse.OpenOut) fuse.Status { func (b *rawBridge) Open(cancel <-chan struct{}, input *fuse.OpenIn, out *fuse.OpenOut) fuse.Status {
n, _ := b.inode(input.NodeId, 0) n, _ := b.inode(input.NodeId, 0)
if op, ok := n.ops.(NodeOpener); ok { op, ok := n.ops.(NodeOpener)
f, flags, errno := op.Open(&fuse.Context{Caller: input.Caller, Cancel: cancel}, input.Flags) if !ok {
if errno != 0 { return fuse.ENOTSUP
return errnoToStatus(errno) }
} f, flags, errno := op.Open(&fuse.Context{Caller: input.Caller, Cancel: cancel}, input.Flags)
out.OpenFlags = flags if errno != 0 {
return errnoToStatus(errno)
}
out.OpenFlags = flags
if f != nil { if f != nil {
b.mu.Lock() b.mu.Lock()
defer b.mu.Unlock() defer b.mu.Unlock()
fe := b.registerFile(n, f, input.Flags) fe := b.registerFile(n, f, input.Flags)
out.Fh = uint64(fe.fh) out.Fh = uint64(fe.fh)
b.addBackingID(n, f, out) b.addBackingID(n, f, out)
}
return fuse.OK
} }
return fuse.OK
return fuse.ENOTSUP
} }
// must hold bridge.mu // must hold bridge.mu
......
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