]> git.proxmox.com Git - pve-storage.git/commitdiff
partially fix #2285: api: disks: allow partitions for creation paths
authorFabian Ebner <f.ebner@proxmox.com>
Wed, 6 Oct 2021 09:18:45 +0000 (11:18 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 7 Oct 2021 12:39:26 +0000 (14:39 +0200)
The calls for directory and ZFS need slight adaptations. Except for
those, the only thing that needs to be done is support partitions in
the disk_is_used helper.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
PVE/API2/Disks/Directory.pm
PVE/API2/Disks/ZFS.pm
PVE/Diskmanage.pm

index 12852748d168c614abb3b6fc0d8c23d8d3da9b28..52f0c863a89ef06158d7f1eb47a53910369cc8e9 100644 (file)
@@ -214,20 +214,24 @@ __PACKAGE__->register_method ({
            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";
-               run_command($cmd);
-
-               my ($devname) = $dev =~ m|^/dev/(.*)$|;
-               my $part = "/dev/";
-               dir_glob_foreach("/sys/block/$devname", qr/\Q$devname\E.+/, sub {
-                   my ($partition) = @_;
-                   $part .= $partition;
-               });
+               my $part = $dev;
+
+               if (!PVE::Diskmanage::is_partition($dev)) {
+                   # create partition
+                   my $cmd = [$SGDISK, '-n1', '-t1:8300', $dev];
+                   print "# ", join(' ', @$cmd), "\n";
+                   run_command($cmd);
+
+                   my ($devname) = $dev =~ m|^/dev/(.*)$|;
+                   $part = "/dev/";
+                   dir_glob_foreach("/sys/block/$devname", qr/\Q$devname\E.+/, sub {
+                       my ($partition) = @_;
+                       $part .= $partition;
+                   });
+               }
 
                # create filesystem
-               $cmd = [$MKFS, '-t', $type, $part];
+               my $cmd = [$MKFS, '-t', $type, $part];
                print "# ", join(' ', @$cmd), "\n";
                run_command($cmd);
 
index 1534631c9a9028fe52698ee60ccf1832409764d3..6486404b917bbac5cd79bdba8b019c0ca4e8346c 100644 (file)
@@ -373,7 +373,16 @@ __PACKAGE__->register_method ({
            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 $is_partition = PVE::Diskmanage::is_partition($dev);
+                   my $sysfsdev = $is_partition ? PVE::Diskmanage::get_blockdev($dev) : $dev;
+
+                   $sysfsdev =~ s!^/dev/!/sys/block/!;
+                   if ($is_partition) {
+                       my $part = $dev =~ s!^/dev/!!r;
+                       $sysfsdev .= "/${part}";
+                   }
+
                    my $udevinfo = PVE::Diskmanage::get_udev_info($sysfsdev);
                    $dev = $udevinfo->{by_id_link} if defined($udevinfo->{by_id_link});
                }
index f0e14dc5f3a3e6b38c7f6e0ba6679b361b92fcfd..18459f95291a5f70af8c051d49208cb7705fee71 100644 (file)
@@ -78,7 +78,7 @@ sub disk_is_used {
     my $dev = $disk;
     $dev =~ s|^/dev/||;
 
-    my $disklist = get_disks($dev, 1);
+    my $disklist = get_disks($dev, 1, 1);
 
     die "'$disk' is not a valid local disk\n" if !defined($disklist->{$dev});
     return 1 if $disklist->{$dev}->{used};