Update man page for multipath -r
[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     # The name of the kpartx table is the name of the parent table
56     dmname=$($DMSETUP info  -c --noheadings -o name -u $dmuuid)
57     echo "DM_NAME=$dmname"
58     # We need the dependencies of the parent table to figure out
59     # the type if the parent is a multipath table
60     case "$dmuuid" in
61         mpath-*)
62             dmdeps=$($DMSETUP deps -u $dmuuid)
63             ;;
64     esac
65 elif [ "$dmtbl" = "mpath" ] ; then
66     dmname=$tblname
67     # We need the dependencies of the table to figure out the type
68     dmdeps=$($DMSETUP deps -u $UUID)
69 elif [ "$dmtbl" = "dmraid" ] ; then
70     dmname=$tblname
71 fi
72
73 [ -n "$dmpart" ] && echo "DM_PART=$dmpart"
74
75 # Figure out the type of the map. For non-multipath maps it's
76 # always 'raid'.
77 if [ -n "$dmdeps" ] ; then
78     case "$dmdeps" in
79         *\(94,*)
80             echo "DM_TYPE=dasd"
81             ;;
82         *\(9*)
83             echo "DM_TYPE=raid"
84             ;;
85         *)
86             echo "DM_TYPE=scsi"
87             ;;
88     esac
89 else
90     echo "DM_TYPE=raid"
91 fi
92
93 exit 0