Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid vgcfgrestore on thin volumes/pools and any other unsupported volume types. #3210

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ EOF
# '--mirrorlog', etc.
# Also, we likely do not support every layout yet (e.g. 'cachepool').

if ! is_true "$MIGRATION_MODE" ; then
if ! is_true "$MIGRATION_MODE" && lvmgrp_supports_vgcfgrestore "$vgrp" ; then
cat >> "$LAYOUT_CODE" <<EOF
LogPrint "Restoring LVM VG '$vg'"
if [ -e "$vgrp" ] ; then
Expand All @@ -124,6 +124,9 @@ if lvm vgcfgrestore -f "$VAR_DIR/layout/lvm/${vg}.cfg" $vg >&2 ; then
create_volume_group=( \$( RmInArray "$vg" "\${create_volume_group[@]}" ) )
create_logical_volumes=( \$( RmInArray "$vg" "\${create_logical_volumes[@]}" ) )

EOF
if is_true "${FORCE_VGCFGRESTORE-no}"; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if is_true "${FORCE_VGCFGRESTORE-no}"; then
if is_true "${FORCE_VGCFGRESTORE:-no}"; then

cat >> "$LAYOUT_CODE" <<EOF
#
# It failed ... restore layout using 'vgcfgrestore --force', but then remove Thin volumes, they are broken
#
Expand All @@ -148,6 +151,9 @@ elif lvm vgcfgrestore --force -f "$VAR_DIR/layout/lvm/${vg}.cfg" $vg >&2 ; then
create_volume_group=( \$( RmInArray "$vg" "\${create_volume_group[@]}" ) )
create_thin_volumes_only+=( "$vg" )

EOF
fi
cat >> "$LAYOUT_CODE" <<EOF
#
# It failed also ... restore using 'vgcreate/lvcreate' commands
#
Expand Down
26 changes: 26 additions & 0 deletions usr/share/rear/lib/layout-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1528,4 +1528,30 @@ delete_dummy_partitions_and_resize_real_ones() {
last_partition_number=0
}

# vgcfgrestore can properly restore only volume groups that do not use
# any kernel metadata. All volume types except linear and striped use
# kernel metadata.
# Check whether a VG (given as /dev/<vgname> in the first argument)
# doesn't contain any LVs that use kernel metadata.
# If the function returns true, we can safely use vgcfgrestore to restore the VG.
function lvmgrp_supports_vgcfgrestore() {
if is_true "${FORCE_VGCFGRESTORE-no}"; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if is_true "${FORCE_VGCFGRESTORE-no}"; then
if is_true "${FORCE_VGCFGRESTORE:-no}"; then

# If we are willing to use vgcfgrestore --force and then remove broken volumes,
# then everything can be considered supported. Don't do it by default though.
return 0
fi

local lvmvol vgrp lvname size layout kval

local supported_layouts=("linear" "striped")

while read lvmvol vgrp lvname size layout kval; do
[ "$vgrp" == "$1" ] || BugError "vgrp '$vgrp' != '$1'"
if ! IsInArray $layout "${supported_layouts[@]}"; then
LogPrint "Layout '$layout' of LV '$lvname' in VG '$vgrp' not supported by vgcfgrestore"
return 1
fi
done < <(grep "^lvmvol $1 " "$LAYOUT_FILE")
}

# vim: set et ts=4 sw=4: