From 2cde92d5def8089db7ebc64c8fd3f7f94cd4834a Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Tue, 5 May 2015 10:29:48 +1000 Subject: [PATCH 1/4] Defined new contract. --- fuseops/convert.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fuseops/convert.go b/fuseops/convert.go index a9c6c1f..0b8729b 100644 --- a/fuseops/convert.go +++ b/fuseops/convert.go @@ -25,9 +25,12 @@ import ( // This function is an implementation detail of the fuse package, and must not // be called by anyone else. // -// Convert the supplied bazilfuse request struct to an Op, returning nil if it -// is unknown. finished will be called with the error supplied to o.Respond -// when the user invokes that method. +// Convert the supplied bazilfuse request struct to an Op. finished will be +// called with the error supplied to o.Respond when the user invokes that +// method. +// +// It is guaranteed that o != nil. If the op is unknown, a special unexported +// type will be used. func Convert( opCtx context.Context, r bazilfuse.Request, From 02983fd557b8858ecafbfe76fad1885be4dfc6c2 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Tue, 5 May 2015 10:32:22 +1000 Subject: [PATCH 2/4] Added unknownOp. --- fuseops/ops.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/fuseops/ops.go b/fuseops/ops.go index d80052a..aaa4601 100644 --- a/fuseops/ops.go +++ b/fuseops/ops.go @@ -40,10 +40,11 @@ type Op interface { Context() context.Context // Repond to the operation with the supplied error. If there is no error, set - // any necessary output fields and then call Respond(nil). + // any necessary output fields and then call Respond(nil). The user must not + // call with a nil error for unrecognized ops; instead, use ENOSYS. // - // Once this is invoked, you must exclude any further calls to any method of - // this op. + // Once this is invoked, the user must exclude any further calls to any + // method of this op. Respond(error) // Log information tied to this operation, with semantics equivalent to @@ -833,3 +834,13 @@ type ReleaseFileHandleOp struct { func (o *ReleaseFileHandleOp) toBazilfuseResponse() (bfResp interface{}) { return } + +// A sentinel used for unknown ops. The user is expected to respond with a +// non-nil error. +type unknownOp struct { + commonOp +} + +func (o *unknownOp) toBazilfuseResponse() (bfResp interface{}) { + panic(fmt.Sprintf("Should never get here for unknown op: %s", o.ShortDesc())) +} From 025ddafef1b7a6106bb54c673fd3a23646287848 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Tue, 5 May 2015 10:32:57 +1000 Subject: [PATCH 3/4] Updated Convert. --- fuseops/convert.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fuseops/convert.go b/fuseops/convert.go index 0b8729b..6d8fbbd 100644 --- a/fuseops/convert.go +++ b/fuseops/convert.go @@ -216,7 +216,9 @@ func Convert( co = &to.commonOp default: - return + to := &unknownOp{} + io = to + co = &to.commonOp } co.init(opCtx, io, r, logForOp, finished) From 64a7c6f973d1b3935443094c0be2ec7ae6271247 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Tue, 5 May 2015 10:33:47 +1000 Subject: [PATCH 4/4] Connection.ReadOp can assume Convert will not fail. --- connection.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/connection.go b/connection.go index 61b3453..637c2fe 100644 --- a/connection.go +++ b/connection.go @@ -127,7 +127,7 @@ func (c *Connection) ReadOp() (op fuseops.Op, err error) { continue } - // Convert it, if possible. + // Convert it. logForOp := func(calldepth int, format string, v ...interface{}) { c.log(opID, calldepth+1, format, v...) } @@ -135,12 +135,6 @@ func (c *Connection) ReadOp() (op fuseops.Op, err error) { finished := func(err error) { c.finishOp() } op = fuseops.Convert(c.parentCtx, bfReq, logForOp, finished) - if op == nil { - c.log(opID, 1, "-> ENOSYS: %v", bfReq) - bfReq.RespondError(ENOSYS) - continue - } - c.beginOp() return }