Commit 0becfa3d authored by Aaron Jacobs's avatar Aaron Jacobs

Began fixing Connection.

parent c0e60edb
...@@ -80,6 +80,7 @@ type Connection struct { ...@@ -80,6 +80,7 @@ type Connection struct {
// Freelists, serviced by freelists.go. // Freelists, serviced by freelists.go.
inMessages freelist.Freelist // GUARDED_BY(mu) inMessages freelist.Freelist // GUARDED_BY(mu)
outMessages freelist.Freelist // GUARDED_BY(mu)
} }
// State that is maintained for each in-flight op. This is stuffed into the // State that is maintained for each in-flight op. This is stuffed into the
......
...@@ -387,35 +387,31 @@ func convertInMessage( ...@@ -387,35 +387,31 @@ func convertInMessage(
// Outgoing messages // Outgoing messages
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// Return the response that should be sent to the kernel. If the op requires no // Return the response that should be sent to the kernel, or nil if the op
// response, return a nil response. // requires no response.
func kernelResponse( func (c *Connection) kernelResponse(
fuseID uint64, fuseID uint64,
op interface{}, op interface{},
opErr error, opErr error) (m *buffer.OutMessage) {
protocol fusekernel.Protocol) (msg []byte) { // If the user replied with an error, create a response containing just the
// If the user replied with an error, create room enough just for the result // result header with the error filled in. Otherwise create an appropriate
// header and fill it in with an error. Otherwise create an appropriate
// response. // response.
var b buffer.OutMessage
if opErr != nil { if opErr != nil {
b = buffer.NewOutMessage(0) m = c.getOutMessage()
if errno, ok := opErr.(syscall.Errno); ok { if errno, ok := opErr.(syscall.Errno); ok {
b.OutHeader().Error = -int32(errno) m.OutHeader().Error = -int32(errno)
} else { } else {
b.OutHeader().Error = -int32(syscall.EIO) m.OutHeader().Error = -int32(syscall.EIO)
} }
} else { } else {
b = kernelResponseForOp(op, protocol) m = c.kernelResponseForOp(op)
} }
msg = b.Bytes()
// Fill in the rest of the header, if a response is required. // Fill in the rest of the header, if a response is required.
if msg != nil { if m != nil {
h := b.OutHeader() h := m.OutHeader()
h.Unique = fuseID h.Unique = fuseID
h.Len = uint32(len(msg)) h.Len = uint32(m.Len())
} }
return return
......
...@@ -20,14 +20,20 @@ import ( ...@@ -20,14 +20,20 @@ import (
"github.com/jacobsa/fuse/internal/buffer" "github.com/jacobsa/fuse/internal/buffer"
) )
////////////////////////////////////////////////////////////////////////
// buffer.InMessage
////////////////////////////////////////////////////////////////////////
// LOCKS_EXCLUDED(c.mu) // LOCKS_EXCLUDED(c.mu)
func (c *Connection) getInMessage() (m *buffer.InMessage) { func (c *Connection) getInMessage() (x *buffer.InMessage) {
c.mu.Lock() c.mu.Lock()
m = (*buffer.InMessage)(c.inMessages.Get()) x = (*buffer.InMessage)(c.inMessages.Get())
if m == nil {
m = new(buffer.InMessage)
}
c.mu.Unlock() c.mu.Unlock()
if x == nil {
x = new(buffer.InMessage)
}
return return
} }
...@@ -37,3 +43,28 @@ func (c *Connection) putInMessage(x *buffer.InMessage) { ...@@ -37,3 +43,28 @@ func (c *Connection) putInMessage(x *buffer.InMessage) {
c.inMessages.Put(unsafe.Pointer(x)) c.inMessages.Put(unsafe.Pointer(x))
c.mu.Unlock() c.mu.Unlock()
} }
////////////////////////////////////////////////////////////////////////
// buffer.OutMessage
////////////////////////////////////////////////////////////////////////
// LOCKS_EXCLUDED(c.mu)
func (c *Connection) getOutMessage() (x *buffer.OutMessage) {
c.mu.Lock()
x = (*buffer.OutMessage)(c.outMessages.Get())
c.mu.Unlock()
if x == nil {
x = new(buffer.OutMessage)
}
x.Reset()
return
}
// LOCKS_EXCLUDED(c.mu)
func (c *Connection) putOutMessage(x *buffer.OutMessage) {
c.mu.Lock()
c.outMessages.Put(unsafe.Pointer(x))
c.mu.Unlock()
}
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