[pve-devel] [PATCH storage 1/1] fix #2777 add by-id link to disk udev info

Stoiko Ivanov s.ivanov at proxmox.com
Thu Jun 4 13:50:52 CEST 2020


when compiling the disk list add a property with a stable
/dev/disk/by-id/ path for a block device when available.

This is needed to create zpools with the stable by-id links

The /dev/disk/by-id/ directory can contain multiple links to the same device
(e.g. when it's used as a LVM PV, or one for the wwn/nvme-eui in addition
to the one with vendor and serial). We take the first one which matches
the bus where the disk is attached. For nvme disks we exclude the one
containing the nvme-eui.

The patch assumes that not all disks need to have such a link (e.g.
virtio-block devices as we pass them to guests).

Additionally the tests were adapted to run successfully.

Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
 PVE/API2/Disks/ZFS.pm                      | 4 ++--
 PVE/Diskmanage.pm                          | 8 ++++++++
 test/disk_tests/sas/disklist_expected.json | 3 ++-
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/PVE/API2/Disks/ZFS.pm b/PVE/API2/Disks/ZFS.pm
index 551f21a..8dcddb8 100644
--- a/PVE/API2/Disks/ZFS.pm
+++ b/PVE/API2/Disks/ZFS.pm
@@ -341,8 +341,8 @@ __PACKAGE__->register_method ({
 	my $compression = $param->{compression} // 'on';
 
 	foreach my $dev (@$devs) {
-	    $dev = PVE::Diskmanage::verify_blockdev_path($dev);
-	    PVE::Diskmanage::assert_disk_unused($dev);
+	    my $abs_dev = PVE::Diskmanage::verify_blockdev_path($dev);
+	    PVE::Diskmanage::assert_disk_unused($abs_dev);
 	}
 
 	PVE::Storage::assert_sid_unused($name) if $param->{add_storage};
diff --git a/PVE/Diskmanage.pm b/PVE/Diskmanage.pm
index cac944d..267da08 100644
--- a/PVE/Diskmanage.pm
+++ b/PVE/Diskmanage.pm
@@ -359,6 +359,11 @@ sub get_udev_info {
 	$data->{wwn} = $1;
     }
 
+    if ($info =~ m/^E: DEVLINKS=(.+)$/m) {
+	my @devlinks = grep(m#^/dev/disk/by-id/(ata|scsi|nvme(?!-eui))#, split (/ /, $1));
+	$data->{by_id_link} = $devlinks[0] if defined($devlinks[0]);
+    }
+
     return $data;
 }
 
@@ -584,6 +589,9 @@ sub get_disks {
 	    wearout => $wearout,
 	};
 
+	my $by_id_link = $data->{by_id_link};
+	$disklist->{$dev}->{by_id_link} = $by_id_link if defined($by_id_link);
+
 	my $osdid = -1;
 	my $bluestore = 0;
 	my $osdencrypted = 0;
diff --git a/test/disk_tests/sas/disklist_expected.json b/test/disk_tests/sas/disklist_expected.json
index 7814765..39b14a5 100644
--- a/test/disk_tests/sas/disklist_expected.json
+++ b/test/disk_tests/sas/disklist_expected.json
@@ -11,6 +11,7 @@
 	"rpm" : -1,
 	"size" : 5120000,
 	"serial" : "SER2",
-	"wearout" : "N/A"
+	"wearout" : "N/A",
+	"by_id_link" : "/dev/disk/by-id/scsi-00000000000000000"
     }
 }
-- 
2.20.1





More information about the pve-devel mailing list