public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Aaron Lauterer <a.lauterer@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH storage] rbd: get_rbd_dev_path: return /dev/rbd path only if cluster matches
Date: Mon, 23 May 2022 12:54:25 +0200	[thread overview]
Message-ID: <20220523105425.3025242-1-a.lauterer@proxmox.com> (raw)

The changes in cfe46e2d4a97a83f1bbe6ad656e6416399309ba2 git not catch
all situations.
In the case of a guest having 2 disk images with the same name on a pool
with the same name but in two different ceph clusters we still had
issues when starting it. The first disk got mapped as expected. The
second disk did not get mapped because we returned the old $path to
"/dev/rbd/<pool>/<image>" because it already existed from the first
disk.

In the case that only the "old" /dev/rbd path exists and we do not have
the /dev/rbd-pve/<cluster>/... path available, we now check if the
cluster fsid used by that rbd device matches the one we expect. If it
does, then we are in the situation that the image has been mapped before
the new rbd-pve udev rule was introduced. If it does not, then we have
the situation of an ambiguous mapping in /dev/rbd and return the
$pve_path.

Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
---
 PVE/Storage/RBDPlugin.pm | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/PVE/Storage/RBDPlugin.pm b/PVE/Storage/RBDPlugin.pm
index 3511914..eeeaf3f 100644
--- a/PVE/Storage/RBDPlugin.pm
+++ b/PVE/Storage/RBDPlugin.pm
@@ -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;
 }
 
-- 
2.30.2





             reply	other threads:[~2022-05-23 10:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-23 10:54 Aaron Lauterer [this message]
2022-06-13 13:00 ` Aaron Lauterer
2022-06-14  8:53 ` [pve-devel] applied: " Fabian Grünbichler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220523105425.3025242-1-a.lauterer@proxmox.com \
    --to=a.lauterer@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal