Blame SOURCES/rear-bz1732328.patch

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