[pve-devel] [PATCH storage] lvmthin: Match snapshot remove regex to allowed names

Thomas Lamprecht t.lamprecht at proxmox.com
Tue Oct 27 13:18:15 CET 2020


On 27.10.20 11:12, Dominic Jäger wrote:
> We allow snapshot names that match pve-configid but during qm destroy we have
> not removed all snapshots that match pve-configid so far. For example, the name
> x-y was allowed but the resulting snap_vm-105-disk-0_x-y was not removed.
> 
> Reported-by: Hannes Laimer <h.laimer at proxmox.com>
> Signed-off-by: Dominic Jäger <d.jaeger at proxmox.com>
> ---
> Something like m/^snap_${volname}_${configidre}$/ would maybe be nicer, but I
> didn't see how to get that RE from JSONSchema in a shorter way than that single
> function call.
> 

hmm, I'd either:

* move that regex to an `our $PROXMOX_CONFID_RE = ...` variable (or a method which
  returns it

* copy over that regex to here, could be just fine here

but I'd like to avoid using a capture group just to pass it a method which then
regex checks it again.

>  PVE/Storage/LvmThinPlugin.pm | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/PVE/Storage/LvmThinPlugin.pm b/PVE/Storage/LvmThinPlugin.pm
> index d1c5b1f..4af57be 100644
> --- a/PVE/Storage/LvmThinPlugin.pm
> +++ b/PVE/Storage/LvmThinPlugin.pm
> @@ -117,7 +117,8 @@ sub free_image {
>  
>  	# remove all volume snapshots first
>  	foreach my $lv (keys %$dat) {
> -	    next if $lv !~ m/^snap_${volname}_(\w+)$/;
> +	    next if $lv !~ m/^snap_${volname}_(.+)$/;
> +	    next if !PVE::JSONSchema::pve_verify_configid($1, 1);
>  	    my $cmd = ['/sbin/lvremove', '-f', "$vg/$lv"];
>  	    run_command($cmd, errmsg => "lvremove snapshot '$vg/$lv' error");
>  	}
> 







More information about the pve-devel mailing list