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