[pve-devel] [RFC qemu-server 2/9] cfg2cmd: improve error message for invalid volume storage content type

Fiona Ebner f.ebner at proxmox.com
Fri Nov 29 15:23:35 CET 2024


Am 16.09.24 um 18:38 schrieb Daniel Kral:
> diff --git a/PVE/QemuServer/Helpers.pm b/PVE/QemuServer/Helpers.pm
> index 0afb6317..9d0f24aa 100644
> --- a/PVE/QemuServer/Helpers.pm
> +++ b/PVE/QemuServer/Helpers.pm
> @@ -106,6 +106,51 @@ sub vm_running_locally {
>      return;
>  }
>  
> +=head3 check_storage_content_type($storecfg, $storeid [, $content_type])

Usually, "assert_" rather than "check_" is used for such helpers that
die upon failing the check, so maybe "assert_content_type_supported"

Nit: there is no blank line below the header when viewed with perldoc

I'd rather have the content type be non-optional. And actually, the
helper should live in the storage library, because it doesn't depend on
anything outside it.

> +
> +Checks whether the storage with the identifier C<$storeid>, that is defined in C<$storecfg>,
> +supports the content type C<$content_type>. If the C<$content_type> is undefined, it will default
> +to the value C<"images">.
> +
> +If the check fails, the subroutine will C<die> with an error message containing the storage and
> +content type that is not supported.
> +
> +Returns C<1> if the check is successful.
> +
> +=cut
> +
> +sub check_storage_content_type : prototype($$;$) {
> +    my ($storecfg, $storeid, $content_type) = @_;
> +
> +    $content_type = "images" if !defined($content_type);
> +    my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
> +    die "storage '$storeid' does not support content type '$content_type'\n"
> +	if !$scfg->{content}->{$content_type};
> +
> +    return 1;
> +}
> +
> +=head3 check_volume_content_type($storecfg, $volid)

assert_volume_content_type_supported

should/could also live in the storage library

> +
> +Checks whether the volume with the identifier C<$volid>, that is defined in C<$storecfg>, supports
> +the content type, which is determined by L<PVE::Storage::parse_volname>.
> +
> +If the check fails, the subroutine will C<die> with an error message containing the storage and
> +content type that is not supported.
> +
> +Returns C<1> if the check is successful.
> +
> +=cut
> +
> +sub check_volume_content_type : prototype($$) {
> +    my ($storecfg, $volid) = @_;
> +
> +    my ($storeid) = PVE::Storage::parse_volume_id($volid);
> +    my ($vtype) = PVE::Storage::parse_volname($storecfg, $volid);
> +
> +    return check_storage_content_type($storecfg, $storeid, $vtype);
> +}
> +
>  sub min_version {
>      my ($verstr, $major, $minor, $pve) = @_;
>  




More information about the pve-devel mailing list