Use package fuseshim in package fuse.
parent
8c94df5ce9
commit
81dee67b51
|
@ -23,15 +23,15 @@ import (
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
"github.com/jacobsa/bazilfuse"
|
|
||||||
"github.com/jacobsa/fuse/fuseops"
|
"github.com/jacobsa/fuse/fuseops"
|
||||||
|
"github.com/jacobsa/fuse/internal/fuseshim"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A connection to the fuse kernel process.
|
// A connection to the fuse kernel process.
|
||||||
type Connection struct {
|
type Connection struct {
|
||||||
debugLogger *log.Logger
|
debugLogger *log.Logger
|
||||||
errorLogger *log.Logger
|
errorLogger *log.Logger
|
||||||
wrapped *bazilfuse.Conn
|
wrapped *fuseshim.Conn
|
||||||
|
|
||||||
// The context from which all op contexts inherit.
|
// The context from which all op contexts inherit.
|
||||||
parentCtx context.Context
|
parentCtx context.Context
|
||||||
|
@ -41,11 +41,11 @@ type Connection struct {
|
||||||
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
|
|
||||||
// A map from bazilfuse request ID (*not* the op ID for logging used above)
|
// A map from fuseshim request ID (*not* the op ID for logging used above) to
|
||||||
// to a function that cancel's its associated context.
|
// a function that cancel's its associated context.
|
||||||
//
|
//
|
||||||
// GUARDED_BY(mu)
|
// GUARDED_BY(mu)
|
||||||
cancelFuncs map[bazilfuse.RequestID]func()
|
cancelFuncs map[fuseshim.RequestID]func()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Responsibility for closing the wrapped connection is transferred to the
|
// Responsibility for closing the wrapped connection is transferred to the
|
||||||
|
@ -56,13 +56,13 @@ func newConnection(
|
||||||
parentCtx context.Context,
|
parentCtx context.Context,
|
||||||
debugLogger *log.Logger,
|
debugLogger *log.Logger,
|
||||||
errorLogger *log.Logger,
|
errorLogger *log.Logger,
|
||||||
wrapped *bazilfuse.Conn) (c *Connection, err error) {
|
wrapped *fuseshim.Conn) (c *Connection, err error) {
|
||||||
c = &Connection{
|
c = &Connection{
|
||||||
debugLogger: debugLogger,
|
debugLogger: debugLogger,
|
||||||
errorLogger: errorLogger,
|
errorLogger: errorLogger,
|
||||||
wrapped: wrapped,
|
wrapped: wrapped,
|
||||||
parentCtx: parentCtx,
|
parentCtx: parentCtx,
|
||||||
cancelFuncs: make(map[bazilfuse.RequestID]func()),
|
cancelFuncs: make(map[fuseshim.RequestID]func()),
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -104,7 +104,7 @@ func (c *Connection) debugLog(
|
||||||
|
|
||||||
// LOCKS_EXCLUDED(c.mu)
|
// LOCKS_EXCLUDED(c.mu)
|
||||||
func (c *Connection) recordCancelFunc(
|
func (c *Connection) recordCancelFunc(
|
||||||
reqID bazilfuse.RequestID,
|
reqID fuseshim.RequestID,
|
||||||
f func()) {
|
f func()) {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
|
@ -117,13 +117,13 @@ func (c *Connection) recordCancelFunc(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up state for an op that is about to be returned to the user, given its
|
// Set up state for an op that is about to be returned to the user, given its
|
||||||
// underlying bazilfuse request.
|
// underlying fuseshim request.
|
||||||
//
|
//
|
||||||
// Return a context that should be used for the op.
|
// Return a context that should be used for the op.
|
||||||
//
|
//
|
||||||
// LOCKS_EXCLUDED(c.mu)
|
// LOCKS_EXCLUDED(c.mu)
|
||||||
func (c *Connection) beginOp(
|
func (c *Connection) beginOp(
|
||||||
bfReq bazilfuse.Request) (ctx context.Context) {
|
bfReq fuseshim.Request) (ctx context.Context) {
|
||||||
reqID := bfReq.Hdr().ID
|
reqID := bfReq.Hdr().ID
|
||||||
|
|
||||||
// Start with the parent context.
|
// Start with the parent context.
|
||||||
|
@ -137,7 +137,7 @@ func (c *Connection) beginOp(
|
||||||
// should not record any state keyed on their ID.
|
// should not record any state keyed on their ID.
|
||||||
//
|
//
|
||||||
// Cf. https://github.com/osxfuse/osxfuse/issues/208
|
// Cf. https://github.com/osxfuse/osxfuse/issues/208
|
||||||
if _, ok := bfReq.(*bazilfuse.ForgetRequest); !ok {
|
if _, ok := bfReq.(*fuseshim.ForgetRequest); !ok {
|
||||||
var cancel func()
|
var cancel func()
|
||||||
ctx, cancel = context.WithCancel(ctx)
|
ctx, cancel = context.WithCancel(ctx)
|
||||||
c.recordCancelFunc(reqID, cancel)
|
c.recordCancelFunc(reqID, cancel)
|
||||||
|
@ -147,12 +147,12 @@ func (c *Connection) beginOp(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean up all state associated with an op to which the user has responded,
|
// Clean up all state associated with an op to which the user has responded,
|
||||||
// given its underlying bazilfuse request. This must be called before a
|
// given its underlying fuseshim request. This must be called before a response
|
||||||
// response is sent to the kernel, to avoid a race where the request's ID might
|
// is sent to the kernel, to avoid a race where the request's ID might be
|
||||||
// be reused by osxfuse.
|
// reused by osxfuse.
|
||||||
//
|
//
|
||||||
// LOCKS_EXCLUDED(c.mu)
|
// LOCKS_EXCLUDED(c.mu)
|
||||||
func (c *Connection) finishOp(bfReq bazilfuse.Request) {
|
func (c *Connection) finishOp(bfReq fuseshim.Request) {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ func (c *Connection) finishOp(bfReq bazilfuse.Request) {
|
||||||
//
|
//
|
||||||
// Special case: we don't do this for Forget requests. See the note in
|
// Special case: we don't do this for Forget requests. See the note in
|
||||||
// beginOp above.
|
// beginOp above.
|
||||||
if _, ok := bfReq.(*bazilfuse.ForgetRequest); !ok {
|
if _, ok := bfReq.(*fuseshim.ForgetRequest); !ok {
|
||||||
cancel, ok := c.cancelFuncs[reqID]
|
cancel, ok := c.cancelFuncs[reqID]
|
||||||
if !ok {
|
if !ok {
|
||||||
panic(fmt.Sprintf("Unknown request ID in finishOp: %v", reqID))
|
panic(fmt.Sprintf("Unknown request ID in finishOp: %v", reqID))
|
||||||
|
@ -176,7 +176,7 @@ func (c *Connection) finishOp(bfReq bazilfuse.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// LOCKS_EXCLUDED(c.mu)
|
// LOCKS_EXCLUDED(c.mu)
|
||||||
func (c *Connection) handleInterrupt(req *bazilfuse.InterruptRequest) {
|
func (c *Connection) handleInterrupt(req *fuseshim.InterruptRequest) {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
|
|
||||||
|
@ -212,8 +212,8 @@ func (c *Connection) handleInterrupt(req *bazilfuse.InterruptRequest) {
|
||||||
func (c *Connection) ReadOp() (op fuseops.Op, err error) {
|
func (c *Connection) ReadOp() (op fuseops.Op, err error) {
|
||||||
// Keep going until we find a request we know how to convert.
|
// Keep going until we find a request we know how to convert.
|
||||||
for {
|
for {
|
||||||
// Read a bazilfuse request.
|
// Read a fuseshim request.
|
||||||
var bfReq bazilfuse.Request
|
var bfReq fuseshim.Request
|
||||||
bfReq, err = c.wrapped.ReadRequest()
|
bfReq, err = c.wrapped.ReadRequest()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -230,14 +230,14 @@ func (c *Connection) ReadOp() (op fuseops.Op, err error) {
|
||||||
// Special case: responding to statfs is required to make mounting work on
|
// Special case: responding to statfs is required to make mounting work on
|
||||||
// OS X. We don't currently expose the capability for the file system to
|
// OS X. We don't currently expose the capability for the file system to
|
||||||
// intercept this.
|
// intercept this.
|
||||||
if statfsReq, ok := bfReq.(*bazilfuse.StatfsRequest); ok {
|
if statfsReq, ok := bfReq.(*fuseshim.StatfsRequest); ok {
|
||||||
c.debugLog(opID, 1, "-> (Statfs) OK")
|
c.debugLog(opID, 1, "-> (Statfs) OK")
|
||||||
statfsReq.Respond(&bazilfuse.StatfsResponse{})
|
statfsReq.Respond(&fuseshim.StatfsResponse{})
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special case: handle interrupt requests.
|
// Special case: handle interrupt requests.
|
||||||
if interruptReq, ok := bfReq.(*bazilfuse.InterruptRequest); ok {
|
if interruptReq, ok := bfReq.(*fuseshim.InterruptRequest); ok {
|
||||||
c.handleInterrupt(interruptReq)
|
c.handleInterrupt(interruptReq)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
16
errors.go
16
errors.go
|
@ -17,17 +17,17 @@ package fuse
|
||||||
import (
|
import (
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/jacobsa/bazilfuse"
|
"github.com/jacobsa/fuse/internal/fuseshim"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Errors corresponding to kernel error numbers. These may be treated
|
// Errors corresponding to kernel error numbers. These may be treated
|
||||||
// specially by fuseops.Op.Respond methods.
|
// specially by fuseops.Op.Respond methods.
|
||||||
EEXIST = bazilfuse.EEXIST
|
EEXIST = fuseshim.EEXIST
|
||||||
EINVAL = bazilfuse.Errno(syscall.EINVAL)
|
EINVAL = fuseshim.Errno(syscall.EINVAL)
|
||||||
EIO = bazilfuse.EIO
|
EIO = fuseshim.EIO
|
||||||
ENOENT = bazilfuse.ENOENT
|
ENOENT = fuseshim.ENOENT
|
||||||
ENOSYS = bazilfuse.ENOSYS
|
ENOSYS = fuseshim.ENOSYS
|
||||||
ENOTDIR = bazilfuse.Errno(syscall.ENOTDIR)
|
ENOTDIR = fuseshim.Errno(syscall.ENOTDIR)
|
||||||
ENOTEMPTY = bazilfuse.Errno(syscall.ENOTEMPTY)
|
ENOTEMPTY = fuseshim.Errno(syscall.ENOTEMPTY)
|
||||||
)
|
)
|
||||||
|
|
|
@ -19,7 +19,8 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/jacobsa/bazilfuse"
|
"github.com/jacobsa/fuse/internal/fuseshim"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -111,13 +112,13 @@ type MountConfig struct {
|
||||||
Options map[string]string
|
Options map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert to mount options to be passed to package bazilfuse.
|
// Convert to mount options to be passed to package fuseshim.
|
||||||
func (c *MountConfig) bazilfuseOptions() (opts []bazilfuse.MountOption) {
|
func (c *MountConfig) bazilfuseOptions() (opts []fuseshim.MountOption) {
|
||||||
isDarwin := runtime.GOOS == "darwin"
|
isDarwin := runtime.GOOS == "darwin"
|
||||||
|
|
||||||
// Enable permissions checking in the kernel. See the comments on
|
// Enable permissions checking in the kernel. See the comments on
|
||||||
// InodeAttributes.Mode.
|
// InodeAttributes.Mode.
|
||||||
opts = append(opts, bazilfuse.SetOption("default_permissions", ""))
|
opts = append(opts, fuseshim.SetOption("default_permissions", ""))
|
||||||
|
|
||||||
// HACK(jacobsa): Work around what appears to be a bug in systemd v219, as
|
// HACK(jacobsa): Work around what appears to be a bug in systemd v219, as
|
||||||
// shipped in Ubuntu 15.04, where it automatically unmounts any file system
|
// shipped in Ubuntu 15.04, where it automatically unmounts any file system
|
||||||
|
@ -135,17 +136,17 @@ func (c *MountConfig) bazilfuseOptions() (opts []bazilfuse.MountOption) {
|
||||||
|
|
||||||
// Special file system name?
|
// Special file system name?
|
||||||
if fsname != "" {
|
if fsname != "" {
|
||||||
opts = append(opts, bazilfuse.FSName(fsname))
|
opts = append(opts, fuseshim.FSName(fsname))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read only?
|
// Read only?
|
||||||
if c.ReadOnly {
|
if c.ReadOnly {
|
||||||
opts = append(opts, bazilfuse.ReadOnly())
|
opts = append(opts, fuseshim.ReadOnly())
|
||||||
}
|
}
|
||||||
|
|
||||||
// OS X: set novncache when appropriate.
|
// OS X: set novncache when appropriate.
|
||||||
if isDarwin && !c.EnableVnodeCaching {
|
if isDarwin && !c.EnableVnodeCaching {
|
||||||
opts = append(opts, bazilfuse.SetOption("novncache", ""))
|
opts = append(opts, fuseshim.SetOption("novncache", ""))
|
||||||
}
|
}
|
||||||
|
|
||||||
// OS X: disable the use of "Apple Double" (._foo and .DS_Store) files, which
|
// OS X: disable the use of "Apple Double" (._foo and .DS_Store) files, which
|
||||||
|
@ -154,7 +155,7 @@ func (c *MountConfig) bazilfuseOptions() (opts []bazilfuse.MountOption) {
|
||||||
//
|
//
|
||||||
// Cf. https://github.com/osxfuse/osxfuse/wiki/Mount-options
|
// Cf. https://github.com/osxfuse/osxfuse/wiki/Mount-options
|
||||||
if isDarwin {
|
if isDarwin {
|
||||||
opts = append(opts, bazilfuse.SetOption("noappledouble", ""))
|
opts = append(opts, fuseshim.SetOption("noappledouble", ""))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ask the Linux kernel for larger read requests.
|
// Ask the Linux kernel for larger read requests.
|
||||||
|
@ -175,11 +176,11 @@ func (c *MountConfig) bazilfuseOptions() (opts []bazilfuse.MountOption) {
|
||||||
//
|
//
|
||||||
// Reading a page at a time is a drag. Ask for a larger size.
|
// Reading a page at a time is a drag. Ask for a larger size.
|
||||||
const maxReadahead = 1 << 20
|
const maxReadahead = 1 << 20
|
||||||
opts = append(opts, bazilfuse.MaxReadahead(maxReadahead))
|
opts = append(opts, fuseshim.MaxReadahead(maxReadahead))
|
||||||
|
|
||||||
// Last but not least: other user-supplied options.
|
// Last but not least: other user-supplied options.
|
||||||
for k, v := range c.Options {
|
for k, v := range c.Options {
|
||||||
opts = append(opts, bazilfuse.SetOption(k, v))
|
opts = append(opts, fuseshim.SetOption(k, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -198,10 +199,10 @@ func Mount(
|
||||||
joinStatusAvailable: make(chan struct{}),
|
joinStatusAvailable: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open a bazilfuse connection.
|
// Open a fuseshim connection.
|
||||||
bfConn, err := bazilfuse.Mount(mfs.dir, config.bazilfuseOptions()...)
|
bfConn, err := fuseshim.Mount(mfs.dir, config.bazilfuseOptions()...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("bazilfuse.Mount: %v", err)
|
err = fmt.Errorf("fuseshim.Mount: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,10 +14,8 @@
|
||||||
|
|
||||||
package fuse
|
package fuse
|
||||||
|
|
||||||
import "github.com/jacobsa/bazilfuse"
|
|
||||||
|
|
||||||
// Attempt to unmount the file system whose mount point is the supplied
|
// Attempt to unmount the file system whose mount point is the supplied
|
||||||
// directory.
|
// directory.
|
||||||
func Unmount(dir string) error {
|
func Unmount(dir string) error {
|
||||||
return bazilfuse.Unmount(dir)
|
return fuseshim.Unmount(dir)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue