Browse Source

clean up previously mounted folder

pull/2668/head
chrislu 3 years ago
parent
commit
7a0c35674c
  1. 7
      go.mod
  2. 1
      go.sum
  3. 7
      weed/command/mount2_std.go
  4. 6
      weed/mount/unmount/unmount.go
  5. 21
      weed/mount/unmount/unmount_linux.go
  6. 18
      weed/mount/unmount/unmount_std.go

7
go.mod

@ -162,14 +162,17 @@ require (
modernc.org/token v1.0.0 // indirect
)
require github.com/fluent/fluent-logger-golang v1.8.0
require (
github.com/fluent/fluent-logger-golang v1.8.0
github.com/hanwen/go-fuse v1.0.0
github.com/hanwen/go-fuse/v2 v2.1.0
)
require (
cloud.google.com/go/kms v1.0.0 // indirect
github.com/DataDog/zstd v1.3.6-0.20190409195224-796139022798 // indirect
github.com/d4l3k/messagediff v1.2.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/hanwen/go-fuse/v2 v2.1.0 // indirect
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
github.com/jcmturner/goidentity/v6 v6.0.1 // indirect

1
go.sum

@ -516,6 +516,7 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kurin/blazer v0.5.3 h1:SAgYv0TKU0kN/ETfO5ExjNAPyMt2FocO2s/UlCHfjAk=
github.com/kurin/blazer v0.5.3/go.mod h1:4FCXMUWo9DllR2Do4TtBd377ezyAJ51vB5uTBjt0pGU=
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3vkb4ax0b5D2DHbNAUsen0Gx5wZoq3lV4=
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.10.0 h1:Zx5DJFEYQXio93kgXnQ09fXNiUKsqv4OUEu2UtGcB1E=

7
weed/command/mount2_std.go

@ -4,6 +4,7 @@ import (
"fmt"
"github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/mount"
"github.com/chrislusf/seaweedfs/weed/mount/unmount"
"github.com/hanwen/go-fuse/v2/fs"
"net/http"
"os"
@ -43,6 +44,12 @@ func RunMount2(option *Mount2Options, umask os.FileMode) bool {
opts := &fs.Options{}
opts.Debug = true
unmount.Unmount(*option.dir)
grace.OnInterrupt(func() {
unmount.Unmount(*option.dir)
})
server, err := fs.Mount(*option.dir, &mount.WeedFS{}, opts)
if err != nil {
glog.Fatalf("Mount fail: %v", err)

6
weed/mount/unmount/unmount.go

@ -0,0 +1,6 @@
package unmount
// Unmount tries to unmount the filesystem mounted at dir.
func Unmount(dir string) error {
return unmount(dir)
}

21
weed/mount/unmount/unmount_linux.go

@ -0,0 +1,21 @@
package unmount
import (
"bytes"
"errors"
"os/exec"
)
func unmount(dir string) error {
cmd := exec.Command("fusermount", "-u", dir)
output, err := cmd.CombinedOutput()
if err != nil {
if len(output) > 0 {
output = bytes.TrimRight(output, "\n")
msg := err.Error() + ": " + string(output)
err = errors.New(msg)
}
return err
}
return nil
}

18
weed/mount/unmount/unmount_std.go

@ -0,0 +1,18 @@
//go:build !linux
// +build !linux
package unmount
import (
"os"
"syscall"
)
func unmount(dir string) error {
err := syscall.Unmount(dir, 0)
if err != nil {
err = &os.PathError{Op: "unmount", Path: dir, Err: err}
return err
}
return nil
}
Loading…
Cancel
Save