If the iprinit daemon runs prior to the sg module being loaded, it is not able to talk to the ipr adapters and do much of anything that is useful. This was observed on a system where the adapter write cache was not getting enabled at times during boot. This modifies iprinit to check to see if the sg module is loaded and also checks to see if its actually been bound to each ipr adapter yet. If not, it makes iprinit wait for a bit until this happens. Some distros load sg via a udev rule which can happen in parallel to iprinit starting, so this fixes this race. It also adds some informational logging to make it easier to track when this indeed does occur in case a system never loads the sg driver.
Signed-off-by: Brian King <brk...@linux.vnet.ibm.com> --- iprconfig.c | 19 ------------------- iprinit.c | 44 ++++++++++++++++++++++++++++++++++++++------ iprlib.c | 22 ++++++++++++++++++++-- iprlib.h | 1 + 4 files changed, 59 insertions(+), 27 deletions(-) diff -puN iprconfig.c~iprutils_wait_for_sg_iprinit iprconfig.c --- iprutils.patched/iprconfig.c~iprutils_wait_for_sg_iprinit 2016-10-24 13:58:07.889789822 -0500 +++ iprutils.patched-bjking1/iprconfig.c 2016-10-25 13:46:29.186586829 -0500 @@ -19421,25 +19421,6 @@ static int non_intenactive_cmd(char *cmd return -EINVAL; } -int check_sg_module() -{ - DIR *sg_dirfd; - char devpath[PATH_MAX]; - - sprintf(devpath, "%s", "/sys/module/sg"); - - sg_dirfd = opendir(devpath); - - if (!sg_dirfd) { - syslog_dbg("Failed to open sg parameter.\n"); - return -1; - } - - closedir(sg_dirfd); - - return 0; -} - void list_options() { int i; diff -puN iprlib.c~iprutils_wait_for_sg_iprinit iprlib.c --- iprutils.patched/iprlib.c~iprutils_wait_for_sg_iprinit 2016-10-24 13:58:07.893789808 -0500 +++ iprutils.patched-bjking1/iprlib.c 2016-10-25 13:46:29.372586051 -0500 @@ -6571,8 +6571,8 @@ void check_current_config(bool allow_reb int *qac_entry_ref; struct ipr_dev_identify_vpd di_vpd; char *pchr; - struct ipr_mode_pages mode_pages; - struct ipr_ioa_mode_page *page; + struct ipr_mode_pages mode_pages; + struct ipr_ioa_mode_page *page; if (ipr_qac_data == NULL) { ipr_qac_data = @@ -10362,3 +10362,21 @@ int ipr_jbod_sysfs_bind(struct ipr_dev * return 0; } +int check_sg_module() +{ + DIR *sg_dirfd; + char devpath[PATH_MAX]; + + sprintf(devpath, "%s", "/sys/module/sg"); + + sg_dirfd = opendir(devpath); + + if (!sg_dirfd) { + syslog_dbg("Failed to open sg parameter.\n"); + return -1; + } + + closedir(sg_dirfd); + + return 0; +} diff -puN iprlib.h~iprutils_wait_for_sg_iprinit iprlib.h --- iprutils.patched/iprlib.h~iprutils_wait_for_sg_iprinit 2016-10-24 13:58:07.896789798 -0500 +++ iprutils.patched-bjking1/iprlib.h 2016-10-25 13:46:29.190586813 -0500 @@ -2960,6 +2960,7 @@ int get_scsi_dev_data(struct scsi_dev_da int ipr_device_lock(struct ipr_dev *dev); void ipr_device_unlock(struct ipr_dev *dev); +int check_sg_module(); static inline u32 ipr_get_dev_res_handle(struct ipr_ioa *ioa, struct ipr_dev_record *dev_rcd) { diff -puN iprinit.c~iprutils_wait_for_sg_iprinit iprinit.c --- iprutils.patched/iprinit.c~iprutils_wait_for_sg_iprinit 2016-10-24 13:58:07.899789788 -0500 +++ iprutils.patched-bjking1/iprinit.c 2016-10-24 13:58:07.912789743 -0500 @@ -27,7 +27,7 @@ char *tool_name = "iprinit"; -static void init_all() +static int init_all() { struct ipr_ioa *ioa; int rc = tool_init(1); @@ -39,8 +39,12 @@ static void init_all() syslog(LOG_ERR, "Error initializing adapters. Perhaps run with sudo?\n"); } check_current_config(false); - for_each_ioa(ioa) + for_each_ioa(ioa) { + if (!strlen(ioa->ioa.gen_name)) + rc |= -EAGAIN; ipr_init_ioa(ioa); + } + return rc; } static void kevent_handler(char *buf) @@ -65,7 +69,7 @@ static void poll_ioas() int main(int argc, char *argv[]) { - int i; + int i, rc, delay_secs, wait; ipr_sg_required = 1; @@ -81,12 +85,40 @@ int main(int argc, char *argv[]) } } - init_all(); + rc = check_sg_module(); if (daemonize) { ipr_daemonize(); + + if (!rc) + rc = init_all(); + + if (rc) { + syslog(LOG_INFO, "Waiting for ipr adapters and sg module to come ready.\n"); + + delay_secs = 2; + sleep(delay_secs); + + for (wait = 0; rc && wait < 300; wait += delay_secs) { + rc = check_sg_module(); + sleep(delay_secs); + if (!rc) + rc = init_all(); + } + + if (rc) + syslog(LOG_ERR, "Timeout reached. Ensure the sg module is loaded, then " + "run iprinit manually to ensure all " + "ipr RAID adapters are running optimally\n"); + } return handle_events(poll_ioas, 60, kevent_handler); - } + } else if (!rc) + rc = init_all(); + + if (rc) + syslog(LOG_ERR, "iprinit failed. Ensure the sg module is loaded, then " + "run iprinit again to ensure all " + "ipr RAID adapters are running optimally\n"); - return 0; + return rc; } _ ------------------------------------------------------------------------------ The Command Line: Reinvented for Modern Developers Did the resurgence of CLI tooling catch you by surprise? Reconnect with the command line and become more productive. Learn the new .NET and ASP.NET CLI. Get your free copy! http://sdm.link/telerik _______________________________________________ Iprdd-devel mailing list Iprdd-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/iprdd-devel