blob: 29a8d84e46eb3c60cae1651e5ca0b0087993b1dc [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001From 2e864386e62e702a343be2507062ee08d5dfc810 Mon Sep 17 00:00:00 2001
2From: Evan Green <evgreen@chromium.org>
3Date: Thu, 14 Nov 2019 15:50:07 -0800
4Subject: loop: Report EOPNOTSUPP properly
5
6Properly plumb out EOPNOTSUPP from loop driver operations, which may
7get returned when for instance a discard operation is attempted but not
8supported by the underlying block device. Before this change, everything
9was reported in the log as an I/O error, which is scary and not
10helpful in debugging.
11
12Signed-off-by: Evan Green <evgreen@chromium.org>
13Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
14Reviewed-by: Bart Van Assche <bvanassche@acm.org>
15---
16 drivers/block/loop.c | 7 +++++--
17 1 file changed, 5 insertions(+), 2 deletions(-)
18
19--- a/drivers/block/loop.c
20+++ b/drivers/block/loop.c
21@@ -462,7 +462,7 @@ static void lo_complete_rq(struct reques
22 if (!cmd->use_aio || cmd->ret < 0 || cmd->ret == blk_rq_bytes(rq) ||
23 req_op(rq) != REQ_OP_READ) {
24 if (cmd->ret < 0)
25- ret = BLK_STS_IOERR;
26+ ret = errno_to_blk_status(cmd->ret);
27 goto end_io;
28 }
29
30@@ -1978,7 +1978,10 @@ static void loop_handle_cmd(struct loop_
31 failed:
32 /* complete non-aio request */
33 if (!cmd->use_aio || ret) {
34- cmd->ret = ret ? -EIO : 0;
35+ if (ret == -EOPNOTSUPP)
36+ cmd->ret = ret;
37+ else
38+ cmd->ret = ret ? -EIO : 0;
39 blk_mq_complete_request(rq);
40 }
41 }