[pve-devel] [PATCH storage 06/10] api: disks: initgpt: explicitly abort for partitions
Thomas Lamprecht
t.lamprecht at proxmox.com
Thu Sep 30 18:02:56 CEST 2021
On 28.09.21 13:39, Fabian Ebner wrote:
> 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>
> ---
> PVE/API2/Disks.pm | 1 +
> PVE/Diskmanage.pm | 10 ++++++++--
> 2 files changed, 9 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 7aad707..73cbb8b 100644
> --- a/PVE/Diskmanage.pm
> +++ b/PVE/Diskmanage.pm
> @@ -57,8 +57,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';
> @@ -798,6 +798,12 @@ sub get_blockdev {
> return $block_dev;
> }
>
> +sub is_partition {
> + my ($dev_path) = @_;
> +
> + return defined(eval { get_partnum($dev_path) });
> +}
> +
you add `is_partition` here but use it already in patch 04/10, can we reorder that?
Or maybe squash in the addition into 03/10?
> sub locked_disk_action {
> my ($sub) = @_;
> my $res = PVE::Tools::lock_file('/run/lock/pve-diskmanage.lck', undef, $sub);
>
More information about the pve-devel
mailing list