Skip to content

Commit

Permalink
NodeUnstageVolume: don't delete target dir
Browse files Browse the repository at this point in the history
  • Loading branch information
huww98 committed Sep 30, 2023
1 parent fa38d41 commit f54d3b5
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 48 deletions.
6 changes: 0 additions & 6 deletions pkg/dbfs/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,6 @@ func (ns *nodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstag
} else {
msgLog = fmt.Sprintf("NodeUnstageVolume: VolumeId: %s, mountpoint: %s not mounted, skipping", req.VolumeId, req.StagingTargetPath)
}
// safe remove mountpoint
err = ns.mounter.SafePathRemove(req.StagingTargetPath)
if err != nil {
log.Log.Errorf("NodeUnstageVolume: VolumeId: %s, Remove targetPath failed, target %v", req.VolumeId, req.StagingTargetPath)
return nil, status.Error(codes.Internal, err.Error())
}
} else {
msgLog = fmt.Sprintf("NodeUnstageVolume: VolumeId: %s, Path %s doesn't exist, skip", req.VolumeId, req.StagingTargetPath)
}
Expand Down
6 changes: 0 additions & 6 deletions pkg/disk/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,12 +778,6 @@ func (ns *nodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstag
} else {
msgLog = fmt.Sprintf("NodeUnstageVolume: VolumeId: %s, mountpoint: %s not mounted, skipping and continue to detach", req.VolumeId, targetPath)
}
// safe remove mountpoint
err = ns.mounter.SafePathRemove(targetPath)
if err != nil {
log.Log.Errorf("NodeUnstageVolume: VolumeId: %s, Remove targetPath failed, target %v", req.VolumeId, targetPath)
return nil, status.Error(codes.Internal, err.Error())
}
} else {
msgLog = fmt.Sprintf("NodeUnstageVolume: VolumeId: %s, Path %s doesn't exist, continue to detach", req.VolumeId, targetPath)
}
Expand Down
6 changes: 0 additions & 6 deletions pkg/ens/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,12 +478,6 @@ func (ns *nodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstag
} else {
msgLog = fmt.Sprintf("NodeUnstageVolume: VolumeId: %s, mountpoint: %s not mounted, skipping and continue to detach", req.VolumeId, targetPath)
}
// safe remove mountpoint
err = ns.mounter.SafePathRemove(targetPath)
if err != nil {
log.Errorf("NodeUnstageVolume: VolumeId: %s, Remove targetPath failed, target %v", req.VolumeId, targetPath)
return nil, status.Error(codes.Internal, err.Error())
}
} else {
msgLog = fmt.Sprintf("NodeUnstageVolume: VolumeId: %s, Path %s doesn't exist, continue to detach", req.VolumeId, targetPath)
}
Expand Down
30 changes: 0 additions & 30 deletions pkg/utils/mounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ type Mounter interface {

IsNotMountPoint(file string) (bool, error)

SafePathRemove(target string) error

HasMountRefs(mountPath string, mountRefs []string) bool
}

Expand Down Expand Up @@ -319,34 +317,6 @@ func (m *mounter) IsMounted(target string) (bool, error) {
return false, nil
}

func (m *mounter) SafePathRemove(targetPath string) error {
fo, err := os.Lstat(targetPath)
if err != nil {
return err
}
isMounted, err := m.IsMounted(targetPath)
if err != nil {
return err
}
if isMounted {
return errors.New("Path is mounted, not remove: " + targetPath)
}
if fo.IsDir() {
empty, err := IsDirEmpty(targetPath)
if err != nil {
return errors.New("Check path empty error: " + targetPath + err.Error())
}
if !empty {
return errors.New("Cannot remove Path not empty: " + targetPath)
}
}
err = os.Remove(targetPath)
if err != nil {
return err
}
return nil
}

func (m *mounter) HasMountRefs(mountPath string, mountRefs []string) bool {
count := 0
for _, refPath := range mountRefs {
Expand Down

0 comments on commit f54d3b5

Please sign in to comment.