diff mbox series

discover: Rescan SCSI devices on reinit

Message ID 20180530053645.9483-1-sam@mendozajonas.com
State Accepted
Headers show
Series discover: Rescan SCSI devices on reinit | expand

Commit Message

samjonas May 30, 2018, 5:36 a.m. UTC
Explicitly rescan SCSI devices on reinit rather than just remounting
them in case a device did not init properly on boot.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
---
 configure.ac              | 1 +
 discover/device-handler.c | 3 +++
 lib/system/system.c       | 1 +
 lib/system/system.h       | 1 +
 utils/Makefile.am         | 3 ++-
 utils/scsi-rescan         | 5 +++++
 6 files changed, 13 insertions(+), 1 deletion(-)
 create mode 100755 utils/scsi-rescan
diff mbox series

Patch

diff --git a/configure.ac b/configure.ac
index bdd7f70..9eb0855 100644
--- a/configure.ac
+++ b/configure.ac
@@ -343,6 +343,7 @@  DEFINE_HOST_PROG(VGCHANGE, vgchange, [/usr/sbin/vgchange])
 DEFINE_HOST_PROG(PB_PLUGIN, pb-plugin, [/usr/sbin/pb-plugin])
 DEFINE_HOST_PROG(PB_EXEC, pb-exec, [/usr/sbin/pb-exec])
 DEFINE_HOST_PROG(SH, sh, [/bin/sh])
+DEFINE_HOST_PROG(SCSI_RESCAN, scsi-rescan, [/usr/sbin/scsi-rescan])
 
 AC_ARG_WITH(
     [tftp],
diff --git a/discover/device-handler.c b/discover/device-handler.c
index 569e652..aa61bd2 100644
--- a/discover/device-handler.c
+++ b/discover/device-handler.c
@@ -451,6 +451,9 @@  void device_handler_reinit(struct device_handler *handler)
 		discover_server_notify_config(handler->server, config);
 	}
 
+	/* Force rediscovery on SCSI devices */
+	process_run_simple(handler, pb_system_apps.scsi_rescan, NULL);
+
 	device_handler_reinit_sources(handler);
 }
 
diff --git a/lib/system/system.c b/lib/system/system.c
index b1121a1..6dafcb0 100644
--- a/lib/system/system.c
+++ b/lib/system/system.c
@@ -33,6 +33,7 @@  const struct pb_system_apps pb_system_apps = {
 	.pb_plugin	= HOST_PROG_PB_PLUGIN,
 	.pb_exec	= HOST_PROG_PB_EXEC,
 	.sh		= HOST_PROG_SH,
+	.scsi_rescan	= HOST_PROG_SCSI_RESCAN,
 };
 
 #ifndef TFTP_TYPE
diff --git a/lib/system/system.h b/lib/system/system.h
index d27c2cd..38fe392 100644
--- a/lib/system/system.h
+++ b/lib/system/system.h
@@ -18,6 +18,7 @@  struct pb_system_apps {
 	const char *pb_plugin;
 	const char *pb_exec;
 	const char *sh;
+	const char *scsi_rescan;
 };
 
 extern const struct pb_system_apps pb_system_apps;
diff --git a/utils/Makefile.am b/utils/Makefile.am
index c9015a0..a523430 100644
--- a/utils/Makefile.am
+++ b/utils/Makefile.am
@@ -12,7 +12,8 @@ 
 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #
 
-dist_sbin_SCRIPTS += utils/pb-udhcpc utils/pb-plugin utils/pb-sos utils/pb-exec
+dist_sbin_SCRIPTS += utils/pb-udhcpc utils/pb-plugin utils/pb-sos \
+		     utils/pb-exec utils/scsi-rescan
 dist_pkglibexec_SCRIPTS = utils/pb-console
 sbin_PROGRAMS += utils/pb-event utils/pb-config
 
diff --git a/utils/scsi-rescan b/utils/scsi-rescan
new file mode 100755
index 0000000..1d1cb1b
--- /dev/null
+++ b/utils/scsi-rescan
@@ -0,0 +1,5 @@ 
+#/bin/sh
+
+for host in /sys/class/scsi_host/host*; do
+	echo "- - -" > ${host}/scan
+done