@@ -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,12 @@ 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 {
134
- return nil , status .Error (codes .Internal , fmt .Sprintf ("mkdir failed on disk %s (%v)" , targetPath , err ))
135
- }
143
+ /*if runtime.GOOS != "windows" {
144
+ if err := os.MkdirAll(targetPath, 0750); err != nil {
145
+ return nil, status.Error(codes.Internal, fmt.Sprintf("mkdir failed on disk %s (%v)", targetPath, err))
146
+ }
147
+ }*/
148
+ preparePublishPath (targetPath , ns .Mounter )
136
149
} else if blk := volumeCapability .GetBlock (); blk != nil {
137
150
klog .V (4 ).Infof ("NodePublishVolume with block volume mode" )
138
151
@@ -218,11 +231,9 @@ func (ns *GCENodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeU
218
231
}
219
232
defer ns .volumeLocks .Release (volumeID )
220
233
221
- err := mount .CleanupMountPoint (targetPath , ns .Mounter .Interface , false /* bind mount */ )
222
- if err != nil {
234
+ if err := cleanupPublishPath (targetPath , ns .Mounter ); err != nil {
223
235
return nil , status .Error (codes .Internal , fmt .Sprintf ("Unmount failed: %v\n Unmounting arguments: %s\n " , err , targetPath ))
224
236
}
225
-
226
237
klog .V (4 ).Infof ("NodeUnpublishVolume succeded on %v from %s" , volumeID , targetPath )
227
238
return & csi.NodeUnpublishVolumeResponse {}, nil
228
239
}
@@ -265,43 +276,51 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
265
276
partition = part
266
277
}
267
278
268
- devicePath , err := ns .getDevicePath (volumeID , partition )
279
+ deviceName , err := common .GetDeviceName (volumeKey )
280
+ if err != nil {
281
+ return nil , fmt .Errorf ("error getting device name: %v" , err )
282
+ }
283
+
284
+ devicePath , err := GetDevicePath (ns , deviceName , partition , volumeKey .Name , ns .Mounter )
285
+ //devicePath, err := ns.getDevicePath(volumeID, partition)
286
+
269
287
if err != nil {
270
288
return nil , status .Error (codes .Internal , fmt .Sprintf ("Error when getting device path: %v" , err ))
271
289
}
272
290
273
291
klog .V (4 ).Infof ("Successfully found attached GCE PD %q at device path %s." , volumeKey .Name , devicePath )
274
292
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 ))
293
+ if runtime .GOOS != "windows" {
294
+ // Part 2: Check if mount already exists at targetpath
295
+ notMnt , err := ns .Mounter .Interface .IsLikelyNotMountPoint (stagingTargetPath )
296
+ if err != nil {
297
+ if os .IsNotExist (err ) {
298
+ if err := os .MkdirAll (stagingTargetPath , 0750 ); err != nil {
299
+ return nil , status .Error (codes .Internal , fmt .Sprintf ("Failed to create directory (%q): %v" , stagingTargetPath , err ))
300
+ }
301
+ notMnt = true
302
+ } else {
303
+ return nil , status .Error (codes .Internal , fmt .Sprintf ("Unknown error when checking mount point (%q): %v" , stagingTargetPath , err ))
281
304
}
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
305
}
286
- }
287
306
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
307
+ if ! notMnt {
308
+ // TODO(#95): Check who is mounted here. No error if its us
309
+ /*
310
+ 1) Target Path MUST be the vol referenced by vol ID
311
+ 2) VolumeCapability MUST match
312
+ 3) Readonly MUST match
294
313
295
- */
314
+ */
296
315
297
- klog .V (4 ).Infof ("NodeStageVolume succeded on %v to %s, mount already exists." , volumeID , stagingTargetPath )
298
- return & csi.NodeStageVolumeResponse {}, nil
316
+ klog .V (4 ).Infof ("NodeStageVolume succeded on %v to %s, mount already exists." , volumeID , stagingTargetPath )
317
+ return & csi.NodeStageVolumeResponse {}, nil
299
318
319
+ }
300
320
}
301
-
302
321
// Part 3: Mount device to stagingTargetPath
303
- // Default fstype is ext4
304
- fstype := "ext4"
322
+ fstype := getDefaultFsType ()
323
+
305
324
options := []string {}
306
325
if mnt := volumeCapability .GetMount (); mnt != nil {
307
326
if mnt .FsType != "" {
@@ -316,7 +335,8 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
316
335
return & csi.NodeStageVolumeResponse {}, nil
317
336
}
318
337
319
- err = ns .Mounter .FormatAndMount (devicePath , stagingTargetPath , fstype , options )
338
+ //err = ns.Mounter.FormatAndMount(devicePath, stagingTargetPath, fstype, options)
339
+ err = FormatAndMount (devicePath , stagingTargetPath , fstype , options , ns .Mounter )
320
340
if err != nil {
321
341
return nil , status .Error (codes .Internal ,
322
342
fmt .Sprintf ("Failed to format and mount device from (%q) to (%q) with fstype (%q) and options (%q): %v" ,
@@ -343,9 +363,8 @@ func (ns *GCENodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUns
343
363
}
344
364
defer ns .volumeLocks .Release (volumeID )
345
365
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 ))
366
+ if err := cleanupPublishPath (stagingTargetPath , ns .Mounter ); err != nil {
367
+ return nil , status .Error (codes .Internal , fmt .Sprintf ("NodeUnstageVolume failed: %v\n Unmounting arguments: %s\n " , err , stagingTargetPath ))
349
368
}
350
369
351
370
klog .V (4 ).Infof ("NodeUnstageVolume succeded on %v from %s" , volumeID , stagingTargetPath )
0 commit comments