Updated Mount.
parent
94292e49fe
commit
9f9e950d17
|
@ -22,6 +22,10 @@ import (
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// A Server is a function that reads ops from the supplied Connection,
|
||||||
|
// responding to them as appropriate.
|
||||||
|
type Server func(*Connection)
|
||||||
|
|
||||||
// A struct representing the status of a mount operation, with a method that
|
// A struct representing the status of a mount operation, with a method that
|
||||||
// waits for unmounting.
|
// waits for unmounting.
|
||||||
type MountedFileSystem struct {
|
type MountedFileSystem struct {
|
||||||
|
@ -43,22 +47,9 @@ func (mfs *MountedFileSystem) Dir() string {
|
||||||
return mfs.dir
|
return mfs.dir
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait until the mount point is ready to be used. After a successful return
|
|
||||||
// from this function, the contents of the mounted file system should be
|
|
||||||
// visible in the directory supplied to NewMountPoint. May be called multiple
|
|
||||||
// times.
|
|
||||||
func (mfs *MountedFileSystem) WaitForReady(ctx context.Context) error {
|
|
||||||
select {
|
|
||||||
case <-mfs.readyStatusAvailable:
|
|
||||||
return mfs.readyStatus
|
|
||||||
case <-ctx.Done():
|
|
||||||
return ctx.Err()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Block until a mounted file system has been unmounted. The return value will
|
// Block until a mounted file system has been unmounted. The return value will
|
||||||
// be non-nil if anything unexpected happened while serving. May be called
|
// be non-nil if anything unexpected happened while serving. May be called
|
||||||
// multiple times. Must not be called unless WaitForReady has returned nil.
|
// multiple times.
|
||||||
func (mfs *MountedFileSystem) Join(ctx context.Context) error {
|
func (mfs *MountedFileSystem) Join(ctx context.Context) error {
|
||||||
select {
|
select {
|
||||||
case <-mfs.joinStatusAvailable:
|
case <-mfs.joinStatusAvailable:
|
||||||
|
@ -69,8 +60,10 @@ func (mfs *MountedFileSystem) Join(ctx context.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to unmount the file system. Use Join to wait for it to actually be
|
// Attempt to unmount the file system. Use Join to wait for it to actually be
|
||||||
// unmounted. You must first call WaitForReady to ensure there is no race with
|
// unmounted.
|
||||||
// mounting.
|
//
|
||||||
|
// TODO(jacobsa): Kill this in favor of an Unmount free function that can be
|
||||||
|
// used even from outside of the daemon process.
|
||||||
func (mfs *MountedFileSystem) Unmount() error {
|
func (mfs *MountedFileSystem) Unmount() error {
|
||||||
return bazilfuse.Unmount(mfs.dir)
|
return bazilfuse.Unmount(mfs.dir)
|
||||||
}
|
}
|
||||||
|
@ -147,21 +140,15 @@ func (c *MountConfig) bazilfuseOptions() (opts []bazilfuse.MountOption) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to mount the supplied file system on the given directory.
|
// Attempt to mount a file system on the given directory, using the supplied
|
||||||
// mfs.WaitForReady() must be called to find out whether the mount was
|
// Server to serve connection requests. This function blocks until the file
|
||||||
// successful.
|
// system is successfully mounted. On some systems, this requires the supplied
|
||||||
//
|
// Server to make forward progress (in particular, to respond to
|
||||||
// TODO(jacobsa): Fold in WaitForReady. See issue #3.
|
// fuseops.InitOp).
|
||||||
func Mount(
|
func Mount(
|
||||||
dir string,
|
dir string,
|
||||||
fs FileSystem,
|
server Server,
|
||||||
config *MountConfig) (mfs *MountedFileSystem, err error) {
|
config *MountConfig) (mfs *MountedFileSystem, err error) {
|
||||||
// Create a server object.
|
|
||||||
server, err := newServer(fs)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize the struct.
|
// Initialize the struct.
|
||||||
mfs = &MountedFileSystem{
|
mfs = &MountedFileSystem{
|
||||||
dir: dir,
|
dir: dir,
|
||||||
|
@ -172,5 +159,9 @@ func Mount(
|
||||||
// Mount in the background.
|
// Mount in the background.
|
||||||
go mfs.mountAndServe(server, config.bazilfuseOptions())
|
go mfs.mountAndServe(server, config.bazilfuseOptions())
|
||||||
|
|
||||||
|
// Wait for ready.
|
||||||
|
<-mfs.readyStatusAvailable
|
||||||
|
err = mfs.readyStatus
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue