Because then it might not be unused anymore. If there really is a race, this prevents e.g. sgdisk creating a partition on a device already in use by LVM or LVM destroying a partitioned device.
For ZFS, also get the latest udev info once inside the worker. Signed-off-by: Fabian Ebner <f.eb...@proxmox.com> --- PVE/API2/Disks/Directory.pm | 2 ++ PVE/API2/Disks/LVM.pm | 2 ++ PVE/API2/Disks/LVMThin.pm | 2 ++ PVE/API2/Disks/ZFS.pm | 10 +++++++--- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/PVE/API2/Disks/Directory.pm b/PVE/API2/Disks/Directory.pm index 2decb89..0068db6 100644 --- a/PVE/API2/Disks/Directory.pm +++ b/PVE/API2/Disks/Directory.pm @@ -212,6 +212,8 @@ __PACKAGE__->register_method ({ my $mountunitpath = "/etc/systemd/system/$mountunitname"; PVE::Diskmanage::locked_disk_action(sub { + PVE::Diskmanage::assert_disk_unused($dev); + # create partition my $cmd = [$SGDISK, '-n1', '-t1:8300', $dev]; print "# ", join(' ', @$cmd), "\n"; diff --git a/PVE/API2/Disks/LVM.pm b/PVE/API2/Disks/LVM.pm index 569e9d1..2c216c0 100644 --- a/PVE/API2/Disks/LVM.pm +++ b/PVE/API2/Disks/LVM.pm @@ -154,6 +154,8 @@ __PACKAGE__->register_method ({ my $worker = sub { PVE::Diskmanage::locked_disk_action(sub { + PVE::Diskmanage::assert_disk_unused($dev); + PVE::Storage::LVMPlugin::lvm_create_volume_group($dev, $name); if ($param->{add_storage}) { diff --git a/PVE/API2/Disks/LVMThin.pm b/PVE/API2/Disks/LVMThin.pm index 4d303f8..81d91a6 100644 --- a/PVE/API2/Disks/LVMThin.pm +++ b/PVE/API2/Disks/LVMThin.pm @@ -108,6 +108,8 @@ __PACKAGE__->register_method ({ my $worker = sub { PVE::Diskmanage::locked_disk_action(sub { + PVE::Diskmanage::assert_disk_unused($dev); + PVE::Storage::LVMPlugin::lvm_create_volume_group($dev, $name); my $pv = PVE::Storage::LVMPlugin::lvm_pv_info($dev); # keep some free space just in case diff --git a/PVE/API2/Disks/ZFS.pm b/PVE/API2/Disks/ZFS.pm index 60077c4..885b93c 100644 --- a/PVE/API2/Disks/ZFS.pm +++ b/PVE/API2/Disks/ZFS.pm @@ -345,9 +345,6 @@ __PACKAGE__->register_method ({ foreach my $dev (@$devs) { $dev = PVE::Diskmanage::verify_blockdev_path($dev); PVE::Diskmanage::assert_disk_unused($dev); - my $sysfsdev = $dev =~ s!^/dev/!/sys/block/!r; - my $udevinfo = PVE::Diskmanage::get_udev_info($sysfsdev); - $dev = $udevinfo->{by_id_link} if defined($udevinfo->{by_id_link}); } PVE::Storage::assert_sid_unused($name) if $param->{add_storage}; @@ -374,6 +371,13 @@ __PACKAGE__->register_method ({ my $worker = sub { PVE::Diskmanage::locked_disk_action(sub { + for my $dev (@$devs) { + PVE::Diskmanage::assert_disk_unused($dev); + my $sysfsdev = $dev =~ s!^/dev/!/sys/block/!r; + my $udevinfo = PVE::Diskmanage::get_udev_info($sysfsdev); + $dev = $udevinfo->{by_id_link} if defined($udevinfo->{by_id_link}); + } + # create zpool with desired raidlevel my $cmd = [$ZPOOL, 'create', '-o', "ashift=$ashift", $name]; -- 2.30.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel