aboutsummaryrefslogtreecommitdiff
path: root/sys/cam/ctl/ctl_tpc.c
diff options
context:
space:
mode:
authorAlexander Motin <mav@FreeBSD.org>2014-12-19 20:35:06 +0000
committerAlexander Motin <mav@FreeBSD.org>2014-12-19 20:35:06 +0000
commit9602f4361653a4cb538c42592b3e11ddab8e79c1 (patch)
tree5228006d083d1353bbc68052dd663f9cc92d5aa2 /sys/cam/ctl/ctl_tpc.c
parent6d659a5d9bf34dabb20d9c7d111f017bd1fb9230 (diff)
downloadsrc-9602f4361653a4cb538c42592b3e11ddab8e79c1.tar.gz
src-9602f4361653a4cb538c42592b3e11ddab8e79c1.zip
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
Notes
Notes: svn path=/head/; revision=275942
Diffstat (limited to 'sys/cam/ctl/ctl_tpc.c')
-rw-r--r--sys/cam/ctl/ctl_tpc.c49
1 files changed, 28 insertions, 21 deletions
diff --git a/sys/cam/ctl/ctl_tpc.c b/sys/cam/ctl/ctl_tpc.c
index 90a31ae59e03..4e67ce14d322 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);