2017-07-02 22:38:32 +03:00
#!/usr/bin/env bash
2016-07-13 22:15:34 +03:00
# Copyright (C) 2016 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,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2024-08-30 13:10:35 +03:00
# Exercise resize of filesystem when size of LV already matches
2016-07-13 22:15:34 +03:00
# https://bugzilla.redhat.com/1354396
2018-05-24 17:49:48 +03:00
2016-07-13 22:15:34 +03:00
SKIP_WITH_LVMPOLLD = 1
. lib/inittest
FSCK = ${ FSCK -fsck }
MKFS = ${ MKFS -mkfs.ext3 }
RESIZEFS = ${ RESIZEFS -resize2fs }
which $FSCK || skip
which $MKFS || skip
which $RESIZEFS || skip
aux prepare_vg 2 20
lvcreate -l100%FREE -n $lv1 $vg
lvdev = " $DM_DEV_DIR / $vg / $lv1 "
lvs -a $vg
" $MKFS " " $lvdev "
# this should resolve to resize to same actual size
2022-09-10 00:07:07 +03:00
not lvreduce -l-100%FREE $vg /$lv1
2024-10-25 17:43:42 +03:00
lvreduce -r -f -l-100%FREE $vg /$lv1
2016-07-13 22:15:34 +03:00
" $FSCK " -n " $lvdev "
# size should remain the same
2022-09-10 00:07:07 +03:00
# lvresize fails with same result with or without -r
not lvextend -l+100%FREE $vg /$lv1
2024-10-25 17:43:42 +03:00
lvextend -r -f -l+100%FREE $vg /$lv1
2016-07-13 22:15:34 +03:00
" $FSCK " -n " $lvdev "
#lvchange -an $vg/$lv1
2022-09-10 00:07:07 +03:00
not lvresize -l+100%FREE $vg /$lv1
2024-10-25 17:43:42 +03:00
lvresize -r -f -l+100%FREE $vg /$lv1
2016-07-13 22:15:34 +03:00
" $FSCK " -n " $lvdev "
# Check there is really file system resize happening
# even when LV itself has still the same size
" $RESIZEFS " -f " $lvdev " 20000
" $FSCK " -n " $lvdev " | tee out
grep "20000 blocks" out
SIZE = $( get lv_field $vg /$lv1 size)
2022-09-10 00:07:07 +03:00
not lvresize -l-100%FREE $vg /$lv1
2024-10-25 17:43:42 +03:00
lvresize -r -f -l-100%FREE $vg /$lv1
2016-07-13 22:15:34 +03:00
test " $SIZE " = " $( get lv_field $vg /$lv1 size) "
" $FSCK " -n " $lvdev " | tee out
grep -v "20000 blocks" out
# Also check it fails when the user 'resize' volume without
# resizing fs and then retries with '-r'.
lvresize: add new options and defaults for fs handling
The new option "--fs String" for lvresize/lvreduce/lvextend
controls the handling of file systems before/after resizing
the LV. --resizefs is the same as --fs resize.
The new option "--fsmode String" can be used to control
mounting and unmounting of the fs during resizing.
Possible --fs values:
checksize
Only applies to reducing size; does nothing for extend.
Check the fs size and reduce the LV if the fs is not using
the affected space, i.e. the fs does not need to be shrunk.
Fail the command without reducing the fs or LV if the fs is
using the affected space.
resize
Resize the fs using the fs-specific resize command.
This may include mounting, unmounting, or running fsck.
See --fsmode to control mounting behavior, and --nofsck to
disable fsck.
resize_fsadm
Use the old method of calling fsadm to handle the fs
(deprecated.) Warning: this option does not prevent lvreduce
from destroying file systems that are unmounted (or mounted
if prompts are skipped.)
ignore
Resize the LV without checking for or handling a file system.
Warning: using ignore when reducing the LV size may destroy the
file system.
Possible --fsmode values:
manage
Mount or unmount the fs as needed to resize the fs,
and attempt to restore the original mount state at the end.
nochange
Do not mount or unmount the fs. If mounting or unmounting
is required to resize the fs, then do not resize the fs or
the LV and fail the command.
offline
Unmount the fs if it is mounted, and resize the fs while it
is unmounted. If mounting is required to resize the fs,
then do not resize the fs or the LV and fail the command.
Notes on lvreduce:
When no --fs or --resizefs option is specified:
. lvextend default behavior is fs ignore.
. lvreduce default behavior is fs checksize
(includes activating the LV.)
With the exception of --fs resize_fsadm|ignore, lvreduce requires
the recent libblkid fields FSLASTBLOCK and FSBLOCKSIZE.
FSLASTBLOCK*FSBLOCKSIZE is the last byte used by the fs on the LV,
which determines if reducing the fs is necessary.
2022-06-14 23:20:21 +03:00
# The first lvreduce intentionally ignores the fs and intentionally
# corrupts the fs so that the second lvresize will fail when it runs
# fsck.
lvreduce -f --fs ignore -l50%VG $vg /$lv1
fail lvresize -r -f -l20%VG $vg /$lv1
2016-07-13 22:15:34 +03:00
lvremove -ff $vg