aboutsummaryrefslogtreecommitdiff
path: root/pkg/driver/volume.go
diff options
context:
space:
mode:
authorChris Lu <chrislusf@users.noreply.github.com>2022-09-03 13:59:30 -0700
committerGitHub <noreply@github.com>2022-09-03 13:59:30 -0700
commiteeb091f89e795eeb8688e277d88a1b11330eddb3 (patch)
treed8e95674b60c979727a06bd79a379e9eeec86bdf /pkg/driver/volume.go
parent3e3d202acdc9cb523ae3f7e71b3e1b595f4d5450 (diff)
parent825920dd8c0640f9ef5942d19fbab5a7e7945c4c (diff)
downloadseaweedfs-csi-driver-eeb091f89e795eeb8688e277d88a1b11330eddb3.tar.xz
seaweedfs-csi-driver-eeb091f89e795eeb8688e277d88a1b11330eddb3.zip
Merge pull request #83 from kvaster/fuse-process
Remove linux specific magic from fuse process start/stop.
Diffstat (limited to 'pkg/driver/volume.go')
-rw-r--r--pkg/driver/volume.go66
1 files changed, 21 insertions, 45 deletions
diff --git a/pkg/driver/volume.go b/pkg/driver/volume.go
index c7d8f64..ff303ea 100644
--- a/pkg/driver/volume.go
+++ b/pkg/driver/volume.go
@@ -15,10 +15,8 @@ import (
type Volume struct {
VolumeId string
- // volume's real mount point
- stagingTargetPath string
-
- mounter Mounter
+ mounter Mounter
+ unmounter Unmounter
// unix socket used to manage volume
localSocket string
@@ -26,33 +24,30 @@ type Volume struct {
func NewVolume(volumeID string, mounter Mounter) *Volume {
return &Volume{
- VolumeId: volumeID,
- mounter: mounter,
+ VolumeId: volumeID,
+ mounter: mounter,
+ localSocket: GetLocalSocket(volumeID),
}
}
func (vol *Volume) Stage(stagingTargetPath string) error {
- if vol.isStaged() {
- return nil
- }
-
// check whether it can be mounted
if notMnt, err := checkMount(stagingTargetPath); err != nil {
return err
} else if !notMnt {
- // maybe already mounted?
- return nil
+ // try to unmount before mounting again
+ _ = mount.New("").Unmount(stagingTargetPath)
}
- if err := vol.mounter.Mount(stagingTargetPath); err != nil {
+ if u, err := vol.mounter.Mount(stagingTargetPath); err == nil {
+ vol.unmounter = u
+ return nil
+ } else {
return err
}
-
- vol.stagingTargetPath = stagingTargetPath
- return nil
}
-func (vol *Volume) Publish(targetPath string, readOnly bool) error {
+func (vol *Volume) Publish(stagingTargetPath string, targetPath string, readOnly bool) error {
// check whether it can be mounted
if notMnt, err := checkMount(targetPath); err != nil {
return err
@@ -68,7 +63,7 @@ func (vol *Volume) Publish(targetPath string, readOnly bool) error {
}
mounter := mount.New("")
- if err := mounter.Mount(vol.stagingTargetPath, targetPath, "", mountOptions); err != nil {
+ if err := mounter.Mount(stagingTargetPath, targetPath, "", mountOptions); err != nil {
return err
}
@@ -76,11 +71,7 @@ func (vol *Volume) Publish(targetPath string, readOnly bool) error {
}
func (vol *Volume) Expand(sizeByte int64) error {
- if !vol.isStaged() {
- return nil
- }
-
- target := fmt.Sprintf("passthrough:///unix://%s", vol.getLocalSocket())
+ target := fmt.Sprintf("passthrough:///unix://%s", vol.localSocket)
dialOption := grpc.WithTransportCredentials(insecure.NewCredentials())
clientConn, err := grpc.Dial(target, dialOption)
@@ -106,36 +97,21 @@ func (vol *Volume) Unpublish(targetPath string) error {
return nil
}
-func (vol *Volume) Unstage(_ string) error {
- if !vol.isStaged() {
+func (vol *Volume) Unstage(stagingTargetPath string) error {
+ glog.V(0).Infof("unmounting volume %s from %s", vol.VolumeId, stagingTargetPath)
+
+ if vol.unmounter == nil {
+ glog.Errorf("volume is not mounted: %s, path", vol.VolumeId, stagingTargetPath)
return nil
}
- mountPoint := vol.stagingTargetPath
- glog.V(0).Infof("unmounting volume %s from %s", vol.VolumeId, mountPoint)
-
- if err := fuseUnmount(mountPoint); err != nil {
+ if err := vol.unmounter.Unmount(); err != nil {
return err
}
- if err := os.Remove(mountPoint); err != nil && !os.IsNotExist(err) {
+ if err := os.Remove(stagingTargetPath); err != nil && !os.IsNotExist(err) {
return err
}
return nil
}
-
-func (vol *Volume) isStaged() bool {
- return vol.stagingTargetPath != ""
-}
-
-func (vol *Volume) getLocalSocket() string {
- if vol.localSocket != "" {
- return vol.localSocket
- }
-
- socket := GetLocalSocket(vol.VolumeId)
-
- vol.localSocket = socket
- return socket
-}