[pve-devel] [PATCH v2 storage 4/6] api: disks: initgpt: explicitly abort for partitions

Fabian Ebner f.ebner at proxmox.com
Wed Oct 6 11:18:44 CEST 2021


In preparation to extend disk_is_used to support partitions. Without
this new check, initgpt would also allow partitions once disk_is_used
supports partitions, which is not desirable.

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---

Changes from v1:
    * is_partition helper is now already added in an earlier patch.

 PVE/API2/Disks.pm | 1 +
 PVE/Diskmanage.pm | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/PVE/API2/Disks.pm b/PVE/API2/Disks.pm
index 96c19fd..25c9ded 100644
--- a/PVE/API2/Disks.pm
+++ b/PVE/API2/Disks.pm
@@ -260,6 +260,7 @@ __PACKAGE__->register_method ({
 
 	my $authuser = $rpcenv->get_user();
 
+	die "$disk is a partition\n" if PVE::Diskmanage::is_partition($disk);
 	die "disk $disk already in use\n" if PVE::Diskmanage::disk_is_used($disk);
 	my $worker = sub {
 	    PVE::Diskmanage::init_disk($disk, $param->{uuid});
diff --git a/PVE/Diskmanage.pm b/PVE/Diskmanage.pm
index c896c5a..f0e14dc 100644
--- a/PVE/Diskmanage.pm
+++ b/PVE/Diskmanage.pm
@@ -63,8 +63,8 @@ sub init_disk {
 
     assert_blockdev($disk);
 
-    # we should already have checked if it is in use in the api call
-    # but we check again for safety
+    # we should already have checked these in the api call, but we check again for safety
+    die "$disk is a partition\n" if is_partition($disk);
     die "disk $disk is already in use\n" if disk_is_used($disk);
 
     my $id = $uuid || 'R';
-- 
2.30.2






More information about the pve-devel mailing list