Author: mav
Date: Fri Dec 19 20:35:06 2014
New Revision: 275942
URL: https://svnweb.freebsd.org/changeset/base/275942

Log:
  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.
  
  MFC after:    2 weeks

Modified:
  head/sys/cam/ctl/ctl.c
  head/sys/cam/ctl/ctl_backend.c
  head/sys/cam/ctl/ctl_frontend.c
  head/sys/cam/ctl/ctl_tpc.c
  head/sys/cam/ctl/ctl_tpc.h
  head/sys/cam/ctl/ctl_tpc_local.c
  head/sys/cam/ctl/scsi_ctl.c

Modified: head/sys/cam/ctl/ctl.c
==============================================================================
--- head/sys/cam/ctl/ctl.c      Fri Dec 19 19:09:22 2014        (r275941)
+++ head/sys/cam/ctl/ctl.c      Fri Dec 19 20:35:06 2014        (r275942)
@@ -398,8 +398,8 @@ static int ctl_ioctl_fill_ooa(struct ctl
                              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);
@@ -441,8 +441,7 @@ static ctl_action ctl_check_for_blockage
 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);
@@ -609,12 +608,12 @@ ctl_isc_handler_finish_ser_only(struct c
 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;
 
 
@@ -640,7 +639,7 @@ ctl_isc_event_handler(ctl_ha_channel cha
 #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");
@@ -672,7 +671,7 @@ ctl_isc_event_handler(ctl_ha_channel cha
                         *
                         * 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
@@ -686,7 +685,7 @@ ctl_isc_event_handler(ctl_ha_channel cha
                        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);
@@ -852,11 +851,11 @@ ctl_isc_event_handler(ctl_ha_channel cha
                 * 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;
 
@@ -886,7 +885,7 @@ ctl_isc_event_handler(ctl_ha_channel cha
                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");
@@ -915,7 +914,7 @@ ctl_isc_event_handler(ctl_ha_channel cha
                /* 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");
@@ -1832,16 +1831,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)
        {
                /*
@@ -1886,7 +1885,7 @@ ctl_serialize_other_sc_cmd(struct ctl_sc
                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 {
@@ -3602,11 +3601,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)
@@ -3615,12 +3614,12 @@ ctl_map_lun(int port_num, uint32_t lun_i
 }
 
 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++) {
@@ -4777,25 +4776,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);
 }
@@ -4803,16 +4802,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) {
                /*
@@ -4820,13 +4818,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);
 
                /*
@@ -4834,9 +4832,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",
@@ -4851,7 +4849,7 @@ ctl_enable_lun(struct ctl_be_lun *be_lun
 #endif
        }
 
-       mtx_unlock(&ctl_softc->ctl_lock);
+       mtx_unlock(&softc->ctl_lock);
 
        return (0);
 }
@@ -4859,27 +4857,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.
@@ -4889,7 +4886,7 @@ ctl_disable_lun(struct ctl_be_lun *be_lu
                 */
                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",
@@ -4898,7 +4895,7 @@ ctl_disable_lun(struct ctl_be_lun *be_lu
                }
        }
 
-       mtx_unlock(&ctl_softc->ctl_lock);
+       mtx_unlock(&softc->ctl_lock);
 
        return (0);
 }
@@ -4906,80 +4903,55 @@ ctl_disable_lun(struct ctl_be_lun *be_lu
 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);
 
@@ -5002,9 +4974,9 @@ ctl_invalidate_lun(struct ctl_be_lun *be
         */
        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);
 
@@ -5014,32 +4986,22 @@ ctl_invalidate_lun(struct ctl_be_lun *be
 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);
 }
 
@@ -5225,7 +5187,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;
 
@@ -5236,7 +5197,6 @@ ctl_scsi_release(struct ctl_scsiio *ctsi
 
        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: {
@@ -5313,7 +5273,6 @@ ctl_scsi_reserve(struct ctl_scsiio *ctsi
        int extent, thirdparty, longid;
        int resv_id, length;
        uint64_t thirdparty_id;
-       struct ctl_softc *ctl_softc;
        struct ctl_lun *lun;
        uint32_t residx;
 
@@ -5328,7 +5287,6 @@ ctl_scsi_reserve(struct ctl_scsiio *ctsi
 
        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: {
@@ -5402,13 +5360,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;
@@ -5529,7 +5485,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;
@@ -5537,7 +5493,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]) {
@@ -5590,7 +5546,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);
@@ -5611,13 +5567,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;
 
@@ -6075,7 +6029,6 @@ ctl_control_page_handler(struct ctl_scsi
 {
        struct scsi_control_page *current_cp, *saved_cp, *user_cp;
        struct ctl_lun *lun;
-       struct ctl_softc *softc;
        int set_ua;
        uint32_t initidx;
 
@@ -6091,8 +6044,6 @@ ctl_control_page_handler(struct ctl_scsi
                (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)) {
@@ -7358,8 +7309,8 @@ ctl_report_tagret_port_groups(struct ctl
        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;
 
@@ -7390,7 +7341,8 @@ ctl_report_tagret_port_groups(struct ctl
        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++;
        }
@@ -7463,8 +7415,8 @@ ctl_report_tagret_port_groups(struct ctl
                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].
@@ -7756,13 +7708,12 @@ ctl_persistent_reserve_in(struct ctl_scs
 
        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);
@@ -8385,10 +8336,9 @@ ctl_persistent_reserve_out(struct ctl_sc
 
        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
@@ -9304,6 +9254,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;
@@ -9319,9 +9270,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:
@@ -9373,12 +9324,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;
 
@@ -9434,7 +9386,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
@@ -9869,15 +9821,15 @@ ctl_inquiry_evpd_devid(struct ctl_scsiio
 {
        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) +
@@ -10011,7 +9963,7 @@ ctl_inquiry_evpd_scsi_ports(struct ctl_s
                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++;
@@ -10065,8 +10017,8 @@ ctl_inquiry_evpd_scsi_ports(struct ctl_s
                        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);
@@ -10342,20 +10294,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;
@@ -10432,7 +10384,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;
@@ -11065,7 +11017,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;
 
@@ -11104,7 +11055,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
@@ -11114,7 +11064,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;
@@ -11148,9 +11098,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;
 
@@ -11162,7 +11113,7 @@ ctl_scsiio_lun_check(struct ctl_softc *c
         * 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;
@@ -11268,14 +11219,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.
@@ -11285,19 +11236,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;
 
@@ -11309,7 +11260,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
@@ -11351,7 +11302,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);
                        /*
@@ -11369,7 +11320,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);
 
@@ -11408,7 +11359,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
@@ -11498,15 +11449,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;
@@ -11519,7 +11470,7 @@ ctl_scsiio_precheck(struct ctl_softc *ct
 
        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
@@ -11651,7 +11602,7 @@ ctl_scsiio_precheck(struct ctl_softc *ct
        }
 
 
-       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);
@@ -11859,13 +11810,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;
@@ -11889,10 +11840,10 @@ ctl_target_reset(struct ctl_softc *ctl_s
        }
        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);
 }
@@ -12078,7 +12029,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];
@@ -12086,19 +12037,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);
        }
 
@@ -12108,7 +12059,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
@@ -12224,7 +12175,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;
 
@@ -12279,12 +12230,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;
                }
@@ -12311,14 +12262,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;
@@ -12345,13 +12296,13 @@ ctl_handle_isc(union ctl_io *io)
 {
        int free_io;
        struct ctl_lun *lun;
-       struct ctl_softc *ctl_softc;

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to