Skip to content

Commit 42473bf

Browse files
committed
remove context partly
1 parent 13ad385 commit 42473bf

2 files changed

Lines changed: 32 additions & 18 deletions

File tree

connection.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ func (c *Connection) SetNotifyContext(op interface{}) (context.Context, error) {
433433
return nil, err
434434
}
435435

436-
ctx := context.Background()
436+
var ctx context.Context
437437

438438
switch op.(type) {
439439
case *fuseops.NotifyInvalInodeOp:
@@ -543,17 +543,13 @@ func (c *Connection) Reply(ctx context.Context, opErr error) {
543543

544544
// The NotifyKernel is same as Reply func of Connection.But the diff is
545545
// that the func only send to kernel.
546-
func (c *Connection) NotifyKernel(ctx context.Context) {
546+
func (c *Connection) NotifyKernel(opstate opState) {
547547

548-
// we should get outmsg from context
549-
var key interface{} = contextKey
550-
foo := ctx.Value(key)
551-
state, ok := foo.(opState)
552-
if !ok {
553-
panic(fmt.Sprintf("Reply called with invalid context: %#v", ctx))
548+
if !opstate {
549+
panic(fmt.Sprintf("must init notify op"))
554550
}
555551

556-
outMsg := state.outMsg
552+
outMsg := opstate.outMsg
557553
defer c.putOutMessage(outMsg)
558554

559555
c.debugLogger.Println("dev fd is:unique:notifycode ", c.dev.Fd(), outMsg.OutHeader().Unique, outMsg.OutHeader().Error)

fuseutil/file_system.go

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,17 @@ func (s *fileSystemServer) InvalidateEntry(parent fuseops.InodeID, name string)
133133
Name: string(name),
134134
}
135135
ctx, _ := c.SetNotifyContext(op)
136+
var key interface{} = contextKey
137+
foo := ctx.Value(key)
138+
opstate, ok := foo.(opState)
139+
if !ok {
140+
panic(fmt.Sprintf("notify op have invalid context: %#v", ctx))
141+
}
136142
s.opsInFlight.Add(1)
137-
go func(ctx context.Context) {
143+
go func(opstate OpState) {
138144
defer s.opsInFlight.Done()
139-
c.NotifyKernel(ctx)
140-
}(ctx)
145+
c.NotifyKernel(opstate)
146+
}(opstate)
141147
return nil
142148
}
143149
func (s *fileSystemServer) NotifyDelete(
@@ -151,11 +157,17 @@ func (s *fileSystemServer) NotifyDelete(
151157
Name: string(name),
152158
}
153159
ctx, _ := c.SetNotifyContext(op)
160+
var key interface{} = contextKey
161+
foo := ctx.Value(key)
162+
opstate, ok := foo.(opState)
163+
if !ok {
164+
panic(fmt.Sprintf("notify op have invalid context: %#v", ctx))
165+
}
154166
s.opsInFlight.Add(1)
155-
go func(ctx context.Context) {
167+
go func(opstate OpState) {
156168
defer s.opsInFlight.Done()
157-
c.NotifyKernel(ctx)
158-
}(ctx)
169+
c.NotifyKernel(opstate)
170+
}(opstate)
159171
return nil
160172

161173
}
@@ -170,11 +182,17 @@ func (s *fileSystemServer) InvalidateInode(
170182
Len: len,
171183
}
172184
ctx, _ := c.SetNotifyContext(op)
185+
var key interface{} = contextKey
186+
foo := ctx.Value(key)
187+
opstate, ok := foo.(opState)
188+
if !ok {
189+
panic(fmt.Sprintf("notify op have invalid context: %#v", ctx))
190+
}
173191
s.opsInFlight.Add(1)
174-
go func(ctx context.Context) {
192+
go func(opstate OpState) {
175193
defer s.opsInFlight.Done()
176-
c.NotifyKernel(ctx)
177-
}(ctx)
194+
c.NotifyKernel(opstate)
195+
}(opstate)
178196
return nil
179197

180198
}

0 commit comments

Comments
 (0)