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