Skip to content

Commit de6346e

Browse files
josefbacikaxboe
authored andcommitted
nbd: protect cmd->status with cmd->lock
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>
1 parent 2b2ed97 commit de6346e

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

‎drivers/block/nbd.c‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -385,17 +385,16 @@ static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req,
385385
struct nbd_device *nbd = cmd->nbd;
386386
struct nbd_config *config;
387387

388+
if (!mutex_trylock(&cmd->lock))
389+
return BLK_EH_RESET_TIMER;
390+
388391
if (!refcount_inc_not_zero(&nbd->config_refs)) {
389392
cmd->status = BLK_STS_TIMEOUT;
393+
mutex_unlock(&cmd->lock);
390394
goto done;
391395
}
392396
config = nbd->config;
393397

394-
if (!mutex_trylock(&cmd->lock)) {
395-
nbd_config_put(nbd);
396-
return BLK_EH_RESET_TIMER;
397-
}
398-
399398
if (config->num_connections > 1) {
400399
dev_err_ratelimited(nbd_to_dev(nbd),
401400
"Connection timed out, retrying (%d/%d alive)\n",
@@ -792,7 +791,10 @@ static bool nbd_clear_req(struct request *req, void *data, bool reserved)
792791
{
793792
struct nbd_cmd *cmd = blk_mq_rq_to_pdu(req);
794793

794+
mutex_lock(&cmd->lock);
795795
cmd->status = BLK_STS_IOERR;
796+
mutex_unlock(&cmd->lock);
797+
796798
blk_mq_complete_request(req);
797799
return true;
798800
}

0 commit comments

Comments
 (0)