From: Hannes Reinecke <hare@suse.de>
To: Laurence Oberman <loberman@redhat.com>
Cc: Bart Van Assche <bart.vanassche@sandisk.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
Christoph Hellwig <hch@lst.de>,
James Bottomley <james.bottomley@hansenpartnership.com>,
linux-scsi@vger.kernel.org
Subject: Re: [PATCHv3] scsi: disable automatic target scan
Date: Tue, 22 Mar 2016 18:36:03 +0100 [thread overview]
Message-ID: <56F18283.2000000@suse.de> (raw)
In-Reply-To: <1709049972.24310562.1458592857261.JavaMail.zimbra@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 1543 bytes --]
On 03/21/2016 09:40 PM, Laurence Oberman wrote:
> Hello Hannes
>
> Please share latest scripts and an example of how you are using them.
> I have some scripts from last November, that you posted but I am sure they have changed.
> If not then I will modify them as appropriate, just let me know.
>
> I have added the patches and booted the system set to async, so before I boot with
> scsi_mod.scan=manual want to prepare my test system.
> This feature may be a very useful feature we would want to include in RHEL as we
> struggle with large LUN boot configurations all the time.
Oh, really? Hardly a surprise.
In fact, I'm constantly surprised that RHEL ships with systemd
enabled, apparently without any issues.
Especially in large machines.
As we found to our dismay; I spent about a year to get things
running smoothly.
Or, to be precise, running at all.
Anyway.
Attached is the original patch to dracut; please check if it's the
correct version (I've changed the 'disabled' to 'manual' for
upstream submission).
I haven't included the systemd service; that's actually quite
trivial: reset the scan mode (as it's now writeable) and call
rescan-scsi-bus.sh or equivalent.
But please add a 'Tested-by' or equivalent to the upstream patch, to
add a bit more urgency to it.
Cheers,
Hannes
--
Dr. Hannes Reinecke Teamlead Storage & Networking
hare@suse.de +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-95lunmask-Add-module-to-handle-LUN-masking.patch --]
[-- Type: text/x-patch; name="0001-95lunmask-Add-module-to-handle-LUN-masking.patch", Size: 6857 bytes --]
From 1d427bcf3527ba96828a4bd5231409967ff096b4 Mon Sep 17 00:00:00 2001
From: Hannes Reinecke <hare@suse.de>
Date: Wed, 11 Nov 2015 12:20:33 +0100
Subject: [PATCH] 95lunmask: Add module to handle LUN masking
Using the module option 'scsi_mod.scan=disabled'
this implements LUN masking by selectively enable only those
devices required for booting.
References: bsc#954600
Signed-off-by: Hannes Reinecke <hare@suse.de>
---
modules.d/95lunmask/fc_transport_scan_lun.sh | 26 ++++++++++
modules.d/95lunmask/module-setup.sh | 70 +++++++++++++++++++++++++++
modules.d/95lunmask/parse-lunmask.sh | 40 +++++++++++++++
modules.d/95lunmask/sas_transport_scan_lun.sh | 26 ++++++++++
4 files changed, 162 insertions(+)
create mode 100755 modules.d/95lunmask/fc_transport_scan_lun.sh
create mode 100755 modules.d/95lunmask/module-setup.sh
create mode 100755 modules.d/95lunmask/parse-lunmask.sh
create mode 100755 modules.d/95lunmask/sas_transport_scan_lun.sh
diff --git a/modules.d/95lunmask/fc_transport_scan_lun.sh b/modules.d/95lunmask/fc_transport_scan_lun.sh
new file mode 100755
index 0000000..d9f84a3
--- /dev/null
+++ b/modules.d/95lunmask/fc_transport_scan_lun.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+#
+# fc_transport_lun_scan
+#
+# Selectively enable individual LUNs behind an FC remote port
+#
+# ACTION=="add", SUBSYSTEM=="fc_transport", ATTR{port_name}=="wwpn", \
+# PROGRAM="fc_transport_lun_scan lun"
+#
+
+[ -z $DEVPATH ] && exit 1
+
+if [ -n "$1" ] ; then
+ LUN=$1
+else
+ LUN=-
+fi
+ID=${DEVPATH##*/rport-}
+HOST=${ID%%:*}
+CHANNEL=${ID%%-*}
+CHANNEL=${CHANNEL#*:}
+if [ -f /sys$DEVPATH/scsi_target_id ] ; then
+ TARGET=$(cat /sys$DEVPATH/scsi_target_id)
+fi
+[ -z "$TARGET" ] && exit 1
+echo $CHANNEL $TARGET $LUN > /sys/class/scsi_host/host$HOST/scan
diff --git a/modules.d/95lunmask/module-setup.sh b/modules.d/95lunmask/module-setup.sh
new file mode 100755
index 0000000..c88b1c0
--- /dev/null
+++ b/modules.d/95lunmask/module-setup.sh
@@ -0,0 +1,70 @@
+#!/bin/bash
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
+# ex: ts=8 sw=4 sts=4 et filetype=sh
+
+# called by dracut
+cmdline() {
+ get_lunmask() {
+ local _dev=$1
+ local _devpath=$(cd -P /sys/dev/block/$_dev ; echo $PWD)
+ local _sdev _lun _rport _end_device _classdev _wwpn _sas_address
+
+ [ "${_devpath#*/sd}" == "$_devpath" ] && return 1
+ _sdev="${_devpath%%/block/*}"
+ _lun="${_sdev##*:}"
+ # Check for FibreChannel
+ _rport="${_devpath##*/rport-}"
+ if [ "$_rport" != "$_devpath" ] ; then
+ _rport="${_rport%%/*}"
+ _classdev="/sys/class/fc_remote_ports/rport-${_rport}"
+ [ -d "$_classdev" ] || return 1
+ _wwpn=$(cat ${_classdev}/port_name)
+ echo "rd.lunmask=fc,${_wwpn},${_lun}"
+ return 0
+ fi
+ # Check for SAS
+ _end_device="${_devpath##*/end_device-}"
+ if [ "$_end_device" != "$_devpath" ] ; then
+ _end_device="${_end_device%%/*}"
+ _classdev="/sys/class/sas_device/end_device-${_end_device}"
+ [ -e "$_classdev" ] || return 1
+ _sas_address=$(cat ${_classdev}/sas_address)
+ echo "rd.lunmask=sas,${_sas_address},${_lun}"
+ return 0
+ fi
+ return 1
+ }
+ [[ $hostonly ]] || [[ $mount_needs ]] && {
+ for_each_host_dev_and_slaves_all get_lunmask
+ } | sort | uniq
+}
+
+# called by dracut
+check() {
+ [[ $hostonly ]] || [[ $mount_needs ]] && {
+ [ -w /sys/module/scsi_mod/parameters/scan ] || return 255
+ scan_type=$(cat /sys/module/scsi_mod/parameters/scan)
+ [ "$scan_type" = "disabled" ] && return 0
+ return 255
+ }
+ return 0
+}
+
+# called by dracut
+depends() {
+ return 0
+}
+
+# called by dracut
+install() {
+ inst_script "$moddir/fc_transport_scan_lun.sh" /usr/lib/udev/fc_transport_scan_lun.sh
+ inst_script "$moddir/sas_transport_scan_lun.sh" /usr/lib/udev/sas_transport_scan_lun.sh
+ inst_hook cmdline 30 "$moddir/parse-lunmask.sh"
+ if [[ $hostonly_cmdline == "yes" ]] ; then
+ local _lunmask
+
+ for _lunmask in $(cmdline) ; do
+ printf "%s\n" "$_lunmask" >> "${initdir}/etc/cmdline.d/95lunmask.conf"
+ done
+ fi
+}
diff --git a/modules.d/95lunmask/parse-lunmask.sh b/modules.d/95lunmask/parse-lunmask.sh
new file mode 100755
index 0000000..81dc412
--- /dev/null
+++ b/modules.d/95lunmask/parse-lunmask.sh
@@ -0,0 +1,40 @@
+#!/bin/sh
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
+# ex: ts=8 sw=4 sts=4 et filetype=sh
+
+create_udev_rule() {
+ local transport=$1
+ local tgtid=$2
+ local lun=$3
+ local _rule=/etc/udev/rules.d/51-${transport}-lunmask-${tgtid}.rules
+ local _cu_type _dev_type
+
+ [ -e ${_rule} ] && return 0
+
+ if [ ! -f "$_rule" ] ; then
+ if [ "$transport" = "fc" ] ; then
+ cat > $_rule <<EOF
+ACTION=="add", SUBSYSTEM=="fc_remote_ports", ATTR{port_name}=="$tgtid", PROGRAM="fc_transport_scan_lun.sh $lun"
+EOF
+ elif [ "$transport" = "sas" ] ; then
+ cat > $_rule <<EOF
+ACTION=="add", SUBSYSTEM=="sas_device", ATTR{sas_address}=="$tgtid", PROGRAM="sas_transport_scan_lun.sh $lun"
+EOF
+ fi
+ fi
+}
+
+for lunmask_arg in $(getargs rd.lunmask); do
+ (
+ local OLDIFS="$IFS"
+ local IFS=","
+ set $lunmask_arg
+ IFS="$OLDIFS"
+ if [ -d /sys/module/scsi_mod ] ; then
+ echo -n "disabled" > /sys/module/scsi_mod/parameters/scan
+ elif [ ! -f /etc/modprobe.d/95lunmask.conf ] ; then
+ echo "options scsi_mod scan=disabled" > /etc/modprobe.d/95lunmask.conf
+ fi
+ create_udev_rule $1 $2 $3
+ )
+done
diff --git a/modules.d/95lunmask/sas_transport_scan_lun.sh b/modules.d/95lunmask/sas_transport_scan_lun.sh
new file mode 100755
index 0000000..f7702f8
--- /dev/null
+++ b/modules.d/95lunmask/sas_transport_scan_lun.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+#
+# sas_transport_lun_scan
+#
+# Selectively enable individual LUNs behind a SAS end device
+#
+# ACTION=="add", SUBSYSTEM=="sas_transport", ATTR{sas_address}=="sas_addr", \
+# PROGRAM="sas_transport_lun_scan lun"
+#
+
+[ -z $DEVPATH ] && exit 1
+
+if [ -n "$1" ] ; then
+ LUN=$1
+else
+ LUN=-
+fi
+ID=${DEVPATH##*/end_device-}
+HOST=${ID%%:*}
+CHANNEL=${ID%%-*}
+CHANNEL=${CHANNEL#*:}
+if [ -f /sys$DEVPATH/scsi_target_id ] ; then
+ TARGET=$(cat /sys$DEVPATH/scsi_target_id)
+fi
+[ -z "$TARGET" ] && exit 1
+echo 0 $TARGET $LUN > /sys/class/scsi_host/host$HOST/scan
--
2.6.2
next prev parent reply other threads:[~2016-03-22 17:36 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-17 7:39 [PATCHv3] scsi: disable automatic target scan Hannes Reinecke
2016-03-18 19:39 ` Ewan D. Milne
2016-03-18 21:56 ` Bart Van Assche
2016-03-19 15:18 ` Hannes Reinecke
2016-03-19 15:29 ` Laurence Oberman
2016-03-21 1:24 ` Bart Van Assche
2016-03-21 7:15 ` Hannes Reinecke
2016-03-21 20:40 ` Laurence Oberman
2016-03-22 17:36 ` Hannes Reinecke [this message]
2016-03-24 2:35 ` Laurence Oberman
2016-03-29 0:27 ` Martin K. Petersen
2016-03-30 19:41 ` Benjamin Block
2016-04-01 7:29 ` Hannes Reinecke
2016-04-05 12:20 ` Benjamin Block
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=56F18283.2000000@suse.de \
--to=hare@suse.de \
--cc=bart.vanassche@sandisk.com \
--cc=hch@lst.de \
--cc=james.bottomley@hansenpartnership.com \
--cc=linux-scsi@vger.kernel.org \
--cc=loberman@redhat.com \
--cc=martin.petersen@oracle.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;
as well as URLs for NNTP newsgroup(s).