aboutsummaryrefslogtreecommitdiff
path: root/testcases/misc/lvm/prepare_lvm.sh
blob: b6557f2210094dd4727a8d89a6648815dd386342 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (c) 2020 SUSE LLC <mdoucha@suse.cz>
#
# Create and mount LVM volume groups for lvm.local runfile

TST_TESTFUNC=prepare_lvm
TST_NEEDS_ROOT=1
TST_NEEDS_CMDS="mount pvcreate vgcreate lvcreate"
. tst_test.sh

LVM_DIR="${LVM_DIR:-/tmp}"
LVM_TMPDIR="$LVM_DIR/ltp/growfiles"
LVM_IMGDIR="$LVM_DIR/ltp/imgfiles"

error_check()
{
	if [ $? -ne 0 ]; then
		tst_brk TBROK "LVM setup failed"
	fi
}

create_volume()
{
	fsname=$2
	ROD mkdir -p $fsname

	# If the FS isn't supported, only create the mountpoint and exit
	if ! tst_supported_fs $fsname; then
		return
	fi

	vgname=$1
	lvname="ltp_lv_$fsname"
	lvdev="/dev/$vgname/$lvname"

	ROD lvcreate -L 1G $vgname -n "$lvname"
	tst_mkfs $fsname "$lvdev"
	ROD mount "$lvdev" $fsname
}

prepare_mounts()
{
	FSNAME1=$1
	FSNAME2=$2
	shift 2
	LVM_DEV1=`tst_device acquire 1040 "$LVM_IMGDIR/lvm_pv1.img"`
	error_check
	LVM_DEV2=`tst_device acquire 1040 "$LVM_IMGDIR/lvm_pv2.img"`
	error_check

	# DEVSIZE=($# * 1GB / 2) + 16MB. The extra 16MB is for LVM physical
	# volume headers
	DEVSIZE=$(( $# * 512 + 16 ))
	LVM_DEV3=`tst_device acquire $DEVSIZE "$LVM_IMGDIR/lvm_pv3.img"`
	error_check
	LVM_DEV4=`tst_device acquire $DEVSIZE "$LVM_IMGDIR/lvm_pv4.img"`
	error_check
	ROD pvcreate $LVM_DEV1 $LVM_DEV2 $LVM_DEV3 $LVM_DEV4
	ROD vgcreate ltp_test_vg1 $LVM_DEV1 $LVM_DEV2
	ROD vgcreate ltp_test_vg2 $LVM_DEV3 $LVM_DEV4

	for fsname in $FSNAME1 $FSNAME2; do
		create_volume ltp_test_vg1 $fsname
	done

	for fsname in $@; do
		create_volume ltp_test_vg2 $fsname
	done
}

prepare_lvm()
{
	FS_LIST=`tst_supported_fs | sort -u`
	ROD mkdir -p "$LVM_TMPDIR"
	ROD mkdir -p "$LVM_IMGDIR"
	chmod 777 "$LVM_TMPDIR"
	cd "$LVM_TMPDIR"
	error_check
	prepare_mounts $FS_LIST
	tst_res TPASS "LVM mounts are ready"
}

tst_run