[PATCH] loop: disable write cache in __loop_clr_fd()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <mfo@xxxxxxxxxxxxx>
Co-developed-by: Eric Desrochers <eric.desrochers@xxxxxxxxxxxxx>
Signed-off-by: Eric Desrochers <eric.desrochers@xxxxxxxxxxxxx>
---
 drivers/block/loop.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index a58084c2ed7c..0e23ab151667 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -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);
 
-- 
2.25.1




[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux