提交 fe2cb290 编写于 作者: C Christoph Hellwig 提交者: 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: NChristoph Hellwig <hch@lst.de>
Reviewed-by: NMing Lei <ming.lei@redhat.com>
Signed-off-by: NJens Axboe <axboe@fb.com>
上级 17d5363b
......@@ -445,32 +445,27 @@ static int lo_req_flush(struct loop_device *lo, struct request *rq)
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)))
return;
struct loop_cmd *cmd = blk_mq_rq_to_pdu(rq);
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;
bio_advance(bio, bytes);
bio_advance(bio, cmd->ret);
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)
{
struct loop_cmd *cmd = container_of(iocb, struct loop_cmd, iocb);
struct request *rq = cmd->rq;
handle_partial_read(cmd, ret);
if (ret > 0)
ret = 0;
else if (ret < 0)
ret = -EIO;
blk_mq_complete_request(rq, ret);
cmd->ret = ret;
blk_mq_complete_request(cmd->rq, 0);
}
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)
ret = do_req_filebacked(lo, cmd->rq);
failed:
/* complete non-aio request */
if (!cmd->use_aio || ret)
blk_mq_complete_request(cmd->rq, ret ? -EIO : 0);
if (!cmd->use_aio || ret) {
cmd->ret = ret ? -EIO : 0;
blk_mq_complete_request(cmd->rq, 0);
}
}
static void loop_queue_work(struct kthread_work *work)
......@@ -1715,6 +1712,7 @@ static int loop_init_request(void *data, struct request *rq,
static const struct blk_mq_ops loop_mq_ops = {
.queue_rq = loop_queue_rq,
.init_request = loop_init_request,
.complete = lo_complete_rq,
};
static int loop_add(struct loop_device **l, int i)
......
......@@ -70,6 +70,7 @@ struct loop_cmd {
struct request *rq;
struct list_head list;
bool use_aio; /* use AIO interface to handle I/O */
long ret;
struct kiocb iocb;
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册