@@ -22,6 +22,7 @@ import (
22
22
"path/filepath"
23
23
"runtime"
24
24
"strconv"
25
+ "strings"
25
26
"time"
26
27
27
28
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-03-01/compute"
@@ -133,36 +134,24 @@ func (a *azureDiskAttacher) VolumesAreAttached(specs []*volume.Spec, nodeName ty
133
134
}
134
135
135
136
func (a * azureDiskAttacher ) WaitForAttach (spec * volume.Spec , devicePath string , _ * v1.Pod , timeout time.Duration ) (string , error ) {
136
- volumeSource , _ , err := getVolumeSource (spec )
137
- if err != nil {
138
- return "" , err
137
+ // devicePath could be a LUN number or
138
+ // "/dev/disk/azure/scsi1/lunx", "/dev/sdx" on Linux node
139
+ // "/dev/diskx" on Windows node
140
+ if strings .HasPrefix (devicePath , "/dev/" ) {
141
+ return devicePath , nil
139
142
}
140
143
141
- diskController , err := getDiskController ( a . plugin . host )
144
+ volumeSource , _ , err := getVolumeSource ( spec )
142
145
if err != nil {
143
146
return "" , err
144
147
}
145
148
146
149
nodeName := types .NodeName (a .plugin .host .GetHostName ())
147
150
diskName := volumeSource .DiskName
148
151
149
- lun := int32 (- 1 )
150
- if runtime .GOOS != "windows" {
151
- // on Linux, usually devicePath is like "/dev/disk/azure/scsi1/lun2", get LUN directly
152
- lun , err = getDiskLUN (devicePath )
153
- if err != nil {
154
- klog .V (2 ).Infof ("azureDisk - WaitForAttach: getDiskLUN(%s) failed with error: %v" , devicePath , err )
155
- }
156
- }
157
-
158
- if lun < 0 {
159
- klog .V (2 ).Infof ("azureDisk - WaitForAttach: begin to GetDiskLun by diskName(%s), DataDiskURI(%s), nodeName(%s), devicePath(%s)" ,
160
- diskName , volumeSource .DataDiskURI , nodeName , devicePath )
161
- lun , err = diskController .GetDiskLun (diskName , volumeSource .DataDiskURI , nodeName )
162
- if err != nil {
163
- return "" , err
164
- }
165
- klog .V (2 ).Infof ("azureDisk - WaitForAttach: GetDiskLun succeeded, got lun(%v)" , lun )
152
+ lun , err := strconv .Atoi (devicePath )
153
+ if err != nil {
154
+ return "" , fmt .Errorf ("parse %s failed with error: %v, diskName: %s, nodeName: %s" , devicePath , err , diskName , nodeName )
166
155
}
167
156
168
157
exec := a .plugin .host .GetExec (a .plugin .GetPluginName ())
@@ -249,6 +238,14 @@ func (attacher *azureDiskAttacher) MountDevice(spec *volume.Spec, devicePath str
249
238
if notMnt {
250
239
diskMounter := util .NewSafeFormatAndMountFromHost (azureDataDiskPluginName , attacher .plugin .host )
251
240
mountOptions := util .MountOptionFromSpec (spec , options ... )
241
+ if runtime .GOOS == "windows" {
242
+ // only parse devicePath on Windows node
243
+ diskNum , err := getDiskNum (devicePath )
244
+ if err != nil {
245
+ return err
246
+ }
247
+ devicePath = diskNum
248
+ }
252
249
err = diskMounter .FormatAndMount (devicePath , deviceMountPath , * volumeSource .FSType , mountOptions )
253
250
if err != nil {
254
251
if cleanErr := os .Remove (deviceMountPath ); cleanErr != nil {
0 commit comments