nwfilter: spawn thread for reloading on firewalld trigger

When firewalld is restarted or has its rules reloaded, we trigger a
reload of the nwfilter driver. This is done directly in the main
event loop thread which is a bad idea.

In a previous commit we fixed a actual deadlock problem with the
virStateReload API, when triggered from SIGHUP:

commit 33c6eb9689
Author: Jim Fehlig <jfehlig@suse.com>
Date:   Thu Mar 8 15:04:48 2018 -0700

    libvirtd: fix potential deadlock when reloading

The same deadlock problem previously existed with the firewalld reload
trigger, however, today it is not quite so series. The QEMU driver uses
a private event thread for each VM, so the particular deadlock would
not occur. None the less during the time the filters are reloading all
use of the event loop is blocked, which prevents APIs being serviced.

Reviewed-by: Erik Skultety <eskultet@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2022-04-01 10:24:37 +01:00
parent 8603b3d76c
commit dae16374dd

View File

@ -54,6 +54,13 @@ static virMutex driverMutex = VIR_MUTEX_INITIALIZER;
#ifdef WITH_FIREWALLD
static void nwfilterStateReloadThread(void *opaque G_GNUC_UNUSED)
{
VIR_INFO("Reloading configuration on firewalld reload/restart");
nwfilterStateReload();
}
static void
nwfilterFirewalldDBusSignalCallback(GDBusConnection *connection G_GNUC_UNUSED,
const char *senderName G_GNUC_UNUSED,
@ -63,7 +70,15 @@ nwfilterFirewalldDBusSignalCallback(GDBusConnection *connection G_GNUC_UNUSED,
GVariant *parameters G_GNUC_UNUSED,
gpointer user_data G_GNUC_UNUSED)
{
nwfilterStateReload();
virThread thr;
if (virThreadCreateFull(&thr, false, nwfilterStateReloadThread,
"firewall-reload", false, NULL) < 0) {
/*
* Not much we can do on error here except log it.
*/
VIR_ERROR(_("Failed to create thread to handle firewall reload/restart"));
}
}
static unsigned int restartID;