]> git.proxmox.com Git - pve-storage.git/commitdiff
pbs: namespace support
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 12 May 2022 08:44:53 +0000 (10:44 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 12 May 2022 09:56:48 +0000 (11:56 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
PVE/API2/Storage/FileRestore.pm
PVE/Storage/PBSPlugin.pm
PVE/Storage/RBDPlugin.pm

index ccc56e53035cfc69cf8185c68b8803b2a2a7c262..5630f5203a140dd4f99a4607ca14e5af320c8a2b 100644 (file)
@@ -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 = {
index 687901fb6352e2fa5bdde9139ad8b9f7ccdc281f..2da939b7eaceadb0d6f406d89a736c28257e39d3 100644 (file)
@@ -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);
index 91a4a76f82a4ed9fffd636b0e9d41e76155e837c..22cac222dbd0f5edfa369c3b30ae4392cee623b2 100644 (file)
@@ -324,7 +324,7 @@ sub properties {
            type => 'string',
        },
        namespace => {
-           description => "RBD Namespace.",
+           description => "Namespace.",
            type => 'string',
        },
        username => {