fix: remove unnecessary lock
fix golint
This commit is contained in:
parent
17fb13f2f7
commit
f5abcf764a
@ -65,11 +65,6 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
|
|||||||
return &csi.NodePublishVolumeResponse{}, nil
|
return &csi.NodePublishVolumeResponse{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if acquired := ns.Driver.volumeLocks.TryAcquire(volumeID); !acquired {
|
|
||||||
return nil, status.Errorf(codes.Aborted, volumeOperationAlreadyExistsFmt, volumeID)
|
|
||||||
}
|
|
||||||
defer ns.Driver.volumeLocks.Release(volumeID)
|
|
||||||
|
|
||||||
mountOptions := req.GetVolumeCapability().GetMount().GetMountFlags()
|
mountOptions := req.GetVolumeCapability().GetMount().GetMountFlags()
|
||||||
if req.GetReadonly() {
|
if req.GetReadonly() {
|
||||||
mountOptions = append(mountOptions, "ro")
|
mountOptions = append(mountOptions, "ro")
|
||||||
@ -122,11 +117,6 @@ func (ns *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
|
|||||||
return nil, status.Error(codes.NotFound, "Volume not mounted")
|
return nil, status.Error(codes.NotFound, "Volume not mounted")
|
||||||
}
|
}
|
||||||
|
|
||||||
if acquired := ns.Driver.volumeLocks.TryAcquire(volumeID); !acquired {
|
|
||||||
return nil, status.Errorf(codes.Aborted, volumeOperationAlreadyExistsFmt, volumeID)
|
|
||||||
}
|
|
||||||
defer ns.Driver.volumeLocks.Release(volumeID)
|
|
||||||
|
|
||||||
klog.V(2).Infof("NodeUnpublishVolume: CleanupMountPoint %s on volumeID(%s)", targetPath, volumeID)
|
klog.V(2).Infof("NodeUnpublishVolume: CleanupMountPoint %s on volumeID(%s)", targetPath, volumeID)
|
||||||
err = mount.CleanupMountPoint(targetPath, ns.mounter, false)
|
err = mount.CleanupMountPoint(targetPath, ns.mounter, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -19,7 +19,6 @@ package nfs
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
@ -69,19 +68,6 @@ func TestNodePublishVolume(t *testing.T) {
|
|||||||
VolumeId: "vol_1"},
|
VolumeId: "vol_1"},
|
||||||
expectedErr: status.Error(codes.InvalidArgument, "Target path not provided"),
|
expectedErr: status.Error(codes.InvalidArgument, "Target path not provided"),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
desc: "[Error] Volume operation in progress",
|
|
||||||
setup: func() {
|
|
||||||
ns.Driver.volumeLocks.TryAcquire("vol_1")
|
|
||||||
},
|
|
||||||
req: csi.NodePublishVolumeRequest{VolumeCapability: &csi.VolumeCapability{AccessMode: &volumeCap},
|
|
||||||
VolumeId: "vol_1",
|
|
||||||
TargetPath: targetTest},
|
|
||||||
expectedErr: status.Error(codes.Aborted, fmt.Sprintf(volumeOperationAlreadyExistsFmt, "vol_1")),
|
|
||||||
cleanup: func() {
|
|
||||||
ns.Driver.volumeLocks.Release("vol_1")
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
desc: "[Success] Stage target path missing",
|
desc: "[Success] Stage target path missing",
|
||||||
req: csi.NodePublishVolumeRequest{VolumeCapability: &csi.VolumeCapability{AccessMode: &volumeCap},
|
req: csi.NodePublishVolumeRequest{VolumeCapability: &csi.VolumeCapability{AccessMode: &volumeCap},
|
||||||
@ -148,7 +134,6 @@ func TestNodeUnpublishVolume(t *testing.T) {
|
|||||||
errorTarget := testutil.GetWorkDirPath("error_is_likely_target", t)
|
errorTarget := testutil.GetWorkDirPath("error_is_likely_target", t)
|
||||||
targetTest := testutil.GetWorkDirPath("target_test", t)
|
targetTest := testutil.GetWorkDirPath("target_test", t)
|
||||||
targetFile := testutil.GetWorkDirPath("abc.go", t)
|
targetFile := testutil.GetWorkDirPath("abc.go", t)
|
||||||
alreadyMountedTarget := testutil.GetWorkDirPath("false_is_likely_exist_target", t)
|
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
desc string
|
desc string
|
||||||
@ -177,17 +162,6 @@ func TestNodeUnpublishVolume(t *testing.T) {
|
|||||||
req: csi.NodeUnpublishVolumeRequest{TargetPath: targetFile, VolumeId: "vol_1"},
|
req: csi.NodeUnpublishVolumeRequest{TargetPath: targetFile, VolumeId: "vol_1"},
|
||||||
expectedErr: status.Error(codes.NotFound, "Volume not mounted"),
|
expectedErr: status.Error(codes.NotFound, "Volume not mounted"),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
desc: "[Error] Volume operation in progress",
|
|
||||||
setup: func() {
|
|
||||||
ns.Driver.volumeLocks.TryAcquire("vol_1")
|
|
||||||
},
|
|
||||||
req: csi.NodeUnpublishVolumeRequest{TargetPath: alreadyMountedTarget, VolumeId: "vol_1"},
|
|
||||||
expectedErr: status.Error(codes.Aborted, fmt.Sprintf(volumeOperationAlreadyExistsFmt, "vol_1")),
|
|
||||||
cleanup: func() {
|
|
||||||
ns.Driver.volumeLocks.Release("vol_1")
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup
|
// Setup
|
||||||
|
|||||||
@ -95,10 +95,6 @@ func logGRPC(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, h
|
|||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
|
||||||
volumeOperationAlreadyExistsFmt = "An operation with the given Volume ID %s already exists"
|
|
||||||
)
|
|
||||||
|
|
||||||
type VolumeLocks struct {
|
type VolumeLocks struct {
|
||||||
locks sets.String
|
locks sets.String
|
||||||
mux sync.Mutex
|
mux sync.Mutex
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user