Skip to content

Commit fe2cb29

Browse files
Christoph Hellwigaxboe
authored andcommitted
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: Christoph Hellwig <hch@lst.de> Reviewed-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent 17d5363 commit fe2cb29

2 files changed

Lines changed: 15 additions & 16 deletions

File tree

drivers/block/loop.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -445,32 +445,27 @@ static int lo_req_flush(struct loop_device *lo, struct request *rq)
445445
return ret;
446446
}
447447

448-
static inline void handle_partial_read(struct loop_cmd *cmd, long bytes)
448+
static void lo_complete_rq(struct request *rq)
449449
{
450-
if (bytes < 0 || op_is_write(req_op(cmd->rq)))
451-
return;
450+
struct loop_cmd *cmd = blk_mq_rq_to_pdu(rq);
452451

453-
if (unlikely(bytes < blk_rq_bytes(cmd->rq))) {
452+
if (unlikely(req_op(cmd->rq) == REQ_OP_READ && cmd->use_aio &&
453+
cmd->ret >= 0 && cmd->ret < blk_rq_bytes(cmd->rq))) {
454454
struct bio *bio = cmd->rq->bio;
455455

456-
bio_advance(bio, bytes);
456+
bio_advance(bio, cmd->ret);
457457
zero_fill_bio(bio);
458458
}
459+
460+
blk_mq_end_request(rq, cmd->ret < 0 ? -EIO : 0);
459461
}
460462

461463
static void lo_rw_aio_complete(struct kiocb *iocb, long ret, long ret2)
462464
{
463465
struct loop_cmd *cmd = container_of(iocb, struct loop_cmd, iocb);
464-
struct request *rq = cmd->rq;
465-
466-
handle_partial_read(cmd, ret);
467466

468-
if (ret > 0)
469-
ret = 0;
470-
else if (ret < 0)
471-
ret = -EIO;
472-
473-
blk_mq_complete_request(rq, ret);
467+
cmd->ret = ret;
468+
blk_mq_complete_request(cmd->rq, 0);
474469
}
475470

476471
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)
16881683
ret = do_req_filebacked(lo, cmd->rq);
16891684
failed:
16901685
/* complete non-aio request */
1691-
if (!cmd->use_aio || ret)
1692-
blk_mq_complete_request(cmd->rq, ret ? -EIO : 0);
1686+
if (!cmd->use_aio || ret) {
1687+
cmd->ret = ret ? -EIO : 0;
1688+
blk_mq_complete_request(cmd->rq, 0);
1689+
}
16931690
}
16941691

16951692
static void loop_queue_work(struct kthread_work *work)
@@ -1715,6 +1712,7 @@ static int loop_init_request(void *data, struct request *rq,
17151712
static const struct blk_mq_ops loop_mq_ops = {
17161713
.queue_rq = loop_queue_rq,
17171714
.init_request = loop_init_request,
1715+
.complete = lo_complete_rq,
17181716
};
17191717

17201718
static int loop_add(struct loop_device **l, int i)

drivers/block/loop.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ struct loop_cmd {
7070
struct request *rq;
7171
struct list_head list;
7272
bool use_aio; /* use AIO interface to handle I/O */
73+
long ret;
7374
struct kiocb iocb;
7475
};
7576

0 commit comments

Comments
 (0)