Blame SOURCES/rear-bz1732328.patch

3adda6
diff --git a/usr/share/rear/layout/save/GNU/Linux/220_lvm_layout.sh b/usr/share/rear/layout/save/GNU/Linux/220_lvm_layout.sh
3adda6
index e43ff896..a9730435 100644
3adda6
--- a/usr/share/rear/layout/save/GNU/Linux/220_lvm_layout.sh
3adda6
+++ b/usr/share/rear/layout/save/GNU/Linux/220_lvm_layout.sh
3adda6
@@ -53,6 +53,7 @@ Log "Saving LVM layout."
3adda6
     done
3adda6
 
3adda6
     header_printed=0
3adda6
+    already_processed_lvs=""
3adda6
 
3adda6
     ## Get all logical volumes
3adda6
     # format: lvmvol <volume_group> <name> <size(bytes)> <layout> [key:value ...]
3adda6
@@ -61,7 +62,7 @@ Log "Saving LVM layout."
3adda6
 
3adda6
     if lvm lvs -o lv_layout >/dev/null 2>&1; then
3adda6
 
3adda6
-        lvm 8>&- 7>&- lvs --separator=":" --noheadings --units b --nosuffix -o origin,lv_name,vg_name,lv_size,lv_layout,pool_lv,chunk_size,stripes,stripe_size | while read line ; do
3adda6
+        lvm 8>&- 7>&- lvs --separator=":" --noheadings --units b --nosuffix -o origin,lv_name,vg_name,lv_size,lv_layout,pool_lv,chunk_size,stripes,stripe_size,seg_size | while read line ; do
3adda6
 
3adda6
             if [ $header_printed -eq 0 ] ; then
3adda6
                 echo "# Format for LVM LVs"
3adda6
@@ -72,7 +73,7 @@ Log "Saving LVM layout."
3adda6
             origin="$(echo "$line" | awk -F ':' '{ print $1 }')"
3adda6
             # Skip snapshots (useless) or caches (dont know how to handle that)
3adda6
             if [ -n "$origin" ] ; then
3adda6
-                echo "# Skipped snapshot of cache information '$line'"
3adda6
+                echo "# Skipped snapshot or cache information '$line'"
3adda6
                 continue
3adda6
             fi
3adda6
 
3adda6
@@ -84,25 +85,45 @@ Log "Saving LVM layout."
3adda6
             chunksize="$(echo "$line" | awk -F ':' '{ print $7 }')"
3adda6
             stripes="$(echo "$line" | awk -F ':' '{ print $8 }')"
3adda6
             stripesize="$(echo "$line" | awk -F ':' '{ print $9 }')"
3adda6
+            segmentsize="$(echo "$line" | awk -F ':' '{ print $10 }')"
3adda6
 
3adda6
             kval=""
3adda6
+            infokval=""
3adda6
             [ -z "$thinpool" ] || kval="${kval:+$kval }thinpool:$thinpool"
3adda6
             [ $chunksize -eq 0 ] || kval="${kval:+$kval }chunksize:${chunksize}b"
3adda6
             [ $stripesize -eq 0 ] || kval="${kval:+$kval }stripesize:${stripesize}b"
3adda6
+            [ $segmentsize -eq $size ] || infokval="${infokval:+$infokval }segmentsize:${segmentsize}b"
3adda6
             if [[ ,$layout, == *,mirror,* ]] ; then
3adda6
                 kval="${kval:+$kval }mirrors:$(($stripes - 1))"
3adda6
             elif [[ ,$layout, == *,striped,* ]] ; then
3adda6
                 kval="${kval:+$kval }stripes:$stripes"
3adda6
             fi
3adda6
 
3adda6
-            echo "lvmvol /dev/$vg $lv ${size}b $layout $kval"
3adda6
+            if [[ " $already_processed_lvs " == *\ $vg/$lv\ * ]] ; then
3adda6
+                # The LV has multiple segments; the create_lvmvol() function in
3adda6
+                # 110_include_lvm_code.sh is not able to recreate this, but
3adda6
+                # keep the information for the administrator anyway.
3adda6
+                echo "#lvmvol /dev/$vg $lv ${size}b $layout $kval"
3adda6
+                if [ -n "$infokval" ] ; then
3adda6
+                    echo "# extra parameters for the line above not taken into account when restoring using 'lvcreate': $infokval"
3adda6
+                fi
3adda6
+            else
3adda6
+                if [ $segmentsize -ne $size ] ; then
3adda6
+                    echo "# WARNING: Volume $vg/$lv has multiple segments. Restoring it in Migration Mode using 'lvcreate' won't preserve segments and properties of the other segments as well!"
3adda6
+                fi
3adda6
+                echo "lvmvol /dev/$vg $lv ${size}b $layout $kval"
3adda6
+                if [ -n "$infokval" ] ; then
3adda6
+                    echo "# extra parameters for the line above not taken into account when restoring using 'lvcreate': $infokval"
3adda6
+                fi
3adda6
+                already_processed_lvs="${already_processed_lvs:+$already_processed_lvs }$vg/$lv"
3adda6
+            fi
3adda6
         done
3adda6
 
3adda6
     else
3adda6
         # Compatibility with older LVM versions (e.g. <= 2.02.98)
3adda6
         # No support for 'lv_layout', too bad, do our best!
3adda6
 
3adda6
-        lvm 8>&- 7>&- lvs --separator=":" --noheadings --units b --nosuffix -o origin,lv_name,vg_name,lv_size,modules,pool_lv,chunk_size,stripes,stripe_size | while read line ; do
3adda6
+        lvm 8>&- 7>&- lvs --separator=":" --noheadings --units b --nosuffix -o origin,lv_name,vg_name,lv_size,modules,pool_lv,chunk_size,stripes,stripe_size,seg_size | while read line ; do
3adda6
 
3adda6
             if [ $header_printed -eq 0 ] ; then
3adda6
                 echo "# Format for LVM LVs"
3adda6
@@ -125,11 +146,14 @@ Log "Saving LVM layout."
3adda6
             chunksize="$(echo "$line" | awk -F ':' '{ print $7 }')"
3adda6
             stripes="$(echo "$line" | awk -F ':' '{ print $8 }')"
3adda6
             stripesize="$(echo "$line" | awk -F ':' '{ print $9 }')"
3adda6
+            segmentsize="$(echo "$line" | awk -F ':' '{ print $10 }')"
3adda6
 
3adda6
             kval=""
3adda6
+            infokval=""
3adda6
             [ -z "$thinpool" ] || kval="${kval:+$kval }thinpool:$thinpool"
3adda6
             [ $chunksize -eq 0 ] || kval="${kval:+$kval }chunksize:${chunksize}b"
3adda6
             [ $stripesize -eq 0 ] || kval="${kval:+$kval }stripesize:${stripesize}b"
3adda6
+            [ $segmentsize -eq $size ] || infokval="${infokval:+$infokval }segmentsize:${segmentsize}b"
3adda6
             if [[ "$modules" == "" ]] ; then
3adda6
                 layout="linear"
3adda6
                 [ $stripes -eq 0 ] || kval="${kval:+$kval }stripes:$stripes"
3adda6
@@ -148,7 +172,24 @@ Log "Saving LVM layout."
3adda6
                 kval="${kval:+$kval }stripes:$stripes"
3adda6
             fi
3adda6
 
3adda6
-            echo "lvmvol /dev/$vg $lv ${size}b $layout $kval"
3adda6
+            if [[ " $already_processed_lvs " == *\ $vg/$lv\ * ]]; then
3adda6
+                # The LV has multiple segments; the create_lvmvol() function in
3adda6
+                # 110_include_lvm_code.sh is not able to recreate this, but
3adda6
+                # keep the information for the administrator anyway.
3adda6
+                echo "#lvmvol /dev/$vg $lv ${size}b $layout $kval"
3adda6
+                if [ -n "$infokval" ] ; then
3adda6
+                    echo "# extra parameters for the line above not taken into account when restoring using 'lvcreate': $infokval"
3adda6
+                fi
3adda6
+            else
3adda6
+                if [ $segmentsize -ne $size ] ; then
3adda6
+                    echo "# WARNING: Volume $vg/$lv has multiple segments. Restoring it in Migration Mode using 'lvcreate' won't preserve segments and properties of the other segments as well!"
3adda6
+                fi
3adda6
+                echo "lvmvol /dev/$vg $lv ${size}b $layout $kval"
3adda6
+                if [ -n "$infokval" ] ; then
3adda6
+                    echo "# extra parameters for the line above not taken into account when restoring using 'lvcreate': $infokval"
3adda6
+                fi
3adda6
+                already_processed_lvs="${already_processed_lvs:+$already_processed_lvs }$vg/$lv"
3adda6
+            fi
3adda6
         done
3adda6
 
3adda6
     fi