diff --git a/connection.go b/connection.go index e3791e64..9bd177f0 100644 --- a/connection.go +++ b/connection.go @@ -433,7 +433,7 @@ func (c *Connection) SetNotifyContext(op interface{}) (context.Context, error) { return nil, err } - ctx := context.Background() + var ctx context.Context switch op.(type) { case *fuseops.NotifyInvalInodeOp: @@ -543,17 +543,13 @@ func (c *Connection) Reply(ctx context.Context, opErr error) { // The NotifyKernel is same as Reply func of Connection.But the diff is // that the func only send to kernel. -func (c *Connection) NotifyKernel(ctx context.Context) { +func (c *Connection) NotifyKernel(opstate opState) { - // we should get outmsg from context - var key interface{} = contextKey - foo := ctx.Value(key) - state, ok := foo.(opState) - if !ok { - panic(fmt.Sprintf("Reply called with invalid context: %#v", ctx)) + if opstate == nil { + panic(fmt.Sprintf("must init notify op")) } - outMsg := state.outMsg + outMsg := opstate.outMsg defer c.putOutMessage(outMsg) c.debugLogger.Println("dev fd is:unique:notifycode ", c.dev.Fd(), outMsg.OutHeader().Unique, outMsg.OutHeader().Error) diff --git a/fuseutil/file_system.go b/fuseutil/file_system.go index ebd2ab26..edbd987b 100644 --- a/fuseutil/file_system.go +++ b/fuseutil/file_system.go @@ -133,11 +133,17 @@ func (s *fileSystemServer) InvalidateEntry(parent fuseops.InodeID, name string) Name: string(name), } ctx, _ := c.SetNotifyContext(op) + var key interface{} = contextKey + foo := ctx.Value(key) + opstate, ok := foo.(opState) + if !ok { + panic(fmt.Sprintf("notify op have invalid context: %#v", ctx)) + } s.opsInFlight.Add(1) - go func(ctx context.Context) { + go func(opstate OpState) { defer s.opsInFlight.Done() - c.NotifyKernel(ctx) - }(ctx) + c.NotifyKernel(opstate) + }(opstate) return nil } func (s *fileSystemServer) NotifyDelete( @@ -151,11 +157,17 @@ func (s *fileSystemServer) NotifyDelete( Name: string(name), } ctx, _ := c.SetNotifyContext(op) + var key interface{} = contextKey + foo := ctx.Value(key) + opstate, ok := foo.(opState) + if !ok { + panic(fmt.Sprintf("notify op have invalid context: %#v", ctx)) + } s.opsInFlight.Add(1) - go func(ctx context.Context) { + go func(opstate OpState) { defer s.opsInFlight.Done() - c.NotifyKernel(ctx) - }(ctx) + c.NotifyKernel(opstate) + }(opstate) return nil } @@ -170,11 +182,17 @@ func (s *fileSystemServer) InvalidateInode( Len: len, } ctx, _ := c.SetNotifyContext(op) + var key interface{} = contextKey + foo := ctx.Value(key) + opstate, ok := foo.(opState) + if !ok { + panic(fmt.Sprintf("notify op have invalid context: %#v", ctx)) + } s.opsInFlight.Add(1) - go func(ctx context.Context) { + go func(opstate OpState) { defer s.opsInFlight.Done() - c.NotifyKernel(ctx) - }(ctx) + c.NotifyKernel(opstate) + }(opstate) return nil }