From: jsmart2021@gmail.com (James Smart)
Subject: [PATCH rfc 6/6] nvme-cli: nvmf auto-connect scripts
Date: Wed, 10 Jul 2019 16:27:40 -0700 [thread overview]
Message-ID: <20190710232740.26734-7-jsmart2021@gmail.com> (raw)
In-Reply-To: <20190710232740.26734-1-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 <jsmart2021 at gmail.com>
CC: Simon Schricker <sschricker at suse.com>
Reviewed-by: Hannes Reinecke <hare at suse.com>
CC: Sagi Grimberg <sagi at grimberg.me>
---
Added install lines for 70-nvmf-autoconnect.conf and nvmf-connect.target
Revised Makefile to set/use LIBDIR. Hardset to /usr/lib to match the
nvme.spec.in file
Revised nvme.spec.in to use %{_libdir}
Added --quiet option udev scripts that specify nvme connect-all args
---
Makefile | 16 ++++++++++++++--
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, 67 insertions(+), 2 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 ebb6b75..0389497 100644
--- a/Makefile
+++ b/Makefile
@@ -8,6 +8,10 @@ DESTDIR =
PREFIX ?= /usr/local
SYSCONFDIR = /etc
SBINDIR = $(PREFIX)/sbin
+LIBDIR ?= /usr/lib
+SYSTEMDDIR ?= $(LIBDIR)/systemd
+UDEVDIR ?= $(LIBDIR)/udev
+DRACUTDIR ?= $(LIBDIR)/dracut
LIB_DEPENDS =
ifeq ($(LIBUUID),0)
@@ -87,6 +91,14 @@ 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-udev:
+ $(INSTALL) -d $(DESTDIR)$(SYSTEMDDIR)/system
+ $(INSTALL) -m 644 ./nvmf-autoconnect/*.service ./nvmf-autoconnect/*.target $(DESTDIR)$(SYSTEMDDIR)/system
+ $(INSTALL) -d $(DESTDIR)$(UDEVDIR)/rules.d
+ $(INSTALL) -m 644 ./nvmf-autoconnect/*.rules $(DESTDIR)$(UDEVDIR)/rules.d
+ $(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
@@ -107,7 +119,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-udev
install: install-spec install-hostparams
nvme.spec: nvme.spec.in NVME-VERSION-FILE
@@ -175,7 +187,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..1286e58 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
+ udevadm control --reload-rules && udevadm trigger
+ systemctl daemon-reload
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..b241b12
--- /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_CTLR_NAME}=="*", ENV{NVME_TRTYPE}=="*", ENV{NVME_TRADDR}=="*", \
+ ENV{NVME_TRSVCID}=="*", ENV{NVME_HOST_TRADDR}=="*", \
+ RUN+="/usr/bin/systemctl --no-block start nvmf-connect at --quiet\t--device=$env{NVME_CTLR_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 --quiet\t--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..7d9f856
--- /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 "/usr/sbin/nvme connect-all `/usr/bin/echo -e $CONNECT_ARGS`"
--
2.13.7
next prev parent reply other threads:[~2019-07-10 23:27 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-10 23:27 [PATCH rfc 0/6] nvme-cli: nvmf auto-connect scripts James Smart
2019-07-10 23:27 ` [PATCH rfc 1/6] nvme-cli: ignore arguments that pass in "none" James Smart
2019-07-11 12:28 ` Minwoo Im
2019-07-10 23:27 ` [PATCH rfc 2/6] nvme-cli: support persistent connections to a discovery controller James Smart
2019-07-11 12:33 ` Minwoo Im
2019-07-10 23:27 ` [PATCH rfc 3/6] nvme-cli: allow discover to address discovery controller by persistent name James Smart
2019-07-11 12:41 ` Minwoo Im
2019-07-11 16:16 ` James Smart
2019-07-11 17:11 ` Minwoo Im
2019-07-10 23:27 ` [PATCH rfc 4/6] nvme-cli: expand --device argument processing James Smart
2019-07-11 0:43 ` Sagi Grimberg
2019-07-11 23:54 ` Sagi Grimberg
2019-07-10 23:27 ` [PATCH rfc 5/6] nvme-cli: add --quiet option James Smart
2019-07-11 12:53 ` Minwoo Im
2019-07-10 23:27 ` James Smart [this message]
2019-07-11 0:42 ` [PATCH rfc 6/6] nvme-cli: nvmf auto-connect scripts Sagi Grimberg
2019-07-11 16:18 ` James Smart
2019-07-11 23:47 ` Sagi Grimberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190710232740.26734-7-jsmart2021@gmail.com \
--to=jsmart2021@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox