kpartx_id 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. DMSETUP=/sbin/dmsetup
  24. MAJOR=$1
  25. MINOR=$2
  26. UUID=$3
  27. if [ -z "$MAJOR" -o -z "$MINOR" ]; then
  28. echo "usage: $0 major minor"
  29. exit 1;
  30. fi
  31. # Device-mapper not installed; not an error
  32. if [ ! -x $DMSETUP ] ; then
  33. exit 0
  34. fi
  35. # Table UUIDs are always '<type>-<uuid>'.
  36. dmuuid=${UUID#*-}
  37. dmtbl=${UUID%%-*}
  38. dmpart=${dmtbl#part}
  39. dmserial=
  40. # kpartx types are 'part<num>'
  41. if [ "$dmpart" = "$dmtbl" ] ; then
  42. dmpart=
  43. else
  44. dmtbl=part
  45. fi
  46. # Set the name of the table. We're only interested in dmraid,
  47. # multipath, and kpartx tables; everything else is ignored.
  48. if [ "$dmtbl" = "part" ] ; then
  49. dmname=$($DMSETUP info -c --noheadings -o name -u $dmuuid)
  50. echo "DM_MPATH=$dmname"
  51. # We need the dependencies of the parent table to figure out
  52. # the type if the parent is a multipath table
  53. case "$dmuuid" in
  54. mpath-*)
  55. dmdeps=$($DMSETUP deps -u $dmuuid)
  56. dmserial=${dmuuid#mpath-}
  57. ;;
  58. esac
  59. elif [ "$dmtbl" = "mpath" ] ; then
  60. dmname="$dmuuid"
  61. dmserial="$dmuuid"
  62. # We need the dependencies of the table to figure out the type
  63. dmdeps=$($DMSETUP deps -u $UUID)
  64. fi
  65. [ -n "$dmpart" ] && echo "DM_PART=$dmpart"
  66. # Figure out the type of the map. For non-multipath maps it's
  67. # always 'raid'.
  68. if [ -n "$dmdeps" ] ; then
  69. case "$dmdeps" in
  70. *\(94,*)
  71. echo "DM_TYPE=ccw"
  72. ;;
  73. *\(104,* | *\(105,* | *\(106,* | *\(107,* | *\(108,* | *\(109,* | *\(110,* | *\(112,*)
  74. echo "DM_TYPE=cciss"
  75. ;;
  76. *\(9*)
  77. echo "DM_TYPE=raid"
  78. ;;
  79. *)
  80. echo "DM_TYPE=scsi"
  81. echo "DM_WWN=0x${dmserial#?}"
  82. ;;
  83. esac
  84. else
  85. echo "DM_TYPE=raid"
  86. fi
  87. if [[ $dmserial ]]; then
  88. echo "DM_SERIAL=$dmserial"
  89. fi
  90. exit 0