[node-patches] Change in ovirt-node[master]: storage: Translate disk to name used by LVM

fabiand at fedoraproject.org fabiand at fedoraproject.org
Mon Nov 19 14:00:46 UTC 2012


Fabian Deutsch has uploaded a new change for review.

Change subject: storage: Translate disk to name used by LVM
......................................................................

storage: Translate disk to name used by LVM

Even if e.g. /dev/sd* is passed to LVM, LVM might decide to use one of
the other dm paths pointing to that device. This raises problems when
the original name of the disk is expected to turn up in the output of
LVM, but this assumption is wrong, as LVM silently translates names.

rhbz#872502

Change-Id: I8a628fcc8c213172bc13a849a5ea9513381faa8b
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/ovirtnode/storage.py
1 file changed, 18 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/26/9326/1

diff --git a/scripts/ovirtnode/storage.py b/scripts/ovirtnode/storage.py
index b831de7..33a9ccf 100644
--- a/scripts/ovirtnode/storage.py
+++ b/scripts/ovirtnode/storage.py
@@ -25,6 +25,7 @@
 import gudev
 import logging
 import subprocess
+import shlex
 
 logger = logging.getLogger(__name__)
 
@@ -151,6 +152,19 @@
         logger.debug(size)
         return size
 
+    def _lvm_name_for_disk(self, disk):
+        name = None
+        cmd = "lvm pvs --noheadings --nameprefixes --unquoted -o pv_name,vg_name '%s' 2> /dev/null" % disk
+        lines = str(_functions.passthrough(cmd)).split("\n")
+        if len(lines) > 1:
+            logger.warning("More than one PV for disk '%s' found: %s" % (disk,
+                                                                         lines))
+        for line in lines:
+            lvm2_vars = dict([tuple(e.split("=", 1)) for e \
+                              in shlex.split(line)])
+            name = lvm2_vars["LVM2_PV_NAME"]
+        return name
+
     def wipe_lvm_on_disk(self, _devs):
         devs = set(_devs.split(","))
         logger.debug("Considering to wipe LVM on: %s / %s" % (_devs, devs))
@@ -168,10 +182,13 @@
             vg_proc = _functions.passthrough(vg_cmd, log_func=logger.debug)
             vgs_on_dev = vg_proc.stdout.split()
             for vg in vgs_on_dev:
+                name = self._lvm_name_for_disk(dev)
                 pvs_cmd = ("pvs -o pv_name,vg_uuid --noheadings | " +
-                           "grep \"%s\" | egrep -v -q \"%s" % (vg, dev))
+                           "grep \"%s\" | egrep -v -q \"%s" % (vg, name))
                 for fdev in devs:
                     pvs_cmd += "|%s%s[0-9]+|%s" % (fdev, part_delim, fdev)
+                    name = self._lvm_name_for_disk(fdev)
+                    pvs_cmd += "|%s%s[0-9]+|%s" % (name, part_delim, name)
                 pvs_cmd += "\""
                 remaining_pvs = _functions.system(pvs_cmd)
                 if remaining_pvs:


--
To view, visit http://gerrit.ovirt.org/9326
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8a628fcc8c213172bc13a849a5ea9513381faa8b
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Fabian Deutsch <fabiand at fedoraproject.org>



More information about the node-patches mailing list