From cc884f73d8527722df56f11acb3eced13cd4f2e4 Mon Sep 17 00:00:00 2001 From: Fabian Ebner Date: Wed, 6 Oct 2021 11:18:44 +0200 Subject: [PATCH] api: disks: initgpt: explicitly abort for partitions 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 --- 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.39.5