作者:postfi
项目:otar
func fusetestCommon(t *testing.T, fs *otaru.FileSystem, f func(mountpoint string)) {
bfuse.Debug = func(msg interface{}) {
log.Printf("fusedbg: %v", msg)
}
mountpoint := "/tmp/hoge"
if err := os.Mkdir(mountpoint, 0777); err != nil && !os.IsExist(err) {
log.Fatalf("Failed to create mountpoint: %v", err)
}
bfuse.Unmount(mountpoint)
done := make(chan bool)
ready := make(chan bool)
go func() {
if err := fuse.ServeFUSE("otaru-test", mountpoint, fs, ready); err != nil {
t.Errorf("ServeFUSE err: %v", err)
close(ready)
}
close(done)
}()
<-ready
f(mountpoint)
time.Sleep(100 * time.Millisecond)
if err := bfuse.Unmount(mountpoint); err != nil {
t.Errorf("umount failed: %v", err)
}
<-done
}
作者:netrob
项目:seaweedf
func runMount(cmd *Command, args []string) bool {
fmt.Printf("This is SeaweedFS version %s %s %s\n", util.VERSION, runtime.GOOS, runtime.GOARCH)
if *mountOptions.dir == "" {
fmt.Printf("Please specify the mount directory via \"-dir\"")
return false
}
c, err := fuse.Mount(*mountOptions.dir)
if err != nil {
glog.Fatal(err)
return false
}
OnInterrupt(func() {
fuse.Unmount(*mountOptions.dir)
c.Close()
})
err = fs.Serve(c, WFS{})
if err != nil {
fuse.Unmount(*mountOptions.dir)
}
// check if the mount process has an error to report
<-c.Ready
if err := c.MountError; err != nil {
glog.Fatal(err)
}
return true
}
作者:Gambatte-kudasa
项目:momf
func main() {
flag.Usage = Usage
flag.Parse()
if flag.NArg() != 2 {
Usage()
os.Exit(2)
}
mountpoint := flag.Arg(0)
c, err := fuse.Mount(
mountpoint,
fuse.FSName("MomFS"),
fuse.Subtype("momfs"),
fuse.LocalVolume(),
fuse.VolumeName("Mom file system"),
)
if err != nil {
log.Fatal(err)
}
defer c.Close()
sigintCh := make(chan os.Signal, 1)
signal.Notify(sigintCh, os.Interrupt)
go func() {
<-sigintCh
log.Printf("Program interrupted. Trying to unmount file system.\n")
err := fuse.Unmount(mountpoint)
if err != nil {
log.Println(err)
log.Println("Failed to unmount file system. Trying again..")
for {
<-time.Tick(1 * time.Second)
fuse.Unmount(mountpoint)
}
}
}()
err = fs.Serve(c, NewOrgFS())
if err != nil {
log.Fatal(err)
}
// check if the mount process has an error to report
<-c.Ready
if err := c.MountError; err != nil {
log.Fatal(err)
}
}
作者:chzye
项目:simsat
func main() {
config := NewConfig()
fuse.Unmount(config.Base)
os.MkdirAll(config.Base, 0777)
conn, err := process(config)
if err != nil {
logex.Fatal(err)
}
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill, syscall.SIGTERM, syscall.SIGHUP)
<-c
fuse.Unmount(config.Base)
conn.Close()
}
作者:GoogleCloudPlatfor
项目:cloudsql-prox
func (r *fsRoot) Close() error {
r.Lock()
if r.dst != nil {
// Since newConn only sends on dst while holding a reader lock, holding the
// writer lock is sufficient to ensure there are no pending sends on the
// channel when it is closed.
close(r.dst)
// Setting it to nil prevents further sends.
r.dst = nil
}
r.Unlock()
log.Printf("unmount %q", r.linkDir)
if err := fuse.Unmount(r.linkDir); err != nil {
return err
}
var errs bytes.Buffer
r.sockLock.Lock()
for _, c := range r.closers {
if err := c.Close(); err != nil {
fmt.Fprintln(&errs, err)
}
}
r.sockLock.Unlock()
if errs.Len() == 0 {
return nil
}
log.Printf("Close %q: %v", r.linkDir, errs.String())
return errors.New(errs.String())
}
作者:disorganize
项目:bri
// Close will wait until all I/O operations are done and unmount the fuse
// mount again.
func (m *Mount) Close() error {
if m.closed {
return nil
}
m.closed = true
log.Info("Umount fuse layer...")
for tries := 0; tries < 20; tries++ {
if err := fuse.Unmount(m.Dir); err != nil {
// log.Printf("unmount error: %v", err)
time.Sleep(100 * time.Millisecond)
continue
}
break
}
// Be sure to drain the error channel:
select {
case err := <-m.errors:
// Serve() had some error after some time:
if err != nil {
log.Warningf("fuse returned an error: %v", err)
}
}
// Be sure to pull the item from the channel:
<-m.done
if err := m.Conn.Close(); err != nil {
return err
}
return nil
}
作者:hajimehosh
项目:otar
func main() {
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
flag.Usage = Usage
flag.Parse()
cfg, err := facade.NewConfigFromTomlFile(*flagConfigFile)
if err != nil {
log.Printf("%v", err)
Usage()
os.Exit(2)
}
if flag.NArg() != 1 {
Usage()
os.Exit(2)
}
mountpoint := flag.Arg(0)
o, err := facade.NewOtaru(cfg, &facade.OneshotConfig{Mkfs: *flagMkfs})
if err != nil {
log.Printf("NewOtaru failed: %v", err)
os.Exit(1)
}
var muClose sync.Mutex
closeOtaruAndExit := func() {
muClose.Lock()
defer muClose.Unlock()
if err := bfuse.Unmount(mountpoint); err != nil {
log.Printf("umount err: %v", err)
}
if o != nil {
if err := o.Close(); err != nil {
log.Printf("Otaru.Close() returned errs: %v", err)
}
o = nil
}
os.Exit(0)
}
defer closeOtaruAndExit()
sigC := make(chan os.Signal, 1)
signal.Notify(sigC, os.Interrupt)
signal.Notify(sigC, syscall.SIGTERM)
go func() {
for s := range sigC {
log.Printf("Received signal: %v", s)
closeOtaruAndExit()
}
}()
bfuse.Debug = func(msg interface{}) {
log.Printf("fusedbg: %v", msg)
}
if err := fuse.ServeFUSE(mountpoint, o.FS, nil); err != nil {
log.Fatalf("ServeFUSE failed: %v", err)
}
log.Printf("ServeFUSE end!")
}
作者:AaronGoldma
项目:ccf
func ccfsUnmount(mountpoint string) {
err := fuse.Unmount(mountpoint)
if err != nil {
log.Printf("Could not unmount: %s", err)
}
log.Printf("Exit-kill program")
os.Exit(0)
}
作者:goze
项目:kbfs-bet
// Unmount tries to unmount normally and then force if unsuccessful
func (m ForceMounter) Unmount() (err error) {
// Try unmount
err = fuse.Unmount(m.dir)
if err != nil {
// Unmount failed, so let's try and force it.
err = m.forceUnmount()
}
return
}
作者:GoogleCloudPlatfor
项目:cloudsql-prox
func TestMain(m *testing.M) {
// Ensure this directory exists.
os.MkdirAll(dir, 0777)
// Unmount before the tests start, else they won't work correctly.
if err := fuse.Unmount(dir); err != nil {
log.Printf("couldn't unmount fuse directory %q: %v", dir, err)
}
ret := m.Run()
// Make sure to unmount at the end, so that we don't leave the system in an
// inconsistent state in case something weird happened.
if err := fuse.Unmount(dir); err != nil {
log.Printf("couldn't unmount fuse directory %q: %v", dir, err)
}
os.Exit(ret)
}
作者:chenchu
项目:cgroupf
func handleStopSignals(mountPoint string) {
s := make(chan os.Signal, 10)
signal.Notify(s, os.Interrupt, syscall.SIGTERM, syscall.SIGSTOP)
for range s {
if err := fuse.Unmount(mountPoint); err != nil {
log.Fatalf("Error umounting %s: %s", mountPoint, err)
}
os.Exit(0)
}
}
作者:jakop34
项目:torren
func exitSignalHandlers(fs *torrentfs.TorrentFS) {
c := make(chan os.Signal)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
for {
<-c
fs.Destroy()
err := fuse.Unmount(*mountDir)
if err != nil {
log.Print(err)
}
}
}
作者:GoogleCloudPlatfor
项目:cloudsql-prox
// NewConnSrc returns a source of new connections based on Lookups in the
// provided mount directory. If there isn't a directory located at tmpdir one
// is created. The second return parameter can be used to shutdown and release
// any resources. As a result of this shutdown, or during any other fatal
// error, the returned chan will be closed.
//
// The connset parameter is optional.
func NewConnSrc(mountdir, tmpdir string, connset *proxy.ConnSet) (<-chan proxy.Conn, io.Closer, error) {
if err := os.MkdirAll(tmpdir, 0777); err != nil {
return nil, nil, err
}
if err := fuse.Unmount(mountdir); err != nil {
// The error is too verbose to be useful to print out
}
log.Printf("Mounting %v...", mountdir)
c, err := fuse.Mount(mountdir, fuse.AllowOther())
if err != nil {
return nil, nil, fmt.Errorf("cannot mount %q: %v", mountdir, err)
}
log.Printf("Mounted %v", mountdir)
if connset == nil {
// Make a dummy one.
connset = proxy.NewConnSet()
}
conns := make(chan proxy.Conn, 1)
root := &fsRoot{
tmpDir: tmpdir,
linkDir: mountdir,
dst: conns,
links: make(map[string]symlink),
closers: []io.Closer{c},
connset: connset,
}
server := fs.New(c, &fs.Config{
Debug: func(msg interface{}) {
if false {
log.Print(msg)
}
},
})
go func() {
if err := server.Serve(root); err != nil {
log.Printf("serve %q exited due to error: %v", mountdir, err)
}
// The server exited but we don't know whether this is because of a
// graceful reason (via root.Close) or via an external force unmounting.
// Closing the root will ensure the 'dst' chan is closed correctly to
// signify that no new connections are possible.
if err := root.Close(); err != nil {
log.Printf("root.Close() error: %v", err)
}
log.Printf("FUSE exited")
}()
return conns, root, nil
}
作者:pombredann
项目:openstorag
func (v *volumeDriver) Unmount(volumeID api.VolumeID, mountpath string) error {
volume, err := v.GetVol(volumeID)
if err != nil {
return err
}
if volume.AttachPath == "" {
return fmt.Errorf("openstorage: device not mounted: %v", volumeID)
}
if err := fuse.Unmount(volume.AttachPath); err != nil {
return err
}
volume.AttachPath = ""
return v.UpdateVol(volume)
}
作者:ejemb
项目:fsprox
func (proxy *Proxy) Serve() error {
err := fuse.Unmount(proxy.Mountpoint)
if err != nil {
log.Print(err)
}
connection, err := fuse.Mount(proxy.Mountpoint)
if err != nil {
log.Fatal(err)
}
log.Printf("%+v", connection)
result := fs.Serve(connection, proxy)
log.Printf("Result %+v", result)
return result
}
作者:jgluc
项目:bazi
// Close unmounts the filesystem and waits for fs.Serve to return.
//
// TODO not true: Any returned error will be stored in Err.
//
// It is safe to call Close multiple times.
func (mnt *Mount) Close() {
if mnt.closed {
return
}
mnt.closed = true
for tries := 0; tries < 1000; tries++ {
err := fuse.Unmount(mnt.Dir)
if err != nil {
// TODO do more than log?
// TODO use lazy unmount where available?
log.Printf("unmount error: %v", err)
time.Sleep(10 * time.Millisecond)
continue
}
break
}
mnt.app.WaitForUnmount(&mnt.Info.VolumeID)
os.Remove(mnt.Dir)
}
作者:rjkroeg
项目:fus
// Close unmounts the filesystem and waits for fs.Serve to return. Any
// returned error will be stored in Err. It is safe to call Close
// multiple times.
func (mnt *Mount) Close() {
if mnt.closed {
return
}
mnt.closed = true
for tries := 0; tries < 1000; tries++ {
err := fuse.Unmount(mnt.Dir)
if err != nil {
// TODO do more than log?
log.Printf("unmount error: %v", err)
time.Sleep(10 * time.Millisecond)
continue
}
break
}
<-mnt.done
mnt.Conn.Close()
os.Remove(mnt.Dir)
}
作者:chzye
项目:simsat
func process(c *Config) (conn *fuse.Conn, err error) {
if err = fuse.Unmount(c.Base); err == nil {
logex.Info("last not unmount")
time.Sleep(1000 * time.Millisecond)
err = nil
} else {
err = nil
}
ops := []fuse.MountOption{
fuse.AllowOther(),
fuse.FSName(FsName),
fuse.LocalVolume(),
}
conn, err = fuse.Mount(c.Base, ops...)
if err != nil {
return nil, logex.Trace(err)
}
go fs.Serve(conn, NewTree("/", c.Target))
logex.Info("connected.")
return conn, nil
}
作者:qbi
项目:clien
// Unmount tries to unmount normally and then if force if unsuccessful.
func Unmount(dir string, force bool, log Log) error {
if !force {
mounted, err := IsMounted(dir, log)
if err != nil {
return err
}
if !mounted {
return fmt.Errorf("Not mounted")
}
}
log.Info("Trying to unmount: %s", dir)
err := fuse.Unmount(dir)
if err != nil {
if !force {
return err
}
// Unmount failed and we want to force it.
log.Info("Unmount %s failed: %s; We will try to force it", dir, err)
err = ForceUnmount(dir, log)
}
return err
}
作者:a2sd
项目:etcf
func main() {
mountpoint := "/Users/gtarcea/fuse/nginx"
fuse.Unmount(mountpoint)
conn, err := fuse.Mount(
mountpoint,
fuse.FSName("etcfs"),
fuse.Subtype("etcfs"),
fuse.LocalVolume(),
fuse.VolumeName("etcfs"),
)
if err != nil {
log.Fatal(err)
}
defer conn.Close()
err = fs.Serve(conn, etcfs.FS{})
<-conn.Ready
if conn.MountError != nil {
log.Fatal(conn.MountError)
}
}