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 7B4CE7D24C for ; Mon, 8 Nov 2021 16:21:39 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 731CF284C6 for ; Mon, 8 Nov 2021 16:21:39 +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 id 648EA284BB for ; Mon, 8 Nov 2021 16:21:38 +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 394AC422F3 for ; Mon, 8 Nov 2021 16:21:38 +0100 (CET) Date: Mon, 08 Nov 2021 16:21:15 +0100 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: Proxmox VE development discussion References: <20211102150335.2371545-1-a.lauterer@proxmox.com> <20211102150335.2371545-2-a.lauterer@proxmox.com> In-Reply-To: <20211102150335.2371545-2-a.lauterer@proxmox.com> MIME-Version: 1.0 User-Agent: astroid/0.15.0 (https://github.com/astroidmail/astroid) Message-Id: <1636384211.m34yji3cck.astroid@nora.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL 0.296 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: Re: [pve-devel] [PATCH v4 storage 1/9] storage: add new find_free_volname 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, 08 Nov 2021 15:21:39 -0000 On November 2, 2021 4:03 pm, Aaron Lauterer wrote: > This new method exposes the functionality to request a new, not yet > used, volname for a storage. >=20 > The default implementation will return the result from > 'find_free_diskname' prefixed with "/" if $scfg->{path} exists. > Otherwise it will only return the result from 'find_free_diskname'. >=20 > If the format suffix is added also depends on the existence of > $scfg->{path}. >=20 > $scfg->{path} will be present for directory based storage types. >=20 > Should a storage need to return different volname, it needs to override > the 'find_free_volname' method. >=20 > Signed-off-by: Aaron Lauterer as discussed off-list (I am sorry I didn't read through the full=20 discussion on-list of all 10 versions of this and the previous series=20 ;)) - IMHO this is not a backwards compatible addition since it's not=20 guarded by any feature flag, so external plugins fall into two=20 categories: - derived from Plugin.pm, so automatically implement it via=20 find_free_diskname -> get_next_vm_diskname, which might or might not=20 be correct for that plugin - not derived from Plugin.pm, don't implement it, no safeguard to handle=20 that RIGHT NOW, the only callers are guarded by the rename feature so there=20 can't be any problems in practice - but there is no guarantee that this=20 will be remembered down the line, and it also breaks the=20 modularization/layering of the code to rely on this fact ;) while we could argue about whether we really want to be that strict,=20 another point against exposing this method for me is that it's also=20 prone to mis-use, since it encourages code patterns like in this=20 series with: get_free_volname do_something_that_allocates_that_volname without holding a storage lock over both calls, since the storage lock=20 is only available on the plugin level and not exposed in PVE::Storage=20 itself. an interface like $plugin->rename_volume($scfg, $storeid, $source, $new_owner, $new_name) with at least $new_owner or $new_name set would also cover both cases=20 (reassign with just $new_owner, rename with just $new_name) and can be=20 feature-guarded while keeping the locking in PVE::Storage for the full=20 operation including finding a free slot if needed. alternatively, just implementing $plugin->reassign_volume($scfg, $storeid, $source, $new_owner) for now (guarded by a 'reassign' feature), and postponing the rename=20 feature for a future series that handles 'custom suffix/volname'=20 across the board of our stack would also be an option. > --- >=20 > v3 -> v4: > * fix style nit >=20 > v2 -> v3: > * dropped exists() check > * fixed base image handling > * fixed smaller code style issues >=20 > v1 -> v2: > * many small fixes and improvements > * rename_volume now accepts $source_volname instead of $source_volid > helps us to avoid to parse the volid a second time >=20 > rfc -> v1: > * reduced number of parameters to minimum needed, plugins infer needed > information themselves > * added storage locking and checking if volume already exists > * parse target_volname prior to renaming to check if valid >=20 > old dedicated API endpoint -> rfc: > only do rename now but the rename function handles templates and returns > the new volid as this can be differently handled on some storages. > =20 > PVE/Storage.pm | 9 +++++++++ > PVE/Storage/Plugin.pm | 8 ++++++++ > 2 files changed, 17 insertions(+) >=20 > diff --git a/PVE/Storage.pm b/PVE/Storage.pm > index 71d6ad7..4fbeaea 100755 > --- a/PVE/Storage.pm > +++ b/PVE/Storage.pm > @@ -203,6 +203,15 @@ sub storage_can_replicate { > return $plugin->storage_can_replicate($scfg, $storeid, $format); > } > =20 > +sub find_free_volname { > + my ($cfg, $storeid, $vmid, $fmt) =3D @_; > + > + my $scfg =3D storage_config($cfg, $storeid); > + my $plugin =3D PVE::Storage::Plugin->lookup($scfg->{type}); > + > + return $plugin->find_free_volname($storeid, $scfg, $vmid, $fmt); > +} > + > sub storage_ids { > my ($cfg) =3D @_; > =20 > diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm > index aeb4fff..d21c874 100644 > --- a/PVE/Storage/Plugin.pm > +++ b/PVE/Storage/Plugin.pm > @@ -732,6 +732,14 @@ sub find_free_diskname { > return get_next_vm_diskname($disk_list, $storeid, $vmid, $fmt, $scfg= , $add_fmt_suffix); > } > =20 > +sub find_free_volname { > + my ($class, $storeid, $scfg, $vmid, $fmt) =3D @_; > + > + my $diskname =3D $class->find_free_diskname($storeid, $scfg, $vmid, = $fmt, $scfg->{path}); > + > + return $scfg->{path} ? "${vmid}/$diskname" : $diskname; > +} > + > sub clone_image { > my ($class, $scfg, $storeid, $volname, $vmid, $snap) =3D @_; > =20 > --=20 > 2.30.2 >=20 >=20 >=20 > _______________________________________________ > pve-devel mailing list > pve-devel@lists.proxmox.com > https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel >=20 >=20 >=20