Blob Blame History Raw
From 7887547dfc11d83641147e645f683e695632ca80 Mon Sep 17 00:00:00 2001
From: Martin Kletzander <mkletzan@redhat.com>
Date: Thu, 27 Feb 2014 13:57:28 +0100
Subject: [PATCH 2/3] disk: generate target controller-wise

https://bugzilla.redhat.com/show_bug.cgi?id=1036716

Add an optional parameter to generate_target() that controls what
controller the disk should reside in (using libvirt's rules to create
addresses).

RHEL-only; upstream patch doing similar functionality is in commit
6c4302b0a7a919afd15aeb87e9625da9c5079db8.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
---
 virtinst/VirtualDisk.py | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/virtinst/VirtualDisk.py b/virtinst/VirtualDisk.py
index 708f34a..5703835 100644
--- a/virtinst/VirtualDisk.py
+++ b/virtinst/VirtualDisk.py
@@ -1683,14 +1683,18 @@ class VirtualDisk(VirtualDevice):
         else:
             return (None, None)
 
-    def generate_target(self, skip_targets):
+    def generate_target(self, skip_targets, pref_ctrl=None):
         """
         Generate target device ('hda', 'sdb', etc..) for disk, excluding
-        any targets in 'skip_targets'. Sets self.target, and returns the
-        generated value
+        any targets in 'skip_targets'. If given the 'pref_ctrl'
+        parameter, it tries to select the target so that the disk is
+        mapped onto that controller.
+        Sets self.target, and returns the generated value
 
         @param skip_targets: list of targets to exclude
         @type skip_targets: C{list}
+        @param pref_ctrl: preferred controller to connect the disk to
+        @type pref_ctrl: C{int}
         @raise ValueError: can't determine target type, no targets available
         @returns generated target
         @rtype C{str}
@@ -1713,10 +1717,15 @@ class VirtualDisk(VirtualDevice):
             raise RuntimeError("maxnode value is too high")
 
         # Regular scanning
-        for i in range(1, maxnode + 1):
+        ran = range(maxnode)
+        if pref_ctrl is not None:
+            # We assume narrow SCSI bus and libvirt assigning 7
+            # (1-7, 8-14, etc.) devices per controller
+            ran = range(pref_ctrl * 7, (pref_ctrl + 1) * 7)
+        for i in ran:
             gen_t = prefix
 
-            tmp = i
+            tmp = i + 1
             digits = []
             for factor in range(0, 3):
                 amt = (tmp % (26 ** (factor + 1))) / (26 ** factor)
@@ -1746,4 +1755,8 @@ class VirtualDisk(VirtualDevice):
             if t.startswith(prefix) and t not in skip_targets:
                 self.target = t
                 return self.target
-        raise ValueError(_("No more space for disks of type '%s'" % prefix))
+        if pref_ctrl is not None:
+            raise ValueError(_("No more space for disks of type '%s' for "
+                               "controller number %d" % (prefix, pref_ctrl)))
+        else:
+            raise ValueError(_("No more space for disks of type '%s'" % prefix))
-- 
1.8.5.3