[libvirt] [PATCHv2 8/9] network: restart radvd/dnsmasq if needed when libvirtd is restarted
Daniel Veillard
veillard at redhat.com
Tue Sep 18 08:02:59 UTC 2012
On Tue, Sep 18, 2012 at 03:39:04AM -0400, Laine Stump wrote:
> A user on IRC had accidentally killed all of his libvirt-started
> dnsmasq instances (due to a buggy dnsmasq service script in Fedora
> 16), and had hoped that libvirtd would notice this on restart and
> reload all the dnsmasq daemons (as it does with iptables
> rules). Unfortunately this was not the case - as long as the network
> object had a pid registered for dnsmasq and/or radvd, it assumed that
> the processes were running.
>
> This patch takes advantage of the new utility functions in
> bridge_driver.c to do a "refresh" of all radvd and dnsmasq processes
> started by libvirt each time libvirtd is restarted - this function
> attempts to do a SIGHUP of each existing process, and if that fails,
> it restarts the process, rebuilding all the associated config files
> and commandline parameters in the process. This normally has no
> effect, but will be useful in solving the occasional "odd situation"
> without needing to take the drastic step of destroying/re-starting the
> network.
> ---
> src/network/bridge_driver.c | 34 ++++++++++++++++++++++++++++++++++
> 1 file changed, 34 insertions(+)
>
> diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
> index 252c964..0e38016 100644
> --- a/src/network/bridge_driver.c
> +++ b/src/network/bridge_driver.c
> @@ -117,6 +117,7 @@ static int networkShutdownNetworkExternal(struct network_driver *driver,
> virNetworkObjPtr network);
>
> static void networkReloadIptablesRules(struct network_driver *driver);
> +static void networkRefreshDaemons(struct network_driver *driver);
>
> static struct network_driver *driverState = NULL;
>
> @@ -344,6 +345,7 @@ networkStartup(int privileged) {
>
> networkFindActiveConfigs(driverState);
> networkReloadIptablesRules(driverState);
> + networkRefreshDaemons(driverState);
> networkAutostartConfigs(driverState);
>
> networkDriverUnlock(driverState);
> @@ -404,6 +406,7 @@ networkReload(void) {
> driverState->networkConfigDir,
> driverState->networkAutostartDir);
> networkReloadIptablesRules(driverState);
> + networkRefreshDaemons(driverState);
> networkAutostartConfigs(driverState);
> networkDriverUnlock(driverState);
> return 0;
> @@ -1210,6 +1213,37 @@ networkRestartRadvd(virNetworkObjPtr network)
> }
> #endif /* #if 0 */
>
> +/* SIGHUP/restart any dnsmasq or radvd daemons.
> + * This should be called when libvirtd is restarted.
> + */
> +static void
> +networkRefreshDaemons(struct network_driver *driver)
> +{
> + unsigned int i;
> +
> + VIR_INFO("Refreshing network daemons");
> +
> + for (i = 0 ; i < driver->networks.count ; i++) {
> + virNetworkObjPtr network = driver->networks.objs[i];
> +
> + virNetworkObjLock(network);
> + if (virNetworkObjIsActive(network) &&
> + ((network->def->forwardType == VIR_NETWORK_FORWARD_NONE) ||
> + (network->def->forwardType == VIR_NETWORK_FORWARD_NAT) ||
> + (network->def->forwardType == VIR_NETWORK_FORWARD_ROUTE))) {
> + /* Only the three L3 network types that are configured by
> + * libvirt will have a dnsmasq or radvd daemon associated
> + * with them. Here we send a SIGHUP to an existing
> + * dnsmasq and/or radvd, or restart them if they've
> + * disappeared.
> + */
> + networkRefreshDhcpDaemon(network);
> + networkRefreshRadvd(network);
> + }
> + virNetworkObjUnlock(network);
> + }
> +}
> +
> static int
> networkAddMasqueradingIptablesRules(struct network_driver *driver,
> virNetworkObjPtr network,
ACK, sounds simple and useful, hopefully there is no side effect to
the HUP'ed daemons.
Daniel
--
Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/
daniel at veillard.com | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library http://libvirt.org/
More information about the libvir-list
mailing list