Blame SOURCES/rear-bz1747468.patch

769012
diff --git a/usr/share/rear/layout/prepare/GNU/Linux/110_include_lvm_code.sh b/usr/share/rear/layout/prepare/GNU/Linux/110_include_lvm_code.sh
769012
index 7cfdfcf2..1be17ba8 100644
769012
--- a/usr/share/rear/layout/prepare/GNU/Linux/110_include_lvm_code.sh
769012
+++ b/usr/share/rear/layout/prepare/GNU/Linux/110_include_lvm_code.sh
769012
@@ -68,9 +68,9 @@ create_lvmgrp() {
769012
     local vg=${vgrp#/dev/}
769012
 
769012
     cat >> "$LAYOUT_CODE" <
769012
-create_volume_group=1
769012
-create_logical_volumes=1
769012
-create_thin_volumes_only=0
769012
+create_volume_group+=( "$vg" )
769012
+create_logical_volumes+=( "$vg" )
769012
+create_thin_volumes_only=( \$( RmInArray "$vg" "\${create_thin_volumes_only[@]}" ) )
769012
 
769012
 EOF
769012
 
769012
@@ -83,7 +83,7 @@ EOF
769012
     # '--mirrorlog', etc.
769012
     # Also, we likely do not support every layout yet (e.g. 'cachepool').
769012
 
769012
-    if ! is_true "$MIGRATION_MODE" ; then
769012
+    if ! is_true "$MIGRATION_MODE" && lvmgrp_supports_vgcfgrestore "$vgrp" ; then
769012
         cat >> "$LAYOUT_CODE" <
769012
 LogPrint "Restoring LVM VG '$vg'"
769012
 if [ -e "$vgrp" ] ; then
769012
@@ -97,9 +97,12 @@ if lvm vgcfgrestore -f "$VAR_DIR/layout/lvm/${vg}.cfg" $vg >&2 ; then
769012
 
769012
     LogPrint "Sleeping 3 seconds to let udev or systemd-udevd create their devices..."
769012
     sleep 3 >&2
769012
-    create_volume_group=0
769012
-    create_logical_volumes=0
769012
+    create_volume_group=( \$( RmInArray "$vg" "\${create_volume_group[@]}" ) )
769012
+    create_logical_volumes=( \$( RmInArray "$vg" "\${create_logical_volumes[@]}" ) )
769012
 
769012
+EOF
769012
+        if is_true "${FORCE_VGCFGRESTORE-no}"; then
769012
+            cat >> "$LAYOUT_CODE" <
769012
 #
769012
 # It failed ... restore layout using 'vgcfgrestore --force', but then remove Thin volumes, they are broken
769012
 #
769012
@@ -121,9 +124,12 @@ elif lvm vgcfgrestore --force -f "$VAR_DIR/layout/lvm/${vg}.cfg" $vg >&2 ; then
769012
     sleep 3 >&2
769012
 
769012
     # All logical volumes have been created, except Thin volumes and pools
769012
-    create_volume_group=0
769012
-    create_thin_volumes_only=1
769012
+    create_volume_group=( \$( RmInArray "$vg" "\${create_volume_group[@]}" ) )
769012
+    create_thin_volumes_only+=( "$vg" )
769012
  
769012
+EOF
769012
+        fi
769012
+        cat >> "$LAYOUT_CODE" <
769012
 #
769012
 # It failed also ... restore using 'vgcreate/lvcreate' commands
769012
 #
769012
@@ -138,7 +144,7 @@ EOF
769012
     local -a devices=($(awk "\$1 == \"lvmdev\" && \$2 == \"$vgrp\" { print \$3 }" "$LAYOUT_FILE"))
769012
 
769012
 cat >> "$LAYOUT_CODE" <
769012
-if [ \$create_volume_group -eq 1 ] ; then
769012
+if IsInArray $vg "\${create_volume_group[@]}" ; then
769012
     LogPrint "Creating LVM VG '$vg'; Warning: some properties may not be preserved..."
769012
     if [ -e "$vgrp" ] ; then
769012
         rm -rf "$vgrp"
769012
@@ -240,9 +246,9 @@ create_lvmvol() {
769012
     local warnraidline
769012
 
769012
     if [ $is_thin -eq 0 ] ; then
769012
-        ifline="if [ \"\$create_logical_volumes\" -eq 1 ] && [ \"\$create_thin_volumes_only\" -eq 0 ] ; then"
769012
+        ifline="if IsInArray $vg \"\${create_logical_volumes[@]}\" && ! \$IsInArray $vg \"\${create_thin_volumes_only[@]}\" ; then"
769012
     else
769012
-        ifline="if [ \"\$create_logical_volumes\" -eq 1 ] ; then"
769012
+        ifline="if IsInArray $vg \"\${create_logical_volumes[@]}\" ; then"
769012
     fi
769012
 
769012
     if [ $is_raidunknown -eq 1 ]; then
769012
diff --git a/usr/share/rear/lib/layout-functions.sh b/usr/share/rear/lib/layout-functions.sh
769012
index 54ddb50f..ae62d666 100644
769012
--- a/usr/share/rear/lib/layout-functions.sh
769012
+++ b/usr/share/rear/lib/layout-functions.sh
769012
@@ -1308,4 +1308,30 @@ delete_dummy_partitions_and_resize_real_ones() {
769012
     last_partition_number=0
769012
 }
769012
 
769012
+# vgcfgrestore can properly restore only volume groups that do not use
769012
+# any kernel metadata. All volume types except linear and striped use
769012
+# kernel metadata.
769012
+# Check whether a VG (given as /dev/<vgname> in the first argument)
769012
+# doesn't contain any LVs that use kernel metadata.
769012
+# If the function returns true, we can safely use vgcfgrestore to restore the VG.
769012
+function lvmgrp_supports_vgcfgrestore() {
769012
+    if is_true "${FORCE_VGCFGRESTORE-no}"; then
769012
+        # If we are willing to use vgcfgrestore --force and then remove broken volumes,
769012
+        # then everything can be considered supported. Don't do it by default though.
769012
+        return 0
769012
+    fi
769012
+
769012
+    local lvmvol vgrp lvname size layout kval
769012
+
769012
+    local supported_layouts=("linear" "striped")
769012
+
769012
+    while read lvmvol vgrp lvname size layout kval; do
769012
+        [ "$vgrp" == "$1" ] || BugError "vgrp '$vgrp' != '$1'"
769012
+        if ! IsInArray $layout "${supported_layouts[@]}"; then
769012
+            LogPrint "Layout '$layout' of LV '$lvname' in VG '$vgrp' not supported by vgcfgrestore"
769012
+            return 1
769012
+        fi
769012
+    done < <(grep "^lvmvol $1 " "$LAYOUT_FILE")
769012
+}
769012
+
769012
 # vim: set et ts=4 sw=4: