render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From c5e551b03bef744fc1302ccb9fc9e38189cdfb7c Mon Sep 17 00:00:00 2001
Message-Id: <c5e551b03bef744fc1302ccb9fc9e38189cdfb7c.1389183248.git.jdenemar@redhat.com>
From: Laine Stump <laine@laine.org>
Date: Tue, 24 Dec 2013 04:24:04 -0700
Subject: [PATCH] qemu: re-add hostdev interfaces to hostdev array on libvirtd
 restart

This resolves:

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

If a domain has an <interface type='hostdev'> or an <interface
type='network'> where the network itself is a pool of hostdev devices,
then libvirt will internally keep that device on both the interface
list *and* the hostdev list for the domain. One of the places this
comes in handy is when a new device is being added and libvirt wants
to find a unique "alias" name for it - it just scans through the
hostdev array and makes sure it picks a name that doesn't match the
alias of any device in that array.

However, when libvirtd was restarted, if there was an <interface
type='network'> with the network being a hostdev pool, the device
would not be added to the reconstructed internal hostdev array, so its
alias would not be found during a scan of the hostdev array, thus
attempts to add a new hostdev (or <interface type='hostdev'> or
<interface type='network'>) would result in a message like this:

internal error: unable to execute QEMU command 'device_add':
                Duplicate ID 'hostdev0' for device

This patch simply fixes the existing code in the domain XML parser
that fixes up the hostdev array in the case of <interface
type='hostdev'> to do the same thing in the case of <interface
type='network'> with a hostdev network.

This bug has existed since the very first addition of hostdev networks
to libvirt (0.10.0).

(cherry picked from commit 8700b87800b0671963de271a480aa3e0dd333897)

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/conf/domain_conf.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9cf5432..656fa93 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -11917,9 +11917,12 @@ virDomainDefParseXML(xmlDocPtr xml,
 
         def->nets[def->nnets++] = net;
 
-        /* <interface type='hostdev'> must also be in the hostdevs array */
-        if (net->type == VIR_DOMAIN_NET_TYPE_HOSTDEV &&
-            virDomainHostdevInsert(def, &net->data.hostdev.def) < 0) {
+        /* <interface type='hostdev'> (and <interface type='net'>
+         * where the actual network type is already known to be
+         * hostdev) must also be in the hostdevs array.
+         */
+        if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_HOSTDEV &&
+            virDomainHostdevInsert(def, virDomainNetGetActualHostdev(net)) < 0) {
             goto error;
         }
     }
-- 
1.8.5.2