From 24ec9af4513890b2ab1a6f3683e8aba007a3c983 Mon Sep 17 00:00:00 2001 From: Heming Zhao Date: Wed, 30 Jun 2021 18:41:42 +0800 Subject: [PATCH] tests: new test suite of fsadm for btrfs refer legacy patche: - Ondrej Kozina https://listman.redhat.com/archives/lvm-devel/2012-November/msg00055.html Signed-off-by: Heming Zhao 2023-09-08: LVs should be resized to 64M after each test. Signed-off-by: Su Yue --- test/shell/fsadm-btrfs.sh | 176 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 test/shell/fsadm-btrfs.sh diff --git a/test/shell/fsadm-btrfs.sh b/test/shell/fsadm-btrfs.sh new file mode 100644 index 000000000000..c1b65036efb2 --- /dev/null +++ b/test/shell/fsadm-btrfs.sh @@ -0,0 +1,176 @@ +#!/usr/bin/env bash + +# Copyright (C) 2012 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +test_description='Exercise fsadm btrfs resize' + +. lib/inittest + +aux prepare_vg 1 1024 + +# set to "skip" to avoid testing given fs and test warning result +# i.e. check_btrfs=skip +check_btrfs= + +which mkfs.btrfs || check_btrfs=${check_btrfs:-mkfs.btrfs} +which btrfs || check_btrfs=${check_btrfs:-btrfs} + +vg_lv=$vg/$lv1 +vg_lv2=$vg/${lv1}bar +vg_lv3=$vg/${lv1}bar2 +dev_vg_lv="$DM_DEV_DIR/$vg_lv" +dev_vg_lv2="$DM_DEV_DIR/$vg_lv2" +dev_vg_lv3="$DM_DEV_DIR/$vg_lv3" +mount_dir="mnt" +mount_space_dir="mnt space dir" +# for recursive call +export LVM_BINARY=$(which lvm) + +test ! -d "$mount_dir" && mkdir "$mount_dir" +test ! -d "$mount_space_dir" && mkdir "$mount_space_dir" + +cleanup_mounted_and_teardown() +{ + umount "$mount_dir" || true + umount "$mount_space_dir" || true + aux teardown +} + +reset_lvs() +{ + # Since we call mkfs.btrfs with '-f', lvreduce to 64M is enough + lvreduce -L64M -nf $vg_lv || true + lvreduce -L64M -nf $vg_lv2 || true + lvreduce -L64M -nf $vg_lv3 || true +} + +check_missing_btrfs() +{ + eval local t=$check_btrfs + test -z "$t" && return 0 + test "$t" = skip && return 1 + # trick for warning test + echo "WARNING: fsadm test skipped btrfs tests, $t tool is missing" + return 1 +} + +fscheck_btrfs() { + btrfsck "$1" +} +scrub_btrfs() { + btrfs scrub start -B "$1" +} + +# btrfs minimal size calculation is complex, we use 64M here. +lvcreate -n $lv1 -L64M $vg +lvcreate -n ${lv1}bar -L64M $vg +lvcreate -n ${lv1}bar2 -L64M $vg +trap 'cleanup_mounted_and_teardown' EXIT + +single_device_test() { + mkfs.btrfs -m single "$dev_vg_lv" + mkfs.btrfs -m single "$dev_vg_lv2" + + # kernel limits 256 MB as minimal btrfs resizable size + # you can grow fs from 30MB->256MB + # but you can't grow from 30MB->180MB + fsadm --lvresize resize $vg_lv 256M + fsadm --lvresize resize $vg_lv2 256M + + not fsadm -y --lvresize resize $vg_lv 200M + lvresize -L+10M -r $vg_lv + lvreduce -L256M -r $vg_lv + fscheck_btrfs $dev_vg_lv + + mount "$dev_vg_lv" "$mount_dir" + mount "$dev_vg_lv2" "$mount_space_dir" + + not fsadm -y --lvresize resize $vg_lv 200M + lvresize -L+10M -r $vg_lv + lvreduce -L256M -r $vg_lv + scrub_btrfs $dev_vg_lv + umount "$mount_dir" + + not fsadm -y --lvresize resize $vg_lv2 200M + lvresize -L+10M -r $vg_lv2 + lvreduce -L256M -r $vg_lv2 + scrub_btrfs $dev_vg_lv2 + umount "$mount_space_dir" +} + +multiple_devices_test() { + mkfs.btrfs -m single -d single -f "$dev_vg_lv" "$dev_vg_lv2" "$dev_vg_lv3" + + fsadm -y --lvresize resize $vg_lv 256M + fsadm -y --lvresize resize $vg_lv2 256M + fsadm -y --lvresize resize $vg_lv3 256M + + # check if fsadm is able to get/resize btrfs on + # the right device + lvresize -L+150M $vg_lv + fsadm -y resize $vg_lv 300M + # no space to extend, so failed + not fsadm -y resize $vg_lv2 300M + not fsadm -y resize $vg_lv3 300M + lvreduce -y -L256M -r $vg_lv + + lvresize -L+150M $vg_lv2 + fsadm -y resize $vg_lv2 300M + not fsadm -y resize $vg_lv3 300M + not fsadm -y resize $vg_lv 300M + lvreduce -y -L256M -r $vg_lv2 + + lvresize -L+150M $vg_lv3 + fsadm -y resize $vg_lv3 300M + not fsadm -y resize $vg_lv2 300M + not fsadm -y resize $vg_lv 300M + lvreduce -y -L256M -r $vg_lv3 + fscheck_btrfs $dev_vg_lv + + # repeat with mounted fs + mount "$dev_vg_lv" "$mount_dir" + mount "$dev_vg_lv2" "$mount_space_dir" + + lvresize -L300M $vg_lv + fsadm -y resize $vg_lv 300M + not fsadm -y resize $vg_lv2 300M + not fsadm -y resize $vg_lv3 300M + lvreduce -y -L256M -r $vg_lv + + lvresize -L300M $vg_lv2 + fsadm -y resize $vg_lv2 300M + not fsadm -y resize $vg_lv3 300M + not fsadm -y resize $vg_lv 300M + lvreduce -y -L256M -r $vg_lv2 + + lvresize -L300M $vg_lv3 + fsadm -y resize $vg_lv3 300M + not fsadm -y resize $vg_lv2 300M + not fsadm -y resize $vg_lv 300M + lvreduce -y -L256M -r $vg_lv3 + + scrub_btrfs $dev_vg_lv + umount "$mount_dir" + umount "$mount_space_dir" + + lvresize -nf -L300M $vg_lv + lvresize -nf -L300M $vg_lv2 +} + +if check_missing_btrfs; then + + single_device_test + # after each test, reset_lv_size should be called to make sure + # all lvs are in same state/size. + reset_lvs + multiple_devices_test +fi + +vgremove -ff $vg -- 2.35.3