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