* [PATCH v3] nbd: Remove __force casts
@ 2024-06-04 22:15 Bart Van Assche
2024-06-05 0:07 ` Chaitanya Kulkarni
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Bart Van Assche @ 2024-06-04 22:15 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-block, Christoph Hellwig, Bart Van Assche, Josef Bacik
From: Christoph Hellwig <hch@lst.de>
Make it again possible for sparse to verify that blk_status_t and Unix
error codes are used in the proper context by making nbd_send_cmd()
return a blk_status_t instead of an integer.
No functionality has been changed.
Signed-off-by: Christoph Hellwig <hch@lst.de>
[ bvanassche: added description and made two small formatting changes ]
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/block/nbd.c | 51 +++++++++++++++++++--------------------------
1 file changed, 22 insertions(+), 29 deletions(-)
Changes compared to v2: fixed return type in the patch description.
Changes compared to v1: instead of making nbd_send_cmd() return a struct,
change the nbd_send_cmd() return type into blk_status_t and move the code
for making a socket dead from the nbd_send_cmd() caller into nbd_send_cmd().
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 22a79a62cc4e..b87aa80a46dd 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -589,10 +589,11 @@ static inline int was_interrupted(int result)
}
/*
- * Returns BLK_STS_RESOURCE if the caller should retry after a delay. Returns
- * -EAGAIN if the caller should requeue @cmd. Returns -EIO if sending failed.
+ * Returns BLK_STS_RESOURCE if the caller should retry after a delay.
+ * Returns BLK_STS_IOERR if sending failed.
*/
-static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
+static blk_status_t nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd,
+ int index)
{
struct request *req = blk_mq_rq_from_pdu(cmd);
struct nbd_config *config = nbd->config;
@@ -614,13 +615,13 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
type = req_to_nbd_cmd_type(req);
if (type == U32_MAX)
- return -EIO;
+ return BLK_STS_IOERR;
if (rq_data_dir(req) == WRITE &&
(config->flags & NBD_FLAG_READ_ONLY)) {
dev_err_ratelimited(disk_to_dev(nbd->disk),
"Write on read-only\n");
- return -EIO;
+ return BLK_STS_IOERR;
}
if (req->cmd_flags & REQ_FUA)
@@ -674,11 +675,11 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
nsock->sent = sent;
}
set_bit(NBD_CMD_REQUEUED, &cmd->flags);
- return (__force int)BLK_STS_RESOURCE;
+ return BLK_STS_RESOURCE;
}
dev_err_ratelimited(disk_to_dev(nbd->disk),
"Send control failed (result %d)\n", result);
- return -EAGAIN;
+ goto requeue;
}
send_pages:
if (type != NBD_CMD_WRITE)
@@ -715,12 +716,12 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
nsock->pending = req;
nsock->sent = sent;
set_bit(NBD_CMD_REQUEUED, &cmd->flags);
- return (__force int)BLK_STS_RESOURCE;
+ return BLK_STS_RESOURCE;
}
dev_err(disk_to_dev(nbd->disk),
"Send data failed (result %d)\n",
result);
- return -EAGAIN;
+ goto requeue;
}
/*
* The completion might already have come in,
@@ -737,7 +738,16 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
trace_nbd_payload_sent(req, handle);
nsock->pending = NULL;
nsock->sent = 0;
- return 0;
+ __set_bit(NBD_CMD_INFLIGHT, &cmd->flags);
+ return BLK_STS_OK;
+
+requeue:
+ /* retry on a different socket */
+ dev_err_ratelimited(disk_to_dev(nbd->disk),
+ "Request send failed, requeueing\n");
+ nbd_mark_nsock_dead(nbd, nsock, 1);
+ nbd_requeue_cmd(cmd);
+ return BLK_STS_OK;
}
static int nbd_read_reply(struct nbd_device *nbd, struct socket *sock,
@@ -1018,7 +1028,7 @@ static blk_status_t nbd_handle_cmd(struct nbd_cmd *cmd, int index)
struct nbd_device *nbd = cmd->nbd;
struct nbd_config *config;
struct nbd_sock *nsock;
- int ret;
+ blk_status_t ret;
lockdep_assert_held(&cmd->lock);
@@ -1072,28 +1082,11 @@ static blk_status_t nbd_handle_cmd(struct nbd_cmd *cmd, int index)
ret = BLK_STS_OK;
goto out;
}
- /*
- * Some failures are related to the link going down, so anything that
- * returns EAGAIN can be retried on a different socket.
- */
ret = nbd_send_cmd(nbd, cmd, index);
- /*
- * Access to this flag is protected by cmd->lock, thus it's safe to set
- * the flag after nbd_send_cmd() succeed to send request to server.
- */
- if (!ret)
- __set_bit(NBD_CMD_INFLIGHT, &cmd->flags);
- else if (ret == -EAGAIN) {
- dev_err_ratelimited(disk_to_dev(nbd->disk),
- "Request send failed, requeueing\n");
- nbd_mark_nsock_dead(nbd, nsock, 1);
- nbd_requeue_cmd(cmd);
- ret = BLK_STS_OK;
- }
out:
mutex_unlock(&nsock->tx_lock);
nbd_config_put(nbd);
- return ret < 0 ? BLK_STS_IOERR : (__force blk_status_t)ret;
+ return ret;
}
static blk_status_t nbd_queue_rq(struct blk_mq_hw_ctx *hctx,
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3] nbd: Remove __force casts
2024-06-04 22:15 [PATCH v3] nbd: Remove __force casts Bart Van Assche
@ 2024-06-05 0:07 ` Chaitanya Kulkarni
2024-06-06 5:39 ` Christoph Hellwig
2024-06-12 20:47 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Chaitanya Kulkarni @ 2024-06-05 0:07 UTC (permalink / raw)
To: Bart Van Assche, Jens Axboe
Cc: linux-block@vger.kernel.org, Christoph Hellwig, Josef Bacik
On 6/4/24 15:15, Bart Van Assche wrote:
> From: Christoph Hellwig <hch@lst.de>
>
> Make it again possible for sparse to verify that blk_status_t and Unix
> error codes are used in the proper context by making nbd_send_cmd()
> return a blk_status_t instead of an integer.
>
> No functionality has been changed.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> [ bvanassche: added description and made two small formatting changes ]
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---
>
Looks good.
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
-ck
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] nbd: Remove __force casts
2024-06-04 22:15 [PATCH v3] nbd: Remove __force casts Bart Van Assche
2024-06-05 0:07 ` Chaitanya Kulkarni
@ 2024-06-06 5:39 ` Christoph Hellwig
2024-06-12 20:47 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2024-06-06 5:39 UTC (permalink / raw)
To: Bart Van Assche; +Cc: Jens Axboe, linux-block, Christoph Hellwig, Josef Bacik
On Tue, Jun 04, 2024 at 04:15:31PM -0600, Bart Van Assche wrote:
> From: Christoph Hellwig <hch@lst.de>
>
> Make it again possible for sparse to verify that blk_status_t and Unix
> error codes are used in the proper context by making nbd_send_cmd()
> return a blk_status_t instead of an integer.
>
> No functionality has been changed.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> [ bvanassche: added description and made two small formatting changes ]
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
I didn't actually add a signoff before, but feel free to keep it.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] nbd: Remove __force casts
2024-06-04 22:15 [PATCH v3] nbd: Remove __force casts Bart Van Assche
2024-06-05 0:07 ` Chaitanya Kulkarni
2024-06-06 5:39 ` Christoph Hellwig
@ 2024-06-12 20:47 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2024-06-12 20:47 UTC (permalink / raw)
To: Bart Van Assche; +Cc: linux-block, Christoph Hellwig, Josef Bacik
On Tue, 04 Jun 2024 16:15:31 -0600, Bart Van Assche wrote:
> Make it again possible for sparse to verify that blk_status_t and Unix
> error codes are used in the proper context by making nbd_send_cmd()
> return a blk_status_t instead of an integer.
>
> No functionality has been changed.
>
>
> [...]
Applied, thanks!
[1/1] nbd: Remove __force casts
commit: 957df9af723ccc570da835978cf7fe7863632842
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-06-12 20:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-04 22:15 [PATCH v3] nbd: Remove __force casts Bart Van Assche
2024-06-05 0:07 ` Chaitanya Kulkarni
2024-06-06 5:39 ` Christoph Hellwig
2024-06-12 20:47 ` Jens Axboe
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).