From: Yu Kuai <yukuai3@huawei.com>
To: <josef@toxicpanda.com>, <axboe@kernel.dk>, <ming.lei@redhat.com>
Cc: <linux-block@vger.kernel.org>, <nbd@other.debian.org>,
<linux-kernel@vger.kernel.org>, <yukuai3@huawei.com>,
<yi.zhang@huawei.com>
Subject: [PATCH -next 3/6] nbd: don't clear 'NBD_CMD_INFLIGHT' flag if request is not completed
Date: Tue, 26 Apr 2022 21:07:43 +0800 [thread overview]
Message-ID: <20220426130746.885140-4-yukuai3@huawei.com> (raw)
In-Reply-To: <20220426130746.885140-1-yukuai3@huawei.com>
Otherwise io will hung because request will only be completed if the
cmd has the flag 'NBD_CMD_INFLIGHT'.
Fixes: 07175cb1baf4 ("nbd: make sure request completion won't concurrent")
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/block/nbd.c | 27 ++++++++++++++++++++-------
1 file changed, 20 insertions(+), 7 deletions(-)
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index c0a787cb5153..4829868706af 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -429,6 +429,7 @@ static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req,
* a new connection is reconfigured or util dead timeout.
*/
if (config->socks) {
+ __set_bit(NBD_CMD_INFLIGHT, &cmd->flags);
if (cmd->index < config->num_connections) {
struct nbd_sock *nsock =
config->socks[cmd->index];
@@ -456,6 +457,8 @@ static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req,
* so just warn and reset the timer.
*/
struct nbd_sock *nsock = config->socks[cmd->index];
+
+ __set_bit(NBD_CMD_INFLIGHT, &cmd->flags);
cmd->retries++;
dev_info(nbd_to_dev(nbd), "Possible stuck request %p: control (%s@%llu,%uB). Runtime %u seconds\n",
req, nbdcmd_to_ascii(req_to_nbd_cmd_type(req)),
@@ -756,31 +759,31 @@ static struct nbd_cmd *nbd_handle_reply(struct nbd_device *nbd, int index,
dev_err(disk_to_dev(nbd->disk), "Unexpected reply %d from different sock %d (expected %d)",
tag, index, cmd->index);
ret = -ENOENT;
- goto out;
+ goto out_reset_inflight;
}
if (cmd->cmd_cookie != nbd_handle_to_cookie(handle)) {
dev_err(disk_to_dev(nbd->disk), "Double reply on req %p, cmd_cookie %u, handle cookie %u\n",
req, cmd->cmd_cookie, nbd_handle_to_cookie(handle));
ret = -ENOENT;
- goto out;
+ goto out_reset_inflight;
}
if (cmd->status != BLK_STS_OK) {
dev_err(disk_to_dev(nbd->disk), "Command already handled %p\n",
req);
ret = -ENOENT;
- goto out;
+ goto out_reset_inflight;
}
if (test_bit(NBD_CMD_REQUEUED, &cmd->flags)) {
dev_err(disk_to_dev(nbd->disk), "Raced with timeout on req %p\n",
req);
ret = -ENOENT;
- goto out;
+ goto out_reset_inflight;
}
if (ntohl(reply->error)) {
dev_err(disk_to_dev(nbd->disk), "Other side returned error (%d)\n",
ntohl(reply->error));
cmd->status = BLK_STS_IOERR;
- goto out;
+ goto out_reset_inflight;
}
dev_dbg(nbd_to_dev(nbd), "request %p: got reply\n", req);
@@ -803,15 +806,22 @@ static struct nbd_cmd *nbd_handle_reply(struct nbd_device *nbd, int index,
*/
if (nbd_disconnected(nbd->config)) {
cmd->status = BLK_STS_IOERR;
- goto out;
+ goto out_reset_inflight;
}
ret = -EIO;
- goto out;
+ goto out_reset_inflight;
}
dev_dbg(nbd_to_dev(nbd), "request %p: got %d bytes data\n",
req, bvec.bv_len);
}
}
+out_reset_inflight:
+ if (ret)
+ /*
+ * Caller will not complete the request, thus set the flag so
+ * that it can be completed from other context.
+ */
+ __set_bit(NBD_CMD_INFLIGHT, &cmd->flags);
out:
trace_nbd_payload_received(req, handle);
mutex_unlock(&cmd->lock);
@@ -857,6 +867,9 @@ static void recv_work(struct work_struct *work)
rq = blk_mq_rq_from_pdu(cmd);
if (likely(!blk_should_fake_timeout(rq->q)))
blk_mq_complete_request(rq);
+ else
+ /* Timeout rely on this flag to complete request. */
+ __test_and_set_bit(NBD_CMD_INFLIGHT, &cmd->flags);
percpu_ref_put(&q->q_usage_counter);
}
--
2.31.1
next prev parent reply other threads:[~2022-04-26 12:54 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-26 13:07 [PATCH -next 0/6] nbd: bugfix and cleanup patches Yu Kuai
2022-04-26 13:07 ` [PATCH -next 1/6] nbd: call genl_unregister_family() first in nbd_cleanup() Yu Kuai
2022-04-26 13:07 ` [PATCH -next 2/6] nbd: fix race between nbd_alloc_config() and module removal Yu Kuai
2022-04-26 13:07 ` Yu Kuai [this message]
2022-04-26 13:07 ` [PATCH -next 4/6] nbd: fix io hung while disconnecting device Yu Kuai
2022-04-26 13:07 ` [PATCH -next 5/6] nbd: fix possible overflow on 'first_minor' in nbd_dev_add() Yu Kuai
2022-04-26 13:07 ` [PATCH -next 6/6] nbd: use pr_err to output error message Yu Kuai
2022-05-05 0:57 ` [PATCH -next 0/6] nbd: bugfix and cleanup patches yukuai (C)
2022-05-12 13:17 ` yukuai (C)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220426130746.885140-4-yukuai3@huawei.com \
--to=yukuai3@huawei.com \
--cc=axboe@kernel.dk \
--cc=josef@toxicpanda.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ming.lei@redhat.com \
--cc=nbd@other.debian.org \
--cc=yi.zhang@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).