linux/drivers
Mauricio Faria de Oliveira 4ceddce55e loop: fix I/O error on fsync() in detached loop devices
There's an I/O error on fsync() in a detached loop device
if it has been previously attached.

The issue is write cache is enabled in the attach path in
loop_configure() but it isn't disabled in the detach path;
thus it remains enabled in the block device regardless of
whether it is attached or not.

Now fsync() can get an I/O request that will just be failed
later in loop_queue_rq() as device's state is not 'Lo_bound'.

So, disable write cache in the detach path.

Do so based on the queue flag, not the loop device flag for
read-only (used to enable) as the queue flag can be changed
via sysfs even on read-only loop devices (e.g., losetup -r.)

Test-case:

    # DEV=/dev/loop7

    # IMG=/tmp/image
    # truncate --size 1M $IMG

    # losetup $DEV $IMG
    # losetup -d $DEV

Before:

    # strace -e fsync parted -s $DEV print 2>&1 | grep fsync
    fsync(3)                                = -1 EIO (Input/output error)
    Warning: Error fsyncing/closing /dev/loop7: Input/output error
    [  982.529929] blk_update_request: I/O error, dev loop7, sector 0 op 0x1:(WRITE) flags 0x800 phys_seg 0 prio class 0

After:

    # strace -e fsync parted -s $DEV print 2>&1 | grep fsync
    fsync(3)                                = 0

Co-developed-by: Eric Desrochers <eric.desrochers@canonical.com>
Signed-off-by: Eric Desrochers <eric.desrochers@canonical.com>
Signed-off-by: Mauricio Faria de Oliveira <mfo@canonical.com>
Tested-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2021-02-22 08:43:57 -07:00
..
accessibility
acpi media updates for v5.12-rc1 2021-02-21 14:10:36 -08:00
amba
android
ata
atm atm: idt77252: fix build broken on amd64 2021-02-15 12:36:27 -08:00
auxdisplay
base sound updates for 5.12 2021-02-21 14:21:35 -08:00
bcma
block loop: fix I/O error on fsync() in detached loop devices 2021-02-22 08:43:57 -07:00
bluetooth TTY/Serial driver changes for 5.12-rc1 2021-02-20 21:28:04 -08:00
bus ARM: SoC drivers for v5.12 2021-02-20 18:42:28 -08:00
cdrom
char Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6 2021-02-21 17:23:56 -08:00
clk Power management updates for 5.12-rc1 2021-02-20 21:42:18 -08:00
clocksource hyperv-next for 5.12 2021-02-21 13:24:39 -08:00
connector
counter
cpufreq Merge branch 'pm-opp' into pm 2021-02-15 17:01:46 +01:00
cpuidle
crypto Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6 2021-02-21 17:23:56 -08:00
dax
dca
devfreq Merge branches 'pm-devfreq' and 'pm-tools' 2021-02-15 17:02:04 +01:00
dio
dma dmaengine dw: Revert "dmaengine: dw: Enable runtime PM" 2021-02-08 17:36:12 +05:30
dma-buf dma-buf: Avoid comma separated statements 2021-02-09 17:14:11 +01:00
edac Merge branch 'edac-misc' into edac-updates-for-v5.12 2021-02-15 10:06:58 +01:00
eisa
extcon
firewire
firmware arm64 updates for 5.12 2021-02-21 13:08:42 -08:00
fpga
fsi
gnss
gpio gpio: ep93xx: Fix single irqchip with multi gpiochips 2021-02-10 14:47:27 +01:00
gpu drm pull for 5.12-rc1 2021-02-21 14:44:44 -08:00
greybus
hid Staging/IIO driver patches for 5.12-rc1 2021-02-20 21:36:51 -08:00
hsi
hv Revert "Drivers: hv: vmbus: Copy packets sent by Hyper-V out of the ring buffer" 2021-02-15 10:49:11 +00:00
hwmon
hwspinlock
hwtracing
i2c sound updates for 5.12 2021-02-21 14:21:35 -08:00
i3c
ide
idle
iio
infiniband
input sound updates for 5.12 2021-02-21 14:21:35 -08:00
interconnect
iommu hyperv-next for 5.12 2021-02-21 13:24:39 -08:00
ipack
irqchip irqchip updates for Linux 5.12: 2021-02-15 15:41:56 +01:00
isdn
leds TTY/Serial driver changes for 5.12-rc1 2021-02-20 21:28:04 -08:00
lightnvm lightnvm: pblk: Replace guid_copy() with export_guid()/import_guid() 2021-02-14 21:27:24 -07:00
macintosh
mailbox
mcb
md for-5.12/drivers-2021-02-17 2021-02-21 11:06:54 -08:00
media sound updates for 5.12 2021-02-21 14:21:35 -08:00
memory Memory controller drivers for v5.12, part two 2021-02-11 13:48:49 +01:00
memstick
message
mfd sound updates for 5.12 2021-02-21 14:21:35 -08:00
misc
mmc for-5.12/block-2021-02-17 2021-02-21 11:02:48 -08:00
most
mtd This pull request contains changes (actually just fixes) for UBIFS 2021-02-21 13:57:08 -08:00
mux
net Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6 2021-02-21 17:23:56 -08:00
nfc nfc: st-nci: Remove unnecessary variable 2021-02-08 14:56:20 -08:00
ntb
nubus
nvdimm for-5.12/block-2021-02-17 2021-02-21 11:02:48 -08:00
nvme for-5.12/drivers-2021-02-17 2021-02-21 11:06:54 -08:00
nvmem
of
opp OPP: Add function to look up required OPP's for a given OPP 2021-02-04 16:30:14 +05:30
parisc
parport
pci drm pull for 5.12-rc1 2021-02-21 14:44:44 -08:00
pcmcia
perf drivers/perf: Replace spin_lock_irqsave to spin_lock 2021-02-10 18:50:42 +00:00
phy
pinctrl
platform ACPI updates for 5.12-rc1 2021-02-20 21:50:59 -08:00
pnp
power
powercap powercap: intel_rapl: Use topology interface in rapl_init_domains() 2021-02-12 16:53:01 +01:00
pps
ps3
ptp ptp: ptp_clockmatrix: clean-up - parenthesis around a == b are unnecessary 2021-02-17 13:49:26 -08:00
pwm
rapidio
ras
regulator
remoteproc
reset ARM: SoC drivers for v5.12 2021-02-20 18:42:28 -08:00
rpmsg
rtc rtc: mc146818: Dont test for bit 0-5 in Register D 2021-02-02 20:35:02 +01:00
s390 s390 updates for the 5.12 merge window 2021-02-21 13:40:06 -08:00
sbus
scsi sound updates for 5.12 2021-02-21 14:21:35 -08:00
sfi
sh
siox
slimbus
soc drm pull for 5.12-rc1 2021-02-21 14:44:44 -08:00
soundwire
spi ACPI updates for 5.12-rc1 2021-02-20 21:50:59 -08:00
spmi
ssb
staging media updates for v5.12-rc1 2021-02-21 14:10:36 -08:00
target for-5.12/block-2021-02-17 2021-02-21 11:02:48 -08:00
tc
tee Simplify i2c acess in OP-TEE driver 2021-02-09 16:10:49 +01:00
thermal Scheduler updates for v5.12: 2021-02-21 12:35:04 -08:00
thunderbolt thunderbolt: Changes for v5.12 merge window 2021-02-09 13:00:07 +01:00
tty TTY/Serial driver changes for 5.12-rc1 2021-02-20 21:28:04 -08:00
uio
usb usb: misc: usb3503: Fix logic in usb3503_init() 2021-02-11 13:52:04 +01:00
vdpa vdpa/mlx5: Restore the hardware used index after change map 2021-02-05 10:28:04 -05:00
vfio
vhost
video drm pull for 5.12-rc1 2021-02-21 14:44:44 -08:00
virt
virtio
visorbus
vlynq
vme
w1
watchdog
xen xen: branch for v5.12-rc1 2021-02-21 13:06:08 -08:00
zorro
Kconfig
Makefile