From d091393e7f56e2ad2d62594450e70cb3b746cbd5 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Tue, 3 Nov 2009 11:24:31 +0100
Subject: [PATCH] Implement cluster verify checks for wrong PV names

Since ':' is not a valid character in PV names (for the way Ganeti uses
LVM), we need to check this and warn the user. This patch adds a new
NV_PVLIST cluster verify check and verifies the PV names returned from
the nodes.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 lib/backend.py   |  5 +++++
 lib/cmdlib.py    | 15 +++++++++++++++
 lib/constants.py |  3 ++-
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/lib/backend.py b/lib/backend.py
index 44a0b4242..75a698da3 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -509,6 +509,11 @@ def VerifyNode(what, cluster_name):
   if constants.NV_VGLIST in what:
     result[constants.NV_VGLIST] = utils.ListVolumeGroups()
 
+  if constants.NV_PVLIST in what:
+    result[constants.NV_PVLIST] = \
+      bdev.LogicalVolume.GetPVInfo(what[constants.NV_PVLIST],
+                                   filter_allocatable=False)
+
   if constants.NV_VERSION in what:
     result[constants.NV_VERSION] = (constants.PROTOCOL_VERSION,
                                     constants.RELEASE_VERSION)
diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index 7e6d879d4..eef478206 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -1127,6 +1127,20 @@ class LUVerifyCluster(LogicalUnit):
     _ErrorIf(test, self.ENODESETUP, node, "node setup error: %s",
              "; ".join(test))
 
+    # check pv names
+    if vg_name is not None:
+      pvlist = node_result.get(constants.NV_PVLIST, None)
+      test = pvlist is None
+      _ErrorIf(test, self.ENODELVM, node, "Can't get PV list from node")
+      if not test:
+        # check that ':' is not present in PV names, since it's a
+        # special character for lvcreate (denotes the range of PEs to
+        # use on the PV)
+        for size, pvname, owner_vg in pvlist:
+          test = ":" in pvname
+          _ErrorIf(test, self.ENODELVM, node, "Invalid character ':' in PV"
+                   " '%s' of VG '%s'", pvname, owner_vg)
+
   def _VerifyInstance(self, instance, instanceconfig, node_vol_is,
                       node_instance, n_offline):
     """Verify an instance.
@@ -1301,6 +1315,7 @@ class LUVerifyCluster(LogicalUnit):
     if vg_name is not None:
       node_verify_param[constants.NV_VGLIST] = None
       node_verify_param[constants.NV_LVLIST] = vg_name
+      node_verify_param[constants.NV_PVLIST] = [vg_name]
       node_verify_param[constants.NV_DRBDLIST] = None
     all_nvinfo = self.rpc.call_node_verify(nodelist, node_verify_param,
                                            self.cfg.GetClusterName())
diff --git a/lib/constants.py b/lib/constants.py
index 815e666a0..eeba79b55 100644
--- a/lib/constants.py
+++ b/lib/constants.py
@@ -515,11 +515,12 @@ NV_FILELIST = "filelist"
 NV_HVINFO = "hvinfo"
 NV_HYPERVISOR = "hypervisor"
 NV_INSTANCELIST = "instancelist"
-NV_LVLIST = "lvlist"
 NV_NODELIST = "nodelist"
 NV_NODENETTEST = "node-net-test"
 NV_VERSION = "version"
 NV_VGLIST = "vglist"
+NV_LVLIST = "lvlist"
+NV_PVLIST = "pvlist"
 NV_DRBDLIST = "drbd-list"
 NV_NODESETUP = "nodesetup"
 
-- 
GitLab