All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH rdma-core 0/6] Systemd integration for ibacm
@ 2017-07-31 20:25 Jason Gunthorpe
       [not found] ` <1501532745-28378-1-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
  0 siblings, 1 reply; 10+ messages in thread
From: Jason Gunthorpe @ 2017-07-31 20:25 UTC (permalink / raw)
  To: Sean Hefty, Hal Rosenstock, linux-rdma-u79uwXL29TY76Z2rM5mHXA

This series makes ibacm socket activable and fine tunes the systemd
integration by running with stderr directed to the logger.

socket activation will help solve some of our boot time ordering issues by
allowing services that use rdma cm to startup without having to be concerned
with the ordering relative to ibacm.

This also makes ibacm more reliable when upgrading as systemd ensures there is
never a time when the listening socket does not exist.

Unlike other socket activation's this does not make ibacm demand start on
first use, this is because the kernel uses ibacm for RDMA local services.

https://github.com/linux-rdma/rdma-core/pull/176

Jason Gunthorpe (6):
  Detect if libsystemd is present
  ibacm: Avoid using @prefix@
  ibacm: Use daemon() instead of open coding
  ibacm: Do not fork under systemd
  ibacm: Adjust systemd service Description
  ibacm: Support systemd socket activation

 CMakeLists.txt                             |  7 +++
 buildlib/FindSystemd.cmake                 | 30 +++++++++++
 buildlib/cbuild                            | 18 ++++---
 buildlib/fixup-include/systemd-sd-daemon.h | 11 ++++
 debian/control                             |  1 +
 debian/ibacm.install                       |  1 +
 ibacm/CMakeLists.txt                       |  7 ++-
 ibacm/ibacm.init.in                        |  6 +--
 ibacm/ibacm.service.in                     |  7 +--
 ibacm/ibacm.socket                         | 10 ++++
 ibacm/man/ibacm.1                          |  4 ++
 ibacm/src/acm.c                            | 87 +++++++++++++++++++-----------
 rdma-core.spec                             |  3 ++
 redhat/rdma-core.spec                      |  2 +
 14 files changed, 150 insertions(+), 44 deletions(-)
 create mode 100644 buildlib/FindSystemd.cmake
 create mode 100644 buildlib/fixup-include/systemd-sd-daemon.h
 create mode 100644 ibacm/ibacm.socket

-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH rdma-core 1/6] Detect if libsystemd is present
       [not found] ` <1501532745-28378-1-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
@ 2017-07-31 20:25   ` Jason Gunthorpe
  2017-07-31 20:25   ` [PATCH rdma-core 2/6] ibacm: Avoid using @prefix@ Jason Gunthorpe
                     ` (4 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Jason Gunthorpe @ 2017-07-31 20:25 UTC (permalink / raw)
  To: Sean Hefty, Hal Rosenstock, linux-rdma-u79uwXL29TY76Z2rM5mHXA

This is needed for systemd integration in the daemons.

Signed-off-by: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
---
 CMakeLists.txt                             |  7 +++++++
 buildlib/FindSystemd.cmake                 | 30 ++++++++++++++++++++++++++++++
 buildlib/cbuild                            | 18 ++++++++++++------
 buildlib/fixup-include/systemd-sd-daemon.h | 11 +++++++++++
 debian/control                             |  1 +
 rdma-core.spec                             |  3 +++
 redhat/rdma-core.spec                      |  1 +
 7 files changed, 65 insertions(+), 6 deletions(-)
 create mode 100644 buildlib/FindSystemd.cmake
 create mode 100644 buildlib/fixup-include/systemd-sd-daemon.h

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1e9b1a363b7436..5de86f13f5ac19 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -328,6 +328,10 @@ CHECK_C_SOURCE_COMPILES("
  int main(int argc,const char *argv[]) {return 0;}"
   HAVE_COHERENT_DMA)
 
+find_package(Systemd)
+include_directories(${SYSTEMD_INCLUDE_DIRS})
+RDMA_DoFixup("${SYSTEMD_FOUND}" "systemd/sd-daemon.h")
+
 #-------------------------
 # Apply fixups
 
@@ -478,6 +482,9 @@ else()
     message(STATUS " netlink/route/link.h and net/if.h NOT co-includable (old headers)")
   endif()
 endif()
+if (NOT SYSTEMD_FOUND)
+  message(STATUS " libsystemd NOT found (disabling features)")
+endif()
 if (NOT UDEV_FOUND)
   message(STATUS " libudev NOT found (disabling features)")
 endif()
diff --git a/buildlib/FindSystemd.cmake b/buildlib/FindSystemd.cmake
new file mode 100644
index 00000000000000..fbced4028e823e
--- /dev/null
+++ b/buildlib/FindSystemd.cmake
@@ -0,0 +1,30 @@
+# COPYRIGHT (c) 2015 Obsidian Research Corporation.
+# Licensed under BSD (MIT variant) or GPLv2. See COPYING.
+
+find_path(LIBSYSTEMD_INCLUDE_DIRS "systemd/sd-journal.h")
+
+if (LIBSYSTEMD_INCLUDE_DIRS)
+  set(SYSTEMD_INCLUDE_DIRS ${LIBSYSTEMD_INCLUDE_DIRS})
+  find_library(LIBSYSTEMD_LIBRARY NAMES systemd libsystemd)
+  # Older systemd uses a split library
+  if (NOT LIBSYSTEMD_LIBRARY)
+    find_library(LIBSYSTEMD_JOURNAL_LIBRARY NAMES systemd-journal libsystemd-journal)
+    find_library(LIBSYSTEMD_ID128_LIBRARY NAMES systemd-id128 libsystemd-id128)
+    find_library(LIBSYSTEMD_DAEMON_LIBRARY NAMES systemd-daemon libsystemd-daemon)
+
+    if (LIBSYSTEMD_JOURNAL_LIBRARY AND LIBSYSTEMD_ID128_LIBRARY AND LIBSYSTEMD_DAEMON_LIBRARY)
+      set(SYSTEMD_LIBRARIES
+	${LIBSYSTEMD_JOURNAL_LIBRARY}
+	${LIBSYSTEMD_ID128_LIBRARY}
+	${LIBSYSTEMD_DAEMON_LIBRARY})
+    endif()
+  else()
+    set(SYSTEMD_LIBRARIES ${LIBSYSTEMD_LIBRARY})
+  endif()
+  set(SYSTEMD_INCLUDE_DIRS)
+endif()
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Systemd REQUIRED_VARS SYSTEMD_LIBRARIES LIBSYSTEMD_INCLUDE_DIRS)
+
+mark_as_advanced(LIBSYSTEMD_LIBRARY LIBSYSTEMD_JOURNAL_LIBRARY LIBSYSTEMD_ID128_LIBRARY LIBSYSTEMD_DAEMON_LIBRARY)
diff --git a/buildlib/cbuild b/buildlib/cbuild
index 888fae6ccca692..9b49fa5343c8b4 100755
--- a/buildlib/cbuild
+++ b/buildlib/cbuild
@@ -107,7 +107,7 @@ class centos6(YumEnvironment):
 
 class centos7(YumEnvironment):
     docker_parent = "centos:7";
-    pkgs = centos6.pkgs;
+    pkgs = centos6.pkgs | {'systemd-devel'};
     name = "centos7";
     use_make = True;
     specfile = "redhat/rdma-core.spec";
@@ -152,7 +152,7 @@ class APTEnvironment(Environment):
 
 class trusty(APTEnvironment):
     docker_parent = "ubuntu:14.04";
-    pkgs = {
+    common_pkgs = {
         'build-essential',
         'cmake',
         'debhelper',
@@ -167,30 +167,35 @@ class trusty(APTEnvironment):
         'python',
         'valgrind',
         };
+    pkgs = common_pkgs | {
+        'libsystemd-daemon-dev',
+        'libsystemd-id128-dev',
+        'libsystemd-journal-dev',
+        };
     name = "ubuntu-14.04";
     aliases = {"trusty"};
 
 class xenial(APTEnvironment):
     docker_parent = "ubuntu:16.04"
-    pkgs = trusty.pkgs;
+    pkgs = trusty.common_pkgs | {"libsystemd-dev"};
     name = "ubuntu-16.04";
     aliases = {"xenial"};
 
 class jessie(APTEnvironment):
     docker_parent = "debian:8"
-    pkgs = trusty.pkgs;
+    pkgs = xenial.pkgs;
     name = "debian-8";
     aliases = {"jessie"};
 
 class stretch(APTEnvironment):
     docker_parent = "debian:9"
-    pkgs = trusty.pkgs;
+    pkgs = jessie.pkgs;
     name = "debian-9";
     aliases = {"stretch"};
 
 class debian_experimental(APTEnvironment):
     docker_parent = "debian:experimental"
-    pkgs = (trusty.pkgs ^ {"gcc"}) | {"gcc-7"};
+    pkgs = (stretch.pkgs ^ {"gcc"}) | {"gcc-7"};
     name = "debian-experimental";
 
     def get_docker_file(self):
@@ -299,6 +304,7 @@ class harlequin(ZypperEnvironment):
         'pkg-config',
         'python',
         'rpm-build',
+        'systemd-devel',
         'valgrind-devel',
     };
     name = "opensuse-13.2";
diff --git a/buildlib/fixup-include/systemd-sd-daemon.h b/buildlib/fixup-include/systemd-sd-daemon.h
new file mode 100644
index 00000000000000..bd111bc6d21cd9
--- /dev/null
+++ b/buildlib/fixup-include/systemd-sd-daemon.h
@@ -0,0 +1,11 @@
+#define SD_LISTEN_FDS_START 3
+
+static inline int sd_listen_fds(int unset_environment)
+{
+	return 0;
+}
+
+static inline int sd_is_socket(int fd, int family, int type, int listening)
+{
+	return 0;
+}
diff --git a/debian/control b/debian/control
index 444b0eaa047ba8..156cec8fbc1a27 100644
--- a/debian/control
+++ b/debian/control
@@ -10,6 +10,7 @@ Build-Depends: cmake (>= 2.8.11),
                dpkg-dev (>= 1.17),
                libnl-3-dev,
                libnl-route-3-dev,
+               libsystemd-dev,
                libudev-dev,
                ninja-build,
                pkg-config,
diff --git a/rdma-core.spec b/rdma-core.spec
index b923a5d7636548..9d767a29eb1bba 100644
--- a/rdma-core.spec
+++ b/rdma-core.spec
@@ -20,6 +20,9 @@ BuildRequires: pkgconfig(libnl-3.0)
 BuildRequires: pkgconfig(libnl-route-3.0)
 BuildRequires: valgrind-devel
 BuildRequires: python
+%if 0%{?_unitdir:1}
+BuildRequires: systemd-devel
+%endif
 
 # Since we recommend developers use Ninja, so should packagers, for consistency.
 %define CMAKE_FLAGS %{nil}
diff --git a/redhat/rdma-core.spec b/redhat/rdma-core.spec
index 4413418ffc44cc..e5a59e073b7afd 100644
--- a/redhat/rdma-core.spec
+++ b/redhat/rdma-core.spec
@@ -20,6 +20,7 @@ BuildRequires: pkgconfig(libnl-3.0)
 BuildRequires: pkgconfig(libnl-route-3.0)
 BuildRequires: valgrind-devel
 BuildRequires: systemd
+BuildRequires: systemd-devel
 BuildRequires: python
 
 Requires: dracut, kmod, systemd
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH rdma-core 2/6] ibacm: Avoid using @prefix@
       [not found] ` <1501532745-28378-1-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
  2017-07-31 20:25   ` [PATCH rdma-core 1/6] Detect if libsystemd is present Jason Gunthorpe
@ 2017-07-31 20:25   ` Jason Gunthorpe
  2017-07-31 20:25   ` [PATCH rdma-core 3/6] ibacm: Use daemon() instead of open coding Jason Gunthorpe
                     ` (3 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Jason Gunthorpe @ 2017-07-31 20:25 UTC (permalink / raw)
  To: Sean Hefty, Hal Rosenstock, linux-rdma-u79uwXL29TY76Z2rM5mHXA

Instead use @CMAKE_INSTALL_FULL_SBINDIR@ like everything else.

Signed-off-by: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
---
 ibacm/CMakeLists.txt   | 1 -
 ibacm/ibacm.init.in    | 6 +++---
 ibacm/ibacm.service.in | 2 +-
 3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/ibacm/CMakeLists.txt b/ibacm/CMakeLists.txt
index 5e3ea5e29de0b6..75869968534438 100644
--- a/ibacm/CMakeLists.txt
+++ b/ibacm/CMakeLists.txt
@@ -59,7 +59,6 @@ rdma_man_pages(
 
 # FIXME: update the .init.in
 set(rdmascript "openibd")
-set(prefix "${CMAKE_INSTALL_PREFIX}")
 rdma_subst_install(FILES "ibacm.init.in"
   DESTINATION "${CMAKE_INSTALL_INITDDIR}"
   RENAME "ibacm"
diff --git a/ibacm/ibacm.init.in b/ibacm/ibacm.init.in
index e53ce1d6e5f7c0..f37dc03a29010c 100644
--- a/ibacm/ibacm.init.in
+++ b/ibacm/ibacm.init.in
@@ -36,14 +36,14 @@ elif [ -s /lib/lsb/init-functions ]; then
 	# SLES / OpenSuSE / Debian
 	. /lib/lsb/init-functions
 	_daemon()   { start_daemon "$@"; }
-        _checkpid() { checkproc -p $pidfile @prefix@/sbin/ibacm; }
+        _checkpid() { checkproc -p $pidfile @CMAKE_INSTALL_FULL_SBINDIR@/ibacm; }
 	_success()  { log_success_msg; }
 	_failure()  { log_failure_msg; }
 elif [ -s /etc/rc.status ]; then
 	# Older SuSE
 	. /etc/rc.status
 	_daemon()   { /sbin/start_daemon ${1+"$@"}; }
-        _checkpid() { checkproc -p $pidfile @prefix@/sbin/ibacm; }
+        _checkpid() { checkproc -p $pidfile @CMAKE_INSTALL_FULL_SBINDIR@/ibacm; }
 	_success()  { rc_status -v; }
 	_failure()  { rc_status -v; }
 fi	
@@ -51,7 +51,7 @@ fi
 start()
 {
     echo -n "Starting ibacm daemon:"
-    _daemon @prefix@/sbin/ibacm
+    _daemon @CMAKE_INSTALL_FULL_SBINDIR@/ibacm
     if [[ $RETVAL -eq 0 ]]; then
         _success
     else
diff --git a/ibacm/ibacm.service.in b/ibacm/ibacm.service.in
index 6cbb203e320884..fae768faef560b 100644
--- a/ibacm/ibacm.service.in
+++ b/ibacm/ibacm.service.in
@@ -5,7 +5,7 @@ After=opensm.service
 
 [Service]
 Type=forking
-ExecStart=@prefix@/sbin/ibacm
+ExecStart=@CMAKE_INSTALL_FULL_SBINDIR@/ibacm
 
 [Install]
 WantedBy=network.target
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH rdma-core 3/6] ibacm: Use daemon() instead of open coding
       [not found] ` <1501532745-28378-1-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
  2017-07-31 20:25   ` [PATCH rdma-core 1/6] Detect if libsystemd is present Jason Gunthorpe
  2017-07-31 20:25   ` [PATCH rdma-core 2/6] ibacm: Avoid using @prefix@ Jason Gunthorpe
@ 2017-07-31 20:25   ` Jason Gunthorpe
  2017-07-31 20:25   ` [PATCH rdma-core 4/6] ibacm: Do not fork under systemd Jason Gunthorpe
                     ` (2 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Jason Gunthorpe @ 2017-07-31 20:25 UTC (permalink / raw)
  To: Sean Hefty, Hal Rosenstock, linux-rdma-u79uwXL29TY76Z2rM5mHXA

The version in glibc does the same things.

Signed-off-by: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
---
 ibacm/src/acm.c | 35 ++++++++---------------------------
 1 file changed, 8 insertions(+), 27 deletions(-)

diff --git a/ibacm/src/acm.c b/ibacm/src/acm.c
index 648ee400f795fb..e5cfdcb8726a8f 100644
--- a/ibacm/src/acm.c
+++ b/ibacm/src/acm.c
@@ -28,6 +28,8 @@
  * SOFTWARE.
  */
 
+#define _GNU_SOURCE
+
 #include <config.h>
 
 #include <stdio.h>
@@ -2933,29 +2935,6 @@ static int acm_open_lock_file(void)
 	return 0;
 }
 
-static void daemonize(void)
-{
-	pid_t pid, sid;
-
-	pid = fork();
-	if (pid)
-		exit(pid < 0);
-
-	sid = setsid();
-	if (sid < 0)
-		exit(1);
-
-	if (chdir("/"))
-		exit(1);
-
-	if(!freopen("/dev/null", "r", stdin))
-		exit(1);
-	if(!freopen("/dev/null", "w", stdout))
-		exit(1);
-	if(!freopen("/dev/null", "w", stderr))
-		exit(1);
-}
-
 static void show_usage(char *program)
 {
 	printf("usage: %s\n", program);
@@ -2969,7 +2948,7 @@ static void show_usage(char *program)
 
 int main(int argc, char **argv)
 {
-	int i, op, daemon = 1;
+	int i, op, as_daemon = 1;
 
 	while ((op = getopt(argc, argv, "DPA:O:")) != -1) {
 		switch (op) {
@@ -2977,7 +2956,7 @@ int main(int argc, char **argv)
 			/* option no longer required */
 			break;
 		case 'P':
-			daemon = 0;
+			as_daemon = 0;
 			break;
 		case 'A':
 			addr_file = optarg;
@@ -2991,8 +2970,10 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (daemon)
-		daemonize();
+	if (as_daemon) {
+		if (daemon(0, 0))
+			return EXIT_FAILURE;
+	}
 
 	acm_set_options();
 	if (acm_open_lock_file())
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH rdma-core 4/6] ibacm: Do not fork under systemd
       [not found] ` <1501532745-28378-1-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
                     ` (2 preceding siblings ...)
  2017-07-31 20:25   ` [PATCH rdma-core 3/6] ibacm: Use daemon() instead of open coding Jason Gunthorpe
@ 2017-07-31 20:25   ` Jason Gunthorpe
  2017-07-31 20:25   ` [PATCH rdma-core 5/6] ibacm: Adjust systemd service Description Jason Gunthorpe
  2017-07-31 20:25   ` [PATCH rdma-core 6/6] ibacm: Support systemd socket activation Jason Gunthorpe
  5 siblings, 0 replies; 10+ messages in thread
From: Jason Gunthorpe @ 2017-07-31 20:25 UTC (permalink / raw)
  To: Sean Hefty, Hal Rosenstock, linux-rdma-u79uwXL29TY76Z2rM5mHXA

This avoids daemonizing the server and forking as systemd does
all of that for us. The notable benefit is to allow stderr to
be routed to the journal in case there is any sort of internal
fault (eg a glibc memory failure)

Signed-off-by: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
---
 ibacm/ibacm.service.in | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/ibacm/ibacm.service.in b/ibacm/ibacm.service.in
index fae768faef560b..7d589b57f59e00 100644
--- a/ibacm/ibacm.service.in
+++ b/ibacm/ibacm.service.in
@@ -4,8 +4,7 @@ Documentation=man:ibacm file:@CMAKE_INSTALL_SYSCONFDIR@/rdma/ibacm_opts.cfg
 After=opensm.service
 
 [Service]
-Type=forking
-ExecStart=@CMAKE_INSTALL_FULL_SBINDIR@/ibacm
+ExecStart=@CMAKE_INSTALL_FULL_SBINDIR@/ibacm -P
 
 [Install]
 WantedBy=network.target
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH rdma-core 5/6] ibacm: Adjust systemd service Description
       [not found] ` <1501532745-28378-1-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
                     ` (3 preceding siblings ...)
  2017-07-31 20:25   ` [PATCH rdma-core 4/6] ibacm: Do not fork under systemd Jason Gunthorpe
@ 2017-07-31 20:25   ` Jason Gunthorpe
  2017-07-31 20:25   ` [PATCH rdma-core 6/6] ibacm: Support systemd socket activation Jason Gunthorpe
  5 siblings, 0 replies; 10+ messages in thread
From: Jason Gunthorpe @ 2017-07-31 20:25 UTC (permalink / raw)
  To: Sean Hefty, Hal Rosenstock, linux-rdma-u79uwXL29TY76Z2rM5mHXA

This looks odd:

 Jul 28 18:06:05 ib9 systemd[1]: Started Starts the InfiniBand Address Cache Manager daemon.

Drop the 'Starts'

Signed-off-by: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
---
 ibacm/ibacm.service.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ibacm/ibacm.service.in b/ibacm/ibacm.service.in
index 7d589b57f59e00..eb74c673552cb4 100644
--- a/ibacm/ibacm.service.in
+++ b/ibacm/ibacm.service.in
@@ -1,5 +1,5 @@
 [Unit]
-Description=Starts the InfiniBand Address Cache Manager daemon
+Description=InfiniBand Address Cache Manager Daemon
 Documentation=man:ibacm file:@CMAKE_INSTALL_SYSCONFDIR@/rdma/ibacm_opts.cfg
 After=opensm.service
 
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH rdma-core 6/6] ibacm: Support systemd socket activation
       [not found] ` <1501532745-28378-1-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
                     ` (4 preceding siblings ...)
  2017-07-31 20:25   ` [PATCH rdma-core 5/6] ibacm: Adjust systemd service Description Jason Gunthorpe
@ 2017-07-31 20:25   ` Jason Gunthorpe
       [not found]     ` <1501532745-28378-7-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
  5 siblings, 1 reply; 10+ messages in thread
From: Jason Gunthorpe @ 2017-07-31 20:25 UTC (permalink / raw)
  To: Sean Hefty, Hal Rosenstock, linux-rdma-u79uwXL29TY76Z2rM5mHXA

This lets systemd create the socket (to the admin's specifications) and
starts ibacm when something connects to it.

We are using this to improve boot ordering by ensuring that any rdma_cm
clients that would use ibacm block until ibacm is started up properly.
A user could also use this to demand start ibacm, but that means it
would not plug into kernel RMDA local services for caching.

For security, the socket will be created on the lo interface by default.
The admin can change this back to the old daemon behavior with a systemd
drop in.

Signed-off-by: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
---
 debian/ibacm.install   |  1 +
 ibacm/CMakeLists.txt   |  6 ++++++
 ibacm/ibacm.service.in |  4 +++-
 ibacm/ibacm.socket     | 10 ++++++++++
 ibacm/man/ibacm.1      |  4 ++++
 ibacm/src/acm.c        | 54 +++++++++++++++++++++++++++++++++++++++++++++-----
 redhat/rdma-core.spec  |  1 +
 7 files changed, 74 insertions(+), 6 deletions(-)
 create mode 100644 ibacm/ibacm.socket

diff --git a/debian/ibacm.install b/debian/ibacm.install
index 41cf5badb3e6c8..d3ed2a2e8f2dc7 100644
--- a/debian/ibacm.install
+++ b/debian/ibacm.install
@@ -1,5 +1,6 @@
 etc/init.d/ibacm
 lib/systemd/system/ibacm.service
+lib/systemd/system/ibacm.socket
 usr/bin/ib_acme
 usr/include/infiniband/acm.h
 usr/include/infiniband/acm_prov.h
diff --git a/ibacm/CMakeLists.txt b/ibacm/CMakeLists.txt
index 75869968534438..5d54411027cc8e 100644
--- a/ibacm/CMakeLists.txt
+++ b/ibacm/CMakeLists.txt
@@ -16,6 +16,7 @@ rdma_sbin_executable(ibacm
 target_link_libraries(ibacm LINK_PRIVATE
   ibverbs
   ibumad
+  ${SYSTEMD_LIBRARIES}
   ${CMAKE_THREAD_LIBS_INIT}
   ${CMAKE_DL_LIBS}
   )
@@ -68,3 +69,8 @@ rdma_subst_install(FILES "ibacm.service.in"
   DESTINATION "${CMAKE_INSTALL_SYSTEMD_SERVICEDIR}"
   RENAME ibacm.service
   PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ)
+
+install(FILES "ibacm.socket"
+  DESTINATION "${CMAKE_INSTALL_SYSTEMD_SERVICEDIR}"
+  RENAME ibacm.socket
+  PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ)
diff --git a/ibacm/ibacm.service.in b/ibacm/ibacm.service.in
index eb74c673552cb4..7f31ba673da979 100644
--- a/ibacm/ibacm.service.in
+++ b/ibacm/ibacm.service.in
@@ -2,9 +2,11 @@
 Description=InfiniBand Address Cache Manager Daemon
 Documentation=man:ibacm file:@CMAKE_INSTALL_SYSCONFDIR@/rdma/ibacm_opts.cfg
 After=opensm.service
+Wants=ibacm.socket
 
 [Service]
-ExecStart=@CMAKE_INSTALL_FULL_SBINDIR@/ibacm -P
+ExecStart=@CMAKE_INSTALL_FULL_SBINDIR@/ibacm --systemd
 
 [Install]
+Also=ibacm.socket
 WantedBy=network.target
diff --git a/ibacm/ibacm.socket b/ibacm/ibacm.socket
new file mode 100644
index 00000000000000..080257e9c7c320
--- /dev/null
+++ b/ibacm/ibacm.socket
@@ -0,0 +1,10 @@
+[Unit]
+Description=Socket for InfiniBand Address Cache Manager Daemon
+Documentation=man:ibacm
+
+[Socket]
+ListenStream=6125
+BindToDevice=lo
+
+[Install]
+WantedBy=sockets.target
diff --git a/ibacm/man/ibacm.1 b/ibacm/man/ibacm.1
index 5042e1ed88ac34..733dc64dde1910 100644
--- a/ibacm/man/ibacm.1
+++ b/ibacm/man/ibacm.1
@@ -50,6 +50,10 @@ address configuration file
 .TP
 \-O option_file
 option configuration file
+.TP
+\--systemd
+Enable systemd integration. This includes optional socket activation of the daemon's
+listening socket.
 .SH "QUICK START GUIDE"
 1. Prerequisites: libibverbs and libibumad must be installed.
 The IB stack should be running with IPoIB configured.
diff --git a/ibacm/src/acm.c b/ibacm/src/acm.c
index e5cfdcb8726a8f..3f28f04d8777b9 100644
--- a/ibacm/src/acm.c
+++ b/ibacm/src/acm.c
@@ -59,6 +59,8 @@
 #include <rdma/ib_user_sa.h>
 #include <poll.h>
 #include <inttypes.h>
+#include <getopt.h>
+#include <systemd/sd-daemon.h>
 #include <ccan/list.h>
 #include <util/util.h>
 #include "acm_mad.h"
@@ -599,6 +601,35 @@ static int acm_listen(void)
 	return 0;
 }
 
+/* Retrieve the listening socket from systemd. */
+static int acm_listen_systemd(void)
+{
+	int rc = sd_listen_fds(1);
+	if (rc == 0) {
+		/* We are in systemd mode but no FDs were passed? Fall back to
+		 * normal mode
+		 */
+		return acm_listen();
+	}
+	if (rc == -1) {
+		fprintf(stderr, "sd_listen_fds failed %d\n", rc);
+		return rc;
+	}
+
+	if (rc != 1) {
+		fprintf(stderr, "sd_listen_fds returned %d fds, expected 1\n", rc);
+		return -1;
+	}
+
+	if (!sd_is_socket(SD_LISTEN_FDS_START, AF_UNSPEC, SOCK_STREAM, 1)) {
+		fprintf(stderr, "sd_listen_fds socket is not a SOCK_STREAM listening socket\n");
+		return -1;
+	}
+
+	listen_socket = SD_LISTEN_FDS_START;
+	return 0;
+}
+
 static void acm_disconnect_client(struct acmc_client *client)
 {
 	pthread_mutex_lock(&client->lock);
@@ -1669,7 +1700,7 @@ static int acm_init_nl(void)
 	return 0;
 }
 
-static void acm_server(void)
+static void acm_server(bool systemd)
 {
 	fd_set readfds;
 	int i, n, ret;
@@ -1677,7 +1708,10 @@ static void acm_server(void)
 
 	acm_log(0, "started\n");
 	acm_init_server();
-	ret = acm_listen();
+	if (systemd)
+		ret = acm_listen_systemd();
+	else
+		ret = acm_listen();
 	if (ret) {
 		acm_log(0, "ERROR - server listen failed\n");
 		return;
@@ -2949,8 +2983,15 @@ static void show_usage(char *program)
 int main(int argc, char **argv)
 {
 	int i, op, as_daemon = 1;
+	bool systemd = false;
+
+	static const struct option long_opts[] = {
+		{"systemd", 0, NULL, 's'},
+		{}
+	};
 
-	while ((op = getopt(argc, argv, "DPA:O:")) != -1) {
+	while ((op = getopt_long(argc, argv, "DPA:O:", long_opts, NULL)) !=
+	       -1) {
 		switch (op) {
 		case 'D':
 			/* option no longer required */
@@ -2964,13 +3005,16 @@ int main(int argc, char **argv)
 		case 'O':
 			opts_file = optarg;
 			break;
+		case 's':
+			systemd = true;
+			break;
 		default:
 			show_usage(argv[0]);
 			exit(1);
 		}
 	}
 
-	if (as_daemon) {
+	if (as_daemon && !systemd) {
 		if (daemon(0, 0))
 			return EXIT_FAILURE;
 	}
@@ -3013,7 +3057,7 @@ int main(int argc, char **argv)
 	}
 	acm_activate_devices();
 	acm_log(1, "starting server\n");
-	acm_server();
+	acm_server(systemd);
 
 	acm_log(0, "shutting down\n");
 	if (client_array[NL_CLIENT_INDEX].sock != -1)
diff --git a/redhat/rdma-core.spec b/redhat/rdma-core.spec
index e5a59e073b7afd..71eae0cf8c2f78 100644
--- a/redhat/rdma-core.spec
+++ b/redhat/rdma-core.spec
@@ -389,6 +389,7 @@ rm -rf %{buildroot}/%{_sbindir}/srp_daemon.sh
 %{_mandir}/man7/ibacm.*
 %{_mandir}/man7/ibacm_prov.*
 %{_unitdir}/ibacm.service
+%{_unitdir}/ibacm.socket
 %dir %{_libdir}/ibacm
 %{_libdir}/ibacm/*
 %doc %{_docdir}/%{name}-%{version}/ibacm.md
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* RE: [PATCH rdma-core 6/6] ibacm: Support systemd socket activation
       [not found]     ` <1501532745-28378-7-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
@ 2017-07-31 20:42       ` Hefty, Sean
       [not found]         ` <1828884A29C6694DAF28B7E6B8A82373AB16373A-P5GAC/sN6hkd3b2yrw5b5LfspsVTdybXVpNB7YpNyf8@public.gmane.org>
  0 siblings, 1 reply; 10+ messages in thread
From: Hefty, Sean @ 2017-07-31 20:42 UTC (permalink / raw)
  To: Jason Gunthorpe, Hal Rosenstock, linux-rdma-u79uwXL29TY76Z2rM5mHXA

> This lets systemd create the socket (to the admin's specifications)
> and starts ibacm when something connects to it.
> 
> We are using this to improve boot ordering by ensuring that any
> rdma_cm clients that would use ibacm block until ibacm is started up
> properly.
> A user could also use this to demand start ibacm, but that means it
> would not plug into kernel RMDA local services for caching.
> 
> For security, the socket will be created on the lo interface by
> default.
> The admin can change this back to the old daemon behavior with a
> systemd drop in.

Calling this change out to increase visibility.

The series looks fine to me, and I don't have any issues.

- Sean
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH rdma-core 6/6] ibacm: Support systemd socket activation
       [not found]         ` <1828884A29C6694DAF28B7E6B8A82373AB16373A-P5GAC/sN6hkd3b2yrw5b5LfspsVTdybXVpNB7YpNyf8@public.gmane.org>
@ 2017-07-31 22:56           ` Jason Gunthorpe
       [not found]             ` <20170731225653.GB30733-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
  0 siblings, 1 reply; 10+ messages in thread
From: Jason Gunthorpe @ 2017-07-31 22:56 UTC (permalink / raw)
  To: Hefty, Sean; +Cc: Hal Rosenstock, linux-rdma-u79uwXL29TY76Z2rM5mHXA

On Mon, Jul 31, 2017 at 08:42:40PM +0000, Hefty, Sean wrote:
> > This lets systemd create the socket (to the admin's specifications)
> > and starts ibacm when something connects to it.
> > 
> > We are using this to improve boot ordering by ensuring that any
> > rdma_cm clients that would use ibacm block until ibacm is started up
> > properly.
> > A user could also use this to demand start ibacm, but that means it
> > would not plug into kernel RMDA local services for caching.
> > 
> > For security, the socket will be created on the lo interface by
> > default.
> > The admin can change this back to the old daemon behavior with a
> > systemd drop in.
> 
> Calling this change out to increase visibility.

Right, is the remote access use case typical?

Someone should also add some systemd compartmentalization directives
(see srp_daemon_port.service.in for some ideas) to help harden things
for an unpriv access daemon.

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: [PATCH rdma-core 6/6] ibacm: Support systemd socket activation
       [not found]             ` <20170731225653.GB30733-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
@ 2017-07-31 23:19               ` Hefty, Sean
  0 siblings, 0 replies; 10+ messages in thread
From: Hefty, Sean @ 2017-07-31 23:19 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: Hal Rosenstock, linux-rdma-u79uwXL29TY76Z2rM5mHXA

> > > For security, the socket will be created on the lo interface by
> > > default.
> > > The admin can change this back to the old daemon behavior with a
> > > systemd drop in.
> >
> > Calling this change out to increase visibility.
> 
> Right, is the remote access use case typical?

I think I've only used this to collect statistics from a remote node for debugging purposes.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-07-31 23:19 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-31 20:25 [PATCH rdma-core 0/6] Systemd integration for ibacm Jason Gunthorpe
     [not found] ` <1501532745-28378-1-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-07-31 20:25   ` [PATCH rdma-core 1/6] Detect if libsystemd is present Jason Gunthorpe
2017-07-31 20:25   ` [PATCH rdma-core 2/6] ibacm: Avoid using @prefix@ Jason Gunthorpe
2017-07-31 20:25   ` [PATCH rdma-core 3/6] ibacm: Use daemon() instead of open coding Jason Gunthorpe
2017-07-31 20:25   ` [PATCH rdma-core 4/6] ibacm: Do not fork under systemd Jason Gunthorpe
2017-07-31 20:25   ` [PATCH rdma-core 5/6] ibacm: Adjust systemd service Description Jason Gunthorpe
2017-07-31 20:25   ` [PATCH rdma-core 6/6] ibacm: Support systemd socket activation Jason Gunthorpe
     [not found]     ` <1501532745-28378-7-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-07-31 20:42       ` Hefty, Sean
     [not found]         ` <1828884A29C6694DAF28B7E6B8A82373AB16373A-P5GAC/sN6hkd3b2yrw5b5LfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2017-07-31 22:56           ` Jason Gunthorpe
     [not found]             ` <20170731225653.GB30733-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-07-31 23:19               ` Hefty, Sean

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.