550-loop-Report-EOPNOTSUPP-properly.patch 1.3 KB

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