]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/Storage/RBDPlugin.pm
rbd: get_rbd_dev_path: return /dev/rbd path only if cluster matches
[pve-storage.git] / PVE / Storage / RBDPlugin.pm
index 91a4a76f82a4ed9fffd636b0e9d41e76155e837c..eeeaf3f51f03edb839f234657c6cbc35e1c76349 100644 (file)
@@ -3,6 +3,7 @@ package PVE::Storage::RBDPlugin;
 use strict;
 use warnings;
 
+use Cwd qw(abs_path);
 use IO::File;
 use JSON;
 use Net::IP;
@@ -13,7 +14,7 @@ use PVE::JSONSchema qw(get_standard_option);
 use PVE::ProcFSTools;
 use PVE::RADOS;
 use PVE::Storage::Plugin;
-use PVE::Tools qw(run_command trim);
+use PVE::Tools qw(run_command trim file_read_firstline);
 
 use base qw(PVE::Storage::Plugin);
 
@@ -66,7 +67,13 @@ my sub get_rbd_dev_path {
     my $pve_path = "/dev/rbd-pve/${cluster_id}/${rbd_path}";
     my $path = "/dev/rbd/${rbd_path}";
 
-    return $path if !-e $pve_path && -e $path; # mapped before rbd-pve udev rule existed
+    if (!-e $pve_path && -e $path) {
+       # possibly mapped before rbd-pve rule existed
+       my $real_dev = abs_path($path);
+       my ($rbd_id) = ($real_dev =~ m|/dev/rbd([0-9]+)$|);
+       my $dev_cluster_id = file_read_firstline("/sys/devices/rbd/${rbd_id}/cluster_fsid");
+       return $path if $cluster_id eq $dev_cluster_id;
+    }
     return $pve_path;
 }
 
@@ -324,7 +331,7 @@ sub properties {
            type => 'string',
        },
        namespace => {
-           description => "RBD Namespace.",
+           description => "Namespace.",
            type => 'string',
        },
        username => {
@@ -630,7 +637,14 @@ sub status {
     my $rados = $librados_connect->($scfg, $storeid);
     my $df = $rados->mon_command({ prefix => 'df', format => 'json' });
 
-    my ($d) = grep { $_->{name} eq $scfg->{pool} } @{$df->{pools}};
+    my $pool = $scfg->{'data-pool'} // $scfg->{pool} // 'rbd';
+
+    my ($d) = grep { $_->{name} eq $pool } @{$df->{pools}};
+
+    if (!defined($d)) {
+       warn "could not get usage stats for pool '$pool'\n";
+       return;
+    }
 
     # max_avail -> max available space for data w/o replication in the pool
     # bytes_used -> data w/o replication in the pool