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