Commit bbb262ee authored by Aaron Jacobs's avatar Aaron Jacobs

Read directly into out messages for files.

parent 2e422a13
......@@ -378,8 +378,10 @@ func (c *Connection) ReadOp() (ctx context.Context, op interface{}, err error) {
}
// Convert the message to an op.
op, err = convertInMessage(inMsg, c.protocol)
outMsg := c.getOutMessage()
op, err = convertInMessage(inMsg, outMsg, c.protocol)
if err != nil {
c.putOutMessage(outMsg)
err = fmt.Errorf("convertInMessage: %v", err)
return
}
......@@ -396,9 +398,6 @@ func (c *Connection) ReadOp() (ctx context.Context, op interface{}, err error) {
continue
}
// Allocate an output message up front, to be used later when replying.
outMsg := c.getOutMessage()
// Set up a context that remembers information about this op.
ctx = c.beginOp(inMsg.Header().Opcode, inMsg.Header().Unique)
ctx = context.WithValue(ctx, contextKey, opState{inMsg, outMsg, op, opID})
......
This diff is collapsed.
......@@ -25,6 +25,9 @@ import (
const outHeaderSize = unsafe.Sizeof(fusekernel.OutHeader{})
// OutMessage structs begin life with Len() == OutMessageInitialSize.
const OutMessageInitialSize = outHeaderSize
// We size out messages to be large enough to hold a header for the response
// plus the largest read that may come in.
const outMessageSize = outHeaderSize + MaxReadSize
......@@ -53,8 +56,8 @@ func init() {
// Reset the message so that it is ready to be used again. Afterward, the
// contents are solely a zeroed header.
func (m *OutMessage) Reset() {
m.offset = outHeaderSize
memclr(unsafe.Pointer(&m.storage), outHeaderSize)
m.offset = OutMessageInitialSize
memclr(unsafe.Pointer(&m.storage), OutMessageInitialSize)
}
// Return a pointer to the header at the start of the message.
......@@ -87,6 +90,15 @@ func (b *OutMessage) GrowNoZero(size uintptr) (p unsafe.Pointer) {
return
}
// Throw away the last n bytes. Panics if n is out of range.
func (b *OutMessage) Shrink(n uintptr) {
if n > b.offset-OutMessageInitialSize {
panic(fmt.Sprintf("Shrink(%d) out of range for offset %d", n, b.offset))
}
b.offset -= n
}
// Equivalent to growing by the length of p, then copying p over the new
// segment. Panics if there is not enough room available.
func (b *OutMessage) Append(src []byte) {
......
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