Updated newConnection.

geesefs-0-30-9
Aaron Jacobs 2015-07-24 16:01:45 +10:00
parent baa7c29fad
commit 2860526871
2 changed files with 22 additions and 7 deletions

View File

@ -58,15 +58,27 @@ type Connection struct {
cancelFuncs map[uint64]func() cancelFuncs map[uint64]func()
} }
// Responsibility for closing the wrapped connection is transferred to the // Create a connection wrapping the supplied file descriptor connected to the
// result. You must call c.close() eventually. // kernel. You must eventually call c.close().
// //
// The loggers may be nil. // The loggers may be nil.
func newConnection( func newConnection(
parentCtx context.Context, parentCtx context.Context,
debugLogger *log.Logger, debugLogger *log.Logger,
errorLogger *log.Logger, errorLogger *log.Logger,
wrapped *fuseshim.Conn) (c *Connection, err error) { dev *os.File) (c *Connection, err error) {
// Create an initialized a wrapped fuseshim connection.
wrapped := &fuseshim.Conn{
Dev: dev,
}
err = fuseshim.InitMount(wrapped, TODO, TODO)
if err != nil {
err = fmt.Errorf("fuseshim.InitMount: %v", err)
return
}
// Create an object wrapping it.
c = &Connection{ c = &Connection{
debugLogger: debugLogger, debugLogger: debugLogger,
errorLogger: errorLogger, errorLogger: errorLogger,

View File

@ -164,7 +164,7 @@ func Mount(dir string, options ...MountOption) (*Conn, error) {
} }
c.Dev = f c.Dev = f
if err := initMount(c, &conf); err != nil { if err := InitMount(c, conf.maxReadahead, conf.initFlags); err != nil {
c.Close() c.Close()
return nil, err return nil, err
} }
@ -181,7 +181,10 @@ func (e *OldVersionError) Error() string {
return fmt.Sprintf("kernel FUSE version is too old: %v < %v", e.Kernel, e.LibraryMin) return fmt.Sprintf("kernel FUSE version is too old: %v < %v", e.Kernel, e.LibraryMin)
} }
func initMount(c *Conn, conf *mountConfig) error { func InitMount(
c *Conn,
maxReadahead uint32,
initFlags fusekernel.InitFlags) error {
req, err := c.ReadRequest() req, err := c.ReadRequest()
if err != nil { if err != nil {
if err == io.EOF { if err == io.EOF {
@ -213,9 +216,9 @@ func initMount(c *Conn, conf *mountConfig) error {
s := &InitResponse{ s := &InitResponse{
Library: proto, Library: proto,
MaxReadahead: conf.maxReadahead, MaxReadahead: maxReadahead,
MaxWrite: maxWrite, MaxWrite: maxWrite,
Flags: fusekernel.InitBigWrites | conf.initFlags, Flags: fusekernel.InitBigWrites | initFlags,
} }
r.Respond(s) r.Respond(s)
return nil return nil