Blame SOURCES/virt-manager-disk-generate-target-controller-wise.patch

343f27
From 7887547dfc11d83641147e645f683e695632ca80 Mon Sep 17 00:00:00 2001
343f27
From: Martin Kletzander <mkletzan@redhat.com>
343f27
Date: Thu, 27 Feb 2014 13:57:28 +0100
343f27
Subject: [PATCH 2/3] disk: generate target controller-wise
343f27
343f27
https://bugzilla.redhat.com/show_bug.cgi?id=1036716
343f27
343f27
Add an optional parameter to generate_target() that controls what
343f27
controller the disk should reside in (using libvirt's rules to create
343f27
addresses).
343f27
343f27
RHEL-only; upstream patch doing similar functionality is in commit
343f27
6c4302b0a7a919afd15aeb87e9625da9c5079db8.
343f27
343f27
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
343f27
---
343f27
 virtinst/VirtualDisk.py | 25 +++++++++++++++++++------
343f27
 1 file changed, 19 insertions(+), 6 deletions(-)
343f27
343f27
diff --git a/virtinst/VirtualDisk.py b/virtinst/VirtualDisk.py
343f27
index 708f34a..5703835 100644
343f27
--- a/virtinst/VirtualDisk.py
343f27
+++ b/virtinst/VirtualDisk.py
343f27
@@ -1683,14 +1683,18 @@ class VirtualDisk(VirtualDevice):
343f27
         else:
343f27
             return (None, None)
343f27
 
343f27
-    def generate_target(self, skip_targets):
343f27
+    def generate_target(self, skip_targets, pref_ctrl=None):
343f27
         """
343f27
         Generate target device ('hda', 'sdb', etc..) for disk, excluding
343f27
-        any targets in 'skip_targets'. Sets self.target, and returns the
343f27
-        generated value
343f27
+        any targets in 'skip_targets'. If given the 'pref_ctrl'
343f27
+        parameter, it tries to select the target so that the disk is
343f27
+        mapped onto that controller.
343f27
+        Sets self.target, and returns the generated value
343f27
 
343f27
         @param skip_targets: list of targets to exclude
343f27
         @type skip_targets: C{list}
343f27
+        @param pref_ctrl: preferred controller to connect the disk to
343f27
+        @type pref_ctrl: C{int}
343f27
         @raise ValueError: can't determine target type, no targets available
343f27
         @returns generated target
343f27
         @rtype C{str}
343f27
@@ -1713,10 +1717,15 @@ class VirtualDisk(VirtualDevice):
343f27
             raise RuntimeError("maxnode value is too high")
343f27
 
343f27
         # Regular scanning
343f27
-        for i in range(1, maxnode + 1):
343f27
+        ran = range(maxnode)
343f27
+        if pref_ctrl is not None:
343f27
+            # We assume narrow SCSI bus and libvirt assigning 7
343f27
+            # (1-7, 8-14, etc.) devices per controller
343f27
+            ran = range(pref_ctrl * 7, (pref_ctrl + 1) * 7)
343f27
+        for i in ran:
343f27
             gen_t = prefix
343f27
 
343f27
-            tmp = i
343f27
+            tmp = i + 1
343f27
             digits = []
343f27
             for factor in range(0, 3):
343f27
                 amt = (tmp % (26 ** (factor + 1))) / (26 ** factor)
343f27
@@ -1746,4 +1755,8 @@ class VirtualDisk(VirtualDevice):
343f27
             if t.startswith(prefix) and t not in skip_targets:
343f27
                 self.target = t
343f27
                 return self.target
343f27
-        raise ValueError(_("No more space for disks of type '%s'" % prefix))
343f27
+        if pref_ctrl is not None:
343f27
+            raise ValueError(_("No more space for disks of type '%s' for "
343f27
+                               "controller number %d" % (prefix, pref_ctrl)))
343f27
+        else:
343f27
+            raise ValueError(_("No more space for disks of type '%s'" % prefix))
343f27
-- 
343f27
1.8.5.3
343f27