[Libvir] PATCH: Fix libvirtd to not shutdown at startup

Changes to the daemon to make it called qemudShutdown() broke the network driver when run in --daemon mode. This is because the main daemon forks into the background, and the original PID then exits destroying any active networks & removing the iptables rules. # /usr/sbin/libvirtd --daemon Shutting down network 'default'iptables: No chain/target/match by that name iptables: Bad rule (does a matching rule exist in that chain?) iptables: Bad rule (does a matching rule exist in that chain?) iptables: Bad rule (does a matching rule exist in that chain?) iptables: No chain/target/match by that name iptables: No chain/target/match by that name iptables: Bad rule (does a matching rule exist in that chain?) iptables: Bad rule (does a matching rule exist in that chain?) iptables: Bad rule (does a matching rule exist in that chain?) iptables: Bad rule (does a matching rule exist in that chain?) Failed to bring down bridge 'virbr0' : No such device Failed to delete bridge 'virbr0' : No such device or address The core issue is that when forking into daemon mode the original process should immediately exit & not do invoke cleanup functions. This patch makes it do that Dan. Index: qemud/qemud.c =================================================================== RCS file: /data/cvs/libvirt/qemud/qemud.c,v retrieving revision 1.89 diff -u -r1.89 qemud.c --- qemud/qemud.c 3 Mar 2008 18:10:19 -0000 1.89 +++ qemud/qemud.c 9 Mar 2008 20:56:27 -0000 @@ -393,7 +393,7 @@ case -1: return -1; default: - return nextpid; + _exit(0); } cleanup: @@ -418,8 +418,7 @@ status != 0) { return -1; } - - return pid; + _exit(0); } } } @@ -2116,16 +2115,12 @@ goto error1; if (godaemon) { - int pid; openlog("libvirtd", 0, 0); - pid = qemudGoDaemon(); - if (pid < 0) { + if (qemudGoDaemon() < 0) { qemudLog(QEMUD_ERR, _("Failed to fork as daemon: %s"), strerror(errno)); goto error1; } - if (pid > 0) - goto out; /* Choose the name of the PID file. */ if (!pid_file) { @@ -2172,7 +2167,6 @@ if (godaemon) closelog(); - out: ret = 0; error2: -- |: Red Hat, Engineering, Boston -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

On Sun, Mar 09, 2008 at 08:59:24PM +0000, Daniel P. Berrange wrote:
Changes to the daemon to make it called qemudShutdown() broke the network driver when run in --daemon mode. This is because the main daemon forks into the background, and the original PID then exits destroying any active networks & removing the iptables rules. [...] Index: qemud/qemud.c =================================================================== RCS file: /data/cvs/libvirt/qemud/qemud.c,v retrieving revision 1.89 diff -u -r1.89 qemud.c --- qemud/qemud.c 3 Mar 2008 18:10:19 -0000 1.89 +++ qemud/qemud.c 9 Mar 2008 20:56:27 -0000 @@ -393,7 +393,7 @@ case -1: return -1; default: - return nextpid; + _exit(0); }
cleanup: @@ -418,8 +418,7 @@ status != 0) { return -1; } - - return pid; + _exit(0); } } } @@ -2116,16 +2115,12 @@ goto error1;
if (godaemon) { - int pid; openlog("libvirtd", 0, 0); - pid = qemudGoDaemon(); - if (pid < 0) { + if (qemudGoDaemon() < 0) { qemudLog(QEMUD_ERR, _("Failed to fork as daemon: %s"), strerror(errno)); goto error1; } - if (pid > 0) - goto out;
/* Choose the name of the PID file. */ if (!pid_file) { @@ -2172,7 +2167,6 @@ if (godaemon) closelog();
- out: ret = 0;
error2:
+1 to this patch. There's another problem I've noticed. If you start the daemon and TLS is enabled in the config and there is no /etc/pki directory, then the daemon exits with an error but doesn't clean up the bridge, meaning that next time you start the daemon the default network cannot be created. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top

On Sun, Mar 09, 2008 at 08:59:24PM +0000, Daniel P. Berrange wrote:
Changes to the daemon to make it called qemudShutdown() broke the network driver when run in --daemon mode. This is because the main daemon forks into the background, and the original PID then exits destroying any active networks & removing the iptables rules. [...] The core issue is that when forking into daemon mode the original process should immediately exit & not do invoke cleanup functions. This patch makes it do that
a serious problem indeed, +1 Daniel -- Red Hat Virtualization group http://redhat.com/virtualization/ Daniel Veillard | virtualization library http://libvirt.org/ veillard@redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
participants (3)
-
Daniel P. Berrange
-
Daniel Veillard
-
Richard W.M. Jones