2017-07-02 22:38:32 +03:00
#!/usr/bin/env bash
2016-02-12 12:21:07 +03:00
# Copyright (C) 2012-2016 Red Hat, Inc. All rights reserved.
2012-03-22 21:29:38 +04: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,
2016-01-21 13:49:46 +03:00
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2012-03-22 21:29:38 +04:00
# no automatic extensions, just umount
2016-02-23 01:13:42 +03:00
SKIP_WITH_LVMLOCKD = 1
2015-10-27 17:10:06 +03:00
SKIP_WITH_LVMPOLLD = 1
2015-05-17 18:22:18 +03:00
export LVM_TEST_THIN_REPAIR_CMD = ${ LVM_TEST_THIN_REPAIR_CMD -/bin/false }
2017-01-21 21:21:08 +03:00
. lib/inittest
2016-07-04 18:39:17 +03:00
mntdir = " ${ PREFIX } mnt with space "
mntusedir = " ${ PREFIX } mntuse "
cleanup_mounted_and_teardown( )
{
umount " $mntdir " 2>/dev/null || true
umount " $mntusedir " 2>/dev/null || true
vgremove -ff $vg
aux teardown
}
2016-02-12 12:21:07 +03:00
is_lv_opened_( )
2012-03-22 21:29:38 +04:00
{
2017-07-10 11:40:09 +03:00
test " $( get lv_field " $1 " lv_device_open --binary) " = 1
2012-03-22 21:29:38 +04:00
}
#
# Main
#
2016-07-04 18:39:17 +03:00
which mkfs.ext4 || skip
export MKE2FS_CONFIG = " $TESTDIR /lib/mke2fs.conf "
2012-03-22 21:29:38 +04:00
aux have_thin 1 0 0 || skip
2017-01-21 19:37:53 +03:00
# Simple implementation of umount when lvextend fails
cat <<- EOF >testcmd.sh
#!/bin/sh
2017-01-21 21:21:08 +03:00
echo "Data: \$DMEVENTD_THIN_POOL_DATA"
echo "Metadata: \$DMEVENTD_THIN_POOL_METADATA"
2017-01-21 19:37:53 +03:00
2017-07-10 11:40:09 +03:00
" $TESTDIR /lib/lvextend " --use-policies \$ 1 || {
2017-01-21 21:21:08 +03:00
umount " $mntdir " || true
umount " $mntusedir " || true
2017-02-13 11:32:28 +03:00
return 0
2017-01-22 00:53:57 +03:00
}
2017-07-10 11:40:09 +03:00
test " \$( $TESTDIR /lib/lvs -o selected -S " data_percent>95|| metadata_percent>95" --noheadings \$1)" -eq 0 || {
2017-01-22 00:53:57 +03:00
umount " $mntdir " || true
umount " $mntusedir " || true
2017-02-13 11:32:28 +03:00
return 0
2017-01-21 19:37:53 +03:00
}
EOF
chmod +x testcmd.sh
2017-01-21 21:21:08 +03:00
# Show prepared script
cat testcmd.sh
2017-01-21 19:37:53 +03:00
2016-02-12 12:21:07 +03:00
# Use autoextend percent 0 - so extension fails and triggers umount...
2012-03-22 21:29:38 +04:00
aux lvmconf "activation/thin_pool_autoextend_percent = 0" \
2017-02-13 11:32:28 +03:00
"activation/thin_pool_autoextend_threshold = 70" \
" dmeventd/thin_command = \"/ $PWD /testcmd.sh\" "
2012-03-22 21:29:38 +04:00
2017-02-13 11:32:28 +03:00
aux prepare_dmeventd
2012-03-22 21:29:38 +04:00
2017-02-13 11:32:28 +03:00
aux prepare_vg 2
2012-03-22 21:29:38 +04:00
lvcreate -L8M -V8M -n $lv1 -T $vg /pool
lvcreate -V8M -n $lv2 -T $vg /pool
2016-07-04 18:39:17 +03:00
mkfs.ext4 " $DM_DEV_DIR / $vg / $lv1 "
mkfs.ext4 " $DM_DEV_DIR / $vg / $lv2 "
2012-03-22 21:29:38 +04:00
lvchange --monitor y $vg /pool
mkdir " $mntdir " " $mntusedir "
2016-07-04 18:39:17 +03:00
trap 'cleanup_mounted_and_teardown' EXIT
2017-02-13 11:32:28 +03:00
mount " $DM_DEV_DIR / $vg / $lv1 " " $mntdir "
mount " $DM_DEV_DIR / $vg / $lv2 " " $mntusedir "
2012-03-22 21:29:38 +04:00
2016-02-12 12:21:07 +03:00
# Check both LVs are opened (~mounted)
is_lv_opened_ " $vg / $lv1 "
is_lv_opened_ " $vg / $lv2 "
2012-03-22 21:29:38 +04:00
touch " $mntusedir /file $$ "
sync
2016-02-12 12:21:07 +03:00
# Running 'keeper' process sleep holds the block device still in use
2016-12-23 01:31:22 +03:00
sleep 60 < " $mntusedir /file $$ " >/dev/null 2>& 1 &
2016-02-12 12:21:07 +03:00
PID_SLEEP = $!
2012-03-22 21:29:38 +04:00
2016-07-04 18:39:17 +03:00
lvs -a $vg
# Fill pool above 95% (to cause 'forced lazy umount)
dd if = /dev/zero of = " $mntdir /file $$ " bs = 256K count = 20 conv = fdatasync
2016-12-23 01:31:22 +03:00
2012-03-22 21:29:38 +04:00
lvs -a $vg
2016-02-12 12:21:07 +03:00
# Could loop here for a few secs so dmeventd can do some work
# In the worst case check only happens every 10 seconds :(
2016-12-23 01:31:22 +03:00
# With low water mark it quickly discovers overflow and umounts $vg/$lv1
2016-02-12 12:21:07 +03:00
for i in $( seq 1 12) ; do
is_lv_opened_ " $vg / $lv1 " || break
test $i -lt 12 || die " $mntdir should have been unmounted by dmeventd! "
2016-02-12 13:59:42 +03:00
sleep 1
2016-02-12 12:21:07 +03:00
done
2016-07-04 18:39:17 +03:00
lvs -a $vg
2016-02-12 12:21:07 +03:00
is_lv_opened_ " $vg / $lv2 " || \
2016-02-12 13:59:42 +03:00
die " $mntusedir is not mounted here (sleep already expired??) "
2016-02-12 12:21:07 +03:00
# Kill device holding process
kill $PID_SLEEP
wait
2016-07-04 18:39:17 +03:00
not is_lv_opened_ " $vg / $lv2 " || {
2016-02-12 13:59:42 +03:00
mount
die " $mntusedir should have been unmounted by dmeventd! "
}