[pve-devel] [PATCH pve-storage v2 4/5] vdisk_alloc: factor out optional parameters in options hash argument
Daniel Kral
d.kral at proxmox.com
Thu Feb 20 10:34:50 CET 2025
On 2/20/25 09:49, Fiona Ebner wrote:
> Am 11.02.25 um 17:07 schrieb Daniel Kral:
>> Moves the optional parameter `name` into an optional hash argument at
>> the end of the function.
>>
>> This allows to add more optional arguments in the future and makes the
>> function call easier to follow when a name is not required.
>>
>> Signed-off-by: Daniel Kral <d.kral at proxmox.com>
>> ---
>
> While the cover letter already talks about it, it never hurts to
> explicitly mention that this requires a versioned breaks for qemu-server
> and pve-container again in the patch itself.
>
>> changes since v1:
>> - new!
>>
>> src/PVE/API2/Storage/Content.pm | 6 +++---
>> src/PVE/GuestImport.pm | 2 +-
>> src/PVE/Storage.pm | 30 ++++++++++++++++++++++++++++--
>> src/test/run_test_zfspoolplugin.pl | 8 ++++----
>> 4 files changed, 36 insertions(+), 10 deletions(-)
>>
>> diff --git a/src/PVE/API2/Storage/Content.pm b/src/PVE/API2/Storage/Content.pm
>> index fe0ad4a..77924a6 100644
>> --- a/src/PVE/API2/Storage/Content.pm
>> +++ b/src/PVE/API2/Storage/Content.pm
>> @@ -220,9 +220,9 @@ __PACKAGE__->register_method ({
>>
>> my $cfg = PVE::Storage::config();
>>
>> - my $volid = PVE::Storage::vdisk_alloc ($cfg, $storeid, $param->{vmid},
>> - $param->{format},
>> - $name, $size);
>> + my $volid = PVE::Storage::vdisk_alloc($cfg, $storeid, $param->{vmid}, $param->{format}, $size, {
>> + name => $name,
>> + });
>
> Style nit: the first line is still too long and just having the last
> param split out like this looks kinda wonky here. I'd go for this instead:
Will do so (also at other locations where this happened)!
>
>> my $volid = PVE::Storage::vdisk_alloc(
>> $cfg, $storeid, $param->{vmid}, $param->{format}, $size, { name => $name });
>
>
>>
>> return $volid;
>> }});
>
> ---snip 8<---
>
>> diff --git a/src/PVE/Storage.pm b/src/PVE/Storage.pm
>> index 0134893..3776565 100755
>> --- a/src/PVE/Storage.pm
>> +++ b/src/PVE/Storage.pm
>> @@ -1041,8 +1041,34 @@ sub unmap_volume {
>> return $plugin->unmap_volume($storeid, $scfg, $volname, $snapname);
>> }
>>
>> -sub vdisk_alloc {
>> - my ($cfg, $storeid, $vmid, $fmt, $name, $size) = @_;
>> +=head3 vdisk_alloc($cfg, $storeid, $vmid, $size, %opts)
>
> It's missing $fmt here.
Sorry, yes it does! Thanks for spotting this and will take more care
with the documentation when preparing the v3.
>
>> +
>> +Allocates a volume on the storage with the identifier C<$storeid> (defined in the storage config
>> +C<$cfg>) for the VM with the id C<$vmid> with format C<$fmt> and a size of C<$size> kilobytes.
>> +
>> +The format C<$fmt> can be C<'raw'>, C<'qcow2'>, C<'subvol'> or C<'vmdk'>. If C<$fmt> is left
>> +undefined, it will fallback on the default format of the storage type of C<$storeid>.
>> +
>> +Optionally, the following key-value pairs are available for C<%opts>:
>> +
>> +=over
>> +
>> +=item * C<< $name => $string >>
>> +
>> +Specifies the name of the new volume.
>> +
>> +If undefined, the name will be generated with C<PVE::Storage::Plugin::find_free_diskname>.
>
> This might be true for our plugins, but other plugins might not use this
> method. I'd just mention that it will be generated, but not how.
Will do so!
More information about the pve-devel
mailing list