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

loop: zero-fill bio on the submitting cpu

In thruth I've just audited which blk-mq drivers don't currently have a
complete callback, but I think this change is at least borderline useful.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarMing Lei <ming.lei@redhat.com>
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
parent 17d5363b
...@@ -445,32 +445,27 @@ static int lo_req_flush(struct loop_device *lo, struct request *rq) ...@@ -445,32 +445,27 @@ static int lo_req_flush(struct loop_device *lo, struct request *rq)
return ret; return ret;
} }
static inline void handle_partial_read(struct loop_cmd *cmd, long bytes) static void lo_complete_rq(struct request *rq)
{ {
if (bytes < 0 || op_is_write(req_op(cmd->rq))) struct loop_cmd *cmd = blk_mq_rq_to_pdu(rq);
return;
if (unlikely(bytes < blk_rq_bytes(cmd->rq))) { if (unlikely(req_op(cmd->rq) == REQ_OP_READ && cmd->use_aio &&
cmd->ret >= 0 && cmd->ret < blk_rq_bytes(cmd->rq))) {
struct bio *bio = cmd->rq->bio; struct bio *bio = cmd->rq->bio;
bio_advance(bio, bytes); bio_advance(bio, cmd->ret);
zero_fill_bio(bio); zero_fill_bio(bio);
} }
blk_mq_end_request(rq, cmd->ret < 0 ? -EIO : 0);
} }
static void lo_rw_aio_complete(struct kiocb *iocb, long ret, long ret2) static void lo_rw_aio_complete(struct kiocb *iocb, long ret, long ret2)
{ {
struct loop_cmd *cmd = container_of(iocb, struct loop_cmd, iocb); struct loop_cmd *cmd = container_of(iocb, struct loop_cmd, iocb);
struct request *rq = cmd->rq;
handle_partial_read(cmd, ret);
if (ret > 0) cmd->ret = ret;
ret = 0; blk_mq_complete_request(cmd->rq, 0);
else if (ret < 0)
ret = -EIO;
blk_mq_complete_request(rq, ret);
} }
static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
...@@ -1688,8 +1683,10 @@ static void loop_handle_cmd(struct loop_cmd *cmd) ...@@ -1688,8 +1683,10 @@ static void loop_handle_cmd(struct loop_cmd *cmd)
ret = do_req_filebacked(lo, cmd->rq); ret = do_req_filebacked(lo, cmd->rq);
failed: failed:
/* complete non-aio request */ /* complete non-aio request */
if (!cmd->use_aio || ret) if (!cmd->use_aio || ret) {
blk_mq_complete_request(cmd->rq, ret ? -EIO : 0); cmd->ret = ret ? -EIO : 0;
blk_mq_complete_request(cmd->rq, 0);
}
} }
static void loop_queue_work(struct kthread_work *work) static void loop_queue_work(struct kthread_work *work)
...@@ -1715,6 +1712,7 @@ static int loop_init_request(void *data, struct request *rq, ...@@ -1715,6 +1712,7 @@ static int loop_init_request(void *data, struct request *rq,
static const struct blk_mq_ops loop_mq_ops = { static const struct blk_mq_ops loop_mq_ops = {
.queue_rq = loop_queue_rq, .queue_rq = loop_queue_rq,
.init_request = loop_init_request, .init_request = loop_init_request,
.complete = lo_complete_rq,
}; };
static int loop_add(struct loop_device **l, int i) static int loop_add(struct loop_device **l, int i)
......
...@@ -70,6 +70,7 @@ struct loop_cmd { ...@@ -70,6 +70,7 @@ struct loop_cmd {
struct request *rq; struct request *rq;
struct list_head list; struct list_head list;
bool use_aio; /* use AIO interface to handle I/O */ bool use_aio; /* use AIO interface to handle I/O */
long ret;
struct kiocb iocb; struct kiocb iocb;
}; };
......
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