summaryrefslogtreecommitdiffstats
path: root/sys/cam
diff options
context:
space:
mode:
authormav <mav@FreeBSD.org>2015-01-03 13:09:32 +0000
committermav <mav@FreeBSD.org>2015-01-03 13:09:32 +0000
commit94e2b4d8f8dde5d8f10ffee7f2bd91cc76cfcafd (patch)
treebdc9386baea54a7c85c99d6bdad3aaa909d88319 /sys/cam
parent2952feb3ad9cd929b2aeb20e2746b63042e042df (diff)
downloadFreeBSD-src-94e2b4d8f8dde5d8f10ffee7f2bd91cc76cfcafd.zip
FreeBSD-src-94e2b4d8f8dde5d8f10ffee7f2bd91cc76cfcafd.tar.gz
MFC r275942: Reduce number of places where global control_softc is used.
At some point we may want to have several CTL instances, and that is not really impossible.
Diffstat (limited to 'sys/cam')
-rw-r--r--sys/cam/ctl/ctl.c347
-rw-r--r--sys/cam/ctl/ctl_backend.c46
-rw-r--r--sys/cam/ctl/ctl_frontend.c84
-rw-r--r--sys/cam/ctl/ctl_tpc.c49
-rw-r--r--sys/cam/ctl/ctl_tpc.h3
-rw-r--r--sys/cam/ctl/ctl_tpc_local.c5
-rw-r--r--sys/cam/ctl/scsi_ctl.c2
7 files changed, 245 insertions, 291 deletions
diff --git a/sys/cam/ctl/ctl.c b/sys/cam/ctl/ctl.c
index d4cfd67..874972d 100644
--- a/sys/cam/ctl/ctl.c
+++ b/sys/cam/ctl/ctl.c
@@ -400,8 +400,8 @@ static int ctl_ioctl_fill_ooa(struct ctl_lun *lun, uint32_t *cur_fill_num,
struct ctl_ooa_entry *kern_entries);
static int ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag,
struct thread *td);
-static uint32_t ctl_map_lun(int port_num, uint32_t lun);
-static uint32_t ctl_map_lun_back(int port_num, uint32_t lun);
+static uint32_t ctl_map_lun(struct ctl_softc *softc, int port_num, uint32_t lun);
+static uint32_t ctl_map_lun_back(struct ctl_softc *softc, int port_num, uint32_t lun);
static int ctl_alloc_lun(struct ctl_softc *ctl_softc, struct ctl_lun *lun,
struct ctl_be_lun *be_lun, struct ctl_id target_id);
static int ctl_free_lun(struct ctl_lun *lun);
@@ -443,8 +443,7 @@ static ctl_action ctl_check_for_blockage(struct ctl_lun *lun,
static ctl_action ctl_check_ooa(struct ctl_lun *lun, union ctl_io *pending_io,
union ctl_io *starting_io);
static int ctl_check_blocked(struct ctl_lun *lun);
-static int ctl_scsiio_lun_check(struct ctl_softc *ctl_softc,
- struct ctl_lun *lun,
+static int ctl_scsiio_lun_check(struct ctl_lun *lun,
const struct ctl_cmd_entry *entry,
struct ctl_scsiio *ctsio);
//static int ctl_check_rtr(union ctl_io *pending_io, struct ctl_softc *softc);
@@ -611,12 +610,12 @@ ctl_isc_handler_finish_ser_only(struct ctl_softc *ctl_softc,
static void
ctl_isc_event_handler(ctl_ha_channel channel, ctl_ha_event event, int param)
{
- struct ctl_softc *ctl_softc;
+ struct ctl_softc *softc;
union ctl_io *io;
struct ctl_prio *presio;
ctl_ha_status isc_status;
- ctl_softc = control_softc;
+ softc = control_softc;
io = NULL;
@@ -642,7 +641,7 @@ ctl_isc_event_handler(ctl_ha_channel channel, ctl_ha_event event, int param)
#if 0
printf("Serialize\n");
#endif
- io = ctl_alloc_io_nowait(ctl_softc->othersc_pool);
+ io = ctl_alloc_io_nowait(softc->othersc_pool);
if (io == NULL) {
printf("ctl_isc_event_handler: can't allocate "
"ctl_io!\n");
@@ -674,7 +673,7 @@ ctl_isc_event_handler(ctl_ha_channel channel, ctl_ha_event event, int param)
*
* XXX KDM add another flag that is more specific.
*/
- if (ctl_softc->ha_mode == CTL_HA_MODE_SER_ONLY)
+ if (softc->ha_mode == CTL_HA_MODE_SER_ONLY)
io->io_hdr.flags |= CTL_FLAG_INT_COPY;
io->io_hdr.nexus = msg_info.hdr.nexus;
#if 0
@@ -688,7 +687,7 @@ ctl_isc_event_handler(ctl_ha_channel channel, ctl_ha_event event, int param)
io->scsiio.tag_type = msg_info.scsi.tag_type;
memcpy(io->scsiio.cdb, msg_info.scsi.cdb,
CTL_MAX_CDBLEN);
- if (ctl_softc->ha_mode == CTL_HA_MODE_XFER) {
+ if (softc->ha_mode == CTL_HA_MODE_XFER) {
const struct ctl_cmd_entry *entry;
entry = ctl_get_cmd_entry(&io->scsiio, NULL);
@@ -854,11 +853,11 @@ ctl_isc_event_handler(ctl_ha_channel channel, ctl_ha_event event, int param)
* mode
*/
case CTL_MSG_FINISH_IO:
- if (ctl_softc->ha_mode == CTL_HA_MODE_XFER)
- ctl_isc_handler_finish_xfer(ctl_softc,
+ if (softc->ha_mode == CTL_HA_MODE_XFER)
+ ctl_isc_handler_finish_xfer(softc,
&msg_info);
else
- ctl_isc_handler_finish_ser_only(ctl_softc,
+ ctl_isc_handler_finish_ser_only(softc,
&msg_info);
break;
@@ -888,7 +887,7 @@ ctl_isc_event_handler(ctl_ha_channel channel, ctl_ha_event event, int param)
case CTL_MSG_MANAGE_TASKS: {
struct ctl_taskio *taskio;
taskio = (struct ctl_taskio *)ctl_alloc_io_nowait(
- ctl_softc->othersc_pool);
+ softc->othersc_pool);
if (taskio == NULL) {
printf("ctl_isc_event_handler: can't allocate "
"ctl_io!\n");
@@ -917,7 +916,7 @@ ctl_isc_event_handler(ctl_ha_channel channel, ctl_ha_event event, int param)
/* Persistent Reserve action which needs attention */
case CTL_MSG_PERS_ACTION:
presio = (struct ctl_prio *)ctl_alloc_io_nowait(
- ctl_softc->othersc_pool);
+ softc->othersc_pool);
if (presio == NULL) {
printf("ctl_isc_event_handler: can't allocate "
"ctl_io!\n");
@@ -1834,16 +1833,16 @@ bailout:
static int
ctl_serialize_other_sc_cmd(struct ctl_scsiio *ctsio)
{
- struct ctl_softc *ctl_softc;
+ struct ctl_softc *softc;
union ctl_ha_msg msg_info;
struct ctl_lun *lun;
int retval = 0;
uint32_t targ_lun;
- ctl_softc = control_softc;
+ softc = control_softc;
targ_lun = ctsio->io_hdr.nexus.targ_mapped_lun;
- lun = ctl_softc->ctl_luns[targ_lun];
+ lun = softc->ctl_luns[targ_lun];
if (lun==NULL)
{
/*
@@ -1888,7 +1887,7 @@ ctl_serialize_other_sc_cmd(struct ctl_scsiio *ctsio)
break;
case CTL_ACTION_PASS:
case CTL_ACTION_SKIP:
- if (ctl_softc->ha_mode == CTL_HA_MODE_XFER) {
+ if (softc->ha_mode == CTL_HA_MODE_XFER) {
ctsio->io_hdr.flags |= CTL_FLAG_IS_WAS_ON_RTR;
ctl_enqueue_rtr((union ctl_io *)ctsio);
} else {
@@ -3604,11 +3603,11 @@ ctl_port_idx(int port_num)
}
static uint32_t
-ctl_map_lun(int port_num, uint32_t lun_id)
+ctl_map_lun(struct ctl_softc *softc, int port_num, uint32_t lun_id)
{
struct ctl_port *port;
- port = control_softc->ctl_ports[ctl_port_idx(port_num)];
+ port = softc->ctl_ports[ctl_port_idx(port_num)];
if (port == NULL)
return (UINT32_MAX);
if (port->lun_map == NULL)
@@ -3617,12 +3616,12 @@ ctl_map_lun(int port_num, uint32_t lun_id)
}
static uint32_t
-ctl_map_lun_back(int port_num, uint32_t lun_id)
+ctl_map_lun_back(struct ctl_softc *softc, int port_num, uint32_t lun_id)
{
struct ctl_port *port;
uint32_t i;
- port = control_softc->ctl_ports[ctl_port_idx(port_num)];
+ port = softc->ctl_ports[ctl_port_idx(port_num)];
if (port->lun_map == NULL)
return (lun_id);
for (i = 0; i < CTL_MAX_LUNS; i++) {
@@ -4779,25 +4778,25 @@ ctl_free_lun(struct ctl_lun *lun)
static void
ctl_create_lun(struct ctl_be_lun *be_lun)
{
- struct ctl_softc *ctl_softc;
+ struct ctl_softc *softc;
- ctl_softc = control_softc;
+ softc = control_softc;
/*
* ctl_alloc_lun() should handle all potential failure cases.
*/
- ctl_alloc_lun(ctl_softc, NULL, be_lun, ctl_softc->target);
+ ctl_alloc_lun(softc, NULL, be_lun, softc->target);
}
int
ctl_add_lun(struct ctl_be_lun *be_lun)
{
- struct ctl_softc *ctl_softc = control_softc;
+ struct ctl_softc *softc = control_softc;
- mtx_lock(&ctl_softc->ctl_lock);
- STAILQ_INSERT_TAIL(&ctl_softc->pending_lun_queue, be_lun, links);
- mtx_unlock(&ctl_softc->ctl_lock);
- wakeup(&ctl_softc->pending_lun_queue);
+ mtx_lock(&softc->ctl_lock);
+ STAILQ_INSERT_TAIL(&softc->pending_lun_queue, be_lun, links);
+ mtx_unlock(&softc->ctl_lock);
+ wakeup(&softc->pending_lun_queue);
return (0);
}
@@ -4805,16 +4804,15 @@ ctl_add_lun(struct ctl_be_lun *be_lun)
int
ctl_enable_lun(struct ctl_be_lun *be_lun)
{
- struct ctl_softc *ctl_softc;
+ struct ctl_softc *softc;
struct ctl_port *port, *nport;
struct ctl_lun *lun;
int retval;
- ctl_softc = control_softc;
-
lun = (struct ctl_lun *)be_lun->ctl_lun;
+ softc = lun->ctl_softc;
- mtx_lock(&ctl_softc->ctl_lock);
+ mtx_lock(&softc->ctl_lock);
mtx_lock(&lun->lun_lock);
if ((lun->flags & CTL_LUN_DISABLED) == 0) {
/*
@@ -4822,13 +4820,13 @@ ctl_enable_lun(struct ctl_be_lun *be_lun)
* enabled?
*/
mtx_unlock(&lun->lun_lock);
- mtx_unlock(&ctl_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
return (0);
}
lun->flags &= ~CTL_LUN_DISABLED;
mtx_unlock(&lun->lun_lock);
- for (port = STAILQ_FIRST(&ctl_softc->port_list); port != NULL; port = nport) {
+ for (port = STAILQ_FIRST(&softc->port_list); port != NULL; port = nport) {
nport = STAILQ_NEXT(port, links);
/*
@@ -4836,9 +4834,9 @@ ctl_enable_lun(struct ctl_be_lun *be_lun)
* This can lead to a callback into CTL (at least in the
* case of the internal initiator frontend.
*/
- mtx_unlock(&ctl_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
retval = port->lun_enable(port->targ_lun_arg, lun->target,lun->lun);
- mtx_lock(&ctl_softc->ctl_lock);
+ mtx_lock(&softc->ctl_lock);
if (retval != 0) {
printf("%s: FETD %s port %d returned error "
"%d for lun_enable on target %ju lun %jd\n",
@@ -4853,7 +4851,7 @@ ctl_enable_lun(struct ctl_be_lun *be_lun)
#endif
}
- mtx_unlock(&ctl_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
return (0);
}
@@ -4861,27 +4859,26 @@ ctl_enable_lun(struct ctl_be_lun *be_lun)
int
ctl_disable_lun(struct ctl_be_lun *be_lun)
{
- struct ctl_softc *ctl_softc;
+ struct ctl_softc *softc;
struct ctl_port *port;
struct ctl_lun *lun;
int retval;
- ctl_softc = control_softc;
-
lun = (struct ctl_lun *)be_lun->ctl_lun;
+ softc = lun->ctl_softc;
- mtx_lock(&ctl_softc->ctl_lock);
+ mtx_lock(&softc->ctl_lock);
mtx_lock(&lun->lun_lock);
if (lun->flags & CTL_LUN_DISABLED) {
mtx_unlock(&lun->lun_lock);
- mtx_unlock(&ctl_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
return (0);
}
lun->flags |= CTL_LUN_DISABLED;
mtx_unlock(&lun->lun_lock);
- STAILQ_FOREACH(port, &ctl_softc->port_list, links) {
- mtx_unlock(&ctl_softc->ctl_lock);
+ STAILQ_FOREACH(port, &softc->port_list, links) {
+ mtx_unlock(&softc->ctl_lock);
/*
* Drop the lock before we call the frontend's disable
* routine, to avoid lock order reversals.
@@ -4891,7 +4888,7 @@ ctl_disable_lun(struct ctl_be_lun *be_lun)
*/
retval = port->lun_disable(port->targ_lun_arg, lun->target,
lun->lun);
- mtx_lock(&ctl_softc->ctl_lock);
+ mtx_lock(&softc->ctl_lock);
if (retval != 0) {
printf("ctl_alloc_lun: FETD %s port %d returned error "
"%d for lun_disable on target %ju lun %jd\n",
@@ -4900,7 +4897,7 @@ ctl_disable_lun(struct ctl_be_lun *be_lun)
}
}
- mtx_unlock(&ctl_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
return (0);
}
@@ -4908,80 +4905,55 @@ ctl_disable_lun(struct ctl_be_lun *be_lun)
int
ctl_start_lun(struct ctl_be_lun *be_lun)
{
- struct ctl_softc *ctl_softc;
- struct ctl_lun *lun;
-
- ctl_softc = control_softc;
-
- lun = (struct ctl_lun *)be_lun->ctl_lun;
+ struct ctl_lun *lun = (struct ctl_lun *)be_lun->ctl_lun;
mtx_lock(&lun->lun_lock);
lun->flags &= ~CTL_LUN_STOPPED;
mtx_unlock(&lun->lun_lock);
-
return (0);
}
int
ctl_stop_lun(struct ctl_be_lun *be_lun)
{
- struct ctl_softc *ctl_softc;
- struct ctl_lun *lun;
-
- ctl_softc = control_softc;
-
- lun = (struct ctl_lun *)be_lun->ctl_lun;
+ struct ctl_lun *lun = (struct ctl_lun *)be_lun->ctl_lun;
mtx_lock(&lun->lun_lock);
lun->flags |= CTL_LUN_STOPPED;
mtx_unlock(&lun->lun_lock);
-
return (0);
}
int
ctl_lun_offline(struct ctl_be_lun *be_lun)
{
- struct ctl_softc *ctl_softc;
- struct ctl_lun *lun;
-
- ctl_softc = control_softc;
-
- lun = (struct ctl_lun *)be_lun->ctl_lun;
+ struct ctl_lun *lun = (struct ctl_lun *)be_lun->ctl_lun;
mtx_lock(&lun->lun_lock);
lun->flags |= CTL_LUN_OFFLINE;
mtx_unlock(&lun->lun_lock);
-
return (0);
}
int
ctl_lun_online(struct ctl_be_lun *be_lun)
{
- struct ctl_softc *ctl_softc;
- struct ctl_lun *lun;
-
- ctl_softc = control_softc;
-
- lun = (struct ctl_lun *)be_lun->ctl_lun;
+ struct ctl_lun *lun = (struct ctl_lun *)be_lun->ctl_lun;
mtx_lock(&lun->lun_lock);
lun->flags &= ~CTL_LUN_OFFLINE;
mtx_unlock(&lun->lun_lock);
-
return (0);
}
int
ctl_invalidate_lun(struct ctl_be_lun *be_lun)
{
- struct ctl_softc *ctl_softc;
+ struct ctl_softc *softc;
struct ctl_lun *lun;
- ctl_softc = control_softc;
-
lun = (struct ctl_lun *)be_lun->ctl_lun;
+ softc = lun->ctl_softc;
mtx_lock(&lun->lun_lock);
@@ -5004,9 +4976,9 @@ ctl_invalidate_lun(struct ctl_be_lun *be_lun)
*/
if (TAILQ_EMPTY(&lun->ooa_queue)) {
mtx_unlock(&lun->lun_lock);
- mtx_lock(&ctl_softc->ctl_lock);
+ mtx_lock(&softc->ctl_lock);
ctl_free_lun(lun);
- mtx_unlock(&ctl_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
} else
mtx_unlock(&lun->lun_lock);
@@ -5016,32 +4988,22 @@ ctl_invalidate_lun(struct ctl_be_lun *be_lun)
int
ctl_lun_inoperable(struct ctl_be_lun *be_lun)
{
- struct ctl_softc *ctl_softc;
- struct ctl_lun *lun;
-
- ctl_softc = control_softc;
- lun = (struct ctl_lun *)be_lun->ctl_lun;
+ struct ctl_lun *lun = (struct ctl_lun *)be_lun->ctl_lun;
mtx_lock(&lun->lun_lock);
lun->flags |= CTL_LUN_INOPERABLE;
mtx_unlock(&lun->lun_lock);
-
return (0);
}
int
ctl_lun_operable(struct ctl_be_lun *be_lun)
{
- struct ctl_softc *ctl_softc;
- struct ctl_lun *lun;
-
- ctl_softc = control_softc;
- lun = (struct ctl_lun *)be_lun->ctl_lun;
+ struct ctl_lun *lun = (struct ctl_lun *)be_lun->ctl_lun;
mtx_lock(&lun->lun_lock);
lun->flags &= ~CTL_LUN_INOPERABLE;
mtx_unlock(&lun->lun_lock);
-
return (0);
}
@@ -5227,7 +5189,6 @@ int
ctl_scsi_release(struct ctl_scsiio *ctsio)
{
int length, longid, thirdparty_id, resv_id;
- struct ctl_softc *ctl_softc;
struct ctl_lun *lun;
uint32_t residx;
@@ -5238,7 +5199,6 @@ ctl_scsi_release(struct ctl_scsiio *ctsio)
residx = ctl_get_resindex(&ctsio->io_hdr.nexus);
lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
- ctl_softc = control_softc;
switch (ctsio->cdb[0]) {
case RELEASE_10: {
@@ -5315,7 +5275,6 @@ ctl_scsi_reserve(struct ctl_scsiio *ctsio)
int extent, thirdparty, longid;
int resv_id, length;
uint64_t thirdparty_id;
- struct ctl_softc *ctl_softc;
struct ctl_lun *lun;
uint32_t residx;
@@ -5330,7 +5289,6 @@ ctl_scsi_reserve(struct ctl_scsiio *ctsio)
residx = ctl_get_resindex(&ctsio->io_hdr.nexus);
lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
- ctl_softc = control_softc;
switch (ctsio->cdb[0]) {
case RESERVE_10: {
@@ -5404,13 +5362,11 @@ ctl_start_stop(struct ctl_scsiio *ctsio)
{
struct scsi_start_stop_unit *cdb;
struct ctl_lun *lun;
- struct ctl_softc *ctl_softc;
int retval;
CTL_DEBUG_PRINT(("ctl_start_stop\n"));
lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
- ctl_softc = control_softc;
retval = 0;
cdb = (struct scsi_start_stop_unit *)ctsio->cdb;
@@ -5531,7 +5487,7 @@ int
ctl_sync_cache(struct ctl_scsiio *ctsio)
{
struct ctl_lun *lun;
- struct ctl_softc *ctl_softc;
+ struct ctl_softc *softc;
uint64_t starting_lba;
uint32_t block_count;
int retval;
@@ -5539,7 +5495,7 @@ ctl_sync_cache(struct ctl_scsiio *ctsio)
CTL_DEBUG_PRINT(("ctl_sync_cache\n"));
lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
- ctl_softc = control_softc;
+ softc = lun->ctl_softc;
retval = 0;
switch (ctsio->cdb[0]) {
@@ -5592,7 +5548,7 @@ ctl_sync_cache(struct ctl_scsiio *ctsio)
* CACHE command directly to the back end.
*/
mtx_lock(&lun->lun_lock);
- if ((ctl_softc->flags & CTL_FLAG_REAL_SYNC)
+ if ((softc->flags & CTL_FLAG_REAL_SYNC)
&& (++(lun->sync_count) >= lun->sync_interval)) {
lun->sync_count = 0;
mtx_unlock(&lun->lun_lock);
@@ -5613,13 +5569,11 @@ ctl_format(struct ctl_scsiio *ctsio)
{
struct scsi_format *cdb;
struct ctl_lun *lun;
- struct ctl_softc *ctl_softc;
int length, defect_list_len;
CTL_DEBUG_PRINT(("ctl_format\n"));
lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
- ctl_softc = control_softc;
cdb = (struct scsi_format *)ctsio->cdb;
@@ -6077,7 +6031,6 @@ ctl_control_page_handler(struct ctl_scsiio *ctsio,
{
struct scsi_control_page *current_cp, *saved_cp, *user_cp;
struct ctl_lun *lun;
- struct ctl_softc *softc;
int set_ua;
uint32_t initidx;
@@ -6093,8 +6046,6 @@ ctl_control_page_handler(struct ctl_scsiio *ctsio,
(page_index->page_data + (page_index->page_len *
CTL_PAGE_SAVED));
- softc = control_softc;
-
mtx_lock(&lun->lun_lock);
if (((current_cp->rlec & SCP_DSENSE) == 0)
&& ((user_cp->rlec & SCP_DSENSE) != 0)) {
@@ -7360,8 +7311,8 @@ ctl_report_tagret_port_groups(struct ctl_scsiio *ctsio)
CTL_DEBUG_PRINT(("ctl_report_tagret_port_groups\n"));
cdb = (struct scsi_maintenance_in *)ctsio->cdb;
- softc = control_softc;
lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
+ softc = lun->ctl_softc;
retval = CTL_RETVAL_COMPLETE;
@@ -7392,7 +7343,8 @@ ctl_report_tagret_port_groups(struct ctl_scsiio *ctsio)
STAILQ_FOREACH(port, &softc->port_list, links) {
if ((port->status & CTL_PORT_STATUS_ONLINE) == 0)
continue;
- if (ctl_map_lun_back(port->targ_port, lun->lun) >= CTL_MAX_LUNS)
+ if (ctl_map_lun_back(softc, port->targ_port, lun->lun) >=
+ CTL_MAX_LUNS)
continue;
num_target_ports++;
}
@@ -7465,8 +7417,8 @@ ctl_report_tagret_port_groups(struct ctl_scsiio *ctsio)
STAILQ_FOREACH(port, &softc->port_list, links) {
if ((port->status & CTL_PORT_STATUS_ONLINE) == 0)
continue;
- if (ctl_map_lun_back(port->targ_port, lun->lun) >=
- CTL_MAX_LUNS)
+ if (ctl_map_lun_back(softc, port->targ_port, lun->lun)
+ >= CTL_MAX_LUNS)
continue;
p = port->targ_port % CTL_MAX_PORTS + g * CTL_MAX_PORTS;
scsi_ulto2b(p, tpg_desc->descriptors[pc].
@@ -7758,13 +7710,12 @@ ctl_persistent_reserve_in(struct ctl_scsiio *ctsio)
CTL_DEBUG_PRINT(("ctl_persistent_reserve_in\n"));
- softc = control_softc;
-
cdb = (struct scsi_per_res_in *)ctsio->cdb;
alloc_len = scsi_2btoul(cdb->length);
lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
+ softc = lun->ctl_softc;
retry:
mtx_lock(&lun->lun_lock);
@@ -8387,10 +8338,9 @@ ctl_persistent_reserve_out(struct ctl_scsiio *ctsio)
retval = CTL_RETVAL_COMPLETE;
- softc = control_softc;
-
cdb = (struct scsi_per_res_out *)ctsio->cdb;
lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
+ softc = lun->ctl_softc;
/*
* We only support whole-LUN scope. The scope & type are ignored for
@@ -9306,6 +9256,7 @@ ctl_verify(struct ctl_scsiio *ctsio)
int
ctl_report_luns(struct ctl_scsiio *ctsio)
{
+ struct ctl_softc *softc = control_softc;
struct scsi_report_luns *cdb;
struct scsi_report_luns_data *lun_data;
struct ctl_lun *lun, *request_lun;
@@ -9321,9 +9272,9 @@ ctl_report_luns(struct ctl_scsiio *ctsio)
CTL_DEBUG_PRINT(("ctl_report_luns\n"));
- mtx_lock(&control_softc->ctl_lock);
- num_luns = control_softc->num_luns;
- mtx_unlock(&control_softc->ctl_lock);
+ mtx_lock(&softc->ctl_lock);
+ num_luns = softc->num_luns;
+ mtx_unlock(&softc->ctl_lock);
switch (cdb->select_report) {
case RPL_REPORT_DEFAULT:
@@ -9375,12 +9326,13 @@ ctl_report_luns(struct ctl_scsiio *ctsio)
initidx = ctl_get_initindex(&ctsio->io_hdr.nexus);
- mtx_lock(&control_softc->ctl_lock);
+ mtx_lock(&softc->ctl_lock);
for (targ_lun_id = 0, num_filled = 0; targ_lun_id < CTL_MAX_LUNS && num_filled < num_luns; targ_lun_id++) {
- lun_id = ctl_map_lun(ctsio->io_hdr.nexus.targ_port, targ_lun_id);
+ lun_id = ctl_map_lun(softc, ctsio->io_hdr.nexus.targ_port,
+ targ_lun_id);
if (lun_id >= CTL_MAX_LUNS)
continue;
- lun = control_softc->ctl_luns[lun_id];
+ lun = softc->ctl_luns[lun_id];
if (lun == NULL)
continue;
@@ -9436,7 +9388,7 @@ ctl_report_luns(struct ctl_scsiio *ctsio)
mtx_unlock(&lun->lun_lock);
}
}
- mtx_unlock(&control_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
/*
* It's quite possible that we've returned fewer LUNs than we allocated
@@ -9871,15 +9823,15 @@ ctl_inquiry_evpd_devid(struct ctl_scsiio *ctsio, int alloc_len)
{
struct scsi_vpd_device_id *devid_ptr;
struct scsi_vpd_id_descriptor *desc;
- struct ctl_softc *ctl_softc;
+ struct ctl_softc *softc;
struct ctl_lun *lun;
struct ctl_port *port;
int data_len;
uint8_t proto;
- ctl_softc = control_softc;
+ softc = control_softc;
- port = ctl_softc->ctl_ports[ctl_port_idx(ctsio->io_hdr.nexus.targ_port)];
+ port = softc->ctl_ports[ctl_port_idx(ctsio->io_hdr.nexus.targ_port)];
lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
data_len = sizeof(struct scsi_vpd_device_id) +
@@ -10013,7 +9965,7 @@ ctl_inquiry_evpd_scsi_ports(struct ctl_scsiio *ctsio, int alloc_len)
if ((port->status & CTL_PORT_STATUS_ONLINE) == 0)
continue;
if (lun != NULL &&
- ctl_map_lun_back(port->targ_port, lun->lun) >=
+ ctl_map_lun_back(softc, port->targ_port, lun->lun) >=
CTL_MAX_LUNS)
continue;
num_target_ports++;
@@ -10067,8 +10019,8 @@ ctl_inquiry_evpd_scsi_ports(struct ctl_scsiio *ctsio, int alloc_len)
if ((port->status & CTL_PORT_STATUS_ONLINE) == 0)
continue;
if (lun != NULL &&
- ctl_map_lun_back(port->targ_port, lun->lun) >=
- CTL_MAX_LUNS)
+ ctl_map_lun_back(softc, port->targ_port, lun->lun)
+ >= CTL_MAX_LUNS)
continue;
p = port->targ_port % CTL_MAX_PORTS + g * CTL_MAX_PORTS;
scsi_ulto2b(p, pd->relative_port_id);
@@ -10344,20 +10296,20 @@ ctl_inquiry_std(struct ctl_scsiio *ctsio)
{
struct scsi_inquiry_data *inq_ptr;
struct scsi_inquiry *cdb;
- struct ctl_softc *ctl_softc;
+ struct ctl_softc *softc;
struct ctl_lun *lun;
char *val;
uint32_t alloc_len, data_len;
ctl_port_type port_type;
- ctl_softc = control_softc;
+ softc = control_softc;
/*
* Figure out whether we're talking to a Fibre Channel port or not.
* We treat the ioctl front end, and any SCSI adapters, as packetized
* SCSI front ends.
*/
- port_type = ctl_softc->ctl_ports[
+ port_type = softc->ctl_ports[
ctl_port_idx(ctsio->io_hdr.nexus.targ_port)]->port_type;
if (port_type == CTL_PORT_IOCTL || port_type == CTL_PORT_INTERNAL)
port_type = CTL_PORT_SCSI;
@@ -10434,7 +10386,7 @@ ctl_inquiry_std(struct ctl_scsiio *ctsio)
if (lun != NULL)
inq_ptr->device = (SID_QUAL_LU_CONNECTED << 5) |
lun->be_lun->lun_type;
- else if (ctl_softc->inquiry_pq_no_lun == 0)
+ else if (softc->inquiry_pq_no_lun == 0)
inq_ptr->device = (SID_QUAL_LU_OFFLINE << 5) | T_DIRECT;
else
inq_ptr->device = (SID_QUAL_BAD_LU << 5) | T_NODEVICE;
@@ -11067,7 +11019,6 @@ ctl_check_blocked(struct ctl_lun *lun)
break;
case CTL_ACTION_PASS:
case CTL_ACTION_SKIP: {
- struct ctl_softc *softc;
const struct ctl_cmd_entry *entry;
int isc_retval;
@@ -11106,7 +11057,6 @@ ctl_check_blocked(struct ctl_lun *lun)
break;
}
entry = ctl_get_cmd_entry(&cur_blocked->scsiio, NULL);
- softc = control_softc;
/*
* Check this I/O for LUN state changes that may
@@ -11116,7 +11066,7 @@ ctl_check_blocked(struct ctl_lun *lun)
* for any states that can be caused by SCSI
* commands.
*/
- if (ctl_scsiio_lun_check(softc, lun, entry,
+ if (ctl_scsiio_lun_check(lun, entry,
&cur_blocked->scsiio) == 0) {
cur_blocked->io_hdr.flags |=
CTL_FLAG_IS_WAS_ON_RTR;
@@ -11150,9 +11100,10 @@ ctl_check_blocked(struct ctl_lun *lun)
* careful attention to the placement of any new checks.
*/
static int
-ctl_scsiio_lun_check(struct ctl_softc *ctl_softc, struct ctl_lun *lun,
+ctl_scsiio_lun_check(struct ctl_lun *lun,
const struct ctl_cmd_entry *entry, struct ctl_scsiio *ctsio)
{
+ struct ctl_softc *softc = lun->ctl_softc;
int retval;
uint32_t residx;
@@ -11164,7 +11115,7 @@ ctl_scsiio_lun_check(struct ctl_softc *ctl_softc, struct ctl_lun *lun,
* If this shelf is a secondary shelf controller, we have to reject
* any media access commands.
*/
- if ((ctl_softc->flags & CTL_FLAG_ACTIVE_SHELF) == 0 &&
+ if ((softc->flags & CTL_FLAG_ACTIVE_SHELF) == 0 &&
(entry->flags & CTL_CMD_FLAG_OK_ON_SECONDARY) == 0) {
ctl_set_lun_standby(ctsio);
retval = 1;
@@ -11270,14 +11221,14 @@ static void
ctl_failover(void)
{
struct ctl_lun *lun;
- struct ctl_softc *ctl_softc;
+ struct ctl_softc *softc;
union ctl_io *next_io, *pending_io;
union ctl_io *io;
int lun_idx;
- ctl_softc = control_softc;
+ softc = control_softc;
- mtx_lock(&ctl_softc->ctl_lock);
+ mtx_lock(&softc->ctl_lock);
/*
* Remove any cmds from the other SC from the rtr queue. These
* will obviously only be for LUNs for which we're the primary.
@@ -11287,19 +11238,19 @@ ctl_failover(void)
* which HA mode we're in.
*/
#ifdef notyet
- mtx_lock(&ctl_softc->queue_lock);
- for (io = (union ctl_io *)STAILQ_FIRST(&ctl_softc->rtr_queue);
+ mtx_lock(&softc->queue_lock);
+ for (io = (union ctl_io *)STAILQ_FIRST(&softc->rtr_queue);
io != NULL; io = next_io) {
next_io = (union ctl_io *)STAILQ_NEXT(&io->io_hdr, links);
if (io->io_hdr.flags & CTL_FLAG_FROM_OTHER_SC)
- STAILQ_REMOVE(&ctl_softc->rtr_queue, &io->io_hdr,
+ STAILQ_REMOVE(&softc->rtr_queue, &io->io_hdr,
ctl_io_hdr, links);
}
- mtx_unlock(&ctl_softc->queue_lock);
+ mtx_unlock(&softc->queue_lock);
#endif
- for (lun_idx=0; lun_idx < ctl_softc->num_luns; lun_idx++) {
- lun = ctl_softc->ctl_luns[lun_idx];
+ for (lun_idx=0; lun_idx < softc->num_luns; lun_idx++) {
+ lun = softc->ctl_luns[lun_idx];
if (lun==NULL)
continue;
@@ -11311,7 +11262,7 @@ ctl_failover(void)
continue;
if ((lun->flags & CTL_LUN_PRIMARY_SC)
- && (ctl_softc->ha_mode == CTL_HA_MODE_SER_ONLY)) {
+ && (softc->ha_mode == CTL_HA_MODE_SER_ONLY)) {
printf("FAILOVER: primary lun %d\n", lun_idx);
/*
* Remove all commands from the other SC. First from the
@@ -11353,7 +11304,7 @@ ctl_failover(void)
}
ctl_check_blocked(lun);
} else if ((lun->flags & CTL_LUN_PRIMARY_SC)
- && (ctl_softc->ha_mode == CTL_HA_MODE_XFER)) {
+ && (softc->ha_mode == CTL_HA_MODE_XFER)) {
printf("FAILOVER: primary lun %d\n", lun_idx);
/*
@@ -11371,7 +11322,7 @@ ctl_failover(void)
io->io_hdr.flags |= CTL_FLAG_ABORT;
}
} else if (((lun->flags & CTL_LUN_PRIMARY_SC) == 0)
- && (ctl_softc->ha_mode == CTL_HA_MODE_XFER)) {
+ && (softc->ha_mode == CTL_HA_MODE_XFER)) {
printf("FAILOVER: secondary lun %d\n", lun_idx);
@@ -11410,7 +11361,7 @@ ctl_failover(void)
ctl_est_ua_all(lun, -1, CTL_UA_ASYM_ACC_CHANGE);
} else if (((lun->flags & CTL_LUN_PRIMARY_SC) == 0)
- && (ctl_softc->ha_mode == CTL_HA_MODE_SER_ONLY)) {
+ && (softc->ha_mode == CTL_HA_MODE_SER_ONLY)) {
printf("FAILOVER: secondary lun %d\n", lun_idx);
/*
* if the first io on the OOA is not on the RtR queue
@@ -11500,15 +11451,15 @@ ctl_failover(void)
ctl_est_ua_all(lun, -1, CTL_UA_ASYM_ACC_CHANGE);
} else {
panic("Unhandled HA mode failover, LUN flags = %#x, "
- "ha_mode = #%x", lun->flags, ctl_softc->ha_mode);
+ "ha_mode = #%x", lun->flags, softc->ha_mode);
}
}
ctl_pause_rtr = 0;
- mtx_unlock(&ctl_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
}
static int
-ctl_scsiio_precheck(struct ctl_softc *ctl_softc, struct ctl_scsiio *ctsio)
+ctl_scsiio_precheck(struct ctl_softc *softc, struct ctl_scsiio *ctsio)
{
struct ctl_lun *lun;
const struct ctl_cmd_entry *entry;
@@ -11521,7 +11472,7 @@ ctl_scsiio_precheck(struct ctl_softc *ctl_softc, struct ctl_scsiio *ctsio)
targ_lun = ctsio->io_hdr.nexus.targ_mapped_lun;
if ((targ_lun < CTL_MAX_LUNS)
- && ((lun = ctl_softc->ctl_luns[targ_lun]) != NULL)) {
+ && ((lun = softc->ctl_luns[targ_lun]) != NULL)) {
/*
* If the LUN is invalid, pretend that it doesn't exist.
* It will go away as soon as all pending I/O has been
@@ -11653,7 +11604,7 @@ ctl_scsiio_precheck(struct ctl_softc *ctl_softc, struct ctl_scsiio *ctsio)
}
- if (ctl_scsiio_lun_check(ctl_softc, lun, entry, ctsio) != 0) {
+ if (ctl_scsiio_lun_check(lun, entry, ctsio) != 0) {
mtx_unlock(&lun->lun_lock);
ctl_done((union ctl_io *)ctsio);
return (retval);
@@ -11861,13 +11812,13 @@ bailout:
* our single target.
*/
static int
-ctl_bus_reset(struct ctl_softc *ctl_softc, union ctl_io *io)
+ctl_bus_reset(struct ctl_softc *softc, union ctl_io *io)
{
- return(ctl_target_reset(ctl_softc, io, CTL_UA_BUS_RESET));
+ return(ctl_target_reset(softc, io, CTL_UA_BUS_RESET));
}
static int
-ctl_target_reset(struct ctl_softc *ctl_softc, union ctl_io *io,
+ctl_target_reset(struct ctl_softc *softc, union ctl_io *io,
ctl_ua_type ua_type)
{
struct ctl_lun *lun;
@@ -11891,10 +11842,10 @@ ctl_target_reset(struct ctl_softc *ctl_softc, union ctl_io *io,
}
retval = 0;
- mtx_lock(&ctl_softc->ctl_lock);
- STAILQ_FOREACH(lun, &ctl_softc->lun_list, links)
+ mtx_lock(&softc->ctl_lock);
+ STAILQ_FOREACH(lun, &softc->lun_list, links)
retval += ctl_lun_reset(lun, io, ua_type);
- mtx_unlock(&ctl_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
return (retval);
}
@@ -12080,7 +12031,7 @@ ctl_abort_task(union ctl_io *io)
{
union ctl_io *xio;
struct ctl_lun *lun;
- struct ctl_softc *ctl_softc;
+ struct ctl_softc *softc;
#if 0
struct sbuf sb;
char printbuf[128];
@@ -12088,19 +12039,19 @@ ctl_abort_task(union ctl_io *io)
int found;
uint32_t targ_lun;
- ctl_softc = control_softc;
+ softc = control_softc;
found = 0;
/*
* Look up the LUN.
*/
targ_lun = io->io_hdr.nexus.targ_mapped_lun;
- mtx_lock(&ctl_softc->ctl_lock);
+ mtx_lock(&softc->ctl_lock);
if ((targ_lun < CTL_MAX_LUNS)
- && (ctl_softc->ctl_luns[targ_lun] != NULL))
- lun = ctl_softc->ctl_luns[targ_lun];
+ && (softc->ctl_luns[targ_lun] != NULL))
+ lun = softc->ctl_luns[targ_lun];
else {
- mtx_unlock(&ctl_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
return (1);
}
@@ -12110,7 +12061,7 @@ ctl_abort_task(union ctl_io *io)
#endif
mtx_lock(&lun->lun_lock);
- mtx_unlock(&ctl_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
/*
* Run through the OOA queue and attempt to find the given I/O.
* The target port, initiator ID, tag type and tag number have to
@@ -12226,7 +12177,7 @@ ctl_abort_task(union ctl_io *io)
static void
ctl_run_task(union ctl_io *io)
{
- struct ctl_softc *ctl_softc = control_softc;
+ struct ctl_softc *softc = control_softc;
int retval = 1;
const char *task_desc;
@@ -12281,12 +12232,12 @@ ctl_run_task(union ctl_io *io)
uint32_t targ_lun;
targ_lun = io->io_hdr.nexus.targ_mapped_lun;
- mtx_lock(&ctl_softc->ctl_lock);
+ mtx_lock(&softc->ctl_lock);
if ((targ_lun < CTL_MAX_LUNS)
- && (ctl_softc->ctl_luns[targ_lun] != NULL))
- lun = ctl_softc->ctl_luns[targ_lun];
+ && (softc->ctl_luns[targ_lun] != NULL))
+ lun = softc->ctl_luns[targ_lun];
else {
- mtx_unlock(&ctl_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
retval = 1;
break;
}
@@ -12313,14 +12264,14 @@ ctl_run_task(union ctl_io *io)
retval = ctl_lun_reset(lun, io,
CTL_UA_LUN_RESET);
- mtx_unlock(&ctl_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
break;
}
case CTL_TASK_TARGET_RESET:
- retval = ctl_target_reset(ctl_softc, io, CTL_UA_TARG_RESET);
+ retval = ctl_target_reset(softc, io, CTL_UA_TARG_RESET);
break;
case CTL_TASK_BUS_RESET:
- retval = ctl_bus_reset(ctl_softc, io);
+ retval = ctl_bus_reset(softc, io);
break;
case CTL_TASK_PORT_LOGIN:
break;
@@ -12347,13 +12298,13 @@ ctl_handle_isc(union ctl_io *io)
{
int free_io;
struct ctl_lun *lun;
- struct ctl_softc *ctl_softc;
+ struct ctl_softc *softc;
uint32_t targ_lun;
- ctl_softc = control_softc;
+ softc = control_softc;
targ_lun = io->io_hdr.nexus.targ_mapped_lun;
- lun = ctl_softc->ctl_luns[targ_lun];
+ lun = softc->ctl_luns[targ_lun];
switch (io->io_hdr.msg_type) {
case CTL_MSG_SERIALIZE:
@@ -12368,7 +12319,7 @@ ctl_handle_isc(union ctl_io *io)
free_io = 0;
entry = ctl_get_cmd_entry(&io->scsiio, NULL);
mtx_lock(&lun->lun_lock);
- if (ctl_scsiio_lun_check(ctl_softc, lun,
+ if (ctl_scsiio_lun_check(lun,
entry, (struct ctl_scsiio *)io) != 0) {
mtx_unlock(&lun->lun_lock);
ctl_done(io);
@@ -12380,7 +12331,7 @@ ctl_handle_isc(union ctl_io *io)
break;
}
case CTL_MSG_FINISH_IO:
- if (ctl_softc->ha_mode == CTL_HA_MODE_XFER) {
+ if (softc->ha_mode == CTL_HA_MODE_XFER) {
free_io = 0;
ctl_done(io);
} else {
@@ -13479,14 +13430,13 @@ static int
ctl_process_done(union ctl_io *io)
{
struct ctl_lun *lun;
- struct ctl_softc *ctl_softc = control_softc;
+ struct ctl_softc *softc = control_softc;
void (*fe_done)(union ctl_io *io);
uint32_t targ_port = ctl_port_idx(io->io_hdr.nexus.targ_port);
CTL_DEBUG_PRINT(("ctl_process_done\n"));
- fe_done =
- control_softc->ctl_ports[targ_port]->fe_done;
+ fe_done = softc->ctl_ports[targ_port]->fe_done;
#ifdef CTL_TIME_IO
if ((time_uptime - io->io_hdr.start_time) > ctl_time_io_secs) {
@@ -13613,9 +13563,9 @@ ctl_process_done(union ctl_io *io)
if ((lun->flags & CTL_LUN_INVALID)
&& TAILQ_EMPTY(&lun->ooa_queue)) {
mtx_unlock(&lun->lun_lock);
- mtx_lock(&ctl_softc->ctl_lock);
+ mtx_lock(&softc->ctl_lock);
ctl_free_lun(lun);
- mtx_unlock(&ctl_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
} else
mtx_unlock(&lun->lun_lock);
@@ -13667,7 +13617,7 @@ bailout:
* if the frontend comes back in in this context to queue
* something.
*/
- if ((ctl_softc->ha_mode == CTL_HA_MODE_XFER)
+ if ((softc->ha_mode == CTL_HA_MODE_XFER)
&& (io->io_hdr.flags & CTL_FLAG_FROM_OTHER_SC)) {
union ctl_ha_msg msg;
@@ -13715,10 +13665,10 @@ int
ctl_queue_sense(union ctl_io *io)
{
struct ctl_lun *lun;
- struct ctl_softc *ctl_softc;
+ struct ctl_softc *softc;
uint32_t initidx, targ_lun;
- ctl_softc = control_softc;
+ softc = control_softc;
CTL_DEBUG_PRINT(("ctl_queue_sense\n"));
@@ -13729,17 +13679,17 @@ ctl_queue_sense(union ctl_io *io)
* things like an INQUIRY to a LUN that we don't have enabled. We
* can't deal with that right now.
*/
- mtx_lock(&ctl_softc->ctl_lock);
+ mtx_lock(&softc->ctl_lock);
/*
* If we don't have a LUN for this, just toss the sense
* information.
*/
targ_lun = io->io_hdr.nexus.targ_lun;
- targ_lun = ctl_map_lun(io->io_hdr.nexus.targ_port, targ_lun);
+ targ_lun = ctl_map_lun(softc, io->io_hdr.nexus.targ_port, targ_lun);
if ((targ_lun < CTL_MAX_LUNS)
- && (ctl_softc->ctl_luns[targ_lun] != NULL))
- lun = ctl_softc->ctl_luns[targ_lun];
+ && (softc->ctl_luns[targ_lun] != NULL))
+ lun = softc->ctl_luns[targ_lun];
else
goto bailout;
@@ -13761,7 +13711,7 @@ ctl_queue_sense(union ctl_io *io)
mtx_unlock(&lun->lun_lock);
bailout:
- mtx_unlock(&ctl_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
ctl_free_io(io);
@@ -13776,12 +13726,9 @@ bailout:
int
ctl_queue(union ctl_io *io)
{
- struct ctl_softc *ctl_softc;
CTL_DEBUG_PRINT(("ctl_queue cdb[0]=%02X\n", io->scsiio.cdb[0]));
- ctl_softc = control_softc;
-
#ifdef CTL_TIME_IO
io->io_hdr.start_time = time_uptime;
getbintime(&io->io_hdr.start_bt);
@@ -13789,7 +13736,8 @@ ctl_queue(union ctl_io *io)
/* Map FE-specific LUN ID into global one. */
io->io_hdr.nexus.targ_mapped_lun =
- ctl_map_lun(io->io_hdr.nexus.targ_port, io->io_hdr.nexus.targ_lun);
+ ctl_map_lun(control_softc, io->io_hdr.nexus.targ_port,
+ io->io_hdr.nexus.targ_lun);
switch (io->io_hdr.io_type) {
case CTL_IO_SCSI:
@@ -13820,9 +13768,6 @@ ctl_done_timer_wakeup(void *arg)
void
ctl_done(union ctl_io *io)
{
- struct ctl_softc *ctl_softc;
-
- ctl_softc = control_softc;
/*
* Enable this to catch duplicate completion issues.
diff --git a/sys/cam/ctl/ctl_backend.c b/sys/cam/ctl/ctl_backend.c
index 0e1a76c..cabecb7 100644
--- a/sys/cam/ctl/ctl_backend.c
+++ b/sys/cam/ctl/ctl_backend.c
@@ -66,33 +66,33 @@ extern struct ctl_softc *control_softc;
int
ctl_backend_register(struct ctl_backend_driver *be)
{
- struct ctl_softc *ctl_softc;
+ struct ctl_softc *softc;
struct ctl_backend_driver *be_tmp;
- ctl_softc = control_softc;
+ softc = control_softc;
- mtx_lock(&ctl_softc->ctl_lock);
+ mtx_lock(&softc->ctl_lock);
/*
* Sanity check, make sure this isn't a duplicate registration.
*/
- STAILQ_FOREACH(be_tmp, &ctl_softc->be_list, links) {
+ STAILQ_FOREACH(be_tmp, &softc->be_list, links) {
if (strcmp(be_tmp->name, be->name) == 0) {
- mtx_unlock(&ctl_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
return (-1);
}
}
- mtx_unlock(&ctl_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
/*
* Call the backend's initialization routine.
*/
be->init();
- mtx_lock(&ctl_softc->ctl_lock);
+ mtx_lock(&softc->ctl_lock);
- STAILQ_INSERT_TAIL(&ctl_softc->be_list, be, links);
+ STAILQ_INSERT_TAIL(&softc->be_list, be, links);
- ctl_softc->num_backends++;
+ softc->num_backends++;
/*
* Don't want to increment the usage count for internal consumers,
@@ -113,7 +113,7 @@ ctl_backend_register(struct ctl_backend_driver *be)
atomic_set(&be->num_luns, 0);
#endif
- mtx_unlock(&ctl_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
return (0);
}
@@ -121,24 +121,24 @@ ctl_backend_register(struct ctl_backend_driver *be)
int
ctl_backend_deregister(struct ctl_backend_driver *be)
{
- struct ctl_softc *ctl_softc;
+ struct ctl_softc *softc;
- ctl_softc = control_softc;
+ softc = control_softc;
- mtx_lock(&ctl_softc->ctl_lock);
+ mtx_lock(&softc->ctl_lock);
#if 0
if (atomic_read(&be->num_luns) != 0) {
#endif
/* XXX KDM fix this! */
if (be->num_luns != 0) {
- mtx_unlock(&ctl_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
return (-1);
}
- STAILQ_REMOVE(&ctl_softc->be_list, be, ctl_backend_driver, links);
+ STAILQ_REMOVE(&softc->be_list, be, ctl_backend_driver, links);
- ctl_softc->num_backends--;
+ softc->num_backends--;
/* XXX KDM find a substitute for this? */
#if 0
@@ -146,7 +146,7 @@ ctl_backend_deregister(struct ctl_backend_driver *be)
MOD_DEC_USE_COUNT;
#endif
- mtx_unlock(&ctl_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
return (0);
}
@@ -154,21 +154,21 @@ ctl_backend_deregister(struct ctl_backend_driver *be)
struct ctl_backend_driver *
ctl_backend_find(char *backend_name)
{
- struct ctl_softc *ctl_softc;
+ struct ctl_softc *softc;
struct ctl_backend_driver *be_tmp;
- ctl_softc = control_softc;
+ softc = control_softc;
- mtx_lock(&ctl_softc->ctl_lock);
+ mtx_lock(&softc->ctl_lock);
- STAILQ_FOREACH(be_tmp, &ctl_softc->be_list, links) {
+ STAILQ_FOREACH(be_tmp, &softc->be_list, links) {
if (strcmp(be_tmp->name, backend_name) == 0) {
- mtx_unlock(&ctl_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
return (be_tmp);
}
}
- mtx_unlock(&ctl_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
return (NULL);
}
diff --git a/sys/cam/ctl/ctl_frontend.c b/sys/cam/ctl/ctl_frontend.c
index 52dc31c..982675e 100644
--- a/sys/cam/ctl/ctl_frontend.c
+++ b/sys/cam/ctl/ctl_frontend.c
@@ -68,21 +68,22 @@ extern struct ctl_softc *control_softc;
int
ctl_frontend_register(struct ctl_frontend *fe)
{
+ struct ctl_softc *softc = control_softc;
struct ctl_frontend *fe_tmp;
- KASSERT(control_softc != NULL, ("CTL is not initialized"));
+ KASSERT(softc != NULL, ("CTL is not initialized"));
/*
* Sanity check, make sure this isn't a duplicate registration.
*/
- mtx_lock(&control_softc->ctl_lock);
- STAILQ_FOREACH(fe_tmp, &control_softc->fe_list, links) {
+ mtx_lock(&softc->ctl_lock);
+ STAILQ_FOREACH(fe_tmp, &softc->fe_list, links) {
if (strcmp(fe_tmp->name, fe->name) == 0) {
- mtx_unlock(&control_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
return (-1);
}
}
- mtx_unlock(&control_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
STAILQ_INIT(&fe->port_list);
/*
@@ -91,24 +92,25 @@ ctl_frontend_register(struct ctl_frontend *fe)
if (fe->init != NULL)
fe->init();
- mtx_lock(&control_softc->ctl_lock);
- control_softc->num_frontends++;
- STAILQ_INSERT_TAIL(&control_softc->fe_list, fe, links);
- mtx_unlock(&control_softc->ctl_lock);
+ mtx_lock(&softc->ctl_lock);
+ softc->num_frontends++;
+ STAILQ_INSERT_TAIL(&softc->fe_list, fe, links);
+ mtx_unlock(&softc->ctl_lock);
return (0);
}
int
ctl_frontend_deregister(struct ctl_frontend *fe)
{
+ struct ctl_softc *softc = control_softc;
if (!STAILQ_EMPTY(&fe->port_list))
return (-1);
- mtx_lock(&control_softc->ctl_lock);
- STAILQ_REMOVE(&control_softc->fe_list, fe, ctl_frontend, links);
- control_softc->num_frontends--;
- mtx_unlock(&control_softc->ctl_lock);
+ mtx_lock(&softc->ctl_lock);
+ STAILQ_REMOVE(&softc->fe_list, fe, ctl_frontend, links);
+ softc->num_frontends--;
+ mtx_unlock(&softc->ctl_lock);
/*
* Call the frontend's shutdown routine.
@@ -121,41 +123,42 @@ ctl_frontend_deregister(struct ctl_frontend *fe)
struct ctl_frontend *
ctl_frontend_find(char *frontend_name)
{
- struct ctl_softc *ctl_softc = control_softc;
+ struct ctl_softc *softc = control_softc;
struct ctl_frontend *fe;
- mtx_lock(&ctl_softc->ctl_lock);
- STAILQ_FOREACH(fe, &ctl_softc->fe_list, links) {
+ mtx_lock(&softc->ctl_lock);
+ STAILQ_FOREACH(fe, &softc->fe_list, links) {
if (strcmp(fe->name, frontend_name) == 0) {
- mtx_unlock(&ctl_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
return (fe);
}
}
- mtx_unlock(&ctl_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
return (NULL);
}
int
ctl_port_register(struct ctl_port *port)
{
+ struct ctl_softc *softc = control_softc;
void *pool;
int port_num;
int retval;
retval = 0;
- KASSERT(control_softc != NULL, ("CTL is not initialized"));
+ KASSERT(softc != NULL, ("CTL is not initialized"));
- mtx_lock(&control_softc->ctl_lock);
- port_num = ctl_ffz(control_softc->ctl_port_mask, CTL_MAX_PORTS);
+ mtx_lock(&softc->ctl_lock);
+ port_num = ctl_ffz(softc->ctl_port_mask, CTL_MAX_PORTS);
if ((port_num == -1)
- || (ctl_set_mask(control_softc->ctl_port_mask, port_num) == -1)) {
+ || (ctl_set_mask(softc->ctl_port_mask, port_num) == -1)) {
port->targ_port = -1;
- mtx_unlock(&control_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
return (1);
}
- control_softc->num_ports++;
- mtx_unlock(&control_softc->ctl_lock);
+ softc->num_ports++;
+ mtx_unlock(&softc->ctl_lock);
/*
* Initialize the initiator and portname mappings
@@ -176,15 +179,15 @@ ctl_port_register(struct ctl_port *port)
* pending sense queue on the next command, whether or not it is
* a REQUEST SENSE.
*/
- retval = ctl_pool_create(control_softc, port->port_name,
+ retval = ctl_pool_create(softc, port->port_name,
port->num_requested_ctl_io + 20, &pool);
if (retval != 0) {
free(port->wwpn_iid, M_CTL);
error:
port->targ_port = -1;
- mtx_lock(&control_softc->ctl_lock);
- ctl_clear_mask(control_softc->ctl_port_mask, port_num);
- mtx_unlock(&control_softc->ctl_lock);
+ mtx_lock(&softc->ctl_lock);
+ ctl_clear_mask(softc->ctl_port_mask, port_num);
+ mtx_unlock(&softc->ctl_lock);
return (retval);
}
port->ctl_pool_ref = pool;
@@ -192,12 +195,12 @@ error:
if (port->options.stqh_first == NULL)
STAILQ_INIT(&port->options);
- mtx_lock(&control_softc->ctl_lock);
- port->targ_port = port_num + control_softc->port_offset;
+ mtx_lock(&softc->ctl_lock);
+ port->targ_port = port_num + softc->port_offset;
STAILQ_INSERT_TAIL(&port->frontend->port_list, port, fe_links);
- STAILQ_INSERT_TAIL(&control_softc->port_list, port, links);
- control_softc->ctl_ports[port_num] = port;
- mtx_unlock(&control_softc->ctl_lock);
+ STAILQ_INSERT_TAIL(&softc->port_list, port, links);
+ softc->ctl_ports[port_num] = port;
+ mtx_unlock(&softc->ctl_lock);
return (retval);
}
@@ -205,6 +208,7 @@ error:
int
ctl_port_deregister(struct ctl_port *port)
{
+ struct ctl_softc *softc = control_softc;
struct ctl_io_pool *pool;
int port_num, retval, i;
@@ -217,15 +221,15 @@ ctl_port_deregister(struct ctl_port *port)
goto bailout;
}
- mtx_lock(&control_softc->ctl_lock);
- STAILQ_REMOVE(&control_softc->port_list, port, ctl_port, links);
+ mtx_lock(&softc->ctl_lock);
+ STAILQ_REMOVE(&softc->port_list, port, ctl_port, links);
STAILQ_REMOVE(&port->frontend->port_list, port, ctl_port, fe_links);
- control_softc->num_ports--;
+ softc->num_ports--;
port_num = (port->targ_port < CTL_MAX_PORTS) ? port->targ_port :
port->targ_port - CTL_MAX_PORTS;
- ctl_clear_mask(control_softc->ctl_port_mask, port_num);
- control_softc->ctl_ports[port_num] = NULL;
- mtx_unlock(&control_softc->ctl_lock);
+ ctl_clear_mask(softc->ctl_port_mask, port_num);
+ softc->ctl_ports[port_num] = NULL;
+ mtx_unlock(&softc->ctl_lock);
ctl_pool_free(pool);
ctl_free_opts(&port->options);
diff --git a/sys/cam/ctl/ctl_tpc.c b/sys/cam/ctl/ctl_tpc.c
index 90a31ae..4e67ce1 100644
--- a/sys/cam/ctl/ctl_tpc.c
+++ b/sys/cam/ctl/ctl_tpc.c
@@ -145,8 +145,6 @@ struct tpc_list {
TAILQ_ENTRY(tpc_list) links;
};
-extern struct ctl_softc *control_softc;
-
static void
tpc_timeout(void *arg)
{
@@ -216,6 +214,7 @@ ctl_tpc_lun_init(struct ctl_lun *lun)
void
ctl_tpc_lun_shutdown(struct ctl_lun *lun)
{
+ struct ctl_softc *softc = lun->ctl_softc;
struct tpc_list *list;
struct tpc_token *token, *ttoken;
@@ -228,11 +227,11 @@ ctl_tpc_lun_shutdown(struct ctl_lun *lun)
}
/* Free ROD tokens for this LUN. */
- mtx_assert(&control_softc->ctl_lock, MA_OWNED);
- TAILQ_FOREACH_SAFE(token, &control_softc->tpc_tokens, links, ttoken) {
+ mtx_assert(&softc->ctl_lock, MA_OWNED);
+ TAILQ_FOREACH_SAFE(token, &softc->tpc_tokens, links, ttoken) {
if (token->lun != lun->lun || token->active)
continue;
- TAILQ_REMOVE(&control_softc->tpc_tokens, token, links);
+ TAILQ_REMOVE(&softc->tpc_tokens, token, links);
free(token->params, M_CTL);
free(token, M_CTL);
}
@@ -796,7 +795,8 @@ tpc_resolve(struct tpc_list *list, uint16_t idx, uint32_t *ss)
}
if (idx >= list->ncscd)
return (UINT64_MAX);
- return (tpcl_resolve(list->init_port, &list->cscd[idx], ss));
+ return (tpcl_resolve(list->lun->ctl_softc,
+ list->init_port, &list->cscd[idx], ss));
}
static int
@@ -1296,6 +1296,7 @@ static void
tpc_process(struct tpc_list *list)
{
struct ctl_lun *lun = list->lun;
+ struct ctl_softc *softc = lun->ctl_softc;
struct scsi_ec_segment *seg;
struct ctl_scsiio *ctsio = list->ctsio;
int retval = CTL_RETVAL_COMPLETE;
@@ -1349,10 +1350,10 @@ done:
free(list->params, M_CTL);
list->params = NULL;
if (list->token) {
- mtx_lock(&control_softc->ctl_lock);
+ mtx_lock(&softc->ctl_lock);
if (--list->token->active == 0)
list->token->last_active = time_uptime;
- mtx_unlock(&control_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
list->token = NULL;
}
mtx_lock(&lun->lun_lock);
@@ -1831,6 +1832,7 @@ ctl_populate_token(struct ctl_scsiio *ctsio)
{
struct scsi_populate_token *cdb;
struct scsi_populate_token_data *data;
+ struct ctl_softc *softc;
struct ctl_lun *lun;
struct ctl_port *port;
struct tpc_list *list, *tlist;
@@ -1840,7 +1842,8 @@ ctl_populate_token(struct ctl_scsiio *ctsio)
CTL_DEBUG_PRINT(("ctl_populate_token\n"));
lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
- port = control_softc->ctl_ports[ctl_port_idx(ctsio->io_hdr.nexus.targ_port)];
+ softc = lun->ctl_softc;
+ port = softc->ctl_ports[ctl_port_idx(ctsio->io_hdr.nexus.targ_port)];
cdb = (struct scsi_populate_token *)ctsio->cdb;
len = scsi_4btoul(cdb->length);
@@ -1944,9 +1947,9 @@ ctl_populate_token(struct ctl_scsiio *ctsio)
list->curseg = 0;
list->completed = 1;
list->last_active = time_uptime;
- mtx_lock(&control_softc->ctl_lock);
- TAILQ_INSERT_TAIL(&control_softc->tpc_tokens, token, links);
- mtx_unlock(&control_softc->ctl_lock);
+ mtx_lock(&softc->ctl_lock);
+ TAILQ_INSERT_TAIL(&softc->tpc_tokens, token, links);
+ mtx_unlock(&softc->ctl_lock);
ctl_set_success(ctsio);
ctl_done((union ctl_io *)ctsio);
return (CTL_RETVAL_COMPLETE);
@@ -1965,6 +1968,7 @@ ctl_write_using_token(struct ctl_scsiio *ctsio)
{
struct scsi_write_using_token *cdb;
struct scsi_write_using_token_data *data;
+ struct ctl_softc *softc;
struct ctl_lun *lun;
struct tpc_list *list, *tlist;
struct tpc_token *token;
@@ -1973,6 +1977,7 @@ ctl_write_using_token(struct ctl_scsiio *ctsio)
CTL_DEBUG_PRINT(("ctl_write_using_token\n"));
lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
+ softc = lun->ctl_softc;
cdb = (struct scsi_write_using_token *)ctsio->cdb;
len = scsi_4btoul(cdb->length);
@@ -2051,8 +2056,8 @@ ctl_write_using_token(struct ctl_scsiio *ctsio)
return (CTL_RETVAL_COMPLETE);
}
- mtx_lock(&control_softc->ctl_lock);
- TAILQ_FOREACH(token, &control_softc->tpc_tokens, links) {
+ mtx_lock(&softc->ctl_lock);
+ TAILQ_FOREACH(token, &softc->tpc_tokens, links) {
if (memcmp(token->token, data->rod_token,
sizeof(data->rod_token)) == 0)
break;
@@ -2063,7 +2068,7 @@ ctl_write_using_token(struct ctl_scsiio *ctsio)
if (data->flags & EC_WUT_DEL_TKN)
token->timeout = 0;
}
- mtx_unlock(&control_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
if (token == NULL) {
mtx_lock(&lun->lun_lock);
TAILQ_REMOVE(&lun->tpc_lists, list, links);
@@ -2188,6 +2193,7 @@ ctl_receive_rod_token_information(struct ctl_scsiio *ctsio)
int
ctl_report_all_rod_tokens(struct ctl_scsiio *ctsio)
{
+ struct ctl_softc *softc;
struct ctl_lun *lun;
struct scsi_report_all_rod_tokens *cdb;
struct scsi_report_all_rod_tokens_data *data;
@@ -2199,14 +2205,15 @@ ctl_report_all_rod_tokens(struct ctl_scsiio *ctsio)
cdb = (struct scsi_report_all_rod_tokens *)ctsio->cdb;
lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
+ softc = lun->ctl_softc;
retval = CTL_RETVAL_COMPLETE;
tokens = 0;
- mtx_lock(&control_softc->ctl_lock);
- TAILQ_FOREACH(token, &control_softc->tpc_tokens, links)
+ mtx_lock(&softc->ctl_lock);
+ TAILQ_FOREACH(token, &softc->tpc_tokens, links)
tokens++;
- mtx_unlock(&control_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
if (tokens > 512)
tokens = 512;
@@ -2231,15 +2238,15 @@ ctl_report_all_rod_tokens(struct ctl_scsiio *ctsio)
data = (struct scsi_report_all_rod_tokens_data *)ctsio->kern_data_ptr;
i = 0;
- mtx_lock(&control_softc->ctl_lock);
- TAILQ_FOREACH(token, &control_softc->tpc_tokens, links) {
+ mtx_lock(&softc->ctl_lock);
+ TAILQ_FOREACH(token, &softc->tpc_tokens, links) {
if (i >= tokens)
break;
memcpy(&data->rod_management_token_list[i * 96],
token->token, 96);
i++;
}
- mtx_unlock(&control_softc->ctl_lock);
+ mtx_unlock(&softc->ctl_lock);
scsi_ulto4b(sizeof(*data) - 4 + i * 96, data->available_data);
/*
printf("RART tokens=%d\n", i);
diff --git a/sys/cam/ctl/ctl_tpc.h b/sys/cam/ctl/ctl_tpc.h
index ecbaec1..ffdab5a 100644
--- a/sys/cam/ctl/ctl_tpc.h
+++ b/sys/cam/ctl/ctl_tpc.h
@@ -31,7 +31,8 @@
void tpc_done(union ctl_io *io);
-uint64_t tpcl_resolve(int init_port, struct scsi_ec_cscd *cscd, uint32_t *ss);
+uint64_t tpcl_resolve(struct ctl_softc *softc, int init_port,
+ struct scsi_ec_cscd *cscd, uint32_t *ss);
union ctl_io * tpcl_alloc_io(void);
int tpcl_queue(union ctl_io *io, uint64_t lun);
diff --git a/sys/cam/ctl/ctl_tpc_local.c b/sys/cam/ctl/ctl_tpc_local.c
index 97a5f98..63360fe 100644
--- a/sys/cam/ctl/ctl_tpc_local.c
+++ b/sys/cam/ctl/ctl_tpc_local.c
@@ -63,7 +63,6 @@ struct tpcl_softc {
int cur_tag_num;
};
-extern struct ctl_softc *control_softc;
static struct tpcl_softc tpcl_softc;
static int tpcl_init(void);
@@ -309,9 +308,9 @@ tpcl_done(union ctl_io *io)
}
uint64_t
-tpcl_resolve(int init_port, struct scsi_ec_cscd *cscd, uint32_t *ss)
+tpcl_resolve(struct ctl_softc *softc, int init_port,
+ struct scsi_ec_cscd *cscd, uint32_t *ss)
{
- struct ctl_softc *softc = control_softc;
struct scsi_ec_cscd_id *cscdid;
struct ctl_port *port;
struct ctl_lun *lun;
diff --git a/sys/cam/ctl/scsi_ctl.c b/sys/cam/ctl/scsi_ctl.c
index a1f39d2..b1dba8c 100644
--- a/sys/cam/ctl/scsi_ctl.c
+++ b/sys/cam/ctl/scsi_ctl.c
@@ -228,8 +228,6 @@ static struct ctl_frontend ctlfe_frontend =
};
CTL_FRONTEND_DECLARE(ctlfe, ctlfe_frontend);
-extern struct ctl_softc *control_softc;
-
void
ctlfeshutdown(void)
{
OpenPOWER on IntegriCloud