[pve-devel] [PATCH V2 pve-storage 1/8] add a storage_exists function
Thomas Lamprecht
t.lamprecht at proxmox.com
Tue Nov 8 18:09:40 CET 2022
Am 12/09/2022 um 17:25 schrieb Stefan Hrdlicka:
> adds a function that can take a volume id and return the relevant
> storage config
>
> Signed-off-by: Stefan Hrdlicka <s.hrdlicka at proxmox.com>
> ---
> PVE/Storage.pm | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/PVE/Storage.pm b/PVE/Storage.pm
> index b9c53a1..9e95e3d 100755
> --- a/PVE/Storage.pm
> +++ b/PVE/Storage.pm
> @@ -158,6 +158,15 @@ my $convert_maxfiles_to_prune_backups = sub {
> }
> };
>
> +sub storage_exists {
slightly odd interface name IMO, as it's a bit more of a "get storage config from
volid", so adapt the method name in that direction, e.g.:
# extract the storage ID from a volume ID and returns it config or undef if storage could not be
# found (i.e., got removed)
sub storage_config_from_volid {
> + my ($cfg, $volid) = @_;
> +
> + my ($storeid, $volname) = parse_volume_id($volid);
> + my $scfg = storage_config($cfg, $storeid, 1);
> +
> + return $scfg;
couldn't we avoid the useless intermediate variable and directly
return storage_config($cfg, $storeid, 1);
At which point the question arises if we really want a common helper "just" for this,
no hard feelings against, but is IMO a bit close to thinking that not much would be
lost in terms of code beauty or maintenance if we'd just program those two lines out
on the few call sites.
> +}
> +
> sub storage_config {
> my ($cfg, $storeid, $noerr) = @_;
>
More information about the pve-devel
mailing list