@@ -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,46 @@ 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
+ klog .Infof ("get device path %v %v" , volumeID , partition )
277
+ devicePath , err := GetDevicePath (ns , volumeID , partition )
267
278
268
- devicePath , err := ns .getDevicePath (volumeID , partition )
269
279
if err != nil {
270
- return nil , status .Error (codes .Internal , fmt .Sprintf ("Error when getting device path: %v" , err ))
280
+ return nil , status .Error (codes .Internal , fmt .Sprintf ("Error when getting device path volumeID %s : %v" , volumeID , err ))
271
281
}
272
282
273
283
klog .V (4 ).Infof ("Successfully found attached GCE PD %q at device path %s." , volumeKey .Name , devicePath )
274
284
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 ))
285
+ if runtime .GOOS != "windows" {
286
+ // Part 2: Check if mount already exists at targetpath
287
+ notMnt , err := ns .Mounter .Interface .IsLikelyNotMountPoint (stagingTargetPath )
288
+ if err != nil {
289
+ if os .IsNotExist (err ) {
290
+ if err := os .MkdirAll (stagingTargetPath , 0750 ); err != nil {
291
+ return nil , status .Error (codes .Internal , fmt .Sprintf ("Failed to create directory (%q): %v" , stagingTargetPath , err ))
292
+ }
293
+ notMnt = true
294
+ } else {
295
+ return nil , status .Error (codes .Internal , fmt .Sprintf ("Unknown error when checking mount point (%q): %v" , stagingTargetPath , err ))
281
296
}
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
297
}
286
- }
287
298
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
299
+ if ! notMnt {
300
+ // TODO(#95): Check who is mounted here. No error if its us
301
+ /*
302
+ 1) Target Path MUST be the vol referenced by vol ID
303
+ 2) VolumeCapability MUST match
304
+ 3) Readonly MUST match
294
305
295
- */
306
+ */
296
307
297
- klog .V (4 ).Infof ("NodeStageVolume succeded on %v to %s, mount already exists." , volumeID , stagingTargetPath )
298
- return & csi.NodeStageVolumeResponse {}, nil
308
+ klog .V (4 ).Infof ("NodeStageVolume succeded on %v to %s, mount already exists." , volumeID , stagingTargetPath )
309
+ return & csi.NodeStageVolumeResponse {}, nil
299
310
311
+ }
300
312
}
301
-
302
313
// Part 3: Mount device to stagingTargetPath
303
- // Default fstype is ext4
304
- fstype := "ext4"
314
+ fstype := getDefaultFsType ()
315
+
305
316
options := []string {}
306
317
if mnt := volumeCapability .GetMount (); mnt != nil {
307
318
if mnt .FsType != "" {
@@ -316,7 +327,8 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
316
327
return & csi.NodeStageVolumeResponse {}, nil
317
328
}
318
329
319
- err = ns .Mounter .FormatAndMount (devicePath , stagingTargetPath , fstype , options )
330
+ //err = ns.Mounter.FormatAndMount(devicePath, stagingTargetPath, fstype, options)
331
+ err = FormatAndMount (devicePath , stagingTargetPath , fstype , options , ns .Mounter )
320
332
if err != nil {
321
333
return nil , status .Error (codes .Internal ,
322
334
fmt .Sprintf ("Failed to format and mount device from (%q) to (%q) with fstype (%q) and options (%q): %v" ,
@@ -343,9 +355,8 @@ func (ns *GCENodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUns
343
355
}
344
356
defer ns .volumeLocks .Release (volumeID )
345
357
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 ))
358
+ if err := cleanupPublishPath (stagingTargetPath , ns .Mounter ); err != nil {
359
+ return nil , status .Error (codes .Internal , fmt .Sprintf ("NodeUnstageVolume failed: %v\n Unmounting arguments: %s\n " , err , stagingTargetPath ))
349
360
}
350
361
351
362
klog .V (4 ).Infof ("NodeUnstageVolume succeded on %v from %s" , volumeID , stagingTargetPath )
@@ -454,7 +465,7 @@ func (ns *GCENodeServer) NodeExpandVolume(ctx context.Context, req *csi.NodeExpa
454
465
return nil , status .Error (codes .InvalidArgument , fmt .Sprintf ("volume ID is invalid: %v" , err ))
455
466
}
456
467
457
- devicePath , err := ns . getDevicePath ( volumeID , "" )
468
+ devicePath , err := GetDevicePath ( ns , volumeID , "" )
458
469
if err != nil {
459
470
return nil , status .Error (codes .Internal , fmt .Sprintf ("error when getting device path for %s: %v" , volumeID , err ))
460
471
}
@@ -517,7 +528,7 @@ func (ns *GCENodeServer) GetVolumeLimits() (int64, error) {
517
528
return volumeLimitBig , nil
518
529
}
519
530
520
- func (ns * GCENodeServer ) getDevicePath (volumeID string , partition string ) (string , error ) {
531
+ /* func (ns *GCENodeServer) getDevicePath(volumeID string, partition string) (string, error) {
521
532
volumeKey, err := common.VolumeIDToKey(volumeID)
522
533
if err != nil {
523
534
return "", err
@@ -537,7 +548,7 @@ func (ns *GCENodeServer) getDevicePath(volumeID string, partition string) (strin
537
548
return "", fmt.Errorf("unable to find device path out of attempted paths: %v", devicePaths)
538
549
}
539
550
return devicePath, nil
540
- }
551
+ }*/
541
552
542
553
func (ns * GCENodeServer ) getBlockSizeBytes (devicePath string ) (int64 , error ) {
543
554
output , err := ns .Mounter .Exec .Command ("blockdev" , "--getsize64" , devicePath ).CombinedOutput ()
0 commit comments