diff mbox series

[1/8] loop: move flush_dcache_page to ->complete of request

Message ID 20211025094437.2837701-2-ming.lei@redhat.com (mailing list archive)
State New, archived
Headers show
Series loop: improve dio on backing file | expand

Commit Message

Ming Lei Oct. 25, 2021, 9:44 a.m. UTC
Prepare for unifying backing buffered IO code, so move
flush_dcache_page() into ->complete() of read request.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 drivers/block/loop.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

Comments

Christoph Hellwig Oct. 26, 2021, 7:21 a.m. UTC | #1
Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox series

Patch

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 7bf4686af774..8f140d637435 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -405,8 +405,6 @@  static int lo_read_simple(struct loop_device *lo, struct request *rq,
 		if (len < 0)
 			return len;
 
-		flush_dcache_page(bvec.bv_page);
-
 		if (len != bvec.bv_len) {
 			struct bio *bio;
 
@@ -507,11 +505,24 @@  static int lo_req_flush(struct loop_device *lo, struct request *rq)
 	return ret;
 }
 
+static void lo_flush_dcache_for_read(struct request *rq)
+{
+	struct bio_vec bvec;
+	struct req_iterator iter;
+
+	rq_for_each_segment(bvec, rq, iter)
+		flush_dcache_page(bvec.bv_page);
+}
+
 static void lo_complete_rq(struct request *rq)
 {
 	struct loop_cmd *cmd = blk_mq_rq_to_pdu(rq);
 	blk_status_t ret = BLK_STS_OK;
 
+	/* Kernel wrote to our pages, call flush_dcache_page */
+	if (req_op(rq) == REQ_OP_READ && !cmd->use_aio && cmd->ret >= 0)
+		lo_flush_dcache_for_read(rq);
+
 	if (!cmd->use_aio || cmd->ret < 0 || cmd->ret == blk_rq_bytes(rq) ||
 	    req_op(rq) != REQ_OP_READ) {
 		if (cmd->ret < 0)