Skip to content

Commit e56d4b6

Browse files
bvanasscheaxboe
authored andcommitted
nbd: Fix signal handling
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 <[email protected]> Cc: Josef Bacik <[email protected]> Cc: Yu Kuai <[email protected]> Cc: Markus Pargmann <[email protected]> Fixes: fc17b65 ("blk-mq: switch ->queue_rq return value to blk_status_t") Cc: [email protected] Signed-off-by: Bart Van Assche <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent f6cb9a2 commit e56d4b6

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

drivers/block/nbd.c

+14-14
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,10 @@ static inline int was_interrupted(int result)
588588
return result == -ERESTARTSYS || result == -EINTR;
589589
}
590590

591+
/*
592+
* Returns BLK_STS_RESOURCE if the caller should retry after a delay. Returns
593+
* -EAGAIN if the caller should requeue @cmd. Returns -EIO if sending failed.
594+
*/
591595
static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
592596
{
593597
struct request *req = blk_mq_rq_from_pdu(cmd);
@@ -670,7 +674,7 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
670674
nsock->sent = sent;
671675
}
672676
set_bit(NBD_CMD_REQUEUED, &cmd->flags);
673-
return BLK_STS_RESOURCE;
677+
return (__force int)BLK_STS_RESOURCE;
674678
}
675679
dev_err_ratelimited(disk_to_dev(nbd->disk),
676680
"Send control failed (result %d)\n", result);
@@ -711,7 +715,7 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
711715
nsock->pending = req;
712716
nsock->sent = sent;
713717
set_bit(NBD_CMD_REQUEUED, &cmd->flags);
714-
return BLK_STS_RESOURCE;
718+
return (__force int)BLK_STS_RESOURCE;
715719
}
716720
dev_err(disk_to_dev(nbd->disk),
717721
"Send data failed (result %d)\n",
@@ -1008,7 +1012,7 @@ static int wait_for_reconnect(struct nbd_device *nbd)
10081012
return !test_bit(NBD_RT_DISCONNECTED, &config->runtime_flags);
10091013
}
10101014

1011-
static int nbd_handle_cmd(struct nbd_cmd *cmd, int index)
1015+
static blk_status_t nbd_handle_cmd(struct nbd_cmd *cmd, int index)
10121016
{
10131017
struct request *req = blk_mq_rq_from_pdu(cmd);
10141018
struct nbd_device *nbd = cmd->nbd;
@@ -1022,14 +1026,14 @@ static int nbd_handle_cmd(struct nbd_cmd *cmd, int index)
10221026
if (!config) {
10231027
dev_err_ratelimited(disk_to_dev(nbd->disk),
10241028
"Socks array is empty\n");
1025-
return -EINVAL;
1029+
return BLK_STS_IOERR;
10261030
}
10271031

10281032
if (index >= config->num_connections) {
10291033
dev_err_ratelimited(disk_to_dev(nbd->disk),
10301034
"Attempted send on invalid socket\n");
10311035
nbd_config_put(nbd);
1032-
return -EINVAL;
1036+
return BLK_STS_IOERR;
10331037
}
10341038
cmd->status = BLK_STS_OK;
10351039
again:
@@ -1052,7 +1056,7 @@ static int nbd_handle_cmd(struct nbd_cmd *cmd, int index)
10521056
*/
10531057
sock_shutdown(nbd);
10541058
nbd_config_put(nbd);
1055-
return -EIO;
1059+
return BLK_STS_IOERR;
10561060
}
10571061
goto again;
10581062
}
@@ -1065,7 +1069,7 @@ static int nbd_handle_cmd(struct nbd_cmd *cmd, int index)
10651069
blk_mq_start_request(req);
10661070
if (unlikely(nsock->pending && nsock->pending != req)) {
10671071
nbd_requeue_cmd(cmd);
1068-
ret = 0;
1072+
ret = BLK_STS_OK;
10691073
goto out;
10701074
}
10711075
/*
@@ -1084,19 +1088,19 @@ static int nbd_handle_cmd(struct nbd_cmd *cmd, int index)
10841088
"Request send failed, requeueing\n");
10851089
nbd_mark_nsock_dead(nbd, nsock, 1);
10861090
nbd_requeue_cmd(cmd);
1087-
ret = 0;
1091+
ret = BLK_STS_OK;
10881092
}
10891093
out:
10901094
mutex_unlock(&nsock->tx_lock);
10911095
nbd_config_put(nbd);
1092-
return ret;
1096+
return ret < 0 ? BLK_STS_IOERR : (__force blk_status_t)ret;
10931097
}
10941098

10951099
static blk_status_t nbd_queue_rq(struct blk_mq_hw_ctx *hctx,
10961100
const struct blk_mq_queue_data *bd)
10971101
{
10981102
struct nbd_cmd *cmd = blk_mq_rq_to_pdu(bd->rq);
1099-
int ret;
1103+
blk_status_t ret;
11001104

11011105
/*
11021106
* Since we look at the bio's to send the request over the network we
@@ -1116,10 +1120,6 @@ static blk_status_t nbd_queue_rq(struct blk_mq_hw_ctx *hctx,
11161120
* appropriate.
11171121
*/
11181122
ret = nbd_handle_cmd(cmd, hctx->queue_num);
1119-
if (ret < 0)
1120-
ret = BLK_STS_IOERR;
1121-
else if (!ret)
1122-
ret = BLK_STS_OK;
11231123
mutex_unlock(&cmd->lock);
11241124

11251125
return ret;

0 commit comments

Comments
 (0)