From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 3106F89D8 for ; Mon, 6 Mar 2023 11:52:09 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0CB9E2FC45 for ; Mon, 6 Mar 2023 11:52:09 +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) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Mon, 6 Mar 2023 11:52:08 +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 C62A445885 for ; Mon, 6 Mar 2023 11:52:07 +0100 (CET) Message-ID: Date: Mon, 6 Mar 2023 11:52:06 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Content-Language: en-US To: Christian Ebner , pve-devel@lists.proxmox.com References: <20230306093743.243210-1-c.ebner@proxmox.com> <351d847b-7ff2-3d73-de11-a77384935387@proxmox.com> <484975879.3330.1678099003576@192.168.2.153> From: Fiona Ebner In-Reply-To: <484975879.3330.1678099003576@192.168.2.153> 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 Subject: Re: [pve-devel] [PATCH 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Mar 2023 10:52:09 -0000 Am 06.03.23 um 11:36 schrieb Christian Ebner: > >> On 06.03.2023 11:17 CET Fiona Ebner wrote: >> >> >> Am 06.03.23 um 10:37 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 `used`, the >>> latter also being a non-optional return value for the api call. >>> >>> 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 >>> --- >>> PVE/API2/Storage/Content.pm | 2 +- >>> PVE/Storage/ISCSIDirectPlugin.pm | 2 +- >>> PVE/Storage/RBDPlugin.pm | 2 +- >>> PVE/Storage/ZFSPoolPlugin.pm | 2 +- >>> 4 files changed, 4 insertions(+), 4 deletions(-) >>> >>> diff --git a/PVE/API2/Storage/Content.pm b/PVE/API2/Storage/Content.pm >>> index fe0ad4a..36433ba 100644 >>> --- a/PVE/API2/Storage/Content.pm >>> +++ b/PVE/API2/Storage/Content.pm >>> @@ -324,7 +324,7 @@ __PACKAGE__->register_method ({ >>> >>> my $path = PVE::Storage::path($cfg, $volid); >>> my ($size, $format, $used, $parent) = PVE::Storage::volume_size_info($cfg, $volid); >>> - die "volume_size_info on '$volid' failed\n" if !($format && $size); >>> + die "volume_size_info on '$volid' failed\n" if !($format && $size && $used); >> >> This change should be it's own patch and I think it's wrong. Can't $used >> be zero and valid, e.g. for a newly created empty image? You'd either >> need to use defined($used) or leave it as-is, i.e. not failing and >> defaulting to 0 when $used is undef. Even with the defined() check, this >> would break an external plugin that doesn't return $used. While I guess >> that could be tolerated, we might do it together with the next APIAGE >> reset and document that volume_size_info explicitly requires it. > > Yes, this was a really sloppy oversight, only added after my testing. On the other hand, should the API call fail for volumes reporting $size = 0 here? Is this intentional or should this also be fixed? I don't think there are valid cases where $size is 0, or? >> >>> >>> my $entry = { >>> path => $path, >>> 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}; >> >> Why return 0 for $used? Doesn't the API call then fail because of the >> check you added above? >> >>> } >>> >>> sub volume_resize { >>> diff --git a/PVE/Storage/RBDPlugin.pm b/PVE/Storage/RBDPlugin.pm >>> index 9047504..e69c44c 100644 >>> --- a/PVE/Storage/RBDPlugin.pm >>> +++ b/PVE/Storage/RBDPlugin.pm >>> @@ -730,7 +730,7 @@ sub volume_size_info { >>> >>> my ($vtype, $name, $vmid) = $class->parse_volname($volname); >>> my ($size, undef) = rbd_volume_info($scfg, $storeid, $name); >>> - return $size; >>> + return wantarray ? ($size, 'raw', 0, undef) : $size; >> >> Also, always returning undef for the parent is also not correct for RBD >> and ZFS. > > What's the cheapest way here to get the parent for ZFS and RBD? I think parse_volname() should already give it to you. It's encoded in the volume ID.