Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions pkg/util/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,41 @@ func GetDevicePath(volumeID string) string {
return diskPaths[0]
}

// For Hyper-V the path_id is created with the pattern *-lun-<sysnum> 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)

Expand All @@ -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) {
Expand Down