Comment 54 for bug 1867916

Revision history for this message
Ryan Finnie (fo0bar) wrote :

With the regression fix tested, I've gone ahead and fixed the core problem on my system, switching the backing device to 4k. Documented below and worked for me, but PLEASE don't take it at face value, since part of it is literally destroying the bcache header area of the backing disk.

# WARNING! Loss of data, life, liberty, etc. Do not blindly copy/paste!
# You need to unmount and make sure the bcache device is not being used,
# and specifically wait for the cache state to go from dirty to clean
# if using writeback.

DEV_BACKING=/dev/sdx1 # /dev/md0 for me
DEV_CACHE=/dev/sdy1 # /dev/sdb1 for me
DEV_BCACHE=bcache0
OFFSET="$(bcache-super-show ${DEV_BACKING?} | awk '$1=="dev.data.first_sector" {print $2}')"
CSET_UUID="$(bcache-super-show ${DEV_CACHE?} | awk '$1=="cset.uuid" {print $2}')"
file -s ${DEV_CACHE?}
file -s ${DEV_BACKING?}
dd if=${DEV_BACKING?} bs=512 skip=${OFFSET?} count=8 | file -

# Remove and wipe cache device
echo ${CSET_UUID?} >/sys/block/${DEV_BCACHE?}/bcache/detach
cat /sys/block/${DEV_BCACHE?}/bcache/state
echo 1 >/sys/fs/bcache/${CSET_UUID?}/stop
while [ -e /sys/fs/bcache/${CSET_UUID?}/stop ]; do sleep 1; done
wipefs -a ${DEV_CACHE?}

# Stop bcache0, wipe and recreate bcache portion of backing device
echo 1 >/sys/block/${DEV_BCACHE?}/bcache/stop
while [ -e /sys/block/${DEV_BCACHE?}/bcache/stop ]; do sleep 1; done
# Removes bcache magic bytes from beginning and (hopefully) leaves all data from
# ${OFFSET?} onward (the actual data). But don't trust me here.
wipefs -a ${DEV_BACKING?}
dd if=/dev/zero of=${DEV_BACKING?} bs=512 count=${OFFSET?}
make-bcache --block 4k --bucket 2M --data-offset ${OFFSET?} -B ${DEV_BACKING?}
while [ ! -e /sys/block/${DEV_BCACHE?}/bcache/attach ]; do sleep 1; done
file -s /dev/${DEV_BCACHE?}

# Safe to remount and use bcache device now

# Recreate and attach cache
make-bcache --block 4k --bucket 2M -C ${DEV_CACHE?}
CSET_UUID="$(bcache-super-show ${DEV_CACHE?} | awk '$1=="cset.uuid" {print $2}')"
echo ${CSET_UUID?} >/sys/block/${DEV_BCACHE?}/bcache/attach
echo writeback >/sys/block/${DEV_BCACHE?}/bcache/cache_mode
cat /sys/block/${DEV_BCACHE?}/bcache/state