Module Name:    src
Committed By:   pgoyette
Date:           Mon Jun  7 01:41:40 UTC 2010

Modified Files:
        src/sys/dev/scsipi: atapiconf.c scsiconf.c scsipi_base.c
            scsipi_verbose.c scsipiconf.c scsipiconf.h

Log Message:
Update scsiverbose module to use module_autoload() rather than module_load().
Load the module right before each attempt to use its features, and let the
module subsystem handle unloading.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/sys/dev/scsipi/atapiconf.c
cvs rdiff -u -r1.257 -r1.258 src/sys/dev/scsipi/scsiconf.c
cvs rdiff -u -r1.152 -r1.153 src/sys/dev/scsipi/scsipi_base.c
cvs rdiff -u -r1.30 -r1.31 src/sys/dev/scsipi/scsipi_verbose.c
cvs rdiff -u -r1.37 -r1.38 src/sys/dev/scsipi/scsipiconf.c
cvs rdiff -u -r1.117 -r1.118 src/sys/dev/scsipi/scsipiconf.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/atapiconf.c
diff -u src/sys/dev/scsipi/atapiconf.c:1.82 src/sys/dev/scsipi/atapiconf.c:1.83
--- src/sys/dev/scsipi/atapiconf.c:1.82	Sun May 30 04:38:04 2010
+++ src/sys/dev/scsipi/atapiconf.c	Mon Jun  7 01:41:39 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: atapiconf.c,v 1.82 2010/05/30 04:38:04 pgoyette Exp $	*/
+/*	$NetBSD: atapiconf.c,v 1.83 2010/06/07 01:41:39 pgoyette Exp $	*/
 
 /*
  * Copyright (c) 1996, 2001 Manuel Bouyer.  All rights reserved.
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: atapiconf.c,v 1.82 2010/05/30 04:38:04 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: atapiconf.c,v 1.83 2010/06/07 01:41:39 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -160,7 +160,6 @@
 		aprint_error_dev(self, "couldn't establish power handler\n");
 
 	/* Probe the bus for devices. */
-	scsipi_verbose_ctl(true);
 	atapi_probe_bus(sc, -1);
 }
 
@@ -207,7 +206,6 @@
 			return (error);
 		KASSERT(scsipi_lookup_periph(chan, target, 0) == NULL);
 	}
-	scsipi_verbose_ctl(false);
 	return (0);
 }
 

Index: src/sys/dev/scsipi/scsiconf.c
diff -u src/sys/dev/scsipi/scsiconf.c:1.257 src/sys/dev/scsipi/scsiconf.c:1.258
--- src/sys/dev/scsipi/scsiconf.c:1.257	Sun May 30 04:38:04 2010
+++ src/sys/dev/scsipi/scsiconf.c	Mon Jun  7 01:41:39 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsiconf.c,v 1.257 2010/05/30 04:38:04 pgoyette Exp $	*/
+/*	$NetBSD: scsiconf.c,v 1.258 2010/06/07 01:41:39 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1998, 1999, 2004 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.257 2010/05/30 04:38:04 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.258 2010/06/07 01:41:39 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -182,7 +182,6 @@
 	scsi_initq = malloc(sizeof(struct scsi_initq), M_DEVBUF, M_WAITOK);
 	scsi_initq->sc_channel = chan;
 	TAILQ_INSERT_TAIL(&scsi_initq_head, scsi_initq, scsi_initq);
-	scsipi_verbose_ctl(true);
         config_pending_incr();
 	if (scsipi_channel_init(chan)) {
 		aprint_error_dev(sc->sc_dev, "failed to init channel\n");
@@ -226,7 +225,6 @@
 	simple_lock(&scsibus_interlock);
 	TAILQ_REMOVE(&scsi_initq_head, scsi_initq, scsi_initq);
 	simple_unlock(&scsibus_interlock);
-	scsipi_verbose_ctl(false);
 
 	free(scsi_initq, M_DEVBUF);
 	wakeup(&scsi_initq_head);

Index: src/sys/dev/scsipi/scsipi_base.c
diff -u src/sys/dev/scsipi/scsipi_base.c:1.152 src/sys/dev/scsipi/scsipi_base.c:1.153
--- src/sys/dev/scsipi/scsipi_base.c:1.152	Sun May 30 04:38:04 2010
+++ src/sys/dev/scsipi/scsipi_base.c	Mon Jun  7 01:41:39 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsipi_base.c,v 1.152 2010/05/30 04:38:04 pgoyette Exp $	*/
+/*	$NetBSD: scsipi_base.c,v 1.153 2010/06/07 01:41:39 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2002, 2003, 2004 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: scsipi_base.c,v 1.152 2010/05/30 04:38:04 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsipi_base.c,v 1.153 2010/06/07 01:41:39 pgoyette Exp $");
 
 #include "opt_scsi.h"
 
@@ -47,7 +47,6 @@
 #include <sys/proc.h>
 #include <sys/kthread.h>
 #include <sys/hash.h>
-#include <sys/module.h>
 
 #include <uvm/uvm_extern.h>
 
@@ -83,27 +82,6 @@
 
 static struct pool scsipi_xfer_pool;
 
-/*              
- * Load/unload the scsiverbose module
- */
-void
-scsipi_verbose_ctl(bool load)
-{
-	static int loaded = 0;
- 
-	if (load) {
-		if (loaded++ == 0)
-			if (module_load("scsiverbose", MODCTL_LOAD_FORCE,
-					NULL, MODULE_CLASS_MISC) != 0)
-		loaded = 0;
-		return;
-	}
-	if (loaded == 0)
-		return;
-	if (--loaded == 0)
-		module_unload("scsiverbose");
-} 
-
 /*
  * scsipi_init:
  *

Index: src/sys/dev/scsipi/scsipi_verbose.c
diff -u src/sys/dev/scsipi/scsipi_verbose.c:1.30 src/sys/dev/scsipi/scsipi_verbose.c:1.31
--- src/sys/dev/scsipi/scsipi_verbose.c:1.30	Sun May 30 04:38:04 2010
+++ src/sys/dev/scsipi/scsipi_verbose.c	Mon Jun  7 01:41:39 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsipi_verbose.c,v 1.30 2010/05/30 04:38:04 pgoyette Exp $	*/
+/*	$NetBSD: scsipi_verbose.c,v 1.31 2010/06/07 01:41:39 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: scsipi_verbose.c,v 1.30 2010/05/30 04:38:04 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsipi_verbose.c,v 1.31 2010/06/07 01:41:39 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/time.h>
@@ -47,9 +47,9 @@
 #include <dev/scsipi/scsipiconf.h>
 #include <dev/scsipi/scsiconf.h>
 
-int	scsipi_print_sense_real(struct scsipi_xfer *, int);
-void	scsipi_print_sense_data_real(struct scsi_sense_data *, int);
-char   *scsipi_decode_sense_real(void *, int);
+int		scsipi_print_sense_real(struct scsipi_xfer *, int);
+void		scsipi_print_sense_data_real(struct scsi_sense_data *, int);
+static char    *scsipi_decode_sense(void *, int);
 
 static const char *sense_keys[16] = {
 	"No Additional Sense",
@@ -606,16 +606,20 @@
 static int
 scsiverbose_modcmd(modcmd_t cmd, void *arg)
 {
+	static int   (*saved_print_sense)(struct scsipi_xfer *, int);
+	static void  (*saved_print_sense_data)(struct scsi_sense_data *, int);
+
 	switch (cmd) {
 	case MODULE_CMD_INIT:
+		saved_print_sense = scsipi_print_sense;
+		saved_print_sense_data = scsipi_print_sense_data;
 		scsipi_print_sense = scsipi_print_sense_real;
 		scsipi_print_sense_data = scsipi_print_sense_data_real;
-		scsipi_decode_sense = scsipi_decode_sense_real;
 		return 0;
 	case MODULE_CMD_FINI:
-		scsipi_print_sense = scsipi_print_sense_stub;
-		scsipi_print_sense_data = scsipi_print_sense_data_stub;
-		scsipi_decode_sense = scsipi_decode_sense_stub;
+		scsipi_print_sense = saved_print_sense;
+		scsipi_print_sense_data = saved_print_sense_data;
+		scsi_verbose_loaded = 0;
 		return 0;
 	default:
 		return ENOTTY;
@@ -626,7 +630,6 @@
 		scsipi_print_sense_real;
 void	(*scsipi_print_sense_data)(struct scsi_sense_data *, int) =
 		scsipi_print_sense_data_real; 
-char   *(*scsipi_decode_sense)(void *, int) = scsipi_decode_sense_real;
 #endif
 
 static void
@@ -768,8 +771,8 @@
 	printf("\n\n");
 }
 
-char *
-scsipi_decode_sense_real(void *sinfo, int flag)
+static char *
+scsipi_decode_sense(void *sinfo, int flag)
 {
 	unsigned char *snsbuf;
 	unsigned char skey;

Index: src/sys/dev/scsipi/scsipiconf.c
diff -u src/sys/dev/scsipi/scsipiconf.c:1.37 src/sys/dev/scsipi/scsipiconf.c:1.38
--- src/sys/dev/scsipi/scsipiconf.c:1.37	Sun May 30 04:38:04 2010
+++ src/sys/dev/scsipi/scsipiconf.c	Mon Jun  7 01:41:39 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsipiconf.c,v 1.37 2010/05/30 04:38:04 pgoyette Exp $	*/
+/*	$NetBSD: scsipiconf.c,v 1.38 2010/06/07 01:41:39 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1998, 1999, 2004 The NetBSD Foundation, Inc.
@@ -48,11 +48,12 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: scsipiconf.c,v 1.37 2010/05/30 04:38:04 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsipiconf.c,v 1.38 2010/06/07 01:41:39 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/malloc.h>
+#include <sys/module.h>
 #include <sys/device.h>
 #include <sys/proc.h>
 
@@ -63,26 +64,26 @@
 #define	STRVIS_ISWHITE(x) ((x) == ' ' || (x) == '\0' || (x) == (u_char)'\377')
 
 /* Function pointers and stub routines for scsiverbose module */
-int     (*scsipi_print_sense)(struct scsipi_xfer *, int) =
-		scsipi_print_sense_stub;
-void    (*scsipi_print_sense_data)(struct scsi_sense_data *, int) =
+int (*scsipi_print_sense)(struct scsipi_xfer *, int) = scsipi_print_sense_stub;
+void (*scsipi_print_sense_data)(struct scsi_sense_data *, int) =
 		scsipi_print_sense_data_stub;
-char   *(*scsipi_decode_sense)(void *, int) = scsipi_decode_sense_stub;
 
-int     scsipi_print_sense_stub(struct scsipi_xfer * xs, int verbosity)
-{
-	return 0;
-}
+int scsi_verbose_loaded = 0; 
 
-void    scsipi_print_sense_data_stub(struct scsi_sense_data *sense,
-				     int verbosity)
+int scsipi_print_sense_stub(struct scsipi_xfer * xs, int verbosity)
 {
-	return;
+	scsipi_load_verbose();
+	if (scsi_verbose_loaded)
+		return scsipi_print_sense(xs, verbosity);
+	else
+		return 0;
 }
 
-char   *scsipi_decode_sense_stub(void *sinfo, int flag)
+void scsipi_print_sense_data_stub(struct scsi_sense_data *sense, int verbosity)
 {
-	return NULL;
+	scsipi_load_verbose();
+	if (scsi_verbose_loaded)
+		scsipi_print_sense_data(sense, verbosity);
 }
 
 int
@@ -100,6 +101,21 @@
 	return (scsipi_execute_xs(xs));
 }
 
+/* 
+ * Load the scsiverbose module
+ */   
+void
+scsipi_load_verbose(void)
+{
+	if (scsi_verbose_loaded)
+		return;
+ 
+	mutex_enter(&module_lock);
+	if (module_autoload("scsiverbose", MODULE_CLASS_MISC) == 0)
+		scsi_verbose_loaded++; 
+	mutex_exit(&module_lock);
+}
+
 /*
  * allocate and init a scsipi_periph structure for a new device.
  */

Index: src/sys/dev/scsipi/scsipiconf.h
diff -u src/sys/dev/scsipi/scsipiconf.h:1.117 src/sys/dev/scsipi/scsipiconf.h:1.118
--- src/sys/dev/scsipi/scsipiconf.h:1.117	Sun May 30 04:38:04 2010
+++ src/sys/dev/scsipi/scsipiconf.h	Mon Jun  7 01:41:39 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsipiconf.h,v 1.117 2010/05/30 04:38:04 pgoyette Exp $	*/
+/*	$NetBSD: scsipiconf.h,v 1.118 2010/06/07 01:41:39 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2004 The NetBSD Foundation, Inc.
@@ -623,7 +623,7 @@
 
 #ifdef _KERNEL
 void	scsipi_init(void);
-void	scsipi_verbose_ctl(bool);
+void	scsipi_load_verbose(void);
 int	scsipi_command(struct scsipi_periph *, struct scsipi_generic *, int,
 	    u_char *, int, int, int, struct buf *, int);
 void	scsipi_create_completion_thread(void *);
@@ -655,11 +655,11 @@
 /* Function pointers for scsiverbose module */
 extern int	(*scsipi_print_sense)(struct scsipi_xfer *, int);
 extern void	(*scsipi_print_sense_data)(struct scsi_sense_data *, int);
-extern char    *(*scsipi_decode_sense)(void *, int);
 
 int     scsipi_print_sense_stub(struct scsipi_xfer *, int);
 void    scsipi_print_sense_data_stub(struct scsi_sense_data *, int);
-char   *scsipi_decode_sense_stub(void *, int);
+
+extern int	scsi_verbose_loaded;
 
 void	scsipi_print_cdb(struct scsipi_generic *cmd);
 int	scsipi_thread_call_callback(struct scsipi_channel *,

Reply via email to