2017-07-02 22:38:32 +03:00
#!/usr/bin/env bash
2012-03-16 17:00:05 +04:00
# Copyright (C) 2010-2012 Red Hat, Inc. All rights reserved.
2010-10-15 20:28:14 +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
2010-10-15 20:28:14 +04:00
2015-10-27 17:10:06 +03:00
SKIP_WITH_LVMPOLLD = 1
2010-10-15 20:28:14 +04:00
2015-10-27 17:10:06 +03:00
. lib/inittest
2015-05-09 02:59:18 +03:00
2010-10-15 20:28:14 +04:00
extend( ) {
2012-08-27 16:04:21 +04:00
lvextend --use-policies --config " activation { snapshot_autoextend_threshold = $1 } " $vg /snap
2010-10-15 20:28:14 +04:00
}
2012-03-16 17:00:05 +04:00
write_( ) {
2015-05-02 22:14:45 +03:00
dd if = /dev/zero of = " $DM_DEV_DIR / $vg /snap " bs = 1k count = $2 seek = $1 oflag = direct
2010-10-15 20:28:14 +04:00
}
2012-03-16 17:00:05 +04:00
percent_( ) {
get lv_field $vg /snap snap_percent | cut -d. -f1
2010-10-15 20:28:14 +04:00
}
2012-03-16 17:00:05 +04:00
wait_for_change_( ) {
# dmeventd only checks every 10 seconds :(
2014-10-01 11:52:09 +04:00
for i in $( seq 1 25) ; do
2012-03-16 17:00:05 +04:00
test " $( percent_) " != " $1 " && return
sleep 1
done
2010-10-15 20:28:14 +04:00
2012-03-16 17:00:05 +04:00
return 1 # timeout
}
2010-10-15 20:28:14 +04:00
2012-03-16 17:00:05 +04:00
aux prepare_dmeventd
aux prepare_vg 2
2010-10-15 20:28:14 +04:00
2013-06-15 13:21:03 +04:00
lvcreate -aey -L16M -n base $vg
2012-03-16 17:00:05 +04:00
lvcreate -s -L4M -n snap $vg /base
2010-10-15 20:28:14 +04:00
2012-03-16 17:00:05 +04:00
write_ 0 1000
2017-07-10 11:40:09 +03:00
test 24 -eq " $( percent_) "
2010-10-15 20:28:14 +04:00
2012-03-16 17:00:05 +04:00
lvchange --monitor y $vg /snap
2011-11-21 16:31:18 +04:00
2012-03-16 17:00:05 +04:00
write_ 1000 1700
pre = $( percent_)
2015-02-19 19:08:33 +03:00
# Normally the usage should be ~66% here, however on slower systems
# dmeventd could be actually 'fast' enough to have COW already resized now
2015-07-06 18:15:11 +03:00
# so mark test skipped if we are below 50% by now
2017-07-10 11:40:09 +03:00
test " $pre " -gt 50 || skip
2012-03-16 17:00:05 +04:00
wait_for_change_ $pre
2017-07-10 11:40:09 +03:00
test " $pre " -gt " $( percent_) "
2011-11-21 16:31:18 +04:00
# check that a second extension happens; we used to fail to extend when the
# utilisation ended up between THRESH and (THRESH + 10)... see RHBZ 754198
# (the utilisation after the write should be 57 %)
2012-03-16 17:00:05 +04:00
write_ 2700 2000
pre = $( percent_)
2015-02-19 19:08:33 +03:00
# Mark test as skipped if already resized...
2017-07-10 11:40:09 +03:00
test " $pre " -gt 70 || skip
2012-03-16 17:00:05 +04:00
wait_for_change_ $pre
2017-07-10 11:40:09 +03:00
test " $pre " -gt " $( percent_) "
2012-03-16 17:00:05 +04:00
vgremove -f $vg