Skip to content

Commit

Permalink
Avoid vgcfgrestore on thin volumes/pools
Browse files Browse the repository at this point in the history
and any other unsupported volume types.

vgcfgrestore is not supposed to be able to restore any logical volumes
that use kernel metadata. All volume types except linear and striped use
kernel metadata. Main purpose of vgcfgrestore (with mandatory --force
option) is to let users fix existing thin-pool, not to recreate the pool
on empty disks. Do not even try vgcfgrestore on VGs that need any kernel
metadata, because it might lead to an inconsistent state (if there are
data that the kernel might interpret as LV metadata present on the disks).

For VGs that have any volume with kernel metadata and are thus
unsupported by vgcfgrestore, switch automatically to LV creation using
lvcreate, similarly to MIGRATION_MODE.

Avoid vgcfgrestore --force entirely, since it should not be needed now.

This mostly reverts changes in commits
311bfb3 and
1b779ab. The former code is preserved
and gets enabled if FORCE_VGCFGRESTORE=y. This option is on purpose
undocumented though and may be removed in the future.
  • Loading branch information
pcahyna committed Oct 5, 2021
1 parent 1cfe44d commit 5d5d1db
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,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 @@ -100,6 +100,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
cat >> "$LAYOUT_CODE" <<EOF
#
# It failed ... restore layout using 'vgcfgrestore --force', but then remove Thin volumes, they are broken
#
Expand All @@ -124,6 +127,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 @@ -1387,4 +1387,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
# 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:

0 comments on commit 5d5d1db

Please sign in to comment.