Skip to contentSkip to conversation

HTML message rejected: Re: [PATCH] loop: move vfs_fsync() out of loop_update_dio()

DISCUSSION Kun Hu 1 participant 1 message Mar 19, 2025 1 message not in the archive Block layer

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Kun Hu

author
#1 lore raw
Quoted 106 lines

下面是被转发的邮件:

发件人: [email protected]
主题: HTML message rejected: Re: [PATCH] loop: move vfs_fsync() out of loop_update_dio() 日期: 2025年3月19日 GMT+8 09:29:24
收件人: [email protected]

Greetings!

This is the mlmmj program managing the <[email protected]> mailing list.

Your message to <[email protected]> was not delivered to the list because it contained a HTML part. Only text/plain messages are allowed on this list.

Please configure your mail client to only send plain text mail.

For your reference, the rejected message follows below.

发件人: Kun Hu <[email protected]>
主题: 回复:[PATCH] loop: move vfs_fsync() out of loop_update_dio()
日期: 2025年3月19日 GMT+8 09:28:24
收件人: Ming Lei <[email protected]>
抄送: linux-block <[email protected]>, Christoph Hellwig <[email protected]>, "[email protected]" <[email protected]>

Quoted 60 lines

2025年3月18日 09:07,Ming Lei <[email protected]> 写道:

Quoted 47 lines · 胡焜
Quoted 47 lines

drivers/block/loop.c | 12 ++++++------

1 file changed, 6 insertions(+), 6 deletions(-)
drivers/block/loop.c +6 -6
index 1ec7417c7f00..be7e20064427 100644
@@ -205,8 +205,6 @@ static bool lo_can_use_dio(struct loop_device *lo)
 */
 static inline void loop_update_dio(struct loop_device *lo)
 {
- bool dio_in_use = lo->lo_flags & LO_FLAGS_DIRECT_IO;
-
 lockdep_assert_held(&lo->lo_mutex);
 WARN_ON_ONCE(lo->lo_state == Lo_bound &&
      lo->lo_queue->mq_freeze_depth == 0);
@@ -215,10 +213,6 @@ static inline void loop_update_dio(struct loop_device *lo)
 lo->lo_flags |= LO_FLAGS_DIRECT_IO;
 if ((lo->lo_flags & LO_FLAGS_DIRECT_IO) && !lo_can_use_dio(lo))
 lo->lo_flags &= ~LO_FLAGS_DIRECT_IO;
-
- /* flush dirty pages before starting to issue direct I/O */
- if ((lo->lo_flags & LO_FLAGS_DIRECT_IO) && !dio_in_use)
- vfs_fsync(lo->lo_backing_file, 0);
 }
 
 /**
@@ -621,6 +615,9 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
 if (get_loop_size(lo, file) != get_loop_size(lo, old_file))
 goto out_err;
 
+ /* may work in dio, so flush page cache for avoiding race */
+ vfs_fsync(file, 0);
+
 /* and ... switch */
 disk_force_media_change(lo->lo_disk);
 blk_mq_freeze_queue(lo->lo_queue);
@@ -1098,6 +1095,9 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
 if (error)
 goto out_unlock;
 
+ /* may work in dio, so flush page cache for avoiding race */
+ vfs_fsync(file, 0);
+
 loop_update_dio(lo);
 loop_sysfs_init(lo);
 
Quoted 7 lines
Quoted 2 lines

--
2.44.0

Hello Ming,

I would like to double check that this fix doesn't seem to have been merged into the main thread, will this version still be merged into mainline kernel tree?

The V2 has been sent out after updating comment, please verify if it fixes your issue:

Quoted 7 lines

https://lore.kernel.org/linux-block/[email protected]/

If yes, feel free to provide one tested-by for moving on.

Thanks,
Ming

Thank you very much, this crash has not triggered again after several rounds of testing!

Best,
Kun