Skip to content

Commit

Permalink
remove context partly
Browse files Browse the repository at this point in the history
  • Loading branch information
inevity committed Sep 27, 2019
1 parent 13ad385 commit 7fd51d8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
14 changes: 5 additions & 9 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
36 changes: 27 additions & 9 deletions fuseutil/file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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

}
Expand All @@ -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

}
Expand Down

0 comments on commit 7fd51d8

Please sign in to comment.