aboutsummaryrefslogtreecommitdiff
path: root/pkg/driver/volume.go
diff options
context:
space:
mode:
authorViktor Kuzmin <kvaster@gmail.com>2022-09-03 11:40:32 +0300
committerViktor Kuzmin <kvaster@gmail.com>2022-09-03 11:40:32 +0300
commitbc49fc11ffe8c687c5d4ea46f25ead9191155ec0 (patch)
tree901e66a4e89fb8d23648ca51c438f74c13bfcc35 /pkg/driver/volume.go
parent3e3d202acdc9cb523ae3f7e71b3e1b595f4d5450 (diff)
downloadseaweedfs-csi-driver-bc49fc11ffe8c687c5d4ea46f25ead9191155ec0.tar.xz
seaweedfs-csi-driver-bc49fc11ffe8c687c5d4ea46f25ead9191155ec0.zip
Remove linux specific magic from fuse process start/stop.
Use pid from cmd.Process instead of /proc lookup Use mount specific mutex Log fuse mount process stderr and stdout for problems investigation
Diffstat (limited to 'pkg/driver/volume.go')
-rw-r--r--pkg/driver/volume.go64
1 files changed, 20 insertions, 44 deletions
diff --git a/pkg/driver/volume.go b/pkg/driver/volume.go
index c7d8f64..29a2e8c 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
+ mount Mount
// 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 m, err := vol.mounter.Mount(stagingTargetPath); err == nil {
+ vol.mount = m
+ 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.mount == 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.mount.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
-}