Skip to contentSkip to conversation

nvme_fc auto-connect scripts

PATCH New Hannes Reinecke 2 participants 4 messages Apr 30, 2019 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme_fc auto-connect scripts

Here's a set of script to enable FC-NVMe autoconnect, based on the initial posting from James Smart.
FC-NVMe already generates an uevent whenever a new FC-NVMe remote port is registered, so we can create an udev rule to parse this event and start connecting to it.

The problem here is that the 'nvme connect-all' call might be taking some time or might even stall altogether, so we cannot call it directly from the udev rule. Rather, the udev rule starts a systemd service, which then calls 'nvme connect-all' as a 'simple' service. With this approach we are insulated from any stalls in udev rules. Additionally we can implement a boot service to restart any missed connections attempts.

To stop autoconnect an additional nvmefc-connect.target has been added, which will instruct systemd to cancel all outstanding autoconnect services.

Cc James Smart <james.smart at broadcom.com>
Signed-off-by Simon Schricker <sschricker at suse.com>
Signed-off-by Hannes Reinecke <hare at suse.com>
---
 nvme-fc-autoconnect/70-nvmefc-autoconnect.conf      |  1 +
 nvme-fc-autoconnect/70-nvmefc-autoconnect.rules     |  8 ++++++++
 nvme-fc-autoconnect/nvmefc-boot-connections.service |  9 +++++++++
 nvme-fc-autoconnect/nvmefc-connect.target           |  2 ++
 nvme-fc-autoconnect/nvmefc-connect at .service         | 13 +++++++++++++
 5 files changed, 33 insertions(+)
 create mode 100644 nvme-fc-autoconnect/70-nvmefc-autoconnect.conf
 create mode 100644 nvme-fc-autoconnect/70-nvmefc-autoconnect.rules
 create mode 100644 nvme-fc-autoconnect/nvmefc-boot-connections.service
 create mode 100644 nvme-fc-autoconnect/nvmefc-connect.target
 create mode 100644 nvme-fc-autoconnect/nvmefc-connect at .service
nvme-fc-autoconnect/70-nvmefc-autoconnect.conf new file +1 -0
new file mode 100644
index 0000000..b92d94f
@@ -0,0 +1 @@
+install_items+="/usr/lib/udev/rules.d/70-nvmefc-autoconnect.rules"
nvme-fc-autoconnect/70-nvmefc-autoconnect.rules new file +8 -0
new file mode 100644
index 0000000..aa4f9bf
@@ -0,0 +1,8 @@
+#
+# nvme_fc: udev event to automatically scan (via discovery controller)
+#   new FC nvme remote ports and auto-connect to the subsystems they report.
+#
+
+ACTION=="change", SUBSYSTEM=="fc", ENV{FC_EVENT}=="nvmediscovery", \
+  ENV{NVMEFC_HOST_TRADDR}=="*",  ENV{NVMEFC_TRADDR}=="*", \
+  RUN+="/usr/bin/systemctl --no-block start nvmefc-connect at --host-traddr=$env{NVMEFC_HOST_TRADDR}\\x20--traddr=$env{NVMEFC_TRADDR}.service"
nvme-fc-autoconnect/nvmefc-boot-connections.service new file +9 -0
new file mode 100644
index 0000000..aa35c15
@@ -0,0 +1,9 @@
+[Unit]
+Description=Auto-connect to subsystems on FC-NVME devices during boot
+
+[Service]
+Type=oneshot
+ExecStart=/bin/sh -c "echo add > /sys/class/fc/fc_udev_device/nvme_discovery"
+
+[Install]
+WantedBy=default.target
nvme-fc-autoconnect/nvmefc-connect.target new file +2 -0
new file mode 100644
index 0000000..953c0b7
@@ -0,0 +1,2 @@
+[Unit]
+Description=All instances of nvme-fc-autoconnect daemon
nvme-fc-autoconnect/nvmefc-connect at .service new file +13 -0
new file mode 100644
index 0000000..a8ff271
@@ -0,0 +1,13 @@
+#
+# Unit file used by 70-nvmefc-autoconnect.rules.
+#
+
+[Unit]
+Description=Auto-connect to subsystems on FC-NVME devices
+After=syslog.target
+PartOf=nvmefc-connect.target
+Requires=nvmefc-connect.target
+
+[Service]
+Type=simple
+ExecStart=/bin/sh -c "/usr/sbin/nvme connect-all --transport=fc `/usr/bin/echo -e '%i'`"
Signature · 1 line
2.16.4
maintainer
#1 lore raw

PATCH 1/1 nvme_fc auto-connect scripts

Hannes,

I added these to the discovery log change stuff, which makes nvme-fc-autoconnect service a unified service not just for FC. I thought you had a look at the series.

#2 lore raw

PATCH 1/1 nvme_fc auto-connect scripts

Quoted 5 lines · Sagi Grimberg

Hannes,

I added these to the discovery log change stuff, which makes nvme-fc-autoconnect service a unified service not just for FC. I thought you had a look at the series.

There had been some fixes to it (namely changing it to a 'simple' service instead of 'oneshot', and adding an nvmefc-connect.target to stop all running instances).
So I've just posted it here for completeness; I've found it rather weird sending a patch to a non-merged patchset.
Do feel free to include it in your patchset.

Cheers,

Hannes

Signature · 5 lines
Dr. Hannes Reinecke		   Teamlead Storage & Networking
hare at suse.de			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: Felix Imend?rffer, Mary Higgins, Sri Rasiah
HRB 21284 (AG N?rnberg)
maintainer
#3 lore raw

PATCH 1/1 nvme_fc auto-connect scripts

Quoted 7 lines
Quoted 6 lines

Hannes,

I added these to the discovery log change stuff, which makes nvme-fc-autoconnect service a unified service not just for FC. I thought you had a look at the series.

Quoted 6 lines

There had been some fixes to it (namely changing it to a 'simple' service instead of 'oneshot', and adding an nvmefc-connect.target to stop all running instances).
So I've just posted it here for completeness; I've found it rather weird sending a patch to a non-merged patchset.
Do feel free to include it in your patchset.

Sure, thanks.