|
|
c401cc |
From f128dfc941dae25a11933e95e9ea27cd01bc19bc Mon Sep 17 00:00:00 2001
|
|
|
c401cc |
Message-Id: <f128dfc941dae25a11933e95e9ea27cd01bc19bc@dist-git>
|
|
|
c401cc |
From: Michal Privoznik <mprivozn@redhat.com>
|
|
|
c401cc |
Date: Mon, 24 Feb 2014 13:12:05 +0100
|
|
|
c401cc |
Subject: [PATCH] virNetServerRun: Notify systemd that we're accepting clients
|
|
|
c401cc |
|
|
|
c401cc |
https://bugzilla.redhat.com/show_bug.cgi?id=1032695
|
|
|
c401cc |
|
|
|
c401cc |
Systemd does not forget about the cases, where client service needs to
|
|
|
c401cc |
wait for daemon service to initialize and start accepting new clients.
|
|
|
c401cc |
Setting a dependency in client is not enough as systemd doesn't know
|
|
|
c401cc |
when the daemon has initialized itself and started accepting new
|
|
|
c401cc |
clients. However, it offers a mechanism to solve this. The daemon needs
|
|
|
c401cc |
to call a special systemd function by which the daemon tells "I'm ready
|
|
|
c401cc |
to accept new clients". This is exactly what we need with
|
|
|
c401cc |
libvirtd-guests (client) and libvirtd (daemon). So now, with this
|
|
|
c401cc |
change, libvirt-guests.service is invoked not any sooner than
|
|
|
c401cc |
libvirtd.service calls the systemd notify function.
|
|
|
c401cc |
|
|
|
c401cc |
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
|
|
|
c401cc |
(cherry picked from commit 68954fb25c4a75c5c2c213f57927eb188cca2239)
|
|
|
c401cc |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
c401cc |
---
|
|
|
c401cc |
configure.ac | 2 ++
|
|
|
c401cc |
daemon/libvirtd.service.in | 1 +
|
|
|
c401cc |
m4/virt-systemd-daemon.m4 | 34 ++++++++++++++++++++++++++++++++++
|
|
|
c401cc |
src/Makefile.am | 4 ++--
|
|
|
c401cc |
src/libvirt_private.syms | 1 +
|
|
|
c401cc |
src/rpc/virnetserver.c | 5 +++++
|
|
|
c401cc |
src/util/virsystemd.c | 12 ++++++++++++
|
|
|
c401cc |
src/util/virsystemd.h | 2 ++
|
|
|
c401cc |
8 files changed, 59 insertions(+), 2 deletions(-)
|
|
|
c401cc |
create mode 100644 m4/virt-systemd-daemon.m4
|
|
|
c401cc |
|
|
|
c401cc |
diff --git a/configure.ac b/configure.ac
|
|
|
c401cc |
index 8f5f167..9734c33 100644
|
|
|
c401cc |
--- a/configure.ac
|
|
|
c401cc |
+++ b/configure.ac
|
|
|
c401cc |
@@ -180,6 +180,7 @@ LIBVIRT_CHECK_SANLOCK
|
|
|
c401cc |
LIBVIRT_CHECK_SASL
|
|
|
c401cc |
LIBVIRT_CHECK_SELINUX
|
|
|
c401cc |
LIBVIRT_CHECK_SSH2
|
|
|
c401cc |
+LIBVIRT_CHECK_SYSTEMD_DAEMON
|
|
|
c401cc |
LIBVIRT_CHECK_UDEV
|
|
|
c401cc |
LIBVIRT_CHECK_YAJL
|
|
|
c401cc |
|
|
|
c401cc |
@@ -2603,6 +2604,7 @@ LIBVIRT_RESULT_SANLOCK
|
|
|
c401cc |
LIBVIRT_RESULT_SASL
|
|
|
c401cc |
LIBVIRT_RESULT_SELINUX
|
|
|
c401cc |
LIBVIRT_RESULT_SSH2
|
|
|
c401cc |
+LIBVIRT_RESULT_SYSTEMD_DAEMON
|
|
|
c401cc |
LIBVIRT_RESULT_UDEV
|
|
|
c401cc |
LIBVIRT_RESULT_YAJL
|
|
|
c401cc |
AC_MSG_NOTICE([ libxml: $LIBXML_CFLAGS $LIBXML_LIBS])
|
|
|
c401cc |
diff --git a/daemon/libvirtd.service.in b/daemon/libvirtd.service.in
|
|
|
c401cc |
index aa5913b..c4286ef 100644
|
|
|
c401cc |
--- a/daemon/libvirtd.service.in
|
|
|
c401cc |
+++ b/daemon/libvirtd.service.in
|
|
|
c401cc |
@@ -11,6 +11,7 @@ After=dbus.service
|
|
|
c401cc |
After=iscsid.service
|
|
|
c401cc |
|
|
|
c401cc |
[Service]
|
|
|
c401cc |
+Type=notify
|
|
|
c401cc |
EnvironmentFile=-/etc/sysconfig/libvirtd
|
|
|
c401cc |
ExecStart=@sbindir@/libvirtd $LIBVIRTD_ARGS
|
|
|
c401cc |
ExecReload=/bin/kill -HUP $MAINPID
|
|
|
c401cc |
diff --git a/m4/virt-systemd-daemon.m4 b/m4/virt-systemd-daemon.m4
|
|
|
c401cc |
new file mode 100644
|
|
|
c401cc |
index 0000000..8516e41
|
|
|
c401cc |
--- /dev/null
|
|
|
c401cc |
+++ b/m4/virt-systemd-daemon.m4
|
|
|
c401cc |
@@ -0,0 +1,34 @@
|
|
|
c401cc |
+dnl The libsystemd-daemon.so library
|
|
|
c401cc |
+dnl
|
|
|
c401cc |
+dnl Copyright (C) 2012-2013 Red Hat, Inc.
|
|
|
c401cc |
+dnl
|
|
|
c401cc |
+dnl This library is free software; you can redistribute it and/or
|
|
|
c401cc |
+dnl modify it under the terms of the GNU Lesser General Public
|
|
|
c401cc |
+dnl License as published by the Free Software Foundation; either
|
|
|
c401cc |
+dnl version 2.1 of the License, or (at your option) any later version.
|
|
|
c401cc |
+dnl
|
|
|
c401cc |
+dnl This library is distributed in the hope that it will be useful,
|
|
|
c401cc |
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
c401cc |
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
c401cc |
+dnl Lesser General Public License for more details.
|
|
|
c401cc |
+dnl
|
|
|
c401cc |
+dnl You should have received a copy of the GNU Lesser General Public
|
|
|
c401cc |
+dnl License along with this library. If not, see
|
|
|
c401cc |
+dnl <http://www.gnu.org/licenses/>.
|
|
|
c401cc |
+dnl
|
|
|
c401cc |
+
|
|
|
c401cc |
+AC_DEFUN([LIBVIRT_CHECK_SYSTEMD_DAEMON],[
|
|
|
c401cc |
+ LIBVIRT_CHECK_PKG([SYSTEMD_DAEMON], [libsystemd-daemon], [0.27.1])
|
|
|
c401cc |
+
|
|
|
c401cc |
+ old_CFLAGS="$CFLAGS"
|
|
|
c401cc |
+ old_LIBS="$LIBS"
|
|
|
c401cc |
+ CFLAGS="$CFLAGS $SYSTEMD_DAEMON_CFLAGS"
|
|
|
c401cc |
+ LIBS="$LIBS $SYSTEMD_DAEMON_LIBS"
|
|
|
c401cc |
+ AC_CHECK_FUNCS([sd_notify])
|
|
|
c401cc |
+ CFLAGS="$old_CFLAGS"
|
|
|
c401cc |
+ LIBS="$old_LIBS"
|
|
|
c401cc |
+])
|
|
|
c401cc |
+
|
|
|
c401cc |
+AC_DEFUN([LIBVIRT_RESULT_SYSTEMD_DAEMON],[
|
|
|
c401cc |
+ LIBVIRT_RESULT_LIB([SYSTEMD_DAEMON])
|
|
|
c401cc |
+])
|
|
|
c401cc |
diff --git a/src/Makefile.am b/src/Makefile.am
|
|
|
c401cc |
index 8a7cefb..948efb4 100644
|
|
|
c401cc |
--- a/src/Makefile.am
|
|
|
c401cc |
+++ b/src/Makefile.am
|
|
|
c401cc |
@@ -904,11 +904,11 @@ libvirt_util_la_SOURCES = \
|
|
|
c401cc |
libvirt_util_la_CFLAGS = $(CAPNG_CFLAGS) $(YAJL_CFLAGS) $(LIBNL_CFLAGS) \
|
|
|
c401cc |
$(AM_CFLAGS) $(AUDIT_CFLAGS) $(DEVMAPPER_CFLAGS) \
|
|
|
c401cc |
$(DBUS_CFLAGS) $(LDEXP_LIBM) $(NUMACTL_CFLAGS) \
|
|
|
c401cc |
- -I$(top_srcdir)/src/conf
|
|
|
c401cc |
+ $(SYSTEMD_DAEMON_CFLAGS) -I$(top_srcdir)/src/conf
|
|
|
c401cc |
libvirt_util_la_LIBADD = $(CAPNG_LIBS) $(YAJL_LIBS) $(LIBNL_LIBS) \
|
|
|
c401cc |
$(THREAD_LIBS) $(AUDIT_LIBS) $(DEVMAPPER_LIBS) \
|
|
|
c401cc |
$(LIB_CLOCK_GETTIME) $(DBUS_LIBS) $(MSCOM_LIBS) $(LIBXML_LIBS) \
|
|
|
c401cc |
- $(SECDRIVER_LIBS) $(NUMACTL_LIBS)
|
|
|
c401cc |
+ $(SECDRIVER_LIBS) $(NUMACTL_LIBS) $(SYSTEMD_DAEMON_LIBS)
|
|
|
c401cc |
|
|
|
c401cc |
|
|
|
c401cc |
noinst_LTLIBRARIES += libvirt_conf.la
|
|
|
c401cc |
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
|
|
|
c401cc |
index 12f70cb..c2ae2c8 100644
|
|
|
c401cc |
--- a/src/libvirt_private.syms
|
|
|
c401cc |
+++ b/src/libvirt_private.syms
|
|
|
c401cc |
@@ -1972,6 +1972,7 @@ virSystemdCreateMachine;
|
|
|
c401cc |
virSystemdMakeMachineName;
|
|
|
c401cc |
virSystemdMakeScopeName;
|
|
|
c401cc |
virSystemdMakeSliceName;
|
|
|
c401cc |
+virSystemdNotifyStartup;
|
|
|
c401cc |
virSystemdTerminateMachine;
|
|
|
c401cc |
|
|
|
c401cc |
|
|
|
c401cc |
diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c
|
|
|
c401cc |
index 2306e10..df61036 100644
|
|
|
c401cc |
--- a/src/rpc/virnetserver.c
|
|
|
c401cc |
+++ b/src/rpc/virnetserver.c
|
|
|
c401cc |
@@ -38,6 +38,7 @@
|
|
|
c401cc |
#include "virnetservermdns.h"
|
|
|
c401cc |
#include "virdbus.h"
|
|
|
c401cc |
#include "virstring.h"
|
|
|
c401cc |
+#include "virsystemd.h"
|
|
|
c401cc |
|
|
|
c401cc |
#ifndef SA_SIGINFO
|
|
|
c401cc |
# define SA_SIGINFO 0
|
|
|
c401cc |
@@ -1085,6 +1086,10 @@ void virNetServerRun(virNetServerPtr srv)
|
|
|
c401cc |
goto cleanup;
|
|
|
c401cc |
}
|
|
|
c401cc |
|
|
|
c401cc |
+ /* We are accepting connections now. Notify systemd
|
|
|
c401cc |
+ * so it can start dependent services. */
|
|
|
c401cc |
+ virSystemdNotifyStartup();
|
|
|
c401cc |
+
|
|
|
c401cc |
VIR_DEBUG("srv=%p quit=%d", srv, srv->quit);
|
|
|
c401cc |
while (!srv->quit) {
|
|
|
c401cc |
/* A shutdown timeout is specified, so check
|
|
|
c401cc |
diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
|
|
|
c401cc |
index 9247c92..8adf209 100644
|
|
|
c401cc |
--- a/src/util/virsystemd.c
|
|
|
c401cc |
+++ b/src/util/virsystemd.c
|
|
|
c401cc |
@@ -21,6 +21,10 @@
|
|
|
c401cc |
|
|
|
c401cc |
#include <config.h>
|
|
|
c401cc |
|
|
|
c401cc |
+#ifdef WITH_SYSTEMD_DAEMON
|
|
|
c401cc |
+# include <systemd/sd-daemon.h>
|
|
|
c401cc |
+#endif
|
|
|
c401cc |
+
|
|
|
c401cc |
#include "virsystemd.h"
|
|
|
c401cc |
#include "virdbus.h"
|
|
|
c401cc |
#include "virstring.h"
|
|
|
c401cc |
@@ -304,3 +308,11 @@ cleanup:
|
|
|
c401cc |
VIR_FREE(machinename);
|
|
|
c401cc |
return ret;
|
|
|
c401cc |
}
|
|
|
c401cc |
+
|
|
|
c401cc |
+void
|
|
|
c401cc |
+virSystemdNotifyStartup(void)
|
|
|
c401cc |
+{
|
|
|
c401cc |
+#ifdef WITH_SYSTEMD_DAEMON
|
|
|
c401cc |
+ sd_notify(0, "READY=1");
|
|
|
c401cc |
+#endif
|
|
|
c401cc |
+}
|
|
|
c401cc |
diff --git a/src/util/virsystemd.h b/src/util/virsystemd.h
|
|
|
c401cc |
index d9845e1..7fed456 100644
|
|
|
c401cc |
--- a/src/util/virsystemd.h
|
|
|
c401cc |
+++ b/src/util/virsystemd.h
|
|
|
c401cc |
@@ -46,4 +46,6 @@ int virSystemdTerminateMachine(const char *name,
|
|
|
c401cc |
const char *drivername,
|
|
|
c401cc |
bool privileged);
|
|
|
c401cc |
|
|
|
c401cc |
+void virSystemdNotifyStartup(void);
|
|
|
c401cc |
+
|
|
|
c401cc |
#endif /* __VIR_SYSTEMD_H__ */
|
|
|
c401cc |
--
|
|
|
c401cc |
1.9.0
|
|
|
c401cc |
|