@@ -18,10 +18,11 @@ package nfs
1818
1919import (
2020 "fmt"
21- "github.com/golang/glog"
2221 "os"
2322 "strings"
2423
24+ "github.com/golang/glog"
25+
2526 "github.com/container-storage-interface/spec/lib/go/csi"
2627 "golang.org/x/net/context"
2728 "google.golang.org/grpc/codes"
@@ -30,12 +31,13 @@ import (
3031)
3132
3233type nodeServer struct {
33- Driver * nfsDriver
34+ Driver * nfsDriver
35+ mounter mount.Interface
3436}
3537
3638func (ns * nodeServer ) NodePublishVolume (ctx context.Context , req * csi.NodePublishVolumeRequest ) (* csi.NodePublishVolumeResponse , error ) {
3739 targetPath := req .GetTargetPath ()
38- notMnt , err := mount . New ( "" ) .IsLikelyNotMountPoint (targetPath )
40+ notMnt , err := ns . mounter .IsLikelyNotMountPoint (targetPath )
3941 if err != nil {
4042 if os .IsNotExist (err ) {
4143 if err := os .MkdirAll (targetPath , 0750 ); err != nil {
@@ -60,8 +62,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
6062 ep := req .GetVolumeContext ()["share" ]
6163 source := fmt .Sprintf ("%s:%s" , s , ep )
6264
63- mounter := mount .New ("" )
64- err = mounter .Mount (source , targetPath , "nfs" , mo )
65+ err = ns .mounter .Mount (source , targetPath , "nfs" , mo )
6566 if err != nil {
6667 if os .IsPermission (err ) {
6768 return nil , status .Error (codes .PermissionDenied , err .Error ())
@@ -77,7 +78,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
7778
7879func (ns * nodeServer ) NodeUnpublishVolume (ctx context.Context , req * csi.NodeUnpublishVolumeRequest ) (* csi.NodeUnpublishVolumeResponse , error ) {
7980 targetPath := req .GetTargetPath ()
80- notMnt , err := mount . New ( "" ) .IsLikelyNotMountPoint (targetPath )
81+ notMnt , err := ns . mounter .IsLikelyNotMountPoint (targetPath )
8182
8283 if err != nil {
8384 if os .IsNotExist (err ) {
@@ -90,7 +91,7 @@ func (ns *nodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
9091 return nil , status .Error (codes .NotFound , "Volume not mounted" )
9192 }
9293
93- err = mount .CleanupMountPoint (req .GetTargetPath (), mount . New ( "" ) , false )
94+ err = mount .CleanupMountPoint (req .GetTargetPath (), ns . mounter , false )
9495 if err != nil {
9596 return nil , status .Error (codes .Internal , err .Error ())
9697 }
0 commit comments