[libvirt] [PATCH v2 0/2] don't kill qemu process on restart if networkNotify fails

John thought I didn't go far enough in my removal of return codes in V1... Laine Stump (2): qemu: don't kill qemu process on restart if networkNotify fails network: better log message when network is inactive during reconnect src/network/bridge_driver.c | 17 +++++++++++------ src/network/bridge_driver.h | 7 +++---- src/qemu/qemu_process.c | 9 +++------ 3 files changed, 17 insertions(+), 16 deletions(-) -- 2.9.3

Nothing that could happen during networkNotifyActualDevice() could justify unceremoniously killing the qemu process, but that's what we were doing. In particular, new code added in commit 85bcc022 (first appearred in libvirt-3.2.0) attempts to reattach tap devices to their assigned bridge devices when libvirtd restarts (to make it easier to recover from a restart of a libvirt network). But if the network has been stopped and *not* restarted, the bridge device won't exist and networkNotifyActualDevice() will fail. This patch changes networkNotifyActualDevice() and qemuProcessNotifyNets() to return void, so that qemuProcessReconnect() will soldier on regardless of what happens (any errors will still be logged though). Partially resolves: https://bugzilla.redhat.com/1442700 --- Change from V1: change networkNotifyActualDevice() so that it also returns void (requested by jferlan). I didn't remove the "error" label in that function though, both for consistency with networkAllocateActualDevice(), and to avoid the large number of changes (error ==> cleanup) that would do nothing more than create opportunities for merge conflicts. src/network/bridge_driver.c | 10 ++++------ src/network/bridge_driver.h | 7 +++---- src/qemu/qemu_process.c | 9 +++------ 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index d2d8557..d18b15b 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4649,9 +4649,9 @@ networkAllocateActualDevice(virDomainDefPtr dom, * order, or re-attach the interface's tap device to the network's * bridge. * - * Returns 0 on success, -1 on failure. + * No return value (but does log any failures) */ -int +void networkNotifyActualDevice(virDomainDefPtr dom, virDomainNetDefPtr iface) { @@ -4661,11 +4661,10 @@ networkNotifyActualDevice(virDomainDefPtr dom, virNetworkDefPtr netdef; virNetworkForwardIfDefPtr dev = NULL; size_t i; - int ret = -1; char *master = NULL; if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK) - return 0; + return; network = virNetworkObjFindByName(driver->networks, iface->data.network.name); if (!network) { @@ -4841,11 +4840,10 @@ networkNotifyActualDevice(virDomainDefPtr dom, } networkLogAllocation(netdef, actualType, dev, iface, true); - ret = 0; cleanup: virNetworkObjEndAPI(&network); VIR_FREE(master); - return ret; + return; error: goto cleanup; diff --git a/src/network/bridge_driver.h b/src/network/bridge_driver.h index fbc7634..7832b60 100644 --- a/src/network/bridge_driver.h +++ b/src/network/bridge_driver.h @@ -37,8 +37,8 @@ int networkRegister(void); int networkAllocateActualDevice(virDomainDefPtr dom, virDomainNetDefPtr iface) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); -int networkNotifyActualDevice(virDomainDefPtr dom, - virDomainNetDefPtr iface) +void networkNotifyActualDevice(virDomainDefPtr dom, + virDomainNetDefPtr iface) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); int networkReleaseActualDevice(virDomainDefPtr dom, virDomainNetDefPtr iface) @@ -72,11 +72,10 @@ int networkBandwidthUpdate(virDomainNetDefPtr iface, # define networkDnsmasqConfContents(network, pidfile, configstr, \ dctx, caps) 0 -static inline int +static inline void networkNotifyActualDevice(virDomainDefPtr dom ATTRIBUTE_UNUSED, virDomainNetDefPtr iface ATTRIBUTE_UNUSED) { - return 0; } static inline int diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 53170d7..fcb5763 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2825,7 +2825,7 @@ int qemuProcessStopCPUs(virQEMUDriverPtr driver, -static int +static void qemuProcessNotifyNets(virDomainDefPtr def) { size_t i; @@ -2840,10 +2840,8 @@ qemuProcessNotifyNets(virDomainDefPtr def) if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_DIRECT) ignore_value(virNetDevMacVLanReserveName(net->ifname, false)); - if (networkNotifyActualDevice(def, net) < 0) - return -1; + networkNotifyActualDevice(def, net); } - return 0; } static int @@ -3480,8 +3478,7 @@ qemuProcessReconnect(void *opaque) if (qemuSecurityReserveLabel(driver->securityManager, obj->def, obj->pid) < 0) goto error; - if (qemuProcessNotifyNets(obj->def) < 0) - goto error; + qemuProcessNotifyNets(obj->def); if (qemuProcessFiltersInstantiate(obj->def)) goto error; -- 2.9.3

If the network isn't active during networkNotifyActualDevice(), we would log an error message stating that the bridge device didn't exist. This patch adds a check to see if the network is active, making the logs more useful in the case that it isn't. Partially resolves: https://bugzilla.redhat.com/1442700 --- No change from V1. src/network/bridge_driver.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index d18b15b..3ba7018 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4675,6 +4675,13 @@ networkNotifyActualDevice(virDomainDefPtr dom, } netdef = network->def; + if (!virNetworkObjIsActive(network)) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("network '%s' is not active"), + netdef->name); + goto error; + } + /* if we're restarting libvirtd after an upgrade from a version * that didn't save bridge name in actualNetDef for * actualType==network, we need to copy it in so that it will be -- 2.9.3

On 04/27/2017 05:25 PM, Laine Stump wrote:
John thought I didn't go far enough in my removal of return codes in V1...
Laine Stump (2): qemu: don't kill qemu process on restart if networkNotify fails network: better log message when network is inactive during reconnect
src/network/bridge_driver.c | 17 +++++++++++------ src/network/bridge_driver.h | 7 +++---- src/qemu/qemu_process.c | 9 +++------ 3 files changed, 17 insertions(+), 16 deletions(-)
ACK series - John
participants (2)
-
John Ferlan
-
Laine Stump