xref: /aosp_15_r20/external/ltp/testcases/misc/lvm/cleanup_lvm.sh (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
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# Clean up LVM volume groups created by prepare_lvm.sh
6*49cdfc7eSAndroid Build Coastguard Worker
7*49cdfc7eSAndroid Build Coastguard WorkerTST_TESTFUNC=cleanup_lvm
8*49cdfc7eSAndroid Build Coastguard WorkerTST_NEEDS_ROOT=1
9*49cdfc7eSAndroid Build Coastguard WorkerTST_NEEDS_CMDS="losetup umount vgremove"
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 Workercleanup_lvm()
16*49cdfc7eSAndroid Build Coastguard Worker{
17*49cdfc7eSAndroid Build Coastguard Worker	DEVLIST=`losetup -lnO NAME,BACK-FILE | grep "$LVM_IMGDIR" | cut -d ' ' -f 1`
18*49cdfc7eSAndroid Build Coastguard Worker
19*49cdfc7eSAndroid Build Coastguard Worker	for dir in "$LVM_TMPDIR/"*; do
20*49cdfc7eSAndroid Build Coastguard Worker		tst_umount $dir
21*49cdfc7eSAndroid Build Coastguard Worker	done
22*49cdfc7eSAndroid Build Coastguard Worker
23*49cdfc7eSAndroid Build Coastguard Worker	ROD vgremove -y ltp_test_vg1
24*49cdfc7eSAndroid Build Coastguard Worker	ROD vgremove -y ltp_test_vg2
25*49cdfc7eSAndroid Build Coastguard Worker
26*49cdfc7eSAndroid Build Coastguard Worker	for devname in $DEVLIST; do
27*49cdfc7eSAndroid Build Coastguard Worker		ROD tst_device release $devname
28*49cdfc7eSAndroid Build Coastguard Worker	done
29*49cdfc7eSAndroid Build Coastguard Worker
30*49cdfc7eSAndroid Build Coastguard Worker	rm -rf $LVM_DIR/ltp
31*49cdfc7eSAndroid Build Coastguard Worker	tst_res TPASS "LVM configuration for LTP removed successfully."
32*49cdfc7eSAndroid Build Coastguard Worker}
33*49cdfc7eSAndroid Build Coastguard Worker
34*49cdfc7eSAndroid Build Coastguard Worker. tst_test.sh
35*49cdfc7eSAndroid Build Coastguard Workertst_run
36