Blame SOURCES/libvirt-conf-properly-clear-out-autogenerated-macvtap-names-when-formatting-parsing.patch

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