Commit c1c87c2b authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

loop: make do_req_filebacked more robust

Use a switch statement to iterate over the possible operations and
error out if it's an incorrect one.
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
parent f0225cac
...@@ -510,14 +510,10 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, ...@@ -510,14 +510,10 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
return 0; return 0;
} }
static int do_req_filebacked(struct loop_device *lo, struct request *rq)
static inline int lo_rw_simple(struct loop_device *lo,
struct request *rq, loff_t pos, bool rw)
{ {
struct loop_cmd *cmd = blk_mq_rq_to_pdu(rq); struct loop_cmd *cmd = blk_mq_rq_to_pdu(rq);
loff_t pos = ((loff_t) blk_rq_pos(rq) << 9) + lo->lo_offset;
if (cmd->use_aio)
return lo_rw_aio(lo, cmd, pos, rw);
/* /*
* lo_write_simple and lo_read_simple should have been covered * lo_write_simple and lo_read_simple should have been covered
...@@ -528,37 +524,30 @@ static inline int lo_rw_simple(struct loop_device *lo, ...@@ -528,37 +524,30 @@ static inline int lo_rw_simple(struct loop_device *lo,
* of the req at one time. And direct read IO doesn't need to * of the req at one time. And direct read IO doesn't need to
* run flush_dcache_page(). * run flush_dcache_page().
*/ */
if (rw == WRITE) switch (req_op(rq)) {
return lo_write_simple(lo, rq, pos); case REQ_OP_FLUSH:
else return lo_req_flush(lo, rq);
return lo_read_simple(lo, rq, pos); case REQ_OP_DISCARD:
} return lo_discard(lo, rq, pos);
case REQ_OP_WRITE:
static int do_req_filebacked(struct loop_device *lo, struct request *rq) if (lo->transfer)
{ return lo_write_transfer(lo, rq, pos);
loff_t pos; else if (cmd->use_aio)
int ret; return lo_rw_aio(lo, cmd, pos, WRITE);
pos = ((loff_t) blk_rq_pos(rq) << 9) + lo->lo_offset;
if (op_is_write(req_op(rq))) {
if (req_op(rq) == REQ_OP_FLUSH)
ret = lo_req_flush(lo, rq);
else if (req_op(rq) == REQ_OP_DISCARD)
ret = lo_discard(lo, rq, pos);
else if (lo->transfer)
ret = lo_write_transfer(lo, rq, pos);
else else
ret = lo_rw_simple(lo, rq, pos, WRITE); return lo_write_simple(lo, rq, pos);
case REQ_OP_READ:
} else {
if (lo->transfer) if (lo->transfer)
ret = lo_read_transfer(lo, rq, pos); return lo_read_transfer(lo, rq, pos);
else if (cmd->use_aio)
return lo_rw_aio(lo, cmd, pos, READ);
else else
ret = lo_rw_simple(lo, rq, pos, READ); return lo_read_simple(lo, rq, pos);
default:
WARN_ON_ONCE(1);
return -EIO;
break;
} }
return ret;
} }
struct switch_request { struct switch_request {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment