From ad114d8cdf271b9dcc1565ad9cab582016f60a4b Mon Sep 17 00:00:00 2001 From: Peter Rosell Date: Thu, 10 Sep 2020 17:06:04 +0200 Subject: [PATCH 1/2] find device by path from lun address Disks can appear with the pattern `/dev/disk/by-path/*lun-` on Hyper-V. Using the address as an id, removing the separators. Not sure about the format and what will happen when more than 255 disks are attached. --- pkg/util/metadata/metadata.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pkg/util/metadata/metadata.go b/pkg/util/metadata/metadata.go index fdc2cbf739..87a2187ecd 100644 --- a/pkg/util/metadata/metadata.go +++ b/pkg/util/metadata/metadata.go @@ -233,6 +233,26 @@ 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] + } + klog.V(4).Infof("expecting to find one disk path for volumeID %q, found %d: %v", volumeID, len(diskPaths), diskPaths) From fb7c08c318099d4511a4e0dba0e2975190c4b16c Mon Sep 17 00:00:00 2001 From: Peter Rosell Date: Mon, 5 Oct 2020 08:51:55 +0200 Subject: [PATCH 2/2] add support for Hyper-V gen1 --- pkg/util/metadata/metadata.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pkg/util/metadata/metadata.go b/pkg/util/metadata/metadata.go index 87a2187ecd..5f5ee9d628 100644 --- a/pkg/util/metadata/metadata.go +++ b/pkg/util/metadata/metadata.go @@ -253,6 +253,21 @@ func GetDevicePath(volumeID string) string { 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) @@ -263,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) {