[Rear-users] SF.net SVN: rear:[622] trunk/usr/share/rear

jhoekx at users.sourceforge.net jhoekx at users.sourceforge.net
Tue Jun 21 13:23:16 CEST 2011


Revision: 622
          http://rear.svn.sourceforge.net/rear/?rev=622&view=rev
Author:   jhoekx
Date:     2011-06-21 11:23:15 +0000 (Tue, 21 Jun 2011)

Log Message:
-----------
layout: improve LUKS handling

Now it works for LUKS on top of any device, not only on top of LVM.

Modified Paths:
--------------
    trunk/usr/share/rear/layout/save/GNU/Linux/26_crypt_layout.sh
    trunk/usr/share/rear/lib/layout-functions.sh

Modified: trunk/usr/share/rear/layout/save/GNU/Linux/26_crypt_layout.sh
===================================================================
--- trunk/usr/share/rear/layout/save/GNU/Linux/26_crypt_layout.sh	2011-06-20 12:31:27 UTC (rev 621)
+++ trunk/usr/share/rear/layout/save/GNU/Linux/26_crypt_layout.sh	2011-06-21 11:23:15 UTC (rev 622)
@@ -8,7 +8,27 @@
 Log "Saving Encrypted volumes."
 REQUIRED_PROGS=( "${REQUIRED_PROGS[@]}" cryptsetup )
 
-for device in /dev/mapper/* ; do
+while read dm_name junk ; do
+    # find the device we're mapping
+    if ! [ -e /dev/mapper/$dm_name ] ; then
+        Log "Device Mapper name $dm_name not found in /dev/mapper."
+        continue
+    fi
+    
+    dev_name=$(get_sysfs_name /dev/mapper/$dm_name)
+    if [ -z "$dev_name" ] ; then
+        Log "Could not find device $dev_number in sysfs."
+        continue
+    fi
+    
+    device=""
+    for slave in /sys/block/$dev_name/slaves/* ; do
+        if ! [ -z "$device" ] ; then
+            BugError "Multiple Device Mapper slaves for crypt $dm_name detected."
+        fi
+        device="/dev/$(get_device_name ${slave##*/})"
+    done
+    
     if ! cryptsetup isLuks $device >&8 2>&1; then
         continue
     fi
@@ -42,5 +62,5 @@
         done < /etc/crypttab
     fi
     
-    echo "crypt /dev/mapper/$name $device cipher=$cipher mode=$mode hash=$hash uuid=${uuid}${keyfile}${password}" >> $DISKLAYOUT_FILE
-done
+    echo "crypt /dev/mapper/$dm_name $device cipher=$cipher mode=$mode hash=$hash uuid=${uuid}${keyfile}${password}" >> $DISKLAYOUT_FILE
+done < <( dmsetup ls --target crypt )

Modified: trunk/usr/share/rear/lib/layout-functions.sh
===================================================================
--- trunk/usr/share/rear/lib/layout-functions.sh	2011-06-20 12:31:27 UTC (rev 621)
+++ trunk/usr/share/rear/lib/layout-functions.sh	2011-06-21 11:23:15 UTC (rev 622)
@@ -254,13 +254,47 @@
 get_sysfs_name() {
     local name=${1#/dev/}
     name=${name#/sys/block/}
-    echo "${name//\//!}"
+    
+    if [ -e /sys/block/${name//\//!} ] ; then
+        echo "${name//\//!}"
+        return 0
+    fi
+    
+    # accomodate for mapper/test -> dm-? mapping
+    local dev_number=$(dmsetup info -c --noheadings -o major,minor ${name##*/} 2>&8 )
+    if [ -n "$dev_number" ] ; then
+        local dev_name sysfs_device
+        for sysfs_device in /sys/block/*/dev ; do
+            if [ "$dev_number" = "$(cat $sysfs_device)" ] ; then
+                dev_name=${sysfs_device#/sys/block/}
+                echo "${dev_name%/*}"
+                return 0
+            fi
+        done
+    fi
 }
 
 # Translate a sysfs name to a device name.
 get_device_name() {
-    local name=$(get_sysfs_name $1)
-    echo "${name//!//}"
+    local name=${1#/dev/}
+    name=${name#/sys/block/}
+    name=${name//!//}
+    
+    if [ -e /dev/$name ] ; then
+        echo "$name"
+        return 0
+    fi
+    
+    # translate dm-8 -> mapper/test
+    local device dev_number mapper_number
+    dev_number=$(cat /sys/block/${name//\//!}/dev 2>&8)
+    for device in /dev/mapper/* ; do
+        mapper_number=$(dmsetup info -c --noheadings -o major,minor ${device#/dev/mapper/} 2>&8 )
+        if [ "$dev_number" = "$mapper_number" ] ; then
+            echo "${device#/dev/}"
+            return 0
+        fi
+    done
 }
 
 # Get the size in bytes of a block device.


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rear-users mailing list