bcache does not work with suspend

Bug #1515780 reported by oliver on 2015-11-12
20
This bug affects 2 people
Affects Status Importance Assigned to Milestone
bcache-tools (Debian)
New
Unknown
bcache-tools (Ubuntu)
Medium
Unassigned

Bug Description

Bcache and suspend do not really go hand in hand. See http://bcache.evilpiepirate.org/FAQ/ for more details.

It boils down to simply disable caching mode before suspend and re-enable it after suspend. I wrote the following script and it should be part of bcache-tools since installing bcache-tools implies bcache might be in use.

The only really 'big' downside is, we always restore to writethrough mode, I guess we could store the state on suspend in /tmp and restore on resume if this is really needed.

cat /lib/systemd/system-sleep/bcache.sh
#!/bin/sh
if [ "$1" = "pre" ]; then
 for cache in /sys/block/bcache*; do
  echo "none" > ${cache}/bcache/cache_mode
 done
fi

if [ "$1" = "post" ]; then
 for cache in /sys/block/bcache*; do
  echo "writethrough" > ${cache}/bcache/cache_mode
 done
fi

Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in bcache-tools (Ubuntu):
status: New → Confirmed
Scott Moser (smoser) on 2016-05-03
Changed in bcache-tools (Ubuntu):
importance: Undecided → Medium
Scott Moser (smoser) wrote :

## This uses qemu and a maas image to easily test bcache of a root disk
## on a vm. Originally put together for bug 1515780
## It does:
## * downloads a maas image, kernel and initramfs
## * and makes a disk with 1M in front for the bcache header (root.img)
## * creates a disk for cache image (cache0.img)
## * puts a bcache header on the root.img pointing to cache disk by cset uuid
## * boots system with uuid of root filesystem
##
## once booted you can login with 'ubuntu:passw0rd' (from the user-data above)
## suspend with:
## sudo systemctl suspend
## unsuspend with:
## 'system_wakeup'
## to issue system_wakeup you need to get to qemu monitor.
## in nographic mode you you toggle between console and qemu monitor with
## the provided 'escape char' (-echr) and 'c'

$ wget http://images.maas.io/ephemeral-v2/daily/xenial/amd64/20160509/root-image.gz
$ wget http://images.maas.io/ephemeral-v2/daily/xenial/amd64/20160509/xenial/generic/boot-initrd
$ wget http://images.maas.io/ephemeral-v2/daily/xenial/amd64/20160509/xenial/generic/boot-kernel

$ sudo apt-get install bcache-tools

## set up the cache disk
$ truncate --size 500M cache0.img
$ make-bcache --cache --writeback cache0.img
UUID: 48320c10-9065-40e1-93cc-d020861e2070
Set UUID: 1d997f00-4d73-40d6-9a09-c9192bf6aed2
version: 0
nbuckets: 1000
block_size: 8
bucket_size: 1024
nr_in_set: 1
nr_this_dev: 0
first_bucket: 1
$ cset_uuid=$(bcache-super-show cache0.img | awk '$1 == "cset.uuid" { print $2 }')
$ echo $cset_uuid
1d997f00-4d73-40d6-9a09-c9192bf6aed2

## setup primary disk
$ truncate --size=1M root.img
$ zcat root-image.gz >> root.img

# 2048 is 1M / 512B sectors
$ make-bcache --bdev --data-offset=2048 "--cset-uuid=${cset_uuid}" root.img

# 1M here is same as our truncate. get the UUID of the filesystem.
$ uuid=$(blkid -p -o export -O 1M root.img | awk -F= '$1 == "UUID" { print $2 }')

## set up a seed disk
$ cat > user-data <<EOF
#cloud-config
password: passw0rd
chpasswd: { expire: False}
EOF

$ cloud-localds -v seed.img user-data

## boot it
$ qemu-system-x86_64 -enable-kvm \
   -device virtio-net-pci,netdev=net00 -netdev type=user,id=net00 \
   -drive if=virtio,file=root.img,format=raw \
   -drive if=virtio,file=cache0.img,format=raw \
   -drive if=virtio,file=seed.img,format=raw \
   -nographic \
   -kernel boot-kernel -initrd boot-initrd \
   -append "root=UUID=${uuid} console=ttyS0" -m 1024 -echr 0x05 -snapshot

Changed in bcache-tools (Debian):
status: Unknown → New
Scott Moser (smoser) wrote :

attaching the version that i've been using successfully for the past 6 months (timestamp on the file is Sep 16, 2016) on a laptop with home on a bcache device.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.