From 3a8b44ea46a52b85aa807cd44aca2b4340f9e59d Mon Sep 17 00:00:00 2001 From: thomas Date: Fri, 9 Nov 2018 15:00:23 +0100 Subject: [PATCH] mxraid/mxraid_assemble: Wait if enclosures start slowly Sometimes the disks in a enclosure are registered a bit lately, so check if there is some dynamic (count of disks), and if so -- just wait a little longer. Note: this was only observed once 'in the wild', and the required delay would have been in the range of 50ms. --- mxraid/mxraid_assemble | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/mxraid/mxraid_assemble b/mxraid/mxraid_assemble index 03b5f40..54bb440 100755 --- a/mxraid/mxraid_assemble +++ b/mxraid/mxraid_assemble @@ -6,6 +6,8 @@ use Data::Dumper; $Data::Dumper::Sortkeys=1; use Getopt::Std; $Getopt::Std::STANDARD_HELP_VERSION=1; sub HELP_MESSAGE{} sub VERSION_MESSAGE{} +use Sys::Syslog; +use Time::HiRes qw(usleep); import MxRaid::ConfData; import MxRaid::HostData; @@ -60,6 +62,22 @@ sub exec_version { exit 0; } +sub check_enclosures { + glob('/sys/class/enclosure/*') or return; + + my $cnt_0 = () = (glob('/sys/block/sd[a-z]'), glob('/sys/block/sd[a-z][a-z]')); + usleep(0.3 * 1e6); + my $cnt_1 = () = (glob('/sys/block/sd[a-z]'), glob('/sys/block/sd[a-z][a-z]')); + + if ( $cnt_0 != $cnt_1 ) { # then something still 'evolves', shout around and take a nap. + my ($prog) = $0 =~ m|([^/]+)$|; + openlog($prog,'pid','user'); + Sys::Syslog::setlogsock('unix'); # with 'native' we get EOLs in the logfile, option "noeol" doesn't work + syslog('info', 'still discovering disks, diff is %d. Waiting 3 seconds ...', $cnt_1 - $cnt_0); + sleep 3; + } +} + my $ROOT=$<==0?1:0; my %opts; @@ -88,6 +106,7 @@ my $MDADM_CONF_BASE = '/dev/shm/mdadm.conf'; # config for mdadm, created with in my $MDADM_ASSEMBLE_OPTIONS = ''; my $cd = MxRaid::ConfData->new($MDADMCONF_DB); $cd->verbose($VERBOSE); $cd->load(); +check_enclosures(); # idle a bit if enclosures are attached ... my $hd = MxRaid::HostData->new($cd); $hd->verbose($VERBOSE); my $utils = MxRaid::Utils->new();