render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
7548c0
From b2e0155b59ae9f038bcf21da7c6b7fb0a99a7b67 Mon Sep 17 00:00:00 2001
7548c0
Message-Id: <b2e0155b59ae9f038bcf21da7c6b7fb0a99a7b67@dist-git>
7548c0
From: Laine Stump <laine@redhat.com>
7548c0
Date: Tue, 1 Dec 2020 22:01:00 -0500
7548c0
Subject: [PATCH] conf: properly clear out autogenerated macvtap names when
7548c0
 formatting/parsing
7548c0
7548c0
Back when macvtap support was added in commit 315baab9443 in Feb. 2010
7548c0
(libvirt-0.7.7), it was setup to autogenerate a name for the device if
7548c0
one wasn't supplied, in the pattern "macvtap%d" (or "macvlan%d"),
7548c0
similar to the way an unspecified standard tap device name will lead
7548c0
to an autogenerated "vnet%d".
7548c0
7548c0
As a matter of fact, in commit ca1b7cc8e45 added in May 2010, the code
7548c0
was changed to *always* ignore a supplied device name for macvtap
7548c0
interfaces by deleting *any* name immediately during the <interface>
7548c0
parsing (this was intended to prevent one domain which had failed to
7548c0
completely start from deleting the macvtap device of another domain
7548c0
which had subsequently been provided the same device name (this will
7548c0
seem mildly ironic later). This was later fixed to only clear the
7548c0
device name when inactive XML was being parsed. HOWEVER - this was
7548c0
only done if the xml was <interface type='direct'> - autogenerated
7548c0
names were not cleared for <interface type='network'> (which could
7548c0
also result in a macvtap device).
7548c0
7548c0
Although the names of "vnetX" tap devices had always been
7548c0
automatically cleared when parsing <interface> (see commit d1304583d
7548c0
from July 2008 (!)), at the time macvtap support was added, both vnetX
7548c0
and macvtapX device names were always included when formatting the
7548c0
XML.
7548c0
7548c0
Then in commit a8be259d0cc (July 2011, libvirt-0.9.4), <interface>
7548c0
formatting was changed to also clear out "vnetX" device names during
7548c0
XML formatting as well. However the same treatment wasn't given to
7548c0
"macvtapX".
7548c0
7548c0
Now in 2020, there has been a report that a failed migration leads to
7548c0
the macvtap device of some other unrelated guest on the destination
7548c0
host losing its network connectivity. It was determined that this was
7548c0
due to the domain XML in the migration containing a macvtap device
7548c0
name, e.g. "macvtap0", that was already in use by the other guest on
7548c0
the destination. Normally this wouldn't be a problem, because libvirt
7548c0
would see that the device was already in use, and then find a
7548c0
different unused name. But in this case, other external problems were
7548c0
causing the migration to fail prior to selecting a macvtap device and
7548c0
successfully opening it, and during error recovery, qemuProcessStop()
7548c0
was called, which went through all def->nets objects and (if they were
7548c0
macvtap) deleted the device specified in net->ifname; since libvirt
7548c0
hadn't gotten to the point of replacing the incoming "macvtap0" with
7548c0
the name of a device it actually created for this guest, that meant
7548c0
that "macvtap0" was deleted, *even though it was currently in use by a
7548c0
different guest*!
7548c0
7548c0
Whew!
7548c0
7548c0
So, it turns out that when formatting "migratable" XML, "vnetX"
7548c0
devices are omitted, just as when formatting "inactive" XML. By making
7548c0
the code in both interface parsing and formatting consistent for
7548c0
"vnetX", "macvtapX", and "macvlanX", we can thus make sure that the
7548c0
autogenerated (and unneeded / completely *not* wanted) macvtap device
7548c0
name will not be sent with the migration XML. This way when a
7548c0
migration fails, net->ifname will be NULL, and libvirt won't have any
7548c0
device to try and (erroneously) delete.
7548c0
7548c0
Signed-off-by: Laine Stump <laine@redhat.com>
7548c0
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
7548c0
(cherry picked from commit 282d135ddbb7203565cd5527b451469b14953994)
7548c0
7548c0
https://bugzilla.redhat.com/1872610
7548c0
7548c0
Signed-off-by: Laine Stump <laine@redhat.com>
7548c0
Message-Id: <20201202030100.458879-1-laine@redhat.com>
7548c0
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
7548c0
---
7548c0
 src/conf/domain_conf.c | 12 ++++--------
7548c0
 1 file changed, 4 insertions(+), 8 deletions(-)
7548c0
7548c0
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
7548c0
index f41559f33e..cd5c15f297 100644
7548c0
--- a/src/conf/domain_conf.c
7548c0
+++ b/src/conf/domain_conf.c
7548c0
@@ -12183,14 +12183,6 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
7548c0
         }
7548c0
 
7548c0
         def->data.direct.linkdev = g_steal_pointer(&dev;;
7548c0
-
7548c0
-        if (ifname &&
7548c0
-            flags & VIR_DOMAIN_DEF_PARSE_INACTIVE &&
7548c0
-            (STRPREFIX(ifname, VIR_NET_GENERATED_MACVTAP_PREFIX) ||
7548c0
-             STRPREFIX(ifname, VIR_NET_GENERATED_MACVLAN_PREFIX))) {
7548c0
-            VIR_FREE(ifname);
7548c0
-        }
7548c0
-
7548c0
         break;
7548c0
 
7548c0
     case VIR_DOMAIN_NET_TYPE_HOSTDEV:
7548c0
@@ -12238,6 +12230,8 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
7548c0
     if (def->managed_tap != VIR_TRISTATE_BOOL_NO && ifname &&
7548c0
         (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) &&
7548c0
         (STRPREFIX(ifname, VIR_NET_GENERATED_TAP_PREFIX) ||
7548c0
+         STRPREFIX(ifname, VIR_NET_GENERATED_MACVTAP_PREFIX) ||
7548c0
+         STRPREFIX(ifname, VIR_NET_GENERATED_MACVLAN_PREFIX) ||
7548c0
          (prefix && STRPREFIX(ifname, prefix)))) {
7548c0
         /* An auto-generated target name, blank it out */
7548c0
         VIR_FREE(ifname);
7548c0
@@ -25996,6 +25990,8 @@ virDomainNetDefFormat(virBufferPtr buf,
7548c0
         (def->managed_tap == VIR_TRISTATE_BOOL_NO ||
7548c0
          !((flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE) &&
7548c0
            (STRPREFIX(def->ifname, VIR_NET_GENERATED_TAP_PREFIX) ||
7548c0
+            STRPREFIX(def->ifname, VIR_NET_GENERATED_MACVTAP_PREFIX) ||
7548c0
+            STRPREFIX(def->ifname, VIR_NET_GENERATED_MACVLAN_PREFIX) ||
7548c0
             (prefix && STRPREFIX(def->ifname, prefix)))))) {
7548c0
         /* Skip auto-generated target names for inactive config. */
7548c0
         virBufferEscapeString(&attrBuf, " dev='%s'", def->ifname);
7548c0
-- 
7548c0
2.29.2
7548c0