Otherwise io will hung because request will only be completed if the cmd has the flag 'NBD_CMD_INFLIGHT'.
Unified · Split
| @@ -403,13 +403,14 @@ static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req, · 402 unmodified lines | ||
| 403 | 403 | if (!mutex_trylock(&cmd->lock)) |
| 404 | 404 | return BLK_EH_RESET_TIMER; |
| 405 | 405 | |
| 406 | − if (!__test_and_clear_bit(NBD_CMD_INFLIGHT, &cmd->flags)) { | |
| 406 | + if (!test_bit(NBD_CMD_INFLIGHT, &cmd->flags)) { | |
| 407 | 407 | mutex_unlock(&cmd->lock); |
| 408 | 408 | return BLK_EH_DONE; |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | if (!refcount_inc_not_zero(&nbd->config_refs)) { |
| 412 | 412 | cmd->status = BLK_STS_TIMEOUT; |
| 413 | + __clear_bit(NBD_CMD_INFLIGHT, &cmd->flags); | |
| 413 | 414 | mutex_unlock(&cmd->lock); |
| 414 | 415 | goto done; |
| 415 | 416 | } |
| @@ -478,6 +479,7 @@ static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req, · 62 unmodified lines | ||
| 478 | 479 | dev_err_ratelimited(nbd_to_dev(nbd), "Connection timed out\n"); |
| 479 | 480 | set_bit(NBD_RT_TIMEDOUT, &config->runtime_flags); |
| 480 | 481 | cmd->status = BLK_STS_IOERR; |
| 482 | + __clear_bit(NBD_CMD_INFLIGHT, &cmd->flags); | |
| 481 | 483 | mutex_unlock(&cmd->lock); |
| 482 | 484 | sock_shutdown(nbd); |
| 483 | 485 | nbd_config_put(nbd); |
| @@ -745,7 +747,7 @@ static struct nbd_cmd *nbd_handle_reply(struct nbd_device *nbd, int index, · 261 unmodified lines | ||
| 745 | 747 | cmd = blk_mq_rq_to_pdu(req); |
| 746 | 748 | |
| 747 | 749 | mutex_lock(&cmd->lock); |
| 748 | − if (!__test_and_clear_bit(NBD_CMD_INFLIGHT, &cmd->flags)) { | |
| 750 | + if (!test_bit(NBD_CMD_INFLIGHT, &cmd->flags)) { | |
| 749 | 751 | dev_err(disk_to_dev(nbd->disk), "Suspicious reply %d (status %u flags %lu)", |
| 750 | 752 | tag, cmd->status, cmd->flags); |
| 751 | 753 | ret = -ENOENT; |
| @@ -854,8 +856,16 @@ static void recv_work(struct work_struct *work) · 102 unmodified lines | ||
| 854 | 856 | } |
| 855 | 857 | |
| 856 | 858 | rq = blk_mq_rq_from_pdu(cmd); |
| 857 | − if (likely(!blk_should_fake_timeout(rq->q))) | |
| 858 | − blk_mq_complete_request(rq); | |
| 859 | + if (likely(!blk_should_fake_timeout(rq->q))) { | |
| 860 | + bool complete; | |
| 861 | + | |
| 862 | + mutex_lock(&cmd->lock); | |
| 863 | + complete = __test_and_clear_bit(NBD_CMD_INFLIGHT, | |
| 864 | + &cmd->flags); | |
| 865 | + mutex_unlock(&cmd->lock); | |
| 866 | + if (complete) | |
| 867 | + blk_mq_complete_request(rq); | |
| 868 | + } | |
| 859 | 869 | percpu_ref_put(&q->q_usage_counter); |
| 860 | 870 | } |
| 861 | 871 | |