Since OVS keeps desired state in a DB, upon sudden crash of the
host we may leave a port behind. There's no problem on VM
shutdown or NIC hotunplug as we call corresponding del-port
function (virNetDevOpenvswitchRemovePort()). But if the host
suddenly crashes we won't ever do that. What happens next, is
when OVS starts it finds desired state in its DB and creates a
stale port.
OVS added support for transient ports in v2.5.0 (Feb 2016) and
since its v2.9.0 it even installs a systemd service
(ovs-delete-transient-ports) that automatically deletes transient
ports on system startup. If we mark a port as transient then OVS
won't restore its state on restart after crash.
This change may render "--may-exist" argument redundant, but I'm
not sure about all the implications if it was removed. Let's keep
it for now.
Resolves:
https://gitlab.com/libvirt/libvirt/-/issues/615
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/util/virnetdevopenvswitch.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c
index f1765ae1c8..e23f4c83b6 100644
--- a/src/util/virnetdevopenvswitch.c
+++ b/src/util/virnetdevopenvswitch.c
@@ -164,7 +164,9 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char
*ifname,
cmd = virNetDevOpenvswitchCreateCmd(&errbuf);
virCommandAddArgList(cmd, "--", "--may-exist",
- "add-port", brname, ifname, NULL);
+ "add-port", brname, ifname,
+ "--", "set", "Port", ifname,
"other_config:transient=true",
+ NULL);
virNetDevOpenvswitchConstructVlans(cmd, virtVlan);
While checking this out, I noticed that the machine I was testing on
still has ports on its OVS bridge that I had manually created back in
2021 the last time I touched anything related to OVS :-). After adding a
new port using the modified commandline, I rebooted the machine and the
pre-existing "stale" interfaces were still there, but the one I had just
created with transient=true was gone.
Reviewed-by: Laine Stump <laine(a)redhat.com>