[pve-devel] [PATCH storage 02/10] api: disk: work around udev bug to ensure its database is updated

Fabian Ebner f.ebner at proxmox.com
Tue Sep 28 13:39:42 CEST 2021


There is a udev bug [0] which can ultimately lead to the udev database
for certain devices not being actively updated. Determining whether a
disk is used or not in get_disks() (in part) relies upon lsblk, which
queries the udev database. Ensure the information is updated by
manually calling 'udevadm trigger' for the changed devices.

It's most important for the 'directory' API path, as mounting depends
on the '/dev/disk/by-uuid'-symlink to be generated.

[0]: https://github.com/systemd/systemd/issues/18525

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 PVE/API2/Disks.pm           | 11 ++++++++++-
 PVE/API2/Disks/Directory.pm |  6 ++++++
 PVE/API2/Disks/LVM.pm       |  8 +++++++-
 PVE/API2/Disks/LVMThin.pm   |  6 ++++++
 PVE/API2/Disks/ZFS.pm       |  6 ++++++
 5 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/PVE/API2/Disks.pm b/PVE/API2/Disks.pm
index 6c20931..96c19fd 100644
--- a/PVE/API2/Disks.pm
+++ b/PVE/API2/Disks.pm
@@ -9,6 +9,7 @@ use HTTP::Status qw(:constants);
 use PVE::Diskmanage;
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::SafeSyslog;
+use PVE::Tools qw(run_command);
 
 use PVE::API2::Disks::Directory;
 use PVE::API2::Disks::LVM;
@@ -302,7 +303,15 @@ __PACKAGE__->register_method ({
 	my $rpcenv = PVE::RPCEnvironment::get();
 	my $authuser = $rpcenv->get_user();
 
-	my $worker = sub { PVE::Diskmanage::wipe_blockdev($disk); };
+	my $worker = sub {
+	    PVE::Diskmanage::wipe_blockdev($disk);
+
+	    # FIXME: Remove once we depend on systemd >= v249.
+	    # Work around udev bug https://github.com/systemd/systemd/issues/18525 to ensure the
+	    # udev database is updated.
+	    eval { run_command(['udevadm', 'trigger', $disk]); };
+	    warn $@ if $@;
+	};
 
 	my $basename = basename($disk); # avoid '/' in the ID
 
diff --git a/PVE/API2/Disks/Directory.pm b/PVE/API2/Disks/Directory.pm
index 0068db6..1285274 100644
--- a/PVE/API2/Disks/Directory.pm
+++ b/PVE/API2/Disks/Directory.pm
@@ -266,6 +266,12 @@ __PACKAGE__->register_method ({
 
 		$write_ini->($ini, $mountunitpath);
 
+		# FIXME: Remove once we depend on systemd >= v249.
+		# Work around udev bug https://github.com/systemd/systemd/issues/18525 to ensure the
+		# udev database is updated and the $uuid_path symlink is actually created!
+		eval { run_command(['udevadm', 'trigger', $part]); };
+		warn $@ if $@;
+
 		run_command(['systemctl', 'daemon-reload']);
 		run_command(['systemctl', 'enable', $mountunitname]);
 		run_command(['systemctl', 'start', $mountunitname]);
diff --git a/PVE/API2/Disks/LVM.pm b/PVE/API2/Disks/LVM.pm
index 2c216c0..eb8f5c0 100644
--- a/PVE/API2/Disks/LVM.pm
+++ b/PVE/API2/Disks/LVM.pm
@@ -7,7 +7,7 @@ use PVE::Storage::LVMPlugin;
 use PVE::Diskmanage;
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::API2::Storage::Config;
-use PVE::Tools qw(lock_file);
+use PVE::Tools qw(lock_file run_command);
 
 use PVE::RPCEnvironment;
 use PVE::RESTHandler;
@@ -158,6 +158,12 @@ __PACKAGE__->register_method ({
 
 		PVE::Storage::LVMPlugin::lvm_create_volume_group($dev, $name);
 
+		# FIXME: Remove once we depend on systemd >= v249.
+		# Work around udev bug https://github.com/systemd/systemd/issues/18525 to ensure the
+		# udev database is updated.
+		eval { run_command(['udevadm', 'trigger', $dev]); };
+		warn $@ if $@;
+
 		if ($param->{add_storage}) {
 		    my $storage_params = {
 			type => 'lvm',
diff --git a/PVE/API2/Disks/LVMThin.pm b/PVE/API2/Disks/LVMThin.pm
index 81d91a6..2fd8484 100644
--- a/PVE/API2/Disks/LVMThin.pm
+++ b/PVE/API2/Disks/LVMThin.pm
@@ -132,6 +132,12 @@ __PACKAGE__->register_method ({
 		    $name
 		]);
 
+		# FIXME: Remove once we depend on systemd >= v249.
+		# Work around udev bug https://github.com/systemd/systemd/issues/18525 to ensure the
+		# udev database is updated.
+		eval { run_command(['udevadm', 'trigger', $dev]); };
+		warn $@ if $@;
+
 		if ($param->{add_storage}) {
 		    my $storage_params = {
 			type => 'lvmthin',
diff --git a/PVE/API2/Disks/ZFS.pm b/PVE/API2/Disks/ZFS.pm
index 885b93c..1534631 100644
--- a/PVE/API2/Disks/ZFS.pm
+++ b/PVE/API2/Disks/ZFS.pm
@@ -406,6 +406,12 @@ __PACKAGE__->register_method ({
 		    run_command($cmd);
 		}
 
+		# FIXME: Remove once we depend on systemd >= v249.
+		# Work around udev bug https://github.com/systemd/systemd/issues/18525 to ensure the
+		# udev database is updated.
+		eval { run_command(['udevadm', 'trigger', $devs->@*]); };
+		warn $@ if $@;
+
 		if ($param->{add_storage}) {
 		    my $storage_params = {
 			type => 'zfspool',
-- 
2.30.2






More information about the pve-devel mailing list