2017-07-02 22:38:32 +03:00
#!/usr/bin/env bash
2015-09-18 18:34:23 +03:00
# Copyright (C) 2015 Red Hat, Inc. All rights reserved.
#
# 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
2015-09-18 18:34:23 +03:00
# check if 'dmsetup --noflush' will work properly for mounted snapshot
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-09-18 18:34:23 +03:00
. lib/inittest
which mkfs.ext2 || skip
aux prepare_vg 5
# Create stacked device
lvcreate --type snapshot -s -L10 -n $lv1 $vg --virtualsize 100M
aux extend_filter_LVMTEST
vgcreate $vg1 " $DM_DEV_DIR " /$vg /$lv1
lvcreate -L20 -n $lv1 $vg1
lvcreate -L10 -n snap -s $vg1 /$lv1
mkfs.ext2 " $DM_DEV_DIR / $vg1 /snap "
mkdir mnt
mount -o errors = remount-ro " $DM_DEV_DIR / $vg1 /snap " mnt
2015-09-21 23:44:43 +03:00
sync
2015-10-30 18:34:00 +03:00
# intentionally suspend layer below
2015-09-18 18:34:23 +03:00
dmsetup suspend $vg -$lv1
# now this should pass without blocking
2015-10-29 14:30:00 +03:00
dmsetup suspend --noflush --nolockfs $vg1 -snap &
2016-09-29 14:18:18 +03:00
DMPID = $!
2015-10-29 14:30:00 +03:00
#dmsetup suspend $vg1-snap &
2015-09-21 23:44:43 +03:00
sleep .5
dmsetup info --noheadings -c -o suspended $vg1 -snap | tee out
should grep -i suspend out
2015-09-18 18:34:23 +03:00
# unlock device below
dmsetup resume $vg -$lv1
# so this will pass without blocking on udev
# otherwise --noudevsync would be needed
dmsetup resume $vg1 -snap
2016-09-29 14:18:18 +03:00
# Expecting success from 'dmsetup'
wait $DMPID
2015-09-18 18:34:23 +03:00
# Try how force removal works
dmsetup suspend $vg -$lv1
# needs to fail as device is still open
2015-10-01 17:45:14 +03:00
not dmsetup remove --force $vg1 -snap &
2016-09-29 14:18:18 +03:00
DMPID = $!
2015-10-01 17:45:14 +03:00
2016-09-29 14:18:18 +03:00
# on older snapshot target 'remove' will wait till $lv1 is resumed
if aux target_at_least dm-snapshot 1 6 0 ; then
2015-10-01 17:45:14 +03:00
sleep .5
dmsetup table $vg1 -snap | tee out
should grep -i error out
2016-09-29 14:18:18 +03:00
fi
2015-10-01 17:45:14 +03:00
2015-09-18 18:34:23 +03:00
dmsetup resume $vg -$lv1
2016-09-29 14:18:18 +03:00
# Expecting success from 'not dmsetup'
wait $DMPID
2015-10-01 17:45:14 +03:00
2015-09-18 18:34:23 +03:00
# check it really is now 'error' target
dmsetup table $vg1 -snap | tee out
grep error out
umount mnt || true
lvremove -f $vg1
vgremove -ff $vg1
vgremove -ff $vg