xref: /titanic_51/usr/src/cmd/ibd_upgrade/ibd_upgrade.sh (revision bbaa8b60dd95d714741fc474adad3cf710ef4efd)
1#!/sbin/sh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22#
23# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24#
25#
26
27PATH=/sbin:/bin
28ORIGIFS="${IFS}"
29USAGE="Usage: ibd_upgrade [-v]"
30DRVCONF=/kernel/drv/ibp.conf.old
31
32#
33# split device path into path components
34#
35split_path_components()
36{
37	hca_path=
38	node_name=
39	port=
40	pkey=
41	service=
42	partition_name=
43
44	hca_path="/dev/`dirname $device_path`"
45	bname=`basename $device_path`
46	IFS=":"
47	set -- $bname
48	node_at_addr=$1
49	partition_name=$2
50	IFS="@"
51	set -- $node_at_addr
52	node_name=$1
53	IFS=","
54	set -- $2
55	port=$1
56	pkey=0x$2
57	service=$3
58
59	IFS="${ORIGIFS}"
60}
61
62do_cmd()
63{
64	if [ $verbose -eq 1 ]; then
65		echo "$1"
66	fi
67	$1
68}
69
70process_rc_mode()
71{
72	device=$1
73
74	#
75	# Get the instance number of ibd
76	# Device name format would be ibd#,
77	#
78	IFS="d"
79	set -- ${device}
80	IFS="${ORIGIFS}"
81
82	if [ "$1" != "ib" ]; then
83		return
84	fi
85
86	inst=$2
87
88	IFS=","
89	set -- ${enable_rc}
90	IFS="${ORIGIFS}"
91
92	if [ ${inst} -lt $# ]; then
93		(( inst = $inst + 1 ))
94		eval "linkmode=\$${inst}"
95	else
96		linkmode=0
97	fi
98
99	if [ "$linkmode" = "0" ]; then
100		do_cmd "dladm set-linkprop -p linkmode=ud ${device}"
101	fi
102}
103
104verbose=0
105while getopts v c
106do
107	case $c in
108	v)	verbose=1;;
109	\?)	echo "$USAGE" 1>&2
110		exit 2;;
111	esac
112done
113
114enable_rc=
115if [ -f ${DRVCONF} ]; then
116	enable_rc=`egrep "^[ 	]*enable_rc[ 	]*=" ${DRVCONF} | sed -e "s/[ 	]*//g" -e "s/enable_rc=//" -e "s/;$//" 2>/dev/null`
117fi
118
119#
120# Loop through all ibd devices based on the old model (i.e., one ibd instance
121# per partition; consequently device names have non zero pkey)
122# and create data links with the same names as in the old model under the
123# new model.
124#
125ls -l /dev/ibd* 2> /dev/null \
126    | while read x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 device_path
127do
128	split_path_components
129
130	if [ "$node_name" != "ibport" -o "$service" != "ipib" \
131	    -o "$pkey" = "0x0" -o "$pkey" = "0x" ]; then
132		continue
133	fi
134
135	# verify that the hca path exists
136	cd $hca_path 2> /dev/null
137	if [ $? -ne 0 ]; then
138		continue
139	fi
140
141	fn=`echo ibport@${port},0,ipib:ibp*[0-9]`
142	if [ -c "$fn" ]; then
143		IFS=":"
144		set -- $fn
145		IFS="${ORIGIFS}"
146
147		do_cmd "dladm delete-phys $partition_name" 2>/dev/null
148		if [ $? -ne 0 ]; then
149			do_cmd "ibd_delete_link $partition_name"
150		fi
151		do_cmd "dladm create-part -f -l $2 -P $pkey $partition_name"
152
153		if [ "$enable_rc" != "" ]; then
154			process_rc_mode $partition_name
155		fi
156	fi
157done
158
159exit 0
160