diff options
author | Josef Bacik <josef@toxicpanda.com> | 2019-10-21 22:56:27 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-11-10 13:27:34 +0300 |
commit | 82b7c99ee1410a50b52283f4b80dca31fa7591b6 (patch) | |
tree | 0ef8d47606ed84cf2d699c8059c9416f46b2cc1b /drivers | |
parent | 80b42f4381c25021cf6d3ca73eb0540c265018b7 (diff) | |
download | linux-82b7c99ee1410a50b52283f4b80dca31fa7591b6.tar.xz |
nbd: protect cmd->status with cmd->lock
[ Upstream commit de6346ecbc8f5591ebd6c44ac164e8b8671d71d7 ]
We already do this for the most part, except in timeout and clear_req.
For the timeout case we take the lock after we grab a ref on the config,
but that isn't really necessary because we're safe to touch the cmd at
this point, so just move the order around.
For the clear_req cause this is initiated by the user, so again is safe.
Reviewed-by: Mike Christie <mchristi@redhat.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/block/nbd.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index bd9aafe86c2f..da6a36d14f4c 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -349,17 +349,16 @@ static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req, struct nbd_device *nbd = cmd->nbd; struct nbd_config *config; + if (!mutex_trylock(&cmd->lock)) + return BLK_EH_RESET_TIMER; + if (!refcount_inc_not_zero(&nbd->config_refs)) { cmd->status = BLK_STS_TIMEOUT; + mutex_unlock(&cmd->lock); goto done; } config = nbd->config; - if (!mutex_trylock(&cmd->lock)) { - nbd_config_put(nbd); - return BLK_EH_RESET_TIMER; - } - if (config->num_connections > 1) { dev_err_ratelimited(nbd_to_dev(nbd), "Connection timed out, retrying (%d/%d alive)\n", @@ -745,7 +744,10 @@ static void nbd_clear_req(struct request *req, void *data, bool reserved) { struct nbd_cmd *cmd = blk_mq_rq_to_pdu(req); + mutex_lock(&cmd->lock); cmd->status = BLK_STS_IOERR; + mutex_unlock(&cmd->lock); + blk_mq_complete_request(req); } |