Skip to content

Commit fd38ab6

Browse files
committed
Add logic for identifying device path on VMware
1 parent b990746 commit fd38ab6

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

pkg/mount/mount.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,3 +372,59 @@ func (m *mounter) Unpublish(path string) error {
372372
func (m *mounter) Unstage(path string) error {
373373
return mount.CleanupMountPoint(path, m, true)
374374
}
375+
376+
func (m *mounter) getDevicePathForVMware(volumeID string) (string, error) {
377+
// Loop through /dev/sdb to /dev/sdz (skip /dev/sda, which is usually the root disk)
378+
for i := 'b'; i <= 'z'; i++ {
379+
devicePath := fmt.Sprintf("/dev/sd%c", i)
380+
fmt.Printf("Checking VMware device path: %s\n", devicePath)
381+
382+
// Check if the device exists
383+
if _, err := os.Stat(devicePath); err == nil {
384+
// Verify it's a block device
385+
isBlock, err := m.IsBlockDevice(devicePath)
386+
if err == nil && isBlock {
387+
// Use the same verification as for XenServer
388+
if m.verifyVMwareDevice(devicePath, volumeID) {
389+
fmt.Printf("Found and verified VMware device: %s\n", devicePath)
390+
return devicePath, nil
391+
}
392+
}
393+
}
394+
}
395+
return "", fmt.Errorf("device not found for volume %s", volumeID)
396+
}
397+
398+
func (m *mounter) verifyVMwareDevice(devicePath string, volumeID string) bool {
399+
// 1. Check device size (optional: compare with expected size if available)
400+
size, err := m.GetBlockSizeBytes(devicePath)
401+
if err != nil {
402+
fmt.Printf("Failed to get device size: %v\n", err)
403+
return false
404+
}
405+
fmt.Printf("Device size: %d bytes\n", size)
406+
407+
// 2. Check if device is not mounted
408+
mounted, err := m.isDeviceMounted(devicePath)
409+
if err != nil {
410+
fmt.Printf("Failed to check if device is mounted: %v\n", err)
411+
return false
412+
}
413+
if mounted {
414+
fmt.Printf("Device is already mounted: %s\n", devicePath)
415+
return false
416+
}
417+
418+
// 3. Check device properties using udevadm (optional, for more robust matching)
419+
props, err := m.getDeviceProperties(devicePath)
420+
if err != nil {
421+
fmt.Printf("Failed to get device properties: %v\n", err)
422+
return false
423+
}
424+
fmt.Printf("Device properties: %v\n", props)
425+
426+
// Optionally, match by serial, wwn, or other property if you have it
427+
// if props["ID_SERIAL"] == expectedSerial { ... }
428+
429+
return true
430+
}

0 commit comments

Comments
 (0)