[Midnightbsd-cvs] src [9086] trunk: make CTL build as module
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sat Oct 1 06:30:27 EDT 2016
Revision: 9086
http://svnweb.midnightbsd.org/src/?rev=9086
Author: laffer1
Date: 2016-10-01 06:30:27 -0400 (Sat, 01 Oct 2016)
Log Message:
-----------
make CTL build as module
Modified Paths:
--------------
trunk/Makefile
trunk/share/man/man4/Makefile
trunk/sys/cam/ctl/README.ctl.txt
trunk/sys/cam/ctl/ctl.c
trunk/sys/cam/ctl/ctl_frontend_cam_sim.c
trunk/sys/cam/ctl/ctl_frontend_internal.c
trunk/sys/cam/ctl/scsi_ctl.c
trunk/sys/modules/Makefile
trunk/usr.bin/ctlstat/ctlstat.8
trunk/usr.sbin/ctladm/ctladm.8
Modified: trunk/Makefile
===================================================================
--- trunk/Makefile 2016-10-01 10:29:58 UTC (rev 9085)
+++ trunk/Makefile 2016-10-01 10:30:27 UTC (rev 9086)
@@ -1,3 +1,29 @@
+# $FreeBSD$
+
+.PATH: ${.CURDIR}/../../cam/ctl
+
+KMOD= ctl
+
+SRCS= ctl.c
+SRCS+= ctl_backend.c
+SRCS+= ctl_backend_block.c
+SRCS+= ctl_backend_ramdisk.c
+SRCS+= ctl_cmd_table.c
+SRCS+= ctl_frontend.c
+SRCS+= ctl_frontend_cam_sim.c
+SRCS+= ctl_frontend_internal.c
+SRCS+= ctl_mem_pool.c
+SRCS+= ctl_scsi_all.c
+SRCS+= ctl_error.c
+SRCS+= ctl_util.c
+SRCS+= scsi_ctl.c
+SRCS+= bus_if.h
+SRCS+= device_if.h
+SRCS+= vnode_if.h
+SRCS+= opt_cam.h
+SRCS+= opt_kdtrace.h
+
+.include <bsd.kmod.mk>
#
# $MidnightBSD$
#
Modified: trunk/share/man/man4/Makefile
===================================================================
--- trunk/share/man/man4/Makefile 2016-10-01 10:29:58 UTC (rev 9085)
+++ trunk/share/man/man4/Makefile 2016-10-01 10:30:27 UTC (rev 9086)
@@ -93,6 +93,7 @@
${_cpuctl.4} \
cpufreq.4 \
crypto.4 \
+ ctl.4 \
cue.4 \
cxgb.4 \
cxgbe.4 \
Modified: trunk/sys/cam/ctl/README.ctl.txt
===================================================================
--- trunk/sys/cam/ctl/README.ctl.txt 2016-10-01 10:29:58 UTC (rev 9085)
+++ trunk/sys/cam/ctl/README.ctl.txt 2016-10-01 10:30:27 UTC (rev 9086)
@@ -227,9 +227,6 @@
To Do List:
==========
- - Make CTL buildable as a module. Work needs to be done on initialization,
- and on freeing resources and LUNs when it is built as a module.
-
- Use devstat(9) for CTL's statistics collection. CTL uses a home-grown
statistics collection system that is similar to devstat(9). ctlstat
should be retired in favor of iostat, etc., once aggregation modes are
Modified: trunk/sys/cam/ctl/ctl.c
===================================================================
--- trunk/sys/cam/ctl/ctl.c 2016-10-01 10:29:58 UTC (rev 9085)
+++ trunk/sys/cam/ctl/ctl.c 2016-10-01 10:30:27 UTC (rev 9086)
@@ -52,6 +52,7 @@
#include <sys/bio.h>
#include <sys/fcntl.h>
#include <sys/lock.h>
+#include <sys/module.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/malloc.h>
@@ -332,7 +333,7 @@
static void ctl_isc_event_handler(ctl_ha_channel chanel, ctl_ha_event event,
int param);
static void ctl_copy_sense_data(union ctl_ha_msg *src, union ctl_io *dest);
-static void ctl_init(void);
+static int ctl_init(void);
void ctl_shutdown(void);
static int ctl_open(struct cdev *dev, int flags, int fmt, struct thread *td);
static int ctl_close(struct cdev *dev, int flags, int fmt, struct thread *td);
@@ -451,12 +452,17 @@
MALLOC_DEFINE(M_CTL, "ctlmem", "Memory used for CTL");
-/*
- * If we have the CAM SIM, we may or may not have another SIM that will
- * cause CTL to get initialized. If not, we need to initialize it.
- */
-SYSINIT(ctl_init, SI_SUB_CONFIGURE, SI_ORDER_THIRD, ctl_init, NULL);
+static int ctl_module_event_handler(module_t, int /*modeventtype_t*/, void *);
+static moduledata_t ctl_moduledata = {
+ "ctl",
+ ctl_module_event_handler,
+ NULL
+};
+
+DECLARE_MODULE(ctl, ctl_moduledata, SI_SUB_CONFIGURE, SI_ORDER_THIRD);
+MODULE_VERSION(ctl, 1);
+
static void
ctl_isc_handler_finish_xfer(struct ctl_softc *ctl_softc,
union ctl_ha_msg *msg_info)
@@ -935,7 +941,7 @@
dest->io_hdr.status = src->hdr.status;
}
-static void
+static int
ctl_init(void)
{
struct ctl_softc *softc;
@@ -946,7 +952,7 @@
#if 0
int i;
#endif
- int retval;
+ int error, retval;
//int isc_retval;
retval = 0;
@@ -955,7 +961,7 @@
/* If we're disabled, don't initialize. */
if (ctl_disable != 0)
- return;
+ return (0);
control_softc = malloc(sizeof(*control_softc), M_DEVBUF,
M_WAITOK | M_ZERO);
@@ -984,7 +990,7 @@
destroy_dev(softc->dev);
free(control_softc, M_DEVBUF);
control_softc = NULL;
- return;
+ return (ENOMEM);
}
SYSCTL_ADD_INT(&softc->sysctl_ctx,
@@ -1046,7 +1052,7 @@
&internal_pool)!= 0){
printf("ctl: can't allocate %d entry internal pool, "
"exiting\n", CTL_POOL_ENTRIES_INTERNAL);
- return;
+ return (ENOMEM);
}
if (ctl_pool_create(softc, CTL_POOL_EMERGENCY,
@@ -1054,7 +1060,7 @@
printf("ctl: can't allocate %d entry emergency pool, "
"exiting\n", CTL_POOL_ENTRIES_EMERGENCY);
ctl_pool_free(softc, internal_pool);
- return;
+ return (ENOMEM);
}
if (ctl_pool_create(softc, CTL_POOL_4OTHERSC, CTL_POOL_ENTRIES_OTHER_SC,
@@ -1064,7 +1070,7 @@
"exiting\n", CTL_POOL_ENTRIES_OTHER_SC);
ctl_pool_free(softc, internal_pool);
ctl_pool_free(softc, emergency_pool);
- return;
+ return (ENOMEM);
}
softc->internal_pool = internal_pool;
@@ -1085,14 +1091,15 @@
mtx_unlock(&softc->ctl_lock);
#endif
- if (kproc_create(ctl_work_thread, softc, &softc->work_thread, 0, 0,
- "ctl_thrd") != 0) {
+ error = kproc_create(ctl_work_thread, softc, &softc->work_thread, 0, 0,
+ "ctl_thrd");
+ if (error != 0) {
printf("error creating CTL work thread!\n");
ctl_free_lun(lun);
ctl_pool_free(softc, internal_pool);
ctl_pool_free(softc, emergency_pool);
ctl_pool_free(softc, other_pool);
- return;
+ return (error);
}
printf("ctl: CAM Target Layer loaded\n");
@@ -1132,10 +1139,11 @@
if (sizeof(struct callout) > CTL_TIMER_BYTES) {
printf("sizeof(struct callout) %zd > CTL_TIMER_BYTES %zd\n",
sizeof(struct callout), CTL_TIMER_BYTES);
- return;
+ return (EINVAL);
}
#endif /* CTL_IO_DELAY */
+ return (0);
}
void
@@ -1192,6 +1200,20 @@
printf("ctl: CAM Target Layer unloaded\n");
}
+static int
+ctl_module_event_handler(module_t mod, int what, void *arg)
+{
+
+ switch (what) {
+ case MOD_LOAD:
+ return (ctl_init());
+ case MOD_UNLOAD:
+ return (EBUSY);
+ default:
+ return (EOPNOTSUPP);
+ }
+}
+
/*
* XXX KDM should we do some access checks here? Bump a reference count to
* prevent a CTL module from being unloaded while someone has it open?
Modified: trunk/sys/cam/ctl/ctl_frontend_cam_sim.c
===================================================================
--- trunk/sys/cam/ctl/ctl_frontend_cam_sim.c 2016-10-01 10:29:58 UTC (rev 9085)
+++ trunk/sys/cam/ctl/ctl_frontend_cam_sim.c 2016-10-01 10:30:27 UTC (rev 9086)
@@ -121,13 +121,24 @@
static int cfcs_max_sense = sizeof(struct scsi_sense_data);
extern int ctl_disable;
-SYSINIT(cfcs_init, SI_SUB_CONFIGURE, SI_ORDER_FOURTH, cfcs_init, NULL);
SYSCTL_NODE(_kern_cam, OID_AUTO, ctl2cam, CTLFLAG_RD, 0,
"CAM Target Layer SIM frontend");
SYSCTL_INT(_kern_cam_ctl2cam, OID_AUTO, max_sense, CTLFLAG_RW,
&cfcs_max_sense, 0, "Maximum sense data size");
+static int cfcs_module_event_handler(module_t, int /*modeventtype_t*/, void *);
+static moduledata_t cfcs_moduledata = {
+ "ctlcfcs",
+ cfcs_module_event_handler,
+ NULL
+};
+
+DECLARE_MODULE(ctlcfcs, cfcs_moduledata, SI_SUB_CONFIGURE, SI_ORDER_FOURTH);
+MODULE_VERSION(ctlcfcs, 1);
+MODULE_DEPEND(ctlcfi, ctl, 1, 1, 1);
+MODULE_DEPEND(ctlcfi, cam, 1, 1, 1);
+
int
cfcs_init(void)
{
@@ -176,7 +187,7 @@
printf("%s: ctl_frontend_register() failed with error %d!\n",
__func__, retval);
mtx_destroy(&softc->lock);
- return (1);
+ return (retval);
}
/*
@@ -236,7 +247,7 @@
CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
printf("%s: error creating path\n", __func__);
xpt_bus_deregister(cam_sim_path(softc->sim));
- retval = 1;
+ retval = EINVAL;
goto bailout;
}
@@ -274,6 +285,20 @@
}
+static int
+cfcs_module_event_handler(module_t mod, int what, void *arg)
+{
+
+ switch (what) {
+ case MOD_LOAD:
+ return (cfcs_init());
+ case MOD_UNLOAD:
+ return (EBUSY);
+ default:
+ return (EOPNOTSUPP);
+ }
+}
+
static void
cfcs_onoffline(void *arg, int online)
{
Modified: trunk/sys/cam/ctl/ctl_frontend_internal.c
===================================================================
--- trunk/sys/cam/ctl/ctl_frontend_internal.c 2016-10-01 10:29:58 UTC (rev 9085)
+++ trunk/sys/cam/ctl/ctl_frontend_internal.c 2016-10-01 10:30:27 UTC (rev 9086)
@@ -55,6 +55,7 @@
#include <sys/kernel.h>
#include <sys/types.h>
#include <sys/malloc.h>
+#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
@@ -189,7 +190,7 @@
static struct cfi_softc fetd_internal_softc;
extern int ctl_disable;
-void cfi_init(void);
+int cfi_init(void);
void cfi_shutdown(void) __unused;
static void cfi_online(void *arg);
static void cfi_offline(void *arg);
@@ -217,9 +218,19 @@
static void cfi_err_recovery_done(union ctl_io *io);
static void cfi_lun_io_done(union ctl_io *io);
-SYSINIT(cfi_init, SI_SUB_CONFIGURE, SI_ORDER_FOURTH, cfi_init, NULL);
+static int cfi_module_event_handler(module_t, int /*modeventtype_t*/, void *);
-void
+static moduledata_t cfi_moduledata = {
+ "ctlcfi",
+ cfi_module_event_handler,
+ NULL
+};
+
+DECLARE_MODULE(ctlcfi, cfi_moduledata, SI_SUB_CONFIGURE, SI_ORDER_FOURTH);
+MODULE_VERSION(ctlcfi, 1);
+MODULE_DEPEND(ctlcfi, ctl, 1, 1, 1);
+
+int
cfi_init(void)
{
struct cfi_softc *softc;
@@ -234,7 +245,7 @@
/* If we're disabled, don't initialize */
if (ctl_disable != 0)
- return;
+ return (0);
if (sizeof(struct cfi_lun_io) > CTL_PORT_PRIV_SIZE) {
printf("%s: size of struct cfi_lun_io %zd > "
@@ -292,7 +303,7 @@
}
bailout:
- return;
+ return (0);
bailout_error:
@@ -309,6 +320,8 @@
default:
break;
}
+
+ return (ENOMEM);
}
void
@@ -331,6 +344,20 @@
printf("%s: error shrinking LUN pool\n", __func__);
}
+static int
+cfi_module_event_handler(module_t mod, int what, void *arg)
+{
+
+ switch (what) {
+ case MOD_LOAD:
+ return (cfi_init());
+ case MOD_UNLOAD:
+ return (EBUSY);
+ default:
+ return (EOPNOTSUPP);
+ }
+}
+
static void
cfi_online(void *arg)
{
Modified: trunk/sys/cam/ctl/scsi_ctl.c
===================================================================
--- trunk/sys/cam/ctl/scsi_ctl.c 2016-10-01 10:29:58 UTC (rev 9085)
+++ trunk/sys/cam/ctl/scsi_ctl.c 2016-10-01 10:30:27 UTC (rev 9086)
@@ -225,11 +225,28 @@
ctlfeinit, "ctl",
TAILQ_HEAD_INITIALIZER(ctlfe_driver.units), /*generation*/ 0
};
-PERIPHDRIVER_DECLARE(ctl, ctlfe_driver);
+static int ctlfe_module_event_handler(module_t, int /*modeventtype_t*/, void *);
+
+/*
+ * We're not using PERIPHDRIVER_DECLARE(), because it runs at SI_SUB_DRIVERS,
+ * and that happens before CTL gets initialised.
+ */
+static moduledata_t ctlfe_moduledata = {
+ "ctlfe",
+ ctlfe_module_event_handler,
+ NULL
+};
+
+DECLARE_MODULE(ctlfe, ctlfe_moduledata, SI_SUB_CONFIGURE, SI_ORDER_FOURTH);
+MODULE_VERSION(ctlfe, 1);
+MODULE_DEPEND(ctlfe, ctl, 1, 1, 1);
+MODULE_DEPEND(ctlfe, cam, 1, 1, 1);
+
extern struct ctl_softc *control_softc;
extern int ctl_disable;
+#ifdef seems_unused
int
ctlfeinitialize(void)
{
@@ -257,6 +274,7 @@
return (0);
}
+#endif
void
ctlfeshutdown(void)
@@ -288,6 +306,21 @@
}
}
+static int
+ctlfe_module_event_handler(module_t mod, int what, void *arg)
+{
+
+ switch (what) {
+ case MOD_LOAD:
+ periphdriver_register(&ctlfe_driver);
+ return (0);
+ case MOD_UNLOAD:
+ return (EBUSY);
+ default:
+ return (EOPNOTSUPP);
+ }
+}
+
static void
ctlfeasync(void *callback_arg, uint32_t code, struct cam_path *path, void *arg)
{
@@ -1969,7 +2002,6 @@
struct cam_sim *sim;
cam_status status;
-
bus_softc = (struct ctlfe_softc *)arg;
sim = bus_softc->sim;
Modified: trunk/sys/modules/Makefile
===================================================================
--- trunk/sys/modules/Makefile 2016-10-01 10:29:58 UTC (rev 9085)
+++ trunk/sys/modules/Makefile 2016-10-01 10:30:27 UTC (rev 9086)
@@ -76,6 +76,7 @@
${_cryptodev} \
${_cs} \
${_ctau} \
+ ctl \
${_cxgb} \
cxgbe \
${_cyclic} \
Modified: trunk/usr.bin/ctlstat/ctlstat.8
===================================================================
--- trunk/usr.bin/ctlstat/ctlstat.8 2016-10-01 10:29:58 UTC (rev 9085)
+++ trunk/usr.bin/ctlstat/ctlstat.8 2016-10-01 10:30:27 UTC (rev 9086)
@@ -34,7 +34,7 @@
.\" $Id: ctlstat.8,v 1.1 2012-11-23 01:13:51 laffer1 Exp $
.\" $FreeBSD$
.\"
-.Dd June 4, 2010
+.Dd March 6, 2013
.Dt CTLSTAT 8
.Os
.Sh NAME
@@ -113,6 +113,7 @@
.Sh SEE ALSO
.Xr cam 3 ,
.Xr cam 4 ,
+.Xr ctl 4 ,
.Xr xpt 4 ,
.Xr camcontrol 8 ,
.Xr ctladm 8 ,
Modified: trunk/usr.sbin/ctladm/ctladm.8
===================================================================
--- trunk/usr.sbin/ctladm/ctladm.8 2016-10-01 10:29:58 UTC (rev 9085)
+++ trunk/usr.sbin/ctladm/ctladm.8 2016-10-01 10:30:27 UTC (rev 9086)
@@ -34,7 +34,7 @@
.\" $Id: ctladm.8,v 1.1 2013-01-30 12:43:58 laffer1 Exp $
.\" $MidnightBSD$
.\"
-.Dd March 6, 2012
+.Dd March 6, 2013
.Dt CTLADM 8
.Os
.Sh NAME
@@ -978,6 +978,7 @@
.Xr cam 3 ,
.Xr cam_cdbparse 3 ,
.Xr cam 4 ,
+.Xr ctl 4 ,
.Xr xpt 4 ,
.Xr camcontrol 8
.Sh HISTORY
More information about the Midnightbsd-cvs
mailing list