Skip to content

Commit 7261d27

Browse files
bvanasschegregkh
authored andcommitted
nbd: Fix signal handling
[ Upstream commit e56d4b6 ] Both nbd_send_cmd() and nbd_handle_cmd() return either a negative error number or a positive blk_status_t value. nbd_queue_rq() converts these return values into a blk_status_t value. There is a bug in the conversion code: if nbd_send_cmd() returns BLK_STS_RESOURCE, nbd_queue_rq() should return BLK_STS_RESOURCE instead of BLK_STS_OK. Fix this, move the conversion code into nbd_handle_cmd() and fix the remaining sparse warnings. This patch fixes the following sparse warnings: drivers/block/nbd.c:673:32: warning: incorrect type in return expression (different base types) drivers/block/nbd.c:673:32: expected int drivers/block/nbd.c:673:32: got restricted blk_status_t [usertype] drivers/block/nbd.c:714:48: warning: incorrect type in return expression (different base types) drivers/block/nbd.c:714:48: expected int drivers/block/nbd.c:714:48: got restricted blk_status_t [usertype] drivers/block/nbd.c:1120:21: warning: incorrect type in assignment (different base types) drivers/block/nbd.c:1120:21: expected int [assigned] ret drivers/block/nbd.c:1120:21: got restricted blk_status_t [usertype] drivers/block/nbd.c:1125:16: warning: incorrect type in return expression (different base types) drivers/block/nbd.c:1125:16: expected restricted blk_status_t drivers/block/nbd.c:1125:16: got int [assigned] ret Cc: Christoph Hellwig <hch@lst.de> Cc: Josef Bacik <jbacik@fb.com> Cc: Yu Kuai <yukuai3@huawei.com> Cc: Markus Pargmann <mpa@pengutronix.de> Fixes: fc17b65 ("blk-mq: switch ->queue_rq return value to blk_status_t") Cc: stable@vger.kernel.org Signed-off-by: Bart Van Assche <bvanassche@acm.org> Link: https://lore.kernel.org/r/20240510202313.25209-6-bvanassche@acm.org Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 193820e commit 7261d27

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

drivers/block/nbd.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,10 @@ static inline int was_interrupted(int result)
569569
return result == -ERESTARTSYS || result == -EINTR;
570570
}
571571

572+
/*
573+
* Returns BLK_STS_RESOURCE if the caller should retry after a delay. Returns
574+
* -EAGAIN if the caller should requeue @cmd. Returns -EIO if sending failed.
575+
*/
572576
static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
573577
{
574578
struct request *req = blk_mq_rq_from_pdu(cmd);
@@ -652,7 +656,7 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
652656
nsock->sent = sent;
653657
}
654658
set_bit(NBD_CMD_REQUEUED, &cmd->flags);
655-
return BLK_STS_RESOURCE;
659+
return (__force int)BLK_STS_RESOURCE;
656660
}
657661
dev_err_ratelimited(disk_to_dev(nbd->disk),
658662
"Send control failed (result %d)\n", result);
@@ -693,7 +697,7 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
693697
nsock->pending = req;
694698
nsock->sent = sent;
695699
set_bit(NBD_CMD_REQUEUED, &cmd->flags);
696-
return BLK_STS_RESOURCE;
700+
return (__force int)BLK_STS_RESOURCE;
697701
}
698702
dev_err(disk_to_dev(nbd->disk),
699703
"Send data failed (result %d)\n",
@@ -990,7 +994,7 @@ static int wait_for_reconnect(struct nbd_device *nbd)
990994
return !test_bit(NBD_RT_DISCONNECTED, &config->runtime_flags);
991995
}
992996

993-
static int nbd_handle_cmd(struct nbd_cmd *cmd, int index)
997+
static blk_status_t nbd_handle_cmd(struct nbd_cmd *cmd, int index)
994998
{
995999
struct request *req = blk_mq_rq_from_pdu(cmd);
9961000
struct nbd_device *nbd = cmd->nbd;
@@ -1004,14 +1008,14 @@ static int nbd_handle_cmd(struct nbd_cmd *cmd, int index)
10041008
if (!config) {
10051009
dev_err_ratelimited(disk_to_dev(nbd->disk),
10061010
"Socks array is empty\n");
1007-
return -EINVAL;
1011+
return BLK_STS_IOERR;
10081012
}
10091013

10101014
if (index >= config->num_connections) {
10111015
dev_err_ratelimited(disk_to_dev(nbd->disk),
10121016
"Attempted send on invalid socket\n");
10131017
nbd_config_put(nbd);
1014-
return -EINVAL;
1018+
return BLK_STS_IOERR;
10151019
}
10161020
cmd->status = BLK_STS_OK;
10171021
again:
@@ -1034,7 +1038,7 @@ static int nbd_handle_cmd(struct nbd_cmd *cmd, int index)
10341038
*/
10351039
sock_shutdown(nbd);
10361040
nbd_config_put(nbd);
1037-
return -EIO;
1041+
return BLK_STS_IOERR;
10381042
}
10391043
goto again;
10401044
}
@@ -1047,7 +1051,7 @@ static int nbd_handle_cmd(struct nbd_cmd *cmd, int index)
10471051
blk_mq_start_request(req);
10481052
if (unlikely(nsock->pending && nsock->pending != req)) {
10491053
nbd_requeue_cmd(cmd);
1050-
ret = 0;
1054+
ret = BLK_STS_OK;
10511055
goto out;
10521056
}
10531057
/*
@@ -1066,19 +1070,19 @@ static int nbd_handle_cmd(struct nbd_cmd *cmd, int index)
10661070
"Request send failed, requeueing\n");
10671071
nbd_mark_nsock_dead(nbd, nsock, 1);
10681072
nbd_requeue_cmd(cmd);
1069-
ret = 0;
1073+
ret = BLK_STS_OK;
10701074
}
10711075
out:
10721076
mutex_unlock(&nsock->tx_lock);
10731077
nbd_config_put(nbd);
1074-
return ret;
1078+
return ret < 0 ? BLK_STS_IOERR : (__force blk_status_t)ret;
10751079
}
10761080

10771081
static blk_status_t nbd_queue_rq(struct blk_mq_hw_ctx *hctx,
10781082
const struct blk_mq_queue_data *bd)
10791083
{
10801084
struct nbd_cmd *cmd = blk_mq_rq_to_pdu(bd->rq);
1081-
int ret;
1085+
blk_status_t ret;
10821086

10831087
/*
10841088
* Since we look at the bio's to send the request over the network we
@@ -1098,10 +1102,6 @@ static blk_status_t nbd_queue_rq(struct blk_mq_hw_ctx *hctx,
10981102
* appropriate.
10991103
*/
11001104
ret = nbd_handle_cmd(cmd, hctx->queue_num);
1101-
if (ret < 0)
1102-
ret = BLK_STS_IOERR;
1103-
else if (!ret)
1104-
ret = BLK_STS_OK;
11051105
mutex_unlock(&cmd->lock);
11061106

11071107
return ret;

0 commit comments

Comments
 (0)