2017-07-02 22:38:32 +03:00
#!/usr/bin/env bash
2017-07-11 18:20:24 +03:00
# Copyright (C) 2017 Red Hat, Inc. All rights reserved.
2017-06-22 21:09:00 +03:00
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions
# of the GNU General Public License v.2.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
# Exercise cache flushing is abortable
2018-05-30 23:56:08 +03:00
2017-06-22 21:09:00 +03:00
SKIP_WITH_LVMPOLLD = 1
. lib/inittest
aux have_cache 1 3 0 || skip
2023-07-17 14:42:58 +03:00
aux prepare_vg
2017-06-22 21:09:00 +03:00
2023-07-17 14:42:58 +03:00
SIZE_MB = 200
2020-09-13 12:33:13 +03:00
2023-07-17 14:42:58 +03:00
# Use large zero device and later delayed metadata dev1
lvcreate -L$(( SIZE_MB * 2 )) M --type zero -n cpool $vg
lvconvert -y --type cache-pool --chunksize 32k $vg /cpool " $dev1 "
lvcreate -L$(( SIZE_MB * 2 )) M --type zero -n $lv1 $vg
lvconvert -y -H --chunksize 32k --cachemode writeback --cachepool $vg /cpool $vg /$lv1
2017-06-22 21:09:00 +03:00
#
# Ensure cache gets promoted blocks
#
2023-07-15 00:24:23 +03:00
for i in $( seq 1 2) ; do
dd if = /dev/zero of = " $DM_DEV_DIR / $vg / $lv1 " bs = 1M count = $SIZE_MB oflag = direct || true
dd if = " $DM_DEV_DIR / $vg / $lv1 " of = /dev/null bs = 1M count = $SIZE_MB iflag = direct || true
2017-06-22 21:09:00 +03:00
done
2023-07-17 14:42:58 +03:00
aux delay_dev " $dev1 " 0 200 " $( get first_extent_sector " $dev1 " ) : "
2020-09-13 12:33:13 +03:00
dd if = /dev/zero of = " $DM_DEV_DIR / $vg / $lv1 " bs = 1M count = $SIZE_MB
2017-06-22 21:09:00 +03:00
2020-09-13 12:33:13 +03:00
lvdisplay --maps $vg
2017-06-22 21:09:00 +03:00
# Delay dev to ensure we have some time to 'capture' interrupt in flush
2017-07-14 01:42:40 +03:00
# TODO, how to make writeback cache dirty
test " $( get lv_field $vg /$lv1 cache_dirty_blocks) " -gt 0 || {
lvdisplay --maps $vg
skip "Cannot make a dirty writeback cache LV."
}
2021-03-16 22:54:28 +03:00
LVM_TEST_TAG = " kill_me_ $PREFIX " lvconvert -vvvv --splitcache $vg /$lv1 >logconvert 2>& 1 &
2017-06-22 21:09:00 +03:00
PID_CONVERT = $!
2017-07-13 22:08:49 +03:00
for i in { 1..50} ; do
2023-07-15 00:24:23 +03:00
out = $( dmsetup status --noflush " $vg - $lv1 " )
case " $out " in
*cleaner*) break; ;
esac
2021-03-16 22:54:28 +03:00
echo " $i : Waiting for cleaner policy on $vg / $lv1 "
2024-03-20 12:53:06 +03:00
sleep .03
2017-07-11 18:20:24 +03:00
done
2021-03-16 22:54:28 +03:00
test " $i " -ge 49 && die " Waited for cleaner policy on $vg / $lv1 too long! "
2020-09-13 12:33:13 +03:00
2023-07-15 00:24:23 +03:00
# While lvconvert updated table to 'cleaner' policy now it
2020-09-13 12:33:13 +03:00
# should be running in 'Flushing' loop and just 1 KILL should
# cause abortion of flushing
2017-06-22 21:09:00 +03:00
kill -INT $PID_CONVERT
2020-09-13 12:33:13 +03:00
aux enable_dev " $dev2 "
2017-06-22 21:09:00 +03:00
wait
2020-09-13 12:33:13 +03:00
#cat logconvert || true
2021-03-16 22:54:28 +03:00
# Problem of this test is, in older kernels, even the initial change to cleaner
# policy table line causes long suspend which in practice is cleaning all the
# dirty blocks - so the test can't really break the cache clearing.
#
# So the failure of test is reported only for recent kernels > 5.6
2024-08-30 13:10:35 +03:00
# and skipped otherwise - as those can't be fixed anyway
2017-07-11 18:20:24 +03:00
grep -E "Flushing.*aborted" logconvert || {
cat logconvert || true
2017-07-13 22:08:49 +03:00
vgremove -f $vg
2021-03-16 22:54:28 +03:00
aux kernel_at_least 5 6 || skip "Cache missed to abort flushing with older kernel"
2017-07-11 18:20:24 +03:00
die " Flushing of $vg / $lv1 not aborted ? "
}
2017-06-22 21:09:00 +03:00
# check the table got restored
check grep_dmsetup table $vg -$lv1 "writeback"
2023-07-17 14:42:58 +03:00
lvdisplay --maps $vg
2017-06-22 21:09:00 +03:00
vgremove -f $vg