File tgt-systemd-notification-support of Package tgt.1509
From: Apollon Oikonomopoulos <apoikos@debian.org> Date: Wed, 21 May 2014 11:43:27 +0900 Subject: systemd notification support Git-commit: 63802aa754f4327833d9cb05cc26815f46b0fc9c Patch-mainline: v1.0.48 tgtd may take some time to initialize before accepting management commands. Since management commands are used to bring the targets up during service startup, we have to make sure that tgtd is responsive before proceeding. To this end, we add a call to sd_notify(3) right before entering the event loop to signal systemd (if applicable) that the main process is ready. Systemd support with the relevant includes and linker flags is optional, controlled by the SD_NOTIFY make flag. Signed-off-by: Apollon Oikonomopoulos <apoikos@debian.org> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Acked-by: Lee Duncan <lduncan@suse.com> --- Makefile | 1 + usr/Makefile | 8 ++++++++ usr/tgtd.c | 4 ++++ usr/tgtd.h | 4 ++++ 4 files changed, 17 insertions(+) --- a/Makefile +++ b/Makefile @@ -12,6 +12,7 @@ export VERSION PREFIX # Export the feature switches so sub-make knows about them export ISCSI_RDMA export CEPH_RBD +export SD_NOTIFY .PHONY: all all: programs doc conf scripts --- a/usr/Makefile +++ b/usr/Makefile @@ -17,6 +17,10 @@ ifneq ($(CEPH_RBD),) MODULES += bs_rbd.so endif +ifneq ($(SD_NOTIFY),) +CFLAGS += -DUSE_SYSTEMD +endif + ifneq ($(shell test -e /usr/include/sys/eventfd.h && test -e /usr/include/libaio.h && echo 1),) CFLAGS += -DUSE_EVENTFD TGTD_OBJS += bs_aio.o @@ -46,6 +50,10 @@ CFLAGS += -DBSDIR=\"$(DESTDIR)$(libdir)/ LIBS += -lpthread -ldl +ifneq ($(SD_NOTIFY),) +LIBS += -lsystemd-daemon +endif + PROGRAMS += tgtd tgtadm tgtimg TGTD_OBJS += tgtd.o mgmt.o target.o scsi.o log.o driver.o util.o work.o \ concat_buf.o parser.o spc.o sbc.o mmc.o osd.o scc.o smc.o \ --- a/usr/tgtd.c +++ b/usr/tgtd.c @@ -617,6 +617,10 @@ int main(int argc, char **argv) bs_init(); +#ifdef USE_SYSTEMD + sd_notify(0, "READY=1\nSTATUS=Starting event loop..."); +#endif + event_loop(); lld_exit(); --- a/usr/tgtd.h +++ b/usr/tgtd.h @@ -5,6 +5,10 @@ #include "scsi_cmnd.h" #include "tgtadm_error.h" +#ifdef USE_SYSTEMD +#include <systemd/sd-daemon.h> +#endif + struct concat_buf; #define NR_SCSI_OPCODES 256