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)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 90EDE77086 for ; Mon, 19 Jul 2021 16:52:57 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 744AC28437 for ; Mon, 19 Jul 2021 16:52:57 +0200 (CEST) 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 id 4EA7B2840E for ; Mon, 19 Jul 2021 16:52:55 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 22EBA4238F for ; Mon, 19 Jul 2021 16:52:55 +0200 (CEST) From: Aaron Lauterer To: pve-devel@lists.proxmox.com Date: Mon, 19 Jul 2021 16:52:46 +0200 Message-Id: <20210719145254.2269142-2-a.lauterer@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210719145254.2269142-1-a.lauterer@proxmox.com> References: <20210719145254.2269142-1-a.lauterer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.563 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 SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH v1 storage 1/9] storage: expose find_free_diskname 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, 19 Jul 2021 14:52:57 -0000 We do not expose the parameter 'add_fmt_suffix' used by the internal implemantion of 'find_free_diskname'. This is something only the plugins themselves know but cannot be determined easily and reliably from an outside caller. This is why the new 'wants_fmt_suffix' method has been introduced. For most plugins the return value is very clear. For the default implementation in Plugin.pm we add another check to be on the safe side and only return true if the '$scfg->{path}' option is present. It indicates that the volume in question is an actual file which will need the suffix. Signed-off-by: Aaron Lauterer --- rfc -> v1: dropped $add_fmt_suffix parameter and added the "wants_fmt_suffix" helper method in each plugin. PVE/Storage.pm | 11 +++++++++++ PVE/Storage/LVMPlugin.pm | 5 +++++ PVE/Storage/Plugin.pm | 7 +++++++ PVE/Storage/RBDPlugin.pm | 5 +++++ PVE/Storage/ZFSPoolPlugin.pm | 5 +++++ 5 files changed, 33 insertions(+) diff --git a/PVE/Storage.pm b/PVE/Storage.pm index c04b5a2..afeb2e3 100755 --- a/PVE/Storage.pm +++ b/PVE/Storage.pm @@ -203,6 +203,17 @@ sub storage_can_replicate { return $plugin->storage_can_replicate($scfg, $storeid, $format); } +sub find_free_diskname { + my ($cfg, $storeid, $vmid, $fmt) = @_; + + my $scfg = storage_config($cfg, $storeid); + my $plugin = PVE::Storage::Plugin->lookup($scfg->{type}); + + my $add_fmt_suffix = $plugin->wants_fmt_suffix($scfg); + + return $plugin->find_free_diskname($storeid, $scfg, $vmid, $fmt, $add_fmt_suffix); +} + sub storage_ids { my ($cfg) = @_; diff --git a/PVE/Storage/LVMPlugin.pm b/PVE/Storage/LVMPlugin.pm index 139d391..3e5b6c8 100644 --- a/PVE/Storage/LVMPlugin.pm +++ b/PVE/Storage/LVMPlugin.pm @@ -201,6 +201,11 @@ sub type { return 'lvm'; } +sub wants_fmt_suffix { + my ($class, $scfg) = @_; + return 0; +} + sub plugindata { return { content => [ {images => 1, rootdir => 1}, { images => 1 }], diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm index b1865cb..5c6c659 100644 --- a/PVE/Storage/Plugin.pm +++ b/PVE/Storage/Plugin.pm @@ -191,6 +191,13 @@ sub default_format { return wantarray ? ($def_format, $valid_formats) : $def_format; } +sub wants_fmt_suffix { + my ($class, $scfg) = @_; + return 1 if $scfg->{path}; + return 0; +} + + PVE::JSONSchema::register_format('pve-storage-path', \&verify_path); sub verify_path { my ($path, $noerr) = @_; diff --git a/PVE/Storage/RBDPlugin.pm b/PVE/Storage/RBDPlugin.pm index a8d1243..86ea45a 100644 --- a/PVE/Storage/RBDPlugin.pm +++ b/PVE/Storage/RBDPlugin.pm @@ -273,6 +273,11 @@ sub type { return 'rbd'; } +sub wants_fmt_suffix { + my ($class, $scfg) = @_; + return 0; +} + sub plugindata { return { content => [ {images => 1, rootdir => 1}, { images => 1 }], diff --git a/PVE/Storage/ZFSPoolPlugin.pm b/PVE/Storage/ZFSPoolPlugin.pm index c4be70f..85e2211 100644 --- a/PVE/Storage/ZFSPoolPlugin.pm +++ b/PVE/Storage/ZFSPoolPlugin.pm @@ -18,6 +18,11 @@ sub type { return 'zfspool'; } +sub wants_fmt_suffix { + my ($class, $scfg) = @_; + return 0; +} + sub plugindata { return { content => [ {images => 1, rootdir => 1}, {images => 1 , rootdir => 1}], -- 2.30.2