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.eb...@proxmox.com> --- No changes from v1. PVE/API2/Disks/Directory.pm | 28 ++++++++++++++++------------ PVE/API2/Disks/ZFS.pm | 11 ++++++++++- PVE/Diskmanage.pm | 2 +- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/PVE/API2/Disks/Directory.pm b/PVE/API2/Disks/Directory.pm index 1285274..52f0c86 100644 --- a/PVE/API2/Disks/Directory.pm +++ b/PVE/API2/Disks/Directory.pm @@ -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); diff --git a/PVE/API2/Disks/ZFS.pm b/PVE/API2/Disks/ZFS.pm index 1534631..6486404 100644 --- a/PVE/API2/Disks/ZFS.pm +++ b/PVE/API2/Disks/ZFS.pm @@ -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}); } diff --git a/PVE/Diskmanage.pm b/PVE/Diskmanage.pm index f0e14dc..18459f9 100644 --- a/PVE/Diskmanage.pm +++ b/PVE/Diskmanage.pm @@ -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}; -- 2.30.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel