diff --git a/pkg/util/metadata/metadata.go b/pkg/util/metadata/metadata.go index fdc2cbf739..5f5ee9d628 100644 --- a/pkg/util/metadata/metadata.go +++ b/pkg/util/metadata/metadata.go @@ -233,6 +233,41 @@ func GetDevicePath(volumeID string) string { return diskPaths[0] } + // For Hyper-V the path_id is created with the pattern *-lun- where sysnum is + // the last number in the address. + // Ref: https://github.com/systemd/systemd/blob/v246/src/udev/udev-builtin-path_id.c#L375 + adressParts := strings.Split(device.Address, ":") + if len(adressParts) > 0 { + diskId := adressParts[len(adressParts)-1] + diskPattern := fmt.Sprintf("/dev/disk/by-path/*-lun-%s", diskId) + diskPaths, err = filepath.Glob(diskPattern) + if err != nil { + klog.Errorf( + "could not retrieve disk path for volumeID: %q. Error filepath.Glob(%q): %v", + volumeID, diskPattern, err) + return "" + } + } + + if len(diskPaths) == 1 { + return diskPaths[0] + } + + // Hyper-V gen1 can have same lun number on several disks + if len(diskPaths) > 1 { + // Remove root and metadata disks + gen1DiskPaths := []string{} + for _, diskPath := range diskPaths { + if !strings.Contains(diskPath, "00000000000088990000000000000000") && + !strings.Contains(diskPath, "00000001000088990000000000000000") { + gen1DiskPaths = append(gen1DiskPaths, diskPath) + } + } + if len(gen1DiskPaths) == 1 { + return gen1DiskPaths[0] + } + } + klog.V(4).Infof("expecting to find one disk path for volumeID %q, found %d: %v", volumeID, len(diskPaths), diskPaths) @@ -243,6 +278,11 @@ func GetDevicePath(volumeID string) string { return "" } +func removeBootAndMetadataDisks(diskPaths []string) []string { + newSlice := []string{} + return newSlice +} + // Get retrieves metadata from either config drive or metadata service. // Search order depends on the order set in config file. func Get(order string) (*Metadata, error) {