diff options
| author | duanhongyi <duanhongyi@doopai.com> | 2024-01-12 09:39:35 +0800 |
|---|---|---|
| committer | Chris Lu <chrislusf@users.noreply.github.com> | 2024-01-11 20:27:28 -0800 |
| commit | 44283c0ffe56e3180dae5b93801d07a3d621d355 (patch) | |
| tree | 73fd2ec5badc953d6c6408c334cf4d99aa56aff7 /pkg/driver/volume.go | |
| parent | 785e69a08ef47eab94742b040870ec0716f20f13 (diff) | |
| download | seaweedfs-csi-driver-44283c0ffe56e3180dae5b93801d07a3d621d355.tar.xz seaweedfs-csi-driver-44283c0ffe56e3180dae5b93801d07a3d621d355.zip | |
chore(seaweedfs-csi-driver): delete unnecessary stage
Diffstat (limited to 'pkg/driver/volume.go')
| -rw-r--r-- | pkg/driver/volume.go | 68 |
1 files changed, 17 insertions, 51 deletions
diff --git a/pkg/driver/volume.go b/pkg/driver/volume.go index ac0a80a..38d1308 100644 --- a/pkg/driver/volume.go +++ b/pkg/driver/volume.go @@ -9,12 +9,11 @@ import ( "github.com/seaweedfs/seaweedfs/weed/pb/mount_pb" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - "k8s.io/mount-utils" ) type Volume struct { VolumeId string - StagedPath string + TargetPath string mounter Mounter unmounter Unmounter @@ -31,55 +30,31 @@ func NewVolume(volumeID string, mounter Mounter) *Volume { } } -func (vol *Volume) Stage(stagingTargetPath string) error { +func (vol *Volume) Publish(targetPath string) error { // check whether it can be mounted - if isMnt, err := checkMount(stagingTargetPath); err != nil { + if isMnt, err := checkMount(targetPath); err != nil { return err } else if isMnt { // try to unmount before mounting again - _ = mountutil.Unmount(stagingTargetPath) + _ = mountutil.Unmount(targetPath) } - if u, err := vol.mounter.Mount(stagingTargetPath); err == nil { - if vol.StagedPath != "" { - if vol.StagedPath == stagingTargetPath { - glog.Warningf("staged path is already set to %s for volume %s", vol.StagedPath, vol.VolumeId) + if u, err := vol.mounter.Mount(targetPath); err == nil { + if vol.TargetPath != "" { + if vol.TargetPath == targetPath { + glog.Warningf("target path is already set to %s for volume %s", vol.TargetPath, vol.VolumeId) } else { - glog.Warningf("staged path is already set to %s and differs from %s for volume %s", vol.StagedPath, stagingTargetPath, vol.VolumeId) + glog.Warningf("target path is already set to %s and differs from %s for volume %s", vol.TargetPath, targetPath, vol.VolumeId) } } - - vol.StagedPath = stagingTargetPath + vol.TargetPath = targetPath vol.unmounter = u - return nil } else { return err } } -func (vol *Volume) Publish(stagingTargetPath string, targetPath string, readOnly bool) error { - // check whether it can be mounted - if isMnt, err := checkMount(targetPath); err != nil { - return err - } else if isMnt { - // maybe already mounted? - return nil - } - - // Use bind mount to create an alias of the real mount point. - mountOptions := []string{"bind"} - if readOnly { - mountOptions = append(mountOptions, "ro") - } - - if err := mountutil.Mount(stagingTargetPath, targetPath, "", mountOptions); err != nil { - return err - } - - return nil -} - func (vol *Volume) Quota(sizeByte int64) error { target := fmt.Sprintf("passthrough:///unix://%s", vol.localSocket) dialOption := grpc.WithTransportCredentials(insecure.NewCredentials()) @@ -98,33 +73,24 @@ func (vol *Volume) Quota(sizeByte int64) error { } func (vol *Volume) Unpublish(targetPath string) error { - // Try unmounting target path and deleting it. - if err := mount.CleanupMountPoint(targetPath, mountutil, true); err != nil { - return err - } - - return nil -} - -func (vol *Volume) Unstage(stagingTargetPath string) error { - glog.V(0).Infof("unmounting volume %s from %s", vol.VolumeId, stagingTargetPath) + glog.V(0).Infof("unmounting volume %s from %s", vol.VolumeId, targetPath) if vol.unmounter == nil { - glog.Errorf("volume is not mounted: %s, path: %s", vol.VolumeId, stagingTargetPath) + glog.Errorf("volume is not mounted: %s, path: %s", vol.VolumeId, targetPath) return nil } - if stagingTargetPath != vol.StagedPath { - glog.Warningf("staging path %s differs for volume %s at %s", stagingTargetPath, vol.VolumeId, vol.StagedPath) + if targetPath != vol.TargetPath { + glog.Warningf("staging path %s differs for volume %s at %s", targetPath, vol.VolumeId, vol.TargetPath) } if err := vol.unmounter.Unmount(); err != nil { - glog.Errorf("error unmounting volume during unstage: %s, err: %v", stagingTargetPath, err) + glog.Errorf("error unmounting volume during unstage: %s, err: %v", targetPath, err) return err } - if err := os.Remove(stagingTargetPath); err != nil && !os.IsNotExist(err) { - glog.Errorf("error removing staging path for volume %s at %s, err: %v", vol.VolumeId, stagingTargetPath, err) + if err := os.Remove(targetPath); err != nil && !os.IsNotExist(err) { + glog.Errorf("error removing staging path for volume %s at %s, err: %v", vol.VolumeId, targetPath, err) return err } |
