changeset 11097:1dfc844e3407

6897038 SRP service goes into maintenance state when no HCAs are present
author Sue Gleeson <Susan.Gleeson@Sun.COM>
date Wed, 18 Nov 2009 19:17:27 -0500
parents 1f03915dd9c3
children 9f8e731abeb0
files usr/src/cmd/srptsvc/srptsvc.c usr/src/uts/common/io/comstar/port/srpt/srpt_ioc.c usr/src/uts/common/io/comstar/port/srpt/srpt_mod.c usr/src/uts/common/io/ib/mgt/ibdma/ibdma.c
diffstat 4 files changed, 38 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/srptsvc/srptsvc.c	Wed Nov 18 22:01:33 2009 -0800
+++ b/usr/src/cmd/srptsvc/srptsvc.c	Wed Nov 18 19:17:27 2009 -0500
@@ -32,6 +32,7 @@
 #include <errno.h>
 #include <unistd.h>
 #include <strings.h>
+#include <libscf.h>	/* for SMF error exit codes */
 
 #include <srpt_ioctl.h>
 
@@ -48,6 +49,7 @@
 	int		fd = -1;
 	int		saverr;
 	char		*txt;
+	struct stat	statbuf;
 
 	(void) setlocale(LC_ALL, "");
 
@@ -68,17 +70,27 @@
 	if (fd < 0) {
 		saverr = errno;
 
-		(void) fprintf(stderr, "%s: %s", cmdName,
-		    gettext("Could not open SRP Target pseudodevice."));
+		(void) fprintf(stderr, "%s: %s (%s): %s\n", cmdName,
+		    gettext("Could not open SRP Target pseudodevice"),
+		    SRPT_NODE, strerror(saverr));
 
 		if (saverr == ENOENT) {
-			(void) fprintf(stderr,
-			    gettext("  Driver may not be loaded."));
+			/* avoid having the service go into maintenance */
+			if ((stat("/devices/ib", &statbuf)) != 0) {
+				(void) fprintf(stderr, "%s: %s\n", cmdName,
+				    gettext(
+				    "No InfiniBand devices on this system."));
+			}
+			ret = 0;
+
 		} else {
-			(void) fprintf(stderr, gettext("  error = %d"), saverr);
+			ret = SMF_EXIT_ERR_FATAL; /* avoid retries */
 		}
-		(void) fprintf(stderr, "\n");
-		return (1);
+
+		(void) fprintf(stderr, "%s: %s\n", cmdName,
+		    gettext("SRPT Driver may not be loaded."));
+
+		return (ret);
 	}
 
 	ret = ioctl(fd, srpt_ioctl, NULL);
@@ -90,7 +102,7 @@
 		}
 
 		(void) fprintf(stderr, "%s: %d", txt, ret);
-		ret = 1;
+		ret = SMF_EXIT_ERR_FATAL;
 	}
 
 	(void) close(fd);
--- a/usr/src/uts/common/io/comstar/port/srpt/srpt_ioc.c	Wed Nov 18 22:01:33 2009 -0800
+++ b/usr/src/uts/common/io/comstar/port/srpt/srpt_ioc.c	Wed Nov 18 19:17:27 2009 -0500
@@ -161,15 +161,14 @@
 
 	hca_cnt = ibt_get_hca_list(&guid);
 	if (hca_cnt < 1) {
+		/*
+		 * not a fatal error.  Service will be up and
+		 * waiting for ATTACH events.
+		 */
 		SRPT_DPRINTF_L2("ioc_attach, no HCA found");
-		(void) ibt_detach(srpt_ctxt->sc_ibt_hdl);
-		srpt_ctxt->sc_ibt_hdl = NULL;
-		return (DDI_FAILURE);
+		return (DDI_SUCCESS);
 	}
 
-	list_create(&srpt_ctxt->sc_ioc_list, sizeof (srpt_ioc_t),
-	    offsetof(srpt_ioc_t, ioc_node));
-
 	for (hca_ndx = 0; hca_ndx < hca_cnt; hca_ndx++) {
 		SRPT_DPRINTF_L2("ioc_attach, adding I/O"
 		    " Controller (%016llx)", (u_longlong_t)guid[hca_ndx]);
@@ -214,8 +213,6 @@
 		srpt_ioc_fini(ioc);
 	}
 
-	list_destroy(&srpt_ctxt->sc_ioc_list);
-
 	(void) ibt_detach(srpt_ctxt->sc_ibt_hdl);
 	srpt_ctxt->sc_ibt_hdl = NULL;
 }
--- a/usr/src/uts/common/io/comstar/port/srpt/srpt_mod.c	Wed Nov 18 22:01:33 2009 -0800
+++ b/usr/src/uts/common/io/comstar/port/srpt/srpt_mod.c	Wed Nov 18 19:17:27 2009 -0500
@@ -158,6 +158,9 @@
 	/* Start-up state is DISABLED.  SMF will tell us if we should enable. */
 	srpt_ctxt->sc_svc_state = SRPT_SVC_DISABLED;
 
+	list_create(&srpt_ctxt->sc_ioc_list, sizeof (srpt_ioc_t),
+	    offsetof(srpt_ioc_t, ioc_node));
+
 	status = mod_install(&srpt_modlinkage);
 	if (status != DDI_SUCCESS) {
 		cmn_err(CE_CONT, "_init, failed mod_install %d", status);
@@ -191,6 +194,8 @@
 		return (status);
 	}
 
+	list_destroy(&srpt_ctxt->sc_ioc_list);
+
 	rw_destroy(&srpt_ctxt->sc_rwlock);
 	kmem_free(srpt_ctxt, sizeof (srpt_ctxt_t));
 	srpt_ctxt = NULL;
@@ -309,10 +314,10 @@
 		goto err_exit_2;
 	}
 
+	/* Not an error if no iocs yet; we will listen for ATTACH events */
 	if (srpt_ctxt->sc_num_iocs == 0) {
 		SRPT_DPRINTF_L2("enable_srp: no IB I/O Controllers found");
-		status = DDI_FAILURE;
-		goto err_exit_3;
+		return (DDI_SUCCESS);
 	}
 
 	/*
@@ -337,9 +342,6 @@
 
 	return (DDI_SUCCESS);
 
-err_exit_3:
-	srpt_ioc_detach();
-
 err_exit_2:
 	(void) stmf_deregister_port_provider(srpt_ctxt->sc_pp);
 
--- a/usr/src/uts/common/io/ib/mgt/ibdma/ibdma.c	Wed Nov 18 22:01:33 2009 -0800
+++ b/usr/src/uts/common/io/ib/mgt/ibdma/ibdma.c	Wed Nov 18 19:17:27 2009 -0500
@@ -298,18 +298,18 @@
 		return (status);
 	}
 
+	list_create(&ibdma->ms_hca_list, sizeof (ibdma_hca_t),
+	    offsetof(ibdma_hca_t, ih_node));
+
 	hca_cnt = ibt_get_hca_list(&guid);
 	if (hca_cnt < 1) {
 #ifdef	DEBUG_IBDMA
 		cmn_err(CE_NOTE, "ibt_init, no HCA(s) found");
 #endif
-		(void) ibt_detach(ibdma->ms_ibt_hdl);
-		return (DDI_FAILURE);
+		/* not an error if no HCAs, but nothing more to do here */
+		return (DDI_SUCCESS);
 	}
 
-	list_create(&ibdma->ms_hca_list, sizeof (ibdma_hca_t),
-	    offsetof(ibdma_hca_t, ih_node));
-
 	mutex_enter(&ibdma->ms_hca_list_lock);
 
 	for (hca_ndx = 0; hca_ndx < hca_cnt; hca_ndx++) {
@@ -364,7 +364,7 @@
 	}
 	list_destroy(&ibdma->ms_hca_list);
 
-	ibt_detach(ibdma->ms_ibt_hdl);
+	(void) ibt_detach(ibdma->ms_ibt_hdl);
 	ibdma->ms_ibt_hdl   = NULL;
 	ibdma->ms_num_hcas  = 0;
 	mutex_exit(&ibdma->ms_hca_list_lock);