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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
|
#!/sbin/sh
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#ident "%Z%%M% %I% %E% SMI"
#
PATH=/usr/bin:/usr/sbin:$PATH; export PATH
STMSBOOTUTIL=/lib/mpxio/stmsboot_util
STMSMETHODSCRIPT=/lib/svc/method/mpxio-upgrade
KDRVCONF=
DRVCONF=
TMPDRVCONF=
TMPDRVCONF_MPXIO_ENTRY=
DRVLIST=
GUID=
VFSTAB=/etc/vfstab
SAVEDIR=/etc/mpxio
RECOVERFILE=$SAVEDIR/recover_instructions
SVCCFG_RECOVERY=$SAVEDIR/svccfg_recover
SUPPORTED_DRIVERS="fp|mpt"
USAGE=`gettext "Usage: stmsboot [-D $SUPPORTED_DRIVERS] -e | -d | -u | -L | -l controller_number"`
TEXTDOMAIN=SUNW_OST_OSCMD
export TEXTDOMAIN
STMSINSTANCE=system/device/mpxio-upgrade:default
STMSBOOT=/usr/sbin/stmsboot
BOOTADM=/sbin/bootadm
MOUNT=/usr/sbin/mount
EGREP=/usr/bin/egrep
GREP=/usr/bin/grep
AWK=/usr/bin/awk
SORT=/usr/bin/sort
UNIQ=/usr/bin/uniq
EXPR=/usr/bin/expr
SED=/usr/bin/sed
SVCPROP=/usr/bin/svcprop
SVCCFG=/usr/sbin/svccfg
SVCS=/usr/bin/svcs
SVCADM=/usr/sbin/svcadm
MACH=`/usr/bin/uname -p`
BOOTENV_FILE=/boot/solaris/bootenv.rc
CLIENT_TYPE_VHCI="/scsi_vhci.*/ssd@|/scsi_vhci.*/disk@"
# The phci client type egrep string will change based on the
# drivers which we are operating on, and the cpu architecture
# and we call stmsboot_util -n -D $drv to get that string
CLIENT_TYPE_PHCI=
reboot_needed=0
#
# Copy all entries (including comments) from source driver.conf
# to destination driver.conf except those entries which contain
# the mpxio-disable property.
# Take into consideration entries that spawn more than one line.
#
# $1 source driver.conf file
# $2 destination driver.conf file
#
# Returns 0 on success, non zero on failure.
#
delete_mpxio_disable_entries()
{
sed '
/^[ ]*#/{ p
d
}
s/[ ]*$//
/^$/{ p
d
}
/mpxio-disable[ ]*=.*;$/{ w '$3'
d
}
/;$/{ p
d
}
:rdnext
N
s/[ ]*$//
/[^;]$/b rdnext
/mpxio-disable[ ]*=/{ s/\n/ /g
w '$3'
d
}
' $1 > $2
return $?
}
#
# backup the last saved copy of the specified files.
# $* files to backup
#
backup_lastsaved()
{
for file in $*
do
file=`basename $file`
if [ -f $SAVEDIR/$file ]; then
mv $SAVEDIR/$file $SAVEDIR/${file}.old
fi
done
}
#
# build recover instructions
#
# $1 1 to include boot script in the instructions
# 0 otherwise
#
build_recover()
{
gettext "Instructions to recover your previous STMS configuration (if in case the system does not boot):\n\n" > $RECOVERFILE
echo "\tboot net \c" >> $RECOVERFILE
gettext "(or from a cd/dvd/another disk)\n" >> $RECOVERFILE
echo "\tfsck <your-root-device>" >> $RECOVERFILE
echo "\tmount <your-root-device> /mnt" >> $RECOVERFILE
if [ "x$cmd" = xupdate ]; then
gettext "\tUndo the modifications you made to STMS configuration.\n\tFor example undo any changes you made to " >> $RECOVERFILE
echo "/mnt$KDRVCONF." >> $RECOVERFILE
else
echo "\tcp /mnt${SAVEDIR}/$DRVCONF /mnt$KDRVCONF" >> $RECOVERFILE
fi
if [ $1 -eq 1 ]; then
echo "\tcp /mnt${SAVEDIR}/vfstab /mnt$VFSTAB" >> $RECOVERFILE
echo "repository /mnt/etc/svc/repository.db" > $SVCCFG_RECOVERY
echo "select $STMSINSTANCE" >> $SVCCFG_RECOVERY
echo "setprop general/enabled=false" >> $SVCCFG_RECOVERY
echo "exit" >> $SVCCFG_RECOVERY
echo "\t$SVCCFG -f /mnt$SVCCFG_RECOVERY" >> $RECOVERFILE
if [ "x$MACH" = "xi386" -a "x$new_bootpath" != "x" ]; then
echo "\tcp /mnt${SAVEDIR}/bootenv.rc /mnt$BOOTENV_FILE" >> $RECOVERFILE
fi
fi
rootdisk=`$MOUNT | $GREP "/ on " | cut -f 3 -d " "`
echo "\tumount /mnt\n\treboot\n\n${rootdisk} \c" >> $RECOVERFILE
gettext "was your root device,\nbut it could be named differently after you boot net.\n" >> $RECOVERFILE
}
#
# Arrange for /etc/vfstab and dump configuration to be updated
# during the next reboot. If the cmd is "enable" or "disable", copy
# $TMPDRVCONF to $KDRVCONF.
#
# Returns 0 on success, 1 on failure.
#
update_sysfiles()
{
gettext "WARNING: This operation will require a reboot.\nDo you want to continue ? [y/n] (default: y) "
read response
if [ "x$response" != x -a "x$response" != xy -a \
"x$response" != xY ]; then
for d in $DRVLIST; do
TMPDRVCONF=/var/run/tmp.$d.conf.$$
rm -f $TMPDRVCONF > /dev/null 2>&1
done;
return 0;
fi
# set need_bootscript to the number of drivers that
# we support.
need_bootscript=`echo $SUPPORTED_DRIVERS|$AWK -F"|" '{print NF}'`
if [ "x$cmd" = xenable -o "x$cmd" = xdisable ]; then
for d in $DRVLIST; do
DRVCONF=$d.conf
KDRVCONF=/kernel/drv/$d.conf
TMPDRVCONF=/var/run/tmp.$d.conf.$$
cp $KDRVCONF $SAVEDIR
if [ -f $TMPDRVCONF ]; then
cp $TMPDRVCONF $KDRVCONF
rm -f $TMPDRVCONF
else
# if $TMPDRVCONF doesn't exist, then we
# haven't made any changes to it
continue;
fi
#
# there is no need to update the system files in the following
# cases:
# - we are enabling mpxio and the system has no configured
# disks accessible by phci paths.
# - we are disabling mpxio and the system has no configured
# disks accessible by vhci paths.
#
# Function to setup the CLIENT_TYPE_PHCI string based on
# the list of drivers that we're operating on. The variable
# depends upon the pathname of the parent node in the
# device tree, which can be different on x86/x64 and sparc.
CLIENT_TYPE_PHCI=`$STMSBOOTUTIL -D $d -n`;
if [ "x$CLIENT_TYPE_PHCI" = "x" ]; then
continue;
fi
if [ "x$cmd" = "xenable" ]; then
ls -l /dev/dsk/*s2 2> /dev/null | \
$EGREP -s "$CLIENT_TYPE_PHCI"
else
ls -l /dev/dsk/*s2 2> /dev/null | \
$EGREP -s "$CLIENT_TYPE_VHCI"
fi
if [ $? -ne 0 ]; then
need_bootscript=`$EXPR $need_bootscript - 1`
fi
done
fi
if [ $need_bootscript -gt 0 ]; then
need_bootscript=1
if [ "x$MACH" = "xi386" -a "x$new_bootpath" != "x" ]; then
#only update bootpath for x86.
cp $BOOTENV_FILE $SAVEDIR
/usr/sbin/eeprom bootpath=$new_bootpath
fi
#
# Enable the mpxio-upgrade service, but don't run it now.
# The service will run during the next reboot and will do
# the actual job of modifying the system files.
#
$SVCADM disable -t $STMSINSTANCE
$SVCCFG -f - << EOF
select $STMSINSTANCE
setprop general/enabled = true
EOF
else
need_bootscript=0
fi
build_recover $need_bootscript
if [ "x$MACH" = "xi386" ]; then
$BOOTADM update-archive
fi
gettext "The changes will come into effect after rebooting the system.\nReboot the system now ? [y/n] (default: y) "
read response
if [ "x$response" = x -o "x$response" = xy -o \
"x$response" = xY ]; then
/usr/sbin/reboot
fi
return 0
}
#
# Enable or disable mpxio as specified by the cmd.
# Returns 0 on success, 1 on failure.
#
# Args: $cmd = {enable | disable}
# $d = {fp | mpt}
#
# the global variable $DRVLIST is used
#
configure_mpxio()
{
mpxiodisableno='mpxio-disable[ ]*=[ ]*"no"[ ]*;'
mpxiodisableyes='mpxio-disable[ ]*=[ ]*"yes"[ ]*;'
if [ "x$cmd" = xenable ]; then
mpxiodisable_cur_entry=$mpxiodisableyes
propval=no
msg=`gettext "STMS already enabled"`
else
mpxiodisable_cur_entry=$mpxiodisableno
propval=yes
msg=`gettext "STMS already disabled"`
fi
DRVCONF=$d.conf
KDRVCONF=/kernel/drv/$d.conf
TMPDRVCONF=/var/run/tmp.$d.conf.$$
TMPDRVCONF_MPXIO_ENTRY=/var/run/tmp.$d.conf.mpxioentry.$$;
echo "Checking mpxio status for driver $d"
if delete_mpxio_disable_entries $KDRVCONF $TMPDRVCONF $TMPDRVCONF_MPXIO_ENTRY; then
if [ -s $TMPDRVCONF_MPXIO_ENTRY ]; then
# $DRVCONF does have mpxiodisable entries
$EGREP -s "$mpxiodisable_cur_entry" $TMPDRVCONF_MPXIO_ENTRY
if [ $? -ne 0 ]; then
# if all mpxiodisable entries are no/yes for
# enable/disable mpxio, notify the user
rm -f $TMPDRVCONF $TMPDRVCONF_MPXIO_ENTRY > /dev/null 2>&1
continue;
else
reboot_needed=`$EXPR $reboot_needed + 1`
fi
# If mpxiodisable entries do not exist, always continue update
fi
else
rm -f $TMPDRVCONF $TMPDRVCONF_MPXIO_ENTRY > /dev/null 2>&1
gettext "failed to update " 1>&2
echo "$KDRVCONF." 1>&2
gettext "No changes were made to your STMS configuration.\n" 1>&2
return 1
fi
rm $TMPDRVCONF_MPXIO_ENTRY > /dev/null 2>&1
echo "mpxio-disable=\"${propval}\";" >> $TMPDRVCONF
}
setcmd()
{
if [ "x$cmd" = xnone ]; then
cmd=$1
else
echo "$USAGE" 1>&2
exit 2
fi
}
#
#Need to update bootpath on x86 if boot system from FC disk
#Only update bootpath here when mpxio is enabled
#If mpxio is disabled currently, will update bootpath in mpxio-upgrade
#
get_newbootpath_for_stmsdev() {
if [ "x$cmd" = "xenable" ]; then
return 0
fi
cur_bootpath=`eeprom bootpath | \
sed 's/bootpath=[ ]*//g' | sed 's/[ ]*$//'`
if [ "x$cur_bootpath" = "x" ]; then
gettext "failed to get bootpath by eeprom\n" 1>&2
return 1
fi
#only update bootpath for STMS path
echo $cur_bootpath|$EGREP $CLIENT_TYPE_VHCI > /dev/null 2>&1
if [ $? -eq 1 ]; then
return 0
fi
new_bootpath=`$STMSBOOTUTIL -p /devices$cur_bootpath`
if [ $? -ne 0 ]; then
new_bootpath=""
return 1
fi
# we replace "sd" with "disk" if we need to work on the eeprom
# bootpath setting, since fibre-channel devices will report as
# being attached via "disk" and not "sd". One day we'll have a
# truly unified and architecture-independent view of the device
# tree, and this block will be redundant
fp_bootpath=`echo $new_bootpath|grep fp.*sd`
if [ "x$fp_bootpath" != "x" ]; then
new_bootpath=`echo $fp_bootpath |sed -e"s,sd,disk,g"`
fi
}
#
# Emit a warning message to the user that by default we
# operate on all multipath-capable controllers that are
# attached to the system, and that if they want to operate
# on only a specific controller type (fp|mpt|....) then
# they need to re-invoke stmsboot with "-D $driver" in
# their argument list
#
emit_driver_warning_msg() {
# for each driver that we support, grab the list
# of controllers attached to the system.
echo ""
echo "WARNING: stmsboot operates on each supported multipath-capable controller"
echo " detected in a host. In your system, these controllers are"
for WARNDRV in `echo $SUPPORTED_DRIVERS| $SED -e"s,|, ,g"`; do
for i in `$STMSBOOTUTIL -D $WARNDRV -n | $SED -e"s,|, ,g"`; do
$GREP "$i.*$WARNDRV.$" /etc/path_to_inst | $AWK -F"\"" '{print "/devices"$2}'
done;
done;
echo ""
echo "If you do NOT wish to operate on these controllers, please quit stmsboot"
echo "and re-invoke with -D { fp | mpt } to specify which controllers you wish"
echo "to modify your multipathing configuration for."
echo ""
gettext "Do you wish to continue? [y/n] (default: y) " 1>&2
read response
if [ "x$response" != "x" -a "x$response" != "xY" -a \
"x$response" != "xy" ]; then
exit
fi
}
cmd=none
# process options
while getopts D:geduLl: c
do
case $c in
e) setcmd enable;;
d) setcmd disable;;
u) setcmd update;;
L) setcmd listall;;
l) setcmd list
controller=$OPTARG;;
D) DRV=$OPTARG;;
g) GUID="-g";;
\?) echo "$USAGE" 1>&2
exit 2;;
esac
done
if [ "x$cmd" = xnone ]; then
echo "$USAGE" 1>&2
exit 2
fi
if [ "x$DRV" = "x" ]; then
DRVLIST="fp mpt"
else
DRVLIST=$DRV
fi
STMSPRIVS=`/usr/bin/ppriv $$ | $EGREP "E:.*all|E:.*sys_devices"`
USERID=`id`
if [ "$USERID" != "uid=0(root) gid=0(root)" ] -o [ "x$STMSPRIVS" == "x" ]; then
gettext "You must be super-user to run this script.\n" 1>&2
exit 1
fi
# just a sanity check
if [ ! -f $STMSBOOTUTIL -o ! -f $STMSMETHODSCRIPT ]; then
fmt=`gettext "Can't find %s and/or %s"`
printf "$fmt\n" "$STMSBOOTUTIL" "$STMSMETHODSCRIPT" 1>&2
exit 1
fi
# If the old sun4u-specific SMF method is found, remove it
$SVCCFG -s "platform/sun4u/mpxio-upgrade:default" < /dev/null > /dev/null 2>&1
if [ $? -eq 0 ]; then
$SVCCFG delete "platform/sun4u/mpxio-upgrade:default" > /dev/null 2>&1
fi
# now import the new service, if necessary
$SVCPROP -q $STMSINSTANCE < /dev/null > /dev/null 2>&1
if [ $? -ne 0 ]; then
if [ -f /var/svc/manifest/system/device/mpxio-upgrade.xml ]; then
$SVCCFG import /var/svc/manifest/system/device/mpxio-upgrade.xml
if [ $? -ne 0 ]; then
fmt=`gettext "Unable to import %s service"`
printf "$fmt\n" "$STMSINSTANCE" 1>&2
exit 1
else
fmt=`gettext "Service %s imported successfully, continuing"`
printf "$fmt\n" "$STMSINSTANCE" 1>&2
fi
else
fmt=`gettext "Service %s does not exist on this host"`
printf "$fmt\n" "$STMSINSTANCE" 1>&2
exit 1
fi
fi
if [ "x$cmd" = xenable -o "x$cmd" = xdisable -o "x$cmd" = xupdate ]; then
#
# The bootup script doesn't work on cache-only-clients as the script
# is executed before the plumbing for cachefs mounting of root is done.
#
if $MOUNT -v | $EGREP -s " on / type (nfs|cachefs) "; then
gettext "This command option is not supported on systems with nfs or cachefs mounted root filesystem.\n" 1>&2
exit 1
fi
# if the user has left the system with the mpxio-upgrade service
# in a temporarily disabled state (ie, service is armed for the next
# reboot), then let them know. We need to ensure that the system is
# is in a sane state before allowing any further invocations, so
# try to get the system admin to do so
ISARMED=`$SVCS -l $STMSINSTANCE |$GREP "enabled.*temporary"`
if [ $? -eq 0 ]; then
echo ""
echo "You need the reboot the system in order to complete"
echo "the previous invocation of stmsboot."
echo ""
echo "Do you wish to reboot the system now? (y/n, default y) \c"
read response
if [ "x$response" = "x" -o "x$response" = "xY" -o \
"x$response" = "xy" ]; then
/usr/sbin/reboot
else
/bin/echo ""
/bin/echo "Please reboot this system before continuing"
/bin/echo ""
exit 1
fi
fi
if [ -d $SAVEDIR ]; then
#
# keep a copy of the last saved files, useful for manual
# recovery in case of a problem.
#
for d in $DRVLIST; do
DRVCONF=$d.conf
KDRVCONF=/kernel/drv/$d.conf
TMPDRVCONF=/var/run/tmp.$d.conf.$$
TMPDRVCONF_MPXIO_ENTRY=/var/run/tmp.$d.conf.mpxioentry.$$;
if [ "x$MACH" = "xsparc" ]; then
backup_lastsaved $KDRVCONF $VFSTAB
else
backup_lastsaved $KDRVCONF $VFSTAB $BOOTENV_FILE
fi
done
else
mkdir $SAVEDIR
fi
fi
if [ "x$cmd" = xenable -o "x$cmd" = xdisable ]; then
msgneeded=`echo "$DRVLIST" |grep " "`
if [ -n "$msgneeded" ]; then
emit_driver_warning_msg
fi
for d in $DRVLIST; do
configure_mpxio $cmd $d
done
if [ $reboot_needed -ne 0 ]; then
# Need to update bootpath on x86 if our boot device is
# now accessed through mpxio.
# Only update bootpath before reboot when mpxio is enabled
# If mpxio is currently disabled, we will update bootpath
# on reboot in the mpxio-upgrade service
if [ "x$MACH" = "xi386" -a "x$cmd" = "xdisable" ]; then
get_newbootpath_for_stmsdev
if [ $? -ne 0 ]; then
rm -f $TMPDRVCONF > /dev/null 2>&1
gettext "failed to update bootpath.\n" 1>&2
gettext "No changes were made to your STMS configuration.\n" 1>&2
return 1
fi
fi
update_sysfiles
else
echo "STMS is already ${cmd}d. No changes or reboots needed"
fi
elif [ "x$cmd" = xupdate ]; then
if [ "x$MACH" = "xi386" ]; then
# In this case we always change the bootpath to phci-based
# path first. bootpath will later be modified in mpxio-upgrade
# to the vhci-based path if mpxio is enabled on root.
get_newbootpath_for_stmsdev
if [ $? -ne 0 ]; then
gettext "failed to update bootpath.\n" 1>&2
return 1
fi
fi
update_sysfiles
elif [ "x$cmd" = xlist ]; then
$STMSBOOTUTIL $GUID -l $controller
else
$STMSBOOTUTIL $GUID -L
fi
exit $?
|