aboutsummaryrefslogtreecommitdiff
path: root/sys/cam/ctl/ctl_tpc.c
diff options
context:
space:
mode:
authorAlexander Motin <mav@FreeBSD.org>2015-06-20 11:20:25 +0000
committerAlexander Motin <mav@FreeBSD.org>2015-06-20 11:20:25 +0000
commit2d8b28765ca359b200f2dc0a46f82be89fd93e9d (patch)
tree46a4e1b1ede5142150279d58de503f92a40d9631 /sys/cam/ctl/ctl_tpc.c
parentffe11f412daa81572bc2a758496eacf0498a5a04 (diff)
downloadsrc-2d8b28765ca359b200f2dc0a46f82be89fd93e9d.tar.gz
src-2d8b28765ca359b200f2dc0a46f82be89fd93e9d.zip
Introduce separate lock for tokens to reduce ctl_lock scope.
Notes
Notes: svn path=/head/; revision=284639
Diffstat (limited to 'sys/cam/ctl/ctl_tpc.c')
-rw-r--r--sys/cam/ctl/ctl_tpc.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/sys/cam/ctl/ctl_tpc.c b/sys/cam/ctl/ctl_tpc.c
index fee5b90bd4f6..490cddd510b7 100644
--- a/sys/cam/ctl/ctl_tpc.c
+++ b/sys/cam/ctl/ctl_tpc.c
@@ -167,6 +167,7 @@ tpc_timeout(void *arg)
}
/* Free inactive ROD tokens with expired timeout. */
+ mtx_lock(&softc->tpc_lock);
TAILQ_FOREACH_SAFE(token, &softc->tpc_tokens, links, ttoken) {
if (token->active ||
time_uptime < token->last_active + token->timeout + 1)
@@ -175,6 +176,7 @@ tpc_timeout(void *arg)
free(token->params, M_CTL);
free(token, M_CTL);
}
+ mtx_unlock(&softc->tpc_lock);
callout_schedule(&softc->tpc_timeout, hz);
}
@@ -182,6 +184,7 @@ void
ctl_tpc_init(struct ctl_softc *softc)
{
+ mtx_init(&softc->tpc_lock, "CTL TPC mutex", NULL, MTX_DEF);
TAILQ_INIT(&softc->tpc_tokens);
callout_init_mtx(&softc->tpc_timeout, &softc->ctl_lock, 0);
callout_reset(&softc->tpc_timeout, hz, tpc_timeout, softc);
@@ -195,13 +198,14 @@ ctl_tpc_shutdown(struct ctl_softc *softc)
callout_drain(&softc->tpc_timeout);
/* Free ROD tokens. */
- mtx_lock(&softc->ctl_lock);
+ mtx_lock(&softc->tpc_lock);
while ((token = TAILQ_FIRST(&softc->tpc_tokens)) != NULL) {
TAILQ_REMOVE(&softc->tpc_tokens, token, links);
free(token->params, M_CTL);
free(token, M_CTL);
}
- mtx_unlock(&softc->ctl_lock);
+ mtx_unlock(&softc->tpc_lock);
+ mtx_destroy(&softc->tpc_lock);
}
void
@@ -227,7 +231,7 @@ ctl_tpc_lun_shutdown(struct ctl_lun *lun)
}
/* Free ROD tokens for this LUN. */
- mtx_assert(&softc->ctl_lock, MA_OWNED);
+ mtx_lock(&softc->tpc_lock);
TAILQ_FOREACH_SAFE(token, &softc->tpc_tokens, links, ttoken) {
if (token->lun != lun->lun || token->active)
continue;
@@ -235,6 +239,7 @@ ctl_tpc_lun_shutdown(struct ctl_lun *lun)
free(token->params, M_CTL);
free(token, M_CTL);
}
+ mtx_unlock(&softc->tpc_lock);
}
int
@@ -1394,10 +1399,10 @@ done:
free(list->params, M_CTL);
list->params = NULL;
if (list->token) {
- mtx_lock(&softc->ctl_lock);
+ mtx_lock(&softc->tpc_lock);
if (--list->token->active == 0)
list->token->last_active = time_uptime;
- mtx_unlock(&softc->ctl_lock);
+ mtx_unlock(&softc->tpc_lock);
list->token = NULL;
}
mtx_lock(&lun->lun_lock);
@@ -1991,9 +1996,9 @@ ctl_populate_token(struct ctl_scsiio *ctsio)
list->curseg = 0;
list->completed = 1;
list->last_active = time_uptime;
- mtx_lock(&softc->ctl_lock);
+ mtx_lock(&softc->tpc_lock);
TAILQ_INSERT_TAIL(&softc->tpc_tokens, token, links);
- mtx_unlock(&softc->ctl_lock);
+ mtx_unlock(&softc->tpc_lock);
ctl_set_success(ctsio);
ctl_done((union ctl_io *)ctsio);
return (CTL_RETVAL_COMPLETE);
@@ -2100,7 +2105,7 @@ ctl_write_using_token(struct ctl_scsiio *ctsio)
return (CTL_RETVAL_COMPLETE);
}
- mtx_lock(&softc->ctl_lock);
+ mtx_lock(&softc->tpc_lock);
TAILQ_FOREACH(token, &softc->tpc_tokens, links) {
if (memcmp(token->token, data->rod_token,
sizeof(data->rod_token)) == 0)
@@ -2112,7 +2117,7 @@ ctl_write_using_token(struct ctl_scsiio *ctsio)
if (data->flags & EC_WUT_DEL_TKN)
token->timeout = 0;
}
- mtx_unlock(&softc->ctl_lock);
+ mtx_unlock(&softc->tpc_lock);
if (token == NULL) {
mtx_lock(&lun->lun_lock);
TAILQ_REMOVE(&lun->tpc_lists, list, links);
@@ -2254,10 +2259,10 @@ ctl_report_all_rod_tokens(struct ctl_scsiio *ctsio)
retval = CTL_RETVAL_COMPLETE;
tokens = 0;
- mtx_lock(&softc->ctl_lock);
+ mtx_lock(&softc->tpc_lock);
TAILQ_FOREACH(token, &softc->tpc_tokens, links)
tokens++;
- mtx_unlock(&softc->ctl_lock);
+ mtx_unlock(&softc->tpc_lock);
if (tokens > 512)
tokens = 512;
@@ -2282,7 +2287,7 @@ 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(&softc->ctl_lock);
+ mtx_lock(&softc->tpc_lock);
TAILQ_FOREACH(token, &softc->tpc_tokens, links) {
if (i >= tokens)
break;
@@ -2290,7 +2295,7 @@ ctl_report_all_rod_tokens(struct ctl_scsiio *ctsio)
token->token, 96);
i++;
}
- mtx_unlock(&softc->ctl_lock);
+ mtx_unlock(&softc->tpc_lock);
scsi_ulto4b(sizeof(*data) - 4 + i * 96, data->available_data);
/*
printf("RART tokens=%d\n", i);