]> git.proxmox.com Git - pve-storage.git/commitdiff
api: disks: create: re-check disk after fork/lock
authorFabian Ebner <f.ebner@proxmox.com>
Tue, 28 Sep 2021 11:39:41 +0000 (13:39 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 30 Sep 2021 16:04:22 +0000 (18:04 +0200)
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.ebner@proxmox.com>
PVE/API2/Disks/Directory.pm
PVE/API2/Disks/LVM.pm
PVE/API2/Disks/LVMThin.pm
PVE/API2/Disks/ZFS.pm

index 2decb89675abc756762822d5bf53e506df0aef98..0068db6bb879fa5cca24efff699339ffbde47c83 100644 (file)
@@ -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";
index 569e9d1afae9b94f3ac200ae1fc74d88bfe0746f..2c216c0f6baeb7d20c3f841a1cd137d944b25c35 100644 (file)
@@ -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}) {
index 4d303f8daa89dbb0fdc35ceb8fb29ade1eebe62e..81d91a616034615f35514fd26004e497a0a92676 100644 (file)
@@ -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
index 60077c421f7a3df7f0ac741d2f7332a10555c5da..885b93c151cf755eed76d8f2c2aa15cb421db848 100644 (file)
@@ -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];