@@ -17,6 +17,7 @@ package gceGCEDriver
17
17
import (
18
18
"fmt"
19
19
"os"
20
+ "runtime"
20
21
"strconv"
21
22
"strings"
22
23
@@ -57,10 +58,20 @@ var _ csi.NodeServer = &GCENodeServer{}
57
58
// node boot disk is considered an attachable disk so effective attach limit is
58
59
// one less.
59
60
const (
60
- volumeLimitSmall int64 = 15
61
- volumeLimitBig int64 = 127
61
+ volumeLimitSmall int64 = 15
62
+ volumeLimitBig int64 = 127
63
+ defaultLinuxFsType = "ext4"
64
+ defaultWindowsFsType = "ntfs"
62
65
)
63
66
67
+ func getDefaultFsType () string {
68
+ if runtime .GOOS == "windows" {
69
+ return defaultWindowsFsType
70
+ } else {
71
+ return defaultLinuxFsType
72
+ }
73
+ }
74
+
64
75
func (ns * GCENodeServer ) NodePublishVolume (ctx context.Context , req * csi.NodePublishVolumeRequest ) (* csi.NodePublishVolumeResponse , error ) {
65
76
// Validate Arguments
66
77
targetPath := req .GetTargetPath ()
@@ -129,10 +140,10 @@ func (ns *GCENodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePub
129
140
}
130
141
131
142
sourcePath = stagingTargetPath
132
-
133
- if err := os .MkdirAll (targetPath , 0750 ); err != nil {
143
+ if err := preparePublishPath (targetPath , ns .Mounter ); err != nil {
134
144
return nil , status .Error (codes .Internal , fmt .Sprintf ("mkdir failed on disk %s (%v)" , targetPath , err ))
135
145
}
146
+
136
147
} else if blk := volumeCapability .GetBlock (); blk != nil {
137
148
klog .V (4 ).Infof ("NodePublishVolume with block volume mode" )
138
149
@@ -141,7 +152,7 @@ func (ns *GCENodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePub
141
152
partition = part
142
153
}
143
154
144
- sourcePath , err = ns . getDevicePath (volumeID , partition )
155
+ sourcePath , err = getDevicePath (ns , volumeID , partition )
145
156
if err != nil {
146
157
return nil , status .Error (codes .Internal , fmt .Sprintf ("Error when getting device path: %v" , err ))
147
158
}
@@ -218,11 +229,9 @@ func (ns *GCENodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeU
218
229
}
219
230
defer ns .volumeLocks .Release (volumeID )
220
231
221
- err := mount .CleanupMountPoint (targetPath , ns .Mounter .Interface , false /* bind mount */ )
222
- if err != nil {
232
+ if err := cleanupPublishPath (targetPath , ns .Mounter ); err != nil {
223
233
return nil , status .Error (codes .Internal , fmt .Sprintf ("Unmount failed: %v\n Unmounting arguments: %s\n " , err , targetPath ))
224
234
}
225
-
226
235
klog .V (4 ).Infof ("NodeUnpublishVolume succeded on %v from %s" , volumeID , targetPath )
227
236
return & csi.NodeUnpublishVolumeResponse {}, nil
228
237
}
@@ -264,27 +273,19 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
264
273
if part , ok := req .GetVolumeContext ()[common .VolumeAttributePartition ]; ok {
265
274
partition = part
266
275
}
276
+ devicePath , err := getDevicePath (ns , volumeID , partition )
267
277
268
- devicePath , err := ns .getDevicePath (volumeID , partition )
269
278
if err != nil {
270
279
return nil , status .Error (codes .Internal , fmt .Sprintf ("Error when getting device path: %v" , err ))
271
280
}
272
281
273
282
klog .V (4 ).Infof ("Successfully found attached GCE PD %q at device path %s." , volumeKey .Name , devicePath )
274
283
275
- // Part 2: Check if mount already exists at targetpath
284
+ // Part 2: Check if mount already exists at stagingTargetPath
276
285
notMnt , err := ns .Mounter .Interface .IsLikelyNotMountPoint (stagingTargetPath )
277
- if err != nil {
278
- if os .IsNotExist (err ) {
279
- if err := os .MkdirAll (stagingTargetPath , 0750 ); err != nil {
280
- return nil , status .Error (codes .Internal , fmt .Sprintf ("Failed to create directory (%q): %v" , stagingTargetPath , err ))
281
- }
282
- notMnt = true
283
- } else {
284
- return nil , status .Error (codes .Internal , fmt .Sprintf ("Unknown error when checking mount point (%q): %v" , stagingTargetPath , err ))
285
- }
286
+ if err != nil && ! os .IsNotExist (err ) {
287
+ return nil , status .Error (codes .Internal , fmt .Sprintf ("cannot validate mount point: %s %v" , stagingTargetPath , err ))
286
288
}
287
-
288
289
if ! notMnt {
289
290
// TODO(#95): Check who is mounted here. No error if its us
290
291
/*
@@ -293,15 +294,17 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
293
294
3) Readonly MUST match
294
295
295
296
*/
296
-
297
297
klog .V (4 ).Infof ("NodeStageVolume succeded on %v to %s, mount already exists." , volumeID , stagingTargetPath )
298
298
return & csi.NodeStageVolumeResponse {}, nil
299
299
300
300
}
301
+ if err := prepareStagePath (stagingTargetPath , ns .Mounter ); err != nil {
302
+ return nil , status .Error (codes .Internal , fmt .Sprintf ("mkdir failed on disk %s (%v)" , stagingTargetPath , err ))
303
+ }
301
304
302
305
// Part 3: Mount device to stagingTargetPath
303
- // Default fstype is ext4
304
- fstype := "ext4"
306
+ fstype := getDefaultFsType ()
307
+
305
308
options := []string {}
306
309
if mnt := volumeCapability .GetMount (); mnt != nil {
307
310
if mnt .FsType != "" {
@@ -316,7 +319,7 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
316
319
return & csi.NodeStageVolumeResponse {}, nil
317
320
}
318
321
319
- err = ns . Mounter . FormatAndMount (devicePath , stagingTargetPath , fstype , options )
322
+ err = formatAndMount (devicePath , stagingTargetPath , fstype , options , ns . Mounter )
320
323
if err != nil {
321
324
return nil , status .Error (codes .Internal ,
322
325
fmt .Sprintf ("Failed to format and mount device from (%q) to (%q) with fstype (%q) and options (%q): %v" ,
@@ -343,9 +346,8 @@ func (ns *GCENodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUns
343
346
}
344
347
defer ns .volumeLocks .Release (volumeID )
345
348
346
- err := mount .CleanupMountPoint (stagingTargetPath , ns .Mounter .Interface , false /* bind mount */ )
347
- if err != nil {
348
- return nil , status .Error (codes .Internal , fmt .Sprintf ("NodeUnstageVolume failed to unmount at path %s: %v" , stagingTargetPath , err ))
349
+ if err := cleanupStagePath (stagingTargetPath , ns .Mounter ); err != nil {
350
+ return nil , status .Error (codes .Internal , fmt .Sprintf ("NodeUnstageVolume failed: %v\n Unmounting arguments: %s\n " , err , stagingTargetPath ))
349
351
}
350
352
351
353
klog .V (4 ).Infof ("NodeUnstageVolume succeded on %v from %s" , volumeID , stagingTargetPath )
@@ -454,7 +456,7 @@ func (ns *GCENodeServer) NodeExpandVolume(ctx context.Context, req *csi.NodeExpa
454
456
return nil , status .Error (codes .InvalidArgument , fmt .Sprintf ("volume ID is invalid: %v" , err ))
455
457
}
456
458
457
- devicePath , err := ns . getDevicePath (volumeID , "" )
459
+ devicePath , err := getDevicePath (ns , volumeID , "" )
458
460
if err != nil {
459
461
return nil , status .Error (codes .Internal , fmt .Sprintf ("error when getting device path for %s: %v" , volumeID , err ))
460
462
}
@@ -517,28 +519,6 @@ func (ns *GCENodeServer) GetVolumeLimits() (int64, error) {
517
519
return volumeLimitBig , nil
518
520
}
519
521
520
- func (ns * GCENodeServer ) getDevicePath (volumeID string , partition string ) (string , error ) {
521
- volumeKey , err := common .VolumeIDToKey (volumeID )
522
- if err != nil {
523
- return "" , err
524
- }
525
- deviceName , err := common .GetDeviceName (volumeKey )
526
- if err != nil {
527
- return "" , fmt .Errorf ("error getting device name: %v" , err )
528
- }
529
-
530
- devicePaths := ns .DeviceUtils .GetDiskByIdPaths (deviceName , partition )
531
- devicePath , err := ns .DeviceUtils .VerifyDevicePath (devicePaths , deviceName )
532
-
533
- if err != nil {
534
- return "" , fmt .Errorf ("error verifying GCE PD (%q) is attached: %v" , volumeKey .Name , err )
535
- }
536
- if devicePath == "" {
537
- return "" , fmt .Errorf ("unable to find device path out of attempted paths: %v" , devicePaths )
538
- }
539
- return devicePath , nil
540
- }
541
-
542
522
func (ns * GCENodeServer ) getBlockSizeBytes (devicePath string ) (int64 , error ) {
543
523
output , err := ns .Mounter .Exec .Command ("blockdev" , "--getsize64" , devicePath ).CombinedOutput ()
544
524
if err != nil {
0 commit comments