aboutsummaryrefslogtreecommitdiff
path: root/scripts/cciss_id
blob: 8ac11d5f2cf90efd57ca7f8f204f8cb0f41763f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
#
# cciss_id
#
# Generates device node names according to the cciss naming rules
#
# Copyright (C) 2011 SUSE Linux Products GmbH
# Author:
#       Hannes Reinecke <hare@suse.de>
#
#
#       This program is free software; you can redistribute it and/or modify it
#       under the terms of the GNU General Public License as published by the
#       Free Software Foundation version 2 of the License.
#
# This script generates a device node name which is compatible
# with the 'cciss' device naming rules.
# It is intended to provide backward-compatible names for the
# 'hpsa' driver.
#

cciss_enumerate()
{
    local last_pci_dev=${1##0000:}
    local cur_pci_dev
    local cciss_num=0

    for cur_pci_dev in $(lspci -n | tac | sed -n 's/\(..:..\..\) .* 103c:\(3220\|3230\|3238\|323a\|323b\) .*/\1/p') ; do
	if [ "$cur_pci_dev" == "$last_pci_dev" ] ; then
	    echo "$cciss_num"
	    return;
	fi
	cciss_num=$(($cciss_num + 1))
    done
    echo "$cciss_num"
}

hpsa_lun_offset()
{
    local scsi_host=$1

    scsi_id=$(lsscsi 2>/dev/null | sed -n "s/.\(${scsi_host}:[0-9]*:[0-9]*:[0-9]*\)..*disk .*/\1/p" | head -1)
    echo ${scsi_id##*:}
}

DEVPATH=$1
SCSIPATH=$(cd -P /sys$DEVPATH/device; echo $PWD)
SCSIID=${SCSIPATH##*/}
HOSTID=${SCSIID%%:*}
LUNID=${SCSIID##*:}
PCIPATH=${SCSIPATH%%/host*}
PCIDEV=${PCIPATH##*/}
HOSTPATH=${PCIPATH}/host${HOSTID}/scsi_host/host${HOSTID}
read controller 2>/dev/null <${HOSTPATH}/ctlr_num || controller=$(cciss_enumerate $PCIDEV)

# hpsa lies about the LUN ...
disk_offset=$(hpsa_lun_offset $HOSTID)
if [ "$disk_offset" ] ; then
    disk=$(( $LUNID - $disk_offset ))
else
    disk=$LUNID
fi

if [ "$controller" ] && [ "$disk" ] ; then
    echo "ID_CCISS=c${controller}d${disk}"
fi