@@ -24,13 +24,15 @@ import (
24
24
"golang.org/x/net/context"
25
25
"google.golang.org/grpc/codes"
26
26
"google.golang.org/grpc/status"
27
+ "k8s.io/kubernetes/pkg/util/mount"
27
28
mountmanager "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/mount-manager"
28
29
utils "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/utils"
29
30
)
30
31
31
32
type GCENodeServer struct {
32
- Driver * GCEDriver
33
- Mounter mountmanager.MountManager
33
+ Driver * GCEDriver
34
+ Mounter * mount.SafeFormatAndMount
35
+ DeviceUtils mountmanager.DeviceUtils
34
36
// TODO: Only lock mutually exclusive calls and make locking more fine grained
35
37
mux sync.Mutex
36
38
}
@@ -61,7 +63,7 @@ func (ns *GCENodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePub
61
63
return nil , status .Error (codes .InvalidArgument , "NodePublishVolume Volume Capability must be provided" )
62
64
}
63
65
64
- notMnt , err := ns .Mounter .GetSafeMounter (). Interface .IsLikelyNotMountPoint (targetPath )
66
+ notMnt , err := ns .Mounter .Interface .IsLikelyNotMountPoint (targetPath )
65
67
if err != nil && ! os .IsNotExist (err ) {
66
68
glog .Errorf ("cannot validate mount point: %s %v" , targetPath , err )
67
69
return nil , err
@@ -71,7 +73,7 @@ func (ns *GCENodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePub
71
73
return nil , nil
72
74
}
73
75
74
- if err := ns .Mounter .GetSafeMounter (). Interface .MakeDir (targetPath ); err != nil {
76
+ if err := ns .Mounter .Interface .MakeDir (targetPath ); err != nil {
75
77
glog .Errorf ("mkdir failed on disk %s (%v)" , targetPath , err )
76
78
return nil , err
77
79
}
@@ -82,19 +84,19 @@ func (ns *GCENodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePub
82
84
options = append (options , "ro" )
83
85
}
84
86
85
- err = ns .Mounter .GetSafeMounter (). Interface .Mount (stagingTargetPath , targetPath , "ext4" , options )
87
+ err = ns .Mounter .Interface .Mount (stagingTargetPath , targetPath , "ext4" , options )
86
88
if err != nil {
87
- notMnt , mntErr := ns .Mounter .GetSafeMounter (). Interface .IsLikelyNotMountPoint (targetPath )
89
+ notMnt , mntErr := ns .Mounter .Interface .IsLikelyNotMountPoint (targetPath )
88
90
if mntErr != nil {
89
91
glog .Errorf ("IsLikelyNotMountPoint check failed: %v" , mntErr )
90
92
return nil , status .Error (codes .Internal , fmt .Sprintf ("TODO: %v" , err ))
91
93
}
92
94
if ! notMnt {
93
- if mntErr = ns .Mounter .GetSafeMounter (). Interface .Unmount (targetPath ); mntErr != nil {
95
+ if mntErr = ns .Mounter .Interface .Unmount (targetPath ); mntErr != nil {
94
96
glog .Errorf ("Failed to unmount: %v" , mntErr )
95
97
return nil , status .Error (codes .Internal , fmt .Sprintf ("TODO: %v" , err ))
96
98
}
97
- notMnt , mntErr := ns .Mounter .GetSafeMounter (). Interface .IsLikelyNotMountPoint (targetPath )
99
+ notMnt , mntErr := ns .Mounter .Interface .IsLikelyNotMountPoint (targetPath )
98
100
if mntErr != nil {
99
101
glog .Errorf ("IsLikelyNotMountPoint check failed: %v" , mntErr )
100
102
return nil , status .Error (codes .Internal , fmt .Sprintf ("TODO: %v" , err ))
@@ -130,7 +132,7 @@ func (ns *GCENodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeU
130
132
131
133
// TODO: Check volume still exists
132
134
133
- err := ns .Mounter .GetSafeMounter (). Interface .Unmount (targetPath )
135
+ err := ns .Mounter .Interface .Unmount (targetPath )
134
136
if err != nil {
135
137
return nil , status .Error (codes .Internal , fmt .Sprintf ("Unmount failed: %v\n Unmounting arguments: %s\n " , err , targetPath ))
136
138
}
@@ -168,8 +170,8 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
168
170
// TODO: Get real partitions
169
171
partition := ""
170
172
171
- devicePaths := ns .Mounter .GetDiskByIdPaths (volumeName , partition )
172
- devicePath , err := ns .Mounter .VerifyDevicePath (devicePaths )
173
+ devicePaths := ns .DeviceUtils .GetDiskByIdPaths (volumeName , partition )
174
+ devicePath , err := ns .DeviceUtils .VerifyDevicePath (devicePaths )
173
175
174
176
if err != nil {
175
177
return nil , status .Error (codes .Internal , fmt .Sprintf ("Error verifying GCE PD (%q) is attached: %v" , volumeName , err ))
@@ -181,10 +183,10 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
181
183
glog .Infof ("Successfully found attached GCE PD %q at device path %s." , volumeName , devicePath )
182
184
183
185
// Part 2: Check if mount already exists at targetpath
184
- notMnt , err := ns .Mounter .GetSafeMounter (). Interface .IsLikelyNotMountPoint (stagingTargetPath )
186
+ notMnt , err := ns .Mounter .Interface .IsLikelyNotMountPoint (stagingTargetPath )
185
187
if err != nil {
186
188
if os .IsNotExist (err ) {
187
- if err := ns .Mounter .GetSafeMounter (). Interface .MakeDir (stagingTargetPath ); err != nil {
189
+ if err := ns .Mounter .Interface .MakeDir (stagingTargetPath ); err != nil {
188
190
return nil , status .Error (codes .Internal , fmt .Sprintf ("Failed to create directory (%q): %v" , stagingTargetPath , err ))
189
191
}
190
192
notMnt = true
@@ -218,7 +220,7 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
218
220
return nil , status .Error (codes .Unimplemented , fmt .Sprintf ("Block volume support is not yet implemented" ))
219
221
}
220
222
221
- err = ns .Mounter .GetSafeMounter (). FormatAndMount (devicePath , stagingTargetPath , fstype , options )
223
+ err = ns .Mounter .FormatAndMount (devicePath , stagingTargetPath , fstype , options )
222
224
if err != nil {
223
225
return nil , status .Error (codes .Internal ,
224
226
fmt .Sprintf ("Failed to format and mount device from (%q) to (%q) with fstype (%q) and options (%q): %v" ,
@@ -242,7 +244,7 @@ func (ns *GCENodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUns
242
244
return nil , status .Error (codes .InvalidArgument , "NodeUnstageVolume Staging Target Path must be provided" )
243
245
}
244
246
245
- err := ns .Mounter .GetSafeMounter (). Interface .Unmount (stagingTargetPath )
247
+ err := ns .Mounter .Interface .Unmount (stagingTargetPath )
246
248
if err != nil {
247
249
return nil , status .Error (codes .Internal , fmt .Sprintf ("NodeUnstageVolume failed to unmount at path %s: %v" , stagingTargetPath , err ))
248
250
}
0 commit comments