@@ -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,44 +273,45 @@ 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
276
- 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 ))
284
+ if runtime .GOOS != "windows" {
285
+ // Part 2: Check if mount already exists at targetpath
286
+ notMnt , err := ns .Mounter .Interface .IsLikelyNotMountPoint (stagingTargetPath )
287
+ if err != nil {
288
+ if os .IsNotExist (err ) {
289
+ if err := os .MkdirAll (stagingTargetPath , 0750 ); err != nil {
290
+ return nil , status .Error (codes .Internal , fmt .Sprintf ("Failed to create directory (%q): %v" , stagingTargetPath , err ))
291
+ }
292
+ notMnt = true
293
+ } else {
294
+ return nil , status .Error (codes .Internal , fmt .Sprintf ("Unknown error when checking mount point (%q): %v" , stagingTargetPath , err ))
281
295
}
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
296
}
286
- }
287
297
288
- if ! notMnt {
289
- // TODO(#95): Check who is mounted here. No error if its us
290
- /*
291
- 1) Target Path MUST be the vol referenced by vol ID
292
- 2) VolumeCapability MUST match
293
- 3) Readonly MUST match
298
+ if ! notMnt {
299
+ // TODO(#95): Check who is mounted here. No error if its us
300
+ /*
301
+ 1) Target Path MUST be the vol referenced by vol ID
302
+ 2) VolumeCapability MUST match
303
+ 3) Readonly MUST match
294
304
295
- */
305
+ */
296
306
297
- klog .V (4 ).Infof ("NodeStageVolume succeded on %v to %s, mount already exists." , volumeID , stagingTargetPath )
298
- return & csi.NodeStageVolumeResponse {}, nil
307
+ klog .V (4 ).Infof ("NodeStageVolume succeded on %v to %s, mount already exists." , volumeID , stagingTargetPath )
308
+ return & csi.NodeStageVolumeResponse {}, nil
299
309
310
+ }
300
311
}
301
-
302
312
// Part 3: Mount device to stagingTargetPath
303
- // Default fstype is ext4
304
- fstype := "ext4"
313
+ fstype := getDefaultFsType ()
314
+
305
315
options := []string {}
306
316
if mnt := volumeCapability .GetMount (); mnt != nil {
307
317
if mnt .FsType != "" {
@@ -316,7 +326,8 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
316
326
return & csi.NodeStageVolumeResponse {}, nil
317
327
}
318
328
319
- err = ns .Mounter .FormatAndMount (devicePath , stagingTargetPath , fstype , options )
329
+ //err = ns.Mounter.FormatAndMount(devicePath, stagingTargetPath, fstype, options)
330
+ err = FormatAndMount (devicePath , stagingTargetPath , fstype , options , ns .Mounter )
320
331
if err != nil {
321
332
return nil , status .Error (codes .Internal ,
322
333
fmt .Sprintf ("Failed to format and mount device from (%q) to (%q) with fstype (%q) and options (%q): %v" ,
@@ -343,9 +354,8 @@ func (ns *GCENodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUns
343
354
}
344
355
defer ns .volumeLocks .Release (volumeID )
345
356
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 ))
357
+ if err := cleanupPublishPath (stagingTargetPath , ns .Mounter ); err != nil {
358
+ return nil , status .Error (codes .Internal , fmt .Sprintf ("NodeUnstageVolume failed: %v\n Unmounting arguments: %s\n " , err , stagingTargetPath ))
349
359
}
350
360
351
361
klog .V (4 ).Infof ("NodeUnstageVolume succeded on %v from %s" , volumeID , stagingTargetPath )
@@ -454,7 +464,7 @@ func (ns *GCENodeServer) NodeExpandVolume(ctx context.Context, req *csi.NodeExpa
454
464
return nil , status .Error (codes .InvalidArgument , fmt .Sprintf ("volume ID is invalid: %v" , err ))
455
465
}
456
466
457
- devicePath , err := ns . getDevicePath ( volumeID , "" )
467
+ devicePath , err := GetDevicePath ( ns , volumeID , "" )
458
468
if err != nil {
459
469
return nil , status .Error (codes .Internal , fmt .Sprintf ("error when getting device path for %s: %v" , volumeID , err ))
460
470
}
@@ -517,28 +527,6 @@ func (ns *GCENodeServer) GetVolumeLimits() (int64, error) {
517
527
return volumeLimitBig , nil
518
528
}
519
529
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
530
func (ns * GCENodeServer ) getBlockSizeBytes (devicePath string ) (int64 , error ) {
543
531
output , err := ns .Mounter .Exec .Command ("blockdev" , "--getsize64" , devicePath ).CombinedOutput ()
544
532
if err != nil {
0 commit comments