Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/scsipi Update scsiverbose module to use module_autol...
details: https://anonhg.NetBSD.org/src/rev/9b73a44ce7bb
branches: trunk
changeset: 755471:9b73a44ce7bb
user: pgoyette <pgoyette%NetBSD.org@localhost>
date: Mon Jun 07 01:41:39 2010 +0000
description:
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.
diffstat:
sys/dev/scsipi/atapiconf.c | 6 +---
sys/dev/scsipi/scsiconf.c | 6 +---
sys/dev/scsipi/scsipi_base.c | 26 +--------------------
sys/dev/scsipi/scsipi_verbose.c | 27 ++++++++++++----------
sys/dev/scsipi/scsipiconf.c | 48 +++++++++++++++++++++++++++-------------
sys/dev/scsipi/scsipiconf.h | 8 +++---
6 files changed, 57 insertions(+), 64 deletions(-)
diffs (truncated from 315 to 300 lines):
diff -r ce8071a62be7 -r 9b73a44ce7bb sys/dev/scsipi/atapiconf.c
--- a/sys/dev/scsipi/atapiconf.c Sun Jun 06 23:11:05 2010 +0000
+++ b/sys/dev/scsipi/atapiconf.c Mon Jun 07 01:41:39 2010 +0000
@@ -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);
}
diff -r ce8071a62be7 -r 9b73a44ce7bb sys/dev/scsipi/scsiconf.c
--- a/sys/dev/scsipi/scsiconf.c Sun Jun 06 23:11:05 2010 +0000
+++ b/sys/dev/scsipi/scsiconf.c Mon Jun 07 01:41:39 2010 +0000
@@ -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);
diff -r ce8071a62be7 -r 9b73a44ce7bb sys/dev/scsipi/scsipi_base.c
--- a/sys/dev/scsipi/scsipi_base.c Sun Jun 06 23:11:05 2010 +0000
+++ b/sys/dev/scsipi/scsipi_base.c Mon Jun 07 01:41:39 2010 +0000
@@ -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:
*
diff -r ce8071a62be7 -r 9b73a44ce7bb sys/dev/scsipi/scsipi_verbose.c
--- a/sys/dev/scsipi/scsipi_verbose.c Sun Jun 06 23:11:05 2010 +0000
+++ b/sys/dev/scsipi/scsipi_verbose.c Mon Jun 07 01:41:39 2010 +0000
@@ -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;
diff -r ce8071a62be7 -r 9b73a44ce7bb sys/dev/scsipi/scsipiconf.c
--- a/sys/dev/scsipi/scsipiconf.c Sun Jun 06 23:11:05 2010 +0000
+++ b/sys/dev/scsipi/scsipiconf.c Mon Jun 07 01:41:39 2010 +0000
@@ -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 scsi_verbose_loaded = 0;
-int scsipi_print_sense_stub(struct scsipi_xfer * xs, int verbosity)
+int scsipi_print_sense_stub(struct scsipi_xfer * xs, int verbosity)
{
- return 0;
+ scsipi_load_verbose();
+ if (scsi_verbose_loaded)
+ return scsipi_print_sense(xs, verbosity);
+ else
+ return 0;
}
-void scsipi_print_sense_data_stub(struct scsi_sense_data *sense,
- int verbosity)
+void scsipi_print_sense_data_stub(struct scsi_sense_data *sense, int verbosity)
{
- return;
-}
-
-char *scsipi_decode_sense_stub(void *sinfo, int flag)
-{
- 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.
*/
diff -r ce8071a62be7 -r 9b73a44ce7bb sys/dev/scsipi/scsipiconf.h
--- a/sys/dev/scsipi/scsipiconf.h Sun Jun 06 23:11:05 2010 +0000
+++ b/sys/dev/scsipi/scsipiconf.h Mon Jun 07 01:41:39 2010 +0000
@@ -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);
Home |
Main Index |
Thread Index |
Old Index