loop: disable write cache in __loop_clr_fd()
PATCH 1/1 loop: disable write cache in __loop_clr_fd()
A detached loop device can hit an I/O error on fsync() if it was previously associated/attached.
This happens because the write cache is enabled in loop_configure() in the attach path, but not disabled anywhere in the detach path.
So, disable write cache in the detach path.
Before:
# losetup /dev/loop7 disk.img # losetup -d /dev/loop7 # strace -e fsync parted -s /dev/loop7 unit s print 2>&1 | grep fsync fsync(3) = -1 EIO (Input/output error) Warning: Error fsyncing/closing /dev/loop7: Input/output error [ 34.696133] blk_update_request: I/O error, dev loop7, sector 0 op 0x1:(WRITE) flags 0x800 phys_seg 0 prio class 0
After:
# losetup /dev/loop7 disk.img # losetup -d /dev/loop7 # strace -e fsync parted -s /dev/loop7 unit s print 2>&1 | grep fsync fsync(3) = 0
Signed-off-by Mauricio Faria de Oliveira <[email protected]>
Co-developed-by Eric Desrochers <[email protected]>
Signed-off-by Eric Desrochers <[email protected]>
--- drivers/block/loop.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/block/loop.c +3 -0
@@ -1223,6 +1223,9 @@ static int __loop_clr_fd(struct loop_device *lo, bool release) goto out_unlock; } +if (!(lo->lo_flags &LO_FLAGS_READ_ONLY ) && filp->f_op->fsync) +blk_queue_write_cache (lo->lo_queue, false, false); +/* freeze request queue during the transition */ blk_mq_freeze_queue (lo->lo_queue);
Signature · 1 line
2.25.1