From 23ac7e9388aec020fc7bb4cc87fbd87eeb236e79 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sat, 29 Dec 2018 11:46:46 -0800 Subject: [PATCH] apply https://github.com/bazil/fuse/pull/162 applying https://patch-diff.githubusercontent.com/raw/bazil/fuse/pull/162.diff --- buffer.go | 8 -- debug.go | 4 +- examples/clockfs/clockfs.go | 2 +- examples/hellofs/hello.go | 2 +- fs/bench/bench_create_test.go | 2 +- fs/bench/bench_lookup_test.go | 3 +- fs/bench/bench_readwrite_test.go | 2 +- fs/fstestutil/record/record.go | 2 +- fs/fstestutil/record/wait.go | 2 +- fs/fstestutil/testfs.go | 2 +- fs/serve.go | 101 +++++++++++----------- fs/serve_test.go | 2 +- fs/tree.go | 3 +- fuse.go | 140 ++++++++++++++++++++----------- options_daemon_timeout_test.go | 2 +- options_test.go | 2 +- 16 files changed, 156 insertions(+), 123 deletions(-) diff --git a/buffer.go b/buffer.go index bb1d2b77..5635a898 100644 --- a/buffer.go +++ b/buffer.go @@ -20,14 +20,6 @@ func (w *buffer) alloc(size uintptr) unsafe.Pointer { return unsafe.Pointer(&(*w)[l]) } -// reset clears out the contents of the buffer. -func (w *buffer) reset() { - for i := range (*w)[:cap(*w)] { - (*w)[i] = 0 - } - *w = (*w)[:0] -} - func newBuffer(extra uintptr) buffer { const hdrSize = unsafe.Sizeof(outHeader{}) buf := make(buffer, hdrSize, hdrSize+extra) diff --git a/debug.go b/debug.go index be9f900d..3a5eea72 100644 --- a/debug.go +++ b/debug.go @@ -9,8 +9,6 @@ func stack() string { return string(buf[:runtime.Stack(buf, false)]) } -func nop(msg interface{}) {} - // Debug is called to output debug messages, including protocol // traces. The default behavior is to do nothing. // @@ -18,4 +16,4 @@ func nop(msg interface{}) {} // safe to marshal to JSON. // // Implementations must not retain msg. -var Debug func(msg interface{}) = nop +var Debug func(msg interface{}) diff --git a/examples/clockfs/clockfs.go b/examples/clockfs/clockfs.go index 29634e80..02d28a21 100644 --- a/examples/clockfs/clockfs.go +++ b/examples/clockfs/clockfs.go @@ -3,6 +3,7 @@ package main import ( + "context" "flag" "fmt" "log" @@ -15,7 +16,6 @@ import ( "github.com/seaweedfs/fuse/fs" _ "github.com/seaweedfs/fuse/fs/fstestutil" "github.com/seaweedfs/fuse/fuseutil" - "golang.org/x/net/context" ) func usage() { diff --git a/examples/hellofs/hello.go b/examples/hellofs/hello.go index 10c9909f..14713794 100644 --- a/examples/hellofs/hello.go +++ b/examples/hellofs/hello.go @@ -2,6 +2,7 @@ package main import ( + "context" "flag" "fmt" "log" @@ -10,7 +11,6 @@ import ( "github.com/seaweedfs/fuse" "github.com/seaweedfs/fuse/fs" _ "github.com/seaweedfs/fuse/fs/fstestutil" - "golang.org/x/net/context" ) func usage() { diff --git a/fs/bench/bench_create_test.go b/fs/bench/bench_create_test.go index 298f894f..2b54a175 100644 --- a/fs/bench/bench_create_test.go +++ b/fs/bench/bench_create_test.go @@ -1,6 +1,7 @@ package bench_test import ( + "context" "fmt" "os" "testing" @@ -8,7 +9,6 @@ import ( "github.com/seaweedfs/fuse" "github.com/seaweedfs/fuse/fs" "github.com/seaweedfs/fuse/fs/fstestutil" - "golang.org/x/net/context" ) type dummyFile struct { diff --git a/fs/bench/bench_lookup_test.go b/fs/bench/bench_lookup_test.go index a74ecc0e..a012c96e 100644 --- a/fs/bench/bench_lookup_test.go +++ b/fs/bench/bench_lookup_test.go @@ -1,11 +1,10 @@ package bench_test import ( + "context" "os" "testing" - "golang.org/x/net/context" - "github.com/seaweedfs/fuse" "github.com/seaweedfs/fuse/fs" "github.com/seaweedfs/fuse/fs/fstestutil" diff --git a/fs/bench/bench_readwrite_test.go b/fs/bench/bench_readwrite_test.go index 186438e3..0cd34719 100644 --- a/fs/bench/bench_readwrite_test.go +++ b/fs/bench/bench_readwrite_test.go @@ -1,6 +1,7 @@ package bench_test import ( + "context" "io" "io/ioutil" "os" @@ -10,7 +11,6 @@ import ( "github.com/seaweedfs/fuse" "github.com/seaweedfs/fuse/fs" "github.com/seaweedfs/fuse/fs/fstestutil" - "golang.org/x/net/context" ) type benchConfig struct { diff --git a/fs/fstestutil/record/record.go b/fs/fstestutil/record/record.go index 05ea5058..7f0a21b1 100644 --- a/fs/fstestutil/record/record.go +++ b/fs/fstestutil/record/record.go @@ -1,12 +1,12 @@ package record // import "github.com/seaweedfs/fuse/fs/fstestutil/record" import ( + "context" "sync" "sync/atomic" "github.com/seaweedfs/fuse" "github.com/seaweedfs/fuse/fs" - "golang.org/x/net/context" ) // Writes gathers data from FUSE Write calls. diff --git a/fs/fstestutil/record/wait.go b/fs/fstestutil/record/wait.go index 34579d63..45e73efd 100644 --- a/fs/fstestutil/record/wait.go +++ b/fs/fstestutil/record/wait.go @@ -1,12 +1,12 @@ package record import ( + "context" "sync" "time" "github.com/seaweedfs/fuse" "github.com/seaweedfs/fuse/fs" - "golang.org/x/net/context" ) type nothing struct{} diff --git a/fs/fstestutil/testfs.go b/fs/fstestutil/testfs.go index 8250c09a..f55710e9 100644 --- a/fs/fstestutil/testfs.go +++ b/fs/fstestutil/testfs.go @@ -1,11 +1,11 @@ package fstestutil import ( + "context" "os" "github.com/seaweedfs/fuse" "github.com/seaweedfs/fuse/fs" - "golang.org/x/net/context" ) // SimpleFS is a trivial FS that just implements the Root method. diff --git a/fs/serve.go b/fs/serve.go index e7811ca6..4a4d8912 100644 --- a/fs/serve.go +++ b/fs/serve.go @@ -3,6 +3,7 @@ package fs // import "github.com/seaweedfs/fuse/fs" import ( + "context" "encoding/binary" "fmt" "hash/fnv" @@ -13,8 +14,6 @@ import ( "strings" "sync" "time" - - "golang.org/x/net/context" ) import ( @@ -346,7 +345,7 @@ type Config struct { func New(conn *fuse.Conn, config *Config) *Server { s := &Server{ conn: conn, - req: map[fuse.RequestID]*serveRequest{}, + req: map[fuse.RequestID]func(){}, nodeRef: map[Node]fuse.NodeID{}, dynamicInode: GenerateDynamicInode, } @@ -372,7 +371,7 @@ type Server struct { // state, protected by meta meta sync.Mutex - req map[fuse.RequestID]*serveRequest + req map[fuse.RequestID]func() // map request to cancel functions node []*serveNode nodeRef map[Node]fuse.NodeID handle []*serveHandle @@ -437,11 +436,6 @@ func Serve(c *fuse.Conn, fs FS) error { type nothing struct{} -type serveRequest struct { - Request fuse.Request - cancel func() -} - type serveNode struct { inode uint64 generation uint64 @@ -538,7 +532,9 @@ func (c *Server) dropNode(id fuse.NodeID, n uint64) (forget bool) { // this should only happen if refcounts kernel<->us disagree // *and* two ForgetRequests for the same node race each other; // this indicates a bug somewhere - c.debug(nodeRefcountDropBug{N: n, Node: id}) + if c.debug != nil { + c.debug(nodeRefcountDropBug{N: n, Node: id}) + } // we may end up triggering Forget twice, but that's better // than not even once, and that's the best we can do @@ -546,7 +542,9 @@ func (c *Server) dropNode(id fuse.NodeID, n uint64) (forget bool) { } if n > snode.refs { - c.debug(nodeRefcountDropBug{N: n, Refs: snode.refs, Node: id}) + if c.debug != nil { + c.debug(nodeRefcountDropBug{N: n, Refs: snode.refs, Node: id}) + } n = snode.refs } @@ -585,10 +583,12 @@ func (c *Server) getHandle(id fuse.HandleID) (shandle *serveHandle) { shandle = c.handle[uint(id)] } if shandle == nil { - c.debug(missingHandle{ - Handle: id, - MaxHandle: fuse.HandleID(len(c.handle)), - }) + if c.debug != nil { + c.debug(missingHandle{ + Handle: id, + MaxHandle: fuse.HandleID(len(c.handle)), + }) + } } return } @@ -774,13 +774,13 @@ func (c *Server) serve(r fuse.Request) { ctx = c.context(ctx, r) } - req := &serveRequest{Request: r, cancel: cancel} - - c.debug(request{ - Op: opName(r), - Request: r.Hdr(), - In: r, - }) + if c.debug != nil { + c.debug(request{ + Op: opName(r), + Request: r.Hdr(), + In: r, + }) + } var node Node var snode *serveNode c.meta.Lock() @@ -791,17 +791,19 @@ func (c *Server) serve(r fuse.Request) { } if snode == nil { c.meta.Unlock() - c.debug(response{ - Op: opName(r), - Request: logResponseHeader{ID: hdr.ID}, - Error: fuse.ESTALE.ErrnoName(), - // this is the only place that sets both Error and - // Out; not sure if i want to do that; might get rid - // of len(c.node) things altogether - Out: logMissingNode{ - MaxNode: fuse.NodeID(len(c.node)), - }, - }) + if c.debug != nil { + c.debug(response{ + Op: opName(r), + Request: logResponseHeader{ID: hdr.ID}, + Error: fuse.ESTALE.ErrnoName(), + // this is the only place that sets both Error and + // Out; not sure if i want to do that; might get rid + // of len(c.node) things altogether + Out: logMissingNode{ + MaxNode: fuse.NodeID(len(c.node)), + }, + }) + } r.RespondError(fuse.ESTALE) return } @@ -814,7 +816,7 @@ func (c *Server) serve(r fuse.Request) { // // TODO this might have been because of missing done() calls } else { - c.req[hdr.ID] = req + c.req[hdr.ID] = cancel } c.meta.Unlock() @@ -842,7 +844,9 @@ func (c *Server) serve(r fuse.Request) { } else { msg.Out = resp } - c.debug(msg) + if c.debug != nil { + c.debug(msg) + } c.meta.Lock() delete(c.req, hdr.ID) @@ -997,10 +1001,12 @@ func (c *Server) handleRequest(ctx context.Context, node Node, snode *serveNode, } c.meta.Unlock() if oldNode == nil { - c.debug(logLinkRequestOldNodeNotFound{ - Request: r.Hdr(), - In: r, - }) + if c.debug != nil { + c.debug(logLinkRequestOldNodeNotFound{ + Request: r.Hdr(), + In: r, + }) + } return fuse.EIO } n2, err := n.Link(ctx, r, oldNode.node) @@ -1322,10 +1328,12 @@ func (c *Server) handleRequest(ctx context.Context, node Node, snode *serveNode, } c.meta.Unlock() if newDirNode == nil { - c.debug(renameNewDirNodeNotFound{ - Request: r.Hdr(), - In: r, - }) + if c.debug != nil { + c.debug(renameNewDirNodeNotFound{ + Request: r.Hdr(), + In: r, + }) + } return fuse.EIO } n, ok := node.(NodeRenamer) @@ -1373,10 +1381,9 @@ func (c *Server) handleRequest(ctx context.Context, node Node, snode *serveNode, case *fuse.InterruptRequest: c.meta.Lock() - ireq := c.req[r.IntrID] - if ireq != nil && ireq.cancel != nil { - ireq.cancel() - ireq.cancel = nil + if cancel := c.req[r.IntrID]; cancel != nil { + cancel() + delete(c.req, r.IntrID) } c.meta.Unlock() done(nil) diff --git a/fs/serve_test.go b/fs/serve_test.go index 40a6e74c..7022a334 100644 --- a/fs/serve_test.go +++ b/fs/serve_test.go @@ -2,6 +2,7 @@ package fs_test import ( "bytes" + "context" "errors" "io" "io/ioutil" @@ -22,7 +23,6 @@ import ( "github.com/seaweedfs/fuse/fs/fstestutil/record" "github.com/seaweedfs/fuse/fuseutil" "github.com/seaweedfs/fuse/syscallx" - "golang.org/x/net/context" ) // TO TEST: diff --git a/fs/tree.go b/fs/tree.go index ab29a75e..47acb89d 100644 --- a/fs/tree.go +++ b/fs/tree.go @@ -3,11 +3,10 @@ package fs import ( + "context" "os" pathpkg "path" "strings" - - "golang.org/x/net/context" ) import ( diff --git a/fuse.go b/fuse.go index b6b0e6bc..bba52bf6 100644 --- a/fuse.go +++ b/fuse.go @@ -124,9 +124,10 @@ type Conn struct { // File handle for kernel communication. Only safe to access if // rio or wio is held. - dev *os.File - wio sync.RWMutex - rio sync.RWMutex + dev *os.File + wio sync.RWMutex + rio sync.Mutex + readbuf []byte // large buffer for reading kernel requests; guarded by rio // Protocol version negotiated with InitRequest/InitResponse. proto Protocol @@ -166,7 +167,8 @@ func Mount(dir string, options ...MountOption) (*Conn, error) { ready := make(chan struct{}, 1) c := &Conn{ - Ready: ready, + Ready: ready, + readbuf: make([]byte, maxBufSize), } f, err := mount(dir, &conf, ready, &c.MountError) if err != nil { @@ -291,8 +293,8 @@ type Header struct { Gid uint32 // group ID of process making request Pid uint32 // process ID of process making request - // for returning to reqPool - msg *message + msg *message // for returning to reqPool + buf [160]byte // pre-allocated buffer for response; 160 bytes is enough to handle most responses } func (h *Header) String() string { @@ -307,6 +309,14 @@ func (h *Header) noResponse() { putMessage(h.msg) } +func (h *Header) newBuffer(extra uintptr) buffer { + const hdrSize = unsafe.Sizeof(outHeader{}) + if int(hdrSize+extra) < len(h.buf) { + return buffer(h.buf[:hdrSize : hdrSize+extra]) + } + return make(buffer, hdrSize, hdrSize+extra) +} + func (h *Header) respond(msg []byte) { out := (*outHeader)(unsafe.Pointer(&msg[0])) out.Unique = uint64(h.ID) @@ -397,7 +407,7 @@ func (h *Header) RespondError(err error) { } // FUSE uses negative errors! // TODO: File bug report against OSXFUSE: positive error causes kernel panic. - buf := newBuffer(0) + buf := h.newBuffer(0) hOut := (*outHeader)(unsafe.Pointer(&buf[0])) hOut.Error = -int32(errno) h.respond(buf) @@ -406,7 +416,9 @@ func (h *Header) RespondError(err error) { // All requests read from the kernel, without data, are shorter than // this. var maxRequestSize = syscall.Getpagesize() -var bufSize = maxRequestSize + maxWrite +var maxBufSize = maxRequestSize + maxWrite + +const bufSize = 128 // 128 bytes is enough for the vast majority of messages. // reqPool is a pool of messages. // @@ -420,12 +432,16 @@ var reqPool = sync.Pool{ New: allocMessage, } -func allocMessage() interface{} { - m := &message{buf: make([]byte, bufSize)} +func makeMessage(n int) *message { + m := &message{buf: make([]byte, n)} m.hdr = (*inHeader)(unsafe.Pointer(&m.buf[0])) return m } +func allocMessage() interface{} { + return makeMessage(bufSize) +} + func getMessage(c *Conn) *message { m := reqPool.Get().(*message) m.conn = c @@ -433,6 +449,12 @@ func getMessage(c *Conn) *message { } func putMessage(m *message) { + // Don't save messages with giant buffers. + // It just creates memory pressure, which triggers GC activity, + // which then empties the sync.Pool. + if cap(m.buf) < bufSize || cap(m.buf) > bufSize*2 { + return + } m.buf = m.buf[:bufSize] m.conn = nil m.off = 0 @@ -546,16 +568,28 @@ func (c *Conn) Protocol() Protocol { // Caller must call either Request.Respond or Request.RespondError in // a reasonable time. Caller must not retain Request after that call. func (c *Conn) ReadRequest() (Request, error) { - m := getMessage(c) -loop: - c.rio.RLock() - n, err := syscall.Read(c.fd(), m.buf) - c.rio.RUnlock() - if err == syscall.EINTR { - // OSXFUSE sends EINTR to userspace when a request interrupt - // completed before it got sent to userspace? - goto loop + var m *message + var n int + var err error + c.rio.Lock() + for m == nil { + n, err = syscall.Read(c.fd(), c.readbuf) + if err == syscall.EINTR { + // OSXFUSE sends EINTR to userspace when a request interrupt + // completed before it got sent to userspace? + continue + } + if n <= bufSize { + m = getMessage(c) + } else { + m = makeMessage(n) + m.conn = c + } + if n > 0 { + copy(m.buf, c.readbuf[:n]) + } } + c.rio.Unlock() if err != nil && err != syscall.ENODEV { putMessage(m) return nil, err @@ -596,7 +630,9 @@ loop: var req Request switch m.hdr.Opcode { default: - Debug(noOpcode{Opcode: m.hdr.Opcode}) + if Debug != nil { + Debug(noOpcode{Opcode: m.hdr.Opcode}) + } goto unrecognized case opLookup: @@ -1049,7 +1085,9 @@ loop: return req, nil corrupt: - Debug(malformedMessage{}) + if Debug != nil { + Debug(malformedMessage{}) + } putMessage(m) return nil, fmt.Errorf("fuse: malformed message") @@ -1095,7 +1133,7 @@ func (c *Conn) writeToKernel(msg []byte) error { c.wio.RLock() defer c.wio.RUnlock() nn, err := syscall.Write(c.fd(), msg) - if err == nil && nn != len(msg) { + if err == nil && nn != len(msg) && Debug != nil { Debug(bugShortKernelWrite{ Written: int64(nn), Length: int64(len(msg)), @@ -1107,7 +1145,7 @@ func (c *Conn) writeToKernel(msg []byte) error { } func (c *Conn) respond(msg []byte) { - if err := c.writeToKernel(msg); err != nil { + if err := c.writeToKernel(msg); err != nil && Debug != nil { Debug(bugKernelWriteError{ Error: errorString(err), Stack: stack(), @@ -1226,7 +1264,7 @@ func (r *InitResponse) String() string { // Respond replies to the request with the given response. func (r *InitRequest) Respond(resp *InitResponse) { - buf := newBuffer(unsafe.Sizeof(initOut{})) + buf := r.newBuffer(unsafe.Sizeof(initOut{})) out := (*initOut)(buf.alloc(unsafe.Sizeof(initOut{}))) out.Major = resp.Library.Major out.Minor = resp.Library.Minor @@ -1255,7 +1293,7 @@ func (r *StatfsRequest) String() string { // Respond replies to the request with the given response. func (r *StatfsRequest) Respond(resp *StatfsResponse) { - buf := newBuffer(unsafe.Sizeof(statfsOut{})) + buf := r.newBuffer(unsafe.Sizeof(statfsOut{})) out := (*statfsOut)(buf.alloc(unsafe.Sizeof(statfsOut{}))) out.St = kstatfs{ Blocks: resp.Blocks, @@ -1308,7 +1346,7 @@ func (r *AccessRequest) String() string { // Respond replies to the request indicating that access is allowed. // To deny access, use RespondError. func (r *AccessRequest) Respond() { - buf := newBuffer(0) + buf := r.newBuffer(0) r.respond(buf) } @@ -1404,7 +1442,7 @@ func (r *GetattrRequest) String() string { // Respond replies to the request with the given response. func (r *GetattrRequest) Respond(resp *GetattrResponse) { size := attrOutSize(r.Header.Conn.proto) - buf := newBuffer(size) + buf := r.newBuffer(size) out := (*attrOut)(buf.alloc(size)) out.AttrValid = uint64(resp.Attr.Valid / time.Second) out.AttrValidNsec = uint32(resp.Attr.Valid % time.Second / time.Nanosecond) @@ -1447,12 +1485,12 @@ func (r *GetxattrRequest) String() string { // Respond replies to the request with the given response. func (r *GetxattrRequest) Respond(resp *GetxattrResponse) { if r.Size == 0 { - buf := newBuffer(unsafe.Sizeof(getxattrOut{})) + buf := r.newBuffer(unsafe.Sizeof(getxattrOut{})) out := (*getxattrOut)(buf.alloc(unsafe.Sizeof(getxattrOut{}))) out.Size = uint32(len(resp.Xattr)) r.respond(buf) } else { - buf := newBuffer(uintptr(len(resp.Xattr))) + buf := r.newBuffer(uintptr(len(resp.Xattr))) buf = append(buf, resp.Xattr...) r.respond(buf) } @@ -1483,12 +1521,12 @@ func (r *ListxattrRequest) String() string { // Respond replies to the request with the given response. func (r *ListxattrRequest) Respond(resp *ListxattrResponse) { if r.Size == 0 { - buf := newBuffer(unsafe.Sizeof(getxattrOut{})) + buf := r.newBuffer(unsafe.Sizeof(getxattrOut{})) out := (*getxattrOut)(buf.alloc(unsafe.Sizeof(getxattrOut{}))) out.Size = uint32(len(resp.Xattr)) r.respond(buf) } else { - buf := newBuffer(uintptr(len(resp.Xattr))) + buf := r.newBuffer(uintptr(len(resp.Xattr))) buf = append(buf, resp.Xattr...) r.respond(buf) } @@ -1525,7 +1563,7 @@ func (r *RemovexattrRequest) String() string { // Respond replies to the request, indicating that the attribute was removed. func (r *RemovexattrRequest) Respond() { - buf := newBuffer(0) + buf := r.newBuffer(0) r.respond(buf) } @@ -1570,7 +1608,7 @@ func (r *SetxattrRequest) String() string { // Respond replies to the request, indicating that the extended attribute was set. func (r *SetxattrRequest) Respond() { - buf := newBuffer(0) + buf := r.newBuffer(0) r.respond(buf) } @@ -1589,7 +1627,7 @@ func (r *LookupRequest) String() string { // Respond replies to the request with the given response. func (r *LookupRequest) Respond(resp *LookupResponse) { size := entryOutSize(r.Header.Conn.proto) - buf := newBuffer(size) + buf := r.newBuffer(size) out := (*entryOut)(buf.alloc(size)) out.Nodeid = uint64(resp.Node) out.Generation = resp.Generation @@ -1632,7 +1670,7 @@ func (r *OpenRequest) String() string { // Respond replies to the request with the given response. func (r *OpenRequest) Respond(resp *OpenResponse) { - buf := newBuffer(unsafe.Sizeof(openOut{})) + buf := r.newBuffer(unsafe.Sizeof(openOut{})) out := (*openOut)(buf.alloc(unsafe.Sizeof(openOut{}))) out.Fh = uint64(resp.Handle) out.OpenFlags = uint32(resp.Flags) @@ -1672,7 +1710,7 @@ func (r *CreateRequest) String() string { // Respond replies to the request with the given response. func (r *CreateRequest) Respond(resp *CreateResponse) { eSize := entryOutSize(r.Header.Conn.proto) - buf := newBuffer(eSize + unsafe.Sizeof(openOut{})) + buf := r.newBuffer(eSize + unsafe.Sizeof(openOut{})) e := (*entryOut)(buf.alloc(eSize)) e.Nodeid = uint64(resp.Node) @@ -1719,7 +1757,7 @@ func (r *MkdirRequest) String() string { // Respond replies to the request with the given response. func (r *MkdirRequest) Respond(resp *MkdirResponse) { size := entryOutSize(r.Header.Conn.proto) - buf := newBuffer(size) + buf := r.newBuffer(size) out := (*entryOut)(buf.alloc(size)) out.Nodeid = uint64(resp.Node) out.Generation = resp.Generation @@ -1760,7 +1798,7 @@ func (r *ReadRequest) String() string { // Respond replies to the request with the given response. func (r *ReadRequest) Respond(resp *ReadResponse) { - buf := newBuffer(uintptr(len(resp.Data))) + buf := r.newBuffer(uintptr(len(resp.Data))) buf = append(buf, resp.Data...) r.respond(buf) } @@ -1803,7 +1841,7 @@ func (r *ReleaseRequest) String() string { // Respond replies to the request, indicating that the handle has been released. func (r *ReleaseRequest) Respond() { - buf := newBuffer(0) + buf := r.newBuffer(0) r.respond(buf) } @@ -1822,7 +1860,7 @@ func (r *DestroyRequest) String() string { // Respond replies to the request. func (r *DestroyRequest) Respond() { - buf := newBuffer(0) + buf := r.newBuffer(0) r.respond(buf) } @@ -1962,7 +2000,7 @@ func (r *WriteRequest) MarshalJSON() ([]byte, error) { // Respond replies to the request with the given response. func (r *WriteRequest) Respond(resp *WriteResponse) { - buf := newBuffer(unsafe.Sizeof(writeOut{})) + buf := r.newBuffer(unsafe.Sizeof(writeOut{})) out := (*writeOut)(buf.alloc(unsafe.Sizeof(writeOut{}))) out.Size = uint32(resp.Size) r.respond(buf) @@ -2053,7 +2091,7 @@ func (r *SetattrRequest) String() string { // giving the updated attributes. func (r *SetattrRequest) Respond(resp *SetattrResponse) { size := attrOutSize(r.Header.Conn.proto) - buf := newBuffer(size) + buf := r.newBuffer(size) out := (*attrOut)(buf.alloc(size)) out.AttrValid = uint64(resp.Attr.Valid / time.Second) out.AttrValidNsec = uint32(resp.Attr.Valid % time.Second / time.Nanosecond) @@ -2088,7 +2126,7 @@ func (r *FlushRequest) String() string { // Respond replies to the request, indicating that the flush succeeded. func (r *FlushRequest) Respond() { - buf := newBuffer(0) + buf := r.newBuffer(0) r.respond(buf) } @@ -2108,7 +2146,7 @@ func (r *RemoveRequest) String() string { // Respond replies to the request, indicating that the file was removed. func (r *RemoveRequest) Respond() { - buf := newBuffer(0) + buf := r.newBuffer(0) r.respond(buf) } @@ -2127,7 +2165,7 @@ func (r *SymlinkRequest) String() string { // Respond replies to the request, indicating that the symlink was created. func (r *SymlinkRequest) Respond(resp *SymlinkResponse) { size := entryOutSize(r.Header.Conn.proto) - buf := newBuffer(size) + buf := r.newBuffer(size) out := (*entryOut)(buf.alloc(size)) out.Nodeid = uint64(resp.Node) out.Generation = resp.Generation @@ -2160,7 +2198,7 @@ func (r *ReadlinkRequest) String() string { } func (r *ReadlinkRequest) Respond(target string) { - buf := newBuffer(uintptr(len(target))) + buf := r.newBuffer(uintptr(len(target))) buf = append(buf, target...) r.respond(buf) } @@ -2180,7 +2218,7 @@ func (r *LinkRequest) String() string { func (r *LinkRequest) Respond(resp *LookupResponse) { size := entryOutSize(r.Header.Conn.proto) - buf := newBuffer(size) + buf := r.newBuffer(size) out := (*entryOut)(buf.alloc(size)) out.Nodeid = uint64(resp.Node) out.Generation = resp.Generation @@ -2206,7 +2244,7 @@ func (r *RenameRequest) String() string { } func (r *RenameRequest) Respond() { - buf := newBuffer(0) + buf := r.newBuffer(0) r.respond(buf) } @@ -2227,7 +2265,7 @@ func (r *MknodRequest) String() string { func (r *MknodRequest) Respond(resp *LookupResponse) { size := entryOutSize(r.Header.Conn.proto) - buf := newBuffer(size) + buf := r.newBuffer(size) out := (*entryOut)(buf.alloc(size)) out.Nodeid = uint64(resp.Node) out.Generation = resp.Generation @@ -2254,7 +2292,7 @@ func (r *FsyncRequest) String() string { } func (r *FsyncRequest) Respond() { - buf := newBuffer(0) + buf := r.newBuffer(0) r.respond(buf) } @@ -2299,6 +2337,6 @@ func (r *ExchangeDataRequest) String() string { } func (r *ExchangeDataRequest) Respond() { - buf := newBuffer(0) + buf := r.newBuffer(0) r.respond(buf) } diff --git a/options_daemon_timeout_test.go b/options_daemon_timeout_test.go index 55f9e2f9..a90eb075 100644 --- a/options_daemon_timeout_test.go +++ b/options_daemon_timeout_test.go @@ -5,6 +5,7 @@ package fuse_test import ( + "context" "os" "runtime" "syscall" @@ -14,7 +15,6 @@ import ( "github.com/seaweedfs/fuse" "github.com/seaweedfs/fuse/fs" "github.com/seaweedfs/fuse/fs/fstestutil" - "golang.org/x/net/context" ) type slowCreaterDir struct { diff --git a/options_test.go b/options_test.go index 91ca165a..002b81c3 100644 --- a/options_test.go +++ b/options_test.go @@ -1,6 +1,7 @@ package fuse_test import ( + "context" "os" "runtime" "syscall" @@ -9,7 +10,6 @@ import ( "github.com/seaweedfs/fuse" "github.com/seaweedfs/fuse/fs" "github.com/seaweedfs/fuse/fs/fstestutil" - "golang.org/x/net/context" ) func init() {