Blame kpartx/kpartx_id

Packit Service 0af388
#!/bin/sh
Packit Service 0af388
#
Packit Service 0af388
# kpartx_id
Packit Service 0af388
#
Packit Service 0af388
# Generates ID information for device-mapper tables.
Packit Service 0af388
#
Packit Service 0af388
# Copyright (C) 2006 SUSE Linux Products GmbH
Packit Service 0af388
# Author:
Packit Service 0af388
#       Hannes Reinecke <hare@suse.de>
Packit Service 0af388
#
Packit Service 0af388
#
Packit Service 0af388
#       This program is free software; you can redistribute it and/or modify it
Packit Service 0af388
#       under the terms of the GNU General Public License as published by the
Packit Service 0af388
#       Free Software Foundation version 2 of the License.
Packit Service 0af388
#
Packit Service 0af388
# This script generates ID information used to generate persistent symlinks.
Packit Service 0af388
# It relies on the UUID strings generated by the various programs; the name
Packit Service 0af388
# of the tables are of no consequence.
Packit Service 0af388
#
Packit Service 0af388
# Please note that dmraid does not provide the UUIDs (yet); a patch has been
Packit Service 0af388
# sent upstream but has not been accepted yet.
Packit Service 0af388
#
Packit Service 0af388
Packit Service 0af388
DMSETUP=/sbin/dmsetup
Packit Service 0af388
Packit Service 0af388
MAJOR=$1
Packit Service 0af388
MINOR=$2
Packit Service 0af388
UUID=$3
Packit Service 0af388
Packit Service 0af388
if [ -z "$MAJOR" -o -z "$MINOR" ]; then
Packit Service 0af388
    echo "usage: $0 major minor"
Packit Service 0af388
    exit 1;
Packit Service 0af388
fi
Packit Service 0af388
Packit Service 0af388
# Device-mapper not installed; not an error
Packit Service 0af388
if [ ! -x $DMSETUP ] ; then
Packit Service 0af388
    exit 0
Packit Service 0af388
fi
Packit Service 0af388
Packit Service 0af388
Packit Service 0af388
# Table UUIDs are always '<type>-<uuid>'.
Packit Service 0af388
dmuuid=${UUID#*-}
Packit Service 0af388
dmtbl=${UUID%%-*}
Packit Service 0af388
dmpart=${dmtbl#part}
Packit Service 0af388
dmserial=
Packit Service 0af388
# kpartx types are 'part<num>'
Packit Service 0af388
if [ "$dmpart" = "$dmtbl" ] ; then
Packit Service 0af388
    dmpart=
Packit Service 0af388
else
Packit Service 0af388
    dmtbl=part
Packit Service 0af388
fi
Packit Service 0af388
Packit Service 0af388
# Set the name of the table. We're only interested in dmraid,
Packit Service 0af388
# multipath, and kpartx tables; everything else is ignored.
Packit Service 0af388
if [ "$dmtbl" = "part" ] ; then
Packit Service 0af388
    dmname=$($DMSETUP info  -c --noheadings -o name -u $dmuuid)
Packit Service 0af388
    echo "DM_MPATH=$dmname"
Packit Service 0af388
    # We need the dependencies of the parent table to figure out
Packit Service 0af388
    # the type if the parent is a multipath table
Packit Service 0af388
    case "$dmuuid" in
Packit Service 0af388
	mpath-*)
Packit Service 0af388
	    dmdeps=$($DMSETUP deps -u $dmuuid)
Packit Service 0af388
	    dmserial=${dmuuid#mpath-}
Packit Service 0af388
	    ;;
Packit Service 0af388
    esac
Packit Service 0af388
elif [ "$dmtbl" = "mpath" ] ; then
Packit Service 0af388
    dmname="$dmuuid"
Packit Service 0af388
    dmserial="$dmuuid"
Packit Service 0af388
    # We need the dependencies of the table to figure out the type
Packit Service 0af388
    dmdeps=$($DMSETUP deps -u $UUID)
Packit Service 0af388
fi
Packit Service 0af388
Packit Service 0af388
[ -n "$dmpart" ] && echo "DM_PART=$dmpart"
Packit Service 0af388
Packit Service 0af388
# Figure out the type of the map. For non-multipath maps it's
Packit Service 0af388
# always 'raid'.
Packit Service 0af388
if [ -n "$dmdeps" ] ; then
Packit Service 0af388
    case "$dmdeps" in
Packit Service 0af388
	*\(94,*)
Packit Service 0af388
	    echo "DM_TYPE=ccw"
Packit Service 0af388
	    ;;
Packit Service 0af388
	*\(104,* | *\(105,* | *\(106,* | *\(107,* | *\(108,* | *\(109,* | *\(110,* | *\(112,*)
Packit Service 0af388
	    echo "DM_TYPE=cciss"
Packit Service 0af388
	    ;;
Packit Service 0af388
	*\(9*)
Packit Service 0af388
	    echo "DM_TYPE=raid"
Packit Service 0af388
	    ;;
Packit Service 0af388
	*)
Packit Service 0af388
	    echo "DM_TYPE=scsi"
Packit Service 0af388
	    echo "DM_WWN=0x${dmserial#?}"
Packit Service 0af388
	    ;;
Packit Service 0af388
    esac
Packit Service 0af388
else
Packit Service 0af388
    echo "DM_TYPE=raid"
Packit Service 0af388
fi
Packit Service 0af388
if [[ $dmserial ]]; then
Packit Service 0af388
    echo "DM_SERIAL=$dmserial"
Packit Service 0af388
fi
Packit Service 0af388
Packit Service 0af388
exit 0