@@ -115,22 +115,23 @@ func (m *mounter) GetDevicePath(ctx context.Context, volumeID string) (string, e
115
115
116
116
func (m * mounter ) getDevicePathBySerialID (volumeID string ) (string , error ) {
117
117
// First try XenServer device paths
118
- for i := 'b' ; i <= 'z' ; i ++ {
119
- devicePath := fmt .Sprintf ("/dev/xvd%c" , i )
120
- fmt .Printf ("Checking XenServer device path: %s\n " , devicePath )
121
-
122
- if _ , err := os .Stat (devicePath ); err == nil {
123
- isBlock , err := m .IsBlockDevice (devicePath )
124
- if err == nil && isBlock {
125
- if m .verifyXenServerDevice (devicePath , volumeID ) {
126
- fmt .Printf ("Found and verified XenServer device: %s\n " , devicePath )
127
- return devicePath , nil
128
- }
129
- }
130
- }
118
+ xenDevicePath , err := m .getDevicePathForXenServer (volumeID )
119
+ if err != nil {
120
+ fmt .Printf ("Failed to get VMware device path: %v\n " , err )
121
+ }
122
+ if xenDevicePath != "" {
123
+ return xenDevicePath , nil
131
124
}
132
125
133
- // Fall back to standard device paths
126
+ // Try VMware device paths
127
+ vmwareDevicePath , err := m .getDevicePathForVMware (volumeID )
128
+ if err != nil {
129
+ fmt .Printf ("Failed to get VMware device path: %v\n " , err )
130
+ }
131
+ if vmwareDevicePath != "" {
132
+ return vmwareDevicePath , nil
133
+ }
134
+ // Fall back to standard device paths (for KVM)
134
135
sourcePathPrefixes := []string {"virtio-" , "scsi-" , "scsi-0QEMU_QEMU_HARDDISK_" }
135
136
serial := diskUUIDToSerial (volumeID )
136
137
fmt .Printf ("Searching for device with serial: %s\n " , serial )
@@ -150,6 +151,24 @@ func (m *mounter) getDevicePathBySerialID(volumeID string) (string, error) {
150
151
return "" , nil
151
152
}
152
153
154
+ func (m * mounter ) getDevicePathForXenServer (volumeID string ) (string , error ) {
155
+ for i := 'b' ; i <= 'z' ; i ++ {
156
+ devicePath := fmt .Sprintf ("/dev/xvd%c" , i )
157
+ fmt .Printf ("Checking XenServer device path: %s\n " , devicePath )
158
+
159
+ if _ , err := os .Stat (devicePath ); err == nil {
160
+ isBlock , err := m .IsBlockDevice (devicePath )
161
+ if err == nil && isBlock {
162
+ if m .verifyXenServerDevice (devicePath , volumeID ) {
163
+ fmt .Printf ("Found and verified XenServer device: %s\n " , devicePath )
164
+ return devicePath , nil
165
+ }
166
+ }
167
+ }
168
+ }
169
+ return "" , fmt .Errorf ("device not found for volume %s" , volumeID )
170
+ }
171
+
153
172
func (m * mounter ) verifyXenServerDevice (devicePath string , volumeID string ) bool {
154
173
size , err := m .GetBlockSizeBytes (devicePath )
155
174
if err != nil {
@@ -372,3 +391,51 @@ func (m *mounter) Unpublish(path string) error {
372
391
func (m * mounter ) Unstage (path string ) error {
373
392
return mount .CleanupMountPoint (path , m , true )
374
393
}
394
+
395
+ func (m * mounter ) getDevicePathForVMware (volumeID string ) (string , error ) {
396
+ // Loop through /dev/sdb to /dev/sdz (/dev/sda -> the root disk)
397
+ for i := 'b' ; i <= 'z' ; i ++ {
398
+ devicePath := fmt .Sprintf ("/dev/sd%c" , i )
399
+ fmt .Printf ("Checking VMware device path: %s\n " , devicePath )
400
+
401
+ if _ , err := os .Stat (devicePath ); err == nil {
402
+ isBlock , err := m .IsBlockDevice (devicePath )
403
+ if err == nil && isBlock {
404
+ // Use the same verification as for XenServer
405
+ if m .verifyVMwareDevice (devicePath , volumeID ) {
406
+ fmt .Printf ("Found and verified VMware device: %s\n " , devicePath )
407
+ return devicePath , nil
408
+ }
409
+ }
410
+ }
411
+ }
412
+ return "" , fmt .Errorf ("device not found for volume %s" , volumeID )
413
+ }
414
+
415
+ func (m * mounter ) verifyVMwareDevice (devicePath string , volumeID string ) bool {
416
+ size , err := m .GetBlockSizeBytes (devicePath )
417
+ if err != nil {
418
+ fmt .Printf ("Failed to get device size: %v\n " , err )
419
+ return false
420
+ }
421
+ fmt .Printf ("Device size: %d bytes\n " , size )
422
+
423
+ mounted , err := m .isDeviceMounted (devicePath )
424
+ if err != nil {
425
+ fmt .Printf ("Failed to check if device is mounted: %v\n " , err )
426
+ return false
427
+ }
428
+ if mounted {
429
+ fmt .Printf ("Device is already mounted: %s\n " , devicePath )
430
+ return false
431
+ }
432
+
433
+ props , err := m .getDeviceProperties (devicePath )
434
+ if err != nil {
435
+ fmt .Printf ("Failed to get device properties: %v\n " , err )
436
+ return false
437
+ }
438
+ fmt .Printf ("Device properties: %v\n " , props )
439
+
440
+ return true
441
+ }
0 commit comments