File: ls-vdev

package info (click to toggle)
powerpc-utils 1.3.13-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,044 kB
  • sloc: ansic: 18,549; sh: 4,697; perl: 980; makefile: 239
file content (93 lines) | stat: -rw-r--r-- 2,766 bytes parent folder | download | duplicates (6)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#! /bin/bash

# Copyright (c) 2010 International Business Machines
#
# 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; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# Author Brian King <brking@linux.vnet.ibm.com>
#
# ls-vdev - This utility provides the HMC or IVM with name information for
# 	    virtual scsi adapters and devices
#

LSVDEV="ls-vdev"
VERSION="0.1"
LS="/bin/ls"
GREP="/bin/grep"
SED="/bin/sed"
PSERIES_PLATFORM=$(dirname $0)/pseries_platform

usage()
{
    echo "Usage: $LSVDEV"
    echo "Provide information on Virtual SCSI adapters and devices"
    echo ""
    echo "Optional arguments."
    echo "  -V	Display version information and exit"
    echo "  -h	Display this help information and exit"
    echo ""
}

show_version()
{
    echo "$LSVDEV: Version $VERSION"
    echo "Written by: Brian King <brking@linux.vnet.ibm.com>"
}

. $PSERIES_PLATFORM
if [[ $platform != $PLATFORM_PSERIES_LPAR ]]; then
	echo "$LSVDEV: is not supported on the $platform_name platform"
	exit 1
fi

while getopts ":Vh" flag ; do
    case "$flag" in
        V) show_version
                        exit 0 ;;

        h)              usage
                        exit 0 ;;
        \?)             usage
                        exit 1 ;;
    esac
done

# Look at every ibmvscsi (Virtual SCSI) device
for dev in $($LS -d /proc/device-tree/vdevice/v-scsi* 2> /dev/null) ; do
    # find the slot so it can be used in sysfs
    slot=$(echo $dev | $SED -e "s/\/proc\/device-tree\/vdevice\/v-scsi@//")

    # there is only one host per device, assign it to the path's name
    for host in $($LS -d /sys/devices/vio/$slot/host* 2> /dev/null) ; do
	parent=$(echo $host | $SED -e "s/.*\///")
	host=$($LS -d /sys/devices/vio/$slot/host*/)

        # loop through the targets for this host.
	for t in $($LS -d $host/target* 2> /dev/null); do
	    target=$(echo $($LS -d $t/$($LS $t | $GREP -v uevent | $GREP -v power | $GREP -v subsystem)))
	    if [[ ! -d $target/block ]]; then
	         name=$(echo $($LS -d $target/block*) | $SED -e "s/.*://")
	    else
	         name=$($LS $target/block)
	    fi

	    echo "$parent $name"
        done
    done
done

exit 0

# end