Skip to content

Commit a42b320

Browse files
authored
Merge pull request #320 from andyzhangx/CleanupMountPoint
fix: use mount.CleanupMountPoint in NodeUnpublishVolume for handling stale nfs connections during unmount process
2 parents 0726684 + 38b6ba2 commit a42b320

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

pkg/nfs/nodeserver.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -130,24 +130,13 @@ func (ns *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
130130
if len(targetPath) == 0 {
131131
return nil, status.Error(codes.InvalidArgument, "Target path missing in request")
132132
}
133-
notMnt, err := ns.mounter.IsLikelyNotMountPoint(targetPath)
134133

134+
klog.V(2).Infof("NodeUnpublishVolume: unmounting volume %s on %s", volumeID, targetPath)
135+
err := mount.CleanupMountPoint(targetPath, ns.mounter, true /*extensiveMountPointCheck*/)
135136
if err != nil {
136-
if os.IsNotExist(err) {
137-
return nil, status.Error(codes.NotFound, "Targetpath not found")
138-
}
139-
return nil, status.Error(codes.Internal, err.Error())
140-
}
141-
if notMnt {
142-
klog.V(2).Infof("NodeUnpublishVolume: Targetpath %s of volumeID(%s) is not mounted", targetPath, volumeID)
143-
return &csi.NodeUnpublishVolumeResponse{}, nil
144-
}
145-
146-
klog.V(2).Infof("NodeUnpublishVolume: CleanupMountPoint %s on volumeID(%s)", targetPath, volumeID)
147-
err = mount.CleanupMountPoint(targetPath, ns.mounter, false)
148-
if err != nil {
149-
return nil, status.Error(codes.Internal, err.Error())
137+
return nil, status.Errorf(codes.Internal, "failed to unmount target %q: %v", targetPath, err)
150138
}
139+
klog.V(2).Infof("NodeUnpublishVolume: unmount volume %s on %s successfully", volumeID, targetPath)
151140

152141
return &csi.NodeUnpublishVolumeResponse{}, nil
153142
}

pkg/nfs/nodeserver_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ package nfs
1919
import (
2020
"context"
2121
"errors"
22+
"fmt"
2223
"os"
2324
"reflect"
25+
"strings"
2426
"testing"
2527

2628
"github.com/container-storage-interface/spec/lib/go/csi"
@@ -186,7 +188,7 @@ func TestNodeUnpublishVolume(t *testing.T) {
186188
{
187189
desc: "[Error] Unmount error mocked by IsLikelyNotMountPoint",
188190
req: csi.NodeUnpublishVolumeRequest{TargetPath: errorTarget, VolumeId: "vol_1"},
189-
expectedErr: status.Error(codes.Internal, "fake IsLikelyNotMountPoint: fake error"),
191+
expectedErr: fmt.Errorf("fake IsLikelyNotMountPoint: fake error"),
190192
},
191193
{
192194
desc: "[Success] Volume not mounted",
@@ -203,7 +205,9 @@ func TestNodeUnpublishVolume(t *testing.T) {
203205
}
204206
_, err := ns.NodeUnpublishVolume(context.Background(), &tc.req)
205207
if !reflect.DeepEqual(err, tc.expectedErr) {
206-
t.Errorf("Desc:%v\nUnexpected error: %v\nExpected: %v", tc.desc, err, tc.expectedErr)
208+
if err == nil || tc.expectedErr == nil || !strings.Contains(err.Error(), tc.expectedErr.Error()) {
209+
t.Errorf("Desc:%v\nUnexpected error: %v\nExpected: %v", tc.desc, err, tc.expectedErr)
210+
}
207211
}
208212
if tc.cleanup != nil {
209213
tc.cleanup()

0 commit comments

Comments
 (0)