Imported Upstream version 0.6.3
[platform/upstream/multipath-tools.git] / kpartx / kpartx_id
1 #!/bin/sh
2 #
3 # kpartx_id
4 #
5 # Generates ID information for device-mapper tables.
6 #
7 # Copyright (C) 2006 SUSE Linux Products GmbH
8 # Author:
9 #       Hannes Reinecke <hare@suse.de>
10 #
11 #
12 #       This program is free software; you can redistribute it and/or modify it
13 #       under the terms of the GNU General Public License as published by the
14 #       Free Software Foundation version 2 of the License.
15 #
16 # This script generates ID information used to generate persistent symlinks.
17 # It relies on the UUID strings generated by the various programs; the name
18 # of the tables are of no consequence.
19 #
20 # Please note that dmraid does not provide the UUIDs (yet); a patch has been
21 # sent upstream but has not been accepted yet.
22 #
23
24 DMSETUP=/sbin/dmsetup
25
26 MAJOR=$1
27 MINOR=$2
28 UUID=$3
29
30 if [ -z "$MAJOR" -o -z "$MINOR" ]; then
31     echo "usage: $0 major minor"
32     exit 1;
33 fi
34
35 # Device-mapper not installed; not an error
36 if [ ! -x $DMSETUP ] ; then
37     exit 0
38 fi
39
40
41 # Table UUIDs are always '<type>-<uuid>'.
42 dmuuid=${UUID#*-}
43 dmtbl=${UUID%%-*}
44 dmpart=${dmtbl#part}
45 # kpartx types are 'part<num>'
46 if [ "$dmpart" = "$dmtbl" ] ; then
47     dmpart=
48 else
49     dmtbl=part
50 fi
51
52 # Set the name of the table. We're only interested in dmraid,
53 # multipath, and kpartx tables; everything else is ignored.
54 if [ "$dmtbl" = "part" ] ; then
55     dmname=$($DMSETUP info  -c --noheadings -o name -u $dmuuid)
56     echo "DM_MPATH=$dmname"
57     # We need the dependencies of the parent table to figure out
58     # the type if the parent is a multipath table
59     case "$dmuuid" in
60         mpath-*)
61             dmdeps=$($DMSETUP deps -u $dmuuid)
62             ;;
63     esac
64 elif [ "$dmtbl" = "mpath" ] ; then
65     dmname="$dmuuid"
66     # We need the dependencies of the table to figure out the type
67     dmdeps=$($DMSETUP deps -u $UUID)
68 fi
69
70 [ -n "$dmpart" ] && echo "DM_PART=$dmpart"
71
72 # Figure out the type of the map. For non-multipath maps it's
73 # always 'raid'.
74 if [ -n "$dmdeps" ] ; then
75     case "$dmdeps" in
76         *\(94,*)
77             echo "DM_TYPE=ccw"
78             ;;
79         *\(104,* | *\(105,* | *\(106,* | *\(107,* | *\(108,* | *\(109,* | *\(110,* | *\(112,*)
80             echo "DM_TYPE=cciss"
81             ;;
82         *\(9*)
83             echo "DM_TYPE=raid"
84             ;;
85         *)
86             echo "DM_TYPE=scsi"
87             echo "DM_WWN=0x${dmname#?}"
88             ;;
89     esac
90 else
91     echo "DM_TYPE=raid"
92 fi
93
94 exit 0