From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <f.ebner@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id CAB288C98
 for <pve-devel@lists.proxmox.com>; Tue,  7 Mar 2023 09:31:35 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id A9D4295BF
 for <pve-devel@lists.proxmox.com>; Tue,  7 Mar 2023 09:31:35 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS
 for <pve-devel@lists.proxmox.com>; Tue,  7 Mar 2023 09:31:33 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 819CE41B34
 for <pve-devel@lists.proxmox.com>; Tue,  7 Mar 2023 09:31:33 +0100 (CET)
Message-ID: <638f7412-b51b-6580-5f9d-3b3259bd404b@proxmox.com>
Date: Tue, 7 Mar 2023 09:31:29 +0100
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
 Thunderbird/102.8.0
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
 Christian Ebner <c.ebner@proxmox.com>
References: <20230306130752.1112199-1-c.ebner@proxmox.com>
Content-Language: en-US
From: Fiona Ebner <f.ebner@proxmox.com>
In-Reply-To: <20230306130752.1112199-1-c.ebner@proxmox.com>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.153 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 NICE_REPLY_A           -0.001 Looks like a legit reply (A)
 POISEN_SPAM_PILL          0.1 Meta: its spam
 POISEN_SPAM_PILL_1        0.1 random spam to be learned in bayes
 POISEN_SPAM_PILL_3        0.1 random spam to be learned in bayes
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [zfspoolplugin.pm, proxmox.com, rbdplugin.pm,
 iscsidirectplugin.pm]
Subject: Re: [pve-devel] [PATCH v2 storage] api: fix get content call for
 volumes
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Tue, 07 Mar 2023 08:31:35 -0000

Am 06.03.23 um 14:07 schrieb Christian Ebner:
> `pvesh get /nodes/{node}/storage/{storage}/content/{volume}` failed for
> several storage types, because the respective storage plugins returned
> only the volumes `size` on `volume_size_info` calls, while also the format
> is required.
> 
> This patch fixes the issue by returning also `format` and where possible `used`.
> 
> The issue was reported in the forum:
> https://forum.proxmox.com/threads/pvesh-get-nodes-node-storage-storage-content-volume-returns-error.123747/
> 
> Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
> ---
> 
> Changes since v1:
>  * Remove errous check for $used being set, rely on fallback to 0 if undef
>  * Return `parent` for RBD and ZFS
>  * Return `used` for ZFS
> 
>  PVE/Storage/ISCSIDirectPlugin.pm | 2 +-
>  PVE/Storage/RBDPlugin.pm         | 4 ++--
>  PVE/Storage/ZFSPoolPlugin.pm     | 8 ++++++--
>  3 files changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/PVE/Storage/ISCSIDirectPlugin.pm b/PVE/Storage/ISCSIDirectPlugin.pm
> index 9777969..eb329d4 100644
> --- a/PVE/Storage/ISCSIDirectPlugin.pm
> +++ b/PVE/Storage/ISCSIDirectPlugin.pm
> @@ -208,7 +208,7 @@ sub volume_size_info {
>      my $vollist = iscsi_ls($scfg,$storeid);
>      my $info = $vollist->{$storeid}->{$volname};
>  
> -    return $info->{size};
> +    return wantarray ? ($info->{size}, 'raw', 0, undef) : $info->{size};

Hmm, maybe we can call Plugin's file_size_info, passing in the path with
iscsi://... to get $used (rather than always 0)? But would need to be
tested if the information is correct. The call could be made
conditionally, only if wantarray.

>  }
>  
>  sub volume_resize {
> diff --git a/PVE/Storage/RBDPlugin.pm b/PVE/Storage/RBDPlugin.pm
> index 9047504..e7a2137 100644
> --- a/PVE/Storage/RBDPlugin.pm
> +++ b/PVE/Storage/RBDPlugin.pm
> @@ -729,8 +729,8 @@ sub volume_size_info {
>      my ($class, $scfg, $storeid, $volname, $timeout) = @_;
>  
>      my ($vtype, $name, $vmid) = $class->parse_volname($volname);
> -    my ($size, undef) = rbd_volume_info($scfg, $storeid, $name);
> -    return $size;
> +    my ($size, $parent) = rbd_volume_info($scfg, $storeid, $name);
> +    return wantarray ? ($size, 'raw', 0, $parent) : $size;

Can't we extend rbd_volume_info to also return $used or is that not
included in the rbd info result? If not, we could again consider
re-using file_size_info.

>  }
>  
>  sub volume_resize {
> diff --git a/PVE/Storage/ZFSPoolPlugin.pm b/PVE/Storage/ZFSPoolPlugin.pm
> index 9fbd149..acc50d9 100644
> --- a/PVE/Storage/ZFSPoolPlugin.pm
> +++ b/PVE/Storage/ZFSPoolPlugin.pm
> @@ -446,13 +446,17 @@ sub status {
>  sub volume_size_info {
>      my ($class, $scfg, $storeid, $volname, $timeout) = @_;
>  
> -    my (undef, $vname, undef, undef, undef, undef, $format) =
> +    my (undef, $vname, undef, $parent, undef, undef, $format) =
>          $class->parse_volname($volname);
>  
>      my $attr = $format eq 'subvol' ? 'refquota' : 'volsize';
>      my $value = $class->zfs_get_properties($scfg, $attr, "$scfg->{pool}/$vname");
> +    my $used = $class->zfs_get_properties($scfg, 'used', "$scfg->{pool}/$vname");

used also includes usage of snapshots and children. I think
usedbydataset is better. Like that used <= size should be guaranteed.
See man zfsprops for more information.

Also, one call to zfs_get_properties should be enough by passing both
"$attr,used".

While you're at it, I'd also rename $value to $size then.

> +
> +    $used = ($used =~ /^(\d+)$/) ? $1 : 0;
> +    
>      if ($value =~ /^(\d+)$/) {
> -	return $1;
> +	return wantarray ? ($1, $format, $used, $parent) : $1;
>      }
>  
>      die "Could not get zfs volume size\n";