Skip to content

Commit 8276a1e

Browse files
rhvgoyalrh-atomic-bot
authored andcommitted
Remove volume group and partitions from disk during reset
When a storage configuration is removed, also remove the volume group and remove partitions from the disk. This is done only if container-storage-setup created a volume group. If a volume group is already found on the system at the time of storage creation, then it is left untouched and no disks are removed as well. Signed-off-by: Vivek Goyal <[email protected]> Closes: #243 Approved by: rhatdan
1 parent 00c9542 commit 8276a1e

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

container-storage-setup.sh

+46-1
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,38 @@ create_disk_partitions() {
876876
done
877877
}
878878

879+
remove_partition() {
880+
local dev="$1"
881+
882+
if [ -x "/usr/sbin/parted" ]; then
883+
parted "$dev" rm 1 >/dev/null
884+
else
885+
sfdisk --delete "$dev" 1 >/dev/null
886+
fi
887+
}
888+
889+
# Remove disk pvs and partitions. This is called in reset storage path.
890+
# If partition or pv does not exist, it will still return success. Error
891+
# will be returned only if pv or partition exists and removal fails.
892+
remove_disk_pvs_parts() {
893+
local devs="$1" part
894+
895+
for dev in $devs; do
896+
part=$(dev_query_first_child $dev)
897+
[ -z "$part" ] && continue
898+
899+
if ! remove_pv_if_exists $part; then
900+
Error "Failed to remove physical volume label on device $part"
901+
return 1
902+
fi
903+
904+
if ! remove_partition $dev; then
905+
Error "Failed to remove partition on device $dev"
906+
return 1
907+
fi
908+
done
909+
}
910+
879911
create_extend_volume_group() {
880912
if [ -z "$_VG_EXISTS" ]; then
881913
vgcreate $VG $_PVS
@@ -1790,7 +1822,7 @@ reset_extra_volume() {
17901822

17911823
# Remove command processing
17921824
reset_storage() {
1793-
local resolved_path
1825+
local resolved_path dev
17941826

17951827
# Populate $_RESOLVED_MOUNT_DIR_PATH
17961828
if [ -n "$_M_CONTAINER_ROOT_LV_MOUNT_PATH" ];then
@@ -1812,6 +1844,19 @@ reset_storage() {
18121844
fi
18131845
fi
18141846

1847+
# If we created a volume group, remove volume group.
1848+
if [ "$_M_VG_CREATED" == "1" ];then
1849+
if ! remove_vg_if_exists "$_M_VG"; then
1850+
Error "Failed to remove volume group $_M_VG"
1851+
return 1
1852+
fi
1853+
1854+
# Cleanup any disks we added to volume group.
1855+
if ! remove_disk_pvs_parts "$_M_DEVS_RESOLVED";then
1856+
return 1
1857+
fi
1858+
fi
1859+
18151860
# Get rid of config data
18161861
rm -rf "$_CONFIG_DIR/$_CONFIG_NAME/"
18171862
}

0 commit comments

Comments
 (0)