1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0-or-later 3# Copyright (c) 2020 SUSE LLC <mdoucha@suse.cz> 4# 5# Create and mount LVM volume groups for lvm.local runfile 6 7TST_TESTFUNC=prepare_lvm 8TST_NEEDS_ROOT=1 9TST_NEEDS_CMDS="mount pvcreate vgcreate lvcreate" 10. tst_test.sh 11 12LVM_DIR="${LVM_DIR:-/tmp}" 13LVM_TMPDIR="$LVM_DIR/ltp/growfiles" 14LVM_IMGDIR="$LVM_DIR/ltp/imgfiles" 15 16error_check() 17{ 18 if [ $? -ne 0 ]; then 19 tst_brk TBROK "LVM setup failed" 20 fi 21} 22 23create_volume() 24{ 25 fsname=$2 26 ROD mkdir -p $fsname 27 28 # If the FS isn't supported, only create the mountpoint and exit 29 if ! tst_supported_fs $fsname; then 30 return 31 fi 32 33 vgname=$1 34 lvname="ltp_lv_$fsname" 35 lvdev="/dev/$vgname/$lvname" 36 37 ROD lvcreate -L 1G $vgname -n "$lvname" 38 tst_mkfs $fsname "$lvdev" 39 ROD mount "$lvdev" $fsname 40} 41 42prepare_mounts() 43{ 44 FSNAME1=$1 45 FSNAME2=$2 46 shift 2 47 LVM_DEV1=`tst_device acquire 1040 "$LVM_IMGDIR/lvm_pv1.img"` 48 error_check 49 LVM_DEV2=`tst_device acquire 1040 "$LVM_IMGDIR/lvm_pv2.img"` 50 error_check 51 52 # DEVSIZE=($# * 1GB / 2) + 16MB. The extra 16MB is for LVM physical 53 # volume headers 54 DEVSIZE=$(( $# * 512 + 16 )) 55 LVM_DEV3=`tst_device acquire $DEVSIZE "$LVM_IMGDIR/lvm_pv3.img"` 56 error_check 57 LVM_DEV4=`tst_device acquire $DEVSIZE "$LVM_IMGDIR/lvm_pv4.img"` 58 error_check 59 ROD pvcreate $LVM_DEV1 $LVM_DEV2 $LVM_DEV3 $LVM_DEV4 60 ROD vgcreate ltp_test_vg1 $LVM_DEV1 $LVM_DEV2 61 ROD vgcreate ltp_test_vg2 $LVM_DEV3 $LVM_DEV4 62 63 for fsname in $FSNAME1 $FSNAME2; do 64 create_volume ltp_test_vg1 $fsname 65 done 66 67 for fsname in $@; do 68 create_volume ltp_test_vg2 $fsname 69 done 70} 71 72prepare_lvm() 73{ 74 FS_LIST=`tst_supported_fs | sort -u` 75 ROD mkdir -p "$LVM_TMPDIR" 76 ROD mkdir -p "$LVM_IMGDIR" 77 chmod 777 "$LVM_TMPDIR" 78 cd "$LVM_TMPDIR" 79 error_check 80 prepare_mounts $FS_LIST 81 tst_res TPASS "LVM mounts are ready" 82} 83 84tst_run 85