Skip to content

Commit

Permalink
Remove volume group and partitions from disk during reset
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rhvgoyal authored and rh-atomic-bot committed Apr 18, 2017
1 parent 00c9542 commit 8276a1e
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion container-storage-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,38 @@ create_disk_partitions() {
done
}

remove_partition() {
local dev="$1"

if [ -x "/usr/sbin/parted" ]; then
parted "$dev" rm 1 >/dev/null
else
sfdisk --delete "$dev" 1 >/dev/null
fi
}

# Remove disk pvs and partitions. This is called in reset storage path.
# If partition or pv does not exist, it will still return success. Error
# will be returned only if pv or partition exists and removal fails.
remove_disk_pvs_parts() {
local devs="$1" part

for dev in $devs; do
part=$(dev_query_first_child $dev)
[ -z "$part" ] && continue

if ! remove_pv_if_exists $part; then
Error "Failed to remove physical volume label on device $part"
return 1
fi

if ! remove_partition $dev; then
Error "Failed to remove partition on device $dev"
return 1
fi
done
}

create_extend_volume_group() {
if [ -z "$_VG_EXISTS" ]; then
vgcreate $VG $_PVS
Expand Down Expand Up @@ -1790,7 +1822,7 @@ reset_extra_volume() {

# Remove command processing
reset_storage() {
local resolved_path
local resolved_path dev

# Populate $_RESOLVED_MOUNT_DIR_PATH
if [ -n "$_M_CONTAINER_ROOT_LV_MOUNT_PATH" ];then
Expand All @@ -1812,6 +1844,19 @@ reset_storage() {
fi
fi

# If we created a volume group, remove volume group.
if [ "$_M_VG_CREATED" == "1" ];then
if ! remove_vg_if_exists "$_M_VG"; then
Error "Failed to remove volume group $_M_VG"
return 1
fi

# Cleanup any disks we added to volume group.
if ! remove_disk_pvs_parts "$_M_DEVS_RESOLVED";then
return 1
fi
fi

# Get rid of config data
rm -rf "$_CONFIG_DIR/$_CONFIG_NAME/"
}
Expand Down

0 comments on commit 8276a1e

Please sign in to comment.