From 78eac5baf2544b41d270522675285079820059a3 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Thu, 12 May 2022 10:44:53 +0200 Subject: [PATCH] pbs: namespace support Signed-off-by: Wolfgang Bumiller --- PVE/API2/Storage/FileRestore.pm | 4 ++-- PVE/Storage/PBSPlugin.pm | 23 +++++++++++++++++++---- PVE/Storage/RBDPlugin.pm | 2 +- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/PVE/API2/Storage/FileRestore.pm b/PVE/API2/Storage/FileRestore.pm index ccc56e5..5630f52 100644 --- a/PVE/API2/Storage/FileRestore.pm +++ b/PVE/API2/Storage/FileRestore.pm @@ -119,7 +119,7 @@ __PACKAGE__->register_method ({ my (undef, $snap) = PVE::Storage::parse_volname($cfg, $volid); my $client = PVE::PBSClient->new($scfg, $storeid); - my $ret = $client->file_restore_list($snap, $path, $base64); + my $ret = $client->file_restore_list([$scfg->{namespace}, $snap], $path, $base64); # 'leaf' is a proper JSON boolean, map to perl-y bool # TODO: make PBSClient decode all bools always as 1/0? @@ -188,7 +188,7 @@ __PACKAGE__->register_method ({ $rpcenv->fork_worker('pbs-download', undef, $user, sub { my $name = decode_base64($path); print "Starting download of file: $name\n"; - $client->file_restore_extract($fifo, $snap, $path, 1); + $client->file_restore_extract($fifo, [$scfg->{namespace}, $snap], $path, 1); }); my $ret = { diff --git a/PVE/Storage/PBSPlugin.pm b/PVE/Storage/PBSPlugin.pm index 687901f..2da939b 100644 --- a/PVE/Storage/PBSPlugin.pm +++ b/PVE/Storage/PBSPlugin.pm @@ -63,6 +63,7 @@ sub options { return { server => { fixed => 1 }, datastore => { fixed => 1 }, + namespace => { optional => 1 }, port => { optional => 1 }, nodes => { optional => 1}, disable => { optional => 1}, @@ -220,9 +221,15 @@ sub print_volid { return "${storeid}:${volname}"; } +my sub ns : prototype($$) { + my ($scfg, $name) = @_; + my $ns = $scfg->{namespace}; + return defined($ns) ? ($name, $ns) : (); +} + # essentially the inverse of print_volid -sub api_param_from_volname { - my ($class, $volname) = @_; +my sub api_param_from_volname : prototype($$$) { + my ($class, $scfg, $volname) = @_; my $name = ($class->parse_volname($volname))[1]; @@ -244,6 +251,7 @@ sub api_param_from_volname { } return { + (ns($scfg, 'backup-ns')), 'backup-type' => $btype, 'backup-id' => $bid, 'backup-time' => $btime, @@ -304,6 +312,9 @@ my sub do_raw_client_cmd { push @$cmd, @$param if defined($param); push @$cmd, "--repository", $repo; + if ($client_cmd ne 'status' && defined(my $ns = $scfg->{namespace})) { + push @$cmd, '--ns', $ns; + } local $ENV{PBS_PASSWORD} = pbs_get_password($scfg, $storeid); @@ -602,6 +613,10 @@ sub path { # artificial url - we currently do not use that anywhere my $path = "pbs://$repo/$name"; + if (defined(my $ns = $scfg->{namespace})) { + $ns =~ s|/|%2f|g; # other characters to escape aren't allowed in the namespace schema + $path .= "?ns=$ns"; + } return ($path, $vmid, $vtype); } @@ -851,7 +866,7 @@ sub get_volume_attribute { } if ($attribute eq 'protected') { - my $param = $class->api_param_from_volname($volname); + my $param = api_param_from_volname($class, $scfg, $volname); my $password = pbs_get_password($scfg, $storeid); my $conn = pbs_api_connect($scfg, $password); @@ -876,7 +891,7 @@ sub update_volume_attribute { } if ($attribute eq 'protected') { - my $param = $class->api_param_from_volname($volname); + my $param = api_param_from_volname($class, $scfg, $volname); $param->{$attribute} = $value; my $password = pbs_get_password($scfg, $storeid); diff --git a/PVE/Storage/RBDPlugin.pm b/PVE/Storage/RBDPlugin.pm index 91a4a76..22cac22 100644 --- a/PVE/Storage/RBDPlugin.pm +++ b/PVE/Storage/RBDPlugin.pm @@ -324,7 +324,7 @@ sub properties { type => 'string', }, namespace => { - description => "RBD Namespace.", + description => "Namespace.", type => 'string', }, username => { -- 2.39.2