# dd if=/dev/zero of=/dev/bcache0 bs=4k
[ 120.268072] Buffer I/O error on dev bcache0, logical block 0, lost async page write
[ 120.271978] Buffer I/O error on dev bcache0, logical block 1, lost async page write
[ 120.274554] Buffer I/O error on dev bcache0, logical block 2, lost async page write
[ 120.276671] Buffer I/O error on dev bcache0, logical block 3, lost async page write
[ 120.278760] Buffer I/O error on dev bcache0, logical block 4, lost async page write
[ 120.288042] Buffer I/O error on dev bcache0, logical block 5, lost async page write
[ 120.290178] Buffer I/O error on dev bcache0, logical block 6, lost async page write
[ 120.296043] Buffer I/O error on dev bcache0, logical block 7, lost async page write
[ 120.298167] Buffer I/O error on dev bcache0, logical block 8, lost async page write
[ 120.300220] Buffer I/O error on dev bcache0, logical block 3260, lost async page write
dd: error writing '/dev/bcache0': No space left on device
262143+0 records in
262142+0 records out
1073733632 bytes (1.1 GB, 1.0 GiB) copied, 3.49705 s, 307 MB/s
# lsblk -e 252
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 1G 0 loop
└─fake-loop0 253:0 0 1024M 0 dm
└─bcache0 251:0 0 1024M 0 disk
I/O Error Test 5
================
commit "bcache: stop bcache device when backing device is offline"
Problem: bcache is unaware that a backing device goes offline,
and accepts writes.
Original kernel: bcache doesn't realize backing device is offline.
Modified kernel: bcache device is removed after backing device is offline.
Original
--------
# uname -rv
4.15.0-55-generic #60-Ubuntu SMP Tue Jul 2 18:22:20 UTC 2019
# apt install -y linux-modules- extra-$ (uname -r)=4.15.0-55.60
# modprobe scsi_debug dev_size_mb=1024
dev_ size_mb= 1024, opts=0x0, submit_queues=1, statistics=0
# dmesg | tail
[ 17.339336] scsi host2: scsi_debug: version 1.86 [20160430]
[ 17.339667] scsi 2:0:0:0: Direct-Access Linux scsi_debug 0186 PQ: 0 ANSI: 7
[ 17.339989] sd 2:0:0:0: Power-on or device reset occurred
[ 17.340184] sd 2:0:0:0: Attached scsi generic sg0 type 0
[ 17.348436] sd 2:0:0:0: [sda] 2097152 512-byte logical blocks: (1.07 GB/1.00 GiB)
[ 17.352496] sd 2:0:0:0: [sda] Write Protect is off
[ 17.352501] sd 2:0:0:0: [sda] Mode Sense: 73 00 10 08
[ 17.360686] sd 2:0:0:0: [sda] Write cache: enabled, read cache: enabled, supports DPO and FUA
[ 17.451956] sd 2:0:0:0: [sda] Attached SCSI disk
# ./setup-sda.sh >/dev/null 2>&1 dev_attach( ) Caching sda as bcache0 on set 0e23e266- 6032-4700- a4c9-464964ed13 49
[ 37.515474] bcache: run_cache_set() invalidating existing data
[ 37.527275] bcache: register_cache() registered cache device dm-0
[ 37.625160] bcache: register_bdev() registered backing device sda
[ 38.466997] bcache: bch_cached_
# lsblk -e 252
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 1G 0 loop
└─fake-loop0 253:0 0 1024M 0 dm
└─bcache0 251:0 0 1024M 0 disk
sda 8:0 0 1G 0 disk
└─bcache0 251:0 0 1024M 0 disk
# echo writeback > /sys/block/ sda/bcache/ cache_mode
# echo 1 > /sys/block/ sda/device/ delete
[ 77.878624] sd 2:0:0:0: [sda] Synchronizing SCSI cache
# sleep 10
#
# dd if=/dev/zero of=/dev/bcache0 bs=4k
[ 120.268072] Buffer I/O error on dev bcache0, logical block 0, lost async page write
[ 120.271978] Buffer I/O error on dev bcache0, logical block 1, lost async page write
[ 120.274554] Buffer I/O error on dev bcache0, logical block 2, lost async page write
[ 120.276671] Buffer I/O error on dev bcache0, logical block 3, lost async page write
[ 120.278760] Buffer I/O error on dev bcache0, logical block 4, lost async page write
[ 120.288042] Buffer I/O error on dev bcache0, logical block 5, lost async page write
[ 120.290178] Buffer I/O error on dev bcache0, logical block 6, lost async page write
[ 120.296043] Buffer I/O error on dev bcache0, logical block 7, lost async page write
[ 120.298167] Buffer I/O error on dev bcache0, logical block 8, lost async page write
[ 120.300220] Buffer I/O error on dev bcache0, logical block 3260, lost async page write
dd: error writing '/dev/bcache0': No space left on device
262143+0 records in
262142+0 records out
1073733632 bytes (1.1 GB, 1.0 GiB) copied, 3.49705 s, 307 MB/s
# lsblk -e 252
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 1G 0 loop
└─fake-loop0 253:0 0 1024M 0 dm
└─bcache0 251:0 0 1024M 0 disk
Modified
--------
# uname -rv 3build1bcache1- Ubuntu SMP Wed Jul 3 21:41:37 UTC
4.15.0-55-generic #60+test2019070
# modprobe scsi_debug dev_size_mb=1024
dev_ size_mb= 1024, opts=0x0, submit_queues=1, statistics=0
# dmesg | tail
[ 27.855163] scsi host2: scsi_debug: version 1.86 [20160430]
[ 27.855497] scsi 2:0:0:0: Direct-Access Linux scsi_debug 0186 PQ: 0 ANSI: 7
[ 27.855829] sd 2:0:0:0: Power-on or device reset occurred
[ 27.855883] sd 2:0:0:0: Attached scsi generic sg0 type 0
[ 27.863979] sd 2:0:0:0: [sda] 2097152 512-byte logical blocks: (1.07 GB/1.00 GiB)
[ 27.868028] sd 2:0:0:0: [sda] Write Protect is off
[ 27.868031] sd 2:0:0:0: [sda] Mode Sense: 73 00 10 08
[ 27.876114] sd 2:0:0:0: [sda] Write cache: enabled, read cache: enabled, supports DPO and FUA
[ 27.966877] sd 2:0:0:0: [sda] Attached SCSI disk
#
# ./setup-sda.sh >/dev/null 2>&1 dev_attach( ) Caching sda as bcache0 on set d3d7816b- 6bd9-4dea- bf0c-4bde76b45f 91
[ 46.294586] bcache: run_cache_set() invalidating existing data
[ 46.306769] bcache: register_cache() registered cache device dm-0
[ 46.400510] bcache: register_bdev() registered backing device sda
[ 47.247662] bcache: bch_cached_
# lsblk -e 252
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 1G 0 loop
└─fake-loop0 253:0 0 1024M 0 dm
└─bcache0 251:0 0 1024M 0 disk
sda 8:0 0 1G 0 disk
└─bcache0 251:0 0 1024M 0 disk
# echo writeback > /sys/block/ sda/bcache/ cache_mode
# echo 1 > /sys/block/ sda/device/ delete
[ 85.713826] sd 2:0:0:0: [sda] Synchronizing SCSI cache
# sleep 10 dev_status_ update( ) sda: device offline for 5 seconds dev_status_ update( ) bdev0: disable I/O request due to backing device offline device_ free() bcache0 stopped
[ 90.428125] bcache: cached_
[ 90.431495] bcache: cached_
[ 90.435591] bcache: bcache_
#
# lsblk -e 252
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 1G 0 loop
└─fake-loop0 253:0 0 1024M 0 dm
# ls /dev/bcache0
ls: cannot access '/dev/bcache0': No such file or directory