api: disk: work around udev bug to ensure its database is updated

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@proxmox.com>
This commit is contained in:
Fabian Ebner
2021-09-28 13:39:42 +02:00
committed by Thomas Lamprecht
parent e99bc248d4
commit 21a75847a8
5 changed files with 35 additions and 2 deletions

View File

@ -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

View File

@ -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]);

View File

@ -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',

View File

@ -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',

View File

@ -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',