Blame SOURCES/rear-bz1732328.patch

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