Blame SOURCES/libvirt-qemu-check-actual-netdev-type-rather-than-config-netdev-type-during-init.patch

43fe83
From 2e3465d664c764032bd133c545905639f459efbc Mon Sep 17 00:00:00 2001
43fe83
Message-Id: <2e3465d664c764032bd133c545905639f459efbc.1381871411.git.jdenemar@redhat.com>
43fe83
From: Laine Stump <laine@laine.org>
43fe83
Date: Fri, 4 Oct 2013 01:53:09 -0600
43fe83
Subject: [PATCH] qemu: check actual netdev type rather than config netdev type
43fe83
 during init
43fe83
43fe83
This resolves:
43fe83
43fe83
   https://bugzilla.redhat.com/show_bug.cgi?id=1012824 (RHEL7)
43fe83
   https://bugzilla.redhat.com/show_bug.cgi?id=1012834 (RHEL6)
43fe83
43fe83
Note that a similar problem was reported in:
43fe83
43fe83
   https://bugzilla.redhat.com/show_bug.cgi?id=827519
43fe83
43fe83
but the fix only worked for <interface type='hostdev'>, *not* for
43fe83
<interface type='network'> where the network itself was a pool of
43fe83
hostdevs.
43fe83
43fe83
The symptom in both cases was this error message:
43fe83
43fe83
   internal error: Unable to determine device index for network device
43fe83
43fe83
In both cases the cause was lack of proper handling for netdevs
43fe83
(<interface>) of type='hostdev' when scanning the netdev list looking
43fe83
for alias names in qemuAssignDeviceNetAlias() - those that aren't
43fe83
type='hostdev' have an alias of the form "net%d", while those that are
43fe83
hostdev use "hostdev%d". This special handling was completely lacking
43fe83
prior to the fix for Bug 827519 which was:
43fe83
43fe83
When searching for the highest alias index, libvirt looks at the alias
43fe83
for each netdev and if it is type='hostdev' it ignores the entry. If
43fe83
the type is not hostdev, then it expects the "net%d" form; if it
43fe83
doesn't find that, it fails and logs the above error message.
43fe83
43fe83
That fix works except in the case of <interface type='network'> where
43fe83
the network uses hostdev (i.e. the network is a pool of VFs to be
43fe83
assigned to the guests via PCI passthrough). In this case, the check
43fe83
for type='hostdev' would fail because it was done as:
43fe83
43fe83
     def->net[i]->type == VIR_DOMAIN_NET_TYPE_HOSTDEV
43fe83
43fe83
(which compares what was written in the config) when it actually
43fe83
should have been:
43fe83
43fe83
    virDomainNetGetActualType(def->net[i]) == VIR_DOMAIN_NET_TYPE_HOSTDEV
43fe83
43fe83
(which compares the type of netdev that was actually allocated from
43fe83
the network at runtime).
43fe83
43fe83
Of course the latter wouldn't be of any use if the netdevs of
43fe83
type='network' hadn't already acquired their actual network connection
43fe83
yet, but manual examination of the code showed that this is never the
43fe83
case.
43fe83
43fe83
While looking through qemu_command.c, two other places were found to
43fe83
directly compare the net[i]->type field rather than getting actualType:
43fe83
43fe83
* qemuAssignDeviceAliases() - in this case, the incorrect comparison
43fe83
  would cause us to create a "net%d" alias for a netdev with
43fe83
  type='network' but actualType='hostdev'. This alias would be
43fe83
  subsequently overwritten by the proper "hostdev%d" form, so
43fe83
  everything would operate properly, but a string would be
43fe83
  leaked. This patch also fixes this problem.
43fe83
43fe83
* qemuAssignDevicePCISlots() - would defer assigning a PCI address to
43fe83
  a netdev if it was type='hostdev', but not for type='network +
43fe83
  actualType='hostdev'. In this case, the actual device usually hasn't
43fe83
  been acquired yet anyway, and even in the case that it has, there is
43fe83
  no practical difference between assigning a PCI address while
43fe83
  traversing the netdev list or while traversing the hostdev
43fe83
  list. Because changing it would be an effective NOP (but potentially
43fe83
  cause some unexpected regression), this usage was left unchanged.
43fe83
43fe83
(cherry picked from commit 9881bfed2541faa428372b4513518b4b9ae1ab15)
43fe83
43fe83
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
43fe83
---
43fe83
 src/qemu/qemu_command.c | 8 +++++---
43fe83
 1 file changed, 5 insertions(+), 3 deletions(-)
43fe83
43fe83
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
43fe83
index 47b488a..dcce432 100644
43fe83
--- a/src/qemu/qemu_command.c
43fe83
+++ b/src/qemu/qemu_command.c
43fe83
@@ -787,7 +787,8 @@ qemuAssignDeviceNetAlias(virDomainDefPtr def, virDomainNetDefPtr net, int idx)
43fe83
         for (i = 0; i < def->nnets; i++) {
43fe83
             int thisidx;
43fe83
 
43fe83
-            if (def->nets[i]->type == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
43fe83
+            if (virDomainNetGetActualType(def->nets[i])
43fe83
+                == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
43fe83
                 /* type='hostdev' interfaces have a hostdev%d alias */
43fe83
                continue;
43fe83
             }
43fe83
@@ -957,8 +958,9 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
43fe83
             /* type='hostdev' interfaces are also on the hostdevs list,
43fe83
              * and will have their alias assigned with other hostdevs.
43fe83
              */
43fe83
-            if ((def->nets[i]->type != VIR_DOMAIN_NET_TYPE_HOSTDEV) &&
43fe83
-                (qemuAssignDeviceNetAlias(def, def->nets[i], i) < 0)) {
43fe83
+            if (virDomainNetGetActualType(def->nets[i])
43fe83
+                != VIR_DOMAIN_NET_TYPE_HOSTDEV &&
43fe83
+                qemuAssignDeviceNetAlias(def, def->nets[i], i) < 0) {
43fe83
                 return -1;
43fe83
             }
43fe83
         }
43fe83
-- 
43fe83
1.8.3.2
43fe83