[pve-devel] [PATCH storage 06/10] api: disks: initgpt: explicitly abort for partitions

Fabian Ebner f.ebner at proxmox.com
Wed Oct 6 09:11:35 CEST 2021


Am 30.09.21 um 18:02 schrieb Thomas Lamprecht:
> 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?
> 

Sorry about that. I think I had the condition inlined in 04/10 at first 
and forgot to re-order after I introduced and switched to the helper.

I'll send a v2 and squash 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