render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Blob Blame History Raw
From c18594a43b583f497baaf07b4d540bf7cab8634f Mon Sep 17 00:00:00 2001
Message-Id: <c18594a43b583f497baaf07b4d540bf7cab8634f.1389183248.git.jdenemar@redhat.com>
From: Laine Stump <laine@laine.org>
Date: Thu, 2 Jan 2014 03:12:52 -0700
Subject: [PATCH] domain: don't try to interpret <driver> as virtio config for
 hostdev interfaces

This resolves:

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

The <driver> name attribute of an interface is interpreted in two
different ways depending on the <interface> type - if the interface is
type='hostdev', then the driver name describes which backend to use
for the hostdev device assignment (vfio or kvm), but if the interface
is any emulated type *and* the model type is "virtio", then the driver
name can be "vhost" or "qemu", telling which backend qemu should use
to communicate with the emulated device.

The problem comes when someone has defined a an interface like this
(which is accepted by the parser as long as no <driver name='xxx'/> is
specified):

    <interface type='hostdev'>
       ...
       <model type='virtio'/>
       ...
    </interface>

As libvirt storing this definition in the domain's status, the driver
name is automatically filled in with the backend that was
automatically decided by libvirt, so it stores this in the status:

    <interface type='hostdev'>
       ...
       <driver name='vfio'/>
       ...
       <model type='virtio'/>
       ...
    </interface>

This isn't noticed until the next time libvirtd is restarted - as it
is reading the status of all domains, it encounters the above
interface definition, logs an error:

  internal error: Unknown interface <driver name='vfio'> has been specified

and fails to reload the domain status, so the domain is marked as
inactive.

The solution is to stop the parser from interpreting <driver>
attributes as if the device was an emulated virtio device, when it is
actually a hostdev.

(Although the bug has existed since vfio support was added, it has
just recently become more apparent because libvirt previously didn't
automatically set the driver name for hostdev interfaces in the domain
status to vfio/kvm as it does since commit f094aa, first appearing in
v1.1.4.)

(cherry picked from commit 3337a98a5ee41ee1d5de796abcb378eacb9bded0)

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

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 656fa93..d4161a5 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6607,7 +6607,8 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
         model = NULL;
     }
 
-    if (def->model && STREQ(def->model, "virtio")) {
+    if (def->type != VIR_DOMAIN_NET_TYPE_HOSTDEV &&
+        STREQ_NULLABLE(def->model, "virtio")) {
         if (backend != NULL) {
             int name;
             if ((name = virDomainNetBackendTypeFromString(backend)) < 0 ||
-- 
1.8.5.2