remove naked returns across the code base (#75)

fixes #73
geesefs-0-30-9
Michael Stapelberg 3 years ago committed by GitHub
parent 4898d79241
commit ae5da07e4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 70
      connection.go
  2. 140
      conversions.go
  3. 12
      freelists.go
  4. 15
      fsutil/fsutil.go
  5. 109
      fusetesting/parallel.go
  6. 11
      fusetesting/readdir.go
  7. 14
      fusetesting/stat_darwin.go
  8. 12
      fusetesting/stat_linux.go
  9. 4
      fuseutil/dirent.go
  10. 140
      fuseutil/not_implemented_file_system.go
  11. 34
      internal/buffer/in_message.go
  12. 14
      internal/buffer/out_message.go
  13. 14
      internal/buffer/out_message_test.go
  14. 8
      internal/freelist/freelist.go
  15. 26
      mount.go
  16. 4
      mount_config.go
  17. 34
      mount_darwin.go
  18. 4
      mount_test.go
  19. 42
      samples/cachingfs/caching_fs.go
  20. 6
      samples/cachingfs/caching_fs_test.go
  21. 74
      samples/dynamicfs/dynamic_fs.go
  22. 72
      samples/errorfs/error_fs.go
  23. 95
      samples/flushfs/flush_fs.go
  24. 49
      samples/flushfs/flush_fs_test.go
  25. 47
      samples/forgetfs/forget_fs.go
  26. 61
      samples/hellofs/hello_fs.go
  27. 32
      samples/in_process.go
  28. 43
      samples/interruptfs/interrupt_fs.go
  29. 63
      samples/memfs/inode.go
  30. 164
      samples/memfs/memfs.go
  31. 3
      samples/memfs/posix_test.go
  32. 36
      samples/mount_sample/mount.go
  33. 35
      samples/statfs/statfs.go
  34. 5
      samples/statfs/statfs_darwin_test.go
  35. 16
      samples/statfs/statfs_test.go
  36. 71
      samples/subprocess.go
  37. 9
      samples/unmount.go
  38. 9
      unmount_linux.go
  39. 10
      unmount_std.go

@ -95,8 +95,8 @@ func newConnection(
cfg MountConfig,
debugLogger *log.Logger,
errorLogger *log.Logger,
dev *os.File) (c *Connection, err error) {
c = &Connection{
dev *os.File) (*Connection, error) {
c := &Connection{
cfg: cfg,
debugLogger: debugLogger,
errorLogger: errorLogger,
@ -105,30 +105,26 @@ func newConnection(
}
// Initialize.
err = c.Init()
if err != nil {
if err := c.Init(); err != nil {
c.close()
err = fmt.Errorf("Init: %v", err)
return
return nil, fmt.Errorf("Init: %v", err)
}
return
return c, nil
}
// Init performs the work necessary to cause the mount process to complete.
func (c *Connection) Init() (err error) {
func (c *Connection) Init() error {
// Read the init op.
ctx, op, err := c.ReadOp()
if err != nil {
err = fmt.Errorf("Reading init op: %v", err)
return
return fmt.Errorf("Reading init op: %v", err)
}
initOp, ok := op.(*initOp)
if !ok {
c.Reply(ctx, syscall.EPROTO)
err = fmt.Errorf("Expected *initOp, got %T", op)
return
return fmt.Errorf("Expected *initOp, got %T", op)
}
// Make sure the protocol version spoken by the kernel is new enough.
@ -139,8 +135,7 @@ func (c *Connection) Init() (err error) {
if initOp.Kernel.LT(min) {
c.Reply(ctx, syscall.EPROTO)
err = fmt.Errorf("Version too old: %v", initOp.Kernel)
return
return fmt.Errorf("Version too old: %v", initOp.Kernel)
}
// Downgrade our protocol if necessary.
@ -169,7 +164,7 @@ func (c *Connection) Init() (err error) {
}
c.Reply(ctx, nil)
return
return nil
}
// Log information for an operation with the given ID. calldepth is the depth
@ -228,9 +223,9 @@ func (c *Connection) recordCancelFunc(
// LOCKS_EXCLUDED(c.mu)
func (c *Connection) beginOp(
opCode uint32,
fuseID uint64) (ctx context.Context) {
fuseID uint64) context.Context {
// Start with the parent context.
ctx = c.cfg.OpContext
ctx := c.cfg.OpContext
// Set up a cancellation function.
//
@ -246,7 +241,7 @@ func (c *Connection) beginOp(
c.recordCancelFunc(fuseID, cancel)
}
return
return ctx
}
// Clean up all state associated with an op to which the user has responded,
@ -307,14 +302,14 @@ func (c *Connection) handleInterrupt(fuseID uint64) {
// Read the next message from the kernel. The message must later be destroyed
// using destroyInMessage.
func (c *Connection) readMessage() (m *buffer.InMessage, err error) {
func (c *Connection) readMessage() (*buffer.InMessage, error) {
// Allocate a message.
m = c.getInMessage()
m := c.getInMessage()
// Loop past transient errors.
for {
// Attempt a reaed.
err = m.Init(c.dev)
err := m.Init(c.dev)
// Special cases:
//
@ -336,28 +331,26 @@ func (c *Connection) readMessage() (m *buffer.InMessage, err error) {
if err != nil {
c.putInMessage(m)
m = nil
return
return nil, err
}
return
return m, nil
}
}
// Write the supplied message to the kernel.
func (c *Connection) writeMessage(msg []byte) (err error) {
func (c *Connection) writeMessage(msg []byte) error {
// Avoid the retry loop in os.File.Write.
n, err := syscall.Write(int(c.dev.Fd()), msg)
if err != nil {
return
return err
}
if n != len(msg) {
err = fmt.Errorf("Wrote %d bytes; expected %d", n, len(msg))
return
return fmt.Errorf("Wrote %d bytes; expected %d", n, len(msg))
}
return
return nil
}
// ReadOp consumes the next op from the kernel process, returning the op and a
@ -371,14 +364,13 @@ func (c *Connection) writeMessage(msg []byte) (err error) {
// /dev/fuse. It must not be called multiple times concurrently.
//
// LOCKS_EXCLUDED(c.mu)
func (c *Connection) ReadOp() (ctx context.Context, op interface{}, err error) {
func (c *Connection) ReadOp() (_ context.Context, op interface{}, _ error) {
// Keep going until we find a request we know how to convert.
for {
// Read the next message from the kernel.
var inMsg *buffer.InMessage
inMsg, err = c.readMessage()
inMsg, err := c.readMessage()
if err != nil {
return
return nil, nil, err
}
// Convert the message to an op.
@ -386,8 +378,7 @@ func (c *Connection) ReadOp() (ctx context.Context, op interface{}, err error) {
op, err = convertInMessage(inMsg, outMsg, c.protocol)
if err != nil {
c.putOutMessage(outMsg)
err = fmt.Errorf("convertInMessage: %v", err)
return
return nil, nil, fmt.Errorf("convertInMessage: %v", err)
}
// Choose an ID for this operation for the purposes of logging, and log it.
@ -402,11 +393,11 @@ func (c *Connection) ReadOp() (ctx context.Context, op interface{}, err error) {
}
// Set up a context that remembers information about this op.
ctx = c.beginOp(inMsg.Header().Opcode, inMsg.Header().Unique)
ctx := c.beginOp(inMsg.Header().Opcode, inMsg.Header().Unique)
ctx = context.WithValue(ctx, contextKey, opState{inMsg, outMsg, op})
// Return the op to the user.
return
return ctx, op, nil
}
}
@ -499,10 +490,9 @@ func (c *Connection) Reply(ctx context.Context, opErr error) {
// Close the connection. Must not be called until operations that were read
// from the connection have been responded to.
func (c *Connection) close() (err error) {
func (c *Connection) close() error {
// Posix doesn't say that close can be called concurrently with read or
// write, but luckily we exclude the possibility of a race by requiring the
// user to respond to all ops first.
err = c.dev.Close()
return
return c.dev.Close()
}

@ -46,8 +46,7 @@ func convertInMessage(
buf := inMsg.ConsumeBytes(inMsg.Len())
n := len(buf)
if n == 0 || buf[n-1] != '\x00' {
err = errors.New("Corrupt OpLookup")
return
return nil, errors.New("Corrupt OpLookup")
}
o = &fuseops.LookUpInodeOp{
@ -64,8 +63,7 @@ func convertInMessage(
type input fusekernel.SetattrIn
in := (*input)(inMsg.Consume(unsafe.Sizeof(input{})))
if in == nil {
err = errors.New("Corrupt OpSetattr")
return
return nil, errors.New("Corrupt OpSetattr")
}
to := &fuseops.SetInodeAttributesOp{
@ -102,8 +100,7 @@ func convertInMessage(
type input fusekernel.ForgetIn
in := (*input)(inMsg.Consume(unsafe.Sizeof(input{})))
if in == nil {
err = errors.New("Corrupt OpForget")
return
return nil, errors.New("Corrupt OpForget")
}
o = &fuseops.ForgetInodeOp{
@ -114,15 +111,13 @@ func convertInMessage(
case fusekernel.OpMkdir:
in := (*fusekernel.MkdirIn)(inMsg.Consume(fusekernel.MkdirInSize(protocol)))
if in == nil {
err = errors.New("Corrupt OpMkdir")
return
return nil, errors.New("Corrupt OpMkdir")
}
name := inMsg.ConsumeBytes(inMsg.Len())
i := bytes.IndexByte(name, '\x00')
if i < 0 {
err = errors.New("Corrupt OpMkdir")
return
return nil, errors.New("Corrupt OpMkdir")
}
name = name[:i]
@ -142,15 +137,13 @@ func convertInMessage(
case fusekernel.OpMknod:
in := (*fusekernel.MknodIn)(inMsg.Consume(fusekernel.MknodInSize(protocol)))
if in == nil {
err = errors.New("Corrupt OpMknod")
return
return nil, errors.New("Corrupt OpMknod")
}
name := inMsg.ConsumeBytes(inMsg.Len())
i := bytes.IndexByte(name, '\x00')
if i < 0 {
err = errors.New("Corrupt OpMknod")
return
return nil, errors.New("Corrupt OpMknod")
}
name = name[:i]
@ -163,15 +156,13 @@ func convertInMessage(
case fusekernel.OpCreate:
in := (*fusekernel.CreateIn)(inMsg.Consume(fusekernel.CreateInSize(protocol)))
if in == nil {
err = errors.New("Corrupt OpCreate")
return
return nil, errors.New("Corrupt OpCreate")
}
name := inMsg.ConsumeBytes(inMsg.Len())
i := bytes.IndexByte(name, '\x00')
if i < 0 {
err = errors.New("Corrupt OpCreate")
return
return nil, errors.New("Corrupt OpCreate")
}
name = name[:i]
@ -185,13 +176,11 @@ func convertInMessage(
// The message is "newName\0target\0".
names := inMsg.ConsumeBytes(inMsg.Len())
if len(names) == 0 || names[len(names)-1] != 0 {
err = errors.New("Corrupt OpSymlink")
return
return nil, errors.New("Corrupt OpSymlink")
}
i := bytes.IndexByte(names, '\x00')
if i < 0 {
err = errors.New("Corrupt OpSymlink")
return
return nil, errors.New("Corrupt OpSymlink")
}
newName, target := names[0:i], names[i+1:len(names)-1]
@ -205,24 +194,20 @@ func convertInMessage(
type input fusekernel.RenameIn
in := (*input)(inMsg.Consume(unsafe.Sizeof(input{})))
if in == nil {
err = errors.New("Corrupt OpRename")
return
return nil, errors.New("Corrupt OpRename")
}
names := inMsg.ConsumeBytes(inMsg.Len())
// names should be "old\x00new\x00"
if len(names) < 4 {
err = errors.New("Corrupt OpRename")
return
return nil, errors.New("Corrupt OpRename")
}
if names[len(names)-1] != '\x00' {
err = errors.New("Corrupt OpRename")
return
return nil, errors.New("Corrupt OpRename")
}
i := bytes.IndexByte(names, '\x00')
if i < 0 {
err = errors.New("Corrupt OpRename")
return
return nil, errors.New("Corrupt OpRename")
}
oldName, newName := names[:i], names[i+1:len(names)-1]
@ -237,8 +222,7 @@ func convertInMessage(
buf := inMsg.ConsumeBytes(inMsg.Len())
n := len(buf)
if n == 0 || buf[n-1] != '\x00' {
err = errors.New("Corrupt OpUnlink")
return
return nil, errors.New("Corrupt OpUnlink")
}
o = &fuseops.UnlinkOp{
@ -250,8 +234,7 @@ func convertInMessage(
buf := inMsg.ConsumeBytes(inMsg.Len())
n := len(buf)
if n == 0 || buf[n-1] != '\x00' {
err = errors.New("Corrupt OpRmdir")
return
return nil, errors.New("Corrupt OpRmdir")
}
o = &fuseops.RmDirOp{
@ -272,8 +255,7 @@ func convertInMessage(
case fusekernel.OpRead:
in := (*fusekernel.ReadIn)(inMsg.Consume(fusekernel.ReadInSize(protocol)))
if in == nil {
err = errors.New("Corrupt OpRead")
return
return nil, errors.New("Corrupt OpRead")
}
to := &fuseops.ReadFileOp{
@ -286,8 +268,7 @@ func convertInMessage(
readSize := int(in.Size)
p := outMsg.GrowNoZero(readSize)
if p == nil {
err = fmt.Errorf("Can't grow for %d-byte read", readSize)
return
return nil, fmt.Errorf("Can't grow for %d-byte read", readSize)
}
sh := (*reflect.SliceHeader)(unsafe.Pointer(&to.Dst))
@ -298,8 +279,7 @@ func convertInMessage(
case fusekernel.OpReaddir:
in := (*fusekernel.ReadIn)(inMsg.Consume(fusekernel.ReadInSize(protocol)))
if in == nil {
err = errors.New("Corrupt OpReaddir")
return
return nil, errors.New("Corrupt OpReaddir")
}
to := &fuseops.ReadDirOp{
@ -312,8 +292,7 @@ func convertInMessage(
readSize := int(in.Size)
p := outMsg.GrowNoZero(readSize)
if p == nil {
err = fmt.Errorf("Can't grow for %d-byte read", readSize)
return
return nil, fmt.Errorf("Can't grow for %d-byte read", readSize)
}
sh := (*reflect.SliceHeader)(unsafe.Pointer(&to.Dst))
@ -325,8 +304,7 @@ func convertInMessage(
type input fusekernel.ReleaseIn
in := (*input)(inMsg.Consume(unsafe.Sizeof(input{})))
if in == nil {
err = errors.New("Corrupt OpRelease")
return
return nil, errors.New("Corrupt OpRelease")
}
o = &fuseops.ReleaseFileHandleOp{
@ -337,8 +315,7 @@ func convertInMessage(
type input fusekernel.ReleaseIn
in := (*input)(inMsg.Consume(unsafe.Sizeof(input{})))
if in == nil {
err = errors.New("Corrupt OpReleasedir")
return
return nil, errors.New("Corrupt OpReleasedir")
}
o = &fuseops.ReleaseDirHandleOp{
@ -348,14 +325,12 @@ func convertInMessage(
case fusekernel.OpWrite:
in := (*fusekernel.WriteIn)(inMsg.Consume(fusekernel.WriteInSize(protocol)))
if in == nil {
err = errors.New("Corrupt OpWrite")
return
return nil, errors.New("Corrupt OpWrite")
}
buf := inMsg.ConsumeBytes(inMsg.Len())
if len(buf) < int(in.Size) {
err = errors.New("Corrupt OpWrite")
return
return nil, errors.New("Corrupt OpWrite")
}
o = &fuseops.WriteFileOp{
@ -369,8 +344,7 @@ func convertInMessage(
type input fusekernel.FsyncIn
in := (*input)(inMsg.Consume(unsafe.Sizeof(input{})))
if in == nil {
err = errors.New("Corrupt OpFsync")
return
return nil, errors.New("Corrupt OpFsync")
}
o = &fuseops.SyncFileOp{
@ -382,8 +356,7 @@ func convertInMessage(
type input fusekernel.FlushIn
in := (*input)(inMsg.Consume(unsafe.Sizeof(input{})))
if in == nil {
err = errors.New("Corrupt OpFlush")
return
return nil, errors.New("Corrupt OpFlush")
}
o = &fuseops.FlushFileOp{
@ -403,8 +376,7 @@ func convertInMessage(
type input fusekernel.InterruptIn
in := (*input)(inMsg.Consume(unsafe.Sizeof(input{})))
if in == nil {
err = errors.New("Corrupt OpInterrupt")
return
return nil, errors.New("Corrupt OpInterrupt")
}
o = &interruptOp{
@ -415,8 +387,7 @@ func convertInMessage(
type input fusekernel.InitIn
in := (*input)(inMsg.Consume(unsafe.Sizeof(input{})))
if in == nil {
err = errors.New("Corrupt OpInit")
return
return nil, errors.New("Corrupt OpInit")
}
o = &initOp{
@ -429,20 +400,17 @@ func convertInMessage(
type input fusekernel.LinkIn
in := (*input)(inMsg.Consume(unsafe.Sizeof(input{})))
if in == nil {
err = errors.New("Corrupt OpLink")
return
return nil, errors.New("Corrupt OpLink")
}
name := inMsg.ConsumeBytes(inMsg.Len())
i := bytes.IndexByte(name, '\x00')
if i < 0 {
err = errors.New("Corrupt OpLink")
return
return nil, errors.New("Corrupt OpLink")
}
name = name[:i]
if len(name) == 0 {
err = errors.New("Corrupt OpLink (Name not read)")
return
return nil, errors.New("Corrupt OpLink (Name not read)")
}
o = &fuseops.CreateLinkOp{
@ -455,8 +423,7 @@ func convertInMessage(
buf := inMsg.ConsumeBytes(inMsg.Len())
n := len(buf)
if n == 0 || buf[n-1] != '\x00' {
err = errors.New("Corrupt OpRemovexattr")
return
return nil, errors.New("Corrupt OpRemovexattr")
}
o = &fuseops.RemoveXattrOp{
@ -468,15 +435,13 @@ func convertInMessage(
type input fusekernel.GetxattrIn
in := (*input)(inMsg.Consume(unsafe.Sizeof(input{})))
if in == nil {
err = errors.New("Corrupt OpGetxattr")
return
return nil, errors.New("Corrupt OpGetxattr")
}
name := inMsg.ConsumeBytes(inMsg.Len())
i := bytes.IndexByte(name, '\x00')
if i < 0 {
err = errors.New("Corrupt OpGetxattr")
return
return nil, errors.New("Corrupt OpGetxattr")
}
name = name[:i]
@ -489,8 +454,7 @@ func convertInMessage(
readSize := int(in.Size)
p := outMsg.GrowNoZero(readSize)
if p == nil {
err = fmt.Errorf("Can't grow for %d-byte read", readSize)
return
return nil, fmt.Errorf("Can't grow for %d-byte read", readSize)
}
sh := (*reflect.SliceHeader)(unsafe.Pointer(&to.Dst))
@ -502,8 +466,7 @@ func convertInMessage(
type input fusekernel.ListxattrIn
in := (*input)(inMsg.Consume(unsafe.Sizeof(input{})))
if in == nil {
err = errors.New("Corrupt OpListxattr")
return
return nil, errors.New("Corrupt OpListxattr")
}
to := &fuseops.ListXattrOp{
@ -515,8 +478,7 @@ func convertInMessage(
if readSize != 0 {
p := outMsg.GrowNoZero(readSize)
if p == nil {
err = fmt.Errorf("Can't grow for %d-byte read", readSize)
return
return nil, fmt.Errorf("Can't grow for %d-byte read", readSize)
}
sh := (*reflect.SliceHeader)(unsafe.Pointer(&to.Dst))
sh.Data = uintptr(p)
@ -527,20 +489,17 @@ func convertInMessage(
type input fusekernel.SetxattrIn
in := (*input)(inMsg.Consume(unsafe.Sizeof(input{})))
if in == nil {
err = errors.New("Corrupt OpSetxattr")
return
return nil, errors.New("Corrupt OpSetxattr")
}
payload := inMsg.ConsumeBytes(inMsg.Len())
// payload should be "name\x00value"
if len(payload) < 3 {
err = errors.New("Corrupt OpSetxattr")
return
return nil, errors.New("Corrupt OpSetxattr")
}
i := bytes.IndexByte(payload, '\x00')
if i < 0 {
err = errors.New("Corrupt OpSetxattr")
return
return nil, errors.New("Corrupt OpSetxattr")
}
name, value := payload[:i], payload[i+1:len(payload)]
@ -555,8 +514,7 @@ func convertInMessage(
type input fusekernel.FallocateIn
in := (*input)(inMsg.Consume(unsafe.Sizeof(input{})))
if in == nil {
err = errors.New("Corrupt OpFallocate")
return
return nil, errors.New("Corrupt OpFallocate")
}
o = &fuseops.FallocateOp{
@ -574,7 +532,7 @@ func convertInMessage(
}
}
return
return o, nil
}
////////////////////////////////////////////////////////////////////////
@ -595,12 +553,10 @@ func (c *Connection) kernelResponse(
// interruptOp .
switch op.(type) {
case *fuseops.ForgetInodeOp:
noResponse = true
return
return true
case *interruptOp:
noResponse = true
return
return true
}
// If the user returned the error, fill in the error field of the outgoing
@ -629,7 +585,7 @@ func (c *Connection) kernelResponse(
}
h.Len = uint32(m.Len())
return
return false
}
// Like kernelResponse, but assumes the user replied with a nil error to the
@ -829,7 +785,7 @@ func convertTime(t time.Time) (secs uint64, nsec uint32) {
totalNano := t.UnixNano()
secs = uint64(totalNano / 1e9)
nsec = uint32(totalNano % 1e9)
return
return secs, nsec
}
func convertAttributes(
@ -886,7 +842,7 @@ func convertExpirationTime(t time.Time) (secs uint64, nsecs uint32) {
nsecs = uint32((d % time.Second) / time.Nanosecond)
}
return
return secs, nsecs
}
func convertChildInodeEntry(

@ -25,16 +25,16 @@ import (
////////////////////////////////////////////////////////////////////////
// LOCKS_EXCLUDED(c.mu)
func (c *Connection) getInMessage() (x *buffer.InMessage) {
func (c *Connection) getInMessage() *buffer.InMessage {
c.mu.Lock()
x = (*buffer.InMessage)(c.inMessages.Get())
x := (*buffer.InMessage)(c.inMessages.Get())
c.mu.Unlock()
if x == nil {
x = new(buffer.InMessage)
}
return
return x
}
// LOCKS_EXCLUDED(c.mu)
@ -49,9 +49,9 @@ func (c *Connection) putInMessage(x *buffer.InMessage) {
////////////////////////////////////////////////////////////////////////
// LOCKS_EXCLUDED(c.mu)
func (c *Connection) getOutMessage() (x *buffer.OutMessage) {
func (c *Connection) getOutMessage() *buffer.OutMessage {
c.mu.Lock()
x = (*buffer.OutMessage)(c.outMessages.Get())
x := (*buffer.OutMessage)(c.outMessages.Get())
c.mu.Unlock()
if x == nil {
@ -59,7 +59,7 @@ func (c *Connection) getOutMessage() (x *buffer.OutMessage) {
}
x.Reset()
return
return x
}
// LOCKS_EXCLUDED(c.mu)

@ -28,25 +28,22 @@ import (
// Warning: this is not production-quality code, and should only be used for
// testing purposes. In particular, there is a race between creating and
// unlinking by name.
func AnonymousFile(dir string) (f *os.File, err error) {
func AnonymousFile(dir string) (*os.File, error) {
// Choose a prefix based on the binary name.
prefix := path.Base(os.Args[0])
// Create the file.
f, err = ioutil.TempFile(dir, prefix)
f, err := ioutil.TempFile(dir, prefix)
if err != nil {
err = fmt.Errorf("TempFile: %v", err)
return
return nil, fmt.Errorf("TempFile: %v", err)
}
// Unlink it.
err = os.Remove(f.Name())
if err != nil {
err = fmt.Errorf("Remove: %v", err)
return
if err := os.Remove(f.Name()); err != nil {
return nil, fmt.Errorf("Remove: %v", err)
}
return
return f, nil
}
// Call fdatasync on the supplied file.

@ -44,22 +44,18 @@ func RunCreateInParallelTest_NoTruncate(
// Set up a function that opens the file with O_CREATE and then appends a
// byte to it.
worker := func(id byte) (err error) {
worker := func(id byte) error {
f, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600)
if err != nil {
err = fmt.Errorf("Worker %d: Open: %v", id, err)
return
return fmt.Errorf("Worker %d: Open: %v", id, err)
}
defer f.Close()
_, err = f.Write([]byte{id})
if err != nil {
err = fmt.Errorf("Worker %d: Write: %v", id, err)
return
if _, err := f.Write([]byte{id}); err != nil {
return fmt.Errorf("Worker %d: Write: %v", id, err)
}
return
return nil
}
// Run several workers in parallel.
@ -67,9 +63,8 @@ func RunCreateInParallelTest_NoTruncate(
b := syncutil.NewBundle(ctx)
for i := 0; i < numWorkers; i++ {
id := byte(i)
b.Add(func(ctx context.Context) (err error) {
err = worker(id)
return
b.Add(func(ctx context.Context) error {
return worker(id)
})
}
@ -121,21 +116,16 @@ func RunCreateInParallelTest_Truncate(
filename,
os.O_CREATE|os.O_WRONLY|os.O_APPEND|os.O_TRUNC,
0600)
if err != nil {
err = fmt.Errorf("Worker %d: Open: %v", id, err)
return
return fmt.Errorf("Worker %d: Open: %v", id, err)
}
defer f.Close()
_, err = f.Write([]byte{id})
if err != nil {
err = fmt.Errorf("Worker %d: Write: %v", id, err)
return
if _, err := f.Write([]byte{id}); err != nil {
return fmt.Errorf("Worker %d: Write: %v", id, err)
}
return
return nil
}
// Run several workers in parallel.
@ -143,9 +133,8 @@ func RunCreateInParallelTest_Truncate(
b := syncutil.NewBundle(ctx)
for i := 0; i < numWorkers; i++ {
id := byte(i)
b.Add(func(ctx context.Context) (err error) {
err = worker(id)
return
b.Add(func(ctx context.Context) error {
return worker(id)
})
}
@ -203,26 +192,22 @@ func RunCreateInParallelTest_Exclusive(
// If we failed to open due to the file already existing, just leave.
if os.IsExist(err) {
err = nil
return
return nil
}
// Propgate other errors.
if err != nil {
err = fmt.Errorf("Worker %d: Open: %v", id, err)
return
return fmt.Errorf("Worker %d: Open: %v", id, err)
}
atomic.AddUint64(&openCount, 1)
defer f.Close()
_, err = f.Write([]byte{id})
if err != nil {
err = fmt.Errorf("Worker %d: Write: %v", id, err)
return
if _, err := f.Write([]byte{id}); err != nil {
return fmt.Errorf("Worker %d: Write: %v", id, err)
}
return
return nil
}
// Run several workers in parallel.
@ -230,9 +215,8 @@ func RunCreateInParallelTest_Exclusive(
b := syncutil.NewBundle(ctx)
for i := 0; i < numWorkers; i++ {
id := byte(i)
b.Add(func(ctx context.Context) (err error) {
err = worker(id)
return
b.Add(func(ctx context.Context) error {
return worker(id)
})
}
@ -269,19 +253,16 @@ func RunMkdirInParallelTest(
filename := path.Join(dir, "foo")
// Set up a function that creates the directory, ignoring EEXIST errors.
worker := func(id byte) (err error) {
err = os.Mkdir(filename, 0700)
worker := func(id byte) error {
err := os.Mkdir(filename, 0700)
if os.IsExist(err) {
err = nil
return nil
}
if err != nil {
err = fmt.Errorf("Worker %d: Mkdir: %v", id, err)
return
return fmt.Errorf("Worker %d: Mkdir: %v", id, err)
}
return
return nil
}
// Run several workers in parallel.
@ -289,9 +270,8 @@ func RunMkdirInParallelTest(
b := syncutil.NewBundle(ctx)
for i := 0; i < numWorkers; i++ {
id := byte(i)
b.Add(func(ctx context.Context) (err error) {
err = worker(id)
return
b.Add(func(ctx context.Context) error {
return worker(id)
})
}
@ -325,19 +305,17 @@ func RunSymlinkInParallelTest(
filename := path.Join(dir, "foo")
// Set up a function that creates the symlink, ignoring EEXIST errors.
worker := func(id byte) (err error) {
err = os.Symlink("blah", filename)
worker := func(id byte) error {
err := os.Symlink("blah", filename)
if os.IsExist(err) {
err = nil
return nil
}
if err != nil {
err = fmt.Errorf("Worker %d: Symlink: %v", id, err)
return
return fmt.Errorf("Worker %d: Symlink: %v", id, err)
}
return
return nil
}
// Run several workers in parallel.
@ -345,9 +323,8 @@ func RunSymlinkInParallelTest(
b := syncutil.NewBundle(ctx)
for i := 0; i < numWorkers; i++ {
id := byte(i)
b.Add(func(ctx context.Context) (err error) {
err = worker(id)
return
b.Add(func(ctx context.Context) error {
return worker(id)
})
}
@ -388,19 +365,16 @@ func RunHardlinkInParallelTest(
filename := path.Join(dir, "foo")
// Set up a function that creates the symlink, ignoring EEXIST errors.
worker := func(id byte) (err error) {
err = os.Link(originalFile, filename)
worker := func(id byte) error {
err := os.Link(originalFile, filename)
if os.IsExist(err) {
err = nil
return nil
}
if err != nil {
err = fmt.Errorf("Worker %d: Link: %v", id, err)
return
return fmt.Errorf("Worker %d: Link: %v", id, err)
}
return
return nil
}
// Run several workers in parallel.
@ -408,9 +382,8 @@ func RunHardlinkInParallelTest(
b := syncutil.NewBundle(ctx)
for i := 0; i < numWorkers; i++ {
id := byte(i)
b.Add(func(ctx context.Context) (err error) {
err = worker(id)
return
b.Add(func(ctx context.Context) error {
return worker(id)
})
}

@ -37,8 +37,7 @@ func ReadDirPicky(dirname string) (entries []os.FileInfo, err error) {
// Open the directory.
f, err := os.Open(dirname)
if err != nil {
err = fmt.Errorf("Open: %v", err)
return
return nil, fmt.Errorf("Open: %v", err)
}
// Don't forget to close it later.
@ -52,8 +51,7 @@ func ReadDirPicky(dirname string) (entries []os.FileInfo, err error) {
// Read all of the names from the directory.
names, err := f.Readdirnames(-1)
if err != nil {
err = fmt.Errorf("Readdirnames: %v", err)
return
return nil, fmt.Errorf("Readdirnames: %v", err)
}
// Stat each one.
@ -62,8 +60,7 @@ func ReadDirPicky(dirname string) (entries []os.FileInfo, err error) {
fi, err = os.Lstat(path.Join(dirname, name))
if err != nil {
err = fmt.Errorf("Lstat(%s): %v", name, err)
return
return nil, fmt.Errorf("Lstat(%s): %v", name, err)
}
entries = append(entries, fi)
@ -72,5 +69,5 @@ func ReadDirPicky(dirname string) (entries []os.FileInfo, err error) {
// Sort the entries by name.
sort.Sort(sortedEntries(entries))
return
return entries, nil
}

@ -20,26 +20,20 @@ import (
)
func extractMtime(sys interface{}) (mtime time.Time, ok bool) {
mtime = time.Unix(sys.(*syscall.Stat_t).Mtimespec.Unix())
ok = true
return
return time.Unix(sys.(*syscall.Stat_t).Mtimespec.Unix()), true
}
func extractBirthtime(sys interface{}) (birthtime time.Time, ok bool) {
birthtime = time.Unix(sys.(*syscall.Stat_t).Birthtimespec.Unix())
ok = true
return
return time.Unix(sys.(*syscall.Stat_t).Birthtimespec.Unix()), true
}
func extractNlink(sys interface{}) (nlink uint64, ok bool) {
nlink = uint64(sys.(*syscall.Stat_t).Nlink)
ok = true
return
return uint64(sys.(*syscall.Stat_t).Nlink), true
}
func getTimes(stat *syscall.Stat_t) (atime, ctime, mtime time.Time) {
atime = time.Unix(stat.Atimespec.Unix())
ctime = time.Unix(stat.Ctimespec.Unix())
mtime = time.Unix(stat.Mtimespec.Unix())
return
return atime, ctime, mtime
}

@ -20,24 +20,20 @@ import (
)
func extractMtime(sys interface{}) (mtime time.Time, ok bool) {
mtime = time.Unix(sys.(*syscall.Stat_t).Mtim.Unix())
ok = true
return
return time.Unix(sys.(*syscall.Stat_t).Mtim.Unix()), true
}
func extractBirthtime(sys interface{}) (birthtime time.Time, ok bool) {
return
return time.Time{}, false
}
func extractNlink(sys interface{}) (nlink uint64, ok bool) {
nlink = sys.(*syscall.Stat_t).Nlink
ok = true
return
return sys.(*syscall.Stat_t).Nlink, true
}
func getTimes(stat *syscall.Stat_t) (atime, ctime, mtime time.Time) {
atime = time.Unix(stat.Atim.Unix())
ctime = time.Unix(stat.Ctim.Unix())
mtime = time.Unix(stat.Mtim.Unix())
return
return atime, ctime, mtime
}

@ -79,7 +79,7 @@ func WriteDirent(buf []byte, d Dirent) (n int) {
// Do we have enough room?
totalLen := direntSize + len(d.Name) + padLen
if totalLen > len(buf) {
return
return n
}
// Write the header.
@ -101,5 +101,5 @@ func WriteDirent(buf []byte, d Dirent) (n int) {
n += copy(buf[n:], padding[:padLen])
}
return
return n
}

@ -32,198 +32,170 @@ var _ FileSystem = &NotImplementedFileSystem{}
func (fs *NotImplementedFileSystem) StatFS(
ctx context.Context,
op *fuseops.StatFSOp) (err error) {
err = fuse.ENOSYS
return
op *fuseops.StatFSOp) error {
return fuse.ENOSYS
}
func (fs *NotImplementedFileSystem) LookUpInode(
ctx context.Context,
op *fuseops.LookUpInodeOp) (err error) {
err = fuse.ENOSYS
return
op *fuseops.LookUpInodeOp) error {
return fuse.ENOSYS
}
func (fs *NotImplementedFileSystem) GetInodeAttributes(
ctx context.Context,
op *fuseops.GetInodeAttributesOp) (err error) {
err = fuse.ENOSYS
return
op *fuseops.GetInodeAttributesOp) error {
return fuse.ENOSYS
}
func (fs *NotImplementedFileSystem) SetInodeAttributes(
ctx context.Context,
op *fuseops.SetInodeAttributesOp) (err error) {
err = fuse.ENOSYS
return
op *fuseops.SetInodeAttributesOp) error {
return fuse.ENOSYS
}
func (fs *NotImplementedFileSystem) ForgetInode(
ctx context.Context,
op *fuseops.ForgetInodeOp) (err error) {
err = fuse.ENOSYS
return
op *fuseops.ForgetInodeOp) error {
return fuse.ENOSYS
}
func (fs *NotImplementedFileSystem) MkDir(
ctx context.Context,
op *fuseops.MkDirOp) (err error) {
err = fuse.ENOSYS
return
op *fuseops.MkDirOp) error {
return fuse.ENOSYS
}
func (fs *NotImplementedFileSystem) MkNode(
ctx context.Context,
op *fuseops.MkNodeOp) (err error) {
err = fuse.ENOSYS
return
op *fuseops.MkNodeOp) error {
return fuse.ENOSYS
}
func (fs *NotImplementedFileSystem) CreateFile(
ctx context.Context,
op *fuseops.CreateFileOp) (err error) {
err = fuse.ENOSYS
return
op *fuseops.CreateFileOp) error {
return fuse.ENOSYS
}
func (fs *NotImplementedFileSystem) CreateSymlink(
ctx context.Context,
op *fuseops.CreateSymlinkOp) (err error) {
err = fuse.ENOSYS
return
op *fuseops.CreateSymlinkOp) error {
return fuse.ENOSYS
}
func (fs *NotImplementedFileSystem) CreateLink(
ctx context.Context,
op *fuseops.CreateLinkOp) (err error) {
err = fuse.ENOSYS
return
op *fuseops.CreateLinkOp) error {
return fuse.ENOSYS
}
func (fs *NotImplementedFileSystem) Rename(
ctx context.Context,
op *fuseops.RenameOp) (err error) {
err = fuse.ENOSYS
return
op *fuseops.RenameOp) error {
return fuse.ENOSYS
}
func (fs *NotImplementedFileSystem) RmDir(
ctx context.Context,
op *fuseops.RmDirOp) (err error) {
err = fuse.ENOSYS
return
op *fuseops.RmDirOp) error {
return fuse.ENOSYS
}
func (fs *NotImplementedFileSystem) Unlink(
ctx context.Context,
op *fuseops.UnlinkOp) (err error) {
err = fuse.ENOSYS
return
op *fuseops.UnlinkOp) error {
return fuse.ENOSYS
}
func (fs *NotImplementedFileSystem) OpenDir(
ctx context.Context,
op *fuseops.OpenDirOp) (err error) {
err = fuse.ENOSYS
return
op *fuseops.OpenDirOp) error {
return fuse.ENOSYS
}
func (fs *NotImplementedFileSystem) ReadDir(
ctx context.Context,
op *fuseops.ReadDirOp) (err error) {
err = fuse.ENOSYS
return
op *fuseops.ReadDirOp) error {
return fuse.ENOSYS
}
func (fs *NotImplementedFileSystem) ReleaseDirHandle(
ctx context.Context,
op *fuseops.ReleaseDirHandleOp) (err error) {
err = fuse.ENOSYS
return
op *fuseops.ReleaseDirHandleOp) error {
return fuse.ENOSYS
}
func (fs *NotImplementedFileSystem) OpenFile(
ctx context.Context,
op *fuseops.OpenFileOp) (err error) {
err = fuse.ENOSYS
return
op *fuseops.OpenFileOp) error {
return fuse.ENOSYS
}
func (fs *NotImplementedFileSystem) ReadFile(
ctx context.Context,
op *fuseops.ReadFileOp) (err error) {
err = fuse.ENOSYS
return
op *fuseops.ReadFileOp) error {
return fuse.ENOSYS
}
func (fs *NotImplementedFileSystem) WriteFile(
ctx context.Context,
op *fuseops.WriteFileOp) (err error) {
err = fuse.ENOSYS
return
op *fuseops.WriteFileOp) error {
return fuse.ENOSYS
}
func (fs *NotImplementedFileSystem) SyncFile(
ctx context.Context,
op *fuseops.SyncFileOp) (err error) {
err = fuse.ENOSYS
return
op *fuseops.SyncFileOp) error {