[pve-devel] [PATCH storage 3/3] rbd: add protect/unprotect helpers

Fiona Ebner f.ebner at proxmox.com
Mon May 5 16:24:31 CEST 2025


Am 23.04.25 um 15:59 schrieb Fabian Grünbichler:
> this is a bit repetitive otherwise, no functional changes intended.
> 
> Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
> ---
>  src/PVE/Storage/RBDPlugin.pm | 55 ++++++++++++++++++------------------
>  1 file changed, 27 insertions(+), 28 deletions(-)
> 
> diff --git a/src/PVE/Storage/RBDPlugin.pm b/src/PVE/Storage/RBDPlugin.pm
> index 3bb5807..6604bc3 100644
> --- a/src/PVE/Storage/RBDPlugin.pm
> +++ b/src/PVE/Storage/RBDPlugin.pm
> @@ -96,7 +96,7 @@ my $rbd_cmd = sub {
>  	my $pool = $scfg->{pool} ? $scfg->{pool} : 'rbd';
>  	push $cmd->@*, '-p', $pool;
>  	if (defined($scfg->{namespace})) {
> -	    push @$cmd, '--namespace', $cfg->{namespace};
> +	    push @$cmd, '--namespace', $scfg->{namespace};
>  	}
>      }
>  

Should be squashed into previous commit.

> @@ -262,6 +262,25 @@ sub rbd_ls_snap {
>      return $res;
>  }
>  
> +my sub rbd_protect_snap {
> +    my ($scfg, $storeid, $image, $snap) = @_;
> +    my (undef, undef, undef, $protected) = rbd_volume_info($scfg, $storeid, $image, $snap);
> +
> +    if (!$protected){

Style nit: missing space between '){'

> +	my $snap_spec = get_rbd_path($scfg, $image, $snap);
> +	my $cmd = $rbd_cmd->($scfg, $storeid, 'snap', 'protect', $snap_spec);
> +	run_rbd_command($cmd, errmsg => "rbd protect '$snap_spec' error");
> +    }
> +}
> +


> @@ -580,15 +593,7 @@ sub clone_image {
>  
>      warn "clone $volname: $basename snapname $snap to $name\n";
>  
> -    if (length($snapname)) {
> -	my (undef, undef, undef, $protected) = rbd_volume_info($scfg, $storeid, $volname, $snapname);
> -
> -	if (!$protected) {
> -	    my $snap_spec = get_rbd_path($scfg, $volname, $snapname);
> -	    my $cmd = $rbd_cmd->($scfg, $storeid, 'snap', 'protect', $snap_spec);
> -	    run_rbd_command($cmd, errmsg => "rbd protect '$snap_spec' error");
> -	}
> -    }
> +    rbd_protect_snap($scfg, $storeid, $volname, $snap) if length($snapname);

Last argument should be $snapname

>  
>      my $newvol = "$basename/$name";
>      $newvol = $name if length($snapname);




More information about the pve-devel mailing list