Allow setting a parent context for all ops.
parent
a76742833c
commit
0985694a4b
|
@ -21,6 +21,8 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
"github.com/jacobsa/bazilfuse"
|
"github.com/jacobsa/bazilfuse"
|
||||||
"github.com/jacobsa/fuse/fuseops"
|
"github.com/jacobsa/fuse/fuseops"
|
||||||
)
|
)
|
||||||
|
@ -31,6 +33,9 @@ type Connection struct {
|
||||||
wrapped *bazilfuse.Conn
|
wrapped *bazilfuse.Conn
|
||||||
opsInFlight sync.WaitGroup
|
opsInFlight sync.WaitGroup
|
||||||
|
|
||||||
|
// The context from which all op contexts inherit.
|
||||||
|
parentCtx context.Context
|
||||||
|
|
||||||
// For logging purposes only.
|
// For logging purposes only.
|
||||||
nextOpID uint32
|
nextOpID uint32
|
||||||
}
|
}
|
||||||
|
@ -38,11 +43,13 @@ type Connection struct {
|
||||||
// Responsibility for closing the wrapped connection is transferred to the
|
// Responsibility for closing the wrapped connection is transferred to the
|
||||||
// result. You must call c.close() eventually.
|
// result. You must call c.close() eventually.
|
||||||
func newConnection(
|
func newConnection(
|
||||||
|
parentCtx context.Context,
|
||||||
logger *log.Logger,
|
logger *log.Logger,
|
||||||
wrapped *bazilfuse.Conn) (c *Connection, err error) {
|
wrapped *bazilfuse.Conn) (c *Connection, err error) {
|
||||||
c = &Connection{
|
c = &Connection{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
wrapped: wrapped,
|
wrapped: wrapped,
|
||||||
|
parentCtx: parentCtx,
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -115,7 +122,8 @@ func (c *Connection) ReadOp() (op fuseops.Op, err error) {
|
||||||
c.log(opID, calldepth+1, format, v...)
|
c.log(opID, calldepth+1, format, v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if op = fuseops.Convert(bfReq, logForOp, &c.opsInFlight); op == nil {
|
op = fuseops.Convert(c.parentCtx, bfReq, logForOp, &c.opsInFlight)
|
||||||
|
if op == nil {
|
||||||
c.log(opID, 1, "-> ENOSYS: %v", bfReq)
|
c.log(opID, 1, "-> ENOSYS: %v", bfReq)
|
||||||
bfReq.RespondError(ENOSYS)
|
bfReq.RespondError(ENOSYS)
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -25,12 +25,13 @@ import (
|
||||||
|
|
||||||
// A helper for embedding common behavior.
|
// A helper for embedding common behavior.
|
||||||
type commonOp struct {
|
type commonOp struct {
|
||||||
ctx context.Context
|
|
||||||
opType string
|
opType string
|
||||||
r bazilfuse.Request
|
r bazilfuse.Request
|
||||||
log func(int, string, ...interface{})
|
log func(int, string, ...interface{})
|
||||||
opsInFlight *sync.WaitGroup
|
opsInFlight *sync.WaitGroup
|
||||||
report reqtrace.ReportFunc
|
|
||||||
|
ctx context.Context
|
||||||
|
report reqtrace.ReportFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
func describeOpType(t reflect.Type) (desc string) {
|
func describeOpType(t reflect.Type) (desc string) {
|
||||||
|
@ -40,13 +41,13 @@ func describeOpType(t reflect.Type) (desc string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *commonOp) init(
|
func (o *commonOp) init(
|
||||||
|
ctx context.Context,
|
||||||
opType reflect.Type,
|
opType reflect.Type,
|
||||||
r bazilfuse.Request,
|
r bazilfuse.Request,
|
||||||
log func(int, string, ...interface{}),
|
log func(int, string, ...interface{}),
|
||||||
opsInFlight *sync.WaitGroup) {
|
opsInFlight *sync.WaitGroup) {
|
||||||
// Initialize basic fields.
|
// Initialize basic fields.
|
||||||
o.opType = describeOpType(opType)
|
o.opType = describeOpType(opType)
|
||||||
o.ctx = context.Background()
|
|
||||||
o.r = r
|
o.r = r
|
||||||
o.log = log
|
o.log = log
|
||||||
o.opsInFlight = opsInFlight
|
o.opsInFlight = opsInFlight
|
||||||
|
|
|
@ -19,6 +19,8 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
"github.com/jacobsa/bazilfuse"
|
"github.com/jacobsa/bazilfuse"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -28,6 +30,7 @@ import (
|
||||||
// This function is an implementation detail of the fuse package, and must not
|
// This function is an implementation detail of the fuse package, and must not
|
||||||
// be called by anyone else.
|
// be called by anyone else.
|
||||||
func Convert(
|
func Convert(
|
||||||
|
parentCtx context.Context,
|
||||||
r bazilfuse.Request,
|
r bazilfuse.Request,
|
||||||
logForOp func(int, string, ...interface{}),
|
logForOp func(int, string, ...interface{}),
|
||||||
opsInFlight *sync.WaitGroup) (o Op) {
|
opsInFlight *sync.WaitGroup) (o Op) {
|
||||||
|
@ -213,7 +216,7 @@ func Convert(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
co.init(reflect.TypeOf(o), r, logForOp, opsInFlight)
|
co.init(parentCtx, reflect.TypeOf(o), r, logForOp, opsInFlight)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,10 @@ func (mfs *MountedFileSystem) Join(ctx context.Context) error {
|
||||||
|
|
||||||
// Optional configuration accepted by Mount.
|
// Optional configuration accepted by Mount.
|
||||||
type MountConfig struct {
|
type MountConfig struct {
|
||||||
|
// The context from which every op read from the connetion by the sever
|
||||||
|
// should inherit. If nil, context.Background() will be used.
|
||||||
|
OpContext context.Context
|
||||||
|
|
||||||
// OS X only.
|
// OS X only.
|
||||||
//
|
//
|
||||||
// Normally on OS X we mount with the novncache option
|
// Normally on OS X we mount with the novncache option
|
||||||
|
@ -127,8 +131,14 @@ func Mount(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Choose a parent context for ops.
|
||||||
|
opContext := config.OpContext
|
||||||
|
if opContext == nil {
|
||||||
|
opContext = context.Background()
|
||||||
|
}
|
||||||
|
|
||||||
// Create our own Connection object wrapping it.
|
// Create our own Connection object wrapping it.
|
||||||
connection, err := newConnection(logger, bfConn)
|
connection, err := newConnection(opContext, logger, bfConn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
bfConn.Close()
|
bfConn.Close()
|
||||||
err = fmt.Errorf("newConnection: %v", err)
|
err = fmt.Errorf("newConnection: %v", err)
|
||||||
|
|
Loading…
Reference in New Issue