From mboxrd@z Thu Jan 1 00:00:00 1970 From: jsmart2021@gmail.com (James Smart) Date: Fri, 19 Jul 2019 15:53:05 -0700 Subject: [PATCH v2 10/10] nvme-cli: nvmf auto-connect scripts In-Reply-To: <20190719225305.11397-1-jsmart2021@gmail.com> References: <20190719225305.11397-1-jsmart2021@gmail.com> Message-ID: <20190719225305.11397-11-jsmart2021@gmail.com> This set of scripts is a combination of those sent by Hannes, Sagi, and I in earlier patches and RFC's. Auto-connect operates by the nvme core layer or nvme-fc transport generating a udev event with directory-controller addressing information. The nvme core layer generates an event when a persistent discovery controller generates a Discovery Log Change Notification AEN. The nvme-fc transport generates an event when an FC rport that has a NVME Discovery controller is detected or when a FC state change event occurs for for an FC rport that has a NVME Discovery controller The udev event is handled by a script that extracts the Discovery controller addressing information and initiates a systemd service to perform a "nvme connect-all" to the Discovery controller. The "nvme connect-all" request is not called directly from the udev handler itself as the request may take some time or stall altogether, which would block other udev event handling. By transitioning to a sytemd service, the call can take as much time as needed to complete. The scripts consist of: - A udev script that handles nvme core and nvme-fc udev events. The udev handler starts a nvmf-connect systemd service. - A nvmf-connect systemd service. The service, in its instance name, is passed the connect arguments for the discovery controller. The service performs a "nvme connect-all" to the discovery controller. - A nvmefc-boot-connections systemd service. This is a run-once service run after udev is enabled, which will replay events generated by NVME-FC devices detected during boot while udev is not yet running. - To stop autoconnect an additional nvmefc-connect.target has been added, which will instruct systemd to cancel all outstanding autoconnect services. Note: Although the nvme-fc subsystem is converting to use the same nvme core layer event mechanism, the nvme-fc-specific udev event that has been in existence for a while is contained in in the script so that the utilities may run against older kernels. Signed-off-by: James Smart Reviewed-by: Sagi Grimberg Reviewed-by: Hannes Reinecke CC: Simon Schricker --- v2: change nvme.spec.in to load systemd mods before loading udev mods --- Makefile | 22 +++++++++++++++++++--- nvme.spec.in | 9 +++++++++ nvmf-autoconnect/70-nvmf-autoconnect.conf | 1 + nvmf-autoconnect/70-nvmf-autoconnect.rules | 18 ++++++++++++++++++ nvmf-autoconnect/nvmefc-boot-connections.service | 9 +++++++++ nvmf-autoconnect/nvmf-connect.target | 2 ++ nvmf-autoconnect/nvmf-connect at .service | 14 ++++++++++++++ 7 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 nvmf-autoconnect/70-nvmf-autoconnect.conf create mode 100644 nvmf-autoconnect/70-nvmf-autoconnect.rules create mode 100644 nvmf-autoconnect/nvmefc-boot-connections.service create mode 100644 nvmf-autoconnect/nvmf-connect.target create mode 100644 nvmf-autoconnect/nvmf-connect at .service diff --git a/Makefile b/Makefile index db594a3..2ce255b 100644 --- a/Makefile +++ b/Makefile @@ -5,9 +5,13 @@ LIBUUID = $(shell $(LD) -o /dev/null -luuid >/dev/null 2>&1; echo $$?) NVME = nvme INSTALL ?= install DESTDIR = -PREFIX ?= /usr/local +PREFIX ?= /usr SYSCONFDIR = /etc SBINDIR = $(PREFIX)/sbin +LIBDIR ?= $(PREFIX)/lib +SYSTEMDDIR ?= $(LIBDIR)/systemd +UDEVDIR ?= $(LIBDIR)/udev +DRACUTDIR ?= $(LIBDIR)/dracut LIB_DEPENDS = ifeq ($(LIBUUID),0) @@ -89,6 +93,18 @@ install-bash-completion: $(INSTALL) -d $(DESTDIR)$(PREFIX)/share/bash-completion/completions $(INSTALL) -m 644 -T ./completions/bash-nvme-completion.sh $(DESTDIR)$(PREFIX)/share/bash-completion/completions/nvme +install-systemd: + $(INSTALL) -d $(DESTDIR)$(SYSTEMDDIR)/system + $(INSTALL) -m 644 ./nvmf-autoconnect/*.service ./nvmf-autoconnect/*.target $(DESTDIR)$(SYSTEMDDIR)/system + +install-udev: + $(INSTALL) -d $(DESTDIR)$(UDEVDIR)/rules.d + $(INSTALL) -m 644 ./nvmf-autoconnect/*.rules $(DESTDIR)$(UDEVDIR)/rules.d + +install-dracut: + $(INSTALL) -d $(DESTDIR)$(DRACUTDIR)/dracut.conf.d + $(INSTALL) -m 644 ./nvmf-autoconnect/*.conf $(DESTDIR)$(DRACUTDIR)/dracut.conf.d + install-zsh-completion: $(INSTALL) -d $(DESTDIR)$(PREFIX)/share/zsh/site-functions $(INSTALL) -m 644 -T ./completions/_nvme $(DESTDIR)$(PREFIX)/share/zsh/site-functions/_nvme @@ -109,7 +125,7 @@ install-etc: $(INSTALL) -m 644 -T ./etc/discovery.conf.in $(DESTDIR)$(SYSCONFDIR)/nvme/discovery.conf; \ fi -install-spec: install-bin install-man install-bash-completion install-zsh-completion install-etc +install-spec: install-bin install-man install-bash-completion install-zsh-completion install-etc install-systemd install-udev install-dracut install: install-spec install-hostparams nvme.spec: nvme.spec.in NVME-VERSION-FILE @@ -177,7 +193,7 @@ deb-light: $(NVME) pkg nvme.control.in dpkg-deb --build nvme-$(NVME_VERSION) rpm: dist - $(RPMBUILD) -ta nvme-$(NVME_VERSION).tar.gz + $(RPMBUILD) --define '_libdir ${LIBDIR}' -ta nvme-$(NVME_VERSION).tar.gz .PHONY: default doc all clean clobber install-man install-bin install .PHONY: dist pkg dist-orig deb deb-light rpm FORCE test diff --git a/nvme.spec.in b/nvme.spec.in index 6934f8f..b8e3377 100644 --- a/nvme.spec.in +++ b/nvme.spec.in @@ -35,6 +35,11 @@ make install-spec DESTDIR=%{buildroot} PREFIX=/usr %{_sysconfdir}/nvme/hostnqn %{_sysconfdir}/nvme/hostid %{_sysconfdir}/nvme/discovery.conf +%{_libdir}/udev/rules.d/70-nvmf-autoconnect.rules +%{_libdir}/dracut/dracut.conf.d/70-nvmf-autoconnect.conf +%{_libdir}/systemd/system/nvmf-connect at .service +%{_libdir}/systemd/system/nvmefc-boot-connections.service +%{_libdir}/systemd/system/nvmf-connect.target %clean rm -rf $RPM_BUILD_ROOT @@ -47,6 +52,10 @@ if [ $1 -eq 1 ]; then # 1 : This package is being installed for the first time if [ ! -s %{_sysconfdir}/nvme/hostid ]; then uuidgen > %{_sysconfdir}/nvme/hostid fi + + # apply udev and systemd changes that we did + systemctl daemon-reload + udevadm control --reload-rules && udevadm trigger fi %changelog diff --git a/nvmf-autoconnect/70-nvmf-autoconnect.conf b/nvmf-autoconnect/70-nvmf-autoconnect.conf new file mode 100644 index 0000000..844f3d9 --- /dev/null +++ b/nvmf-autoconnect/70-nvmf-autoconnect.conf @@ -0,0 +1 @@ +install_items+="/usr/lib/udev/rules.d/70-nvmf-autoconnect.rules" diff --git a/nvmf-autoconnect/70-nvmf-autoconnect.rules b/nvmf-autoconnect/70-nvmf-autoconnect.rules new file mode 100644 index 0000000..f901bd1 --- /dev/null +++ b/nvmf-autoconnect/70-nvmf-autoconnect.rules @@ -0,0 +1,18 @@ +# +# nvmf-autoconnect.rules: +# Handles udev events which invoke automatically scan via discovery +# controller and connect to elements in the discovery log. +# +# + +# Events from persistent discovery controllers or nvme-fc transport events +ACTION=="change", SUBSYSTEM=="nvme", ENV{NVME_EVENT}=="discovery",\ + ENV{NVME_CTRL_NAME}=="*", ENV{NVME_TRTYPE}=="*", ENV{NVME_TRADDR}=="*", \ + ENV{NVME_TRSVCID}=="*", ENV{NVME_HOST_TRADDR}=="*", \ + RUN+="/usr/bin/systemctl --no-block start nvmf-connect at --device=$env{NVME_CTRL_NAME}\t--transport=$env{NVME_TRTYPE}\t--traddr=$env{NVME_TRADDR}\t--trsvcid=$env{NVME_TRSVCID}\t--host-traddr=$env{NVME_HOST_TRADDR}.service" + +# nvme-fc transport generated events (old-style for compatibility) +ACTION=="change", SUBSYSTEM=="fc", ENV{FC_EVENT}=="nvmediscovery", \ + ENV{NVMEFC_HOST_TRADDR}=="*", ENV{NVMEFC_TRADDR}=="*", \ + RUN+="/usr/bin/systemctl --no-block start nvmf-connect at --device=none\t--transport=fc\t--traddr=$env{NVMEFC_TRADDR}\t--trsvcid=none\t--host-traddr=$env{NVMEFC_HOST_TRADDR}.service" + diff --git a/nvmf-autoconnect/nvmefc-boot-connections.service b/nvmf-autoconnect/nvmefc-boot-connections.service new file mode 100644 index 0000000..84f6486 --- /dev/null +++ b/nvmf-autoconnect/nvmefc-boot-connections.service @@ -0,0 +1,9 @@ +[Unit] +Description=Auto-connect to subsystems on FC-NVME devices found during boot + +[Service] +Type=oneshot +ExecStart=/bin/sh -c "echo add > /sys/class/fc/fc_udev_device/nvme_discovery" + +[Install] +WantedBy=default.target diff --git a/nvmf-autoconnect/nvmf-connect.target b/nvmf-autoconnect/nvmf-connect.target new file mode 100644 index 0000000..f64a37c --- /dev/null +++ b/nvmf-autoconnect/nvmf-connect.target @@ -0,0 +1,2 @@ +[Unit] +Description=All instances of nvmf-autoconnect daemon diff --git a/nvmf-autoconnect/nvmf-connect at .service b/nvmf-autoconnect/nvmf-connect at .service new file mode 100644 index 0000000..25dca0e --- /dev/null +++ b/nvmf-autoconnect/nvmf-connect at .service @@ -0,0 +1,14 @@ +# +# Unit file used by 70-nvmf-autoconnect.rules. +# + +[Unit] +Description=NVMf auto-connect scan upon nvme discovery controller Events +After=syslog.target +PartOf=nvmf-connect.target +Requires=nvmf-connect.target + +[Service] +Type=simple +Environment="CONNECT_ARGS=%i" +ExecStart=/bin/sh -c "nvme connect-all --quiet `echo -e $CONNECT_ARGS`" -- 2.13.7