Skip to contentSkip to conversation

loop: add file_start_write() and file_end_write()

PATCH Applied Ming Lei 3 participants 4 messages May 27, 2025 Block layer

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

PATCH v2 1/1 loop: add file_start_write() and file_end_write()

file_start_write() and file_end_write() should be added around ->write_iter().

Recently we switch to ->write_iter() from vfs_iter_write(), and the implied fs_start_write() and fs_end_write() are lost.

Also we never add them for dio code path, so add them back for covering both.

Cc Jeff Moyer <[email protected]>
Fixes f2fed441c69b ("loop: stop using vfs_iter_{read,write} for buffered I/O")
Fixes bc07c10a3603 ("block: loop: support DIO & AIO")

---
V2:
- fix commit log & patch title

 drivers/block/loop.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/block/loop.c +6 -2
index b8ba7de08753..7eca957dc656 100644
@@ -308,11 +308,14 @@ static void lo_complete_rq(struct request *rq)
 static void lo_rw_aio_do_completion(struct loop_cmd *cmd)
 {
 	struct request *rq = blk_mq_rq_from_pdu(cmd);
+	struct loop_device *lo = rq->q->queuedata;
 
 	if (!atomic_dec_and_test(&cmd->ref))
 		return;
 	kfree(cmd->bvec);
 	cmd->bvec = NULL;
+	if (req_op(rq) == REQ_OP_WRITE)
+		file_end_write(lo->lo_backing_file);
 	if (likely(!blk_should_fake_timeout(rq->q)))
 		blk_mq_complete_request(rq);
 }
@@ -387,9 +390,10 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
 		cmd->iocb.ki_flags = 0;
 	}
 
-	if (rw == ITER_SOURCE)
+	if (rw == ITER_SOURCE) {
+		file_start_write(lo->lo_backing_file);
 		ret = file->f_op->write_iter(&cmd->iocb, &iter);
-	else
+	} else
 		ret = file->f_op->read_iter(&cmd->iocb, &iter);
 
 	lo_rw_aio_do_completion(cmd);
Signature · 1 line
2.47.0
maintainer Applied
#1 lore raw
Quoted 9 lines · Ming Lei

file_start_write() and file_end_write() should be added around ->write_iter().

Recently we switch to ->write_iter() from vfs_iter_write(), and the implied fs_start_write() and fs_end_write() are lost.

Also we never add them for dio code path, so add them back for covering both.

[...]

Applied, thanks!

[1/1] loop: add file_start_write() and file_end_write()
(no commit info)

Best regards,

Signature · 1 line
Jens Axboe
#2 lore raw
In reply to Ming Lei
Quoted 5 lines · Ming Lei

file_start_write() and file_end_write() should be added around ->write_iter().

Recently we switch to ->write_iter() from vfs_iter_write(), and the implied fs_start_write() and fs_end_write() are lost.

Still referring to "fs_start_write()" and "fs_end_write()" here

Quoted 50 lines

Also we never add them for dio code path, so add them back for covering both.

Cc Jeff Moyer <[email protected]>
Fixes f2fed441c69b ("loop: stop using vfs_iter_{read,write} for buffered I/O")
Fixes bc07c10a3603 ("block: loop: support DIO & AIO")

---
V2:
- fix commit log & patch title

 drivers/block/loop.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/block/loop.c +6 -3
index b8ba7de08753..7eca957dc656 100644
@@ -308,11 +308,14 @@ static void lo_complete_rq(struct request *rq)
 static void lo_rw_aio_do_completion(struct loop_cmd *cmd)
 {
        struct request *rq = blk_mq_rq_from_pdu(cmd);
+       struct loop_device *lo = rq->q->queuedata;
 
        if (!atomic_dec_and_test(&cmd->ref))
                return;
        kfree(cmd->bvec);
        cmd->bvec = NULL;
+       if (req_op(rq) == REQ_OP_WRITE)
+               file_end_write(lo->lo_backing_file);
        if (likely(!blk_should_fake_timeout(rq->q)))
                blk_mq_complete_request(rq);
 }
@@ -387,9 +390,10 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
                cmd->iocb.ki_flags = 0;
        }
 
-       if (rw == ITER_SOURCE)
+       if (rw == ITER_SOURCE) {
+               file_start_write(lo->lo_backing_file);
                ret = file->f_op->write_iter(&cmd->iocb, &iter);
-       else
+       } else
                ret = file->f_op->read_iter(&cmd->iocb, &iter);
 
        lo_rw_aio_do_completion(cmd);
--

2.47.0

maintainer
#3 lore raw
Quoted 8 lines · Caleb Sander Mateos
Quoted 5 lines · Ming Lei

file_start_write() and file_end_write() should be added around ->write_iter().

Recently we switch to ->write_iter() from vfs_iter_write(), and the implied fs_start_write() and fs_end_write() are lost.

Still referring to "fs_start_write()" and "fs_end_write()" here

I fixed it up.

Signature · 1 line
Jens Axboe